QXRD  0.11.16
Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Public Attributes | Properties | Private Attributes | List of all members
QxrdCenterFinder Class Reference

#include <qxrdcenterfinder.h>

Inheritance diagram for QxrdCenterFinder:
Inheritance graph
[legend]
Collaboration diagram for QxrdCenterFinder:
Collaboration graph
[legend]

Public Types

enum  {
  UserAbsorptionNone = 0, UserAbsorptionPixelCoords = 1, UserAbsorptionFromCenter = 2, UserAbsorptionRChi = 3,
  UserAbsorptionQChi = 4
}
 

Public Slots

void printMessage (QString msg, QDateTime ts=QDateTime::currentDateTime()) const
 
void statusMessage (QString msg, QDateTime ts=QDateTime::currentDateTime()) const
 
void onCenterChanged (QPointF pt)
 
void onPointSelected (QPointF pt)
 
double getTTH (double x, double y) const
 
double getTTH (QPointF pt) const
 
double getQ (double x, double y) const
 
double getQ (QPointF pt) const
 
double getR (double x, double y) const
 
double getR (QPointF pt) const
 
double getChi (double x, double y) const
 
double getChi (QPointF pt) const
 
double getDist (double x, double y) const
 
double getDist (QPointF pt) const
 
QPointF getXY (double tth, double chi)
 
void fitPowderCircle (int n=0)
 
void fitPowderEllipse (int n=0)
 
void fitPowderEllipses ()
 
void adjustEnergy (int n)
 
void adjustDistance (int n)
 
void deletePowderPointNear (double x, double y)
 
void deletePowderPoints ()
 
void deletePowderRing (int n)
 
void disablePowderRing (int n)
 
void enablePowderRing (int n)
 
void appendPowderPoint (double x, double y)
 
void appendPowderPoint (int n1, int n2, int n3, double x, double y, double r1=0, double r2=0, double az=0)
 
void normalizePowderRings ()
 
QxrdPowderPoint powderPoint (int i)
 
int nearestPowderPointIndex (double x, double y)
 
QxrdPowderPoint nearestPowderPoint (double x, double y)
 
bool fitPeakNear (double x, double y)
 
bool fitRingNear (double x0, double y0)
 
bool traceRingNear (double x0, double y0, double step=25.0)
 
bool missingRingNear (double x, double y)
 
int getPowderPointN1 (int i)
 
int getPowderPointN2 (int i)
 
double getPowderPointX (int i)
 
double getPowderPointY (int i)
 
void setPowderPoint (int i, int n1, int n2, int n3, double x, double y, double r1, double r2, double az)
 
QScriptValue getPowderPoint (int i)
 
QScriptValue getPowderPoints ()
 
void setPowderPoint (int i, QScriptValue val)
 
int countPowderRings () const
 
int countPowderRingPoints () const
 
int countPowderRingPoints (int r) const
 
QxrdPowderPoint powderRingPoint (int i) const
 
QxrdPowderPoint powderRingPoint (int r, int i) const
 
double powderRingAverageR (int r) const
 
double powderRingAverageTTH (int r) const
 
double powderRingAverageQ (int r) const
 
double calibrantDSpacing (int n)
 
double calibrantTTH (int n)
 
void calculateCalibration ()
 
- Public Slots inherited from QxrdDetectorGeometry
static double convertEnergyToWavelength (double energy)
 
static double convertWavelengthToEnergy (double wavelength)
 
static double convertTwoThetaToQ (double twoTheta, double wavelength)
 
static double convertQToTwoTheta (double Q, double wavelength)
 
static double getRadius (double xCenter, double yCenter, double distance, double xPixel, double yPixel, double pixelLength, double pixelHeight, double cos_beta, double sin_beta, double cos_rotation, double sin_rotation)
 
static double getTwoTheta (double xCenter, double yCenter, double distance, double xPixel, double yPixel, double pixelLength, double pixelHeight, double cos_beta, double sin_beta, double cos_rotation, double sin_rotation)
 
static void getTwoThetaChi (double xCenter, double yCenter, double distance, double xPixel, double yPixel, double pixelLength, double pixelHeight, double rotation, double cos_beta, double sin_beta, double cos_alpha, double sin_alpha, double cos_rotation, double sin_rotation, double *twoTheta, double *chi)
 
static void getQChi (double xCenter, double yCenter, double distance, double energy, double xPixel, double yPixel, double pixelLength, double pixelHeight, double rotation, double cos_beta, double sin_beta, double cos_alpha, double sin_alpha, double cos_rotation, double sin_rotation, double *q, double *chi)
 
static void getXY (double xCenter, double yCenter, double distance, double energy, double q, double chi, double pixelLength, double pixelHeight, double rotation, double cos_beta, double sin_beta, double cos_alpha, double sin_alpha, double cos_rotation, double sin_rotation, double *xPixel, double *yPixel)
 
- Public Slots inherited from QcepObject
virtual void printLine (QString line)
 
virtual void printMessage (QString msg, QDateTime dt=QDateTime::currentDateTime()) const
 
virtual void criticalMessage (QString msg, QDateTime ts=QDateTime::currentDateTime()) const
 
virtual void statusMessage (QString msg, QDateTime ts=QDateTime::currentDateTime()) const
 
virtual QString settingsScript ()
 
QString scriptValueLiteral (QVariant v)
 

Signals

void parameterChanged ()
 

Public Member Functions

 QxrdCenterFinder (QcepSettingsSaverWPtr saver, QxrdExperimentWPtr expt)
 
virtual ~QxrdCenterFinder ()
 
void readSettings (QSettings *settings, QString section)
 
void writeSettings (QSettings *settings, QString section)
 
void setData (QcepDoubleImageDataPtr data)
 
double imageValue (double x, double y)
 
QxrdExperimentWPtr experiment () const
 
QcepDoubleImageDataPtr data () const
 
QcepDoubleImageDataPtr newData ()
 
- Public Member Functions inherited from QxrdDetectorGeometry
 QxrdDetectorGeometry (QString name, QcepObject *parent)
 
- Public Member Functions inherited from QcepObject
 QcepObject (QString name, QcepObject *parent)
 
virtual ~QcepObject ()
 
QString get_Name () const
 
void set_Name (QString name)
 

Static Public Member Functions

static QScriptValue toScriptValue (QScriptEngine *engine, const QxrdCenterFinderPtr &proc)
 
static void fromScriptValue (const QScriptValue &obj, QxrdCenterFinderPtr &proc)
 
static QString levmarFailureReason (int n)
 
- Static Public Member Functions inherited from QcepObject
static int allocatedObjects ()
 
static int deletedObjects ()
 
static QSet< QcepObject * > allocatedObjectsSet ()
 
static QString addSlashes (QString str)
 

Public Attributes

enum QxrdCenterFinder:: { ... }  UserAbsorptionKinds
 

Properties

double centerX
 
double centerY
 
double centerStep
 
double detectorXPixelSize
 
double detectorYPixelSize
 
double detectorDistance
 
double detectorDistanceStep
 
double energy
 
bool implementTilt
 
double detectorTilt
 
double detectorTiltStep
 
double tiltPlaneRotation
 
double tiltPlaneRotationStep
 
QxrdPowderPointVector markedPoints
 
QxrdPowderPointVector fittedRings
 
double ringRadius
 
double ringRadiusA
 
double ringRadiusB
 
double ringRotation
 
double peakFitRadius
 
double peakHeight
 
double peakCenterX
 
double peakCenterY
 
double peakWidth
 
double peakBackground
 
double peakBackgroundX
 
double peakBackgroundY
 
bool peakFitDebug
 
int peakFitIterations
 
QcepDoubleVector ringAngles
 
double ringAngleTolerance
 
int powderFitOptions
 
int ringIndex
 
bool subtractRingAverages
 
double ringAverageDisplacement
 
double fittedWidthMin
 
double fittedWidthMax
 
double fittedHeightMinRatio
 
double fittedPositionMaxDistance
 
bool fitPowderPointPosition
 
- Properties inherited from QcepObject
QString name
 

Private Attributes

QMutex m_Mutex
 
QxrdExperimentWPtr m_Experiment
 
QcepDoubleImageDataPtr m_Data
 
int m_CenterFitRingNumber
 

Detailed Description

Definition at line 19 of file qxrdcenterfinder.h.

Member Enumeration Documentation

anonymous enum
Enumerator
UserAbsorptionNone 
UserAbsorptionPixelCoords 
UserAbsorptionFromCenter 
UserAbsorptionRChi 
UserAbsorptionQChi 

Definition at line 149 of file qxrdcenterfinder.h.

Constructor & Destructor Documentation

QxrdCenterFinder::QxrdCenterFinder ( QcepSettingsSaverWPtr  saver,
QxrdExperimentWPtr  expt 
)

Definition at line 31 of file qxrdcenterfinder.cpp.

References parameterChanged(), QcepDoubleProperty::valueChanged(), and QcepBoolProperty::valueChanged().

32  : QxrdDetectorGeometry("centering", NULL),
33  m_CenterX(saver, this, "centerX", 0, "X Center"),
34  m_CenterY(saver, this, "centerY", 0, "Y Center"),
35  m_CenterStep(saver, this, "centerStep", 1, "Center Step"),
36  m_DetectorXPixelSize(saver, this, "detectorXPixelSize", 200, "Detector X Pixels (um)"),
37  m_DetectorYPixelSize(saver, this, "detectorYPixelSize", 200, "Detector Y Pixels (um)"),
38  m_DetectorDistance(saver, this, "detectorDistance", 1000, "Sample-Detector Distance (mm)"),
39  m_DetectorDistanceStep(saver, this, "detectorDistanceStep", 100, "Sample-Detector Distance Step (mm)"),
40  m_Energy(saver, this, "energy", 20000, "Beam Energy (eV)"),
41  m_ImplementTilt(saver, this,"implementTilt", false, "Implement Detector Tilt?"),
42  m_DetectorTilt(saver, this, "detectorTilt", 0, "Tilt Angle (deg)"),
43  m_DetectorTiltStep(saver, this, "detectorTiltStep", 0.1, "Tilt Angle Step(deg)"),
44  m_TiltPlaneRotation(saver, this, "tiltPlaneRotation", 90, "Tilt Plane Rotation (deg)"),
45  m_TiltPlaneRotationStep(saver, this, "tiltPlaneRotationStep", 10, "Tilt Plane Rotation Step (deg)"),
46  m_MarkedPoints(saver, this, "markedPoints", QxrdPowderPointVector(), "Marker Points"),
47  m_FittedRings(saver, this, "fittedRings", QxrdPowderPointVector(), "Fitted Powder Rings"),
48  m_RingRadius(saver, this, "ringRadius", 0.0, "Estimated Powder Ring Radius"),
49  m_RingRadiusA(saver, this, "ringRadiusA", 0.0, "Estimated Powder Ellipse Major Axis Radius"),
50  m_RingRadiusB(saver, this, "ringRadiusB", 0.0, "Estimated Powder Ellipse Minor Axis Radius"),
51  m_RingRotation(saver, this, "ringRotation", 0.0, "Estimated Powder Ellipse Major Axis Rotation"),
52  m_PeakFitRadius(saver, this, "peakFitRadius", 10, "Half size of fitted area for peak fitting"),
53  m_PeakHeight(saver, this, "peakHeight", 100.0, "Height of fitted peak"),
54  m_PeakCenterX(saver, this, "peakCenterX", 0, "X Center of fitted peak"),
55  m_PeakCenterY(saver, this, "peakCenterY", 0, "Y Center of fitted peak"),
56  m_PeakWidth(saver, this, "peakWidth", 2.0, "Width of fitted peak"),
57  m_PeakBackground(saver, this, "peakBackground", 0, "Background Height of fitted peak"),
58  m_PeakBackgroundX(saver, this, "peakBackgroundX", 0, "X Slope of Background"),
59  m_PeakBackgroundY(saver, this, "peakBackgroundY", 0, "Y Slope of Background"),
60  m_PeakFitDebug(saver, this, "peakFitDebug", false, "Debug Print for peak fitting"),
61  m_PeakFitIterations(saver, this, "peakFitIterations", 200, "Max Iterations during fitting"),
62  m_RingAngles(saver, this, "ringAngles", QcepDoubleVector(), "Diffraction ring angles"),
63  m_RingAngleTolerance(saver, this, "ringAngleTolerance", 0.1, "Diffraction ring angle tolerance"),
64  m_PowderFitOptions(saver, this, "powderFitOptions", 0, "Powder fitting options"),
65  m_RingIndex(saver, this, "ringIndex", 0, "Fitted Powder Ring Index"),
66  m_SubtractRingAverages(saver, this, "subtractRingAverages", false, "Plot deviations of each ring from average"),
67  m_RingAverageDisplacement(saver, this, "ringAverageDisplacement", 0.0, "Extra displacement between curves in ring radius plot"),
68  m_FittedWidthMin(saver, this, "fittedWidthMin", 0.5, "Minimum acceptable fitted width (pixels)"),
69  m_FittedWidthMax(saver, this, "fittedWidthMax", 3.0, "Maximum acceptable fitted width (pixels)"),
70  m_FittedHeightMinRatio(saver, this, "fittedHeightMinRatio", 0.25, "Minimum acceptable peak height ratio"),
71  m_FittedPositionMaxDistance(saver, this, "fittedPositionMaxDistance", 2.0, "Maximum acceptable fitted position shift (pixels)"),
72  m_FitPowderPointPosition(saver, this, "fitPowderPointPosition", true, "Fit to nearby peak when adding powder points individually"),
73  m_Experiment(expt)
74 {
75  qRegisterMetaType<QPointF>("QPointF");
76 
77 // m_CenterX.setDebug(true);
78 // m_CenterY.setDebug(true);
79 
80  connect(prop_CenterX(), &QcepDoubleProperty::valueChanged, this, &QxrdCenterFinder::parameterChanged, Qt::DirectConnection);
81  connect(prop_CenterY(), &QcepDoubleProperty::valueChanged, this, &QxrdCenterFinder::parameterChanged, Qt::DirectConnection);
82  connect(prop_DetectorXPixelSize(), &QcepDoubleProperty::valueChanged, this, &QxrdCenterFinder::parameterChanged, Qt::DirectConnection);
83  connect(prop_DetectorYPixelSize(), &QcepDoubleProperty::valueChanged, this, &QxrdCenterFinder::parameterChanged, Qt::DirectConnection);
84  connect(prop_DetectorDistance(), &QcepDoubleProperty::valueChanged, this, &QxrdCenterFinder::parameterChanged, Qt::DirectConnection);
85  connect(prop_Energy(), &QcepDoubleProperty::valueChanged, this, &QxrdCenterFinder::parameterChanged, Qt::DirectConnection);
86  connect(prop_ImplementTilt(), &QcepBoolProperty::valueChanged, this, &QxrdCenterFinder::parameterChanged, Qt::DirectConnection);
87  connect(prop_DetectorTilt(), &QcepDoubleProperty::valueChanged, this, &QxrdCenterFinder::parameterChanged, Qt::DirectConnection);
88  connect(prop_TiltPlaneRotation(), &QcepDoubleProperty::valueChanged, this, &QxrdCenterFinder::parameterChanged, Qt::DirectConnection);
89 }
QxrdDetectorGeometry(QString name, QcepObject *parent)
QVector< double > QcepDoubleVector
Definition: qcepmacros.h:19
void parameterChanged()
QxrdExperimentWPtr m_Experiment
void valueChanged(double val, int index)
void valueChanged(bool val, int index)
QxrdCenterFinder::~QxrdCenterFinder ( )
virtual

Definition at line 91 of file qxrdcenterfinder.cpp.

92 {
93 #ifndef QT_NO_DEBUG
94  printf("Deleting center finder\n");
95 #endif
96 }

Member Function Documentation

void QxrdCenterFinder::adjustDistance ( int  n)
slot

Definition at line 468 of file qxrdcenterfinder.cpp.

References calibrantTTH(), and powderRingAverageR().

469 {
470  double r = powderRingAverageR(n);
471  double tth = calibrantTTH(n);
472  double d = r/tan(tth*M_PI/180.0);
473 
474  QString message;
475 
476  message.append(tr("Ring %1 average radius = %2\n").arg(n).arg(r));
477  message.append(tr("Calibrant Peak %1 TTH = %2\n").arg(n).arg(tth));
478  message.append(tr("Adjust sample - detector distance from %1 to %2\n")
479  .arg(get_DetectorDistance()).arg(d));
480  message.append(tr("to improve fit to ring %1").arg(n));
481 
482  if (QMessageBox::question(NULL, "Update Detector Distance?",
483  message, QMessageBox::Ok | QMessageBox::No, QMessageBox::Ok)
484  == QMessageBox::Ok) {
485  set_DetectorDistance(d);
486  }
487 }
double calibrantTTH(int n)
double powderRingAverageR(int r) const

Here is the call graph for this function:

void QxrdCenterFinder::adjustEnergy ( int  n)
slot

Definition at line 444 of file qxrdcenterfinder.cpp.

References calibrantDSpacing(), calibrantTTH(), and powderRingAverageTTH().

445 {
446  double tth = powderRingAverageTTH(n);
447  double th = tth/2.0;
448  double dlatt = calibrantDSpacing(n);
449  double caltth = calibrantTTH(n);
450 
451  double newLambda = 2.0*dlatt*sin(th*M_PI/180.0);
452  double newEnergy = 12398.4187/newLambda;
453 
454  QString message;
455 
456  message.append(tr("Ring %1 average TTH = %2\n").arg(n).arg(tth));
457  message.append(tr("Calibrant Peak %1 TTH = %2\n").arg(n).arg(caltth));
458  message.append(tr("Adjust Energy from %1 to %2\n").arg(get_Energy()).arg(newEnergy));
459  message.append(tr("to improve fit to ring %1").arg(n));
460 
461  if (QMessageBox::question(NULL, "Update Energy?",
462  message, QMessageBox::Ok | QMessageBox::No, QMessageBox::Ok)
463  == QMessageBox::Ok) {
464  set_Energy(newEnergy);
465  }
466 }
double calibrantDSpacing(int n)
double powderRingAverageTTH(int r) const
double calibrantTTH(int n)

Here is the call graph for this function:

void QxrdCenterFinder::appendPowderPoint ( double  x,
double  y 
)
slot

Definition at line 531 of file qxrdcenterfinder.cpp.

Referenced by fitPeakNear(), fitRingNear(), missingRingNear(), and onPointSelected().

532 {
533  m_MarkedPoints.appendValue(QxrdPowderPoint(get_RingIndex(), 0, 0, x,y, 0,0,0));
534 }

Here is the caller graph for this function:

void QxrdCenterFinder::appendPowderPoint ( int  n1,
int  n2,
int  n3,
double  x,
double  y,
double  r1 = 0,
double  r2 = 0,
double  az = 0 
)
slot

Definition at line 536 of file qxrdcenterfinder.cpp.

537 {
538  m_MarkedPoints.appendValue(QxrdPowderPoint(n1,n2,n3, x, y, r1, r2, az));
539 }
void QxrdCenterFinder::calculateCalibration ( )
slot

Definition at line 1435 of file qxrdcenterfinder.cpp.

References QxrdPlaneFitter::addPoint(), calibrantTTH(), compareXYX(), countPowderRingPoints(), differentVertices(), getTTH(), QxrdPowderPoint::isValid(), m_Experiment, QxrdPowderPoint::n1(), nearby(), newData(), powderPoint(), printMessage(), Triangulate(), QxrdPlaneFitter::value(), XYZ::x, QxrdPowderPoint::x(), XYZ::y, QxrdPowderPoint::y(), and XYZ::z.

Referenced by QxrdWindow::initialize().

1436 {
1437  printMessage("centering.calculateCalibration()");
1439 
1440  if (expt) {
1441  QxrdDataProcessorPtr proc(expt->dataProcessor());
1442 
1443  if (proc) {
1445  res -> fill(nan(""));
1446 
1447  int wd = res->get_Width();
1448  int ht = res->get_Height();
1449 
1450  QxrdPlaneFitter f00, f01, f10, f11;
1451 
1452  int np = countPowderRingPoints();
1453 
1454  QVector<XYZ> verts;
1455 
1456  for (int i=0; i<np; i++) {
1457  QxrdPowderPoint pt = powderPoint(i);
1458 
1459  if (pt.isValid()) {
1460  double x = pt.x();
1461  double y = pt.y();
1462  double tth = getTTH(x, y);
1463  double tthNom = calibrantTTH(pt.n1());
1464  double disp = get_DetectorDistance()*(tan(tth*M_PI/180.0)/tan(tthNom*M_PI/180.0)-1.0);
1465 
1466  XYZ p;
1467  p.x = x;
1468  p.y = y;
1469  p.z = disp;
1470  verts.append(p);
1471 
1472  if (nearby(x,y,0,0)) {
1473  f00.addPoint(x,y,disp);
1474  }
1475 
1476  if (nearby(x,y,0,ht)) {
1477  f01.addPoint(x,y,disp);
1478  }
1479 
1480  if (nearby(x,y,wd,0)) {
1481  f10.addPoint(x,y,disp);
1482  }
1483 
1484  if (nearby(x,y,wd,ht)) {
1485  f11.addPoint(x,y,disp);
1486  }
1487  }
1488  }
1489 
1490  XYZ pc;
1491 
1492  pc.x = 0; pc.y = 0; pc.z = f00.value(0,0); verts.append(pc); printMessage(tr("appended (%1,%2,%3)").arg(pc.x).arg(pc.y).arg(pc.z));
1493  pc.x = 0; pc.y = ht; pc.z = f01.value(0,ht); verts.append(pc); printMessage(tr("appended (%1,%2,%3)").arg(pc.x).arg(pc.y).arg(pc.z));
1494  pc.x = wd; pc.y = 0; pc.z = f10.value(wd,0); verts.append(pc); printMessage(tr("appended (%1,%2,%3)").arg(pc.x).arg(pc.y).arg(pc.z));
1495  pc.x = wd; pc.y = ht; pc.z = f11.value(wd,ht); verts.append(pc); printMessage(tr("appended (%1,%2,%3)").arg(pc.x).arg(pc.y).arg(pc.z));
1496 
1497  XYZ p = {0,0,0};
1498 
1499  std::sort(verts.begin(), verts.end(), compareXYX);
1500 
1501  int n = verts.count();
1502 
1503  QVector<XYZ> uniq;
1504 
1505  for (int i=0; i<n; i++) {
1506  if (i==0 || differentVertices(verts[i], verts[i-1])) {
1507  uniq.append(verts[i]);
1508  }
1509  }
1510 
1511  int drop = verts.count() - uniq.count();
1512 
1513  if (drop > 0) {
1514  printMessage(tr("Dropped %1 duplicated vertices").arg(drop));
1515  }
1516 
1517  n = uniq.count();
1518 
1519  uniq.append(p);
1520  uniq.append(p);
1521  uniq.append(p);
1522 
1523  QVector<ITRIANGLE> tris(n*3);
1524 
1525  int ntri = 0;
1526 
1527  Triangulate(n, uniq.data(), tris.data(), &ntri);
1528 
1529  printMessage(tr("Formed %1 triangles").arg(ntri));
1530 
1531  int ndup = 0, nMsg = 0;
1532 
1533  for (int i=0; i<ntri; i++) {
1534  int p1 = tris[i].p1;
1535  int p2 = tris[i].p2;
1536  int p3 = tris[i].p3;
1537 
1538  // printMessage(tr("%1: (%2,%3) - (%4,%5) - (%6,%7)")
1539  // .arg(i)
1540  // .arg(uniq[p1].x).arg(uniq[p1].y)
1541  // .arg(uniq[p2].x).arg(uniq[p2].y)
1542  // .arg(uniq[p3].x).arg(uniq[p3].y)
1543  // );
1544 
1545  double x1 = uniq[p1].x;
1546  double x2 = uniq[p2].x;
1547  double x3 = uniq[p3].x;
1548  double y1 = uniq[p1].y;
1549  double y2 = uniq[p2].y;
1550  double y3 = uniq[p3].y;
1551  double z1 = uniq[p1].z;
1552  double z2 = uniq[p2].z;
1553  double z3 = uniq[p3].z;
1554 
1555  double minX = qMax((double) 0,floor(qMin(qMin(x1,x2),x3)));
1556  double maxX = qMin((double) wd,ceil(qMax(qMax(x1,x2),x3)));
1557  double minY = qMax((double) 0,floor(qMin(qMin(y1,y2),y3)));
1558  double maxY = qMin((double) ht,ceil(qMax(qMax(y1,y2),y3)));
1559 
1560  double detT = (y2 - y3)*(x1 - x3) + (x3 - x2)*(y1 - y3);
1561 
1562  int ndupt = 0;
1563  int nptst = 0;
1564 
1565  for (double y=minY; y<=maxY; y++) {
1566  for (double x=minX; x<=maxX; x++) {
1567  double l1 = ((y2 - y3)*(x - x3) + (x3 - x2)*(y - y3))/detT;
1568  double l2 = ((y3 - y1)*(x - x3) + (x1 - x3)*(y - y3))/detT;
1569  double l3 = 1 - l1 - l2;
1570 
1571  if (0 < l1 && l1 < 1.0 &&
1572  0 < l2 && l2 < 1.0 &&
1573  0 < l3 && l3 < 1.0) {
1574  double z = l1*z1 + l2*z2 + l3*z3;
1575 
1576  double val = res->getImageData(x,y);
1577 
1578  if (val == val) {
1579  ndup += 1;
1580  ndupt += 1;
1581  res -> setImageData(x,y, i);
1582  } else {
1583  res -> setImageData(x,y, z);
1584  }
1585 
1586  nptst += 1;
1587  }
1588  }
1589  }
1590 
1591  if (ndupt > 0 && nMsg++ < 50) {
1592  printMessage(tr("Triangle %1 : (%2,%3) - (%4,%5) - (%6,%7) : %8/%9 dups")
1593  .arg(i)
1594  .arg(uniq[p1].x).arg(uniq[p1].y)
1595  .arg(uniq[p2].x).arg(uniq[p2].y)
1596  .arg(uniq[p3].x).arg(uniq[p3].y)
1597  .arg(ndupt).arg(nptst));
1598  }
1599  }
1600 
1601  int nunset = 0;
1602 
1603  for (int y=0; y<ht; y++) {
1604  for (int x=0; x<wd; x++) {
1605  double val = res->getImageData(x,y);
1606 
1607  if (val!=val) {
1608  nunset += 1;
1609  }
1610  }
1611  }
1612 
1613  for (int y=0; y<ht; y+=ht-1) {
1614  for (int x=0; x<wd; x+=wd-1) {
1615  double val = res->getImageData(x,y);
1616 
1617  if (val!=val) {
1618  printMessage(tr("[%1,%2] unset").arg(x).arg(y));
1619  }
1620  }
1621  }
1622 
1623  printMessage(tr("%1 duplicated points, %2 unset pixels").arg(ndup).arg(nunset));
1624  proc->newData(res, QcepMaskDataPtr());
1625  }
1626  }
1627 }
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
double y() const
double getTTH(double x, double y) const
int countPowderRingPoints() const
static int nearby(double x1, double y1, double x2, double y2)
void addPoint(double x, double y, double z)
QSharedPointer< QxrdDataProcessor > QxrdDataProcessorPtr
int Triangulate(int nv, XYZ *pxyz, ITRIANGLE *v, int *ntri)
Definition: triangulate.c:41
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
double x
Definition: triangulate.c:14
static int differentVertices(const XYZ &a, const XYZ &b)
double z
Definition: triangulate.c:14
double calibrantTTH(int n)
QxrdExperimentWPtr m_Experiment
bool isValid() const
double x() const
double y
Definition: triangulate.c:14
int n1() const
static int compareXYX(const XYZ &a, const XYZ &b)
QxrdPowderPoint powderPoint(int i)
QSharedPointer< QcepMaskData > QcepMaskDataPtr
QcepDoubleImageDataPtr newData()
double value(double x, double y)
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr

Here is the call graph for this function:

Here is the caller graph for this function:

double QxrdCenterFinder::calibrantDSpacing ( int  n)
slot

Definition at line 1370 of file qxrdcenterfinder.cpp.

References m_Experiment.

Referenced by adjustEnergy().

1371 {
1372  double res = qQNaN();
1373 
1375 
1376  if (expt) {
1377  QxrdCalibrantDSpacingsPtr dsp(expt->calibrantDSpacings());
1378 
1379  if (dsp) {
1380  res = dsp->calibrantDSpacing(n);
1381  }
1382  }
1383 
1384  return res;
1385 }
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
QSharedPointer< QxrdCalibrantDSpacings > QxrdCalibrantDSpacingsPtr
QxrdExperimentWPtr m_Experiment

Here is the caller graph for this function:

double QxrdCenterFinder::calibrantTTH ( int  n)
slot

Definition at line 1387 of file qxrdcenterfinder.cpp.

References m_Experiment.

Referenced by adjustDistance(), adjustEnergy(), and calculateCalibration().

1388 {
1389  double res = qQNaN();
1390 
1392 
1393  if (expt) {
1394  QxrdCalibrantDSpacingsPtr dsp(expt->calibrantDSpacings());
1395 
1396  if (dsp) {
1397  res = dsp->calibrantTTH(n);
1398  }
1399  }
1400 
1401  return res;
1402 }
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
QSharedPointer< QxrdCalibrantDSpacings > QxrdCalibrantDSpacingsPtr
QxrdExperimentWPtr m_Experiment

Here is the caller graph for this function:

int QxrdCenterFinder::countPowderRingPoints ( ) const
slot

Definition at line 1192 of file qxrdcenterfinder.cpp.

Referenced by calculateCalibration(), QxrdFitterRingEllipse::fit(), and QxrdFitterRingCircle::fit().

1193 {
1194  return get_MarkedPoints().count();
1195 }

Here is the caller graph for this function:

int QxrdCenterFinder::countPowderRingPoints ( int  r) const
slot

Definition at line 1197 of file qxrdcenterfinder.cpp.

References QxrdPowderPoint::n1().

1198 {
1199  QxrdPowderPointVector pts = get_MarkedPoints();
1200 
1201  int sum = 0;
1202 
1203  foreach (QxrdPowderPoint pt, pts) {
1204  if (pt.n1() == r || r < 0) {
1205  sum += 1;
1206  }
1207  }
1208 
1209  return sum;
1210 }
int n1() const

Here is the call graph for this function:

int QxrdCenterFinder::countPowderRings ( ) const
slot

Definition at line 1169 of file qxrdcenterfinder.cpp.

References QxrdPowderPoint::n1().

Referenced by fitPowderEllipses().

1170 {
1171  int max = -1;
1172 
1173  QxrdPowderPointVector pts = get_MarkedPoints();
1174 
1175  int n = pts.count();
1176 
1177  for (int i=0; i<n; i++) {
1178  QxrdPowderPoint pt = pts.value(i);
1179 
1180  if (pt.n1()>max) {
1181  max = pt.n1();
1182  }
1183  }
1184 
1185  if (max>1000) {
1186  return 1000;
1187  } else {
1188  return max+1;
1189  }
1190 }
int n1() const

Here is the call graph for this function:

Here is the caller graph for this function:

QcepDoubleImageDataPtr QxrdCenterFinder::data ( ) const

Definition at line 103 of file qxrdcenterfinder.cpp.

References m_Data.

Referenced by QxrdFitterPeakPoint::fit(), QxrdFitterRingPoint::fit(), setData(), and traceRingNear().

104 {
105  return m_Data;
106 }
QcepDoubleImageDataPtr m_Data

Here is the caller graph for this function:

void QxrdCenterFinder::deletePowderPointNear ( double  x,
double  y 
)
slot

Definition at line 518 of file qxrdcenterfinder.cpp.

References nearestPowderPointIndex().

519 {
520  int nearest = nearestPowderPointIndex(x, y);
521 
522  if (nearest >= 0) {
523  QxrdPowderPointVector pts = get_MarkedPoints();
524 
525  pts.remove(nearest);
526 
527  set_MarkedPoints(pts);
528  }
529 }
int nearestPowderPointIndex(double x, double y)

Here is the call graph for this function:

void QxrdCenterFinder::deletePowderPoints ( )
slot

Definition at line 593 of file qxrdcenterfinder.cpp.

Referenced by QxrdWindow::initialize().

594 {
595  m_MarkedPoints.clear();
596 
597  set_RingIndex(0);
598 }

Here is the caller graph for this function:

void QxrdCenterFinder::deletePowderRing ( int  n)
slot

Definition at line 541 of file qxrdcenterfinder.cpp.

References QxrdPowderPoint::az(), QxrdPowderPoint::n1(), QxrdPowderPoint::n2(), QxrdPowderPoint::n3(), QxrdPowderPoint::r1(), QxrdPowderPoint::r2(), QxrdPowderPoint::x(), and QxrdPowderPoint::y().

542 {
543  QxrdPowderPointVector pts = get_MarkedPoints();
544 
546 
547  foreach (QxrdPowderPoint pt, pts) {
548  if (pt.n1() < n) {
549  res.append(pt);
550  } else if (pt.n1() > n) {
551  res.append(QxrdPowderPoint(pt.n1()-1, pt.n2(), pt.n3(), pt.x(), pt.y(), pt.r1(), pt.r2(), pt.az()));
552  }
553  }
554 
555  set_MarkedPoints(res);
556 }
double y() const
double az() const
int n2() const
double r2() const
int n3() const
double x() const
int n1() const
double r1() const

