OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
QuadricT.hh
Go to the documentation of this file.
1 /* ========================================================================= *
2  * *
3  * OpenMesh *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openmesh.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenMesh. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40  * ========================================================================= */
41 
42 
43 
44 /*===========================================================================*\
45  * *
46  * $Revision$ *
47  * $Date$ *
48  * *
49 \*===========================================================================*/
50 
55 //=============================================================================
56 //
57 // CLASS QuadricT
58 //
59 //=============================================================================
60 
61 #ifndef OPENMESH_GEOMETRY_QUADRIC_HH
62 #define OPENMESH_GEOMETRY_QUADRIC_HH
63 
64 
65 //== INCLUDES =================================================================
66 
67 #include "Config.hh"
68 #include <OpenMesh/Core/Geometry/VectorT.hh>
69 #include <OpenMesh/Core/Utils/GenProg.hh>
70 
71 //== NAMESPACE ================================================================
72 
73 namespace OpenMesh { //BEGIN_NS_OPENMESH
74 namespace Geometry { //BEGIN_NS_GEOMETRY
75 
76 
77 //== CLASS DEFINITION =========================================================
78 
79 
86 template <class Scalar>
87 class QuadricT
88 {
89 public:
90  typedef Scalar value_type;
91  typedef QuadricT<Scalar> type;
92  typedef QuadricT<Scalar> Self;
93  // typedef VectorInterface<Scalar, VecStorage3<Scalar> > Vec3;
94  // typedef VectorInterface<Scalar, VecStorage4<Scalar> > Vec4;
95  //typedef Vector3Elem Vec3;
96  //typedef Vector4Elem Vec4;
97 
99  QuadricT(Scalar _a, Scalar _b, Scalar _c, Scalar _d,
100  Scalar _e, Scalar _f, Scalar _g,
101  Scalar _h, Scalar _i,
102  Scalar _j)
103  : a_(_a), b_(_b), c_(_c), d_(_d),
104  e_(_e), f_(_f), g_(_g),
105  h_(_h), i_(_i),
106  j_(_j)
107  {
108  }
109 
110 
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),
116  j_(_d*_d)
117  {}
118 
119  template <class _Point>
120  QuadricT(const _Point& _pt)
121  {
122  set_distance_to_point(_pt);
123  }
124 
125  template <class _Normal, class _Point>
126  QuadricT(const _Normal& _n, const _Point& _p)
127  {
128  set_distance_to_plane(_n,_p);
129  }
130 
131  //set operator
132  void set(Scalar _a, Scalar _b, Scalar _c, Scalar _d,
133  Scalar _e, Scalar _f, Scalar _g,
134  Scalar _h, Scalar _i,
135  Scalar _j)
136  {
137  a_ = _a; b_ = _b; c_ = _c; d_ = _d;
138  e_ = _e; f_ = _f; g_ = _g;
139  h_ = _h; i_ = _i;
140  j_ = _j;
141  }
142 
143  //sets the quadric representing the squared distance to _pt
144  template <class _Point>
145  void set_distance_to_point(const _Point& _pt)
146  {
147  set(1, 0, 0, -_pt[0],
148  1, 0, -_pt[1],
149  1, -_pt[2],
150  dot(_pt,_pt));
151  }
152 
153  //sets the quadric representing the squared distance to the plane [_a,_b,_c,_d]
154  void set_distance_to_plane(Scalar _a, Scalar _b, Scalar _c, Scalar _d)
155  {
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;
159  j_ = _d*_d;
160  }
161 
162  //sets the quadric representing the squared distance to the plane
163  //determined by the normal _n and the point _p
164  template <class _Normal, class _Point>
165  void set_distance_to_plane(const _Normal& _n, const _Point& _p)
166  {
167  set_distance_to_plane(_n[0], _n[1], _n[2], -dot(_n,_p));
168  }
169 
171  void clear() { a_ = b_ = c_ = d_ = e_ = f_ = g_ = h_ = i_ = j_ = 0.0; }
172 
175  {
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_;
179  j_ += _q.j_;
180  return *this;
181  }
182 
183 
186  {
187  a_ *= _s; b_ *= _s; c_ *= _s; d_ *= _s;
188  e_ *= _s; f_ *= _s; g_ *= _s;
189  h_ *= _s; i_ *= _s;
190  j_ *= _s;
191  return *this;
192  }
193 
194 
196  template <class _Vec4>
197  _Vec4 operator*(const _Vec4& _v) const
198  {
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_);
204  }
205 
207  template <class _Vec>
208  Scalar operator()(const _Vec& _v) const
209  {
210  return evaluate(_v, GenProg::Int2Type<_Vec::size_>());
211  }
212 
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_; }
223 
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_; }
234 
235 protected:
236 
238  template <class _Vec3>
239  Scalar evaluate(const _Vec3& _v, GenProg::Int2Type<3>/*_dimension*/) const
240  {
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
244  + h_*z*z + 2.0*i_*z
245  + j_;
246  }
247 
249  template <class _Vec4>
250  Scalar evaluate(const _Vec4& _v, GenProg::Int2Type<4>/*_dimension*/) const
251  {
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
256  + j_*w*w;
257  }
258 
259 private:
260 
261  Scalar a_, b_, c_, d_,
262  e_, f_, g_,
263  h_, i_,
264  j_;
265 };
266 
267 
269 typedef QuadricT<float> Quadricf;
270 
272 typedef QuadricT<double> Quadricd;
273 
274 
275 //=============================================================================
276 } // END_NS_GEOMETRY
277 } // END_NS_OPENMESH
278 //============================================================================
279 #endif // OPENMESH_GEOMETRY_HH defined
280 //=============================================================================
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:112
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Definition: VectorAdapter.hh:181
_Vec4 operator*(const _Vec4 &_v) const
multiply 4D vector from right: Q*v
Definition: QuadricT.hh:197
Scalar evaluate(const _Vec4 &_v, GenProg::Int2Type< 4 >) const
evaluate quadric Q at 4D vector v: v*Q*v
Definition: QuadricT.hh:250
void clear()
set all entries to zero
Definition: QuadricT.hh:171
Scalar evaluate(const _Vec3 &_v, GenProg::Int2Type< 3 >) const
evaluate quadric Q at 3D vector v: v*Q*v
Definition: QuadricT.hh:239
QuadricT< Scalar > & operator+=(const QuadricT< Scalar > &_q)
add quadrics
Definition: QuadricT.hh:174
/class QuadricT Geometry/QuadricT.hh
Definition: QuadricT.hh:87
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
Scalar operator()(const _Vec &_v) const
evaluate quadric Q at (3D or 4D) vector v: v*Q*v
Definition: QuadricT.hh:208
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:99
QuadricT< Scalar > & operator*=(Scalar _s)
multiply by scalar
Definition: QuadricT.hh:185

Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .