Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
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>
67 #include <OpenMesh/Tools/Utils/HeapT.hh>
68 #include <OpenMesh/Tools/Decimater/BaseDecimaterT.hh>
69
70 //== NAMESPACE ================================================================
71
72 namespace OpenMesh {
73 namespace Decimater {
74
75
76 //== CLASS DEFINITION =========================================================
77
78
82 template < typename MeshT >
83 class DecimaterT : virtual public BaseDecimaterT<MeshT> //virtual especially for the mixed decimater
84 {
85 public: //-------------------------------------------------------- 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
94 public: //------------------------------------------------------ public methods
95
97 DecimaterT( Mesh& _mesh );
98
100 ~DecimaterT();
101
102 public:
103
107 size_t decimate( size_t _n_collapses = 0 );
108
110 size_t decimate_to( size_t _n_vertices )
111 {
112 return ( (_n_vertices < this->mesh().n_vertices()) ?
113 decimate( this->mesh().n_vertices() - _n_vertices ) : 0 );
114 }
115
120 size_t decimate_to_faces( size_t _n_vertices=0, size_t _n_faces=0 );
121
122 public:
123
124 typedef typename Mesh::VertexHandle VertexHandle;
125 typedef typename Mesh::HalfedgeHandle HalfedgeHandle;
126
128 class HeapInterface
129 {
130 public:
131
132 HeapInterface(Mesh& _mesh,
133 VPropHandleT<float> _prio,
134 VPropHandleT<int> _pos)
135 : mesh_(_mesh), prio_(_prio), pos_(_pos)
136 { }
137
138 inline bool
139 less( VertexHandle _vh0, VertexHandle _vh1 )
140 { return mesh_.property(prio_, _vh0) < mesh_.property(prio_, _vh1); }
141
142 inline bool
143 greater( VertexHandle _vh0, VertexHandle _vh1 )
144 { return mesh_.property(prio_, _vh0) > mesh_.property(prio_, _vh1); }
145
146 inline int
147 get_heap_position(VertexHandle _vh)
148 { return mesh_.property(pos_, _vh); }
149
150 inline void
151 set_heap_position(VertexHandle _vh, int _pos)
152 { mesh_.property(pos_, _vh) = _pos; }
153
154
155 private:
156 Mesh& mesh_;
157 VPropHandleT<float> prio_;
158 VPropHandleT<int> pos_;
159 };
160
161 typedef Utils::HeapT<VertexHandle, HeapInterface> DeciHeap;
162
163
164 private: //---------------------------------------------------- private methods
165
167 void heap_vertex(VertexHandle _vh);
168
169 private: //------------------------------------------------------- private data
170
171
172 // reference to mesh
173 Mesh& mesh_;
174
175 // heap
176 #if _MSC_VER >= 1900 || __cplusplus > 199711L || defined( __GXX_EXPERIMENTAL_CXX0X__ )
177 std::unique_ptr<DeciHeap> heap_;
178 #else
179 std::auto_ptr<DeciHeap> heap_;
180 #endif
181
182 // vertex properties
183 VPropHandleT<HalfedgeHandle> collapse_target_;
184 VPropHandleT<float> priority_;
185 VPropHandleT<int> heap_position_;
186
187 };
188
189 //=============================================================================
190 } // END_NS_DECIMATER
191 } // END_NS_OPENMESH
192 //=============================================================================
193 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_DECIMATERT_CC)
194 #define OPENMESH_DECIMATER_TEMPLATES
195 #include "DecimaterT.cc"
196 #endif
197 //=============================================================================
198 #endif // OPENMESH_DECIMATER_DECIMATERT_HH defined
199 //=============================================================================
200
HeapT.hh
BaseDecimaterT.hh
OpenMesh
Definition: MeshItems.hh:64
OpenMesh::Decimater::BaseDecimaterT::mesh
Mesh & mesh()
access mesh. used in modules.
Definition: BaseDecimaterT.hh:143
OpenMesh::Decimater::DecimaterT::decimate_to_faces
size_t decimate_to_faces(size_t _n_vertices=0, size_t _n_faces=0)
Definition: DecimaterT.cc:260
OpenMesh::Decimater::DecimaterT::DecimaterT
DecimaterT(Mesh &_mesh)
Constructor.
Definition: DecimaterT.cc:78
OpenMesh::Decimater::DecimaterT::decimate
size_t decimate(size_t _n_collapses=0)
Definition: DecimaterT.cc:156
OpenMesh::Decimater::DecimaterT::~DecimaterT
~DecimaterT()
Destructor.
Definition: DecimaterT.cc:98
OpenMesh::HalfedgeHandle
Handle for a halfedge entity.
Definition: Handles.hh:132
OpenMesh::Decimater::DecimaterT
Definition: DecimaterT.hh:83
OpenMesh::VPropHandleT< float >
DecimaterT.cc
OpenMesh::Decimater::CollapseInfoT
Definition: CollapseInfoT.hh:80
OpenMesh::Decimater::ModBaseT
Definition: ModBaseT.hh:197
OpenMesh::VertexHandle
Handle for a vertex entity.
Definition: Handles.hh:125
OpenMesh::Decimater::BaseDecimaterT
Definition: BaseDecimaterT.hh:90
OpenMesh::Decimater::DecimaterT::heap_vertex
void heap_vertex(VertexHandle _vh)
Insert vertex in heap.
Definition: DecimaterT.cc:110
OpenMesh::PolyMeshT::VertexHandle
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:139
OpenMesh::Decimater::DecimaterT::HeapInterface
Heap interface.
Definition: DecimaterT.hh:128
OpenMesh::Utils::HeapT
Definition: HeapT.hh:143
OpenMesh::Decimater::DecimaterT::decimate_to
size_t decimate_to(size_t _n_vertices)
Decimate to target complexity, returns number of collapses.
Definition: DecimaterT.hh:110