QXRD  0.11.16
qxrdhistogramdialog.cpp
Go to the documentation of this file.
1 #include "qxrdhistogramdialog.h"
2 #include "ui_qxrdhistogramdialog.h"
3 #include <QSettings>
4 #include "qcepsettingssaver.h"
5 #include "qxrddebug.h"
7 #include "qxrdexperiment.h"
8 #include "qxrdacquisition.h"
9 
11  QxrdExperimentWPtr expt,
12  QWidget *parent) :
13  QDockWidget(parent),
14  m_Experiment(expt),
15  m_HistogramDialogSettings(settings)
16 {
18  printf("QxrdHistogramDialog::QxrdHistogramDialog(%p)\n", this);
19  }
20 
21  setupUi(this);
22 
24 
25  if (set) {
26  m_HistogramPlot->init(set->histogramPlotSettings());
27  }
28 }
29 
31 {
33  printf("QxrdHistogramDialog::~QxrdHistogramDialog(%p)\n", this);
34  }
35 }
36 
38 {
39  m_Image = image;
40 
42 }
43 
45 {
47 
48  if (set) {
49  set->set_HistogramRect(rect);
50 
52  }
53 }
54 
56 {
58 }
59 
61 {
63 
64  if (set && m_Image) {
66 
67  if (expt) {
68  QTime tic;
69  tic.start();
70 
71  QRectF rect = set->get_HistogramRect();
72 
73  int nsum = m_Image->get_SummedExposures();
74 
75  if (nsum < 1) {
76  nsum = 1;
77  }
78 
79  QxrdAcquisitionPtr acq(expt->acquisition());
80 
81  double satlev = 60000;
82 
83  if (acq) {
84  satlev = acq->get_OverflowLevel();
85  }
86 
87  double min = 0, max = satlev*nsum;
88 
89  const int nbins=1000;
90 
91  QcepDoubleVector x0(nbins), h0(nbins), h1(nbins);
92 
93  for (int i=0; i<nbins; i++) {
94 // double x = min+i*(max-min)/1000.0;
95  x0[i] = i*100.0/(double)nbins;
96  h0[i] = 0;
97  h1[i] = 0;
98  }
99 
100  int width = m_Image->get_Width();
101  int height= m_Image->get_Height();
102 
103  double *data = m_Image->data();
104 
105  for (int i=0; i<width; i++) {
106  for (int j=0; j<height; j++) {
107  double v = *data++;
108 
109  int n;
110 
111  if (v<min) {
112  n=0;
113  } else if (v>max) {
114  n=nbins-1;
115  } else {
116  n=(nbins-1)*(v-min)/(max-min);
117  }
118 
119  if (n<0) {
120  n=0;
121  }
122 
123  if (n>=nbins) {
124  n=nbins-1;
125  }
126 
127  h0[n]++;
128 
129  if (rect.contains(i,j)) {
130  h1[n]++;
131  }
132  }
133  }
134 
135  m_HistogramPlot->detachItems();
136 
137  QwtPlotPiecewiseCurve *pc0 = new QwtPlotPiecewiseCurve(m_HistogramPlot, "Entire Image");
138 
139  pc0->setSamples(x0, h0);
140  pc0->setPen(QPen(Qt::red));
141 
142  pc0->attach(m_HistogramPlot);
143 
144  QwtPlotPiecewiseCurve *pc1 = new QwtPlotPiecewiseCurve(m_HistogramPlot,
145  tr("[%1,%2]-[%3,%4]")
146  .arg(rect.left()).arg(rect.bottom())
147  .arg(rect.right()).arg(rect.top()));
148 
149  pc1->setSamples(x0, h1);
150  pc1->setPen(QPen(Qt::darkRed));
151 
152  pc1->attach(m_HistogramPlot);
153 
154  m_HistogramPlot->replot();
155 
156  if (qcepDebug(DEBUG_HISTOGRAM)) {
157  expt -> printMessage(tr("Histogram of data took %1 msec").arg(tic.elapsed()));
158  }
159  }
160  }
161 }
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
QSharedPointer< QxrdAcquisition > QxrdAcquisitionPtr
QSharedPointer< QxrdHistogramDialogSettings > QxrdHistogramDialogSettingsPtr
QWeakPointer< QxrdExperiment > QxrdExperimentWPtr
QVector< double > QcepDoubleVector
Definition: qcepmacros.h:19
QcepDoubleImageDataPtr m_Image
QxrdExperimentWPtr m_Experiment
A class which draws piecewise curves.
QWeakPointer< QxrdHistogramDialogSettings > QxrdHistogramDialogSettingsWPtr
void onProcessedImageAvailable(QcepDoubleImageDataPtr image, QcepMaskDataPtr overflow)
void histogramSelectionChanged(QRectF rect)
QSharedPointer< QcepMaskData > QcepMaskDataPtr
QxrdHistogramDialog(QxrdHistogramDialogSettingsWPtr settings, QxrdExperimentWPtr expt, QWidget *parent)
QxrdHistogramDialogSettingsWPtr m_HistogramDialogSettings
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr