QXRD  0.11.16
qxrdcenterfinderplot.cpp
Go to the documentation of this file.
1 #include "qxrdcenterfinderplot.h"
2 #include "qcepimagedata.h"
3 #include "qcepmaskdata.h"
4 
5 #include <QPen>
6 #include <qwt_plot_curve.h>
7 #include <qwt_plot_picker.h>
8 #include <qwt_plot_zoomer.h>
9 #include <qwt_plot_panner.h>
10 #include <qwt_plot_magnifier.h>
11 #include <qwt_symbol.h>
12 #include <qwt_legend.h>
13 #include <QMetaMethod>
14 #include "qxrdwindow.h"
15 #include "qxrddataprocessor.h"
16 #include "qxrdcenterfinder.h"
17 #include "qcepplotmeasurer.h"
19 #include "qxrdapplication.h"
20 
22  : QcepPlot(parent),
23  m_ObjectNamer(this, "centeringGraph"),
24  m_Window(),
25  m_DataProcessor(),
26  m_CenterFinder(),
27  m_FirstTime(true)
28 {
29 }
30 
32 {
33  QcepPlot::init(settings);
34 
35  if (m_Legend) {
36  insertLegend(m_Legend, QwtPlot::RightLegend);
37  }
38 }
39 
41 {
42  m_Window = win;
43 
44  QxrdWindow *wp = m_Window;
45 
46  if (wp) {
47  m_DataProcessor = wp -> dataProcessor();
48  }
49 
51 
52  if (dp) {
53  m_CenterFinder = dp -> centerFinder();
54 
55  connect(m_Measurer, (void (QcepPlotMeasurer::*)( const QVector<QPointF> &)) &QcepPlotMeasurer::selected,
57 
59 
60  if (cf) {
62  }
63  }
64 }
65 
67 {
69 
70  if (cf) {
71  onCenterChanged(cf -> get_CenterX(), cf -> get_CenterY());
72  }
73 }
74 
76 {
78 
79  if (cf) {
80  onCenterChanged(cf -> get_CenterX(), cf -> get_CenterY());
81  }
82 }
83 
85 {
87 
88  if (cf) {
89  onCenterChanged(cf -> get_CenterX(), cf -> get_CenterY());
90  }
91 }
92 
94 {
96 
97  if (cf) {
98  onCenterChanged(cx, cf -> get_CenterY());
99  }
100 }
101 
103 {
105 
106  if (cf) {
107  onCenterChanged(cf -> get_CenterX(), cy);
108  }
109 }
110 
112 {
113  onCenterChanged(c.x(), c.y());
114 }
115 
116 void QxrdCenterFinderPlot::onCenterChanged(double cx, double cy)
117 {
118  QxrdWindow *wp = m_Window;
120 
121  if (wp && cf) {
122  try {
123  QcepDoubleImageDataPtr img = wp -> data();
124  QcepMaskDataPtr mask = wp -> mask();
125 
126  if (img /* && mask*/) {
127  int width =img->get_Width();
128  int height=img->get_Height();
129 
130  int len = (int) sqrt((double)(width*width+height*height));
131 
132  detachItems(QwtPlotItem::Rtti_PlotCurve);
133  detachItems(QwtPlotItem::Rtti_PlotMarker);
134 
135  QPen pen;
136 
137  for (double ang=0; ang<2*M_PI; ang+=M_PI/36) {
138  double x = cx, y = cy;
139  double dx = cos(ang);
140  double dy = sin(ang);
141  int nn=0;
142 
143  double distance = cf->get_DetectorDistance();
144 
145  if (distance <= 0) distance = 1000;
146 
147  double plx = cf->get_DetectorXPixelSize();
148  double ply = cf->get_DetectorYPixelSize();
149 
150  m_XData.resize(len);
151  m_YData.resize(len);
152 
153  if (cf->get_ImplementTilt()) {
154  double rot = cf->get_TiltPlaneRotation()*M_PI/180.0;
155  double sinrot = sin(rot);
156  double cosrot = cos(rot);
157  double beta = cf->get_DetectorTilt()*M_PI/180.0;
158  double sinbeta = sin(beta);
159  double cosbeta = cos(beta);
160 
161  for (int n = 0; n<=len; n++) {
162  double twoTheta = cf->getTwoTheta(cx,cy,distance,x,y,plx,ply,cosbeta,sinbeta,cosrot,sinrot);
163 
164  int ix = (int)qRound(x);
165  int iy = (int)qRound(y);
166 
167  if (ix >= 0 && iy >= 0 && ix < width && iy < height) {
168  double v = img->value(ix,iy);
169 
170  bool mv = true;
171 
172  if (mask) {
173  mv = mask->maskValue(ix,iy);
174  }
175 
176  if (mv) {
177  m_XData[nn] = twoTheta;
178  m_YData[nn] = v;
179 
180  nn++;
181  }
182  }
183 
184  x += dx;
185  y += dy;
186  }
187  } else {
188  for (int n = 0; n<=len; n++) {
189  double delx = (x - cx)*plx/1000.0;
190  double dely = (y - cy)*ply/1000.0;
191 
192  double radius = sqrt(delx*delx + dely*dely);
193  double twoTheta = atan2(radius, distance)*180.0/M_PI;
194 
195  int ix = (int)qRound(x);
196  int iy = (int)qRound(y);
197 
198  if (ix >= 0 && iy >= 0 && ix < width && iy < height) {
199  double v = img->value(ix,iy);
200 
201  bool mv = true;
202 
203  if (mask) {
204  mv = mask->maskValue(ix,iy);
205  }
206 
207  if (mv) {
208  m_XData[nn] = twoTheta;
209  m_YData[nn] = v;
210 
211  nn++;
212  }
213  }
214 
215  x += dx;
216  y += dy;
217  }
218  }
219 
220  m_XData.resize(nn);
221  m_YData.resize(nn);
222 
223  double angdeg = 180*(ang)/M_PI;
224 
225  QwtPlotCurve *pc = new QwtPlotPiecewiseCurve(this,QString("%1").arg(180*(ang)/M_PI));
226 
227  pc->setSamples(m_XData, m_YData);
228  // pc->setStyle(QwtPlotCurve::Dots);
229  pen.setColor(QColor::fromHsv((int) angdeg, 255, 255));
230 
231  QwtSymbol *s = new QwtSymbol();
232 
233  s->setStyle(QwtSymbol::Rect);
234  s->setSize(3,3);
235  s->setPen(pen);
236 
237  pc->setSymbol(s);
238  pc->setPen(pen);
239  pc->attach(this);
240  }
241 
242  QString title = QString("Center:%1:").arg(img->get_Title());
243  title += QString("(%1,%2):").arg(cx).arg(cy);
244 
245  setTitle(title);
246 
247  setAxisTitle(xBottom, "2Theta (deg)");
248 
249  if (m_Zoomer && m_Zoomer -> zoomRectIndex() == 0) {
250  m_Zoomer -> setZoomBase();
251  }
252 
253  if (m_FirstTime) {
254  autoScale();
255  m_FirstTime = false;
256  } else {
257  replot();
258  }
259  }
260  }
261 
262  catch(...) {
263  if (g_Application) {
264  g_Application->printMessage("QxrdCenterFinderPlot::onCenterChanged failed");
265  }
266  }
267  }
268 }
QSharedPointer< QxrdCenterFinder > QxrdCenterFinderPtr
QWeakPointer< QcepPlotSettings > QcepPlotSettingsWPtr
void onCenterYChanged(double cy)
void onCenterXChanged(double cx)
QSharedPointer< QxrdDataProcessor > QxrdDataProcessorPtr
QxrdCenterFinderPlot(QWidget *parent=0)
void init(QcepPlotSettingsWPtr settings)
QxrdCenterFinderWPtr m_CenterFinder
QwtLegend * m_Legend
Definition: qcepplot.h:58
virtual void autoScale()
Definition: qcepplot.cpp:188
QwtPlotZoomer * m_Zoomer
Definition: qcepplot.h:59
void printMeasuredPolygon(QVector< QPointF > poly)
void onCenterChanged(double cx, double cy)
A class which draws piecewise curves.
void init(QcepPlotSettingsWPtr settings)
Definition: qcepplot.cpp:36
void parameterChanged()
QVector< double > m_YData
void onMaskedImageAvailable(QcepDoubleImageDataPtr image, QcepMaskDataPtr mask)
QxrdDataProcessorWPtr m_DataProcessor
QcepPlotMeasurerPtr m_Measurer
Definition: qcepplot.h:62
QVector< double > m_XData
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QcepApplication * g_Application
QSharedPointer< QcepMaskData > QcepMaskDataPtr
void setWindow(QxrdWindow *win)
void onProcessedImageAvailable(QcepDoubleImageDataPtr image)
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr