00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00035
00036
00037
00038
00039
00040
00041 #ifndef OPENMESH_GEOMETRY_QUADRIC_HH
00042 #define OPENMESH_GEOMETRY_QUADRIC_HH
00043
00044
00045
00046
00047 #include "Config.hh"
00048 #include <OpenMesh/Core/Math/VectorT.hh>
00049
00050
00051
00052 namespace OpenMesh {
00053 namespace Geometry {
00054
00055
00056
00057
00058
00065 template <class Scalar,
00066 class Vector3Elem = VectorT<Scalar, 3>,
00067 class Vector4Elem = VectorT<Scalar, 4> >
00068 class QuadricT
00069 {
00070 public:
00071 typedef Scalar value_type;
00072 typedef QuadricT<Scalar> type;
00073 typedef QuadricT<Scalar> Self;
00074
00075
00076 typedef Vector3Elem Vec3;
00077 typedef Vector4Elem Vec4;
00078
00080 QuadricT(Scalar _a, Scalar _b, Scalar _c, Scalar _d,
00081 Scalar _e, Scalar _f, Scalar _g,
00082 Scalar _h, Scalar _i,
00083 Scalar _j)
00084 : a(_a), b(_b), c(_c), d(_d),
00085 e(_e), f(_f), g(_g),
00086 h(_h), i(_i),
00087 j(_j)
00088 {}
00089
00090
00092 QuadricT( Scalar _a=0.0, Scalar _b=0.0, Scalar _c=0.0, Scalar _d=0.0 )
00093 : a(_a*_a), b(_a*_b), c(_a*_c), d(_a*_d),
00094 e(_b*_b), f(_b*_c), g(_b*_d),
00095 h(_c*_c), i(_c*_d),
00096 j(_d*_d)
00097 {}
00098
00099
00101 void clear() { a = b = c = d = e = f = g = h = i = j = 0.0; }
00102
00103
00105 QuadricT<Scalar>& operator+=( const QuadricT<Scalar>& _q )
00106 {
00107 a += _q.a; b += _q.b; c += _q.c; d += _q.d;
00108 e += _q.e; f += _q.f; g += _q.g;
00109 h += _q.h; i += _q.i;
00110 j += _q.j;
00111 return *this;
00112 }
00113
00114
00116 QuadricT<Scalar>& operator*=( Scalar _s)
00117 {
00118 a *= _s; b *= _s; c *= _s; d *= _s;
00119 e *= _s; f *= _s; g *= _s;
00120 h *= _s; i *= _s;
00121 j *= _s;
00122 return *this;
00123 }
00124
00125
00127 Vec4 operator*(const Vec4& _v) const
00128 {
00129 return Vec4(_v[0]*a + _v[1]*b + _v[2]*c + _v[3]*d,
00130 _v[0]*b + _v[1]*e + _v[2]*f + _v[3]*g,
00131 _v[0]*c + _v[1]*f + _v[2]*h + _v[3]*i,
00132 _v[0]*d + _v[1]*g + _v[2]*i + _v[3]*j);
00133 }
00134
00135
00137 Scalar operator()(const Vec3 _v) const
00138 {
00139 Scalar x(_v[0]), y(_v[1]), z(_v[2]);
00140 return a*x*x + 2.0*b*x*y + 2.0*c*x*z + 2.0*d*x
00141 + e*y*y + 2.0*f*y*z + 2.0*g*y
00142 + h*z*z + 2.0*i*z
00143 + j;
00144 }
00145
00146
00148 Scalar operator()(const Vec4 _v) const
00149 {
00150 Scalar x(_v[0]), y(_v[1]), z(_v[2]), w(_v[3]);
00151 return a*x*x + 2.0*b*x*y + 2.0*c*x*z + 2.0*d*x*w
00152 + e*y*y + 2.0*f*y*z + 2.0*g*y*w
00153 + h*z*z + 2.0*i*z*w
00154 + j*w*w;
00155 }
00156
00157
00158 private:
00159
00160 Scalar a, b, c, d,
00161 e, f, g,
00162 h, i,
00163 j;
00164 };
00165
00166
00168 typedef QuadricT<float> Quadricf;
00169
00171 typedef QuadricT<double> Quadricd;
00172
00173
00174
00175 }
00176 }
00177
00178 #endif // OPENMESH_GEOMETRY_HH defined
00179