UltraScan III
us_resplot_fem.cpp
Go to the documentation of this file.
1 
3 #include "us_resplot_fem.h"
4 #include "us_fematch.h"
5 #include "us_settings.h"
6 #include "us_gui_settings.h"
7 #include "us_math2.h"
8 #include "us_constants.h"
9 
10 #include <qwt_legend.h>
11 
12 // constructor: residuals plot widget
13 US_ResidPlotFem::US_ResidPlotFem( QWidget* parent = 0 )
14  : US_WidgetsDialog( 0, 0 )
15 {
16  // lay out the GUI
17  setWindowTitle( tr( "Finite Element Data/Residuals Viewer" ) );
18  setPalette( US_GuiSettings::frameColor() );
19 
20  QSize p1size( 560, 240 );
21  QSize p2size( 560, 240 );
22 
24 
25  mainLayout = new QHBoxLayout( this );
26  leftLayout = new QVBoxLayout();
27  rightLayout = new QVBoxLayout();
28  datctrlsLayout = new QGridLayout();
29  resctrlsLayout = new QGridLayout();
30  buttonsLayout = new QVBoxLayout();
31 
32  mainLayout->setSpacing ( 2 );
33  mainLayout->setContentsMargins( 2, 2, 2, 2 );
34 
35  QLabel* lb_datctrls = us_banner( tr( "FE Analysis Data Viewer" ) );
36  QLabel* lb_resctrls = us_banner( tr( "FE Analysis Residuals Viewer" ) );
37  QLabel* lb_vari = us_label( tr( "Variance:" ) );
38  QLabel* lb_rmsd = us_label( tr( "RMSD:" ) );
39 
40  QPushButton* pb_close = us_pushbutton( tr( "Close" ) );
41 
42  QLayout* lo_plteda =
43  us_checkbox( tr( "Plot Experimental Data" ), ck_plteda, true );
44  QLayout* lo_subtin =
45  us_checkbox( tr( "Subtract Time Invariant Noise" ), ck_subtin );
46  QLayout* lo_subrin =
47  us_checkbox( tr( "Subtract Radially Invariant Noise" ), ck_subrin );
48  QLayout* lo_pltsda =
49  us_checkbox( tr( "Plot Simulated/Modeled Data" ), ck_pltsda, true );
50  QLayout* lo_addtin =
51  us_checkbox( tr( "Add Time Invariant Noise" ), ck_addtin );
52  QLayout* lo_addrin =
53  us_checkbox( tr( "Add Radially Invariant Noise" ), ck_addrin );
54  QLayout* lo_pltres =
55  us_checkbox( tr( "Plot Residuals" ), ck_pltres, true );
56  QLayout* lo_plttin =
57  us_checkbox( tr( "Plot Time Invariant Noise" ), ck_plttin );
58  QLayout* lo_pltrin =
59  us_checkbox( tr( "Plot Radially Invariant Noise" ), ck_pltrin );
60  QLayout* lo_pltran =
61  us_checkbox( tr( "Plot Random Noise" ), ck_pltran );
62  QLayout* lo_shorbm =
63  us_checkbox( tr( "Show Residuals Bitmap" ), ck_shorbm );
64 
65  le_vari = us_lineedit( "0.0", -1, true );
66  le_rmsd = us_lineedit( "0.0", -1, true );
67 
68  datctrlsLayout->addWidget( lb_datctrls, 0, 0, 1, 8 );
69  datctrlsLayout->addLayout( lo_plteda, 1, 0, 1, 8 );
70  datctrlsLayout->addLayout( lo_subtin, 2, 1, 1, 7 );
71  datctrlsLayout->addLayout( lo_subrin, 3, 1, 1, 7 );
72  datctrlsLayout->addLayout( lo_pltsda, 4, 0, 1, 8 );
73  datctrlsLayout->addLayout( lo_addtin, 5, 1, 1, 7 );
74  datctrlsLayout->addLayout( lo_addrin, 6, 1, 1, 7 );
75 
76  resctrlsLayout->addWidget( lb_resctrls, 0, 0, 1, 8 );
77  resctrlsLayout->addLayout( lo_pltres, 1, 0, 1, 8 );
78  resctrlsLayout->addLayout( lo_plttin, 2, 0, 1, 8 );
79  resctrlsLayout->addLayout( lo_pltrin, 3, 0, 1, 8 );
80  resctrlsLayout->addLayout( lo_pltran, 4, 0, 1, 8 );
81  resctrlsLayout->addLayout( lo_shorbm, 5, 0, 1, 8 );
82  resctrlsLayout->addWidget( lb_vari, 6, 0, 1, 3 );
83  resctrlsLayout->addWidget( le_vari, 6, 3, 1, 5 );
84  resctrlsLayout->addWidget( lb_rmsd, 7, 0, 1, 3 );
85  resctrlsLayout->addWidget( le_rmsd, 7, 3, 1, 5 );
86 
87  buttonsLayout ->addWidget( pb_close );
88 
90  tr( "Experimental Data" ),
91  tr( "Radius (cm)" ),
92  tr( "Absorbance" ) );
93 
95  tr( "Residuals" ),
96  tr( "Radius (cm)" ),
97  tr( "OD Difference" ) );
98 
99  data_plot1->setCanvasBackground( Qt::black );
100  data_plot2->setCanvasBackground( Qt::black );
101  data_plot1->setMinimumSize( p1size );
102  data_plot2->setMinimumSize( p2size );
103 
104  rightLayout->addLayout( plotLayout1 );
105  rightLayout->addLayout( plotLayout2 );
106 
107  leftLayout ->addLayout( datctrlsLayout );
108  leftLayout ->addLayout( resctrlsLayout );
109  leftLayout ->addStretch();
110  leftLayout ->addLayout( buttonsLayout );
111 
112  mainLayout->addLayout( leftLayout );
113  mainLayout->addLayout( rightLayout );
114 
115  connect( ck_plteda, SIGNAL( toggled( bool ) ),
116  this, SLOT( pedaCheck( bool ) ) );
117  connect( ck_subtin, SIGNAL( toggled( bool ) ),
118  this, SLOT( stinCheck( bool ) ) );
119  connect( ck_subrin, SIGNAL( toggled( bool ) ),
120  this, SLOT( srinCheck( bool ) ) );
121  connect( ck_pltsda, SIGNAL( toggled( bool ) ),
122  this, SLOT( psdaCheck( bool ) ) );
123  connect( ck_addtin, SIGNAL( toggled( bool ) ),
124  this, SLOT( atinCheck( bool ) ) );
125  connect( ck_addrin, SIGNAL( toggled( bool ) ),
126  this, SLOT( arinCheck( bool ) ) );
127  connect( ck_pltres, SIGNAL( toggled( bool ) ),
128  this, SLOT( presCheck( bool ) ) );
129  connect( ck_plttin, SIGNAL( toggled( bool ) ),
130  this, SLOT( ptinCheck( bool ) ) );
131  connect( ck_pltrin, SIGNAL( toggled( bool ) ),
132  this, SLOT( prinCheck( bool ) ) );
133  connect( ck_pltran, SIGNAL( toggled( bool ) ),
134  this, SLOT( pranCheck( bool ) ) );
135  connect( ck_shorbm, SIGNAL( toggled( bool ) ),
136  this, SLOT( srbmCheck( bool ) ) );
137 
138  connect( pb_close, SIGNAL( clicked() ),
139  this, SLOT( close_all() ) );
140 
141  have_ed = false;
142  have_sd = false;
143  have_ti = false;
144  have_ri = false;
145  have_bm = false;
146  skip_plot = true;
147 
148  if ( parent )
149  { // Get data pointers from parent of parent
150  US_FeMatch* fem = (US_FeMatch*)parent;
151  edata = fem->fem_editdata();
152  sdata = fem->fem_simdata();
153  excllist = fem->fem_excllist();
154  ti_noise = fem->fem_ti_noise();
155  ri_noise = fem->fem_ri_noise();
156  resbmap = fem->fem_resbmap();
157  have_ed = ( edata != 0 );
158  have_sd = ( sdata != 0 );
159  have_ti = ( ti_noise != 0 && ti_noise->count > 0 );
160  have_ri = ( ri_noise != 0 && ri_noise->count > 0 );
161  have_bm = ( resbmap != 0 );
162 DbgLv(1) << "RP:edata " << have_ed;
163 DbgLv(1) << "RP:sdata " << have_sd;
164 DbgLv(1) << "RP:ti_noise count" << (have_ti ? ti_noise->count : 0);
165 DbgLv(1) << "RP:ri_noise count" << (have_ri ? ri_noise->count : 0);
166 DbgLv(1) << "RP:resbmap" << have_bm;
167  }
168 
169  else
170  {
171  qDebug() << "*ERROR* unable to get RP parent";
172  }
173 
174  ck_subtin->setEnabled( have_ti );
175  ck_subrin->setEnabled( have_ri );
176  ck_addtin->setEnabled( have_ti );
177  ck_addrin->setEnabled( have_ri );
178  ck_plttin->setEnabled( have_ti );
179  ck_pltrin->setEnabled( have_ri );
180 
181  ck_plteda->setChecked( true );
182  ck_subtin->setChecked( have_ti );
183  ck_subrin->setChecked( have_ri );
184 
185  skip_plot = false;
186  data_plot1->resize( p1size );
187  data_plot2->resize( p2size );
188 
189  plot_data();
190 
191  setVisible( true );
192  resize( p2size );
193 }
194 
195 // externally force a specific plot for lower plot
196 void US_ResidPlotFem::set_plot( int plotf )
197 {
198  if ( plotf == 1 )
199  { // ti_noise plot
200  ck_plttin->setChecked( true );
201  }
202 
203  else if ( plotf == 2 )
204  { // ri_noise plot
205  ck_pltrin->setChecked( true );
206  }
207 
208  else if ( plotf == 0 )
209  { // residuals plot
210  ck_pltres->setChecked( true );
211  }
212 }
213 
214 // return a pointer to the QwtPlot for the lower plot
216 {
217  return data_plot2;
218 }
219 
220 // plot-experimental-data box [un]checked
221 void US_ResidPlotFem::pedaCheck( bool chkd )
222 {
223  if ( chkd )
224  { // box is being checked: sub boxes enabled if data present
225  ck_subtin->setEnabled( have_ti );
226  ck_subrin->setEnabled( have_ri );
227  }
228 
229  else
230  { // box is being unchecked: sub boxes disabled
231  ck_subtin->setEnabled( false );
232  ck_subrin->setEnabled( false );
233  }
234 
235  plot_data();
236 }
237 
238 // subtract-ti-noise box [un]checked
240 {
241  plot_data();
242 }
243 
244 // subtract-ri-noise box [un]checked
246 {
247  plot_data();
248 }
249 
250 // plot-simulation-data box [un]checked
251 void US_ResidPlotFem::psdaCheck( bool chkd )
252 {
253  if ( chkd )
254  { // box is being checked: sub boxes enabled if data present
255  ck_addtin->setEnabled( have_ti );
256  ck_addrin->setEnabled( have_ri );
257  }
258 
259  else
260  { // box is being unchecked: sub boxes disabled
261  ck_addtin->setEnabled( false );
262  ck_addrin->setEnabled( false );
263  }
264 
265  plot_data();
266 }
267 
268 // add-ti-noise box [un]checked
270 {
271  plot_data();
272 }
273 
274 // add-ri-noise box [un]checked
276 {
277  plot_data();
278 }
279 
280 // plot-residuals box [un]checked
281 void US_ResidPlotFem::presCheck( bool chkd )
282 {
283  skip_plot = true;
284 
285  if ( chkd )
286  { // alternate residual plots unchecked
287  ck_plttin->setChecked( false );
288  ck_pltrin->setChecked( false );
289  ck_pltran->setChecked( false );
290  }
291 
292  skip_plot = false;
293 
294  plot_data();
295 }
296 
297 // plot-ti-noise box [un]checked
298 void US_ResidPlotFem::ptinCheck( bool chkd )
299 {
300  skip_plot = true;
301 
302  if ( chkd )
303  { // alternate residual plots unchecked
304  ck_pltres->setChecked( false );
305  ck_pltrin->setChecked( false );
306  ck_pltran->setChecked( false );
307  }
308 
309  skip_plot = false;
310 
311  plot_data();
312 }
313 
314 // plot-ri-noise box [un]checked
315 void US_ResidPlotFem::prinCheck( bool chkd )
316 {
317  skip_plot = true;
318 
319  if ( chkd )
320  { // alternate residual plots unchecked
321  ck_pltres->setChecked( false );
322  ck_plttin->setChecked( false );
323  ck_pltran->setChecked( false );
324  }
325 
326  skip_plot = false;
327 
328  plot_data();
329 }
330 
331 // plot-random-noise box [un]checked
332 void US_ResidPlotFem::pranCheck( bool chkd )
333 {
334  skip_plot = true;
335 
336  if ( chkd )
337  { // alternate residual plots unchecked
338  ck_pltres->setChecked( false );
339  ck_plttin->setChecked( false );
340  ck_pltrin->setChecked( false );
341  }
342 
343  skip_plot = false;
344 
345  plot_data();
346 }
347 
348 // show-residual-bitmap box [un]checked
349 void US_ResidPlotFem::srbmCheck( bool chkd )
350 {
351  if ( chkd )
352  { // bitmap checked: replot to possibly build new map
353  have_bm = ( resbmap != 0 );
354 
355  if ( have_bm )
356  { // if bitmap exists already, detect when closed
357  connect( resbmap, SIGNAL( destroyed() ),
358  this, SLOT( resids_closed() ) );
359  }
360 
361  plot_data();
362  }
363 }
364 
365 // close button clicked
367 {
368  if ( resbmap != 0 )
369  resbmap->close();
370 
371  close();
372 }
373 
374 // plot the data
376 {
377  if ( skip_plot ) // avoid redundant successive calls
378  return;
379 
380  plot_edata(); // plot experimental
381 
382  plot_rdata(); // plot residuals
383 }
384 
385 // plot the experimental data
387 {
388  data_plot1->detachItems();
389  data_plot1->clear();
390 
391  bool do_plteda = have_ed && ck_plteda->isChecked();
392  bool do_pltsda = have_sd && ck_pltsda->isChecked();
393  bool do_addtin = have_ti && ck_addtin->isChecked();
394  bool do_subtin = have_ti && ck_subtin->isChecked();
395  bool do_addrin = have_ri && ck_addrin->isChecked();
396  bool do_subrin = have_ri && ck_subrin->isChecked();
397 
398  int points = 0;
399  int count = 0;
400  double tinoi = 0.0;
401  double rinoi = 0.0;
402  double rl = 0.0;
403  double vh = 9999.0;
404  double sval;
405 
406  if ( have_ed )
407  {
408  points = edata->pointCount();
409  rl = edata->radius( 0 );
410  }
411 
412  if ( !do_plteda && !do_pltsda )
413  { // no real experimental plot specified: re-do plot and return
414  data_plot1->replot();
415  return;
416  }
417 
418  if ( do_plteda && !do_pltsda )
419  data_plot1->setTitle( tr( "Experimental Data" ) );
420 
421  else if ( do_plteda && do_pltsda )
422  data_plot1->setTitle( tr( "Experimental and Simulated Data" ) );
423 
424  else if ( do_pltsda )
425  data_plot1->setTitle( tr( "Simulated Data" ) );
426 
427  us_grid( data_plot1 );
428 
429  if ( do_plteda )
430  { // set title and values count for experimental data
431  data_plot1->setAxisTitle( QwtPlot::yLeft,
432  tr( "Absorbance at " ) + edata->wavelength + tr( " nm" ) );
433  points = edata->pointCount();
434  }
435 
436  if ( do_pltsda )
437  { // set title and values count for simulation data
438  if ( have_ed )
439  data_plot1->setAxisTitle( QwtPlot::yLeft,
440  tr( "Absorbance at " ) + edata->wavelength + tr( " nm" ) );
441  else
442  data_plot1->setAxisTitle( QwtPlot::yLeft, tr( "Absorbance" ) );
443 
444  count = sdata->pointCount();
445  }
446 
447  count = ( points > count ) ? points : count; // maximum array count
448 
449  QVector< double > rvec( count, 0.0 );
450  QVector< double > vvec( count, 0.0 );
451  double* rr = rvec.data();
452  double* vv = vvec.data();
453 
454  QString title;
455  QwtPlotCurve* curv;
456  QPen pen_red( Qt::red );
457  QPen pen_plot( US_GuiSettings::plotCurve() );
458 
459  if ( do_plteda )
460  { // plot experimental curves
461  points = edata->pointCount();
462  count = edata->scanCount();
463  rinoi = 0.0;
464  tinoi = 0.0;
465 
466  for ( int jj = 0; jj < points; jj++ )
467  { // get radii (x) just once
468  rr[ jj ] = edata->radius( jj );
469  }
470 
471  for ( int ii = 0; ii < count; ii++ )
472  { // get readings (y) for each scan
473  if ( excllist->contains( ii ) ) continue;
474 
475  if ( do_subrin )
476  rinoi = ri_noise->values[ ii ];
477 
478  for ( int jj = 0; jj < points; jj++ )
479  { // each y is reading, optionally minus some noise
480  if ( do_subtin )
481  tinoi = ti_noise->values[ jj ];
482 
483  vv[ jj ] = edata->value( ii, jj ) - rinoi - tinoi;
484  }
485 
486  title = tr( "Curve " ) + QString::number( ii );
487  curv = us_curve( data_plot1, title );
488 
489  curv->setPen( pen_plot );
490  curv->setData( rr, vv, points );
491  }
492  }
493 
494  if ( do_pltsda )
495  { // plot simulation curves
496  points = sdata->pointCount();
497  count = sdata->scanCount();
498  rinoi = 0.0;
499  tinoi = 0.0;
500 
501  for ( int jj = 0; jj < points; jj++ )
502  { // get radii (x) just once
503  rr[ jj ] = sdata->radius( jj );
504  }
505 
506  for ( int ii = 0; ii < count; ii++ )
507  { // get readings (y) for each scan
508  if ( excllist->contains( ii ) ) continue;
509 
510  if ( do_addrin )
511  rinoi = ri_noise->values[ ii ];
512 
513  for ( int jj = 0; jj < points; jj++ )
514  { // each y is reading, optionally plus some noise
515  if ( do_addtin )
516  tinoi = ti_noise->values[ jj ];
517 
518  if ( rr[ jj ] >= rl )
519  sval = sdata->value( ii, jj ) + rinoi + tinoi;
520 
521  else
522  sval = edata->value( ii, jj ) - rinoi - tinoi;
523 
524  if ( sval > vh )
525  sval = vv[ jj - 1 ];
526 
527  vv[ jj ] = sval;
528  }
529 
530  title = tr( "S-Curve " ) + QString::number( ii );
531  curv = us_curve( data_plot1, title );
532 
533  curv->setPen( pen_red );
534  curv->setData( rr, vv, points );
535  }
536  }
537 
538  data_plot1->replot();
539 }
540 
541 // plot the residual data
543 {
544  data_plot2->detachItems();
545  data_plot2->clear();
546 
547  bool do_pltres = have_ed && ck_pltres->isChecked() && have_sd;
548  bool do_plttin = have_ti && ck_plttin->isChecked();
549  bool do_pltrin = have_ri && ck_pltrin->isChecked();
550  bool do_pltran = have_ed && ck_pltran->isChecked() && have_sd;
551  bool do_shorbm = have_ed && ck_shorbm->isChecked() && have_sd;
552  bool do_addtin = have_ti && ck_addtin->isChecked();
553  bool do_subtin = have_ti && ck_subtin->isChecked();
554  bool do_addrin = have_ri && ck_addrin->isChecked();
555  bool do_subrin = have_ri && ck_subrin->isChecked();
556 
557  int points = edata->pointCount();
558  int count = edata->scanCount();
559  double tinoi = 0.0;
560  double rinoi = 0.0;
561  double rvalu = 0.0;
562  double rmsd = 0.0;
563 
564  if ( !do_pltres && !do_plttin && !do_pltrin &&
565  !do_pltran && !do_shorbm )
566  { // if no plots specified, just clean up plot and return
567  data_plot2->replot();
568  return;
569  }
570 
571  us_grid( data_plot2 );
572  data_plot2->setAxisTitle( QwtPlot::xBottom, tr( "Radius (cm)" ) );
573 
574  int vsize = qMax( sdata->pointCount(), qMax( points, count ) );
575 
576  QVector< double > rvec( vsize, 0.0 );
577  QVector< double > vvec( vsize, 0.0 );
578  double* rr = rvec.data();
579  double* vv = vvec.data();
580 
581  QString title;
582  QwtPlotCurve* curv;
583  QPen pen_plot( Qt::green );
584 
585  // plot a zero line in red
586  double rmin = sdata->radius( 0 ) - 0.02;
587  double rmax = sdata->radius( points - 1 ) + 0.02;
588  rr[ 0 ] = !do_pltrin ? rmin : 0.0;
589  rr[ 1 ] = !do_pltrin ? rmax : double( count );
590  vv[ 0 ] = 0.0;
591  vv[ 1 ] = 0.0;
592  curv = us_curve( data_plot2, "zero-line" );
593  curv->setPen( QPen( QBrush( Qt::red ), 2 ) );
594  curv->setData( rr, vv, 2 );
595 
596  if ( do_pltres )
597  { // plot residuals
598  data_plot2->setTitle( tr( "Residuals" ) );
599 
600  for ( int jj = 0; jj < points; jj++ )
601  { // get radii (x) just once
602  rr[ jj ] = sdata->radius( jj );
603  }
604 
605  int kpts = 0;
606 
607  for ( int ii = 0; ii < count; ii++ )
608  { // get readings (y) for each scan
609  if ( excllist->contains( ii ) ) continue;
610 
611  rinoi = 0.0;
612  if ( do_subrin )
613  rinoi = ri_noise->values[ ii ];
614  if ( do_addrin )
615  rinoi += ri_noise->values[ ii ];
616 
617  for ( int jj = 0; jj < points; jj++ )
618  { // each residual is e-value minus s-value
619  tinoi = 0.0;
620  if ( do_subtin )
621  tinoi = ti_noise->values[ jj ];
622  if ( do_addtin )
623  tinoi += ti_noise->values[ jj ];
624 
625  rvalu = edata->value( ii, jj ) - sdata->value( ii, jj )
626  - rinoi - tinoi;
627 
628  rmsd += sq( rvalu );
629  kpts++;
630 
631  vv[ jj ] = rvalu;
632  }
633 
634  title = tr( "resids " ) + QString::number( ii );
635  curv = us_curve( data_plot2, title );
636 
637  curv->setPen( pen_plot );
638  curv->setStyle( QwtPlotCurve::Dots );
639  curv->setData( rr, vv, points );
640  }
641 
642  // display variance and RMSD
643  rmsd /= (double)( kpts );
644  le_vari->setText( QString::number( rmsd ) );
645  rmsd = sqrt( rmsd );
646  le_rmsd->setText( QString::number( rmsd ) );
647 //*Debug
648 //DbgLv(1) << "BEFORE data00" << edata->value(0,0);
649 //ti_noise->apply_to_data(*edata);
650 //DbgLv(1) << " TIrmv data00" << edata->value(0,0);
651 //ti_noise->apply_to_data(*edata,false);
652 //DbgLv(1) << " TIadd data00" << edata->value(0,0);
653 //ri_noise->apply_to_data(*edata);
654 //DbgLv(1) << " RIrmv data00" << edata->value(0,0);
655 //ri_noise->apply_to_data(*edata,false);
656 //DbgLv(1) << " RIadd data00" << edata->value(0,0);
657 //US_Noise::apply_noise(*edata,ti_noise);
658 //DbgLv(1) << " TIrmv data00" << edata->value(0,0);
659 //US_Noise::apply_noise(*edata,ti_noise,false);
660 //DbgLv(1) << " TIadd data00" << edata->value(0,0);
661 //US_Noise::apply_noise(*edata,ri_noise);
662 //DbgLv(1) << " RIrmv data00" << edata->value(0,0);
663 //US_Noise::apply_noise(*edata,ri_noise,false);
664 //DbgLv(1) << " RIadd data00" << edata->value(0,0);
665  }
666 
667  else if ( do_plttin )
668  { // plot time-invariant noise
669  data_plot2->setTitle( tr( "Time-Invariant Noise" ) );
670 
671  for ( int jj = 0; jj < points; jj++ )
672  { // accumulate radii and noise values
673  rr[ jj ] = edata->radius( jj );
674  vv[ jj ] = ti_noise->values[ jj ];
675  }
676 
677  title = tr( "ti_noise" );
678  curv = us_curve( data_plot2, title );
679 
680  curv->setPen( pen_plot );
681  curv->setData( rr, vv, points );
682  }
683 
684  else if ( do_pltrin )
685  { // plot radially-invariant noise
686  data_plot2->setTitle( tr( "Radially-Invariant Noise" ) );
687 
688  for ( int ii = 0; ii < count; ii++ )
689  { // accumulate scan numbers and noise values
690  rr[ ii ] = (double)( ii + 1 );
691  vv[ ii ] = ri_noise->values[ ii ];
692  }
693 
694  title = tr( "ri_noise" );
695  curv = us_curve( data_plot2, title );
696 
697  data_plot2->setAxisTitle( QwtPlot::xBottom, tr( "Scan Number" ) );
698  curv->setPen( pen_plot );
699  curv->setData( rr, vv, count );
700  }
701 
702  else if ( do_pltran )
703  { // plot random noise
704  data_plot2->setTitle( tr( "Random Noise" ) );
705  points = sdata->pointCount();
706  count = sdata->scanCount();
707 
708  for ( int jj = 0; jj < points; jj++ )
709  { // get radii (x) just once
710  rr[ jj ] = sdata->radius( jj );
711  }
712 
713  int kpts = 0;
714 
715  for ( int ii = 0; ii < count; ii++ )
716  { // get random noise (y) for each scan
717  if ( excllist->contains( ii ) ) continue;
718 
719  rinoi = have_ri ? ri_noise->values[ ii ] : 0.0;
720 
721  for ( int jj = 0; jj < points; jj++ )
722  { // each random value is e-value minus s-value with optional noise
723  tinoi = have_ti ? ti_noise->values[ jj ] : 0.0;
724  rvalu = edata->value( ii, jj ) - sdata->value( ii, jj )
725  - rinoi - tinoi;
726 
727  rmsd += sq( rvalu );
728  kpts++;
729 
730  vv[ jj ] = rvalu;
731  }
732 
733  title = tr( "random noise " ) + QString::number( ii );
734  curv = us_curve( data_plot2, title );
735 
736  curv->setPen( pen_plot );
737  curv->setStyle( QwtPlotCurve::Dots );
738  curv->setData( rr, vv, points );
739  }
740 
741  // display variance and RMSD
742  rmsd /= (double)( kpts );
743  le_vari->setText( QString::number( rmsd ) );
744  rmsd = sqrt( rmsd );
745  le_rmsd->setText( QString::number( rmsd ) );
746  }
747 
748 
749  if ( do_shorbm )
750  { // show residuals bitmap (if not already shown)
751 
752  QVector< QVector< double > > resids;
753  QVector< double > resscan;
754 
755  resids .resize( count );
756  resscan.resize( points );
757  rmsd = 0.0;
758  int kpts = 0;
759 
760  for ( int ii = 0; ii < count; ii++ )
761  { // build a vector for each scan
762  if ( excllist->contains( ii ) )
763  {
764  resscan.fill( 0.0 );
765  resids[ ii ] = resscan;
766  continue;
767  }
768 
769  rinoi = 0.0;
770  if ( do_subrin )
771  rinoi = ri_noise->values[ ii ];
772  if ( do_addrin )
773  rinoi += ri_noise->values[ ii ];
774 
775  for ( int jj = 0; jj < points; jj++ )
776  { // build residual values within a scan
777  tinoi = 0.0;
778  if ( do_subtin )
779  tinoi = ti_noise->values[ jj ];
780  if ( do_addtin )
781  tinoi += ti_noise->values[ jj ];
782 
783  rvalu = edata->value( ii, jj ) - sdata->value( ii, jj )
784  - rinoi - tinoi;
785 
786  rmsd += sq( rvalu );
787  kpts++;
788 
789  resscan[ jj ] = rvalu;
790  }
791 
792  resids[ ii ] = resscan;
793  }
794 
795  rmsd /= (double)( kpts );
796  le_vari->setText( QString::number( rmsd ) );
797  rmsd = sqrt( rmsd );
798  le_rmsd->setText( QString::number( rmsd ) );
799 
800  if ( resbmap )
801  { // already have resbmap: just replot residuals bitmap
802  resbmap->replot( resids );
803  resbmap->raise();
804  resbmap->activateWindow();
805  }
806 
807  else
808  { // pop up a little dialog with residuals bitmap
809  resbmap = new US_ResidsBitmap( resids );
810  connect( resbmap, SIGNAL( destroyed() ),
811  this, SLOT( resids_closed() ) );
812  resbmap->move( this->pos() + QPoint( 100, 100 ) );
813  resbmap->show();
814  resbmap->raise();
815  }
816 
817  qApp->processEvents();
818  }
819 
820  // display curves we have created; then clean up
821 
822  data_plot2->setAxisScale( QwtPlot::xBottom, rmin, rmax );
823  data_plot2->replot();
824 }
825 
826 // react to residual bitmap having been closed
828 {
829 DbgLv(1) << "Resids BitMap Closed!!!";
830  resbmap = 0;
831  have_bm = false;
832  ck_shorbm->setChecked( false );
833 }
834