61 #ifndef OPENMESH_GEOMETRY_QUADRIC_HH 62 #define OPENMESH_GEOMETRY_QUADRIC_HH 68 #include <OpenMesh/Core/Geometry/VectorT.hh> 69 #include <OpenMesh/Core/Utils/GenProg.hh> 86 template <
class Scalar>
90 typedef Scalar value_type;
99 QuadricT(Scalar _a, Scalar _b, Scalar _c, Scalar _d,
100 Scalar _e, Scalar _f, Scalar _g,
101 Scalar _h, Scalar _i,
103 : a_(_a), b_(_b), c_(_c), d_(_d),
104 e_(_e), f_(_f), g_(_g),
112 QuadricT( Scalar _a=0.0, Scalar _b=0.0, Scalar _c=0.0, Scalar _d=0.0 )
113 : a_(_a*_a), b_(_a*_b), c_(_a*_c), d_(_a*_d),
114 e_(_b*_b), f_(_b*_c), g_(_b*_d),
115 h_(_c*_c), i_(_c*_d),
119 template <
class _Po
int>
122 set_distance_to_point(_pt);
125 template <
class _Normal,
class _Po
int>
126 QuadricT(
const _Normal& _n,
const _Point& _p)
128 set_distance_to_plane(_n,_p);
132 void set(Scalar _a, Scalar _b, Scalar _c, Scalar _d,
133 Scalar _e, Scalar _f, Scalar _g,
134 Scalar _h, Scalar _i,
137 a_ = _a; b_ = _b; c_ = _c; d_ = _d;
138 e_ = _e; f_ = _f; g_ = _g;
144 template <
class _Po
int>
145 void set_distance_to_point(
const _Point& _pt)
147 set(1, 0, 0, -_pt[0],
154 void set_distance_to_plane(Scalar _a, Scalar _b, Scalar _c, Scalar _d)
156 a_ = _a*_a; b_ = _a*_b; c_ = _a*_c; d_ = _a*_d;
157 e_ = _b*_b; f_ = _b*_c; g_ = _b*_d;
158 h_ = _c*_c; i_ = _c*_d;
164 template <
class _Normal,
class _Po
int>
165 void set_distance_to_plane(
const _Normal& _n,
const _Point& _p)
167 set_distance_to_plane(_n[0], _n[1], _n[2], -
dot(_n,_p));
171 void clear() { a_ = b_ = c_ = d_ = e_ = f_ = g_ = h_ = i_ = j_ = 0.0; }
176 a_ += _q.a_; b_ += _q.b_; c_ += _q.c_; d_ += _q.d_;
177 e_ += _q.e_; f_ += _q.f_; g_ += _q.g_;
178 h_ += _q.h_; i_ += _q.i_;
187 a_ *= _s; b_ *= _s; c_ *= _s; d_ *= _s;
188 e_ *= _s; f_ *= _s; g_ *= _s;
196 template <
class _Vec4>
199 Scalar x(_v[0]), y(_v[1]), z(_v[2]), w(_v[3]);
200 return _Vec4(x*a_ + y*b_ + z*c_ + w*d_,
201 x*b_ + y*e_ + z*f_ + w*g_,
202 x*c_ + y*f_ + z*h_ + w*i_,
203 x*d_ + y*g_ + z*i_ + w*j_);
207 template <
class _Vec>
210 return evaluate(_v, GenProg::Int2Type<_Vec::size_>());
213 Scalar a()
const {
return a_; }
214 Scalar b()
const {
return b_; }
215 Scalar c()
const {
return c_; }
216 Scalar d()
const {
return d_; }
217 Scalar e()
const {
return e_; }
218 Scalar f()
const {
return f_; }
219 Scalar g()
const {
return g_; }
220 Scalar h()
const {
return h_; }
221 Scalar i()
const {
return i_; }
222 Scalar j()
const {
return j_; }
224 Scalar xx()
const {
return a_; }
225 Scalar xy()
const {
return b_; }
226 Scalar xz()
const {
return c_; }
227 Scalar xw()
const {
return d_; }
228 Scalar yy()
const {
return e_; }
229 Scalar yz()
const {
return f_; }
230 Scalar yw()
const {
return g_; }
231 Scalar zz()
const {
return h_; }
232 Scalar zw()
const {
return i_; }
233 Scalar ww()
const {
return j_; }
238 template <
class _Vec3>
239 Scalar
evaluate(
const _Vec3& _v, GenProg::Int2Type<3>)
const 241 Scalar x(_v[0]), y(_v[1]), z(_v[2]);
242 return a_*x*x + 2.0*b_*x*y + 2.0*c_*x*z + 2.0*d_*x
243 + e_*y*y + 2.0*f_*y*z + 2.0*g_*y
249 template <
class _Vec4>
250 Scalar
evaluate(
const _Vec4& _v, GenProg::Int2Type<4>)
const 252 Scalar x(_v[0]), y(_v[1]), z(_v[2]), w(_v[3]);
253 return a_*x*x + 2.0*b_*x*y + 2.0*c_*x*z + 2.0*d_*x*w
254 + e_*y*y + 2.0*f_*y*z + 2.0*g_*y*w
255 + h_*z*z + 2.0*i_*z*w
261 Scalar a_, b_, c_, d_,
279 #endif // OPENMESH_GEOMETRY_HH defined _Vec4 operator*(const _Vec4 &_v) const
multiply 4D vector from right: Q*v
QuadricT(Scalar _a=0.0, Scalar _b=0.0, Scalar _c=0.0, Scalar _d=0.0)
constructor from given plane equation: ax+by+cz+d_=0
QuadricT< Scalar > & operator+=(const QuadricT< Scalar > &_q)
add quadrics
QuadricT(Scalar _a, Scalar _b, Scalar _c, Scalar _d, Scalar _e, Scalar _f, Scalar _g, Scalar _h, Scalar _i, Scalar _j)
construct with upper triangle of symmetrix 4x4 matrix
Scalar operator()(const _Vec &_v) const
evaluate quadric Q at (3D or 4D) vector v: v*Q*v
Scalar evaluate(const _Vec4 &_v, GenProg::Int2Type< 4 >) const
evaluate quadric Q at 4D vector v: v*Q*v
QuadricT< Scalar > & operator*=(Scalar _s)
multiply by scalar
Scalar evaluate(const _Vec3 &_v, GenProg::Int2Type< 3 >) const
evaluate quadric Q at 3D vector v: v*Q*v
void clear()
set all entries to zero
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.