Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Quadric3.cpp
1 #include "Quadric3.hh"
2 
3 using namespace BIAS;
4 using namespace std;
5 
6 namespace BIAS {
7 
8 Quadric3::Quadric3(double a, double b, double c, double d, double area){
9  a2 = a*a;
10  ab = a*b;
11  ac = a*c;
12  ad = a*d;
13  b2 = b*b;
14  bc = b*c;
15  bd = b*d;
16  c2 = c*c;
17  cd = c*d;
18  d2 = d*d;
19 
20  r = area;
21 }
22 
24  return Vector3<double>(ad,bd,cd);
25 }
26 
28  return Matrix3x3<double>(a2,ab,ac,
29  ab,b2,bc,
30  ac,bc,c2);
31 }
32 
34  return Matrix4x4<double>(a2,ab,ac,ad,
35  ab,b2,bc,bd,
36  ac,bc,c2,cd,
37  ad,bd,cd,d2);
38 }
39 
40 double Quadric3::Evaluate(double x, double y, double z){
41  return x*x*a2 + 2*x*y*ab + 2*x*z*ac + 2*x*ad
42  + y*y*b2 + 2*y*z*bc + 2*y*bd
43  + z*z*c2 + 2*z*cd
44  + d2;
45 }
46 
48  Matrix3x3<double> Ainv;
49  Ainv = GetTensor();
50  Ainv.InvertIP();
51  double det = Ainv.GetDeterminant();
52 
53  if(det < 1e-12)
54  return false;
55 
56  Ainv.Mult(GetVector(),v);
57  v.MultIP(-1);
58  return true;
59 }
60 
62 operator=(const Quadric3& Q){
63  r = Q.r;
64 
65  a2 = Q.a2; ab = Q.ab; ac = Q.ac; ad = Q.ad;
66  b2 = Q.b2; bc = Q.bc; bd = Q.bd;
67  c2 = Q.c2; cd = Q.cd;
68  d2 = Q.d2;
69 
70  return *this;
71 }
72 
75 {
76  // Accumulate area
77  r += Q.r;
78 
79  // Accumulate coefficients
80  a2 += Q.a2; ab += Q.ab; ac += Q.ac; ad += Q.ad;
81  b2 += Q.b2; bc += Q.bc; bd += Q.bd;
82  c2 += Q.c2; cd += Q.cd;
83  d2 += Q.d2;
84 
85  return *this;
86 }
87 
89 operator*=(double s)
90 {
91  // Accumulate coefficients
92  a2 *= s; ab *= s; ac *= s; ad *= s;
93  b2 *= s; bc *= s; bd *= s;
94  c2 *= s; cd *= s;
95  d2 *= s;
96 
97  return *this;
98 }
99 
100 }//end namespace BIAS
101 
bool Optimize(Vector3< double > &v)
Definition: Quadric3.cpp:47
Quadric3 & operator*=(double s)
Definition: Quadric3.cpp:89
double Evaluate(double x, double y, double z)
Definition: Quadric3.cpp:40
Vector3< double > GetVector()
Definition: Quadric3.cpp:23
void Mult(const Vector3< T > &argvec, Vector3< T > &destvec) const
matrix - vector multiplicate this matrix with Vector3, storing the result in destvec calculates: dest...
Definition: Matrix3x3.hh:302
Matrix3x3< double > GetTensor()
Definition: Quadric3.cpp:27
Quadric3 & operator+=(const Quadric3 &Q)
Definition: Quadric3.cpp:74
void MultIP(const T &scalar)
Definition: Vector3.hh:327
T GetDeterminant() const
returns the Determinant |A| of this
Definition: Matrix3x3.cpp:347
Matrix4x4< double > GetHomogenous()
Definition: Quadric3.cpp:33
int InvertIP()
In place matrix conversion.
Definition: Matrix3x3.cpp:420
Implements a 3D quadric and quadric operations.
Definition: Quadric3.hh:25
Quadric3 & operator=(const Quadric3 &Q)
Definition: Quadric3.cpp:62