cctw  0.2.1
cctwcrystalcoordinateparameters.cpp
Go to the documentation of this file.
2 #include "cctwdebug.h"
3 #include "cctwapplication.h"
4 
5 #if QT_VERSION >= 0x050000
6 #include <QUrlQuery>
7 #endif
8 
9 #include <QRegExp>
10 
12  CctwObject(name, parent),
13  m_TwoTheta(QcepSettingsSaverWPtr(), this, "twoTheta", "", "twoTheta spec"),
14  m_TwoThetaCorrection(QcepSettingsSaverWPtr(), this, "twoThetaCorrection", 0.0, "twoTheta correction"),
15  m_TwoThetaNom(QcepSettingsSaverWPtr(), this, "twoThetaNom", 0.0, "twoTheta nominal (start)"),
16  m_TwoThetaStep(QcepSettingsSaverWPtr(), this, "twoThetaStep", 0.0, "twoTheta step"),
17  m_TwoThetaAngles(QcepSettingsSaverWPtr(), this, "twoThetaAngles", QcepDoubleVector(), "twoTheta Angles"),
18 
19  m_Omega(QcepSettingsSaverWPtr(), this, "omega", "", "omega spec"),
20  m_OmegaCorrection(QcepSettingsSaverWPtr(), this, "omegaCorrection", 0.0, "omega correction"),
21  m_OmegaNom(QcepSettingsSaverWPtr(), this, "omegaNom", 0.0, "omega nominal (start)"),
22  m_OmegaStep(QcepSettingsSaverWPtr(), this, "omegaStep", 0.0, "omega step"),
23  m_OmegaAngles(QcepSettingsSaverWPtr(), this, "omegaAngles", QcepDoubleVector(), "omega Angles"),
24 
25  m_Chi(QcepSettingsSaverWPtr(), this, "chi", "", "chi spec"),
26  m_ChiCorrection(QcepSettingsSaverWPtr(), this, "chiCorrection", 0.0, "chi correction"),
27  m_ChiNom(QcepSettingsSaverWPtr(), this, "chiNom", 0.0, "chi nominal (start)"),
28  m_ChiStep(QcepSettingsSaverWPtr(), this, "chiStep", 0.0, "chi step"),
29  m_ChiAngles(QcepSettingsSaverWPtr(), this, "chiAngles", QcepDoubleVector(), "chi Angles"),
30 
31  m_Phi(QcepSettingsSaverWPtr(), this, "phi", "", "phi spec"),
32  m_PhiCorrection(QcepSettingsSaverWPtr(), this, "phiCorrection", 0.0, "phi correction"),
33  m_PhiNom(QcepSettingsSaverWPtr(), this, "phiNom", 0.0, "phi nominal (start)"),
34  m_PhiStep(QcepSettingsSaverWPtr(), this, "phiStep", 0.0, "phi step"),
35  m_PhiAngles(QcepSettingsSaverWPtr(), this, "phiAngles", QcepDoubleVector(), "phi Angles"),
36 
37  m_ExtraFlip(QcepSettingsSaverWPtr(), this, "extraFlip", 1, "Extra Flip on input x->(2048-y), y->(2048-x)")
38 {
39  setDefaults();
40 }
41 
43 {
44  setPixelSize(0.080567);
45  setWavelength(0.153870);
46  setDistance(365.97);
47 
48  setUnitCell(CctwUnitCell(4.04, 4.04, 4.04, 1.570796, 1.570796, 1.570796));
49 
50  setUBMat(CctwDoubleMatrix3x3(-0.001955, 0.177126, -0.172890,
51  -0.247516, -0.000885, 0.001892,
52  0.000736, 0.172899, 0.177127));
53 
54  setOMat(CctwDoubleMatrix3x3(0.0, -1.0, 0.0,
55  0.0, 0.0, 1.0,
56  -1.0, 0.0, 0.0));
57 
58  setDet0x(1041.266200);
59  setDet0y(989.624800);
60 
61  setXTrans(CctwDoubleVector3D(0.005277, -0.006373, 0.034958));
62 
63  setOrientErrorDetPitch(-0.014305);
64  setOrientErrorDetRoll(-0.008063);
65  setOrientErrorDetYaw(-0.000361);
66  setOrientErrorGonPitch(-0.000000);
67 
68  setGridOrigin(CctwDoubleVector3D(1.5, -0.5, 0.0));
69  setGridBasis(CctwDoubleMatrix3x3(1.0, 0.0, 0.0,
70  0.0, 0.5, 0.5,
71  0.0, 0.5, -0.5));
72  setGridDim(CctwDoubleVector3D(101,71,71));
73 
74  setGridOffset(CctwDoubleVector3D(1024,1024,1024));
75 
76  set_ExtraFlip(1);
77 }
78 
82 
87 
88 double CctwCrystalCoordinateParameters::det0x() const { return m_Det0x; }
89 double CctwCrystalCoordinateParameters::det0y() const { return m_Det0y; }
90 
92 
97 
102 
106 
111 
114 
116 
121 
123  set_TwoTheta(tth);
124 
125  parseAngleArgument(tth,"twoTheta", &m_TwoThetaCorrection, &m_TwoThetaNom, &m_TwoThetaStep, &m_TwoThetaAngles);
126 }
127 
129 {
130  return interpolateAngle(frame, &m_TwoThetaCorrection, &m_TwoThetaNom, &m_TwoThetaStep, &m_TwoThetaAngles);
131 }
132 
134  set_Omega(omg);
135 
136  parseAngleArgument(omg, "omega", &m_OmegaCorrection, &m_OmegaNom, &m_OmegaStep, &m_OmegaAngles);
137 }
138 
140 {
141  return interpolateAngle(frame, &m_OmegaCorrection, &m_OmegaNom, &m_OmegaStep, &m_OmegaAngles);
142 }
143 
145  set_Chi(chi);
146 
147  parseAngleArgument(chi, "chi", &m_ChiCorrection, &m_ChiNom, &m_ChiStep, &m_ChiAngles);
148 }
149 
151 {
152  return interpolateAngle(frame, &m_ChiCorrection, &m_ChiNom, &m_ChiStep, prop_ChiAngles());
153 }
154 
156  set_Phi(phi);
157 
158  parseAngleArgument(phi, "phi", &m_PhiCorrection, &m_PhiNom, &m_PhiStep, &m_PhiAngles);
159 }
160 
162 {
163  return interpolateAngle(frame, &m_PhiCorrection, &m_PhiNom, &m_PhiStep, &m_PhiAngles);
164 }
165 
170 
171 //void CctwCrystalCoordinateParameters::setExtraFlip(int extra) { m_ExtraFlip = extra; }
172 
174  const QString arg,
175  const QString angleName,
176  QcepDoubleProperty *corr,
177  QcepDoubleProperty *start,
178  QcepDoubleProperty *step,
179  QcepDoubleVectorProperty *angs)
180 {
181  QUrl url(arg);
182  QString fileName = "";
183  QString dataSetName = "";
184  QcepDoubleVector a;
185 
186  if (arg.length()) {
187 
188  if (qcepDebug(DEBUG_APP)) {
189  printMessage(tr("%1.parseAngleArgument(\"%2\")").arg(get_Name()).arg(CctwApplication::addSlashes(arg)));
190 
191  printMessage(tr("scheme: %1").arg(url.scheme()));
192  printMessage(tr("host: %1").arg(url.host()));
193  printMessage(tr("path: %1").arg(url.path()));
194  printMessage(tr("filename: %1").arg(url.fileName()));
195 #if QT_VERSION >= 0x050000
196  printMessage(tr("query: %1").arg(url.query()));
197 #endif
198  printMessage(tr("fragment: %1").arg(url.fragment()));
199  }
200 
201 #if QT_VERSION >= 0x050000
202  if (url.hasQuery()) {
203  QUrlQuery qry(url);
204 
205  QList <QPair <QString, QString> > l = qry.queryItems();
206 
207  QPair<QString, QString> v;
208  foreach (v, l) {
209  if (qcepDebug(DEBUG_APP)) {
210  printMessage(tr(" key: %1").arg(v.first));
211  printMessage(tr(" val: %1").arg(v.second));
212  }
213  }
214 
215  if (qry.hasQueryItem("start") && start) {
216  QString chunkSize = qry.queryItemValue("start");
217 
218  start->setValue(chunkSize.toDouble());
219  printMessage(tr("%1 start at %2").arg(angleName).arg(start->value()));
220  }
221 
222  if (qry.hasQueryItem("nom") && start) {
223  QString s = qry.queryItemValue("nom");
224 
225  start->setValue(s.toDouble());
226  printMessage(tr("%1 start At %2").arg(angleName).arg(start->value()));
227  }
228 
229  if (qry.hasQueryItem("step") && step) {
230  QString s = qry.queryItemValue("step");
231 
232  step->setValue(s.toDouble());
233  printMessage(tr("%1 step by %2").arg(angleName).arg(step->value()));
234  }
235  }
236  }
237 #endif
238 
239  QRegExp n1("[-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?");
240  QRegExp n2("([-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?),([-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?)");
241 
242  if (n1.exactMatch(arg)) { // One number...
243  if (start) {
244  start->setValue(arg.toDouble());
245  printMessage(tr("%1 angle = %2").arg(angleName).arg(start->value()));
246  }
247  } else if (n2.exactMatch(arg)) { // Two numbers...
248  if (qcepDebug(DEBUG_APP)) {
249  printMessage(tr("Matched two numbers : count %1").arg(n2.captureCount()));
250  }
251  if (start && n2.captureCount()==2) {
252  start->setValue(n2.cap(1).toDouble());
253  printMessage(tr("%1 start at %2").arg(angleName).arg(start->value()));
254  }
255  if (step && n2.captureCount()==2) {
256  step->setValue(n2.cap(2).toDouble());
257  printMessage(tr("%1 step by %2").arg(angleName).arg(step->value()));
258  }
259  } else if (url.path().length() >= 1){
260  fileName = url.path();
261  dataSetName = url.fragment();
262 
263  if (fileName.length() == 0) {
264  printMessage(tr("No filename given for %1 angles, skipping").arg(angleName));
265  }
266 
267  if (dataSetName.length() == 0) {
268  printMessage(tr("No dataset name given for %1 angles, skipping").arg(angleName));
269  }
270 
271  QFileInfo f(fileName);
272 
273  hid_t fileId = -1;
274  hid_t dsetId = -1;
275  hid_t dspcId = -1;
276 
277  try
278  {
279  if (!f.exists())
280  throw tr("%1 angles file %2 does not exist").arg(angleName).arg(fileName);
281 
282  if (H5Fis_hdf5(qPrintable(fileName)) <= 0)
283  throw tr("%1 angles file %2 exists but is not an hdf file").arg(angleName).arg(fileName);
284 
285  fileId = H5Fopen(qPrintable(fileName), H5F_ACC_RDONLY, H5P_DEFAULT);
286 
287  if (fileId < 0)
288  throw tr("%1 angles file %2 could not be opened").arg(angleName).arg(fileName);
289 
290  dsetId = H5Dopen(fileId, qPrintable(dataSetName), H5P_DEFAULT);
291 
292  if (dsetId <= 0)
293  throw tr("Could not open %1 angles dataset %2").arg(angleName).arg(dataSetName);
294 
295  dspcId = H5Dget_space(dsetId);
296 
297  if (dspcId < 0)
298  throw tr("Could not get dataspace of existing %1 angles dataset %2").arg(angleName).arg(dataSetName);
299 
300  hsize_t dims[3];
301  int ndims = H5Sget_simple_extent_ndims(dspcId);
302 
303  if (ndims != 1)
304  throw tr("%1 angles dataset %2, dataspace is not 1-dimensional").arg(angleName).arg(dataSetName);
305 
306  int ndims2 = H5Sget_simple_extent_dims(dspcId, dims, NULL);
307 
308  if (ndims2 != 1)
309  throw tr("Could not get %1 angles dataset %2 dimensions").arg(angleName).arg(dataSetName);
310 
311  if (angs == NULL)
312  throw tr("Angles argument not given");
313 
314  a.resize(dims[0]);
315 
316  hid_t memspace_id = -1;
317  hsize_t offset[1], count[1], stride[1], block[1];
318  offset[0] = 0;
319  count[0] = a.size();
320  stride[0] = 1;
321  block[0] = 1;
322 
323  double *angles = a.data();
324 
325  memspace_id = H5Screate_simple(1, count, NULL);
326 
327  herr_t selerr = H5Sselect_hyperslab(dspcId, H5S_SELECT_SET, offset, stride, count, block);
328 
329  if (selerr < 0)
330  throw tr("Error selecting hyperslab for %1 failed, selerr = %2").arg(angleName).arg(selerr);
331 
332  herr_t rderr = H5Dread(dsetId,
333  H5T_NATIVE_DOUBLE,
334  memspace_id,
335  dspcId, H5P_DEFAULT, angles);
336 
337  if (rderr < 0)
338  throw tr("Error reading %1 angles, rderr = %2").arg(angleName).arg(rderr);
339 
340  if (angs) {
341  angs->setValue(a);
342  }
343  }
344 
345  catch (QString &msg)
346  {
347  printMessage(msg);
348  }
349 
350  if (dspcId >= 0) H5Sclose(dspcId);
351  if (dsetId >= 0) H5Dclose(dsetId);
352  if (fileId >= 0) H5Fclose(fileId);
353  }
354 }
355 
357  QcepDoubleProperty *corr,
358  QcepDoubleProperty *start,
359  QcepDoubleProperty *step,
360  QcepDoubleVectorProperty *angs)
361 {
362  double res;
363 
364  QcepDoubleVector a;
365 
366  if (angs) a=angs->value();
367 
368  if (a.length() == 0) {
369  res = start->value() + frame*step->value() + corr->value();
370  } else {
371  int f0 = ::floor(frame);
372  int f1 = f0+1;
373  double df = frame-f0;
374 
375  res = corr->value() + a.value(f0)+df*(a.value(f1) - a.value(f0));
376  }
377 
378  return res;
379 }
CctwDoubleVector3D gridOrigin() const
static QString addSlashes(QString str)
CctwDoubleVector3D gridDim() const
CctwDoubleMatrix3x3 oMat() const
double interpolateAngle(double frame, QcepDoubleProperty *corr, QcepDoubleProperty *start, QcepDoubleProperty *step, QcepDoubleVectorProperty *angs)
CctwDoubleVector3D oVec() const
CctwCrystalCoordinateParameters(QString name, QObject *parent)
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
CctwDoubleVector3D xTrans() const
void parseAngleArgument(const QString arg, const QString angleName, QcepDoubleProperty *corr, QcepDoubleProperty *start, QcepDoubleProperty *step, QcepDoubleVectorProperty *angs)
CctwUnitCell unitCell() const
CctwDoubleMatrix3x3 ubMat() const
double orientErrorDetPitch() const
CctwMatrix3x3< double > CctwDoubleMatrix3x3
Definition: cctwmatrix3x3.h:59
CctwDoubleVector3D gridOffset() const
CctwDoubleMatrix3x3 gridBasis() const
CctwVector3D< double > CctwDoubleVector3D
Definition: cctwvector3d.h:71
double orientErrorDetRoll() const
double orientErrorGonPitch() const