26 #include "Quadric3D.hh"
29 #define SVD_ZERO_THRESH DBL_EPSILON * 16.0
31 #define SINGULAR_THRESH_INVERSION 1e-20
38 const double &dScale) {
42 if (InversionResult!=0) {
50 if (S[0]<SINGULAR_THRESH_INVERSION)
51 S[0]=SINGULAR_THRESH_INVERSION;
52 if (S[1]<SINGULAR_THRESH_INVERSION)
53 S[1]=SINGULAR_THRESH_INVERSION;
54 if (S[2]<SINGULAR_THRESH_INVERSION)
55 S[2]=SINGULAR_THRESH_INVERSION;
63 InvCov = V * SdT * UT;
69 for (
unsigned int i=0; i<3; i++) {
70 for (
unsigned int j=0; j<3; j++) {
71 EllipsoidAtOrigin[i][j] = InvCov[i][j];
74 EllipsoidAtOrigin[3][3] = -1;
79 for (
int i=0; i<3; i++) {
80 MoveToOrigin[i][3] = -C[i];
82 MoveToOrigin[3][3] = C[3];
85 (*this) = MoveToOrigin.
Transpose() * (EllipsoidAtOrigin * MoveToOrigin);
102 signed char Signature = 0;
103 for (
unsigned int i=0; i<4; i++) {
105 eigenvector = VT.GetRow(i);
106 eigenimage = (*this)*eigenvector;
109 S[i] = eigenimage[0] * eigenvector[0] + eigenimage[1] * eigenvector[1]+
110 eigenimage[2] * eigenvector[2]+ eigenimage[3] * eigenvector[3];
111 if (S[i]<-SVD_ZERO_THRESH) Signature--;
112 else if (S[i]>SVD_ZERO_THRESH) Signature++;
117 if (Signature<0)
return (
unsigned int)(-Signature);
118 return (
unsigned int)Signature;
124 SVD qsvd((*
this), SVD_ZERO_THRESH,
false);
129 const QUADRIC3D_TYPE& a = (*this)[0][0];
130 const QUADRIC3D_TYPE& b = (*this)[0][1];
131 const QUADRIC3D_TYPE& c = (*this)[0][2];
132 const QUADRIC3D_TYPE& d = (*this)[0][3];
133 const QUADRIC3D_TYPE& e = (*this)[1][1];
134 const QUADRIC3D_TYPE& f = (*this)[1][2];
135 const QUADRIC3D_TYPE& g = (*this)[1][3];
136 const QUADRIC3D_TYPE& h = (*this)[2][2];
137 const QUADRIC3D_TYPE& i = (*this)[2][3];
138 const QUADRIC3D_TYPE& k = (*this)[3][3];
142 Dual[0][0] = 2.0*f*g*i - e*i*i - f*f*k + e*h*k - g*g*h;
143 Dual[1][0] = Dual[0][1] = d*g*h - d*f*i - c*g*i + b*i*i + c*f*k - b*h*k;
144 Dual[2][0] = Dual[0][2] = c*g*g + d*e*i - b*g*i - c*e*k + b*f*k -d*f*g;
145 Dual[3][0] = Dual[0][3] = b*g*h + d*f*f - d*e*h + c*e*i - b*f*i -c*f*g;
146 Dual[1][1] = 2.0*c*d*i - a*i*i - c*c*k + a*h*k -d*d*h;
147 Dual[2][1] = Dual[1][2] = a*g*i - d*(c*g + b*i - d*f) + b*c*k - a*f*k;
148 Dual[3][1] = Dual[1][3] = b*d*h - a*g*h + a*f*i - c*(d*f + b*i - c*g);
149 Dual[2][2] = 2.0*b*d*g - a*g*g - b*b*k + a*e*k - d*d*e;
150 Dual[3][2] = Dual[2][3] = c*d*e - b*d*f - b*c*g + a*f*g + b*b*i - a*e*i;
151 Dual[3][3] = 2.0*b*c*f - a*f*f - b*b*h + a*e*h -c*c*e;
computes and holds the singular value decomposition of a rectangular (not necessarily quadratic) Matr...
Matrix< T > Transpose() const
transpose function, storing data destination matrix
A quadric as a 4x4 matrix describing a surface in 3d projective space defined by a quadratic equation...
class Vector4 contains a Vector of dim.
Matrix< double > GetV() const
return V
int GetInverse(Matrix3x3< T > &inv) const
Matrix inversion: inverts this and stores resulty in argument inv.
const Matrix< double > & GetVT() const
return VT (=transposed(V))
class for 3x3 covariance matrices
Matrix4x4 Transpose() const
const Vector< double > & GetS() const
return S which is a vector of the singular values of A in descending order.
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
void SetIdentity()
set the elements of this matrix to the identity matrix (posisbly overriding the inherited method) ...
const Matrix< double > & GetU() const
return U U is a m x m orthogonal matrix
Matrix< double > Invert()
returns pseudoinverse of A = U * S * V^T A^+ = V * S^+ * U^T
unsigned int GetSignature()
computes signature of matrix, (no.
Quadric3D GetDualQuadric(bool UseSVD=false) const
computes the dual quadric (points <-> planes)