OpenMesh
PropertyManager.hh
1#ifndef OPENMESH_PYTHON_PROPERTYMANAGER_HH
2#define OPENMESH_PYTHON_PROPERTYMANAGER_HH
3
4#include "Python/Bindings.hh"
5#include "OpenMesh/Core/Utils/PropertyManager.hh"
6
7namespace OpenMesh {
8namespace Python {
9
10BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(retain_overloads, retain, 0, 1)
11
12
23template <class PropertyManager, class IndexHandle>
24object propman_get_item(PropertyManager& _self, IndexHandle _handle) {
25 return _self[_handle];
26}
27
38template <class PropertyManager, class IndexHandle>
39void propman_set_item(PropertyManager& _self, IndexHandle _handle, object _value) {
40 _self[_handle] = _value;
41}
42
54template <class PropertyManager, class Iterator>
55void propman_set_range(PropertyManager& _self, Iterator _it, object _value) {
56 try {
57 while (true) {
58 _self[_it.next()] = _value;
59 }
60 }
61 catch (error_already_set exception) {
62 // This is expected behavior
63 PyErr_Clear();
64 }
65}
66
76template <class PropertyManager, class Mesh>
77bool property_exists(Mesh& _mesh, const char *_propname) {
78 return PropertyManager::propertyExists(_mesh, _propname);
79}
80
96template <class PropHandle, class IndexHandle, class Iterator>
97void expose_property_manager(const char *_name) {
98 // Convenience typedef
100
101 // Function pointers
102 void (PropertyManager::*retain)(bool) = &PropertyManager::retain;
103
104 object (*getitem)(PropertyManager&, IndexHandle ) = &propman_get_item;
105 void (*setitem)(PropertyManager&, IndexHandle, object) = &propman_set_item;
106
107 void (*set_range)(PropertyManager&, Iterator, object) = &propman_set_range;
108
109 bool (*property_exists_poly)(PolyMesh&, const char *) = &property_exists<PropertyManager, PolyMesh>;
110 bool (*property_exists_tri )(TriMesh&, const char *) = &property_exists<PropertyManager, TriMesh >;
111
112 // Expose property manager
113 class_<PropertyManager, boost::noncopyable>(_name)
114 .def(init<PolyMesh&, const char *, optional<bool> >()[with_custodian_and_ward<1,2>()])
115 .def(init<TriMesh&, const char *, optional<bool> >()[with_custodian_and_ward<1,2>()])
116
117 .def("swap", &PropertyManager::swap)
118 .def("is_valid", &PropertyManager::isValid)
119
120 .def("__bool__", &PropertyManager::operator bool)
121 .def("__nonzero__", &PropertyManager::operator bool)
122
123 .def("get_raw_property", &PropertyManager::getRawProperty, return_value_policy<copy_const_reference>())
124 .def("get_name", &PropertyManager::getName, return_value_policy<copy_const_reference>())
125 .def("get_mesh", &PropertyManager::getMesh, return_value_policy<reference_existing_object>())
126
127 .def("retain", retain, retain_overloads())
128
129 .def("__getitem__", getitem)
130 .def("__setitem__", setitem)
131
132 .def("set_range", set_range)
133
134 .def("property_exists", property_exists_poly)
135 .def("property_exists", property_exists_tri)
136 .staticmethod("property_exists")
137 ;
138}
139
140} // namespace OpenMesh
141} // namespace Python
142
143#endif
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
void expose_property_manager(const char *_name)
Expose a property manager type to Python.
Definition: PropertyManager.hh:97
void propman_set_range(PropertyManager &_self, Iterator _it, object _value)
Conveniently set the property value for an entire range of mesh items using a Python iterator.
Definition: PropertyManager.hh:55
bool property_exists(Mesh &_mesh, const char *_propname)
Thin wrapper for propertyExists.
Definition: PropertyManager.hh:77
object propman_get_item(PropertyManager &_self, IndexHandle _handle)
Implementation of Python's __getitem__ magic method.
Definition: PropertyManager.hh:24
void propman_set_item(PropertyManager &_self, IndexHandle _handle, object _value)
Implementation of Python's __setitem__ magic method.
Definition: PropertyManager.hh:39
Polygonal mesh based on the ArrayKernel.
Definition: PolyMesh_ArrayKernelT.hh:100
Triangle mesh based on the ArrayKernel.
Definition: TriMesh_ArrayKernelT.hh:100
This class is intended to manage the lifecycle of properties.
Definition: PropertyManager.hh:94
void retain(bool doRetain=true)
Disable lifecycle management for this property.
Definition: PropertyManager.hh:340

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