Commit 2a38dbc4 authored by Alexander Dielen's avatar Alexander Dielen
Browse files

exposed property manager

parent d9424073
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "Mesh.hh" #include "Mesh.hh"
#include "Iterator.hh" #include "Iterator.hh"
#include "Circulator.hh" #include "Circulator.hh"
#include "PropertyManager.hh"
#include "InputOutput.hh" #include "InputOutput.hh"
#include <pybind11/pybind11.h> #include <pybind11/pybind11.h>
...@@ -45,15 +46,15 @@ PYBIND11_MODULE(openmesh, m) { ...@@ -45,15 +46,15 @@ PYBIND11_MODULE(openmesh, m) {
expose_circulator<OM::PolyConnectivity::HalfedgeLoopIter, OM::HalfedgeHandle>(m, "HalfedgeLoopIter"); expose_circulator<OM::PolyConnectivity::HalfedgeLoopIter, OM::HalfedgeHandle>(m, "HalfedgeLoopIter");
// typedef IteratorWrapperT<PolyConnectivity::VertexIter, &ArrayKernel::n_vertices> VertexIterWrapper; typedef IteratorWrapperT<OM::PolyConnectivity::VertexIter, &OM::ArrayKernel::n_vertices> VertexIterWrapper;
// typedef IteratorWrapperT<PolyConnectivity::HalfedgeIter, &ArrayKernel::n_halfedges> HalfedgeIterWrapper; typedef IteratorWrapperT<OM::PolyConnectivity::HalfedgeIter, &OM::ArrayKernel::n_halfedges> HalfedgeIterWrapper;
// typedef IteratorWrapperT<PolyConnectivity::EdgeIter, &ArrayKernel::n_edges> EdgeIterWrapper; typedef IteratorWrapperT<OM::PolyConnectivity::EdgeIter, &OM::ArrayKernel::n_edges> EdgeIterWrapper;
// typedef IteratorWrapperT<PolyConnectivity::FaceIter, &ArrayKernel::n_faces> FaceIterWrapper; typedef IteratorWrapperT<OM::PolyConnectivity::FaceIter, &OM::ArrayKernel::n_faces> FaceIterWrapper;
// expose_property_manager<VPropHandleT<object>, VertexHandle, VertexIterWrapper>("VPropertyManager"); expose_property_manager<OM::VPropHandleT<py::object>, OM::VertexHandle, VertexIterWrapper>(m, "VPropertyManager");
// expose_property_manager<HPropHandleT<object>, HalfedgeHandle, HalfedgeIterWrapper>("HPropertyManager"); expose_property_manager<OM::HPropHandleT<py::object>, OM::HalfedgeHandle, HalfedgeIterWrapper>(m, "HPropertyManager");
// expose_property_manager<EPropHandleT<object>, EdgeHandle, EdgeIterWrapper>("EPropertyManager"); expose_property_manager<OM::EPropHandleT<py::object>, OM::EdgeHandle, EdgeIterWrapper>(m, "EPropertyManager");
// expose_property_manager<FPropHandleT<object>, FaceHandle, FaceIterWrapper>("FPropertyManager"); expose_property_manager<OM::FPropHandleT<py::object>, OM::FaceHandle, FaceIterWrapper>(m, "FPropertyManager");
expose_io(m); expose_io(m);
......
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
#include "Bindings.hh" #include "Bindings.hh"
#include <OpenMesh/Core/Utils/PropertyManager.hh> #include <OpenMesh/Core/Utils/PropertyManager.hh>
namespace OpenMesh { #include <pybind11/pybind11.h>
namespace Python {
namespace py = pybind11;
namespace OM = OpenMesh;
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(retain_overloads, retain, 0, 1)
/** /**
* Implementation of %Python's \_\_getitem\_\_ magic method. * Implementation of %Python's \_\_getitem\_\_ magic method.
...@@ -21,7 +22,7 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(retain_overloads, retain, 0, 1) ...@@ -21,7 +22,7 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(retain_overloads, retain, 0, 1)
* @return The requested property value. * @return The requested property value.
*/ */
template <class PropertyManager, class IndexHandle> template <class PropertyManager, class IndexHandle>
object propman_get_item(PropertyManager& _self, IndexHandle _handle) { py::object propman_get_item(PropertyManager& _self, IndexHandle _handle) {
return _self[_handle]; return _self[_handle];
} }
...@@ -36,7 +37,7 @@ object propman_get_item(PropertyManager& _self, IndexHandle _handle) { ...@@ -36,7 +37,7 @@ object propman_get_item(PropertyManager& _self, IndexHandle _handle) {
* @param _value The property value to be set. * @param _value The property value to be set.
*/ */
template <class PropertyManager, class IndexHandle> template <class PropertyManager, class IndexHandle>
void propman_set_item(PropertyManager& _self, IndexHandle _handle, object _value) { void propman_set_item(PropertyManager& _self, IndexHandle _handle, py::object _value) {
_self[_handle] = _value; _self[_handle] = _value;
} }
...@@ -52,13 +53,13 @@ void propman_set_item(PropertyManager& _self, IndexHandle _handle, object _value ...@@ -52,13 +53,13 @@ void propman_set_item(PropertyManager& _self, IndexHandle _handle, object _value
* @param _value The value the range will be set to. * @param _value The value the range will be set to.
*/ */
template <class PropertyManager, class Iterator> template <class PropertyManager, class Iterator>
void propman_set_range(PropertyManager& _self, Iterator _it, object _value) { void propman_set_range(PropertyManager& _self, Iterator _it, py::object _value) {
try { try {
while (true) { while (true) {
_self[_it.next()] = _value; _self[_it.next()] = _value;
} }
} }
catch (error_already_set exception) { catch (py::stop_iteration exception) {
// This is expected behavior // This is expected behavior
PyErr_Clear(); PyErr_Clear();
} }
...@@ -94,25 +95,25 @@ bool property_exists(Mesh& _mesh, const char *_propname) { ...@@ -94,25 +95,25 @@ bool property_exists(Mesh& _mesh, const char *_propname) {
* @param _name The name of the property manager type to be exposed. * @param _name The name of the property manager type to be exposed.
*/ */
template <class PropHandle, class IndexHandle, class Iterator> template <class PropHandle, class IndexHandle, class Iterator>
void expose_property_manager(const char *_name) { void expose_property_manager(py::module& m, const char *_name) {
// Convenience typedef // Convenience typedef
typedef PropertyManager<PropHandle, PolyConnectivity> PropertyManager; typedef OM::PropertyManager<PropHandle, OM::PolyConnectivity> PropertyManager;
// Function pointers // Function pointers
void (PropertyManager::*retain)(bool) = &PropertyManager::retain; py::object (*getitem)(PropertyManager&, IndexHandle ) = &propman_get_item;
void (*setitem)(PropertyManager&, IndexHandle, py::object) = &propman_set_item;
object (*getitem)(PropertyManager&, IndexHandle ) = &propman_get_item;
void (*setitem)(PropertyManager&, IndexHandle, object) = &propman_set_item;
void (*set_range)(PropertyManager&, Iterator, object) = &propman_set_range; void (*set_range)(PropertyManager&, Iterator, py::object) = &propman_set_range;
bool (*property_exists_poly)(PolyMesh&, const char *) = &property_exists<PropertyManager, PolyMesh>; bool (*property_exists_poly)(PolyMesh&, const char *) = &property_exists<PropertyManager, PolyMesh>;
bool (*property_exists_tri )(TriMesh&, const char *) = &property_exists<PropertyManager, TriMesh >; bool (*property_exists_tri )(TriMesh&, const char *) = &property_exists<PropertyManager, TriMesh >;
// Expose property manager // Expose property manager
class_<PropertyManager, boost::noncopyable>(_name) py::class_<PropertyManager>(m, _name)
.def(init<PolyMesh&, const char *, optional<bool> >()[with_custodian_and_ward<1,2>()]) .def(py::init<PolyMesh&, const char *>(), py::keep_alive<1,2>())
.def(init<TriMesh&, const char *, optional<bool> >()[with_custodian_and_ward<1,2>()]) .def(py::init<PolyMesh&, const char *, bool>(), py::keep_alive<1,2>())
.def(py::init<TriMesh&, const char *>(), py::keep_alive<1,2>())
.def(py::init<TriMesh&, const char *, bool>(), py::keep_alive<1,2>())
.def("swap", &PropertyManager::swap) .def("swap", &PropertyManager::swap)
.def("is_valid", &PropertyManager::isValid) .def("is_valid", &PropertyManager::isValid)
...@@ -120,24 +121,20 @@ void expose_property_manager(const char *_name) { ...@@ -120,24 +121,20 @@ void expose_property_manager(const char *_name) {
.def("__bool__", &PropertyManager::operator bool) .def("__bool__", &PropertyManager::operator bool)
.def("__nonzero__", &PropertyManager::operator bool) .def("__nonzero__", &PropertyManager::operator bool)
.def("get_raw_property", &PropertyManager::getRawProperty, return_value_policy<copy_const_reference>()) .def("get_raw_property", &PropertyManager::getRawProperty, py::return_value_policy::copy)
.def("get_name", &PropertyManager::getName, return_value_policy<copy_const_reference>()) .def("get_name", &PropertyManager::getName, py::return_value_policy::copy)
.def("get_mesh", &PropertyManager::getMesh, return_value_policy<reference_existing_object>()) .def("get_mesh", &PropertyManager::getMesh, py::return_value_policy::reference)
.def("retain", retain, retain_overloads()) .def("retain", &PropertyManager::retain, py::arg("do_retain")=false)
.def("__getitem__", getitem) .def("__getitem__", getitem)
.def("__setitem__", setitem) .def("__setitem__", setitem)
.def("set_range", set_range) .def("set_range", set_range)
.def("property_exists", property_exists_poly) .def_static("property_exists", property_exists_poly)
.def("property_exists", property_exists_tri) .def_static("property_exists", property_exists_tri)
.staticmethod("property_exists")
; ;
} }
} // namespace OpenMesh
} // namespace Python
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment