OpenMesh

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DecimaterT.hh
Go to the documentation of this file.
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5 * www.openmesh.org *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of OpenMesh. *
9 * *
10 * OpenMesh is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenMesh is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenMesh. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34
35 /*===========================================================================*\
36 * *
37 * $Revision: 737 $ *
38 * $Date: 2012-10-08 09:33:20 +0200 (Mo, 08. Okt 2012) $ *
39 * *
40 \*===========================================================================*/
41
45 //=============================================================================
46 //
47 // CLASS DecimaterT
48 //
49 //=============================================================================
50
51 #ifndef OPENMESH_DECIMATER_DECIMATERT_HH
52 #define OPENMESH_DECIMATER_DECIMATERT_HH
53
54
55 //== INCLUDES =================================================================
56
57 #include <memory>
58
59 #include <OpenMesh/Core/Utils/Property.hh>
60 #include <OpenMesh/Tools/Utils/HeapT.hh>
61 #include <OpenMesh/Tools/Decimater/BaseDecimaterT.hh>
62
63
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 DecimaterT( Mesh& _mesh );
93
95 ~DecimaterT();
96
97 public:
98
102 size_t decimate( size_t _n_collapses = 0 );
103
105 size_t decimate_to( size_t _n_vertices )
106 {
107 return ( (_n_vertices < this->mesh().n_vertices()) ?
108 decimate( this->mesh().n_vertices() - _n_vertices ) : 0 );
109 }
110
115 size_t decimate_to_faces( size_t _n_vertices=0, size_t _n_faces=0 );
116
117 public:
118
119 typedef typename Mesh::VertexHandle VertexHandle;
120 typedef typename Mesh::HalfedgeHandle HalfedgeHandle;
121
123 class HeapInterface
124 {
125 public:
126
127 HeapInterface(Mesh& _mesh,
128 VPropHandleT<float> _prio,
129 VPropHandleT<int> _pos)
130 : mesh_(_mesh), prio_(_prio), pos_(_pos)
131 { }
132
133 inline bool
134 less( VertexHandle _vh0, VertexHandle _vh1 )
135 { return mesh_.property(prio_, _vh0) < mesh_.property(prio_, _vh1); }
136
137 inline bool
138 greater( VertexHandle _vh0, VertexHandle _vh1 )
139 { return mesh_.property(prio_, _vh0) > mesh_.property(prio_, _vh1); }
140
141 inline int
142 get_heap_position(VertexHandle _vh)
143 { return mesh_.property(pos_, _vh); }
144
145 inline void
146 set_heap_position(VertexHandle _vh, int _pos)
147 { mesh_.property(pos_, _vh) = _pos; }
148
149
150 private:
151 Mesh& mesh_;
152 VPropHandleT<float> prio_;
153 VPropHandleT<int> pos_;
154 };
155
156 typedef Utils::HeapT<VertexHandle, HeapInterface> DeciHeap;
157
158
159 private: //---------------------------------------------------- private methods
160
162 void heap_vertex(VertexHandle _vh);
163
164 private: //------------------------------------------------------- private data
165
166
167 // reference to mesh
168 Mesh& mesh_;
169
170 // heap
171 std::auto_ptr<DeciHeap> heap_;
172
173 // vertex properties
174 VPropHandleT<HalfedgeHandle> collapse_target_;
175 VPropHandleT<float> priority_;
176 VPropHandleT<int> heap_position_;
177
178 };
179
180 //=============================================================================
181 } // END_NS_DECIMATER
182 } // END_NS_OPENMESH
183 //=============================================================================
184 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_DECIMATERT_CC)
185 #define OPENMESH_DECIMATER_TEMPLATES
186 #include "DecimaterT.cc"
187 #endif
188 //=============================================================================
189 #endif // OPENMESH_DECIMATER_DECIMATERT_HH defined
190 //=============================================================================
191