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
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
7 namespace OpenMesh {
8 namespace Python {
9
10 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(retain_overloads, retain, 0, 1)
11
12
23 template <class PropertyManager, class IndexHandle>
24 object propman_get_item(PropertyManager& _self, IndexHandle _handle) {
25 return _self[_handle];
26 }
27
38 template <class PropertyManager, class IndexHandle>
39 void propman_set_item(PropertyManager& _self, IndexHandle _handle, object _value) {
40 _self[_handle] = _value;
41 }
42
54 template <class PropertyManager, class Iterator>
55 void 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
76 template <class PropertyManager, class Mesh>
77 bool property_exists(Mesh& _mesh, const char *_propname) {
78 return PropertyManager::propertyExists(_mesh, _propname);
79 }
80
96 template <class PropHandle, class IndexHandle, class Iterator>
97 void expose_property_manager(const char *_name) {
98 // Convenience typedef
99 typedef PropertyManager<PropHandle, PolyConnectivity> PropertyManager;
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
OpenMesh::Python::propman_get_item
object propman_get_item(PropertyManager &_self, IndexHandle _handle)
Definition: PropertyManager.hh:24
OpenMesh::PropertyManager::retain
void retain(bool doRetain=true)
Disable lifecycle management for this property.
Definition: PropertyManager.hh:283
OpenMesh::PolyMesh_ArrayKernelT
Definition: PolyMesh_ArrayKernelT.hh:98
OpenMesh
Definition: MeshItems.hh:64
OpenMesh::Python::property_exists
bool property_exists(Mesh &_mesh, const char *_propname)
Definition: PropertyManager.hh:77
OpenMesh::PropertyManager
Definition: PropertyManager.hh:94
OpenMesh::TriMesh_ArrayKernelT< CustomTraits >
OpenMesh::Python::propman_set_range
void propman_set_range(PropertyManager &_self, Iterator _it, object _value)
Definition: PropertyManager.hh:55
OpenMesh::Python::expose_property_manager
void expose_property_manager(const char *_name)
Definition: PropertyManager.hh:97
Bindings.hh
OpenMesh::Python::propman_set_item
void propman_set_item(PropertyManager &_self, IndexHandle _handle, object _value)
Definition: PropertyManager.hh:39