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 
83 //== CLASS DEFINITION =========================================================
84 
93 template <typename MeshType, typename RealType=float>
95 {
96 public:
97 
98  typedef MeshType mesh_t;
99  typedef RealType real_t;
100 
101 public:
102 
104 
105  SubdividerT(void) : attached_(NULL) { }
108 
111  SubdividerT( MeshType &_m ) : attached_(NULL) { attach(_m); }
112 
114 
116  virtual ~SubdividerT()
117  { detach(); }
118 
120  virtual const char *name( void ) const = 0;
121 
122 
123 public:
124 
126  bool operator () ( MeshType& _m, size_t _n , const bool _update_points = true)
129  {
130  return prepare(_m) && subdivide( _m, _n , _update_points ) && cleanup( _m );
131  }
133 
134 public:
135 
136  bool attach( MeshType& _m )
139  {
140  if ( attached_ == &_m )
141  return true;
142 
143  detach();
144  if (prepare( _m ))
145  {
146  attached_ = &_m;
147  return true;
148  }
149  return false;
150  }
151 
154  bool operator()( size_t _n , const bool _update_points = true)
155  {
156  return attached_ ? subdivide( *attached_, _n , _update_points) : false;
157  }
158 
161  void detach(void)
162  {
163  if ( attached_ )
164  {
165  cleanup( *attached_ );
166  attached_ = NULL;
167  }
168  }
170 
171 protected:
172 
174 
175  virtual bool prepare( MeshType& _m ) = 0;
177 
179  virtual bool subdivide( MeshType& _m, size_t _n, const bool _update_points = true) = 0;
180 
182  virtual bool cleanup( MeshType& _m ) = 0;
184 
185 private:
186 
187  MeshType *attached_;
188 
189 };
190 
191 //=============================================================================
192 } // namespace Uniform
193 } // namespace Subdivider
194 } // namespace OpenMesh
195 //=============================================================================
196 #endif // OPENMESH_SUBDIVIDER_UNIFORM_SUBDIVIDERT_HH
197 //=============================================================================
bool operator()(size_t _n, const bool _update_points=true)
Subdivide the attached _n times.
Definition: SubdividerT.hh:154
Abstract base class for uniform subdivision algorithms.
Definition: SubdividerT.hh:94
SubdividerT(void)
Constructor to be used with interface 2.
Definition: SubdividerT.hh:107
void detach(void)
Detach an eventually attached mesh.
Definition: SubdividerT.hh:161
bool attach(MeshType &_m)
Attach mesh _m to self.
Definition: SubdividerT.hh:138
virtual bool prepare(MeshType &_m)=0
Prepare mesh, e.g. add properties.
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(MeshType &_m)
Constructor to be used with interface 1 (calls attach())
Definition: SubdividerT.hh:111
bool operator()(MeshType &_m, size_t _n, const bool _update_points=true)
Subdivide the mesh _m _n times.
Definition: SubdividerT.hh:128
virtual bool subdivide(MeshType &_m, size_t _n, const bool _update_points=true)=0
Subdivide mesh _m _n times.
This class demonstrates the non copyable idiom.
Definition: Noncopyable.hh:76
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
virtual ~SubdividerT()
Descructor (calls detach())
Definition: SubdividerT.hh:116

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