OpenMesh: OpenMesh/Core/Geometry/QuadricT.hh Source File

| OpenMesh

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
174 QuadricT<Scalar>& operator+=( const QuadricT<Scalar>& _q )
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 QuadricT<Scalar> operator+(const QuadricT<Scalar>& _other ) const
184 {
185 QuadricT<Scalar> result = *this;
186 return result += _other;
187 }
188
189
191 QuadricT<Scalar>& operator*=( Scalar _s)
192 {
193 a_ *= _s; b_ *= _s; c_ *= _s; d_ *= _s;
194 e_ *= _s; f_ *= _s; g_ *= _s;
195 h_ *= _s; i_ *= _s;
196 j_ *= _s;
197 return *this;
198 }
199
200 QuadricT<Scalar> operator*(Scalar _s) const
201 {
202 QuadricT<Scalar> result = *this;
203 return result *= _s;
204 }
205
207 template <class _Vec4>
208 _Vec4 operator*(const _Vec4& _v) const
209 {
210 Scalar x(_v[0]), y(_v[1]), z(_v[2]), w(_v[3]);
211 return _Vec4(x*a_ + y*b_ + z*c_ + w*d_,
212 x*b_ + y*e_ + z*f_ + w*g_,
213 x*c_ + y*f_ + z*h_ + w*i_,
214 x*d_ + y*g_ + z*i_ + w*j_);
215 }
216
218 template <class _Vec>
219 Scalar operator()(const _Vec& _v) const
220 {
221 return evaluate(_v, GenProg::Int2Type<vector_traits<_Vec>::size_>());
222 }
223
224 Scalar a() const { return a_; }
225 Scalar b() const { return b_; }
226 Scalar c() const { return c_; }
227 Scalar d() const { return d_; }
228 Scalar e() const { return e_; }
229 Scalar f() const { return f_; }
230 Scalar g() const { return g_; }
231 Scalar h() const { return h_; }
232 Scalar i() const { return i_; }
233 Scalar j() const { return j_; }
234
235 Scalar xx() const { return a_; }
236 Scalar xy() const { return b_; }
237 Scalar xz() const { return c_; }
238 Scalar xw() const { return d_; }
239 Scalar yy() const { return e_; }
240 Scalar yz() const { return f_; }
241 Scalar yw() const { return g_; }
242 Scalar zz() const { return h_; }
243 Scalar zw() const { return i_; }
244 Scalar ww() const { return j_; }
245
246 protected:
247
249 template <class _Vec3>
250 Scalar evaluate(const _Vec3& _v, GenProg::Int2Type<3>/*_dimension*/) const
251 {
252 Scalar x(_v[0]), y(_v[1]), z(_v[2]);
253 return a_*x*x + 2.0*b_*x*y + 2.0*c_*x*z + 2.0*d_*x
254 + e_*y*y + 2.0*f_*y*z + 2.0*g_*y
255 + h_*z*z + 2.0*i_*z
256 + j_;
257 }
258
260 template <class _Vec4>
261 Scalar evaluate(const _Vec4& _v, GenProg::Int2Type<4>/*_dimension*/) const
262 {
263 Scalar x(_v[0]), y(_v[1]), z(_v[2]), w(_v[3]);
264 return a_*x*x + 2.0*b_*x*y + 2.0*c_*x*z + 2.0*d_*x*w
265 + e_*y*y + 2.0*f_*y*z + 2.0*g_*y*w
266 + h_*z*z + 2.0*i_*z*w
267 + j_*w*w;
268 }
269
270 private:
271
272 Scalar a_, b_, c_, d_,
273 e_, f_, g_,
274 h_, i_,
275 j_;
276 };
277
278
280 typedef QuadricT<float> Quadricf;
281
283 typedef QuadricT<double> Quadricd;
284
285
286 //=============================================================================
287 } // END_NS_GEOMETRY
288 } // END_NS_OPENMESH
289 //============================================================================
290 #endif // OPENMESH_GEOMETRY_HH defined
291 //=============================================================================
OpenMesh::Geometry::QuadricT::evaluate
Scalar evaluate(const _Vec3 &_v, GenProg::Int2Type< 3 >) const
evaluate quadric Q at 3D vector v: v*Q*v
Definition: QuadricT.hh:250
OpenMesh::Geometry::QuadricT::operator()
Scalar operator()(const _Vec &_v) const
evaluate quadric Q at (3D or 4D) vector v: v*Q*v
Definition: QuadricT.hh:219
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
OpenMesh::Geometry::QuadricT::operator+=
QuadricT< Scalar > & operator+=(const QuadricT< Scalar > &_q)
add quadrics
Definition: QuadricT.hh:174
OpenMesh::Geometry::QuadricT::operator*=
QuadricT< Scalar > & operator*=(Scalar _s)
multiply by scalar
Definition: QuadricT.hh:191
OpenMesh::Geometry::QuadricT::QuadricT
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
OpenMesh::dot
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
OpenMesh::Geometry::QuadricT::operator*
_Vec4 operator*(const _Vec4 &_v) const
multiply 4D vector from right: Q*v
Definition: QuadricT.hh:208
OpenMesh::Geometry::QuadricT
/class QuadricT Geometry/QuadricT.hh
Definition: QuadricT.hh:87
OpenMesh::Geometry::QuadricT::clear
void clear()
set all entries to zero
Definition: QuadricT.hh:171
OpenMesh::vector_traits
Helper class providing information about a vector type.
Definition: vector_traits.hh:93
OpenMesh::Geometry::QuadricT::QuadricT
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
OpenMesh::Geometry::QuadricT::evaluate
Scalar evaluate(const _Vec4 &_v, GenProg::Int2Type< 4 >) const
evaluate quadric Q at 4D vector v: v*Q*v
Definition: QuadricT.hh:261
Config.hh