OpenMesh
|
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_TRAITS_HH 00053 #define OPENMESH_SUBDIVIDER_ADAPTIVE_TRAITS_HH 00054 00055 00056 //== INCLUDES ================================================================= 00057 00058 #include <map> 00059 #include <OpenMesh/Core/Mesh/Types/TriMesh_ArrayKernelT.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 00077 typedef int state_t; 00078 typedef bool final_t; 00079 00080 struct State 00081 { 00082 int state : 31; 00083 unsigned final : 1; 00084 }; 00085 00086 struct Traits : public OpenMesh::DefaultTraits 00087 { 00088 00089 // add face normals 00090 FaceAttributes( OpenMesh::Attributes::Normal ); 00091 00092 // add vertex normals 00093 VertexAttributes( OpenMesh::Attributes::Normal ); 00094 00095 // add previous halfedge handle 00096 HalfedgeAttributes( OpenMesh::Attributes::PrevHalfedge ); 00097 00098 FaceTraits 00099 { 00100 00101 private: 00102 00103 typedef typename Refs::Point Point; 00104 typedef typename Refs::HalfedgeHandle HalfedgeHandle; 00105 typedef std::map<state_t, Point> PositionHistory; 00106 00107 State state_; 00108 HalfedgeHandle red_halfedge_; 00109 00110 PositionHistory pos_map_; 00111 00112 public: 00113 00114 // face state 00115 state_t state() const { return state_t(state_.state); } 00116 void set_state(const state_t _s) { state_.state = _s; } 00117 void inc_state() { ++state_.state; } 00118 00119 // face not final if divided (loop) or edge not flipped (sqrt(3)) 00120 final_t final() const { return final_t(state_.final); } 00121 void set_final() { state_.final = true; } 00122 void set_not_final() { state_.final = false; } 00123 00124 // halfedge of dividing edge (red-green triangulation) 00125 const HalfedgeHandle& red_halfedge() const { return red_halfedge_; } 00126 void set_red_halfedge(const HalfedgeHandle& _h) { red_halfedge_ = _h; } 00127 00128 // position of face, depending on generation _i. 00129 void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; } 00130 const Point position(const int& _i) { 00131 if (pos_map_.find(_i) != pos_map_.end()) 00132 return pos_map_[_i]; 00133 else { 00134 00135 if (_i <= 0) { 00136 const Point zero_point(0.0, 0.0, 0.0); 00137 return zero_point; 00138 } 00139 00140 return position(_i - 1); 00141 } 00142 } 00143 }; // end class FaceTraits 00144 00145 00146 EdgeTraits 00147 { 00148 00149 private: 00150 00151 typedef typename Refs::Point Point; 00152 typedef std::map<state_t, Point> PositionHistory; 00153 00154 State state_; 00155 PositionHistory pos_map_; 00156 00157 public: 00158 00159 typedef typename Refs::Scalar Scalar; 00160 00161 // Scalar weight_; 00162 00163 // state of edge 00164 state_t state() const { return state_t(state_.state); } 00165 void set_state(const state_t _s) { state_.state = _s; } 00166 void inc_state() { ++state_.state; } 00167 00168 // edge not final if dividing face (Loop) or edge not flipped (SQRT(3)) 00169 final_t final() const { return final_t(state_.final); } 00170 void set_final() { state_.final = true; } 00171 void set_not_final() { state_.final = false; } 00172 00173 // position of edge, depending on generation _i. 00174 void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; } 00175 const Point position(const int& _i) { 00176 00177 if (pos_map_.find(_i) != pos_map_.end()) 00178 { 00179 return pos_map_[_i]; 00180 } 00181 else 00182 { 00183 if (_i <= 0) 00184 { 00185 const Point zero_point(0.0, 0.0, 0.0); 00186 return zero_point; 00187 } 00188 00189 return position(_i - 1); 00190 } 00191 } 00192 }; // end class EdgeTraits 00193 00194 00195 VertexTraits 00196 { 00197 00198 private: 00199 00200 typedef typename Refs::Point Point; 00201 typedef std::map<state_t, Point> PositionHistory; 00202 00203 State state_; 00204 00205 PositionHistory pos_map_; 00206 00207 public: 00208 00209 // state of vertex 00210 state_t state() const { return state_.state; } 00211 void set_state(const state_t _s) { state_.state = _s; } 00212 void inc_state() { ++state_.state; } 00213 00214 00215 // usually not needed by loop or sqrt(3) 00216 final_t final() const { return state_.final; } 00217 void set_final() { state_.final = true; } 00218 void set_not_final() { state_.final = false; } 00219 00220 // position of vertex, depending on generation _i. (not for display) 00221 void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; } 00222 const Point position(const int& _i) { 00223 00224 if (pos_map_.find(_i) != pos_map_.end()) 00225 00226 return pos_map_[_i]; 00227 00228 else { 00229 00230 if (_i <= 0) { 00231 00232 const Point zero_point(0.0, 0.0, 0.0); 00233 return zero_point; 00234 } 00235 00236 return position(_i - 1); 00237 } 00238 } 00239 }; // end class VertexTraits 00240 }; // end class Traits 00241 00242 //============================================================================= 00243 } // END_NS_ADAPTIVE 00244 } // END_NS_SUBDIVIDER 00245 } // END_NS_OPENMESH 00246 //============================================================================= 00247 #endif // OPENMESH_SUBDIVIDER_ADAPTIVE_TRAITS_HH defined 00248 //=============================================================================