Here is the call graph for this function:

void QxrdCenterFinder::disablePowderRing ( int  n)
slot

Definition at line 558 of file qxrdcenterfinder.cpp.

References printMessage().

559 {
560  QxrdPowderPointVector pts = get_MarkedPoints();
561 
562  int np = 0;
563 
564  for (int i=0; i<pts.count(); i++) {
565  if (pts[i].n1() == n) {
566  pts[i].n2() = -1;
567  np++;
568  }
569  }
570 
571  printMessage(tr("Disabled %1 points in ring %2").arg(np).arg(n));
572 
573  set_MarkedPoints(pts);
574 }
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const

Here is the call graph for this function:

void QxrdCenterFinder::enablePowderRing ( int  n)
slot

Definition at line 576 of file qxrdcenterfinder.cpp.

References printMessage().

577 {
578  QxrdPowderPointVector pts = get_MarkedPoints();
579 
580  int np=0;
581 
582  for (int i=0; i<pts.count(); i++) {
583  if (pts[i].n1() == n) {
584  pts[i].n2() = np++;
585  }
586  }
587 
588  printMessage(tr("Enabled %1 points in ring %2").arg(np).arg(n));
589 
590  set_MarkedPoints(pts);
591 }
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const

Here is the call graph for this function:

QxrdExperimentWPtr QxrdCenterFinder::experiment ( ) const

Definition at line 98 of file qxrdcenterfinder.cpp.

References m_Experiment.

99 {
100  return m_Experiment;
101 }
QxrdExperimentWPtr m_Experiment
bool QxrdCenterFinder::fitPeakNear ( double  x,
double  y 
)
slot

Definition at line 659 of file qxrdcenterfinder.cpp.

References appendPowderPoint(), QxrdFitterPeakPoint::fit(), QxrdFitterPeakOrRing::fittedBkgd(), QxrdFitterPeakOrRing::fittedBkgdX(), QxrdFitterPeakOrRing::fittedBkgdY(), QxrdFitterPeakOrRing::fittedHeight(), QxrdFitterPeakOrRing::fittedWidth(), QxrdFitterPeakOrRing::fittedX(), QxrdFitterPeakOrRing::fittedY(), printMessage(), QxrdFitter::reason(), and QxrdFitter::Successful.

Referenced by onPointSelected().

660 {
661  printMessage(tr("centering.fitPeakNear(%1,%2)").arg(x).arg(y));
662 
663  QxrdFitterPeakPoint fit(this, 0, x, y, 0, 0);
664  fit.fit();
665 
666  if (fit.reason() == QxrdFitter::Successful) {
667  set_PeakCenterX(fit.fittedX());
668  set_PeakCenterY(fit.fittedY());
669  set_PeakWidth(fit.fittedWidth());
670  set_PeakHeight(fit.fittedHeight());
671  set_PeakBackground(fit.fittedBkgd());
672  set_PeakBackgroundX(fit.fittedBkgdX());
673  set_PeakBackgroundY(fit.fittedBkgdY());
674 
675  appendPowderPoint(fit.fittedX(), fit.fittedY());
676 
677  return true;
678  } else {
679  printMessage(tr("Fitting Failed"));
680 
681  return false;
682  }
683 }
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
void appendPowderPoint(double x, double y)

Here is the call graph for this function:

Here is the caller graph for this function:

void QxrdCenterFinder::fitPowderCircle ( int  n = 0)
slot

Definition at line 310 of file qxrdcenterfinder.cpp.

References QxrdFitterRingCircle::fit(), QxrdFitterRingCircle::fittedR(), QxrdFitterRingCircle::fittedX(), QxrdFitterRingCircle::fittedY(), g_Application, printMessage(), QxrdFitter::reason(), QxrdFitter::reasonString(), and QxrdFitter::Successful.

Referenced by QxrdWindow::initialize().

311 {
312  QxrdFitterRingCircle fitter(this, n, get_CenterX(), get_CenterY());
313 
314  int niter = fitter.fit();
315 
316  int update = false;
317  QString message;
318 
319  if (fitter.reason() == QxrdFitter::Successful) {
320  message.append(tr("Circle Fitting Succeeded after %1 iterations\n").arg(niter));
321  message.append(tr("Old Center = [%1,%2]\n").arg(get_CenterX()).arg(get_CenterY()));
322  message.append(tr("New Center = [%1,%2], New Radius = %3\n").arg(fitter.fittedX()).arg(fitter.fittedY()).arg(fitter.fittedR()));
323  double dx = fitter.fittedX() - get_CenterX();
324  double dy = fitter.fittedY() - get_CenterY();
325  message.append(tr("Moved by [%1,%2] = %3\n").arg(dx).arg(dy).arg(sqrt(dx*dx + dy*dy)));
326  } else {
327  message.append(tr("Circle Fitting Failed: Reason = %1\n").arg(fitter.reasonString()));
328  }
329 
330  printMessage(message);
331 
332  QxrdApplication *app = qobject_cast<QxrdApplication*>(g_Application);
333 
334  if (app && app->get_GuiWanted()) {
335  if (niter >= 0) {
336  message.append(tr("Do you want to update the beam centering parameters?"));
337 
338  if (QMessageBox::question(NULL, "Update Fitted Center?", message, QMessageBox::Ok | QMessageBox::No, QMessageBox::Ok) == QMessageBox::Ok) {
339  update = true;
340  }
341  } else {
342  QMessageBox::information(NULL, "Fitting Failed", message);
343  }
344  } else if (niter >= 0){
345  update = true;
346  }
347 
348  if (update) {
349  set_CenterX(fitter.fittedX());
350  set_CenterY(fitter.fittedY());
351  set_RingRadius(fitter.fittedR());
352  }
353 }
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
QcepApplication * g_Application

Here is the call graph for this function:

Here is the caller graph for this function:

void QxrdCenterFinder::fitPowderEllipse ( int  n = 0)
slot

Definition at line 355 of file qxrdcenterfinder.cpp.

References QxrdFitterRingEllipse::fit(), QxrdFitterRingEllipse::fittedA(), QxrdFitterRingEllipse::fittedB(), QxrdFitterRingEllipse::fittedRot(), QxrdFitterRingEllipse::fittedX(), QxrdFitterRingEllipse::fittedY(), g_Application, printMessage(), QxrdFitter::reason(), QxrdFitter::reasonString(), and QxrdFitter::Successful.

356 {
357  QxrdFitterRingEllipse fitter(this, n, get_CenterX(), get_CenterY());
358 
359  int niter = fitter.fit();
360 
361  int update = false;
362  QString message;
363 
364  if (fitter.reason() == QxrdFitter::Successful) {
365  message.append(tr("Ellipse Fitting Succeeded after %1 iterations\n").arg(niter));
366  message.append(tr("Old Center = [%1,%2]\n").arg(get_CenterX()).arg(get_CenterY()));
367  message.append(tr("New Center = [%1,%2], New Radii = %3,%4\n")
368  .arg(fitter.fittedX()).arg(fitter.fittedY()).arg(fitter.fittedA()).arg(fitter.fittedB()));
369  message.append(tr("Major Axis rotation = %1 deg\n").arg(fitter.fittedRot()*180.0/M_PI));
370 
371  double dx = fitter.fittedX() - get_CenterX();
372  double dy = fitter.fittedY() - get_CenterY();
373  message.append(tr("Moved by [%1,%2] = %3\n").arg(dx).arg(dy).arg(sqrt(dx*dx + dy*dy)));
374  } else {
375  message.append(tr("Ellipse Fitting Failed: Reason = %1\n").arg(fitter.reasonString()));
376  }
377 
378  printMessage(message);
379 
380  QxrdApplication *app = qobject_cast<QxrdApplication*>(g_Application);
381 
382  if (app && app->get_GuiWanted()) {
383  if (fitter.reason() == QxrdFitter::Successful) {
384  message.append(tr("Do you want to update the beam centering parameters?"));
385  if (QMessageBox::question(NULL, "Update Fitted Center?", message, QMessageBox::Ok | QMessageBox::No, QMessageBox::Ok) == QMessageBox::Ok) {
386  update = true;
387  }
388  } else {
389  QMessageBox::information(NULL, "Fitting Failed", message);
390  }
391  } else if (niter >= 0){
392  update = true;
393  }
394 
395  if (update) {
396  set_CenterX(fitter.fittedX());
397  set_CenterY(fitter.fittedY());
398  set_RingRadiusA(fitter.fittedA());
399  set_RingRadiusB(fitter.fittedB());
400  set_RingRotation(fitter.fittedRot());
401  }
402 }
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
QcepApplication * g_Application

Here is the call graph for this function:

void QxrdCenterFinder::fitPowderEllipses ( )
slot

Definition at line 404 of file qxrdcenterfinder.cpp.

References countPowderRings(), DEBUG_FITTING, DEBUG_NOPARALLEL, QxrdFitterRingEllipse::fit(), QxrdFitterRingEllipse::fittedA(), QxrdFitterRingEllipse::fittedB(), QxrdFitterRingEllipse::fittedRot(), QxrdFitterRingEllipse::fittedX(), QxrdFitterRingEllipse::fittedY(), printMessage(), qcepDebug(), QxrdFitter::reason(), QxrdFitter::reasonString(), and QxrdFitter::Successful.

405 {
406  int nrings = countPowderRings();
407 
408  QVector<QxrdFitterRingEllipse> fits;
409 
410  for (int i=0; i<nrings; i++) {
411  fits.append(QxrdFitterRingEllipse(this, i, get_CenterX(), get_CenterY()));
412  }
413 
415  for (int i=0; i<nrings; i++) {
416  fits[i].fit();
417  }
418  } else {
419  QFuture<void> fitDone = QtConcurrent::map(fits, &QxrdFitterRingEllipse::fit);
420 
421  fitDone.waitForFinished();
422  }
423 
425 
426  for (int i=0; i<nrings; i++) {
427  QxrdFitterRingEllipse &r = fits[i];
428 
429  if (qcepDebug(DEBUG_FITTING) || get_PeakFitDebug()) {
430  printMessage(tr("Fitted Ring %1: x: %2, y: %3, a: %4, b: %5, rot: %6, rzn: %7")
431  .arg(i).arg(r.fittedX()).arg(r.fittedY())
432  .arg(r.fittedA()).arg(r.fittedB()).arg(r.fittedRot())
433  .arg(r.reasonString()));
434  }
435 
436  if (r.reason() == QxrdFitter::Successful) {
437  pts.append(QxrdPowderPoint(i, 0, 0, r.fittedX(), r.fittedY(), r.fittedA(), r.fittedB(), r.fittedRot()));
438  }
439  }
440 
441  set_FittedRings(pts);
442 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
FitResult reason() const
Definition: qxrdfitter.h:25
int countPowderRings() const
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
QString reasonString() const
Definition: qxrdfitter.cpp:15

Here is the call graph for this function:

bool QxrdCenterFinder::fitRingNear ( double  x0,
double  y0 
)
slot

Definition at line 685 of file qxrdcenterfinder.cpp.

