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