QuadricT.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6743 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 11:03:10 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  CLASS QuadricT
00049 //
00050 //=============================================================================
00051 
00052 #ifndef ACG_QUADRIC_HH
00053 #define ACG_QUADRIC_HH
00054 
00055 
00056 //== INCLUDES =================================================================
00057 
00058 
00059 #include "../../Math/VectorT.hh"
00060 
00061 
00062 //== NAMESPACE ================================================================
00063 
00064 
00065 namespace ACG {
00066 namespace Geometry {
00067 
00068 
00069 //== CLASS DEFINITION =========================================================
00070 
00071 
00078 template <class Scalar>
00079 class ACGDLLEXPORT QuadricT
00080 {
00081 public:
00082 
00083 
00085   QuadricT(Scalar _a, Scalar _b, Scalar _c, Scalar _d,
00086                       Scalar _e, Scalar _f, Scalar _g,
00087                                  Scalar _h, Scalar _i,
00088                                             Scalar _j)
00089     : a(_a), b(_b), c(_c), d(_d),
00090              e(_e), f(_f), g(_g),
00091                     h(_h), i(_i),
00092                            j(_j)
00093   {}
00094 
00095 
00097   QuadricT( Scalar _a=0.0, Scalar _b=0.0, Scalar _c=0.0, Scalar _d=0.0 )
00098     :  a(_a*_a), b(_a*_b),  c(_a*_c),  d(_a*_d),
00099                  e(_b*_b),  f(_b*_c),  g(_b*_d),
00100                             h(_c*_c),  i(_c*_d),
00101                                        j(_d*_d)
00102   {}
00103 
00104 
00106   void clear()  { a = b = c = d = e = f = g = h = i = j = 0.0; }
00107 
00108 
00110   QuadricT<Scalar>& operator+=( const QuadricT<Scalar>& _q )
00111   {
00112     a += _q.a;  b += _q.b;  c += _q.c;  d += _q.d;
00113                 e += _q.e;  f += _q.f;  g += _q.g;
00114                             h += _q.h;  i += _q.i;
00115                                         j += _q.j;
00116     return *this;
00117   }
00118 
00119 
00121   QuadricT<Scalar>& operator*=( Scalar _s)
00122   {
00123     a *= _s;  b *= _s;  c *= _s;  d *= _s;
00124               e *= _s;  f *= _s;  g *= _s;
00125                         h *= _s;  i *= _s;
00126                                   j *= _s;
00127     return *this;
00128   }
00129 
00130 
00132   VectorT<Scalar,4> operator*(const VectorT<Scalar,4>& _v) const
00133   {
00134     return VectorT<Scalar,4>(_v[0]*a + _v[1]*b + _v[2]*c + _v[3]*d,
00135                              _v[0]*b + _v[1]*e + _v[2]*f + _v[3]*g,
00136                              _v[0]*c + _v[1]*f + _v[2]*h + _v[3]*i,
00137                              _v[0]*d + _v[1]*g + _v[2]*i + _v[3]*j);
00138   }
00139 
00140 
00142   Scalar operator()(const VectorT<Scalar,3> _v) const
00143   {
00144     Scalar x(_v[0]), y(_v[1]), z(_v[2]);
00145     return a*x*x + 2.0*b*x*y + 2.0*c*x*z + 2.0*d*x
00146                  +     e*y*y + 2.0*f*y*z + 2.0*g*y
00147                              +     h*z*z + 2.0*i*z
00148                                          +     j;
00149   }
00150 
00151 
00153   Scalar operator()(const VectorT<Scalar,4> _v) const
00154   {
00155     Scalar x(_v[0]), y(_v[1]), z(_v[2]), w(_v[3]);
00156     return a*x*x + 2.0*b*x*y + 2.0*c*x*z + 2.0*d*x*w
00157                  +     e*y*y + 2.0*f*y*z + 2.0*g*y*w
00158                              +     h*z*z + 2.0*i*z*w
00159                                          +     j*w*w;
00160   }
00161 
00162 
00163 private:
00164 
00165   Scalar a, b, c, d,
00166             e, f, g,
00167                h, i,
00168                   j;
00169 };
00170 
00171 
00173 typedef QuadricT<float> Quadricf;
00174 
00176 typedef QuadricT<double> Quadricd;
00177 
00178 
00179 //=============================================================================
00180 } // namespace Geometry
00181 } // namespace ACG
00182 //=============================================================================
00183 #endif // ACG_QUADRIC_HH defined
00184 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .