OpenMesh
Decimater.hh
1 #ifndef OPENMESH_PYTHON_DECIMATER_HH
2 #define OPENMESH_PYTHON_DECIMATER_HH
3 
4 #include "Python/Bindings.hh"
9 #include "OpenMesh/Tools/Decimater/ModIndependentSetsT.hh"
16 
17 #include <cstdio>
18 
19 namespace OpenMesh {
20 namespace Python {
21 
22 #define INIT_MESH_REF init<Mesh&>()[with_custodian_and_ward<1,2>()]
23 
24 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(decimate_overloads, decimate, 0, 1)
25 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(decimate_to_faces_overloads, decimate_to_faces, 0, 2)
26 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_max_err_overloads, set_max_err, 1, 2)
27 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(set_min_roundness_overloads, set_min_roundness, 1, 2)
28 
29 
30 template <class Handle>
31 void expose_module_handle(const char *_name) {
32  class_<Handle, boost::noncopyable>(_name)
33  .def("is_valid", &Handle::is_valid)
34  ;
35 }
36 
37 template <class Module>
38 list infolist(Module& _self) {
39  const typename Module::InfoList& infos = _self.infolist();
40  list res;
41  for (size_t i = 0; i < infos.size(); ++i) {
42  res.append(infos[i]);
43  }
44  return res;
45 }
46 
47 template <class Mesh>
48 void expose_decimater(const char *_name) {
49 
50  typedef Decimater::ModBaseT<Mesh> ModBase;
51  typedef Decimater::ModAspectRatioT<Mesh> ModAspectRatio;
52  typedef Decimater::ModEdgeLengthT<Mesh> ModEdgeLength;
53  typedef Decimater::ModHausdorffT<Mesh> ModHausdorff;
54  typedef Decimater::ModIndependentSetsT<Mesh> ModIndependentSets;
55  typedef Decimater::ModNormalDeviationT<Mesh> ModNormalDeviation;
56  typedef Decimater::ModNormalFlippingT<Mesh> ModNormalFlipping;
57  typedef Decimater::ModProgMeshT<Mesh> ModProgMesh;
58  typedef Decimater::ModQuadricT<Mesh> ModQuadric;
59  typedef Decimater::ModRoundnessT<Mesh> ModRoundness;
60 
61  typedef Decimater::ModHandleT<ModAspectRatio> ModAspectRatioHandle;
62  typedef Decimater::ModHandleT<ModEdgeLength> ModEdgeLengthHandle;
63  typedef Decimater::ModHandleT<ModHausdorff> ModHausdorffHandle;
64  typedef Decimater::ModHandleT<ModIndependentSets> ModIndependentSetsHandle;
65  typedef Decimater::ModHandleT<ModNormalDeviation> ModNormalDeviationHandle;
66  typedef Decimater::ModHandleT<ModNormalFlipping> ModNormalFlippingHandle;
67  typedef Decimater::ModHandleT<ModProgMesh> ModProgMeshHandle;
68  typedef Decimater::ModHandleT<ModQuadric> ModQuadricHandle;
69  typedef Decimater::ModHandleT<ModRoundness> ModRoundnessHandle;
70 
71  typedef Decimater::BaseDecimaterT<Mesh> BaseDecimater;
72  typedef Decimater::DecimaterT<Mesh> Decimater;
73 
74  typedef typename ModProgMesh::Info Info;
75  typedef std::vector<Info> InfoList;
76 
77  bool (BaseDecimater::*add1)(ModAspectRatioHandle&) = &Decimater::add;
78  bool (BaseDecimater::*add2)(ModEdgeLengthHandle&) = &Decimater::add;
79  bool (BaseDecimater::*add3)(ModHausdorffHandle&) = &Decimater::add;
80  bool (BaseDecimater::*add4)(ModIndependentSetsHandle&) = &Decimater::add;
81  bool (BaseDecimater::*add5)(ModNormalDeviationHandle&) = &Decimater::add;
82  bool (BaseDecimater::*add6)(ModNormalFlippingHandle&) = &Decimater::add;
83  bool (BaseDecimater::*add7)(ModProgMeshHandle&) = &Decimater::add;
84  bool (BaseDecimater::*add8)(ModQuadricHandle&) = &Decimater::add;
85  bool (BaseDecimater::*add9)(ModRoundnessHandle&) = &Decimater::add;
86 
87  bool (BaseDecimater::*remove1)(ModAspectRatioHandle&) = &Decimater::remove;
88  bool (BaseDecimater::*remove2)(ModEdgeLengthHandle&) = &Decimater::remove;
89  bool (BaseDecimater::*remove3)(ModHausdorffHandle&) = &Decimater::remove;
90  bool (BaseDecimater::*remove4)(ModIndependentSetsHandle&) = &Decimater::remove;
91  bool (BaseDecimater::*remove5)(ModNormalDeviationHandle&) = &Decimater::remove;
92  bool (BaseDecimater::*remove6)(ModNormalFlippingHandle&) = &Decimater::remove;
93  bool (BaseDecimater::*remove7)(ModProgMeshHandle&) = &Decimater::remove;
94  bool (BaseDecimater::*remove8)(ModQuadricHandle&) = &Decimater::remove;
95  bool (BaseDecimater::*remove9)(ModRoundnessHandle&) = &Decimater::remove;
96 
97  ModAspectRatio& (BaseDecimater::*module1)(ModAspectRatioHandle&) = &Decimater::module;
98  ModEdgeLength& (BaseDecimater::*module2)(ModEdgeLengthHandle&) = &Decimater::module;
99  ModHausdorff& (BaseDecimater::*module3)(ModHausdorffHandle&) = &Decimater::module;
100  ModIndependentSets& (BaseDecimater::*module4)(ModIndependentSetsHandle&) = &Decimater::module;
101  ModNormalDeviation& (BaseDecimater::*module5)(ModNormalDeviationHandle&) = &Decimater::module;
102  ModNormalFlipping& (BaseDecimater::*module6)(ModNormalFlippingHandle&) = &Decimater::module;
103  ModProgMesh& (BaseDecimater::*module7)(ModProgMeshHandle&) = &Decimater::module;
104  ModQuadric& (BaseDecimater::*module8)(ModQuadricHandle&) = &Decimater::module;
105  ModRoundness& (BaseDecimater::*module9)(ModRoundnessHandle&) = &Decimater::module;
106 
107  // Decimater
108  // ----------------------------------------
109 
110  char buffer[64];
111  snprintf(buffer, sizeof buffer, "%s%s", _name, "Decimater");
112 
113  class_<Decimater, boost::noncopyable>(buffer, INIT_MESH_REF)
114  .def("decimate", &Decimater::decimate, decimate_overloads())
115  .def("decimate_to", &Decimater::decimate_to)
116  .def("decimate_to_faces", &Decimater::decimate_to_faces, decimate_to_faces_overloads())
117 
118  .def("initialize", &Decimater::initialize)
119  .def("is_initialized", &Decimater::is_initialized)
120 
121  .def("add", add1)
122  .def("add", add2)
123  .def("add", add3)
124  .def("add", add4)
125  .def("add", add5)
126  .def("add", add6)
127  .def("add", add7)
128  .def("add", add8)
129  .def("add", add9)
130 
131  .def("remove", remove1)
132  .def("remove", remove2)
133  .def("remove", remove3)
134  .def("remove", remove4)
135  .def("remove", remove5)
136  .def("remove", remove6)
137  .def("remove", remove7)
138  .def("remove", remove8)
139  .def("remove", remove9)
140 
141  .def("module", module1, return_value_policy<reference_existing_object>())
142  .def("module", module2, return_value_policy<reference_existing_object>())
143  .def("module", module3, return_value_policy<reference_existing_object>())
144  .def("module", module4, return_value_policy<reference_existing_object>())
145  .def("module", module5, return_value_policy<reference_existing_object>())
146  .def("module", module6, return_value_policy<reference_existing_object>())
147  .def("module", module7, return_value_policy<reference_existing_object>())
148  .def("module", module8, return_value_policy<reference_existing_object>())
149  .def("module", module9, return_value_policy<reference_existing_object>())
150  ;
151 
152  // ModBase
153  // ----------------------------------------
154 
155  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModBase");
156 
157  class_<ModBase, boost::noncopyable>(buffer, no_init)
158  .def("name", &ModBase::name, OPENMESH_PYTHON_DEFAULT_POLICY)
159  .def("is_binary", &ModBase::is_binary)
160  .def("set_binary", &ModBase::set_binary)
161  .def("initialize", &ModBase::initialize) // TODO VIRTUAL
162  .def("collapse_priority", &ModBase::collapse_priority) // TODO VIRTUAL
163  .def("preprocess_collapse", &ModBase::preprocess_collapse) // TODO VIRTUAL
164  .def("postprocess_collapse", &ModBase::postprocess_collapse) // TODO VIRTUAL
165  .def("set_error_tolerance_factor", &ModBase::set_error_tolerance_factor) // TODO VIRTUAL
166  ;
167 
168  // ModAspectRatio
169  // ----------------------------------------
170 
171  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModAspectRatio");
172 
173  class_<ModAspectRatio, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF)
174  .def("aspect_ratio", &ModAspectRatio::aspect_ratio)
175  .def("set_aspect_ratio", &ModAspectRatio::set_aspect_ratio)
176  ;
177 
178  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModAspectRatioHandle");
179  expose_module_handle<ModAspectRatioHandle>(buffer);
180 
181  // ModEdgeLength
182  // ----------------------------------------
183 
184  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModEdgeLength");
185 
186  class_<ModEdgeLength, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF)
187  .def("edge_length", &ModEdgeLength::edge_length)
188  .def("set_edge_length", &ModEdgeLength::set_edge_length)
189  ;
190 
191  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModEdgeLengthHandle");
192  expose_module_handle<ModEdgeLengthHandle>(buffer);
193 
194  // ModHausdorff
195  // ----------------------------------------
196 
197  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModHausdorff");
198 
199  class_<ModHausdorff, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF)
200  .def("tolerance", &ModHausdorff::tolerance)
201  .def("set_tolerance", &ModHausdorff::set_tolerance)
202  ;
203 
204  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModHausdorffHandle");
205  expose_module_handle<ModHausdorffHandle>(buffer);
206 
207  // ModIndependentSets
208  // ----------------------------------------
209 
210  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModIndependentSets");
211 
212  class_<ModIndependentSets, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF);
213 
214  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModIndependentSetsHandle");
215  expose_module_handle<ModIndependentSetsHandle>(buffer);
216 
217  // ModNormalDeviation
218  // ----------------------------------------
219 
220  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModNormalDeviation");
221 
222  class_<ModNormalDeviation, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF)
223  .def("normal_deviation", &ModNormalDeviation::normal_deviation)
224  .def("set_normal_deviation", &ModNormalDeviation::set_normal_deviation)
225  ;
226 
227  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModNormalDeviationHandle");
228  expose_module_handle<ModNormalDeviationHandle>(buffer);
229 
230  // ModNormalFlipping
231  // ----------------------------------------
232 
233  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModNormalFlipping");
234 
235  class_<ModNormalFlipping, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF)
236  .def("max_normal_deviation", &ModNormalFlipping::max_normal_deviation)
237  .def("set_max_normal_deviation", &ModNormalFlipping::set_max_normal_deviation)
238  ;
239 
240  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModNormalFlippingHandle");
241  expose_module_handle<ModNormalFlippingHandle>(buffer);
242 
243  // ModProgMesh
244  // ----------------------------------------
245 
246  class_<Info>("Info", no_init)
247  .def_readwrite("v0", &Info::v0)
248  .def_readwrite("v1", &Info::v1)
249  .def_readwrite("vl", &Info::vl)
250  .def_readwrite("vr", &Info::vr)
251  ;
252 
253  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModProgMesh");
254 
255  class_<ModProgMesh, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF)
256  .def("pmi", &infolist<ModProgMesh>)
257  .def("infolist", &infolist<ModProgMesh>)
258  .def("write", &ModProgMesh::write)
259  ;
260 
261  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModProgMeshHandle");
262  expose_module_handle<ModProgMeshHandle>(buffer);
263 
264  // ModQuadric
265  // ----------------------------------------
266 
267  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModQuadric");
268 
269  class_<ModQuadric, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF)
270  .def("set_max_err", &ModQuadric::set_max_err, set_max_err_overloads())
271  .def("unset_max_err", &ModQuadric::unset_max_err)
272  .def("max_err", &ModQuadric::max_err)
273  ;
274 
275  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModQuadricHandle");
276  expose_module_handle<ModQuadricHandle>(buffer);
277 
278  // ModRoundness
279  // ----------------------------------------
280 
281  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModRoundness");
282 
283  class_<ModRoundness, bases<ModBase>, boost::noncopyable>(buffer, INIT_MESH_REF)
284  .def("set_min_angle", &ModRoundness::set_min_angle)
285  .def("set_min_roundness", &ModRoundness::set_min_roundness, set_min_roundness_overloads())
286  .def("unset_min_roundness", &ModRoundness::unset_min_roundness)
287  .def("roundness", &ModRoundness::roundness)
288  ;
289 
290  snprintf(buffer, sizeof buffer, "%s%s", _name, "ModRoundnessHandle");
291  expose_module_handle<ModRoundnessHandle>(buffer);
292 }
293 
294 } // namespace OpenMesh
295 } // namespace Python
296 
297 #endif
Base class for all decimation modules.
#define OPENMESH_PYTHON_DEFAULT_POLICY
Return value policy for functions that return references to objects that are managed by OpenMesh...
Definition: Bindings.hh:29
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64

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