Blender  V2.59
LOD_NdQuadric.h
Go to the documentation of this file.
00001 /*
00002  * $Id: LOD_NdQuadric.h 35147 2011-02-25 10:47:28Z jesterking $
00003  * ***** BEGIN GPL LICENSE BLOCK *****
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00020  * All rights reserved.
00021  *
00022  * The Original Code is: all of this file.
00023  *
00024  * Contributor(s): none yet.
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 
00034 #ifndef NAN_INCLUDED_LOD_NdQuardic_h
00035 #define NAN_INCLUDED_LOD_NdQuardic_h
00036 
00037 // An N dimensional quadric form.
00039 
00040 #include "TNT/cmat.h"
00041 #include "TNT/vec.h"
00042 #include "MT_Matrix3x3.h"
00043 #include "LOD_Quadric.h"
00044 
00045 
00046 class LOD_NdQuadric {
00047 
00048 private :
00049 
00050         LOD_Quadric m_q;
00051 
00052         // For space efficiency we should not use
00053         // TNT matrices to hold variables in. Use
00054         // fixed sized arrays based on template size
00055         // and load them into the quadric only when
00056         // needed for computation.
00057 
00058         TNT::Vector<MT_Scalar> m_prop_grad1;
00059         TNT::Vector<MT_Scalar> m_prop_grad2;
00060         TNT::Vector<MT_Scalar> m_prop_grad3;
00061         TNT::Vector<MT_Scalar> m_bbottom;
00062 
00063         // Not essential but makes it easier to debug if keep an
00064         // explicit version of the diagonal.
00065 #if 1
00066         TNT::Vector<MT_Scalar> m_diag;
00067 #else
00068         MT_Scalar m_diag;
00069 #endif
00070 public :
00071 
00072         // The general idea of these 2 constructors
00073         // is that first you build a quadric Qg from the
00074         // geometric properties of a vertex v. Then for
00075         // each of the properties i construct a property
00076         // quadric Qpi. Then sum them altogether to get
00077         // the final combined geomeetry and property quadric
00078         // Qv = Qg + Qpi
00079 
00080         // Initialize a quadric with a default geometric plane
00081 
00082     LOD_NdQuadric(
00083                 const MT_Vector3 & vec,
00084                 const MT_Scalar & offset
00085         ); 
00086 
00087         // Initialize a quadric from a linear functional describing
00088         // the property gradient.pos is the position where this
00089         // functional is placed in the array.
00090 
00091         LOD_NdQuadric(
00092                 const MT_Vector3 & vec,
00093                 const MT_Scalar & offset,
00094                 int pos
00095         );
00096 
00097         // Make sure the internal vectors are of the correct size.
00098 
00099         LOD_NdQuadric(
00100         );
00101 
00102         // This class also has the default copy constructors
00103         // available.
00104 
00105         ~LOD_NdQuadric(
00106         ){
00107                 //nothing to do
00108         };
00109 
00110                 void
00111         Tensor(
00112                 TNT::Matrix<MT_Scalar> &                
00113         ) const; 
00114 
00115                 void
00116         Vector(
00117                 TNT::Vector<MT_Scalar> &
00118         ) const; 
00119 
00120                 void 
00121         Clear(
00122                 MT_Scalar val=0.0
00123         );
00124 
00125                 LOD_NdQuadric & 
00126         operator=(
00127                 const LOD_NdQuadric& Q
00128         ); 
00129                 
00130                 LOD_NdQuadric& 
00131         operator+=(
00132                 const LOD_NdQuadric& Q
00133         );
00134 
00135         // You can increase or decrease the relative importance
00136         // of a quadric prior the summation by multiplying it
00137         // with a scalar value s.
00138 
00139                 LOD_NdQuadric& 
00140         operator*=(
00141                 const MT_Scalar & s
00142         ); 
00143 
00144                 MT_Scalar 
00145         Evaluate(
00146                 const TNT::Vector<MT_Scalar> & vec
00147         ) const;
00148  
00149                 bool 
00150         Optimize(
00151                 TNT::Vector<MT_Scalar> & vec
00152         ) const ;
00153 
00154         
00155 };
00156 
00157 #endif
00158