References appendPowderPoint(), QxrdFitterRingPoint::fit(), QxrdFitterPeakOrRing::fittedBkgd(), QxrdFitterPeakOrRing::fittedBkgdX(), QxrdFitterPeakOrRing::fittedBkgdY(), QxrdFitterPeakOrRing::fittedHeight(), QxrdFitterPeakOrRing::fittedWidth(), QxrdFitterPeakOrRing::fittedX(), QxrdFitterPeakOrRing::fittedY(), printMessage(), QxrdFitter::reason(), and QxrdFitter::Successful.

686 {
687  printMessage(tr("centering.fitRingNear(%1,%2)").arg(x0).arg(y0));
688 
689  QxrdFitterRingPoint fit(this, 0, x0, y0, 0, 0);
690  fit.fit();
691 
692  if (fit.reason() == QxrdFitter::Successful) {
693  set_PeakCenterX(fit.fittedX());
694  set_PeakCenterY(fit.fittedY());
695  set_PeakWidth(fit.fittedWidth());
696  set_PeakHeight(fit.fittedHeight());
697  set_PeakBackground(fit.fittedBkgd());
698  set_PeakBackgroundX(fit.fittedBkgdX());
699  set_PeakBackgroundY(fit.fittedBkgdY());
700 
701  appendPowderPoint(fit.fittedX(), fit.fittedY());
702 
703  return true;
704  } else {
705  printMessage(tr("Fitting Failed"));
706 
707  return false;
708  }
709 }
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
void appendPowderPoint(double x, double y)

Here is the call graph for this function:

void QxrdCenterFinder::fromScriptValue ( const QScriptValue &  obj,
QxrdCenterFinderPtr proc 
)
static

Definition at line 1634 of file qxrdcenterfinder.cpp.

1635 {
1636  QObject *qobj = obj.toQObject();
1637 
1638  if (qobj) {
1639  QxrdCenterFinder *f = qobject_cast<QxrdCenterFinder*>(qobj);
1640 
1641  if (f) {
1642  proc = QxrdCenterFinderPtr(f);
1643  }
1644  }
1645 }
QSharedPointer< QxrdCenterFinder > QxrdCenterFinderPtr
double QxrdCenterFinder::getChi ( double  x,
double  y 
) const
slot

Definition at line 235 of file qxrdcenterfinder.cpp.

References QxrdDetectorGeometry::getQChi().

Referenced by getChi(), and missingRingNear().

236 {
237  double q,chi;
238  double beta = get_DetectorTilt()*M_PI/180.0;
239  double rot = get_TiltPlaneRotation()*M_PI/180.0;
240 
241  if (get_ImplementTilt()) {
242  getQChi(get_CenterX(), get_CenterY(), get_DetectorDistance(),
243  get_Energy(),
244  x, y, get_DetectorXPixelSize(), get_DetectorYPixelSize(),
245  rot, cos(beta), sin(beta), 1.0, 0.0, cos(rot), sin(rot),
246  &q, &chi);
247  } else {
248  getQChi(get_CenterX(), get_CenterY(), get_DetectorDistance(),
249  get_Energy(),
250  x, y, get_DetectorXPixelSize(), get_DetectorYPixelSize(),
251  0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0,
252  &q, &chi);
253  }
254 
255  return chi;
256 }
static void getQChi(double xCenter, double yCenter, double distance, double energy, double xPixel, double yPixel, double pixelLength, double pixelHeight, double rotation, double cos_beta, double sin_beta, double cos_alpha, double sin_alpha, double cos_rotation, double sin_rotation, double *q, double *chi)

Here is the call graph for this function:

Here is the caller graph for this function:

double QxrdCenterFinder::getChi ( QPointF  pt) const
slot

Definition at line 230 of file qxrdcenterfinder.cpp.

References getChi().

231 {
232  return getChi(pt.x(), pt.y());
233 }
double getChi(double x, double y) const

Here is the call graph for this function:

double QxrdCenterFinder::getDist ( double  x,
double  y 
) const
slot

Definition at line 263 of file qxrdcenterfinder.cpp.

References getTTH().

Referenced by getDist().

264 {
265  double tth = getTTH(x,y);
266 
267  return get_DetectorDistance()/cos(tth*M_PI/180.0);
268 }
double getTTH(double x, double y) const

Here is the call graph for this function:

Here is the caller graph for this function:

double QxrdCenterFinder::getDist ( QPointF  pt) const
slot

Definition at line 258 of file qxrdcenterfinder.cpp.

References getDist().

259 {
260  return getDist(pt.x(), pt.y());
261 }
double getDist(double x, double y) const

Here is the call graph for this function:

QScriptValue QxrdCenterFinder::getPowderPoint ( int  i)
slot

Definition at line 1041 of file qxrdcenterfinder.cpp.

References QxrdPowderPoint::az(), m_Experiment, QxrdPowderPoint::n1(), QxrdPowderPoint::n2(), QxrdPowderPoint::r1(), QxrdPowderPoint::r2(), QxrdPowderPoint::x(), and QxrdPowderPoint::y().

1042 {
1044 
1045  if (exp) {
1046  QxrdScriptEnginePtr eng(exp->scriptEngine());
1047  QxrdPowderPointVector pts = get_MarkedPoints();
1048 
1049  if (eng) {
1050  if (i>=0 && i<get_MarkedPoints().count()) {
1051  QScriptValue val = eng->newObject();
1052 
1053  QxrdPowderPoint &pt = pts[i];
1054  val.setProperty("n1", pt.n1());
1055  val.setProperty("n2", pt.n2());
1056  val.setProperty("x", pt.x());
1057  val.setProperty("y", pt.y());
1058  val.setProperty("r1", pt.r1());
1059  val.setProperty("r2", pt.r2());
1060  val.setProperty("az", pt.az());
1061 
1062  return val;
1063  }
1064  }
1065  }
1066 
1067  return QScriptValue();
1068 }
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
double y() const
double az() const
int n2() const
QSharedPointer< QxrdScriptEngine > QxrdScriptEnginePtr
double r2() const
QxrdExperimentWPtr m_Experiment
double x() const
int n1() const
double r1() const

Here is the call graph for this function:

int QxrdCenterFinder::getPowderPointN1 ( int  i)
slot

Definition at line 1000 of file qxrdcenterfinder.cpp.

References QxrdPowderPoint::n1().

1001 {
1002  QxrdPowderPoint res = get_MarkedPoints().value(i);
1003 
1004  return res.n1();
1005 }
int n1() const

Here is the call graph for this function:

int QxrdCenterFinder::getPowderPointN2 ( int  i)
slot

Definition at line 1007 of file qxrdcenterfinder.cpp.

References QxrdPowderPoint::n2().

1008 {
1009  QxrdPowderPoint res = get_MarkedPoints().value(i);
1010 
1011  return res.n2();
1012 }
int n2() const

Here is the call graph for this function:

QScriptValue QxrdCenterFinder::getPowderPoints ( )
slot

Definition at line 1070 of file qxrdcenterfinder.cpp.

References QxrdPowderPoint::az(), m_Experiment, QxrdPowderPoint::n1(), QxrdPowderPoint::n2(), QxrdPowderPoint::r1(), QxrdPowderPoint::r2(), QxrdPowderPoint::x(), and QxrdPowderPoint::y().

1071 {
1073 
1074  if (exp) {
1075  QxrdScriptEnginePtr eng(exp->scriptEngine());
1076 
1077  if (eng) {
1078  QxrdPowderPointVector pts = get_MarkedPoints();
1079 
1080  QScriptValue val = eng->newArray();
1081 
1082  for (int i=0; i<pts.count(); i++) {
1083  QScriptValue item = eng->newObject();
1084 
1085  QxrdPowderPoint &pt = pts[i];
1086  item.setProperty("n1", pt.n1());
1087  item.setProperty("n2", pt.n2());
1088  item.setProperty("x", pt.x());
1089  item.setProperty("y", pt.y());
1090  item.setProperty("r1", pt.r1());
1091  item.setProperty("r2", pt.r2());
1092  item.setProperty("az", pt.az());
1093 
1094  val.setProperty(tr("%1").arg(i), item);
1095  }
1096 
1097  return val;
1098  }
1099  }
1100 
1101  return QScriptValue();
1102 }
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
double y() const
double az() const
int n2() const
QSharedPointer< QxrdScriptEngine > QxrdScriptEnginePtr
double r2() const
QxrdExperimentWPtr m_Experiment
double x() const
int n1() const
double r1() const

Here is the call graph for this function:

double QxrdCenterFinder::getPowderPointX ( int  i)
slot

Definition at line 1014 of file qxrdcenterfinder.cpp.

References QxrdPowderPoint::x().

1015 {
1016  QxrdPowderPoint res = get_MarkedPoints().value(i);
1017 
1018  return res.x();
1019 }
double x() const

Here is the call graph for this function:

double QxrdCenterFinder::getPowderPointY ( int  i)
slot

Definition at line 1021 of file qxrdcenterfinder.cpp.

References QxrdPowderPoint::y().

1022 {
1023  QxrdPowderPoint res = get_MarkedPoints().value(i);
1024 
1025  return res.y();
1026 }
double y() const

Here is the call graph for this function:

double QxrdCenterFinder::getQ ( double  x,
double  y 
) const
slot

Definition at line 207 of file qxrdcenterfinder.cpp.

References QxrdDetectorGeometry::getQChi().

Referenced by getQ(), and powderRingAverageQ().

208 {
209  double q,chi;
210  double beta = get_DetectorTilt()*M_PI/180.0;
211  double rot = get_TiltPlaneRotation()*M_PI/180.0;
212 
213  if (get_ImplementTilt()) {
214  getQChi(get_CenterX(), get_CenterY(), get_DetectorDistance(),
215  get_Energy(),
216  x, y, get_DetectorXPixelSize(), get_DetectorYPixelSize(),
217  rot, cos(beta), sin(beta), 1.0, 0.0, cos(rot), sin(rot),
218  &q, &chi);
219  } else {
220  getQChi(get_CenterX(), get_CenterY(), get_DetectorDistance(),
221  get_Energy(),
222  x, y, get_DetectorXPixelSize(), get_DetectorYPixelSize(),
223  0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0,
224  &q, &chi);
225  }
226 
227  return q;
228 }
static void getQChi(double xCenter, double yCenter, double distance, double energy, double xPixel, double yPixel, double pixelLength, double pixelHeight, double rotation, double cos_beta, double sin_beta, double cos_alpha, double sin_alpha, double cos_rotation, double sin_rotation, double *q, double *chi)

Here is the call graph for this function:

Here is the caller graph for this function:

double QxrdCenterFinder::getQ ( QPointF  pt) const
slot

Definition at line 202 of file qxrdcenterfinder.cpp.

References getQ().

203 {
204  return getQ(pt.x(), pt.y());
205 }
double getQ(double x, double y) const

Here is the call graph for this function:

double QxrdCenterFinder::getR ( double  x,
double  y 
) const
slot

Definition at line 275 of file qxrdcenterfinder.cpp.

References getTTH().

Referenced by getR(), missingRingNear(), normalizePowderRings(), and powderRingAverageR().

276 {
277  double tth = getTTH(x, y);
278  double r = get_DetectorDistance()*tan(tth*M_PI/180.0);
279 
280  return r;
281 }
double getTTH(double x, double y) const

Here is the call graph for this function:

Here is the caller graph for this function:

