OpenMesh
SubdividerT.hh
Go to the documentation of this file.
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2025, 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
48//=============================================================================
49//
50// CLASS SubdividerT
51//
52//=============================================================================
53
54#ifndef OPENMESH_SUBDIVIDER_UNIFORM_SUDIVIDERT_HH
55#define OPENMESH_SUBDIVIDER_UNIFORM_SUDIVIDERT_HH
56
57//== INCLUDE ==================================================================
58
59#include <OpenMesh/Core/System/config.hh>
60#include <OpenMesh/Core/Utils/Noncopyable.hh>
61#if defined(_DEBUG) || defined(DEBUG)
62// Makes life lot easier, when playing/messing around with low-level topology
63// changing methods of OpenMesh
64# include <OpenMesh/Tools/Utils/MeshCheckerT.hh>
65# define ASSERT_CONSISTENCY( T, m ) \
66 assert(OpenMesh::Utils::MeshCheckerT<T>(m).check())
67#else
68# define ASSERT_CONSISTENCY( T, m )
69#endif
70
71//== NAMESPACE ================================================================
72
73namespace OpenMesh {
74namespace Subdivider {
75namespace Uniform {
76
77//== CLASS DEFINITION =========================================================
78
87template <typename MeshType, typename RealType = double>
89{
90public:
91
92 typedef MeshType mesh_t;
93 typedef RealType real_t;
94
95public:
96
98
99
101 SubdividerT(void) : attached_() { }
102
105 explicit SubdividerT( MeshType &_m ) : attached_(nullptr) { attach(_m); }
106
108
110 virtual ~SubdividerT()
111 { detach(); }
112
114 virtual const char *name( void ) const = 0;
115
116
117public:
118
120
122 bool operator () ( MeshType& _m, size_t _n , const bool _update_points = true)
123 {
124 return prepare(_m) && subdivide( _m, _n , _update_points ) && cleanup( _m );
125 }
127
128public:
130
132 bool attach( MeshType& _m )
133 {
134 if ( attached_ == &_m )
135 return true;
136
137 detach();
138 if (prepare( _m ))
139 {
140 attached_ = &_m;
141 return true;
142 }
143 return false;
144 }
145
148 bool operator()( size_t _n , const bool _update_points = true)
149 {
150 return attached_ ? subdivide( *attached_, _n , _update_points) : false;
151 }
152
155 void detach(void)
156 {
157 if ( attached_ )
158 {
159 cleanup( *attached_ );
160 attached_ = nullptr;
161 }
162 }
164
165protected:
166
168
169
174 virtual bool prepare( MeshType& /*_m*/ ) { return false; };
175
177 virtual bool subdivide( MeshType& _m, size_t _n, const bool _update_points = true) = 0;
178
180 virtual bool cleanup( MeshType& _m ) = 0;
182
183private:
184
185 MeshType *attached_;
186
187};
188
189//=============================================================================
190} // namespace Uniform
191} // namespace Subdivider
192} // namespace OpenMesh
193//=============================================================================
194#endif // OPENMESH_SUBDIVIDER_UNIFORM_SUBDIVIDERT_HH
195//=============================================================================
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
This class demonstrates the non copyable idiom.
Definition: Noncopyable.hh:72
Abstract base class for uniform subdivision algorithms.
Definition: SubdividerT.hh:89
virtual bool cleanup(MeshType &_m)=0
Cleanup mesh after usage, e.g. remove added properties.
bool operator()(MeshType &_m, size_t _n, const bool _update_points=true)
Subdivide the mesh _m _n times.
Definition: SubdividerT.hh:122
bool operator()(size_t _n, const bool _update_points=true)
Subdivide the attached _n times.
Definition: SubdividerT.hh:148
bool attach(MeshType &_m)
Attach mesh _m to self.
Definition: SubdividerT.hh:132
void detach(void)
Detach an eventually attached mesh.
Definition: SubdividerT.hh:155
SubdividerT(MeshType &_m)
Constructor to be used with interface 1 (calls attach())
Definition: SubdividerT.hh:105
SubdividerT(void)
Constructor to be used with interface 2.
Definition: SubdividerT.hh:101
virtual ~SubdividerT()
Destructor (calls detach())
Definition: SubdividerT.hh:110
virtual bool subdivide(MeshType &_m, size_t _n, const bool _update_points=true)=0
Subdivide mesh _m _n times.
virtual bool prepare(MeshType &)
Prepare mesh, e.g.
Definition: SubdividerT.hh:174
virtual const char * name(void) const =0
Return name of subdivision algorithm.

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .