Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

bmesh_curvature.H

Go to the documentation of this file.
00001 #ifndef BMESH_CURVATURE_H_IS_INCLUDED
00002 #define BMESH_CURVATURE_H_IS_INCLUDED
00003 
00004 /*!
00005  *  \file bmesh_curvature.H
00006  *  \brief Contains the declaration of the curvature computation classes
00007  *  for the BMESH class.
00008  *
00009  *  \note This uses code from the TriMesh2 library written by Szymon Rusinkiewicz
00010  *  of Princeton University (http://www.cs.princeton.edu/gfx/proj/trimesh2/).
00011  *
00012  */
00013 
00014 #include <vector>
00015 
00016 class Bvert;
00017 class BMESH;
00018 
00019 /*!
00020  *  \brief Computes curvature data for a BMESH object.
00021  *
00022  */
00023 class BMESHcurvature_data {
00024    
00025    public:
00026    
00027       //! \name Constructors
00028       //@{
00029    
00030       //! \brief Computes all curvature data for the given BMESH.
00031       BMESHcurvature_data(const BMESH *mesh_in);
00032       
00033       //@}
00034    
00035       //! \name Curvature Data Structures
00036       //! These structures store various different types of data needed for
00037       //! computing the curvature of a BMESH.
00038       //@{
00039    
00040       /*!
00041        *  \brief Stores "Voronoi" corner area values for a single face in a mesh.
00042        *
00043        */
00044       struct corner_areas_t {
00045       
00046          corner_areas_t(double val = 0.0) { areas[0] = areas[1] = areas[2] = val; }
00047          
00048          double areas[3];
00049          
00050          double &operator[](int idx) { return areas[idx]; }
00051          double operator[](int idx) const { return areas[idx]; }
00052          
00053       };
00054    
00055       /*!
00056        *  \brief Stores the three unique values of a 2x2 curvature tensor.
00057        *  
00058        *  This is used to store curvature tensors for both faces and vertices.
00059        *
00060        */
00061       struct curv_tensor_t {
00062          
00063          curv_tensor_t(double val = 0.0)
00064             { curv[0] = curv[1] = curv[2] = val; }
00065             
00066          curv_tensor_t(double val0, double val1, double val2)
00067             { curv[0] = val0; curv[1] = val1; curv[2] = val2; }
00068          
00069          double curv[3];
00070          
00071          double &operator[](int idx) { return curv[idx]; }
00072          double operator[](int idx) const { return curv[idx]; }
00073          
00074          curv_tensor_t operator+(const curv_tensor_t &other) const
00075             { return curv_tensor_t(curv[0] + other[0],
00076                                    curv[1] + other[1],
00077                                    curv[2] + other[2]); }
00078          
00079          curv_tensor_t &operator+=(const curv_tensor_t &other)
00080             { *this = curv_tensor_t(curv[0] + other[0], curv[1] + other[1],
00081                                     curv[2] + other[2]);
00082               return *this; }
00083          
00084          curv_tensor_t operator-(const curv_tensor_t &other) const
00085             { return curv_tensor_t(curv[0] - other[0],
00086                                    curv[1] - other[1],
00087                                    curv[2] - other[2]); }
00088          
00089          curv_tensor_t operator*(double s) const
00090             { return curv_tensor_t(curv[0]*s, curv[1]*s, curv[2]*s); }
00091             
00092          friend curv_tensor_t operator*(double s, const curv_tensor_t &curv)
00093             { return curv*s; }
00094          
00095       };
00096    
00097       /*!
00098        *  \brief Stores the four unique values of a 2x2x2 curvature derivative
00099        *  tensor.
00100        *  
00101        *  This is used to store curvature derivative tensors for both faces and
00102        *  vertices.
00103        *
00104        */
00105       struct dcurv_tensor_t {
00106          
00107          dcurv_tensor_t(double val = 0.0)
00108             { dcurv[0] = dcurv[1] = dcurv[2] = dcurv[3] = val; }
00109          
00110          dcurv_tensor_t(double val0, double val1, double val2, double val3)
00111             { dcurv[0] = val0; dcurv[1] = val1; dcurv[2] = val2; dcurv[3] = val3; }
00112          
00113          double dcurv[4];
00114          
00115          double &operator[](int idx) { return dcurv[idx]; }
00116          double operator[](int idx) const { return dcurv[idx]; }
00117          
00118          dcurv_tensor_t operator+(const dcurv_tensor_t &other) const
00119             { return dcurv_tensor_t(dcurv[0] + other[0], dcurv[1] + other[1],
00120                                     dcurv[2] + other[2], dcurv[3] + other[3]); }
00121          
00122          dcurv_tensor_t &operator+=(const dcurv_tensor_t &other)
00123             { *this = dcurv_tensor_t(dcurv[0] + other[0], dcurv[1] + other[1],
00124                                      dcurv[2] + other[2], dcurv[3] + other[3]);
00125               return *this; }
00126          
00127          dcurv_tensor_t operator-(const dcurv_tensor_t &other) const
00128             { return dcurv_tensor_t(dcurv[0] - other[0], dcurv[1] - other[1],
00129                                     dcurv[2] - other[2], dcurv[3] - other[3]); }
00130          
00131          dcurv_tensor_t operator*(double s) const
00132             { return dcurv_tensor_t(dcurv[0]*s, dcurv[1]*s, dcurv[2]*s, dcurv[3]*s); }
00133             
00134          friend dcurv_tensor_t operator*(double s, const dcurv_tensor_t &dcurv)
00135             { return dcurv*s; }
00136          
00137       };
00138    
00139       /*!
00140        *  \brief Stores the results of diagonalizing a curvature tensor for a
00141        *  vertex.  Specifically it stores the principal curvatures and directions
00142        *  for a vertex.
00143        *
00144        */
00145       struct diag_curv_t {
00146          
00147 //          Wvec curv1, curv2;
00148 //          
00149 //          double k1() const { return curv1.length(); }
00150 //          double k2() const { return curv2.length(); }
00151 //          
00152 //          Wvec pdir1() const { return curv1.normalized(); }
00153 //          Wvec pdir2() const { return curv2.normalized(); }
00154          
00155          double _k1, _k2;
00156          Wvec _pdir1, _pdir2;
00157          
00158          double k1() const { return _k1; }
00159          double k2() const { return _k2; }
00160          
00161          Wvec pdir1() const { return _pdir1; }
00162          Wvec pdir2() const { return _pdir2; }
00163          
00164       };
00165       
00166       //@}
00167       
00168       //! \name Curvature Data Queries
00169       //@{
00170       
00171       curv_tensor_t curv_tensor(const Bvert *v);
00172       diag_curv_t diag_curv(const Bvert *v);
00173       double k1(const Bvert *v);
00174       double k2(const Bvert *v);
00175       Wvec pdir1(const Bvert *v);
00176       Wvec pdir2(const Bvert *v);
00177       dcurv_tensor_t dcurv_tensor(const Bvert *v);
00178       double feature_size()
00179          { return mesh_feature_size; }
00180       
00181       //@}
00182    
00183    private:
00184    
00185       const BMESH *mesh;
00186       
00187       std::vector<corner_areas_t> corner_areas;   //!< "Voronoi" corner areas for all faces.
00188       std::vector<double> vertex_areas;           //!< "Voronoi" areas for all vertices.
00189       std::vector<curv_tensor_t> face_curv;       //!< Per-face curvature tensors.
00190       std::vector<curv_tensor_t> vertex_curv;     //!< Per-vertex curvature tensors.
00191       std::vector<diag_curv_t> diag_vertex_curv;  //!< Diagonolized per-vertex curvature tensors.
00192       std::vector<dcurv_tensor_t> face_dcurv;     //!< Per-face curvature derivative tensors.
00193       std::vector<dcurv_tensor_t> vertex_dcurv;   //!< Per-vertex curvature derivative tensors.
00194       double mesh_feature_size;                   //!< Feature size of the mesh.
00195       
00196       //! \name Curvature Computation Functions
00197       //@{
00198       
00199       void compute_corner_areas();
00200       void compute_vertex_areas();
00201       void compute_face_curvatures();
00202       void compute_vertex_curvatures();
00203       void diagonalize_vertex_curvatures();
00204       void compute_face_dcurv();
00205       void compute_vertex_dcurv();
00206       void compute_feature_size();
00207       
00208       //@}
00209 
00210 };
00211 
00212 #endif

Generated on Mon Sep 18 11:39:28 2006 for jot by  doxygen 1.4.4