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

CompositeTraits.hh

Go to the documentation of this file.
00001 //=============================================================================
00002 //                                                                            
00003 //                               OpenMesh                                     
00004 //      Copyright (C) 2001-2005 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.1.1.1 $
00027 //   $Date: 2004/09/06 12:37:16 $
00028 //                                                                            
00029 //=============================================================================
00030 
00035 //=============================================================================
00036 //
00037 //  CLASS Traits
00038 //
00039 //=============================================================================
00040 
00041 #ifndef OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITETRAITS_HH
00042 #define OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITETRAITS_HH
00043 
00044 
00045 //== INCLUDES =================================================================
00046 
00047 #include <map>
00048 #include <OpenMesh/Core/Mesh/Traits.hh>
00049 
00050 //== NAMESPACE ================================================================
00051 
00052 namespace OpenMesh   { // BEGIN_NS_OPENMESH
00053 namespace Subdivider { // BEGIN_NS_DECIMATER
00054 namespace Adaptive   { // BEGIN_NS_UNIFORM
00055 
00056 
00057 //== CLASS DEFINITION =========================================================
00058 
00062 // typedef unsigned short state_t;
00063 // const state_t mask_final = 1 << ((sizeof(state_t)*8)-1);
00064 // const state_t mask_state = ~mask_final;
00065 
00068 struct CompositeTraits : public OpenMesh::DefaultTraits
00069 {
00070   typedef int  state_t; 
00071   typedef bool final_t; 
00072   
00073   
00075   struct State
00076   {
00077     int      state : 31;
00078     unsigned final : 1;
00079   };  
00080 
00081   // ---------------------------------------- attributes
00082 
00083   // add face normals
00084   FaceAttributes( OpenMesh::Attributes::Normal );
00085   
00086   // add vertex normals
00087   VertexAttributes( OpenMesh::Attributes::Normal );
00088   
00089   // add previous halfedge handle
00090   HalfedgeAttributes( OpenMesh::Attributes::PrevHalfedge );
00091 
00092   // ---------------------------------------- items
00093 
00094   FaceTraits
00095   {
00096     
00097   private:
00098     
00099     typedef typename Refs::Point Point;
00100     typedef typename Refs::HalfedgeHandle HalfedgeHandle;
00101     typedef std::map<state_t, Point> PositionHistory;
00102     
00103     State                state_;
00104     HalfedgeHandle       red_halfedge_;
00105     
00106     PositionHistory      pos_map_;
00107     
00108   public:
00109     
00110     // face state
00111     state_t state() const { return state_t(state_.state); }
00112     void    set_state(const state_t _s) { state_.state = _s; }
00113     void    inc_state() { ++state_.state; }
00114     
00115     // face not final if divided (loop) or edge not flipped (sqrt(3))
00116     final_t final() const   { return final_t(state_.final); }
00117     void    set_final()     { state_.final = true; }
00118     void    set_not_final() { state_.final = false; }
00119     
00120     // halfedge of dividing edge (red-green triangulation)
00121     const HalfedgeHandle& red_halfedge() const { return red_halfedge_; }
00122     void  set_red_halfedge(const HalfedgeHandle& _h) { red_halfedge_ = _h; }
00123     
00124     // position of face, depending on generation _i. 
00125     void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; }
00126     const Point position(const int& _i) { 
00127       if (pos_map_.find(_i) != pos_map_.end())
00128         return pos_map_[_i];
00129       else {
00130         
00131         if (_i <= 0) {
00132           return Point(0.0, 0.0, 0.0);
00133         }
00134         
00135         return position(_i - 1);
00136       }
00137     }
00138   }; // end class FaceTraits
00139   
00140   
00141   EdgeTraits
00142   {
00143     
00144   private:
00145     
00146     typedef typename Refs::Point Point;
00147     typedef std::map<state_t, Point> PositionHistory;
00148     
00149     State           state_;
00150     PositionHistory pos_map_;
00151     
00152   public: 
00153     
00154     typedef typename Refs::Scalar Scalar;
00155     
00156     // Scalar weight_;
00157     
00158     // state of edge
00159     state_t state() const { return state_t(state_.state); }
00160     void    set_state(const state_t _s) { state_.state = _s; }
00161     void    inc_state() { ++state_.state; }
00162     
00163     // edge not final if dividing face (Loop) or edge not flipped (SQRT(3))
00164     final_t final() const   { return final_t(state_.final); }
00165     void    set_final()     { state_.final = true; }
00166     void    set_not_final() { state_.final = false; }
00167     
00168     // position of edge, depending on generation _i. 
00169     void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; }
00170     
00171     const Point position(const int& _i) {
00172         
00173       if (pos_map_.find(_i) != pos_map_.end()) 
00174         return pos_map_[_i];
00175       else 
00176       {
00177         if (_i <= 0) 
00178         {
00179           const Point zero_point(0.0, 0.0, 0.0);
00180           return zero_point;
00181         }
00182         
00183         return position(_i - 1);
00184       }
00185     }
00186   }; // end class EdgeTraits
00187 
00188 
00189   VertexTraits
00190   {
00191 
00192   private:
00193 
00194     typedef typename Refs::Point Point;
00195     typedef std::map<state_t, Point> PositionHistory;
00196 
00197     State           state_;
00198     PositionHistory pos_map_;
00199 
00200   public:
00201 
00202     // state of vertex
00203     state_t state() const { return state_.state; }
00204     void    set_state(const state_t _s) { state_.state = _s; }
00205     void    inc_state() { ++state_.state; }
00206 
00207 
00208     // usually not needed by loop or sqrt(3)
00209     final_t final() const   { return state_.final; }
00210     void    set_final()     { state_.final = true; }
00211     void    set_not_final() { state_.final = false; }
00212 
00213     // position of vertex, depending on generation _i. (not for display)
00214     void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; }
00215     const Point position(const int& _i) { 
00216 
00217       if (pos_map_.find(_i) != pos_map_.end()) 
00218 
00219         return pos_map_[_i];
00220 
00221       else {
00222 
00223         if (_i <= 0) {
00224 
00225           const Point zero_point(0.0, 0.0, 0.0);
00226           return zero_point;
00227         }
00228 
00229         return position(_i - 1);
00230       }
00231     }
00232   }; // end class VertexTraits
00233 }; // end class CompositeTraits
00234 
00235 
00236 // export items to namespace to maintain compatibility
00237 typedef CompositeTraits::state_t state_t;
00238 typedef CompositeTraits::final_t final_t;
00239 typedef CompositeTraits::State   State;
00240 
00241 //=============================================================================
00242 } // END_NS_ADAPTIVE
00243 } // END_NS_SUBDIVIDER
00244 } // END_NS_OPENMESH
00245 //=============================================================================
00246 #endif // OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITETRAITS_HH defined
00247 //=============================================================================

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