cctw  0.2.1
cctwcrystalcoordinatetransform.cpp
Go to the documentation of this file.
2 #include <cmath>
3 
4 CctwCrystalCoordinateTransform::CctwCrystalCoordinateTransform(CctwCrystalCoordinateParameters *parms, QString name, const double *angles, QObject *parent) :
5  CctwTransformInterface(name, parent),
6  m_Parms(parms),
7  m_CurrentFrame(-1),
8  m_CurrentFrameChangeCount(0),
9  m_Angles(angles)
10 {
12 }
13 
15 {
17  m_TwoThetaAngle = m_Parms->twoThetaAngle(0.0); // + m_Parms->twoThetaCorrection();
18  m_PhiAngle = m_Parms->phiAngle(0.0); // + m_Parms->phiCorrection();
19  m_ChiAngle = m_Parms->chiAngle(0.0); // + m_Parms->chiCorrection();
20 
22 
23  m_OMat = m_Parms->oMat();
25  m_OVec = m_Parms->oVec();
26 
28 
31 
34 }
35 
37 {
38  if (frame != m_CurrentFrame) {
39  m_CurrentFrame = frame;
40 
43  m_PhiAngle = m_Parms->phiAngle(frame);
44  m_ChiAngle = m_Parms->chiAngle(frame);
45 
46  // if (m_Angles == NULL) {
47 // m_OmegaAngle = frame*m_Parms->omegaStep() + m_Parms->omegaCorrection();
48 // } else {
49 // int f0 = ::floor(frame);
50 // int f1 = f0+1;
51 // double df = frame-f0;
52 // m_OmegaAngle = m_Angles[f0]+df*(m_Angles[f1]-m_Angles[f0]);
53 // }
54 
56 
62 
63  m_DMatInv = dimat;
64  m_DMat = dimat.inverted();
65 
67 
72 
73  m_GMat = gmat;
74  m_GMatInv = gmat.inverted();
75 
76  CctwDoubleVector3D cD(m_Parms->distance(), 0, 0);
79  CctwDoubleVector3D tVec = m_GMat*m_Parms->xTrans();
80 
81  cD = tVec - cD;
82 
83  CctwDoubleVector3D nD(dimat(0,0), dimat(1,0), dimat(2,0));
84 
85  m_CD = cD;
86  m_ND = nD;
87 
89  }
90 }
91 
93 {
95 }
96 
98 {
99 // printMessage(tr("CctwqtCrystalCoordinateParameters - wavelength() = %1")
100 // .arg(m_QTParms->wavelength()));
101 
102 // printMessage(tr("CctwCrystalCoordinateParameters::m_Wavelength = %1")
103 // .arg(((CctwCrystalCoordinateParameters*) m_QTParms)->m_Wavelength));
104 }
105 
107 {
108  double alat = cell.a();
109  double blat = cell.b();
110  double clat = cell.c();
111  double alpha = cell.alpha();
112  double beta = cell.beta();
113  double gamma = cell.gamma();
114 
116 
117  zzz(0,0) = alat;
118  zzz(1,0) = 0;
119  zzz(2,0) = 0;
120 
121  zzz(0,1) = blat*cos(gamma);
122  zzz(1,1) = blat*sin(gamma);
123  zzz(2,1) = 0;
124 
125  zzz(0,2) = clat*cos(beta);
126  zzz(1,2) = clat*(cos(alpha) - cos(beta)*cos(gamma))/sin(gamma);
127  zzz(2,2) = sqrt(clat*clat - zzz(0,2)*zzz(0,2) - zzz(1,2)*zzz(1,2));
128 
129  CctwDoubleMatrix3x3 tmat = zzz.inverted();
130 
131  return tmat.transposed();
132 }
133 
135 {
136  return false;
137 }
138 
140 {
141  setCurrentFrame(d.z());
142 
143  return hkl2grid(qlab2hkl(pixel2qlab(getDetPos(d.x(), d.y()))));
144 }
145 
147 {
148  return CctwDoubleVector3D();
149 }
150 
152 {
153  return getDetPos(xyz.x(), xyz.y());
154 }
155 
157 {
158  double pixelSize = m_Parms->pixelSize();
159 
160  if (m_Parms->get_ExtraFlip()) {
161  return CctwDoubleVector3D(((2048-y)+0.5 - m_Parms->det0x())*pixelSize,
162  ((2048-x)+0.5 - m_Parms->det0y())*pixelSize, 0.0);
163  } else {
164  return CctwDoubleVector3D((x+0.5 - m_Parms->det0x())*pixelSize,
165  (y+0.5 - m_Parms->det0y())*pixelSize, 0.0);
166  }
167 }
168 
170 {
171  return pixel2qlab(CctwDoubleVector3D(x,y,z));
172 }
173 
175 {
176  CctwDoubleVector3D xyz = pixel;
177  double scale = 1.0/m_Parms->wavelength();
178 
179  xyz = m_OMatInv*xyz;
180  xyz = xyz - m_OVec;
181 
182  xyz = m_DMatInv*xyz;
183  xyz = xyz - m_CD;
184  xyz = xyz.normalized();
185  xyz = xyz*scale;
186 
187  xyz.x() -= scale;
188 
189  xyz = m_GMatInv*xyz;
190 
191  return xyz;
192 }
193 
195 {
196  return qlab2hkl(CctwDoubleVector3D(qx,qy,qz));
197 }
198 
200 {
201  return m_UBMatInv*qlab;
202 }
203 
205 {
206  return hkl2grid(CctwDoubleVector3D(h,k,l));
207 }
208 
210 {
211  CctwDoubleVector3D xyz = hkl;
212 
213  xyz = xyz - m_Parms->gridOrigin();
214  xyz = m_GridBasisInv*xyz;
215 
216  for (int i=0; i<3; i++) {
217  xyz(i) *= qMax(m_Parms->gridDim()(i),0.0);
218  }
219 
220  return xyz+m_Parms->gridOffset();
221 }
222 
224 {
225  return grid2hkl(CctwDoubleVector3D(gx,gy,gz));
226 }
227 
229 {
230  CctwDoubleVector3D xyz = grid - m_Parms->gridOffset();
231 
232  for (int i=0; i<3; i++) {
233  xyz(i) /= qMax(m_Parms->gridDim()(i),0.0);
234  }
235 
236  xyz = m_Parms->gridBasis()*xyz;
237  xyz = xyz + m_Parms->gridOrigin();
238 
239  return xyz;
240 }
241 
243 {
244  return hkl2qlab(CctwDoubleVector3D(h,k,l));
245 }
246 
248 {
249  return m_Parms->ubMat()*hkl;
250 }
251 
253 {
254  return qlab2pixel(CctwDoubleVector3D(qx,qy,qz));
255 }
256 
258 {
259  CctwDoubleVector3D xyz = qlab;
260 
261  xyz = m_GMat*xyz;
262  xyz(0) += 1.0/m_Parms->wavelength();
263  xyz = xyz.normalized();
264 
266  double cosang = CctwDoubleVector3D::dotProduct(xyz, m_ND);
267 
268  double pdist = -dmin/cosang;
269 
270  xyz = xyz*pdist;
271 
272  xyz = xyz + m_CD;
273 
274  xyz = m_DMat*xyz;
275 
276  xyz = xyz + m_OVec;
277 
278  xyz = m_OMat*xyz;
279 
280  return xyz;
281 }
282 
284 {
285  return getDetPix(CctwDoubleVector3D(x,y,z));
286 }
287 
289 {
290  CctwDoubleVector3D detpix;
291 
292  detpix.x() = (int)(xyz.x()/m_Parms->pixelSize() + m_Parms->det0x() - 0.5);
293  detpix.y() = (int)(xyz.y()/m_Parms->pixelSize() + m_Parms->det0y() - 0.5);
294 
295  if (m_Parms->get_ExtraFlip()) {
296  double x = detpix.x();
297  double y = detpix.y();
298 
299  detpix.x() = 2048-y;
300  detpix.y() = 2048-x;
301  }
302 
303  return detpix;
304 }
CctwCrystalCoordinateParameters * m_Parms
CctwDoubleMatrix3x3 createBMatrix(const CctwUnitCell &cell) const
static CctwMatrix3x3 rotZ(double r)
CctwDoubleVector3D hkl2grid(double h, double k, double l)
static CctwMatrix3x3 rotX(double r)
static CctwMatrix3x3 rotY(double r)
double beta() const
CctwDoubleVector3D getDetPos(double x, double y)
double b() const
CctwDoubleVector3D pixel2qlab(double x, double y, double z)
double a() const
double alpha() const
T x() const
Definition: cctwvector3d.h:17
CctwDoubleVector3D hkl2qlab(double h, double k, double l)
CctwMatrix3x3 transposed() const
T z() const
Definition: cctwvector3d.h:19
CctwDoubleVector3D qlab2pixel(double qx, double qy, double qz)
CctwDoubleVector3D grid2hkl(double gx, double gy, double gz)
static double dotProduct(const CctwVector3D< double > &v1, const CctwVector3D< double > &v2)
virtual CctwDoubleVector3D forward(CctwDoubleVector3D d)
CctwVector3D< T > normalized() const
virtual CctwDoubleVector3D inverse(CctwDoubleVector3D q)
double gamma() const
CctwMatrix3x3 inverted(bool *invertible=NULL) const
static CctwMatrix3x3 identity()
double c() const
CctwCrystalCoordinateTransform(CctwCrystalCoordinateParameters *parms, QString name, const double *angles, QObject *parent)
T y() const
Definition: cctwvector3d.h:18
CctwVector3D< double > CctwDoubleVector3D
Definition: cctwvector3d.h:71
CctwDoubleVector3D qlab2hkl(double qx, double qy, double qz)
CctwDoubleVector3D getDetPix(double x, double y, double z)