double QxrdCenterFinder::getR ( QPointF  pt) const
slot

Definition at line 270 of file qxrdcenterfinder.cpp.

References getR().

271 {
272  return getR(pt.x(), pt.y());
273 }
double getR(double x, double y) const

Here is the call graph for this function:

double QxrdCenterFinder::getTTH ( double  x,
double  y 
) const
slot

Definition at line 160 of file qxrdcenterfinder.cpp.

References QxrdDetectorGeometry::getTwoTheta().

Referenced by calculateCalibration(), getDist(), getR(), getTTH(), and powderRingAverageTTH().

161 {
162  if (get_ImplementTilt()) {
163  double beta = get_DetectorTilt()*M_PI/180.0;
164  double rot = get_TiltPlaneRotation()*M_PI/180.0;
165 
166  return getTwoTheta(get_CenterX(), get_CenterY(), get_DetectorDistance(),
167  x, y, get_DetectorXPixelSize(), get_DetectorYPixelSize(),
168  cos(beta), sin(beta), cos(rot), sin(rot));
169  } else {
170  return getTwoTheta(get_CenterX(), get_CenterY(), get_DetectorDistance(),
171  x, y, get_DetectorXPixelSize(), get_DetectorYPixelSize(),
172  1.0, 0.0, 1.0, 0.0);
173  }
174 }
static double getTwoTheta(double xCenter, double yCenter, double distance, double xPixel, double yPixel, double pixelLength, double pixelHeight, double cos_beta, double sin_beta, double cos_rotation, double sin_rotation)

Here is the call graph for this function:

Here is the caller graph for this function:

double QxrdCenterFinder::getTTH ( QPointF  pt) const
slot

Definition at line 155 of file qxrdcenterfinder.cpp.

References getTTH().

156 {
157  return getTTH(pt.x(), pt.y());
158 }
double getTTH(double x, double y) const

Here is the call graph for this function:

QPointF QxrdCenterFinder::getXY ( double  tth,
double  chi 
)
slot

Definition at line 176 of file qxrdcenterfinder.cpp.

References QxrdDetectorGeometry::convertEnergyToWavelength(), QxrdDetectorGeometry::convertTwoThetaToQ(), and QxrdDetectorGeometry::getXY().

177 {
178  double x,y;
179  double beta = get_DetectorTilt()*M_PI/180.0;
180  double rot = get_TiltPlaneRotation()*M_PI/180.0;
181 
182  if (get_ImplementTilt()) {
183 
184  QxrdDetectorGeometry::getXY(get_CenterX(), get_CenterY(), get_DetectorDistance(),
185  get_Energy(),
186  convertTwoThetaToQ(tth, convertEnergyToWavelength(get_Energy())), chi,
187  get_DetectorXPixelSize(), get_DetectorYPixelSize(),
188  rot, cos(beta), sin(beta), 1.0, 0.0, cos(rot), sin(rot),
189  &x, &y);
190  } else {
191  QxrdDetectorGeometry::getXY(get_CenterX(), get_CenterY(), get_DetectorDistance(),
192  get_Energy(),
193  convertTwoThetaToQ(tth, convertEnergyToWavelength(get_Energy())), chi,
194  get_DetectorXPixelSize(), get_DetectorYPixelSize(),
195  rot, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0,
196  &x, &y);
197  }
198 
199  return QPointF(x,y);
200 }
static double convertEnergyToWavelength(double energy)
static double convertTwoThetaToQ(double twoTheta, double wavelength)
static void getXY(double xCenter, double yCenter, double distance, double energy, double q, double chi, double pixelLength, double pixelHeight, double rotation, double cos_beta, double sin_beta, double cos_alpha, double sin_alpha, double cos_rotation, double sin_rotation, double *xPixel, double *yPixel)

Here is the call graph for this function:

double QxrdCenterFinder::imageValue ( double  x,
double  y 
)

Definition at line 1124 of file qxrdcenterfinder.cpp.

References m_Data.

Referenced by QxrdFitterPeakPoint::evaluate(), QxrdFitterRingPoint::evaluate(), QxrdFitterRingPoint::fit(), QxrdFitterPeakPoint::fit(), and traceRingNear().

1125 {
1126  if (m_Data) {
1127  return m_Data->value(x,y);
1128  } else {
1129  return 0;
1130  }
1131 }
QcepDoubleImageDataPtr m_Data

Here is the caller graph for this function:

QString QxrdCenterFinder::levmarFailureReason ( int  n)
static

Definition at line 1133 of file qxrdcenterfinder.cpp.

1134 {
1135  switch (n) {
1136  case 1:
1137  return "Stopped by Small Gradient";
1138  break;
1139 
1140  case 2:
1141  return "Stopped by Small Dp";
1142  break;
1143 
1144  case 3:
1145  return "Stopped by iteration limit";
1146  break;
1147 
1148  case 4:
1149  return "Stopped by singular matrix";
1150  break;
1151 
1152  case 5:
1153  return "No further error reduction possible";
1154  break;
1155 
1156  case 6:
1157  return "Stopped by small ||e||^2";
1158  break;
1159 
1160  case 7:
1161  return "Stopped by invalid (i.e. NaN or Inf) function values";
1162  break;
1163 
1164  default:
1165  return "Unknown reason for failure";
1166  }
1167 }
bool QxrdCenterFinder::missingRingNear ( double  x,
double  y 
)
slot

Definition at line 890 of file qxrdcenterfinder.cpp.

References appendPowderPoint(), getChi(), and getR().

891 {
892  appendPowderPoint(get_RingIndex(), -1, 0, x, y, getR(x,y), getR(x,y), getChi(x,y));
893  prop_RingIndex()->incValue(1);
894 
895  return true;
896 }
double getChi(double x, double y) const
double getR(double x, double y) const
void appendPowderPoint(double x, double y)

Here is the call graph for this function:

QxrdPowderPoint QxrdCenterFinder::nearestPowderPoint ( double  x,
double  y 
)
slot

Definition at line 513 of file qxrdcenterfinder.cpp.

References nearestPowderPointIndex().

514 {
515  return get_MarkedPoints().value(nearestPowderPointIndex(x,y));
516 }
int nearestPowderPointIndex(double x, double y)

Here is the call graph for this function:

int QxrdCenterFinder::nearestPowderPointIndex ( double  x,
double  y 
)
slot

Definition at line 494 of file qxrdcenterfinder.cpp.

References QxrdPowderPoint::x(), and QxrdPowderPoint::y().

Referenced by deletePowderPointNear(), and nearestPowderPoint().

495 {
496  int nearest = -1;
497  double nearestDist;
498  QxrdPowderPointVector pts = get_MarkedPoints();
499 
500  for (int i=0; i<pts.count(); i++) {
501  QxrdPowderPoint pt = pts.value(i);
502  double dist = sqrt(pow(x-pt.x(), 2) + pow(y-pt.y(), 2));
503 
504  if (nearest == -1 || dist < nearestDist) {
505  nearest = i;
506  nearestDist = dist;
507  }
508  }
509 
510  return nearest;
511 }
double y() const
double x() const

Here is the call graph for this function:

Here is the caller graph for this function:

QcepDoubleImageDataPtr QxrdCenterFinder::newData ( )

Definition at line 108 of file qxrdcenterfinder.cpp.

References m_Data, and m_Experiment.

Referenced by calculateCalibration().

109 {
110  int wd, ht;
111 
112  if (m_Data) {
113  wd = m_Data->get_Width();
114  ht = m_Data->get_Height();
115  } else {
116  wd = 2048;
117  ht = 2048;
118  }
119 
121 
122  if (expt) {
123  QxrdDataProcessorPtr proc(expt->dataProcessor());
124 
125  if (proc) {
126  QcepDoubleImageDataPtr res = proc->takeNextFreeImage(wd,ht);
127 
128  return res;
129  }
130  }
131 
132  return QcepDoubleImageDataPtr();
133 }
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
QSharedPointer< QxrdDataProcessor > QxrdDataProcessorPtr
QcepDoubleImageDataPtr m_Data
QxrdExperimentWPtr m_Experiment
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr

Here is the caller graph for this function:

void QxrdCenterFinder::normalizePowderRings ( )
slot

Definition at line 600 of file qxrdcenterfinder.cpp.

References getR(), QxrdPowderPoint::n1(), ringIndex, QxrdPowderPoint::x(), and QxrdPowderPoint::y().

601 {
602  QxrdPowderPointVector pts = get_MarkedPoints();
603 
604  double maxR = 0;
605 
606  foreach(QxrdPowderPoint pt, pts) {
607  double r = getR(pt.x(), pt.y());
608 
609  if (r > maxR) {
610  maxR = r;
611  }
612  }
613 
614  if (maxR > 0 && maxR < 10000) {
615  int nbins = (int) maxR + 5;
616  QVector<int> npts(nbins);
617 
618  npts.fill(0);
619 
620  foreach(QxrdPowderPoint pt, pts) {
621  double r = getR(pt.x(), pt.y());
622  npts[(int) r] ++;
623  }
624 
625  int ringIndex = 0;
626 
627  for (int i=0; i<nbins-1; i++) {
628  if (npts[i] > 0) {
629  if (npts[i+1] == 0) {
630  npts[i] = ringIndex++;
631  } else {
632  npts[i] = ringIndex;
633  }
634  }
635  }
636 
637 // for (int i=0; i<nbins; i++) {
638 // if (npts[i] > 0) {
639 // printMessage(tr("i: %1, r: %2").arg(i).arg(npts[i]));
640 // }
641 // }
642 
643  int n = pts.count();
644 
645  for (int i=0; i<n; i++) {
646  QxrdPowderPoint &pt = pts[i];
647 
648  double r = getR(pt.x(), pt.y());
649  int idx = npts[(int) r];
650 
651  pt.n1() = idx;
652  }
653 
654  set_MarkedPoints(pts);
655  set_RingIndex(ringIndex);
656  }
657 }
double y() const
double getR(double x, double y) const
double x() const
int n1() const

Here is the call graph for this function:

void QxrdCenterFinder::onCenterChanged ( QPointF  pt)
slot

Definition at line 149 of file qxrdcenterfinder.cpp.

Referenced by QxrdImagePlot::setProcessor().

150 {
151  set_CenterX(pt.x());
152  set_CenterY(pt.y());
153 }

Here is the caller graph for this function:

void QxrdCenterFinder::onPointSelected ( QPointF  pt)
slot

Definition at line 283 of file qxrdcenterfinder.cpp.

References appendPowderPoint(), and fitPeakNear().

Referenced by QxrdImagePlot::setProcessor().

284 {
285  if (get_FitPowderPointPosition()) {
286  fitPeakNear(pt.x(), pt.y());
287  } else {
288  appendPowderPoint(pt.x(), pt.y());
289  }
290 }
bool fitPeakNear(double x, double y)
void appendPowderPoint(double x, double y)

Here is the call graph for this function:

Here is the caller graph for this function:

void QxrdCenterFinder::parameterChanged ( )
signal

Referenced by QxrdCenterFinder(), QxrdIntegrator::QxrdIntegrator(), and QxrdCenterFinderPlot::setWindow().

Here is the caller graph for this function:

QxrdPowderPoint QxrdCenterFinder::powderPoint ( int  i)
slot

Definition at line 489 of file qxrdcenterfinder.cpp.

