11 m_DistortionImagePath(saver, this,
"distortionImagePath",
"",
"File path for distortion calibration image"),
12 m_P0(saver, this,
"p0", QPointF(100,100),
"Origin of distortion image grid"),
13 m_P1(saver, this,
"p1", QPointF(200,100),
"1st X Position on distortion grid"),
14 m_P2(saver, this,
"p2", QPointF(100,200),
"1st Y Position on distortion grid"),
15 m_N1(saver, this,
"n1", 40,
"Number of grid points along x"),
16 m_N2(saver, this,
"n2", 40,
"Number of grid points along y"),
17 m_F0(saver, this,
"f0", QPointF(100,100),
"Fitted Origin of distortion image grid"),
18 m_F1(saver, this,
"f1", QPointF(200,100),
"Fitted 1st X Position on distortion grid"),
19 m_F2(saver, this,
"f2", QPointF(100,200),
"Fitted 1st Y Position on distortion grid"),
20 m_IVals(saver, this,
"iVals",
QcepIntVector(),
"Grid point i indices"),
21 m_JVals(saver, this,
"jVals",
QcepIntVector(),
"Grid point j indices"),
28 m_WMin(saver, this,
"wMin", 1,
"Minimum acceptable grid peak width (pixels)"),
29 m_WMax(saver, this,
"wMax", 4,
"Maximum acceptable grid peak width (pixels)"),
30 m_WNom(saver, this,
"wNom", 2,
"Nominal initial grid peak width (pixels)"),
31 m_RatMin(saver, this,
"ratMin", 3,
"Minimum acceptable peak/background ratio for grid peaks"),
32 m_HgtMin(saver, this,
"hgtMin", 1000,
"Minimum acceptable peak height for grid peaks"),
33 m_DistMax(saver, this,
"distMax", QPointF(5,5),
"Maximum acceptable grid peak position distance from nominal"),
50 prop_IVals()->clear();
51 prop_JVals()->clear();
52 prop_XVals()->clear();
53 prop_YVals()->clear();
54 prop_FXVals()->clear();
55 prop_FYVals()->clear();
56 prop_DXVals()->clear();
57 prop_DYVals()->clear();
62 prop_IVals()->appendValue(i);
63 prop_JVals()->appendValue(j);
64 prop_XVals()->appendValue(x);
65 prop_YVals()->appendValue(y);
74 double p0x = parms[0];
75 double p0y = parms[1];
76 double dxx = parms[2]-p0x;
77 double dxy = parms[3]-p0y;
78 double dyx = parms[4]-p0x;
79 double dyy = parms[5]-p0y;
81 for (
int i=0; i<n; i++) {
82 int ii = get_IVals()[i];
83 int jj = get_JVals()[i];
84 double fx = p0x + ii*dxx + jj*dyx;
85 double fy = p0y + ii*dxy + jj*dyy;
87 double dx = fx - get_XVals()[i];
88 double dy = fy - get_YVals()[i];
90 hx[i] = sqrt(dx*dx + dy*dy);
94 static void fitGrid(
double parms[],
double hx[],
int m,
int n,
void *adata)
107 parms[0] = get_P0().x();
108 parms[1] = get_P0().y();
109 parms[2] = get_P1().x();
110 parms[3] = get_P1().y();
111 parms[4] = get_P2().x();
112 parms[5] = get_P2().y();
114 double info[LM_INFO_SZ];
116 int ndata = get_IVals().count();
118 int niter = dlevmar_dif(
fitGrid, parms, NULL, 6, ndata, 300, NULL, info, NULL, NULL,
this);
121 set_F0(QPointF(parms[0], parms[1]));
122 set_F1(QPointF(parms[2], parms[3]));
123 set_F2(QPointF(parms[4], parms[5]));
129 double p0x = get_F0().x();
130 double p0y = get_F0().y();
131 double dxx = get_F1().x() - p0x;
132 double dxy = get_F1().y() - p0y;
133 double dyx = get_F2().x() - p0x;
134 double dyy = get_F2().y() - p0y;
136 int n = get_IVals().count();
138 for (
int i=0; i<n; i++) {
139 int ii = get_IVals()[i];
140 int jj = get_JVals()[i];
141 double fx = p0x + ii*dxx + jj*dyx;
142 double fy = p0y + ii*dxy + jj*dyy;
144 double dx = fx - get_XVals()[i];
145 double dy = fy - get_YVals()[i];
147 prop_FXVals()->appendValue(fx);
148 prop_FYVals()->appendValue(fy);
149 prop_DXVals()->appendValue(dx);
150 prop_DYVals()->appendValue(dy);
156 int n = get_IVals().count();
160 FILE *f = fopen(qPrintable(path),
"a+");
163 fprintf(f,
"i\tj\tx\ty\tfx\tfy\tdx\tdy\n");
165 for (
int i=0; i<n; i++) {
166 fprintf(f,
"%d\t%d\t%g\t%g\t%g\t%g\t%g\t%g\n",
167 get_IVals()[i], get_JVals()[i],
168 get_XVals()[i], get_YVals()[i],
169 get_FXVals()[i], get_FYVals()[i],
170 get_DXVals()[i], get_DYVals()[i]);
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
QVector< int > QcepIntVector
static void fitGrid(double parms[], double hx[], int m, int n, void *adata)
QWeakPointer< QxrdExperiment > QxrdExperimentWPtr
void evalCalibrationGrid()
void evaluateFitGrid(double parms[], double hx[], int m, int n)
QVector< double > QcepDoubleVector
QPointF inverse(QPointF pt)
void appendGridPoint(int i, int j, double x, double y)
QPointF transform(QPointF pt)
void dumpCalibrationGrid(QString path)
QxrdDistortionCorrection(QcepSettingsSaverWPtr saver, QxrdExperimentWPtr expt)
QxrdExperimentWPtr m_Experiment
void fitCalibrationGrid()
QWeakPointer< QcepSettingsSaver > QcepSettingsSaverWPtr