OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QuadricT.hh
Go to the documentation of this file.
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5 * www.openmesh.org *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of OpenMesh. *
9 * *
10 * OpenMesh is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenMesh is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenMesh. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34
35 /*===========================================================================*\
36 * *
37 * $Revision: 736 $ *
38 * $Date: 2012-10-08 09:30:49 +0200 (Mo, 08. Okt 2012) $ *
39 * *
40 \*===========================================================================*/
41
46 //=============================================================================
47 //
48 // CLASS QuadricT
49 //
50 //=============================================================================
51
52 #ifndef OPENMESH_GEOMETRY_QUADRIC_HH
53 #define OPENMESH_GEOMETRY_QUADRIC_HH
54
55
56 //== INCLUDES =================================================================
57
58 #include "Config.hh"
59 #include <OpenMesh/Core/Geometry/VectorT.hh>
60 #include <OpenMesh/Core/Utils/GenProg.hh>
61
62 //== NAMESPACE ================================================================
63
64 namespace OpenMesh { //BEGIN_NS_OPENMESH
65 namespace Geometry { //BEGIN_NS_GEOMETRY
66
67
68 //== CLASS DEFINITION =========================================================
69
70
77 template <class Scalar>
78 class QuadricT
79 {
80 public:
81 typedef Scalar value_type;
82 typedef QuadricT<Scalar> type;
83 typedef QuadricT<Scalar> Self;
84 // typedef VectorInterface<Scalar, VecStorage3<Scalar> > Vec3;
85 // typedef VectorInterface<Scalar, VecStorage4<Scalar> > Vec4;
86 //typedef Vector3Elem Vec3;
87 //typedef Vector4Elem Vec4;
88
90 QuadricT(Scalar _a, Scalar _b, Scalar _c, Scalar _d,
91 Scalar _e, Scalar _f, Scalar _g,
92 Scalar _h, Scalar _i,
93 Scalar _j)
94 : a_(_a), b_(_b), c_(_c), d_(_d),
95 e_(_e), f_(_f), g_(_g),
96 h_(_h), i_(_i),
97 j_(_j)
98 {
99 }
100
101
103 QuadricT( Scalar _a=0.0, Scalar _b=0.0, Scalar _c=0.0, Scalar _d=0.0 )
104 : a_(_a*_a), b_(_a*_b), c_(_a*_c), d_(_a*_d),
105 e_(_b*_b), f_(_b*_c), g_(_b*_d),
106 h_(_c*_c), i_(_c*_d),
107 j_(_d*_d)
108 {}
109
110 template <class _Point>
111 QuadricT(const _Point& _pt)
112 {
113 set_distance_to_point(_pt);
114 }
115
116 template <class _Normal, class _Point>
117 QuadricT(const _Normal& _n, const _Point& _p)
118 {
119 set_distance_to_plane(_n,_p);
120 }
121
122 //set operator
123 void set(Scalar _a, Scalar _b, Scalar _c, Scalar _d,
124 Scalar _e, Scalar _f, Scalar _g,
125 Scalar _h, Scalar _i,
126 Scalar _j)
127 {
128 a_ = _a; b_ = _b; c_ = _c; d_ = _d;
129 e_ = _e; f_ = _f; g_ = _g;
130 h_ = _h; i_ = _i;
131 j_ = _j;
132 }
133
134 //sets the quadric representing the squared distance to _pt
135 template <class _Point>
136 void set_distance_to_point(const _Point& _pt)
137 {
138 set(1, 0, 0, -_pt[0],
139 1, 0, -_pt[1],
140 1, -_pt[2],
141 dot(_pt,_pt));
142 }
143
144 //sets the quadric representing the squared distance to the plane [_a,_b,_c,_d]
145 void set_distance_to_plane(Scalar _a, Scalar _b, Scalar _c, Scalar _d)
146 {
147 a_ = _a*_a; b_ = _a*_b; c_ = _a*_c; d_ = _a*_d;
148 e_ = _b*_b; f_ = _b*_c; g_ = _b*_d;
149 h_ = _c*_c; i_ = _c*_d;
150 j_ = _d*_d;
151 }
152
153 //sets the quadric representing the squared distance to the plane
154 //determined by the normal _n and the point _p
155 template <class _Normal, class _Point>
156 void set_distance_to_plane(const _Normal& _n, const _Point& _p)
157 {
158 set_distance_to_plane(_n[0], _n[1], _n[2], -dot(_n,_p));
159 }
160
162 void clear() { a_ = b_ = c_ = d_ = e_ = f_ = g_ = h_ = i_ = j_ = 0.0; }
163
165 QuadricT<Scalar>& operator+=( const QuadricT<Scalar>& _q )
166 {
167 a_ += _q.a_; b_ += _q.b_; c_ += _q.c_; d_ += _q.d_;
168 e_ += _q.e_; f_ += _q.f_; g_ += _q.g_;
169 h_ += _q.h_; i_ += _q.i_;
170 j_ += _q.j_;
171 return *this;
172 }
173
174
176 QuadricT<Scalar>& operator*=( Scalar _s)
177 {
178 a_ *= _s; b_ *= _s; c_ *= _s; d_ *= _s;
179 e_ *= _s; f_ *= _s; g_ *= _s;
180 h_ *= _s; i_ *= _s;
181 j_ *= _s;
182 return *this;
183 }
184
185
187 template <class _Vec4>
188 _Vec4 operator*(const _Vec4& _v) const
189 {
190 Scalar x(_v[0]), y(_v[1]), z(_v[2]), w(_v[3]);
191 return _Vec4(x*a_ + y*b_ + z*c_ + w*d_,
192 x*b_ + y*e_ + z*f_ + w*g_,
193 x*c_ + y*f_ + z*h_ + w*i_,
194 x*d_ + y*g_ + z*i_ + w*j_);
195 }
196
198 template <class _Vec>
199 Scalar operator()(const _Vec& _v) const
200 {
201 return evaluate(_v, GenProg::Int2Type<_Vec::size_>());
202 }
203
204 Scalar a() const { return a_; }
205 Scalar b() const { return b_; }
206 Scalar c() const { return c_; }
207 Scalar d() const { return d_; }
208 Scalar e() const { return e_; }
209 Scalar f() const { return f_; }
210 Scalar g() const { return g_; }
211 Scalar h() const { return h_; }
212 Scalar i() const { return i_; }
213 Scalar j() const { return j_; }
214
215 Scalar xx() const { return a_; }
216 Scalar xy() const { return b_; }
217 Scalar xz() const { return c_; }
218 Scalar xw() const { return d_; }
219 Scalar yy() const { return e_; }
220 Scalar yz() const { return f_; }
221 Scalar yw() const { return g_; }
222 Scalar zz() const { return h_; }
223 Scalar zw() const { return i_; }
224 Scalar ww() const { return j_; }
225
226 protected:
227
229 template <class _Vec3>
230 Scalar evaluate(const _Vec3& _v, GenProg::Int2Type<3>/*_dimension*/) const
231 {
232 Scalar x(_v[0]), y(_v[1]), z(_v[2]);
233 return a_*x*x + 2.0*b_*x*y + 2.0*c_*x*z + 2.0*d_*x
234 + e_*y*y + 2.0*f_*y*z + 2.0*g_*y
235 + h_*z*z + 2.0*i_*z
236 + j_;
237 }
238
240 template <class _Vec4>
241 Scalar evaluate(const _Vec4& _v, GenProg::Int2Type<4>/*_dimension*/) const
242 {
243 Scalar x(_v[0]), y(_v[1]), z(_v[2]), w(_v[3]);
244 return a_*x*x + 2.0*b_*x*y + 2.0*c_*x*z + 2.0*d_*x*w
245 + e_*y*y + 2.0*f_*y*z + 2.0*g_*y*w
246 + h_*z*z + 2.0*i_*z*w
247 + j_*w*w;
248 }
249
250 private:
251
252 Scalar a_, b_, c_, d_,
253 e_, f_, g_,
254 h_, i_,
255 j_;
256 };
257
258
260 typedef QuadricT<float> Quadricf;
261
263 typedef QuadricT<double> Quadricd;
264
265
266 //=============================================================================
267 } // END_NS_GEOMETRY
268 } // END_NS_OPENMESH
269 //============================================================================
270 #endif // OPENMESH_GEOMETRY_HH defined
271 //=============================================================================