QXRD  0.11.16
qcepimageslicegraphcontroller.cpp
Go to the documentation of this file.
2 #include <stdio.h>
5 #include "qcepimagedata.h"
6 #include "qcepimagedata-ptr.h"
8 
10  : QcepDataObjectGraphController(window, mode, object)
11 {
12 
13 }
14 
16 {
17  delete(m_Widget);
18 }
19 
21 {
23 
24  m_Window->m_Splitter->addWidget(m_Widget);
25 
27 }
28 
30 {
31  m_Window -> clearPlot();
32  int curveNumber = 0;
33 
34  QcepImageDataBase* data = qobject_cast<QcepImageDataBase*>(m_Object.data());
35 
36  if (data) {
37  int mode = m_Window -> currentGraphMode();
38 
39  int nRows = data->get_Height();
40  int nCols = data->get_Width();
41 
42  double hStart = data->get_HStart();
43  double hStep = data->get_HStep();
44 
45  double vStart = data->get_VStart();
46  double vStep = data->get_VStep();
47 
49  m_Window -> m_ImagePlot -> setAxisTitle(QwtPlot::xBottom, tr("%1 (%2)")
50  .arg(data->get_HLabel()).arg(data->get_HUnits()));
51  m_Window -> m_ImagePlot -> setAxisTitle(QwtPlot::yLeft, "Intensity");
52 
53  int start = m_Window->get_SliceHStart();
54  int summed = m_Window->get_SliceHSummed();
55  int skipped = m_Window->get_SliceHSkipped();
56  int repeats = m_Window->get_SliceHRepeats();
57 
58  if (summed < 1) summed = 1;
59  if (skipped < 0) skipped = 0;
60  if (repeats < 1) repeats = 1;
61 
62  for (int rpt = 0; rpt<repeats; rpt++) {
63  int st = start+rpt*(summed+skipped);
64 
65  if (st < nRows) {
66  QVector<double> x,y;
67 
68  for (int col=0; col<nCols; col++) {
69  double s=0;
70  int n=0;
71 
72  for (int sum=0; sum<summed; sum++) {
73  int row=start+rpt*(summed+skipped)+sum;
74 
75  if (row < nRows) {
76  double v = data->getImageData(col, row);
77 
78  if (v==v) {
79  s += v;
80  n += 1;
81  }
82  }
83  }
84 
85  x.append(hStart+col*hStep);
86  y.append(s/n);
87  }
88 
89  if (x.count() > 0) {
90  int st = start+rpt*(summed+skipped);
91  int en = st+summed-1;
92 
93  if (en >= nRows) {
94  en = nRows-1;
95  }
96 
97  QwtPlotCurve *curve = NULL;
98 
99  if (st == en) {
100  curve = new QwtPlotPiecewiseCurve(m_Window->m_ImagePlot, tr("%1 = %2")
101  .arg(data->get_VLabel())
102  .arg(vStart+st*vStep)
103  .arg(data->get_VUnits()));
104  } else {
105  curve = new QwtPlotPiecewiseCurve(m_Window->m_ImagePlot, tr("%1 = %2 to %3 %4")
106  .arg(data->get_VLabel())
107  .arg(vStart+st*vStep).arg(vStart+en*vStep)
108  .arg(data->get_VUnits()));
109  }
110 
111  curve->setSamples(x, y);
112 
113  m_Window->m_ImagePlot->setPlotCurveStyle(curveNumber++, curve);
114 
115  m_Window->appendCurve(curve);
116  }
117  }
118  }
119  } else if (mode == QcepDataObjectGraphWindow::VerticalSlice) {
120  m_Window -> m_ImagePlot -> setAxisTitle(QwtPlot::xBottom, tr("%1 (%2)")
121  .arg(data->get_VLabel()).arg(data->get_VUnits()));
122  m_Window -> m_ImagePlot -> setAxisTitle(QwtPlot::yLeft, "Intensity");
123 
124  int start = m_Window->get_SliceVStart();
125  int summed = m_Window->get_SliceVSummed();
126  int skipped = m_Window->get_SliceVSkipped();
127  int repeats = m_Window->get_SliceVRepeats();
128 
129  if (summed < 1) summed = 1;
130  if (skipped < 0) skipped = 0;
131  if (repeats < 1) repeats = 1;
132 
133  for (int rpt = 0; rpt<repeats; rpt++) {
134  int st = start+rpt*(summed+skipped);
135 
136  if (st < nCols) {
137  QVector<double> x,y;
138 
139  for (int row=0; row<nRows; row++) {
140  double s=0;
141  int n=0;
142 
143  for (int sum=0; sum<summed; sum++) {
144  int col=start+rpt*(summed+skipped)+sum;
145 
146  if (col < nCols) {
147  double v = data->getImageData(col, row);
148 
149  if (v==v) {
150  s += v;
151  n += 1;
152  }
153  }
154  }
155 
156  x.append(vStart+row*vStep);
157  y.append(s/n);
158  }
159 
160  if (x.count() > 0) {
161  int st = start+rpt*(summed+skipped);
162  int en = st+summed-1;
163 
164  if (en >= nCols) {
165  en = nCols-1;
166  }
167 
168  QwtPlotPiecewiseCurve *curve = NULL;
169 
170  if (st == en) {
171  curve = new QwtPlotPiecewiseCurve(m_Window->m_ImagePlot, tr("%1 = %2 %3")
172  .arg(data->get_HLabel())
173  .arg(hStart+st*hStep)
174  .arg(data->get_HUnits()));
175  } else {
176  curve = new QwtPlotPiecewiseCurve(m_Window->m_ImagePlot, tr("%1 = %2 to %3 %4")
177  .arg(data->get_HLabel())
178  .arg(hStart+st*hStep).arg(hStart+en*hStep)
179  .arg(data->get_HUnits()));
180  }
181 
182  curve->setSamples(x, y);
183 
184  m_Window->m_ImagePlot->setPlotCurveStyle(curveNumber++, curve);
185 
186  m_Window->appendCurve(curve);
187  }
188  }
189  }
190  }
191  }
192 
193  m_Window -> m_ImagePlot -> replot();
194 
196 }
QcepImageSliceGraphController(QcepDataObjectGraphWindow *window, int mode, QcepDataObjectWPtr object)
void appendCurve(QwtPlotCurve *curve)
virtual double getImageData(int x, int y) const =0
A class which draws piecewise curves.
QWeakPointer< QcepDataObject > QcepDataObjectWPtr