OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SubdividerT.hh
Go to the documentation of this file.
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5 * www.openmesh.org *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of OpenMesh. *
9 * *
10 * OpenMesh is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenMesh is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenMesh. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34
35 /*===========================================================================*\
36 * *
37 * $Revision: 736 $ *
38 * $Date: 2012-10-08 09:30:49 +0200 (Mo, 08. Okt 2012) $ *
39 * *
40 \*===========================================================================*/
41
46 //=============================================================================
47 //
48 // CLASS SubdividerT
49 //
50 //=============================================================================
51
52 #ifndef OPENMESH_SUBDIVIDER_UNIFORM_SUDIVIDERT_HH
53 #define OPENMESH_SUBDIVIDER_UNIFORM_SUDIVIDERT_HH
54
55 //== INCLUDE ==================================================================
56
57 #include <OpenMesh/Core/System/config.hh>
58 #include <OpenMesh/Core/Utils/Noncopyable.hh>
59 #if defined(_DEBUG) || defined(DEBUG)
60 // Makes life lot easier, when playing/messing around with low-level topology
61 // changing methods of OpenMesh
62 # include <OpenMesh/Tools/Utils/MeshCheckerT.hh>
63 # define ASSERT_CONSISTENCY( T, m ) \
64 assert(OpenMesh::Utils::MeshCheckerT<T>(m).check())
65 #else
66 # define ASSERT_CONSISTENCY( T, m )
67 #endif
68
69 //== NAMESPACE ================================================================
70
71 namespace OpenMesh {
72 namespace Subdivider {
73 namespace Uniform {
74
75
76 //== CLASS DEFINITION =========================================================
77
86 template <typename MeshType, typename RealType=float>
87 class SubdividerT : private Utils::Noncopyable
88 {
89 public:
90
91 typedef MeshType mesh_t;
92 typedef RealType real_t;
93
94 public:
95
97
98
99
100 SubdividerT(void) : attached_(NULL) { }
101
104 SubdividerT( MeshType &_m ) : attached_(NULL) { attach(_m); }
105
107
109 virtual ~SubdividerT()
110 { detach(); }
111
113 virtual const char *name( void ) const = 0;
114
115
116 public:
117
119
120
121 bool operator () ( MeshType& _m, size_t _n , const bool _update_points = true)
122 {
123 return prepare(_m) && subdivide( _m, _n , _update_points ) && cleanup( _m );
124 }
126
127 public:
128
129
130
131 bool attach( MeshType& _m )
132 {
133 if ( attached_ == &_m )
134 return true;
135
136 detach();
137 if (prepare( _m ))
138 {
139 attached_ = &_m;
140 return true;
141 }
142 return false;
143 }
144
147 bool operator()( size_t _n , const bool _update_points = true)
148 {
149 return attached_ ? subdivide( *attached_, _n , _update_points) : false;
150 }
151
154 void detach(void)
155 {
156 if ( attached_ )
157 {
158 cleanup( *attached_ );
159 attached_ = NULL;
160 }
161 }
163
164 protected:
165
167
168
169 virtual bool prepare( MeshType& _m ) = 0;
170
172 virtual bool subdivide( MeshType& _m, size_t _n, const bool _update_points = true) = 0;
173
175 virtual bool cleanup( MeshType& _m ) = 0;
177
178 private:
179
180 MeshType *attached_;
181
182 };
183
184 //=============================================================================
185 } // namespace Uniform
186 } // namespace Subdivider
187 } // namespace OpenMesh
188 //=============================================================================
189 #endif // OPENMESH_SUBDIVIDER_UNIFORM_SUBDIVIDERT_HH
190 //=============================================================================