QXRD  0.11.16
qxrdgeneratetestimage.cpp
Go to the documentation of this file.
2 
3 #define _USE_MATH_DEFINES
4 
5 #include <cmath>
6 
7 #include "qxrddataprocessor.h"
8 #include "qxrddetectorgeometry.h"
9 #include "qcepallocator.h"
10 #include "qcepsettingssaver.h"
11 
13  QcepObject("testImage", NULL),
14  m_Processor(),
15  m_Geometry(new QxrdDetectorGeometry("testGeometry", NULL)),
16  m_NRows(saver, this, "nRows", 2048, "Number of Rows"),
17  m_NCols(saver, this, "nCols", 2048, "Number of Cols"),
18  m_CenterX(saver, this, "centerX", 1024, "X Center"),
19  m_CenterY(saver, this, "centerY", 1024, "Y Center"),
20  m_Distance(saver, this, "distance", 1000, "Detector - Sample Distance (in mm)"),
21  m_Energy(saver, this, "energy", 22000, "Beam Energy (in eV)"),
22  m_PixelWidth(saver, this, "pixelWidth", 10, "Pixel Width (in um)"),
23  m_PixelHeight(saver, this, "pixelHeight", 10, "Pixel Height (in um)"),
24  m_Alpha(saver, this, "alpha", 0, "Alpha"),
25  m_Beta(saver, this, "beta", 0, "Beta"),
26  m_Gamma(saver, this, "gamma", 0, "Gamma"),
27  m_ChiMin(saver, this, "chiMin", 0, "Chi Min"),
28  m_ChiMax(saver, this, "chiMax", 360, "Chi Max"),
29  m_RingTTH(saver, this, "ringTTH", QcepDoubleList(), "TTH values of rings"),
30  m_RingIntensity(saver, this, "ringIntensity", QcepDoubleList(), "Intensities of rings"),
31  m_RingWidth(saver, this, "ringWidth", QcepDoubleList(), "Widths of Rings")
32 {
33 }
34 
36 {
37  m_Processor = proc;
38 }
39 
41 {
42  set_NRows(nr);
43  set_NCols(nc);
44 }
45 
46 void QxrdGenerateTestImage::setCenter(double cx, double cy)
47 {
48  set_CenterX(cx);
49  set_CenterY(cy);
50 }
51 
52 void QxrdGenerateTestImage::setDistance(double l, double pw, double ph)
53 {
54  set_Distance(l);
55  set_PixelWidth(pw);
56  set_PixelHeight(ph);
57 }
58 
60 {
61  set_Energy(energy);
62 }
63 
65 {
66  set_Alpha(alpha);
67  set_Beta(beta);
68  set_Gamma(gamma);
69 }
70 
72 {
73  set_ChiMin(chiMin);
74  set_ChiMax(chiMax);
75 }
76 
78 {
79  m_RingTTH.clear();
80  m_RingIntensity.clear();
81  m_RingWidth.clear();
82 }
83 
84 void QxrdGenerateTestImage::appendRing(double tth, double intensity, double width)
85 {
86  m_RingTTH.appendValue(tth);
87  m_RingIntensity.appendValue(intensity);
88  m_RingWidth.appendValue(width);
89 }
90 
92 {
94  get_NCols(),
95  get_NRows(),
96  0,
97  this));
98 
99  img->clear();
100 
101  int col, row, ncols = get_NCols(), nrows = get_NRows();
102 
103  double xc = get_CenterX();
104  double yc = get_CenterY();
105  double distance = get_Distance();
106  double pixWidth = get_PixelWidth();
107  double pixHeight = get_PixelHeight();
108  double alpha = get_Alpha();
109  double cos_alpha = cos(alpha*M_PI/180.0);
110  double sin_alpha = sin(alpha*M_PI/180.0);
111  double beta = get_Beta();
112  double cos_beta = cos(beta*M_PI/180.0);
113  double sin_beta = sin(beta*M_PI/180.0);
114  double rotation = get_Gamma();
115  double cos_rotation = cos(rotation*M_PI/180.0);
116  double sin_rotation = sin(rotation*M_PI/180.0);
117 
118  double twoTheta, chi;
119  double chiMin = get_ChiMin();
120  double chiMax = get_ChiMax();
121 
122  int nrings = get_RingTTH().length();
123 
124  for (row = 0; row < nrows; row++) {
125  for (col = 0; col < ncols; col++) {
126  m_Geometry -> getTwoThetaChi(xc,yc,distance,col,row,
127  pixWidth, pixHeight,
128  rotation, cos_beta, sin_beta,
129  cos_alpha, sin_alpha,
130  cos_rotation, sin_rotation,
131  &twoTheta, &chi);
132 
133  if (chiMin <= chi && chi <= chiMax) {
134  double sum = 0;
135 
136  for (int i = 0; i<nrings; i++) {
137  double ringTTH = get_RingTTH()[i];
138  double ringInt = get_RingIntensity()[i];
139  double ringWdt = get_RingWidth()[i];
140 
141  double nsigma = fabs((ringTTH-twoTheta)/ringWdt);
142 
143  if (nsigma < 5) {
144  sum += ringInt*exp(-nsigma*nsigma);
145  }
146  }
147 
148  img->setValue(col,row,sum);
149  }
150  }
151  }
152 
154 
155  if (proc) {
156  proc -> newData(img, QcepMaskDataPtr());
157  }
158 }
159 
161 {
163 
164  img->clear();
165 
166  int col, row, ncols = get_NCols(), nrows = get_NRows();
167 
168  double xc = get_CenterX();
169  double yc = get_CenterY();
170  double distance = get_Distance();
171  double pixWidth = get_PixelWidth();
172  double pixHeight = get_PixelHeight();
173  double alpha = get_Alpha();
174  double cos_alpha = cos(alpha*M_PI/180.0);
175  double sin_alpha = sin(alpha*M_PI/180.0);
176  double beta = get_Beta();
177  double cos_beta = cos(beta*M_PI/180.0);
178  double sin_beta = sin(beta*M_PI/180.0);
179  double rotation = get_Gamma();
180  double cos_rotation = cos(rotation*M_PI/180.0);
181  double sin_rotation = sin(rotation*M_PI/180.0);
182 
183  double twoTheta, chi;
184 
185  for (row = 0; row < nrows; row++) {
186  for (col = 0; col < ncols; col++) {
187  m_Geometry -> getTwoThetaChi(xc,yc,distance,col,row,
188  pixWidth, pixHeight,
189  rotation, cos_beta, sin_beta,
190  cos_alpha, sin_alpha,
191  cos_rotation, sin_rotation,
192  &twoTheta, &chi);
193 
194  img->setValue(col,row,twoTheta);
195  }
196  }
197 
199 
200  if (proc) {
201  proc -> newData(img, QcepMaskDataPtr());
202  }
203 }
204 
206 {
208 
209  img->clear();
210 
211  int col, row, ncols = get_NCols(), nrows = get_NRows();
212 
213  double xc = get_CenterX();
214  double yc = get_CenterY();
215  double distance = get_Distance();
216  double pixWidth = get_PixelWidth();
217  double pixHeight = get_PixelHeight();
218  double alpha = get_Alpha();
219  double cos_alpha = cos(alpha*M_PI/180.0);
220  double sin_alpha = sin(alpha*M_PI/180.0);
221  double beta = get_Beta();
222  double cos_beta = cos(beta*M_PI/180.0);
223  double sin_beta = sin(beta*M_PI/180.0);
224  double rotation = get_Gamma();
225  double cos_rotation = cos(rotation*M_PI/180.0);
226  double sin_rotation = sin(rotation*M_PI/180.0);
227 
228  double twoTheta, chi;
229 
230  for (row = 0; row < nrows; row++) {
231  for (col = 0; col < ncols; col++) {
232  m_Geometry -> getTwoThetaChi(xc,yc,distance,col,row,
233  pixWidth, pixHeight,
234  rotation, cos_beta, sin_beta,
235  cos_alpha, sin_alpha,
236  cos_rotation, sin_rotation,
237  &twoTheta, &chi);
238 
239  img->setValue(col,row,chi);
240  }
241  }
242 
244 
245  if (proc) {
246  proc -> newData(img, QcepMaskDataPtr());
247  }
248 }
QxrdDetectorGeometryPtr m_Geometry
QcepImageData< double > QcepDoubleImageData
QWeakPointer< QxrdDataProcessor > QxrdDataProcessorWPtr
void setDistance(double l, double pw, double ph)
QSharedPointer< QxrdDataProcessor > QxrdDataProcessorPtr
void setChiRange(double chiMin, double chiMax)
void appendRing(double tth, double intensity, double width)
void setProcessor(QxrdDataProcessorWPtr proc)
static QcepDoubleImageDataPtr newDoubleImage(AllocationStrategy strat, int width, int height, QcepObject *parent)
void setTiltAngles(double alpha, double beta, double gamma)
QxrdGenerateTestImage(QcepSettingsSaverWPtr saver)
void setDimension(int nc, int nr)
QList< double > QcepDoubleList
Definition: qcepmacros.h:28
void setEnergy(double energy)
QSharedPointer< QcepSettingsSaver > QcepSettingsSaverPtr
QxrdDataProcessorWPtr m_Processor
void setCenter(double cx, double cy)
QSharedPointer< QcepMaskData > QcepMaskDataPtr
QWeakPointer< QcepSettingsSaver > QcepSettingsSaverWPtr
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr