OpenMesh
DecimaterT.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
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>
64
65//== NAMESPACE ================================================================
66
67namespace OpenMesh {
68namespace Decimater {
69
70
71//== CLASS DEFINITION =========================================================
72
73
77template < typename MeshT >
78class DecimaterT : virtual public BaseDecimaterT<MeshT> //virtual especially for the mixed decimater
79{
80public: //-------------------------------------------------------- public types
81
83 typedef MeshT Mesh;
85 typedef ModBaseT<MeshT> Module;
86 typedef std::vector< Module* > ModuleList;
87 typedef typename ModuleList::iterator ModuleListIterator;
88
89public: //------------------------------------------------------ public methods
90
92 explicit DecimaterT( Mesh& _mesh );
93
96
97public:
98
109 size_t decimate( size_t _n_collapses = 0 , bool _only_selected = false);
110
121 size_t decimate_to( size_t _n_vertices , bool _only_selected = false)
122 {
123 return ( (_n_vertices < this->mesh().n_vertices()) ?
124 decimate( this->mesh().n_vertices() - _n_vertices , _only_selected ) : 0 );
125 }
126
140 size_t decimate_to_faces( size_t _n_vertices=0, size_t _n_faces=0 , bool _only_selected = false);
141
142public:
143
144 typedef typename Mesh::VertexHandle VertexHandle;
145 typedef typename Mesh::HalfedgeHandle HalfedgeHandle;
146
149 {
150 public:
151
152 HeapInterface(Mesh& _mesh,
155 : mesh_(_mesh), prio_(_prio), pos_(_pos)
156 { }
157
158 inline bool
159 less( VertexHandle _vh0, VertexHandle _vh1 )
160 { return mesh_.property(prio_, _vh0) < mesh_.property(prio_, _vh1); }
161
162 inline bool
163 greater( VertexHandle _vh0, VertexHandle _vh1 )
164 { return mesh_.property(prio_, _vh0) > mesh_.property(prio_, _vh1); }
165
166 inline int
167 get_heap_position(VertexHandle _vh)
168 { return mesh_.property(pos_, _vh); }
169
170 inline void
171 set_heap_position(VertexHandle _vh, int _pos)
172 { mesh_.property(pos_, _vh) = _pos; }
173
174
175 private:
176 Mesh& mesh_;
179 };
180
182
183
184private: //---------------------------------------------------- private methods
185
187 void heap_vertex(VertexHandle _vh);
188
189private: //------------------------------------------------------- private data
190
191
192 // reference to mesh
193 Mesh& mesh_;
194
195 // heap
196 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined( __GXX_EXPERIMENTAL_CXX0X__ )
197 std::unique_ptr<DeciHeap> heap_;
198 #else
199 std::auto_ptr<DeciHeap> heap_;
200 #endif
201
202 // vertex properties
203 VPropHandleT<HalfedgeHandle> collapse_target_;
204 VPropHandleT<float> priority_;
205 VPropHandleT<int> heap_position_;
206
207};
208
209//=============================================================================
210} // END_NS_DECIMATER
211} // END_NS_OPENMESH
212//=============================================================================
213#if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_DECIMATERT_CC)
214#define OPENMESH_DECIMATER_TEMPLATES
215#include "DecimaterT_impl.hh"
216#endif
217//=============================================================================
218#endif // OPENMESH_DECIMATER_DECIMATERT_HH defined
219//=============================================================================
220
A generic heap class.
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
Handle for a vertex entity.
Definition: Handles.hh:121
Handle for a halfedge entity.
Definition: Handles.hh:128
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:136
Kernel::HalfedgeHandle HalfedgeHandle
Scalar type.
Definition: PolyMeshT.hh:137
Definition: BaseDecimaterT.hh:86
Mesh & mesh()
access mesh. used in modules.
Definition: BaseDecimaterT.hh:138
Stores information about a halfedge collapse.
Definition: CollapseInfoT.hh:74
Decimater framework.
Definition: DecimaterT.hh:79
size_t decimate(size_t _n_collapses=0, bool _only_selected=false)
Perform a number of collapses on the mesh.
Definition: DecimaterT_impl.hh:150
size_t decimate_to_faces(size_t _n_vertices=0, size_t _n_faces=0, bool _only_selected=false)
Attempts to decimate the mesh until a desired vertex or face complexity is achieved.
Definition: DecimaterT_impl.hh:259
~DecimaterT()
Destructor.
Definition: DecimaterT_impl.hh:92
size_t decimate_to(size_t _n_vertices, bool _only_selected=false)
Decimate the mesh to a desired target vertex complexity.
Definition: DecimaterT.hh:121
DecimaterT(Mesh &_mesh)
Constructor.
Definition: DecimaterT_impl.hh:72
Heap interface.
Definition: DecimaterT.hh:149
Base class for all decimation modules.
Definition: ModBaseT.hh:193
An efficient, highly customizable heap.
Definition: HeapT.hh:139

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