OpenMesh
Loading...
Searching...
No Matches
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 * *
44 * $Revision$ *
45 * $Date$ *
46 * *
47\*===========================================================================*/
48
51
52//=============================================================================
53//
54// CLASS DecimaterT
55//
56//=============================================================================
57
58#ifndef OPENMESH_DECIMATER_DECIMATERT_HH
59#define OPENMESH_DECIMATER_DECIMATERT_HH
60
61
62//== INCLUDES =================================================================
63
64#include <memory>
65
66#include <OpenMesh/Core/Utils/Property.hh>
69
70//== NAMESPACE ================================================================
71
72namespace OpenMesh {
73namespace Decimater {
74
75
76//== CLASS DEFINITION =========================================================
77
78
82template < typename MeshT >
83class DecimaterT : virtual public BaseDecimaterT<MeshT> //virtual especially for the mixed decimater
84{
85public: //-------------------------------------------------------- public types
86
87 typedef DecimaterT< MeshT > Self;
88 typedef MeshT Mesh;
89 typedef CollapseInfoT<MeshT> CollapseInfo;
90 typedef ModBaseT<MeshT> Module;
91 typedef std::vector< Module* > ModuleList;
92 typedef typename ModuleList::iterator ModuleListIterator;
93
94public: //------------------------------------------------------ public methods
95
97 DecimaterT( Mesh& _mesh );
98
101
102public:
103
113 size_t decimate( size_t _n_collapses = 0 );
114
124 size_t decimate_to( size_t _n_vertices )
125 {
126 return ( (_n_vertices < this->mesh().n_vertices()) ?
127 decimate( this->mesh().n_vertices() - _n_vertices ) : 0 );
128 }
129
142 size_t decimate_to_faces( size_t _n_vertices=0, size_t _n_faces=0 );
143
144public:
145
146 typedef typename Mesh::VertexHandle VertexHandle;
147 typedef typename Mesh::HalfedgeHandle HalfedgeHandle;
148
150 class HeapInterface
151 {
152 public:
153
154 HeapInterface(Mesh& _mesh,
157 : mesh_(_mesh), prio_(_prio), pos_(_pos)
158 { }
159
160 inline bool
161 less( VertexHandle _vh0, VertexHandle _vh1 )
162 { return mesh_.property(prio_, _vh0) < mesh_.property(prio_, _vh1); }
163
164 inline bool
165 greater( VertexHandle _vh0, VertexHandle _vh1 )
166 { return mesh_.property(prio_, _vh0) > mesh_.property(prio_, _vh1); }
167
168 inline int
169 get_heap_position(VertexHandle _vh)
170 { return mesh_.property(pos_, _vh); }
171
172 inline void
173 set_heap_position(VertexHandle _vh, int _pos)
174 { mesh_.property(pos_, _vh) = _pos; }
175
176
177 private:
178 Mesh& mesh_;
181 };
182
184
185
186private: //---------------------------------------------------- private methods
187
189 void heap_vertex(VertexHandle _vh);
190
191private: //------------------------------------------------------- private data
192
193
194 // reference to mesh
195 Mesh& mesh_;
196
197 // heap
198 #if (defined(_MSC_VER) && (_MSC_VER >= 1900)) || __cplusplus > 199711L || defined( __GXX_EXPERIMENTAL_CXX0X__ )
199 std::unique_ptr<DeciHeap> heap_;
200 #else
201 std::auto_ptr<DeciHeap> heap_;
202 #endif
203
204 // vertex properties
205 VPropHandleT<HalfedgeHandle> collapse_target_;
206 VPropHandleT<float> priority_;
207 VPropHandleT<int> heap_position_;
208
209};
210
211//=============================================================================
212} // END_NS_DECIMATER
213} // END_NS_OPENMESH
214//=============================================================================
215#if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_DECIMATERT_CC)
216#define OPENMESH_DECIMATER_TEMPLATES
217#include "DecimaterT.cc"
218#endif
219//=============================================================================
220#endif // OPENMESH_DECIMATER_DECIMATERT_HH defined
221//=============================================================================
222
A generic heap class.
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition MeshItems.hh:64
Software related to mesh decimation.
AttribKernel::VertexHandle VertexHandle
Definition PolyMeshT.hh:139
AttribKernel::HalfedgeHandle HalfedgeHandle
Definition PolyMeshT.hh:140
Handle representing a vertex property.
Definition Property.hh:488
Mesh & mesh()
access mesh. used in modules.
Definition BaseDecimaterT.hh:143
Stores information about a halfedge collapse.
Definition CollapseInfoT.hh:80
size_t decimate_to(size_t _n_vertices)
Decimate the mesh to a desired target vertex complexity.
Definition DecimaterT.hh:124
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.cc:260
~DecimaterT()
Destructor.
Definition DecimaterT.cc:98
DecimaterT(Mesh &_mesh)
Constructor.
Definition DecimaterT.cc:78
size_t decimate(size_t _n_collapses=0)
Perform a number of collapses on the mesh.
Definition DecimaterT.cc:156
Base class for all decimation modules.
Definition ModBaseT.hh:198
An efficient, highly customizable heap.
Definition HeapT.hh:144

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