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