Referenced by calculateCalibration().

490 {
491  return get_MarkedPoints().value(i);
492 }

Here is the caller graph for this function:

double QxrdCenterFinder::powderRingAverageQ ( int  r) const
slot

Definition at line 1252 of file qxrdcenterfinder.cpp.

References getQ(), QxrdPowderPoint::n1(), QxrdPowderPoint::x(), and QxrdPowderPoint::y().

1253 {
1254  QxrdPowderPointVector pts = get_MarkedPoints();
1255 
1256  double sum = 0, npts = 0;
1257 
1258  foreach (QxrdPowderPoint pt, pts) {
1259  if (pt.n1() == r) {
1260  npts += 1;
1261  sum += getQ(pt.x(), pt.y());
1262  }
1263  }
1264 
1265  return sum/npts;
1266 }
double y() const
double getQ(double x, double y) const
double x() const
int n1() const

Here is the call graph for this function:

double QxrdCenterFinder::powderRingAverageR ( int  r) const
slot

Definition at line 1236 of file qxrdcenterfinder.cpp.

References getR(), QxrdPowderPoint::n1(), QxrdPowderPoint::x(), and QxrdPowderPoint::y().

Referenced by adjustDistance().

1237 {
1238  QxrdPowderPointVector pts = get_MarkedPoints();
1239 
1240  double sum = 0, npts = 0;
1241 
1242  foreach (QxrdPowderPoint pt, pts) {
1243  if (pt.n1() == r) {
1244  npts += 1;
1245  sum += getR(pt.x(), pt.y());
1246  }
1247  }
1248 
1249  return sum/npts;
1250 }
double y() const
double getR(double x, double y) const
double x() const
int n1() const

Here is the call graph for this function:

Here is the caller graph for this function:

double QxrdCenterFinder::powderRingAverageTTH ( int  r) const
slot

Definition at line 1268 of file qxrdcenterfinder.cpp.

References getTTH(), QxrdPowderPoint::n1(), QxrdPowderPoint::x(), and QxrdPowderPoint::y().

Referenced by adjustEnergy().

1269 {
1270  QxrdPowderPointVector pts = get_MarkedPoints();
1271 
1272  double sum = 0, npts = 0;
1273 
1274  foreach (QxrdPowderPoint pt, pts) {
1275  if (pt.n1() == r) {
1276  npts += 1;
1277  sum += getTTH(pt.x(), pt.y());
1278  }
1279  }
1280 
1281  return sum/npts;
1282 }
double y() const
double getTTH(double x, double y) const
double x() const
int n1() const

Here is the call graph for this function:

Here is the caller graph for this function:

QxrdPowderPoint QxrdCenterFinder::powderRingPoint ( int  i) const
slot

Definition at line 1212 of file qxrdcenterfinder.cpp.

Referenced by QxrdFitterRingCircle::evaluate(), QxrdFitterRingEllipse::evaluate(), QxrdFitterRingEllipse::fit(), and QxrdFitterRingCircle::fit().

1213 {
1214  return get_MarkedPoints().value(i);
1215 }

Here is the caller graph for this function:

QxrdPowderPoint QxrdCenterFinder::powderRingPoint ( int  r,
int  i 
) const
slot

Definition at line 1217 of file qxrdcenterfinder.cpp.

References QxrdPowderPoint::n1().

1218 {
1219  QxrdPowderPointVector pts = get_MarkedPoints();
1220 
1221  int sum = 0;
1222 
1223  foreach (QxrdPowderPoint pt, pts) {
1224  if (pt.n1() == r || r < 0) {
1225  if (sum == i) {
1226  return pt;
1227  } else {
1228  sum += 1;
1229  }
1230  }
1231  }
1232 
1233  return QxrdPowderPoint();
1234 }
int n1() const

Here is the call graph for this function:

void QxrdCenterFinder::printMessage ( QString  msg,
QDateTime  ts = QDateTime::currentDateTime() 
) const
slot

Definition at line 292 of file qxrdcenterfinder.cpp.

References m_Experiment.

Referenced by calculateCalibration(), disablePowderRing(), enablePowderRing(), QxrdFitterRingPoint::evaluate(), QxrdFitterPeakPoint::evaluate(), fitPeakNear(), fitPowderCircle(), fitPowderEllipse(), fitPowderEllipses(), fitRingNear(), and traceRingNear().

293 {
295 
296  if (exp) {
297  exp->printMessage(msg, ts);
298  }
299 }
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
QxrdExperimentWPtr m_Experiment

Here is the caller graph for this function:

void QxrdCenterFinder::readSettings ( QSettings *  settings,
QString  section 
)
virtual

Reimplemented from QcepObject.

Definition at line 142 of file qxrdcenterfinder.cpp.

References m_Mutex, and QcepObject::readSettings().

143 {
144  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
145 
146  QxrdDetectorGeometry::readSettings(settings, section);
147 }
virtual void readSettings(QSettings *set, QString section)
Definition: qcepobject.cpp:119

Here is the call graph for this function:

void QxrdCenterFinder::setData ( QcepDoubleImageDataPtr  data)

Definition at line 1119 of file qxrdcenterfinder.cpp.

References data(), and m_Data.

1120 {
1121  m_Data = data;
1122 }
QcepDoubleImageDataPtr data() const
QcepDoubleImageDataPtr m_Data

Here is the call graph for this function:

void QxrdCenterFinder::setPowderPoint ( int  i,
int  n1,
int  n2,
int  n3,
double  x,
double  y,
double  r1,
double  r2,
double  az 
)
slot

Definition at line 1028 of file qxrdcenterfinder.cpp.

Referenced by setPowderPoint().

1029 {
1030  QxrdPowderPointVector pts = get_MarkedPoints();
1031 
1032  if (i>=0 && i<pts.count()) {
1033  pts[i] = QxrdPowderPoint(n1,n2,n3,x,y,r1,r2,az);
1034  } else {
1035  pts.append(QxrdPowderPoint(n1,n2,n3,x,y,r1,r2,az));
1036  }
1037 
1038  set_MarkedPoints(pts);
1039 }

Here is the caller graph for this function:

void QxrdCenterFinder::setPowderPoint ( int  i,
QScriptValue  val 
)
slot

Definition at line 1104 of file qxrdcenterfinder.cpp.

References setPowderPoint().

1105 {
1106  int n1 = val.property("n1").toInteger();
1107  int n2 = val.property("n2").toInteger();
1108  int n3 = val.property("n3").toInteger();
1109  double x = val.property("x").toNumber();
1110  double y = val.property("y").toNumber();
1111  double r1 = val.property("r1").toNumber();
1112  double r2 = val.property("r2").toNumber();
1113  double az = val.property("az").toNumber();
1114 
1115  setPowderPoint(i, n1, n2, n3, x, y, r1, r2, az);
1116 }
void setPowderPoint(int i, int n1, int n2, int n3, double x, double y, double r1, double r2, double az)

Here is the call graph for this function:

void QxrdCenterFinder::statusMessage ( QString  msg,
QDateTime  ts = QDateTime::currentDateTime() 
) const
slot

Definition at line 301 of file qxrdcenterfinder.cpp.

References m_Experiment.

Referenced by traceRingNear().

302 {
304 
305  if (exp) {
306  exp->statusMessage(msg, ts);
307  }
308 }
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
QxrdExperimentWPtr m_Experiment

Here is the caller graph for this function:

QScriptValue QxrdCenterFinder::toScriptValue ( QScriptEngine *  engine,
const QxrdCenterFinderPtr proc 
)
static

Definition at line 1629 of file qxrdcenterfinder.cpp.

1630 {
1631  return engine->newQObject(proc.data());
1632 }
bool QxrdCenterFinder::traceRingNear ( double  x0,
double  y0,
double  step = 25.0 
)
slot

Definition at line 711 of file qxrdcenterfinder.cpp.

References QxrdFitterPeakOrRing::bkgd(), data(), DEBUG_FITTING, QxrdFitterRingPoint::fit(), QxrdFitterPeakOrRing::fittedAz(), QxrdFitterPeakOrRing::fittedBkgd(), QxrdFitterPeakOrRing::fittedBkgdX(), QxrdFitterPeakOrRing::fittedBkgdY(), QxrdFitterPeakOrRing::fittedHeight(), QxrdFitterPeakOrRing::fittedR(), QxrdFitterPeakOrRing::fittedWidth(), QxrdFitterPeakOrRing::fittedX(), QxrdFitterPeakOrRing::fittedY(), imageValue(), QxrdFitterPeakOrRing::index(), QxrdFitter::LastReason, m_Data, m_Experiment, QxrdFitterPeakOrRing::pkht(), printMessage(), qcepDebug(), QxrdFitter::reason(), QxrdFitter::reasonString(), statusMessage(), QxrdFitter::Successful, QxrdFitterPeakOrRing::x0(), and QxrdFitterPeakOrRing::y0().

