61 normRv(rotation_axis, q_vector);
65 Q.
s =
_cos(q_angle/2.0f);
84 const unsigned int n = (
unsigned int) P.size();
85 for(
unsigned int i=0; i<n; i++)
95 const unsigned int n = (
unsigned int) P.size();
99 for(
unsigned int i=0; i<n; i++)
103 Qp.at(i).v[0] = Q.at(i).v[0] / Q.at(i).v[2];
104 Qp.at(i).v[1] = Q.at(i).v[1] / Q.at(i).v[2];
118 const real_t cosAsinB = cosA * sinB;
119 const real_t sinAsinB = sinA * sinB;
121 R.
m[0][0] = cosA*cosB;
122 R.
m[0][1] = cosAsinB*sinC-sinA*cosC;
123 R.
m[0][2] = cosAsinB*cosC+sinA*sinC;
125 R.
m[1][0] = sinA*cosB;
126 R.
m[1][1] = sinAsinB*sinC+cosA*cosC;
127 R.
m[1][2] = sinAsinB*cosC-cosA*sinC;
130 R.
m[2][1] = cosB*sinC;
131 R.
m[2][2] = cosB*cosC;
136 const real_t sinB = -(R.
m[2][0]);
141 const real_t sinA = R.
m[1][0] / cosB;
142 const real_t cosA = R.
m[0][0] / cosB;
143 const real_t sinC = R.
m[2][1] / cosB;
144 const real_t cosC = R.
m[2][2] / cosB;
149 const real_t sinC = (R.
m[0][1] - R.
m[1][2]) / 2.0
f;
150 const real_t cosC = (R.
m[1][1] - R.
m[0][2]) / 2.0
f;
201 const unsigned int n = (
unsigned int) P.size();
272 const unsigned int n = (
unsigned int) P.size();
282 const bool mask_z[3] = {0,0,1};
289 V.
v[0] = Q.at(i).v[0] / Q.at(i).v[2];
290 V.
v[1] = Q.at(i).v[1] / Q.at(i).v[2];
317 if(!initR_approximate)
348 abskernel(Ri,ti,Qi,old_err,P,Q,F,tFactor);
353 abskernel(Ri,ti,Qi,new_err,P,Qi,F,tFactor);
356 while((
_abs((old_err-new_err)/old_err) > options.
tol) && (new_err > options.
epsilon) &&
360 abskernel(Ri,ti,Qi,new_err,P,Qi,F,tFactor);
376 for(
unsigned int j=0; j<n; j++)
402 const unsigned int n = (
unsigned int) v.size();
423 const real_t v11 = V.at(i).m[0][0];
424 const real_t v21 = V.at(i).m[1][0];
425 const real_t v31 = V.at(i).m[2][0];
426 const real_t v12 = V.at(i).m[0][1];
427 const real_t v22 = V.at(i).m[1][1];
428 const real_t v32 = V.at(i).m[2][1];
429 const real_t v13 = V.at(i).m[0][2];
430 const real_t v23 = V.at(i).m[1][2];
431 const real_t v33 = V.at(i).m[2][2];
432 const real_t px = p.at(i).v[0];
433 const real_t py = p.at(i).v[1];
434 const real_t pz = p.at(i).v[2];
446 _o.
m[0][0] = (((v11-
real_t(1))*r2+v12*r5+v13*r8)*py+(-(v11-
real_t(1))*r1-v12*r4-v13*r7)*px+(-(v11-
real_t(1))*r3-v12*r6-v13*r9)*pz);
448 _o.
m[0][2] = ((v11-
real_t(1))*r1+v12*r4+v13*r7)*px+((v11-
real_t(1))*r3+v12*r6+v13*r9)*pz+((v11-
real_t(1))*r2+v12*r5+v13*r8)*py;
450 _o.
m[1][0] = ((v21*r2+(v22-
real_t(1))*r5+v23*r8)*py+(-v21*r1-(v22-
real_t(1))*r4-v23*r7)*px+(-v21*r3-(v22-
real_t(1))*r6-v23*r9)*pz);
452 _o.
m[1][2] = (v21*r1+(v22-
real_t(1))*r4+v23*r7)*px+(v21*r3+(v22-
real_t(1))*r6+v23*r9)*pz+(v21*r2+(v22-
real_t(1))*r5+v23*r8)*py;
454 _o.
m[2][0] = ((v31*r2+v32*r5+(v33-
real_t(1))*r8)*py+(-v31*r1-v32*r4-(v33-
real_t(1))*r7)*px+(-v31*r3-v32*r6-(v33-
real_t(1))*r9)*pz);
456 _o.
m[2][2] = (v31*r1+v32*r4+(v33-
real_t(1))*r7)*px+(v31*r3+v32*r6+(v33-
real_t(1))*r9)*pz+(v31*r2+v32*r5+(v33-
real_t(1))*r8)*py;
463 real_t E_2[5] = {0,0,0,0,0};
467 const real_t v11 = V.at(i).m[0][0];
468 const real_t v21 = V.at(i).m[1][0];
469 const real_t v31 = V.at(i).m[2][0];
470 const real_t v12 = V.at(i).m[0][1];
471 const real_t v22 = V.at(i).m[1][1];
472 const real_t v32 = V.at(i).m[2][1];
473 const real_t v13 = V.at(i).m[0][2];
474 const real_t v23 = V.at(i).m[1][2];
475 const real_t v33 = V.at(i).m[2][2];
477 const real_t px = p.at(i).v[0];
478 const real_t py = p.at(i).v[1];
479 const real_t pz = p.at(i).v[2];
492 vec3_t _E2_0,_E2_1,_E2_2,_E2_3,_E2_4;
533 at.assign(at_sol.begin(),at_sol.end());
540 at.assign(at_sol.begin(),at_sol.end());
548 for(i=0; i<at.size(); i++)
550 if(
_abs(e[i]) <
real_t(1e-3)) at_.push_back(at_sol[i]);
559 for(i=0; i<at_.size(); i++)
561 if(
_abs(p1[i]) >
real_t(0.1
f)) at.push_back(at_[i]);
579 _c_tMaxMin.resize(at.size());
584 _at.assign(at.begin(),at.end());
592 _at.assign(at.begin(),at.end());
599 scalar_array tMaxMin(_c_tMaxMin.begin(),_c_tMaxMin.end());
602 for(i=0; i<tMaxMin.size(); i++)
604 if(tMaxMin.at(i) > 0) al_.push_back(al.at(i));
607 tnew.resize(al_.size());
608 for(
unsigned int a=0; a<al_.size(); a++)
634 al_ret.assign(al_.begin(),al_.end());
663 const unsigned int n = (
unsigned int) v.size();
666 for(
unsigned int i=0; i<n; i++)
673 sol.resize(bl.size());
675 for(
unsigned int j=0; j<(
unsigned int)bl.size(); j++)
685 for(
unsigned int i=0; i<n; i++)
728 for(
unsigned int i=0; i<sol.size(); i++)
751 vec3_array model(_model.begin(),_model.end());
752 vec3_array iprts(_iprts.begin(),_iprts.end());
754 memcpy(&options,&_options,
sizeof(
options_t));
762 objpose(Rlu_, tlu_, it1_, obj_err1_, img_err1_,
true, model, iprts, options);
767 int min_err_idx = (-1);
769 for(
unsigned int i=0; i<sol.size(); i++)
772 objpose(Rlu_, tlu_, it1_, obj_err1_, img_err1_,
true, model, iprts, options);
775 sol[i].obj_err = obj_err1_;
776 if(sol[i].obj_err < min_err)
778 min_err = sol[i].obj_err;
787 err = sol[min_err_idx].obj_err;
real_t vec3trans_mul_vec3(const vec3_t &va, const vec3_t &vb)
void scalar_array_clear(scalar_array &sa)
std::vector< pose_t > pose_vec
void mat33_eye(mat33_t &m)
void mat33_svd2(mat33_t &u, mat33_t &s, mat33_t &v, const mat33_t &m)
void rpyAng_X(vec3_t &ang_zyx, const mat33_t &R)
void mat33_to_col_vec3(vec3_t &c0, vec3_t &c1, vec3_t &c2, const mat33_t &m)
void normRv(vec3_t &n, const vec3_t &v)
void objpose(mat33_t &R, vec3_t &t, unsigned int &it, real_t &obj_err, real_t &img_err, bool calc_img_err, const vec3_array _P, const vec3_array Qp, const options_t options)
void mat33_div(mat33_t &m, const real_t f)
void vec3_array_sub(vec3_array &va, const vec3_t &a)
void mat33_mult(mat33_t &m0, const mat33_t &m1, const mat33_t &m2)
std::vector< mat33_t > mat33_array
void abskernel(mat33_t &R, vec3_t &t, vec3_array &Qout, real_t &err2, const vec3_array _P, const vec3_array _Q, const mat33_array F, const mat33_t G)
void Quaternion_byAngleAndVector(quat_t &Q, const real_t &q_angle, const vec3_t &q_vector)
void scalar_array_negate(scalar_array &sa)
real_t vec3_dot(const vec3_t &va, const vec3_t &vb)
void rpyAng(vec3_t &angs, const mat33_t &R)
void scalar_array_mult(scalar_array &sa, real_t f)
bool mat33_all_zeros(const mat33_t &m)
void rpyMat(mat33_t &R, const vec3_t &rpy)
std::vector< vec3_t > vec3_array
void quat_mult(quat_t &q, const real_t s)
void mat33_clear(mat33_t &m)
void vec3_cross(vec3_t &va, const vec3_t &vb, const vec3_t &vc)
void mat33_assign(mat33_t &m, const real_t m00, const real_t m01, const real_t m02, const real_t m10, const real_t m11, const real_t m12, const real_t m20, const real_t m21, const real_t m22)
void vec3_array_mult(vec3_array &va, const scalar_array &c)
std::vector< real_t > scalar_array
void scalar_array_atan2(scalar_array &sa, const scalar_array &sb, const scalar_array &sc)
void mat33_from_quat(mat33_t &m, const quat_t &q)
void scalar_array_add(scalar_array &sa, const scalar_array &sb)
void GetRotationbyVector(mat33_t &R, const vec3_t &v1, const vec3_t &v2)
void get2ndPose_Exact(pose_vec &sol, const vec3_array &v, const vec3_array &P, const mat33_t R, const vec3_t t, const real_t DB)
void mat33_sub(mat33_t &mr, const mat33_t &ma, const mat33_t &mb)
void xform(vec3_array &Q, const vec3_array &P, const mat33_t &R, const vec3_t &t)
real_t vec3_sum(const vec3_t &v)
void vec3_add(vec3_t &va, const real_t f)
void mat33_inv(mat33_t &mi, const mat33_t &ma)
int solve_polynomial(scalar_array &r_sol, const scalar_array &coefficients)
void scalar_array_pow(scalar_array &sa, const real_t f)
void decomposeR(mat33_t &Rz, const mat33_t &R)
void mat33_array_sum(mat33_t &s, const mat33_array &ma)
real_t quat_norm(const quat_t &q)
void vec3_mul_vec3trans(mat33_t &m, const vec3_t &va, const vec3_t &vb)
void vec3_array_mean(vec3_t &v_mean, const vec3_array &va)
void vec3_clear(vec3_t &v)
void getRotationY_wrtT(scalar_array &al_ret, vec3_array &tnew, const vec3_array &v, const vec3_array &p, const vec3_t &t, const real_t &DB, const mat33_t &Rz)
void vec3_sub(vec3_t &va, const real_t f)
void vec3_array_sum(vec3_t &v_sum2, const vec3_array &va)
void mat33_copy(mat33_t &md, const mat33_t &ms)
void vec3_div(vec3_t &va, const real_t n)
void getRfor2ndPose_V_Exact(pose_vec &sol, const vec3_array &v, const vec3_array &P, const mat33_t R, const vec3_t t, const real_t DB)
real_t _atan2(real_t a, real_t b)
void robust_pose(real_t &err, mat33_t &R, vec3_t &t, const vec3_array &_model, const vec3_array &_iprts, const options_t _options)
void mat33_transpose(mat33_t &t, const mat33_t m)
void mat33_add(mat33_t &mr, const mat33_t &ma, const mat33_t &mb)
void vec3_array_set(vec3_array &va, const vec3_t &a, const bool mask[3])
void vec3_copy(vec3_t &a, const vec3_t &b)
void scalar_array_div(scalar_array &sa, real_t f)
void vec3_assign(vec3_t &v, const real_t x, const real_t y, const real_t z)
void xformproj(vec3_array &Qp, const vec3_array &P, const mat33_t &R, const vec3_t &t)
void vec3_mult(vec3_t &va, const real_t n)