Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS QuadricT
56 //
57 //=============================================================================
58 
59 #ifndef ACG_QUADRIC_HH
60 #define ACG_QUADRIC_HH
61 
62 
63 //== INCLUDES =================================================================
64 
65 
66 #include "../../Math/VectorT.hh"
67 
68 
69 //== NAMESPACE ================================================================
70 
71 
72 namespace ACG {
73 namespace Geometry {
74 
75 
76 //== CLASS DEFINITION =========================================================
77 
78 
85 template <class Scalar>
86 class ACGDLLEXPORT QuadricT
87 {
88 public:
89 
90 
92  QuadricT(Scalar _a, Scalar _b, Scalar _c, Scalar _d,
93  Scalar _e, Scalar _f, Scalar _g,
94  Scalar _h, Scalar _i,
95  Scalar _j)
96  : a(_a), b(_b), c(_c), d(_d),
97  e(_e), f(_f), g(_g),
98  h(_h), i(_i),
99  j(_j)
100  {}
101 
102 
104  QuadricT( Scalar _a=0.0, Scalar _b=0.0, Scalar _c=0.0, Scalar _d=0.0 )
105  : a(_a*_a), b(_a*_b), c(_a*_c), d(_a*_d),
106  e(_b*_b), f(_b*_c), g(_b*_d),
107  h(_c*_c), i(_c*_d),
108  j(_d*_d)
109  {}
110 
111 
113  void clear() { a = b = c = d = e = f = g = h = i = j = 0.0; }
114 
115 
118  {
119  a += _q.a; b += _q.b; c += _q.c; d += _q.d;
120  e += _q.e; f += _q.f; g += _q.g;
121  h += _q.h; i += _q.i;
122  j += _q.j;
123  return *this;
124  }
125 
126 
129  {
130  a *= _s; b *= _s; c *= _s; d *= _s;
131  e *= _s; f *= _s; g *= _s;
132  h *= _s; i *= _s;
133  j *= _s;
134  return *this;
135  }
136 
137 
140  {
141  return VectorT<Scalar,4>(_v[0]*a + _v[1]*b + _v[2]*c + _v[3]*d,
142  _v[0]*b + _v[1]*e + _v[2]*f + _v[3]*g,
143  _v[0]*c + _v[1]*f + _v[2]*h + _v[3]*i,
144  _v[0]*d + _v[1]*g + _v[2]*i + _v[3]*j);
145  }
146 
147 
149  Scalar operator()(const VectorT<Scalar,3> _v) const
150  {
151  Scalar x(_v[0]), y(_v[1]), z(_v[2]);
152  return a*x*x + 2.0*b*x*y + 2.0*c*x*z + 2.0*d*x
153  + e*y*y + 2.0*f*y*z + 2.0*g*y
154  + h*z*z + 2.0*i*z
155  + j;
156  }
157 
158 
160  Scalar operator()(const VectorT<Scalar,4> _v) const
161  {
162  Scalar x(_v[0]), y(_v[1]), z(_v[2]), w(_v[3]);
163  return a*x*x + 2.0*b*x*y + 2.0*c*x*z + 2.0*d*x*w
164  + e*y*y + 2.0*f*y*z + 2.0*g*y*w
165  + h*z*z + 2.0*i*z*w
166  + j*w*w;
167  }
168 
169 
170 private:
171 
172  Scalar a, b, c, d,
173  e, f, g,
174  h, i,
175  j;
176 };
177 
178 
181 
184 
185 
186 //=============================================================================
187 } // namespace Geometry
188 } // namespace ACG
189 //=============================================================================
190 #endif // ACG_QUADRIC_HH defined
191 //=============================================================================
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
QuadricT< Scalar > & operator*=(Scalar _s)
multiply by scalar
Definition: QuadricT.hh:128
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:104
Scalar operator()(const VectorT< Scalar, 3 > _v) const
evaluate quadric Q at vector v: v*Q*v
Definition: QuadricT.hh:149
Scalar operator()(const VectorT< Scalar, 4 > _v) const
evaluate quadric Q at vector v: v*Q*v
Definition: QuadricT.hh:160
QuadricT< Scalar > & operator+=(const QuadricT< Scalar > &_q)
add quadrics
Definition: QuadricT.hh:117
QuadricT< float > Quadricf
Quadric using floats.
Definition: QuadricT.hh:180
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:92
VectorT< Scalar, 4 > operator*(const VectorT< Scalar, 4 > &_v) const
multiply 4D vector from right: Q*v
Definition: QuadricT.hh:139
void clear()
set all entries to zero
Definition: QuadricT.hh:113
QuadricT< double > Quadricd
Quadric using double.
Definition: QuadricT.hh:183