712 {
713  printMessage(tr("centering.traceRingNear(%1,%2,%3)").arg(x0).arg(y0).arg(step));
714 
715  double x=x0, y=y0;
716  double xc = get_CenterX();
717  double yc = get_CenterY();
718  double dx = x0-xc;
719  double dy = y0-yc;
720  double az = atan2(dy, dx);
721  double az0 = az;
722  double r = sqrt(dx*dx + dy*dy);
723  double ast = step/r;
724  double dr = get_PeakFitRadius();
725 
726  QxrdFitterRingPoint fit(this, 0, x0, y0, 0, 0);
727  fit.fit();
728 
729  printMessage(tr("Initial fit: az: %1, x: %2, y: %3, nx: %4, ny: %5, wd: %6, ht: %7, rz: %8")
730  .arg(az).arg(x).arg(y).arg(fit.fittedX()).arg(fit.fittedY())
731  .arg(fit.fittedWidth()).arg(fit.fittedHeight())
732  .arg(fit.reasonString()));
733 
734  double bkgd = ( imageValue(xc+(r+dr)*cos(az), yc+(r+dr)*sin(az))
735  +imageValue(xc+(r-dr)*cos(az), yc+(r-dr)*sin(az)))/2.0;
736 
737  double pkht = imageValue(x0,y0) - bkgd;
738 
739  int width = 0, height = 0;
740 
741  if (m_Data) {
742  width = m_Data->get_Width()+1;
743  height = m_Data->get_Height()+1;
744  }
745 
746  QVector<QxrdFitterRingPoint> fits;
747 
748  while (true) {
749  if (x >= 0 && y >= 0 && x <= width && y <= height) {
750  QxrdFitterRingPoint fit(this, 0, x, y, pkht, bkgd);
751  fit.fit();
752  fits.append(fit);
753 
754  if (qcepDebug(DEBUG_FITTING) || get_PeakFitDebug()) {
755  printMessage(tr("Fit Ring Near: az: %1, x: %2, y: %3, nx: %4, ny: %5, wd: %6, ht: %7, rz: %8")
756  .arg(az).arg(x).arg(y).arg(fit.fittedX()).arg(fit.fittedY())
757  .arg(fit.fittedWidth()).arg(fit.fittedHeight())
758  .arg(fit.reasonString()));
759  }
760 
761  x = fit.fittedX();
762  y = fit.fittedY();
763 
764  if (fit.reason()==QxrdFitter::Successful) {
765  r = sqrt((x-xc)*(x-xc) + (y-yc)*(y-yc));
766  }
767  }
768 
769  az += ast;
770 
771  if (step > 0) {
772  if ((az-az0) >= 2*M_PI) break;
773  } else {
774  if ((az-az0) <= -2*M_PI) break;
775  }
776 
777  x = xc + r*cos(az);
778  y = yc + r*sin(az);
779  }
780 
781  int npts = fits.count();
782  int nok = 0;
783 
784  QxrdPowderPointVector pts = get_MarkedPoints();
785 
786  QVector<int> nreason(QxrdFitter::LastReason);
787 
788  for(int i=0; i<fits.count(); i++) {
789  QxrdFitterRingPoint &fit = fits[i];
790 
791  if (fit.reason() == QxrdFitter::Successful) {
792  nok += 1;
793  pts.append(QxrdPowderPoint(get_RingIndex(), 0, 0, fit.fittedX(), fit.fittedY(), fit.fittedR(), fit.fittedR(), fit.fittedAz()));
794  }
795 
796  nreason[fit.reason()] += 1;
797  }
798 
800 
801  if (expt) {
802  QcepDatasetModelPtr data = expt->dataset();
803 
804  if (data) {
805  QcepDataColumnScanPtr scan = data->columnScan(tr("fitted/ring%1").arg(get_RingIndex()));
806 
807  if (scan == NULL) {
808  scan = data->newColumnScan(tr("fitted/ring%1").arg(get_RingIndex()));
809  }
810 
811  if (scan) {
812  scan->clear();
813 
814  scan->appendColumn("i");
815  scan->appendColumn("index");
816  scan->appendColumn("Reason");
817  scan->appendColumn("X0");
818  scan->appendColumn("Y0");
819  scan->appendColumn("pkht");
820  scan->appendColumn("bkgd");
821  scan->appendColumn("XFit");
822  scan->appendColumn("YFit");
823  scan->appendColumn("WdFit");
824  scan->appendColumn("HtFit");
825  scan->appendColumn("BkgdFit");
826  scan->appendColumn("BkgdXFit");
827  scan->appendColumn("BkgdYFit");
828  scan->appendColumn("RFit");
829  scan->appendColumn("AzFit");
830  scan->appendColumn("dx");
831  scan->appendColumn("dy");
832  scan->appendColumn("dr");
833 
834  scan->resizeRows(fits.count());
835 
836  for (int i=0; i<fits.count(); i++) {
837  QxrdFitterRingPoint &fit = fits[i];
838  int col=0;
839 
840  double dx = fit.fittedX() - fit.x0();
841  double dy = fit.fittedY() - fit.y0();
842  double dr = sqrt(dx*dx + dy*dy);
843 
844  scan->setValue(col++, i, i);
845  scan->setValue(col++, i, fit.index());
846  scan->setValue(col++, i, fit.reason());
847  scan->setValue(col++, i, fit.x0());
848  scan->setValue(col++, i, fit.y0());
849  scan->setValue(col++, i, fit.pkht());
850  scan->setValue(col++, i, fit.bkgd());
851  scan->setValue(col++, i, fit.fittedX());
852  scan->setValue(col++, i, fit.fittedY());
853  scan->setValue(col++, i, fit.fittedWidth());
854  scan->setValue(col++, i, fit.fittedHeight());
855  scan->setValue(col++, i, fit.fittedBkgd());
856  scan->setValue(col++, i, fit.fittedBkgdX());
857  scan->setValue(col++, i, fit.fittedBkgdY());
858  scan->setValue(col++, i, fit.fittedR());
859  scan->setValue(col++, i, fit.fittedAz()*180.0/M_PI);
860  scan->setValue(col++, i, dx);
861  scan->setValue(col++, i, dy);
862  scan->setValue(col++, i, dr);
863  }
864  }
865  }
866  }
867 
868  if (npts) {
869  QString msg(tr("centering.traceRingNear : %1/%2 fitted points").arg(nok).arg(npts));
870 
871  printMessage(msg);
872  statusMessage(msg);
873 
874  for (int i=0; i<QxrdFitter::LastReason; i++) {
875  if (nreason[i] > 0) {
876  QString msg(tr(" %1 : %2").arg(nreason[i]).arg(QxrdFitter::reasonString((QxrdFitter::FitResult) i)));
877  printMessage(msg);
878  }
879  }
880 
881  if (nok) {
882  prop_RingIndex()->incValue(1);
883  set_MarkedPoints(pts);
884  }
885  }
886 
887  return nok;
888 }
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
QcepDoubleImageDataPtr data() const
FitResult reason() const
Definition: qxrdfitter.h:25
QSharedPointer< QcepDataColumnScan > QcepDataColumnScanPtr
double fittedWidth() const
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
QcepDoubleImageDataPtr m_Data
double fittedBkgdX() const
QxrdExperimentWPtr m_Experiment
QString reasonString() const
Definition: qxrdfitter.cpp:15
void statusMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
double imageValue(double x, double y)
double fittedBkgd() const
double fittedBkgdY() const
double fittedHeight() const
QSharedPointer< QcepDatasetModel > QcepDatasetModelPtr

Here is the call graph for this function:

void QxrdCenterFinder::writeSettings ( QSettings *  settings,
QString  section 
)
virtual

Reimplemented from QcepObject.

Definition at line 135 of file qxrdcenterfinder.cpp.

References m_Mutex, and QcepObject::writeSettings().

136 {
137  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
138 
139  QxrdDetectorGeometry::writeSettings(settings, section);
140 }
virtual void writeSettings(QSettings *set, QString section)
Definition: qcepobject.cpp:114

Here is the call graph for this function:

Member Data Documentation

int QxrdCenterFinder::m_CenterFitRingNumber
private

Definition at line 263 of file qxrdcenterfinder.h.

QcepDoubleImageDataPtr QxrdCenterFinder::m_Data
private

Definition at line 262 of file qxrdcenterfinder.h.

Referenced by data(), imageValue(), newData(), setData(), and traceRingNear().

QxrdExperimentWPtr QxrdCenterFinder::m_Experiment
private
QMutex QxrdCenterFinder::m_Mutex
mutableprivate

Definition at line 260 of file qxrdcenterfinder.h.

Referenced by readSettings(), and writeSettings().

enum { ... } QxrdCenterFinder::UserAbsorptionKinds

Property Documentation

double QxrdCenterFinder::centerStep
readwrite

Definition at line 34 of file qxrdcenterfinder.h.

double QxrdCenterFinder::centerX
readwrite

Definition at line 28 of file qxrdcenterfinder.h.

double QxrdCenterFinder::centerY
readwrite

Definition at line 31 of file qxrdcenterfinder.h.

double QxrdCenterFinder::detectorDistance
readwrite

Definition at line 43 of file qxrdcenterfinder.h.

double QxrdCenterFinder::detectorDistanceStep
readwrite

Definition at line 46 of file qxrdcenterfinder.h.

double QxrdCenterFinder::detectorTilt
readwrite

Definition at line 55 of file qxrdcenterfinder.h.

double QxrdCenterFinder::detectorTiltStep
readwrite

Definition at line 58 of file qxrdcenterfinder.h.

double QxrdCenterFinder::detectorXPixelSize
readwrite

Definition at line 37 of file qxrdcenterfinder.h.

double QxrdCenterFinder::detectorYPixelSize
readwrite

Definition at line 40 of file qxrdcenterfinder.h.

double QxrdCenterFinder::energy
readwrite

Definition at line 49 of file qxrdcenterfinder.h.

bool QxrdCenterFinder::fitPowderPointPosition
readwrite

Definition at line 145 of file qxrdcenterfinder.h.

double QxrdCenterFinder::fittedHeightMinRatio
readwrite

Definition at line 139 of file qxrdcenterfinder.h.

double QxrdCenterFinder::fittedPositionMaxDistance
readwrite

Definition at line 142 of file qxrdcenterfinder.h.

QxrdPowderPointVector QxrdCenterFinder::fittedRings
readwrite

Definition at line 70 of file qxrdcenterfinder.h.

double QxrdCenterFinder::fittedWidthMax
readwrite

Definition at line 136 of file qxrdcenterfinder.h.

double QxrdCenterFinder::fittedWidthMin
readwrite

Definition at line 133 of file qxrdcenterfinder.h.

bool QxrdCenterFinder::implementTilt
readwrite

Definition at line 52 of file qxrdcenterfinder.h.

QxrdPowderPointVector QxrdCenterFinder::markedPoints
readwrite

Definition at line 67 of file qxrdcenterfinder.h.

double QxrdCenterFinder::peakBackground
readwrite

Definition at line 100 of file qxrdcenterfinder.h.

double QxrdCenterFinder::peakBackgroundX
readwrite

Definition at line 103 of file qxrdcenterfinder.h.

double QxrdCenterFinder::peakBackgroundY
readwrite

Definition at line 106 of file qxrdcenterfinder.h.

double QxrdCenterFinder::peakCenterX
readwrite

Definition at line 91 of file qxrdcenterfinder.h.

double QxrdCenterFinder::peakCenterY
readwrite

Definition at line 94 of file qxrdcenterfinder.h.

bool QxrdCenterFinder::peakFitDebug
readwrite

Definition at line 109 of file qxrdcenterfinder.h.

int QxrdCenterFinder::peakFitIterations
readwrite

Definition at line 112 of file qxrdcenterfinder.h.

double QxrdCenterFinder::peakFitRadius
readwrite

Definition at line 85 of file qxrdcenterfinder.h.

double QxrdCenterFinder::peakHeight
readwrite

Definition at line 88 of file qxrdcenterfinder.h.

double QxrdCenterFinder::peakWidth
readwrite

Definition at line 97 of file qxrdcenterfinder.h.

int QxrdCenterFinder::powderFitOptions
readwrite

Definition at line 121 of file qxrdcenterfinder.h.

QcepDoubleVector QxrdCenterFinder::ringAngles
readwrite

Definition at line 115 of file qxrdcenterfinder.h.

double QxrdCenterFinder::ringAngleTolerance
readwrite

Definition at line 118 of file qxrdcenterfinder.h.

double QxrdCenterFinder::ringAverageDisplacement
readwrite

Definition at line 130 of file qxrdcenterfinder.h.

int QxrdCenterFinder::ringIndex
readwrite

Definition at line 124 of file qxrdcenterfinder.h.

Referenced by normalizePowderRings().

double QxrdCenterFinder::ringRadius
readwrite

Definition at line 73 of file qxrdcenterfinder.h.

double QxrdCenterFinder::ringRadiusA
readwrite

Definition at line 76 of file qxrdcenterfinder.h.

double QxrdCenterFinder::ringRadiusB
readwrite

Definition at line 79 of file qxrdcenterfinder.h.

double QxrdCenterFinder::ringRotation
readwrite

Definition at line 82 of file qxrdcenterfinder.h.

bool QxrdCenterFinder::subtractRingAverages
readwrite

Definition at line 127 of file qxrdcenterfinder.h.

double QxrdCenterFinder::tiltPlaneRotation
readwrite

Definition at line 61 of file qxrdcenterfinder.h.

double QxrdCenterFinder::tiltPlaneRotationStep
readwrite

Definition at line 64 of file qxrdcenterfinder.h.


The documentation for this class was generated from the following files: