OpenMesh
SubdividerT.hh
Go to the documentation of this file.
1 /* ========================================================================= *
2  * *
3  * OpenMesh *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openmesh.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenMesh. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40  * ========================================================================= */
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Date$ *
46  * *
47 \*===========================================================================*/
48 
53 //=============================================================================
54 //
55 // CLASS SubdividerT
56 //
57 //=============================================================================
58 
59 #ifndef OPENMESH_SUBDIVIDER_UNIFORM_SUDIVIDERT_HH
60 #define OPENMESH_SUBDIVIDER_UNIFORM_SUDIVIDERT_HH
61 
62 //== INCLUDE ==================================================================
63 
64 #include <OpenMesh/Core/System/config.hh>
65 #include <OpenMesh/Core/Utils/Noncopyable.hh>
66 #if defined(_DEBUG) || defined(DEBUG)
67 // Makes life lot easier, when playing/messing around with low-level topology
68 // changing methods of OpenMesh
69 # include <OpenMesh/Tools/Utils/MeshCheckerT.hh>
70 # define ASSERT_CONSISTENCY( T, m ) \
71  assert(OpenMesh::Utils::MeshCheckerT<T>(m).check())
72 #else
73 # define ASSERT_CONSISTENCY( T, m )
74 #endif
75 
76 //== NAMESPACE ================================================================
77 
78 namespace OpenMesh {
79 namespace Subdivider {
80 namespace Uniform {
81 
82 //== CLASS DEFINITION =========================================================
83 
92 template <typename MeshType, typename RealType = double>
94 {
95 public:
96 
97  typedef MeshType mesh_t;
98  typedef RealType real_t;
99 
100 public:
101 
103 
104  SubdividerT(void) : attached_() { }
107 
110  explicit SubdividerT( MeshType &_m ) : attached_(NULL) { attach(_m); }
111 
113 
115  virtual ~SubdividerT()
116  { detach(); }
117 
119  virtual const char *name( void ) const = 0;
120 
121 
122 public:
123 
125  bool operator () ( MeshType& _m, size_t _n , const bool _update_points = true)
128  {
129  return prepare(_m) && subdivide( _m, _n , _update_points ) && cleanup( _m );
130  }
132 
133 public:
134 
135  bool attach( MeshType& _m )
138  {
139  if ( attached_ == &_m )
140  return true;
141 
142  detach();
143  if (prepare( _m ))
144  {
145  attached_ = &_m;
146  return true;
147  }
148  return false;
149  }
150 
153  bool operator()( size_t _n , const bool _update_points = true)
154  {
155  return attached_ ? subdivide( *attached_, _n , _update_points) : false;
156  }
157 
160  void detach(void)
161  {
162  if ( attached_ )
163  {
164  cleanup( *attached_ );
165  attached_ = NULL;
166  }
167  }
169 
170 protected:
171 
173 
174  virtual bool prepare( MeshType& _m ) = 0;
176 
178  virtual bool subdivide( MeshType& _m, size_t _n, const bool _update_points = true) = 0;
179 
181  virtual bool cleanup( MeshType& _m ) = 0;
183 
184 private:
185 
186  MeshType *attached_;
187 
188 };
189 
190 //=============================================================================
191 } // namespace Uniform
192 } // namespace Subdivider
193 } // namespace OpenMesh
194 //=============================================================================
195 #endif // OPENMESH_SUBDIVIDER_UNIFORM_SUBDIVIDERT_HH
196 //=============================================================================
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
virtual bool subdivide(MeshType &_m, size_t _n, const bool _update_points=true)=0
Subdivide mesh _m _n times.
bool operator()(MeshType &_m, size_t _n, const bool _update_points=true)
Subdivide the mesh _m _n times.
Definition: SubdividerT.hh:127
virtual bool prepare(MeshType &_m)=0
Prepare mesh, e.g. add properties.
bool operator()(size_t _n, const bool _update_points=true)
Subdivide the attached _n times.
Definition: SubdividerT.hh:153
Abstract base class for uniform subdivision algorithms.
Definition: SubdividerT.hh:93
bool attach(MeshType &_m)
Attach mesh _m to self.
Definition: SubdividerT.hh:137
virtual ~SubdividerT()
Destructor (calls detach())
Definition: SubdividerT.hh:115
virtual bool cleanup(MeshType &_m)=0
Cleanup mesh after usage, e.g. remove added properties.
virtual const char * name(void) const =0
Return name of subdivision algorithm.
SubdividerT(void)
Constructor to be used with interface 2.
Definition: SubdividerT.hh:106
This class demonstrates the non copyable idiom.
Definition: Noncopyable.hh:76
void detach(void)
Detach an eventually attached mesh.
Definition: SubdividerT.hh:160
SubdividerT(MeshType &_m)
Constructor to be used with interface 1 (calls attach())
Definition: SubdividerT.hh:110

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