Developer Documentation

DecimaterT.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
47 //=============================================================================
48 //
49 // CLASS DecimaterT
50 //
51 //=============================================================================
52
53 #ifndef OPENMESH_DECIMATER_DECIMATERT_HH
54 #define OPENMESH_DECIMATER_DECIMATERT_HH
55
56
57 //== INCLUDES =================================================================
58
59 #include <memory>
60
61 #include <OpenMesh/Core/Utils/Property.hh>
62 #include <OpenMesh/Tools/Utils/HeapT.hh>
63 #include <OpenMesh/Tools/Decimater/BaseDecimaterT.hh>
64
65 //== NAMESPACE ================================================================
66
67 namespace OpenMesh {
68 namespace Decimater {
69
70
71 //== CLASS DEFINITION =========================================================
72
73
77 template < typename MeshT >
78 class DecimaterT : virtual public BaseDecimaterT<MeshT> //virtual especially for the mixed decimater
79 {
80 public: //-------------------------------------------------------- public types
81
82 typedef DecimaterT< MeshT > Self;
83 typedef MeshT Mesh;
84 typedef CollapseInfoT<MeshT> CollapseInfo;
85 typedef ModBaseT<MeshT> Module;
86 typedef std::vector< Module* > ModuleList;
87 typedef typename ModuleList::iterator ModuleListIterator;
88
89 public: //------------------------------------------------------ public methods
90
92 explicit DecimaterT( Mesh& _mesh );
93
95 ~DecimaterT();
96
97 public:
98
108 size_t decimate( size_t _n_collapses = 0 );
109
119 size_t decimate_to( size_t _n_vertices )
120 {
121 return ( (_n_vertices < this->mesh().n_vertices()) ?
122 decimate( this->mesh().n_vertices() - _n_vertices ) : 0 );
123 }
124
137 size_t decimate_to_faces( size_t _n_vertices=0, size_t _n_faces=0 );
138
139 public:
140
141 typedef typename Mesh::VertexHandle VertexHandle;
142 typedef typename Mesh::HalfedgeHandle HalfedgeHandle;
143
145 class HeapInterface
146 {
147 public:
148
149 HeapInterface(Mesh& _mesh,
150 VPropHandleT<float> _prio,
151 VPropHandleT<int> _pos)
152 : mesh_(_mesh), prio_(_prio), pos_(_pos)
153 { }
154
155 inline bool
156 less( VertexHandle _vh0, VertexHandle _vh1 )
157 { return mesh_.property(prio_, _vh0) < mesh_.property(prio_, _vh1); }
158
159 inline bool
160 greater( VertexHandle _vh0, VertexHandle _vh1 )
161 { return mesh_.property(prio_, _vh0) > mesh_.property(prio_, _vh1); }
162
163 inline int
164 get_heap_position(VertexHandle _vh)
165 { return mesh_.property(pos_, _vh); }
166
167 inline void
168 set_heap_position(VertexHandle _vh, int _pos)
169 { mesh_.property(pos_, _vh) = _pos; }
170
171
172 private:
173 Mesh& mesh_;
174 VPropHandleT<float> prio_;
175 VPropHandleT<int> pos_;
176 };
177
178 typedef Utils::HeapT<VertexHandle, HeapInterface> DeciHeap;
179
180
181 private: //---------------------------------------------------- private methods
182
184 void heap_vertex(VertexHandle _vh);
185
186 private: //------------------------------------------------------- private data
187
188
189 // reference to mesh
190 Mesh& mesh_;
191
192 // heap
193 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined( __GXX_EXPERIMENTAL_CXX0X__ )
194 std::unique_ptr<DeciHeap> heap_;
195 #else
196 std::auto_ptr<DeciHeap> heap_;
197 #endif
198
199 // vertex properties
200 VPropHandleT<HalfedgeHandle> collapse_target_;
201 VPropHandleT<float> priority_;
202 VPropHandleT<int> heap_position_;
203
204 };
205
206 //=============================================================================
207 } // END_NS_DECIMATER
208 } // END_NS_OPENMESH
209 //=============================================================================
210 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_DECIMATERT_CC)
211 #define OPENMESH_DECIMATER_TEMPLATES
212 #include "DecimaterT_impl.hh"
213 #endif
214 //=============================================================================
215 #endif // OPENMESH_DECIMATER_DECIMATERT_HH defined
216 //=============================================================================
217
OpenMesh::Decimater::DecimaterT::~DecimaterT
~DecimaterT()
Destructor.
Definition: DecimaterT_impl.hh:92
OpenMesh::Decimater::CollapseInfoT
Definition: CollapseInfoT.hh:74
OpenMesh::VPropHandleT< float >
OpenMesh::Utils::HeapT
Definition: HeapT.hh:138
OpenMesh::Decimater::ModBaseT
Definition: ModBaseT.hh:192
OpenMesh::Decimater::DecimaterT::DecimaterT
DecimaterT(Mesh &_mesh)
Constructor.
Definition: DecimaterT_impl.hh:72
OpenMesh::Decimater::BaseDecimaterT
Definition: BaseDecimaterT.hh:85
OpenMesh::Decimater::BaseDecimaterT::mesh
Mesh & mesh()
access mesh. used in modules.
Definition: BaseDecimaterT.hh:138
OpenMesh
Definition: MeshItems.hh:59
OpenMesh::Decimater::DecimaterT::decimate_to_faces
size_t decimate_to_faces(size_t _n_vertices=0, size_t _n_faces=0)
Attempts to decimate the mesh until a desired vertex or face complexity is achieved.
Definition: DecimaterT_impl.hh:254
BaseDecimaterT.hh
OpenMesh::Decimater::DecimaterT::heap_vertex
void heap_vertex(VertexHandle _vh)
Insert vertex in heap.
Definition: DecimaterT_impl.hh:104
DecimaterT_impl.hh
HeapT.hh
OpenMesh::Decimater::DecimaterT
Definition: DecimaterT.hh:78
OpenMesh::Decimater::DecimaterT::decimate
size_t decimate(size_t _n_collapses=0)
Perform a number of collapses on the mesh.
Definition: DecimaterT_impl.hh:150
OpenMesh::Decimater::DecimaterT::HeapInterface
Heap interface.
Definition: DecimaterT.hh:145
OpenMesh::Decimater::DecimaterT::decimate_to
size_t decimate_to(size_t _n_vertices)
Decimate the mesh to a desired target vertex complexity.
Definition: DecimaterT.hh:119
OpenMesh::PolyMeshT::VertexHandle
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:136