Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

QuadricT.hh

Go to the documentation of this file.
00001 //=============================================================================
00002 //                                                                            
00003 //                               OpenMesh                                     
00004 //        Copyright (C) 2003 by Computer Graphics Group, RWTH Aachen          
00005 //                           www.openmesh.org                                 
00006 //                                                                            
00007 //-----------------------------------------------------------------------------
00008 //                                                                            
00009 //                                License                                     
00010 //                                                                            
00011 //   This library is free software; you can redistribute it and/or modify it 
00012 //   under the terms of the GNU Library General Public License as published  
00013 //   by the Free Software Foundation, version 2.                             
00014 //                                                                             
00015 //   This library is distributed in the hope that it will be useful, but       
00016 //   WITHOUT ANY WARRANTY; without even the implied warranty of                
00017 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         
00018 //   Library General Public License for more details.                          
00019 //                                                                            
00020 //   You should have received a copy of the GNU Library General Public         
00021 //   License along with this library; if not, write to the Free Software       
00022 //   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 
00023 //                                                                            
00024 //-----------------------------------------------------------------------------
00025 //                                                                            
00026 //   $Revision: 1.3 $
00027 //   $Date: 2003/04/08 10:53:00 $
00028 //                                                                            
00029 //=============================================================================
00030 
00035 //=============================================================================
00036 //
00037 //  CLASS QuadricT
00038 //
00039 //=============================================================================
00040 
00041 #ifndef OPENMESH_GEOMETRY_QUADRIC_HH
00042 #define OPENMESH_GEOMETRY_QUADRIC_HH
00043 
00044 
00045 //== INCLUDES =================================================================
00046 
00047 #include "Config.hh"
00048 #include <OpenMesh/Core/Math/VectorT.hh>
00049 
00050 //== NAMESPACE ================================================================
00051 
00052 namespace OpenMesh { //BEGIN_NS_OPENMESH
00053 namespace Geometry { //BEGIN_NS_GEOMETRY
00054 
00055 
00056 //== CLASS DEFINITION =========================================================
00057 
00058 
00065 template <class Scalar,
00066           class Vector3Elem = VectorT<Scalar, 3>,
00067           class Vector4Elem = VectorT<Scalar, 4> >
00068 class QuadricT
00069 {
00070 public:
00071    typedef Scalar           value_type;
00072    typedef QuadricT<Scalar> type;
00073    typedef QuadricT<Scalar> Self;
00074    //   typedef VectorInterface<Scalar, VecStorage3<Scalar> > Vec3;
00075    //   typedef VectorInterface<Scalar, VecStorage4<Scalar> > Vec4;
00076    typedef Vector3Elem      Vec3;
00077    typedef Vector4Elem      Vec4;
00078    
00080    QuadricT(Scalar _a, Scalar _b, Scalar _c, Scalar _d,
00081                        Scalar _e, Scalar _f, Scalar _g,
00082                                   Scalar _h, Scalar _i,
00083                                              Scalar _j)
00084          : a(_a), b(_b), c(_c), d(_d), 
00085                   e(_e), f(_f), g(_g),    
00086                          h(_h), i(_i), 
00087                                 j(_j)
00088    {}
00089 
00090 
00092    QuadricT( Scalar _a=0.0, Scalar _b=0.0, Scalar _c=0.0, Scalar _d=0.0 )
00093          :  a(_a*_a), b(_a*_b),  c(_a*_c),  d(_a*_d),
00094                       e(_b*_b),  f(_b*_c),  g(_b*_d),
00095                                  h(_c*_c),  i(_c*_d),
00096                                             j(_d*_d)
00097    {}
00098 
00099 
00101    void clear()  { a = b = c = d = e = f = g = h = i = j = 0.0; }
00102 
00103   
00105    QuadricT<Scalar>& operator+=( const QuadricT<Scalar>& _q )
00106    {
00107       a += _q.a;  b += _q.b;  c += _q.c;  d += _q.d;
00108                   e += _q.e;  f += _q.f;  g += _q.g;
00109                               h += _q.h;  i += _q.i;
00110                                           j += _q.j;
00111       return *this;
00112    }
00113 
00114 
00116    QuadricT<Scalar>& operator*=( Scalar _s)
00117    {
00118       a *= _s;  b *= _s;  c *= _s;  d *= _s;
00119               e *= _s;  f *= _s;  g *= _s;
00120                         h *= _s;  i *= _s;
00121                                   j *= _s;
00122       return *this;
00123    }
00124 
00125 
00127    Vec4 operator*(const Vec4& _v) const
00128    {
00129       return Vec4(_v[0]*a + _v[1]*b + _v[2]*c + _v[3]*d,
00130                   _v[0]*b + _v[1]*e + _v[2]*f + _v[3]*g,
00131                   _v[0]*c + _v[1]*f + _v[2]*h + _v[3]*i,
00132                   _v[0]*d + _v[1]*g + _v[2]*i + _v[3]*j);
00133    }
00134   
00135 
00137    Scalar operator()(const Vec3 _v) const
00138    {
00139       Scalar x(_v[0]), y(_v[1]), z(_v[2]);
00140       return a*x*x + 2.0*b*x*y + 2.0*c*x*z + 2.0*d*x
00141                    +     e*y*y + 2.0*f*y*z + 2.0*g*y
00142                                +     h*z*z + 2.0*i*z
00143                                            +     j;
00144    }
00145 
00146 
00148    Scalar operator()(const Vec4 _v) const
00149    {
00150       Scalar x(_v[0]), y(_v[1]), z(_v[2]), w(_v[3]);
00151       return a*x*x + 2.0*b*x*y + 2.0*c*x*z + 2.0*d*x*w
00152                    +     e*y*y + 2.0*f*y*z + 2.0*g*y*w
00153                                +     h*z*z + 2.0*i*z*w
00154                                            +     j*w*w;
00155    }
00156   
00157 
00158 private:
00159 
00160    Scalar a, b, c, d, 
00161              e, f, g, 
00162                 h, i, 
00163                    j;
00164 };
00165 
00166 
00168 typedef QuadricT<float> Quadricf;
00169 
00171 typedef QuadricT<double> Quadricd;
00172 
00173 
00174 //=============================================================================
00175 } // END_NS_GEOMETRY
00176 } // END_NS_OPENMESH
00177 //============================================================================
00178 #endif // OPENMESH_GEOMETRY_HH defined
00179 //=============================================================================

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