50 #include <visp/vpLevenbergMarquartd.h>
51 #include <visp/vpPose.h>
55 #define MINIMUM 0.000001
57 #define DEBUG_LEVEL1 0
84 #define MIJ(m,i,j,s) ((m) + ((long) (i) * (long) (s)) + (long) (j))
88 static double XI[NBPTMAX],YI[NBPTMAX];
89 static double XO[NBPTMAX],YO[NBPTMAX],ZO[NBPTMAX];
93 #define MINIMUM 0.000001
95 void eval_function(
int npt,
double *xc,
double *f);
96 void fcn (
int m,
int n,
double *xc,
double *fvecc,
double *jac,
int ldfjac,
int iflag);
98 void eval_function(
int npt,
double *xc,
double *f)
111 x = rd[0][0]*XO[i] + rd[0][1]*YO[i] + rd[0][2]*ZO[i] + xc[0];
112 y = rd[1][0]*XO[i] + rd[1][1]*YO[i] + rd[1][2]*ZO[i] + xc[1];
113 z = rd[2][0]*XO[i] + rd[2][1]*YO[i] + rd[2][2]*ZO[i] + xc[2];
115 f[npt+i] = y/z - YI[i];
147 void fcn (
int m,
int n,
double *xc,
double *fvecc,
double *jac,
int ldfjac,
int iflag)
149 double u[X3_SIZE], rx, ry, rz;
150 double tt, mco, co, si, u1, u2, u3, x, y, z;
151 double drxt, drxu1, drxu2, drxu3;
152 double dryt, dryu1, dryu2, dryu3;
153 double drzt, drzu1, drzu2, drzu3;
154 double dxit, dxiu1, dxiu2, dxiu3;
155 double dyit, dyiu1, dyiu2, dyiu3;
160 if (m < n) printf(
"pas assez de points\n");
163 if (iflag == 1) eval_function (npt, xc, fvecc);
174 tt = sqrt (u[0] * u[0] + u[1] * u[1] + u[2] * u[2]);
181 else u1 = u2 = u3 = 0.0;
186 for (i = 0; i < npt; i++)
193 rx = rd[0][0] * x + rd[0][1] * y + rd[0][2] * z + xc[0];
194 ry = rd[1][0] * x + rd[1][1] * y + rd[1][2] * z + xc[1];
195 rz = rd[2][0] * x + rd[2][1] * y + rd[2][2] * z + xc[2];
200 drxt = (si * u1 * u3 + co * u2) * z + (si * u1 * u2 - co * u3) * y
201 + (si * u1 * u1 - si) * x;
202 drxu1 = mco * u3 * z + mco * u2 * y + 2 * mco * u1 * x;
203 drxu2 = si * z + mco * u1 * y;
204 drxu3 = mco * u1 * z - si * y;
206 dryt = (si * u2 * u3 - co * u1) * z + (si * u2 * u2 - si) * y
207 + (co * u3 + si * u1 * u2) * x;
208 dryu1 = mco * u2 * x - si * z;
209 dryu2 = mco * u3 * z + 2 * mco * u2 * y + mco * u1 * x;
210 dryu3 = mco * u2 * z + si * x;
212 drzt = (si * u3 * u3 - si) * z + (si * u2 * u3 + co * u1) * y
213 + (si * u1 * u3 - co * u2) * x;
214 drzu1 = si * y + mco * u3 * x;
215 drzu2 = mco * u3 * y - si * x;
216 drzu3 = 2 * mco * u3 * z + mco * u2 * y + mco * u1 * x;
221 dxit = drxt / rz - rx * drzt / (rz * rz);
223 dyit = dryt / rz - ry * drzt / (rz * rz);
225 dxiu1 = drxu1 / rz - drzu1 * rx / (rz * rz);
226 dyiu1 = dryu1 / rz - drzu1 * ry / (rz * rz);
228 dxiu2 = drxu2 / rz - drzu2 * rx / (rz * rz);
229 dyiu2 = dryu2 / rz - drzu2 * ry / (rz * rz);
231 dxiu3 = drxu3 / rz - drzu3 * rx / (rz * rz);
232 dyiu3 = dryu3 / rz - drzu3 * ry / (rz * rz);
238 *MIJ(jac, 0, i, ldfjac) = 1 / rz;
239 *MIJ(jac, 1, i, ldfjac) = 0.0;
240 *MIJ(jac, 2, i, ldfjac) = - rx / (rz * rz);
243 *MIJ(jac, 3, i, ldfjac) = u1 * dxit + (1 - u1 * u1) * dxiu1 / tt
244 - u1 * u2 * dxiu2 / tt - u1 * u3 * dxiu3 / tt;
245 *MIJ(jac, 4, i, ldfjac) = u2 * dxit - u1 * u2 * dxiu1 / tt
246 + (1 - u2 * u2) * dxiu2 / tt- u2 * u3 * dxiu3 / tt;
248 *MIJ(jac, 5, i, ldfjac) = u3 * dxit - u1 * u3 * dxiu1 / tt - u2 * u3 * dxiu2 / tt
249 + (1 - u3 * u3) * dxiu3 / tt;
253 *MIJ(jac, 3, i, ldfjac) = 0.0;
254 *MIJ(jac, 4, i, ldfjac) = 0.0;
255 *MIJ(jac, 5, i, ldfjac) = 0.0;
257 *MIJ(jac, 0, npt + i, ldfjac) = 0.0;
258 *MIJ(jac, 1, npt + i, ldfjac) = 1 / rz;
259 *MIJ(jac, 2, npt + i, ldfjac) = - ry / (rz * rz);
262 *MIJ(jac, 3, npt + i, ldfjac) = u1 * dyit + (1 - u1 * u1) * dyiu1 / tt
263 - u1 * u2 * dyiu2 / tt - u1 * u3 * dyiu3 / tt;
264 *MIJ(jac, 4, npt + i, ldfjac) = u2 * dyit - u1 * u2 * dyiu1 / tt
265 + (1 - u2 * u2) * dyiu2 / tt- u2 * u3 * dyiu3 / tt;
266 *MIJ(jac, 5, npt + i, ldfjac) = u3 * dyit - u1 * u3 * dyiu1 / tt
267 - u2 * u3 * dyiu2 / tt + (1 - u3 * u3) * dyiu3 / tt;
271 *MIJ(jac, 3, npt + i, ldfjac) = 0.0;
272 *MIJ(jac, 4, npt + i, ldfjac) = 0.0;
273 *MIJ(jac, 5, npt + i, ldfjac) = 0.0;
291 std::cout <<
"begin CCalcuvpPose::PoseLowe(...) " << std::endl;
296 int info, ipvt[NBR_PAR];
298 double f[2 * NBPTMAX], sol[NBR_PAR];
299 double tol, jac[NBR_PAR][2 * NBPTMAX], wa[2 * NBPTMAX + 50];
305 lwa = 2 * NBPTMAX + 50;
306 ldfjac = 2 * NBPTMAX;
307 tol = std::numeric_limits<double>::epsilon();
316 for (
unsigned int i=0;i<3;i++)
324 for (std::list<vpPoint>::const_iterator it =
listP.begin(); it !=
listP.end(); ++it)
334 tst_lmder = lmder1 (&fcn, m, n, sol, f, &jac[0][0], ldfjac, tol, &info, ipvt, lwa, wa);
337 std::cout <<
" in CCalculPose::PoseLowe(...) : " ;
338 std::cout <<
"pb de minimisation, returns FATAL_ERROR";
342 for (
unsigned int i = 0; i < 3; i++)
345 for (
unsigned int i=0;i<3;i++)
357 std::cout <<
"end CCalculPose::PoseLowe(...) " << std::endl;
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
double get_oY() const
Get the point Y coordinate in the object frame.
double get_y() const
Get the point y coordinate in the image plane.
std::list< vpPoint > listP
array of point (use here class vpPoint)
Class that defines what is a point.
The vpRotationMatrix considers the particular case of a rotation matrix.
void insert(const vpRotationMatrix &R)
vpRotationMatrix buildFrom(const vpHomogeneousMatrix &M)
Build a rotation matrix from an homogeneous matrix.
double get_oZ() const
Get the point Z coordinate in the object frame.
void poseLowe(vpHomogeneousMatrix &cMo)
Compute the pose using the Lowe non linear approach it consider the minimization of a residual using ...
void extract(vpRotationMatrix &R) const
double get_x() const
Get the point x coordinate in the image plane.
double get_oX() const
Get the point X coordinate in the object frame.
Class that consider the case of the parameterization for the rotation.