Developer Documentation

QuadricT.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
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 // CLASS QuadricT
47 //
48 //=============================================================================
49
50 #ifndef ACG_QUADRIC_HH
51 #define ACG_QUADRIC_HH
52
53
54 //== INCLUDES =================================================================
55
56
57 #include "../../Math/VectorT.hh"
58
59
60 //== NAMESPACE ================================================================
61
62
63 namespace ACG {
64 namespace Geometry {
65
66
67 //== CLASS DEFINITION =========================================================
68
69
76 template <class Scalar>
77 class ACGDLLEXPORT QuadricT
78 {
79 public:
80
81
83 QuadricT(Scalar _a, Scalar _b, Scalar _c, Scalar _d,
84 Scalar _e, Scalar _f, Scalar _g,
85 Scalar _h, Scalar _i,
86 Scalar _j)
87 : a(_a), b(_b), c(_c), d(_d),
88 e(_e), f(_f), g(_g),
89 h(_h), i(_i),
90 j(_j)
91 {}
92
93
95 QuadricT( Scalar _a=0.0, Scalar _b=0.0, Scalar _c=0.0, Scalar _d=0.0 )
96 : a(_a*_a), b(_a*_b), c(_a*_c), d(_a*_d),
97 e(_b*_b), f(_b*_c), g(_b*_d),
98 h(_c*_c), i(_c*_d),
99 j(_d*_d)
100 {}
101
102
104 void clear() { a = b = c = d = e = f = g = h = i = j = 0.0; }
105
106
108 QuadricT<Scalar>& operator+=( const QuadricT<Scalar>& _q )
109 {
110 a += _q.a; b += _q.b; c += _q.c; d += _q.d;
111 e += _q.e; f += _q.f; g += _q.g;
112 h += _q.h; i += _q.i;
113 j += _q.j;
114 return *this;
115 }
116
117
119 QuadricT<Scalar>& operator*=( Scalar _s)
120 {
121 a *= _s; b *= _s; c *= _s; d *= _s;
122 e *= _s; f *= _s; g *= _s;
123 h *= _s; i *= _s;
124 j *= _s;
125 return *this;
126 }
127
128
130 VectorT<Scalar,4> operator*(const VectorT<Scalar,4>& _v) const
131 {
132 return VectorT<Scalar,4>(_v[0]*a + _v[1]*b + _v[2]*c + _v[3]*d,
133 _v[0]*b + _v[1]*e + _v[2]*f + _v[3]*g,
134 _v[0]*c + _v[1]*f + _v[2]*h + _v[3]*i,
135 _v[0]*d + _v[1]*g + _v[2]*i + _v[3]*j);
136 }
137
138
140 Scalar operator()(const VectorT<Scalar,3> _v) const
141 {
142 Scalar x(_v[0]), y(_v[1]), z(_v[2]);
143 return a*x*x + 2.0*b*x*y + 2.0*c*x*z + 2.0*d*x
144 + e*y*y + 2.0*f*y*z + 2.0*g*y
145 + h*z*z + 2.0*i*z
146 + j;
147 }
148
149
151 Scalar operator()(const VectorT<Scalar,4> _v) const
152 {
153 Scalar x(_v[0]), y(_v[1]), z(_v[2]), w(_v[3]);
154 return a*x*x + 2.0*b*x*y + 2.0*c*x*z + 2.0*d*x*w
155 + e*y*y + 2.0*f*y*z + 2.0*g*y*w
156 + h*z*z + 2.0*i*z*w
157 + j*w*w;
158 }
159
160
161 private:
162
163 Scalar a, b, c, d,
164 e, f, g,
165 h, i,
166 j;
167 };
168
169
171 typedef QuadricT<float> Quadricf;
172
174 typedef QuadricT<double> Quadricd;
175
176
177 //=============================================================================
178 } // namespace Geometry
179 } // namespace ACG
180 //=============================================================================
181 #endif // ACG_QUADRIC_HH defined
182 //=============================================================================
ACG::Geometry::QuadricT::operator()
Scalar operator()(const VectorT< Scalar, 3 > _v) const
evaluate quadric Q at vector v: v*Q*v
Definition: QuadricT.hh:140
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
ACG::Geometry::Quadricf
QuadricT< float > Quadricf
Quadric using floats.
Definition: QuadricT.hh:171
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::Geometry::QuadricT::operator()
Scalar operator()(const VectorT< Scalar, 4 > _v) const
evaluate quadric Q at vector v: v*Q*v
Definition: QuadricT.hh:151
ACG::Geometry::QuadricT::operator+=
QuadricT< Scalar > & operator+=(const QuadricT< Scalar > &_q)
add quadrics
Definition: QuadricT.hh:108
ACG::Geometry::QuadricT::clear
void clear()
set all entries to zero
Definition: QuadricT.hh:104
ACG::Geometry::QuadricT::operator*=
QuadricT< Scalar > & operator*=(Scalar _s)
multiply by scalar
Definition: QuadricT.hh:119
ACG::Geometry::QuadricT::operator*
VectorT< Scalar, 4 > operator*(const VectorT< Scalar, 4 > &_v) const
multiply 4D vector from right: Q*v
Definition: QuadricT.hh:130
ACG::Geometry::Quadricd
QuadricT< double > Quadricd
Quadric using double.
Definition: QuadricT.hh:174
ACG::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:95
ACG::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:83
ACG::Geometry::QuadricT
Definition: QuadricT.hh:77