56#ifndef OPENMESH_GEOMETRY_QUADRIC_HH
57#define OPENMESH_GEOMETRY_QUADRIC_HH
63#include <OpenMesh/Core/Geometry/VectorT.hh>
64#include <OpenMesh/Core/Utils/GenProg.hh>
81template <
class Scalar>
85 typedef Scalar value_type;
94 QuadricT(Scalar _a, Scalar _b, Scalar _c, Scalar _d,
95 Scalar _e, Scalar _f, Scalar _g,
98 : a_(_a), b_(_b), c_(_c), d_(_d),
99 e_(_e), f_(_f), g_(_g),
107 QuadricT( Scalar _a=0.0, Scalar _b=0.0, Scalar _c=0.0, Scalar _d=0.0 )
108 : a_(_a*_a), b_(_a*_b), c_(_a*_c), d_(_a*_d),
109 e_(_b*_b), f_(_b*_c), g_(_b*_d),
110 h_(_c*_c), i_(_c*_d),
114 template <
class _Po
int>
115 explicit QuadricT(
const _Point& _pt)
117 set_distance_to_point(_pt);
120 template <
class _Normal,
class _Po
int>
121 QuadricT(
const _Normal& _n,
const _Point& _p)
123 set_distance_to_plane(_n,_p);
127 void set(Scalar _a, Scalar _b, Scalar _c, Scalar _d,
128 Scalar _e, Scalar _f, Scalar _g,
129 Scalar _h, Scalar _i,
132 a_ = _a; b_ = _b; c_ = _c; d_ = _d;
133 e_ = _e; f_ = _f; g_ = _g;
139 template <
class _Po
int>
140 void set_distance_to_point(
const _Point& _pt)
142 set(1, 0, 0, -_pt[0],
149 void set_distance_to_plane(Scalar _a, Scalar _b, Scalar _c, Scalar _d)
151 a_ = _a*_a; b_ = _a*_b; c_ = _a*_c; d_ = _a*_d;
152 e_ = _b*_b; f_ = _b*_c; g_ = _b*_d;
153 h_ = _c*_c; i_ = _c*_d;
159 template <
class _Normal,
class _Po
int>
160 void set_distance_to_plane(
const _Normal& _n,
const _Point& _p)
162 set_distance_to_plane(_n[0], _n[1], _n[2], -
dot(_n,_p));
166 void clear() { a_ = b_ = c_ = d_ = e_ = f_ = g_ = h_ = i_ = j_ = 0.0; }
171 a_ += _q.a_; b_ += _q.b_; c_ += _q.c_; d_ += _q.d_;
172 e_ += _q.e_; f_ += _q.f_; g_ += _q.g_;
173 h_ += _q.h_; i_ += _q.i_;
181 return result += _other;
188 a_ *= _s; b_ *= _s; c_ *= _s; d_ *= _s;
189 e_ *= _s; f_ *= _s; g_ *= _s;
202 template <
class _Vec4>
205 Scalar x(_v[0]), y(_v[1]), z(_v[2]), w(_v[3]);
206 return _Vec4(x*a_ + y*b_ + z*c_ + w*d_,
207 x*b_ + y*e_ + z*f_ + w*g_,
208 x*c_ + y*f_ + z*h_ + w*i_,
209 x*d_ + y*g_ + z*i_ + w*j_);
213 template <
class _Vec>
219 Scalar a()
const {
return a_; }
220 Scalar b()
const {
return b_; }
221 Scalar c()
const {
return c_; }
222 Scalar d()
const {
return d_; }
223 Scalar e()
const {
return e_; }
224 Scalar f()
const {
return f_; }
225 Scalar g()
const {
return g_; }
226 Scalar h()
const {
return h_; }
227 Scalar i()
const {
return i_; }
228 Scalar j()
const {
return j_; }
230 Scalar xx()
const {
return a_; }
231 Scalar xy()
const {
return b_; }
232 Scalar xz()
const {
return c_; }
233 Scalar xw()
const {
return d_; }
234 Scalar yy()
const {
return e_; }
235 Scalar yz()
const {
return f_; }
236 Scalar yw()
const {
return g_; }
237 Scalar zz()
const {
return h_; }
238 Scalar zw()
const {
return i_; }
239 Scalar ww()
const {
return j_; }
244 template <
class _Vec3>
245 Scalar
evaluate(
const _Vec3& _v, GenProg::Int2Type<3>)
const
247 Scalar x(_v[0]), y(_v[1]), z(_v[2]);
248 return a_*x*x + 2.0*b_*x*y + 2.0*c_*x*z + 2.0*d_*x
249 + e_*y*y + 2.0*f_*y*z + 2.0*g_*y
255 template <
class _Vec4>
256 Scalar
evaluate(
const _Vec4& _v, GenProg::Int2Type<4>)
const
258 Scalar x(_v[0]), y(_v[1]), z(_v[2]), w(_v[3]);
259 return a_*x*x + 2.0*b_*x*y + 2.0*c_*x*z + 2.0*d_*x*w
260 + e_*y*y + 2.0*f_*y*z + 2.0*g_*y*w
261 + h_*z*z + 2.0*i_*z*w
267 Scalar a_, b_, c_, d_,
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Definition: VectorAdapter.hh:176
/class QuadricT Geometry/QuadricT.hh
Definition: QuadricT.hh:83
_Vec4 operator*(const _Vec4 &_v) const
multiply 4D vector from right: Q*v
Definition: QuadricT.hh:203
void clear()
set all entries to zero
Definition: QuadricT.hh:166
Scalar evaluate(const _Vec4 &_v, GenProg::Int2Type< 4 >) const
evaluate quadric Q at 4D vector v: v*Q*v
Definition: QuadricT.hh:256
QuadricT< Scalar > & operator+=(const QuadricT< Scalar > &_q)
add quadrics
Definition: QuadricT.hh:169
Scalar evaluate(const _Vec3 &_v, GenProg::Int2Type< 3 >) const
evaluate quadric Q at 3D vector v: v*Q*v
Definition: QuadricT.hh:245
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
Definition: QuadricT.hh:94
QuadricT< Scalar > & operator*=(Scalar _s)
multiply by scalar
Definition: QuadricT.hh:186
Scalar operator()(const _Vec &_v) const
evaluate quadric Q at (3D or 4D) vector v: v*Q*v
Definition: QuadricT.hh:214
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
Definition: QuadricT.hh:107
Helper class providing information about a vector type.
Definition: vector_traits.hh:89