QXRD  0.11.16
qxrdslicedialog.cpp
Go to the documentation of this file.
1 #include "qxrdslicedialog.h"
2 #include "ui_qxrdslicedialog.h"
4 #include <QSettings>
5 #include "qcepsettingssaver.h"
6 #include "qxrddebug.h"
7 
9  QDockWidget(parent),
10  m_SliceDialogSettings(settings)
11 {
13  printf("QxrdSliceDialog::QxrdSliceDialog(%p)\n", this);
14  }
15 
16  setupUi(this);
17 
19 
20  if (set) {
21  m_SlicePlot->init(set->slicePlotSettings());
22  }
23 }
24 
26 {
28  printf("QxrdSliceDialog::~QxrdSliceDialog(%p)\n", this);
29  }
30 }
31 
33 {
34  m_Image = image;
35 
36  reslice();
37 }
38 
39 void QxrdSliceDialog::slicePolygon(QVector<QPointF> poly)
40 {
42 
43  if (set) {
44  set->set_SlicePolygon(poly);
45  }
46 
47  reslice();
48 }
49 
51 {
52  m_SlicePlot->detachItems(QwtPlotItem::Rtti_PlotCurve);
53  m_SlicePlot->detachItems(QwtPlotItem::Rtti_PlotMarker);
54 
56 
57  if (set && m_Image) {
58  QVector<double> xp,yp;
59  QString title = m_Image->get_Title();
60 
61  double length = 0;
62 
63  QcepPolygon poly = set->get_SlicePolygon();
64 
65  if (poly.size() >= 2) {
66  QPointF p0 = poly[0];
67 
68  for (int i=1; i<poly.size(); i++) {
69  QPointF p1 = poly[i];
70  double dx = p1.x() - p0.x();
71  double dy = p1.y() - p0.y();
72  length += sqrt(dx*dx + dy*dy);
73  p0=p1;
74  }
75 
76  p0 = poly[0];
77  double r = 0;
78  double r0 = 0;
79 
80  title += tr(" [%1,%2]").arg(p0.x()).arg(p0.y());
81 
82  for (int i=1; i<poly.size(); i++) {
83  QPointF p1 = poly[i];
84  double dx = p1.x() - p0.x();
85  double dy = p1.y() - p0.y();
86  double len = sqrt(dx*dx + dy*dy);
87 
88  if (len > 0) {
89  for (; r<len; r+=1) {
90  double x = p0.x() + r*dx/len;
91  double y = p0.y() + r*dy/len;
92 
93  xp.append(r+r0);
94  yp.append(m_Image->value((int) x, (int) y));
95  }
96  }
97 
98  p0 = p1;
99  r0 += len;
100  r -= len;
101  }
102 
103  if (poly.size() > 2) {
104  title += "...";
105  } else {
106  title += "-";
107  }
108 
109  QPointF p1 = poly.last();
110  title += tr("[%1,%2]").arg(p1.x()).arg(p1.y());
111 
112  QwtPlotCurve *pc = new QwtPlotPiecewiseCurve(m_SlicePlot, title);
113 
114  pc->setSamples(xp, yp);
115 
116  pc->attach(m_SlicePlot);
117 
118  m_SlicePlot->updateZoomer();
119  m_SlicePlot->replot();
120  }
121  }
122 }
QxrdSliceDialogSettingsWPtr m_SliceDialogSettings
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
void onProcessedImageAvailable(QcepDoubleImageDataPtr image, QcepMaskDataPtr overflow)
A class which draws piecewise curves.
QxrdSliceDialog(QxrdSliceDialogSettingsWPtr settings, QWidget *parent)
QVector< QPointF > QcepPolygon
Definition: qcepmacros.h:37
QWeakPointer< QxrdSliceDialogSettings > QxrdSliceDialogSettingsWPtr
QcepDoubleImageDataPtr m_Image
QSharedPointer< QcepMaskData > QcepMaskDataPtr
void slicePolygon(QVector< QPointF > poly)
QSharedPointer< QxrdSliceDialogSettings > QxrdSliceDialogSettingsPtr
virtual ~QxrdSliceDialog()
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr