QXRD  0.11.16
qxrdcenterfinder.h
Go to the documentation of this file.
1 #ifndef QXRDCENTERFINDER_H
2 #define QXRDCENTERFINDER_H
3 
4 #include "qcepmacros.h"
5 
6 #include <QObject>
7 #include <QPen>
8 #include "qcepproperty.h"
9 #include "qxrddetectorgeometry.h"
10 #include "qcepsettingssaver-ptr.h"
11 #include "qxrddataprocessor-ptr.h"
12 #include "qcepimagedata-ptr.h"
13 #include "qcepimagedata.h"
14 #include "qxrdexperiment-ptr.h"
15 #include <QScriptValue>
17 #include "qxrdcenterfinder-ptr.h"
18 
20 {
21  Q_OBJECT
22 
23 public:
25  virtual ~QxrdCenterFinder();
26 
27 public:
28  Q_PROPERTY(double centerX READ get_CenterX WRITE set_CenterX)
29  QCEP_DOUBLE_PROPERTY(CenterX)
30 
31  Q_PROPERTY(double centerY READ get_CenterY WRITE set_CenterY)
32  QCEP_DOUBLE_PROPERTY(CenterY)
33 
34  Q_PROPERTY(double centerStep READ get_CenterStep WRITE set_CenterStep)
35  QCEP_DOUBLE_PROPERTY(CenterStep)
36 
37  Q_PROPERTY(double detectorXPixelSize READ get_DetectorXPixelSize WRITE set_DetectorXPixelSize)
38  QCEP_DOUBLE_PROPERTY(DetectorXPixelSize)
39 
40  Q_PROPERTY(double detectorYPixelSize READ get_DetectorYPixelSize WRITE set_DetectorYPixelSize)
41  QCEP_DOUBLE_PROPERTY(DetectorYPixelSize)
42 
43  Q_PROPERTY(double detectorDistance READ get_DetectorDistance WRITE set_DetectorDistance)
44  QCEP_DOUBLE_PROPERTY(DetectorDistance)
45 
46  Q_PROPERTY(double detectorDistanceStep READ get_DetectorDistanceStep WRITE set_DetectorDistanceStep)
47  QCEP_DOUBLE_PROPERTY(DetectorDistanceStep)
48 
49  Q_PROPERTY(double energy READ get_Energy WRITE set_Energy)
50  QCEP_DOUBLE_PROPERTY(Energy)
51 
52  Q_PROPERTY(bool implementTilt READ get_ImplementTilt WRITE set_ImplementTilt)
53  QCEP_BOOLEAN_PROPERTY(ImplementTilt)
54 
55  Q_PROPERTY(double detectorTilt READ get_DetectorTilt WRITE set_DetectorTilt)
56  QCEP_DOUBLE_PROPERTY(DetectorTilt)
57 
58  Q_PROPERTY(double detectorTiltStep READ get_DetectorTiltStep WRITE set_DetectorTiltStep)
59  QCEP_DOUBLE_PROPERTY(DetectorTiltStep)
60 
61  Q_PROPERTY(double tiltPlaneRotation READ get_TiltPlaneRotation WRITE set_TiltPlaneRotation)
62  QCEP_DOUBLE_PROPERTY(TiltPlaneRotation)
63 
64  Q_PROPERTY(double tiltPlaneRotationStep READ get_TiltPlaneRotationStep WRITE set_TiltPlaneRotationStep)
65  QCEP_DOUBLE_PROPERTY(TiltPlaneRotationStep)
66 
67  Q_PROPERTY(QxrdPowderPointVector markedPoints READ get_MarkedPoints WRITE set_MarkedPoints)
69 
70  Q_PROPERTY(QxrdPowderPointVector fittedRings READ get_FittedRings WRITE set_FittedRings)
72 
73  Q_PROPERTY(double ringRadius READ get_RingRadius WRITE set_RingRadius)
74  QCEP_DOUBLE_PROPERTY(RingRadius)
75 
76  Q_PROPERTY(double ringRadiusA READ get_RingRadiusA WRITE set_RingRadiusA)
77  QCEP_DOUBLE_PROPERTY(RingRadiusA)
78 
79  Q_PROPERTY(double ringRadiusB READ get_RingRadiusB WRITE set_RingRadiusB)
80  QCEP_DOUBLE_PROPERTY(RingRadiusB)
81 
82  Q_PROPERTY(double ringRotation READ get_RingRotation WRITE set_RingRotation)
83  QCEP_DOUBLE_PROPERTY(RingRotation)
84 
85  Q_PROPERTY(double peakFitRadius READ get_PeakFitRadius WRITE set_PeakFitRadius)
86  QCEP_DOUBLE_PROPERTY(PeakFitRadius)
87 
88  Q_PROPERTY(double peakHeight READ get_PeakHeight WRITE set_PeakHeight)
89  QCEP_DOUBLE_PROPERTY(PeakHeight)
90 
91  Q_PROPERTY(double peakCenterX READ get_PeakCenterX WRITE set_PeakCenterX)
92  QCEP_DOUBLE_PROPERTY(PeakCenterX)
93 
94  Q_PROPERTY(double peakCenterY READ get_PeakCenterY WRITE set_PeakCenterY)
95  QCEP_DOUBLE_PROPERTY(PeakCenterY)
96 
97  Q_PROPERTY(double peakWidth READ get_PeakWidth WRITE set_PeakWidth)
98  QCEP_DOUBLE_PROPERTY(PeakWidth)
99 
100  Q_PROPERTY(double peakBackground READ get_PeakBackground WRITE set_PeakBackground)
101  QCEP_DOUBLE_PROPERTY(PeakBackground)
102 
103  Q_PROPERTY(double peakBackgroundX READ get_PeakBackgroundX WRITE set_PeakBackgroundX)
104  QCEP_DOUBLE_PROPERTY(PeakBackgroundX)
105 
106  Q_PROPERTY(double peakBackgroundY READ get_PeakBackgroundY WRITE set_PeakBackgroundY)
107  QCEP_DOUBLE_PROPERTY(PeakBackgroundY)
108 
109  Q_PROPERTY(bool peakFitDebug READ get_PeakFitDebug WRITE set_PeakFitDebug)
110  QCEP_BOOLEAN_PROPERTY(PeakFitDebug)
111 
112  Q_PROPERTY(int peakFitIterations READ get_PeakFitIterations WRITE set_PeakFitIterations)
113  QCEP_INTEGER_PROPERTY(PeakFitIterations)
114 
115  Q_PROPERTY(QcepDoubleVector ringAngles READ get_RingAngles WRITE set_RingAngles)
116  QCEP_DOUBLE_VECTOR_PROPERTY(RingAngles)
117 
118  Q_PROPERTY(double ringAngleTolerance READ get_RingAngleTolerance WRITE set_RingAngleTolerance)
119  QCEP_DOUBLE_PROPERTY(RingAngleTolerance)
120 
121  Q_PROPERTY(int powderFitOptions READ get_PowderFitOptions WRITE set_PowderFitOptions)
122  QCEP_INTEGER_PROPERTY(PowderFitOptions)
123 
124  Q_PROPERTY(int ringIndex READ get_RingIndex WRITE set_RingIndex)
125  QCEP_INTEGER_PROPERTY(RingIndex)
126 
127  Q_PROPERTY(bool subtractRingAverages READ get_SubtractRingAverages WRITE set_SubtractRingAverages)
128  QCEP_BOOLEAN_PROPERTY(SubtractRingAverages)
129 
130  Q_PROPERTY(double ringAverageDisplacement READ get_RingAverageDisplacement WRITE set_RingAverageDisplacement)
131  QCEP_DOUBLE_PROPERTY(RingAverageDisplacement)
132 
133  Q_PROPERTY(double fittedWidthMin READ get_FittedWidthMin WRITE set_FittedWidthMin)
134  QCEP_DOUBLE_PROPERTY(FittedWidthMin)
135 
136  Q_PROPERTY(double fittedWidthMax READ get_FittedWidthMax WRITE set_FittedWidthMax)
137  QCEP_DOUBLE_PROPERTY(FittedWidthMax)
138 
139  Q_PROPERTY(double fittedHeightMinRatio READ get_FittedHeightMinRatio WRITE set_FittedHeightMinRatio)
140  QCEP_DOUBLE_PROPERTY(FittedHeightMinRatio)
141 
142  Q_PROPERTY(double fittedPositionMaxDistance READ get_FittedPositionMaxDistance WRITE set_FittedPositionMaxDistance)
143  QCEP_DOUBLE_PROPERTY(FittedPositionMaxDistance)
144 
145  Q_PROPERTY(bool fitPowderPointPosition READ get_FitPowderPointPosition WRITE set_FitPowderPointPosition)
146  QCEP_BOOLEAN_PROPERTY(FitPowderPointPosition)
147 
148 public:
149  enum {
156 
157 //public slots:
158 // void onCenterXChanged(double cx);
159 // void onCenterYChanged(double cy);
160 // void onCenterChanged(QPointF pt);
161 // void onCenterChanged(QPointF pt);
162 // void onCenterStepChanged(double stp);
163 
164 signals:
165  void parameterChanged();
166 
167 public slots:
168  void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const;
169  void statusMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const;
170 
171  void onCenterChanged(QPointF pt);
172  void onPointSelected(QPointF pt);
173 
174  double getTTH(double x, double y) const;
175  double getTTH(QPointF pt) const;
176 
177  double getQ(double x, double y) const;
178  double getQ(QPointF pt) const;
179 
180  double getR(double x, double y) const;
181  double getR(QPointF pt) const;
182 
183  double getChi(double x, double y) const;
184  double getChi(QPointF pt) const;
185 
186  double getDist(double x, double y) const;
187  double getDist(QPointF pt) const;
188 
189  QPointF getXY(double tth, double chi);
190 
191  void fitPowderCircle(int n=0);
192  void fitPowderEllipse(int n=0);
193  void fitPowderEllipses();
194 
195  void adjustEnergy(int n);
196  void adjustDistance(int n);
197 
198  void deletePowderPointNear(double x, double y);
199  void deletePowderPoints();
200  void deletePowderRing(int n);
201  void disablePowderRing(int n);
202  void enablePowderRing(int n);
203  void appendPowderPoint(double x, double y);
204  void appendPowderPoint(int n1, int n2, int n3, double x, double y, double r1=0, double r2=0, double az=0);
205  void normalizePowderRings();
206 
208  int nearestPowderPointIndex(double x, double y);
209  QxrdPowderPoint nearestPowderPoint(double x, double y);
210 
211  bool fitPeakNear(double x, double y);
212  bool fitRingNear(double x0, double y0);
213  bool traceRingNear(double x0, double y0, double step=25.0);
214 // bool traceRingNearParallel(double x0, double y0, double step=25.0);
215  bool missingRingNear(double x, double y);
216 
217  int getPowderPointN1(int i);
218  int getPowderPointN2(int i);
219  double getPowderPointX(int i);
220  double getPowderPointY(int i);
221  void setPowderPoint(int i, int n1, int n2, int n3, double x, double y, double r1, double r2, double az);
222 
223  QScriptValue getPowderPoint(int i);
224  QScriptValue getPowderPoints();
225  void setPowderPoint(int i, QScriptValue val);
226 
227  int countPowderRings() const;
228  int countPowderRingPoints() const;
229  int countPowderRingPoints(int r) const;
230  QxrdPowderPoint powderRingPoint(int i) const;
231  QxrdPowderPoint powderRingPoint(int r, int i) const;
232 
233  double powderRingAverageR(int r) const;
234  double powderRingAverageTTH(int r) const;
235  double powderRingAverageQ(int r) const;
236 
237 // void updateCalibrantDSpacings();
238  double calibrantDSpacing(int n);
239  double calibrantTTH(int n);
240 
241  void calculateCalibration();
242 
243 public:
244  void readSettings(QSettings *settings, QString section);
245  void writeSettings(QSettings *settings, QString section);
246 
247  static QScriptValue toScriptValue(QScriptEngine *engine, const QxrdCenterFinderPtr &proc);
248  static void fromScriptValue(const QScriptValue &obj, QxrdCenterFinderPtr &proc);
249 
251  double imageValue(double x, double y);
252 
256 
257  static QString levmarFailureReason(int n);
258 
259 private:
260  mutable QMutex m_Mutex;
264 };
265 
266 
267 #endif // QXRDCENTERFINDER_H
double getChi(double x, double y) const
virtual ~QxrdCenterFinder()
QSharedPointer< QxrdCenterFinder > QxrdCenterFinderPtr
double getTTH(double x, double y) const
double ringAverageDisplacement
void disablePowderRing(int n)
QcepDoubleImageDataPtr data() const
int countPowderRingPoints() const
void fitPowderCircle(int n=0)
double getQ(double x, double y) const
void adjustDistance(int n)
#define QCEP_DOUBLE_PROPERTY(propname)
Definition: qcepproperty.h:629
double getR(double x, double y) const
int countPowderRings() const
#define QCEP_DOUBLE_VECTOR_PROPERTY(propname)
Definition: qcepproperty.h:839
void setData(QcepDoubleImageDataPtr data)
double calibrantDSpacing(int n)
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
QWeakPointer< QxrdExperiment > QxrdExperimentWPtr
static QString levmarFailureReason(int n)
bool traceRingNear(double x0, double y0, double step=25.0)
void onPointSelected(QPointF pt)
void writeSettings(QSettings *settings, QString section)
QScriptValue getPowderPoint(int i)
static void fromScriptValue(const QScriptValue &obj, QxrdCenterFinderPtr &proc)
QVector< double > QcepDoubleVector
Definition: qcepmacros.h:19
QScriptValue getPowderPoints()
double powderRingAverageQ(int r) const
#define QCEP_INTEGER_PROPERTY(propname)
Definition: qcepproperty.h:698
bool missingRingNear(double x, double y)
QxrdPowderPointVector markedPoints
double getPowderPointY(int i)
static QScriptValue toScriptValue(QScriptEngine *engine, const QxrdCenterFinderPtr &proc)
QPointF getXY(double tth, double chi)
double powderRingAverageTTH(int r) const
bool fitPeakNear(double x, double y)
double tiltPlaneRotationStep
QxrdCenterFinder(QcepSettingsSaverWPtr saver, QxrdExperimentWPtr expt)
void setPowderPoint(int i, int n1, int n2, int n3, double x, double y, double r1, double r2, double az)
QcepDoubleImageDataPtr m_Data
double calibrantTTH(int n)
QxrdPowderPoint nearestPowderPoint(double x, double y)
void readSettings(QSettings *settings, QString section)
void onCenterChanged(QPointF pt)
QcepDoubleVector ringAngles
void parameterChanged()
QxrdPowderPoint powderRingPoint(int i) const
QxrdExperimentWPtr m_Experiment
double fittedPositionMaxDistance
bool fitRingNear(double x0, double y0)
#define QCEP_BOOLEAN_PROPERTY(propname)
Definition: qcepproperty.h:732
void adjustEnergy(int n)
QxrdExperimentWPtr experiment() const
void deletePowderRing(int n)
double powderRingAverageR(int r) const
double getDist(double x, double y) const
void statusMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
QxrdPowderPoint powderPoint(int i)
int nearestPowderPointIndex(double x, double y)
void enablePowderRing(int n)
#define QXRD_POWDERPOINTVECTOR_PROPERTY(propname)
QxrdPowderPointVector fittedRings
void appendPowderPoint(double x, double y)
void deletePowderPointNear(double x, double y)
double imageValue(double x, double y)
double getPowderPointX(int i)
void fitPowderEllipse(int n=0)
QWeakPointer< QcepSettingsSaver > QcepSettingsSaverWPtr
QcepDoubleImageDataPtr newData()
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr
enum QxrdCenterFinder::@5 UserAbsorptionKinds