Commit d58bdfdc authored by Alexander Dielen's avatar Alexander Dielen

exposed iterators and circulators

parent c61c308e
#include "Bindings.hh"
#include "Miscellaneous.hh"
#include "Vector.hh"
#include "Iterator.hh"
#include "Circulator.hh"
#include <pybind11/pybind11.h>
namespace py = pybind11;
namespace OM = OpenMesh;
PYBIND11_MODULE(openmesh, m) {
......@@ -21,23 +25,23 @@ PYBIND11_MODULE(openmesh, m) {
// expose_mesh<PolyMesh>("PolyMesh");
// expose_mesh<TriMesh>("TriMesh");
// expose_iterator<OpenMesh::PolyConnectivity::VertexIter, &OpenMesh::ArrayKernel::n_vertices>("VertexIter");
// expose_iterator<OpenMesh::PolyConnectivity::HalfedgeIter, &OpenMesh::ArrayKernel::n_halfedges>("HalfedgeIter");
// expose_iterator<OpenMesh::PolyConnectivity::EdgeIter, &OpenMesh::ArrayKernel::n_edges>("EdgeIter");
// expose_iterator<OpenMesh::PolyConnectivity::FaceIter, &OpenMesh::ArrayKernel::n_faces>("FaceIter");
expose_iterator<OM::PolyConnectivity::VertexIter, &OM::ArrayKernel::n_vertices>(m, "VertexIter");
expose_iterator<OM::PolyConnectivity::HalfedgeIter, &OM::ArrayKernel::n_halfedges>(m, "HalfedgeIter");
expose_iterator<OM::PolyConnectivity::EdgeIter, &OM::ArrayKernel::n_edges>(m, "EdgeIter");
expose_iterator<OM::PolyConnectivity::FaceIter, &OM::ArrayKernel::n_faces>(m, "FaceIter");
// expose_circulator<OpenMesh::PolyConnectivity::VertexVertexIter, VertexHandle>("VertexVertexIter");
// expose_circulator<OpenMesh::PolyConnectivity::VertexIHalfedgeIter, VertexHandle>("VertexIHalfedgeIter");
// expose_circulator<OpenMesh::PolyConnectivity::VertexOHalfedgeIter, VertexHandle>("VertexOHalfedgeIter");
// expose_circulator<OpenMesh::PolyConnectivity::VertexEdgeIter, VertexHandle>("VertexEdgeIter");
// expose_circulator<OpenMesh::PolyConnectivity::VertexFaceIter, VertexHandle>("VertexFaceIter");
expose_circulator<OM::PolyConnectivity::VertexVertexIter, OM::VertexHandle>(m, "VertexVertexIter");
expose_circulator<OM::PolyConnectivity::VertexIHalfedgeIter, OM::VertexHandle>(m, "VertexIHalfedgeIter");
expose_circulator<OM::PolyConnectivity::VertexOHalfedgeIter, OM::VertexHandle>(m, "VertexOHalfedgeIter");
expose_circulator<OM::PolyConnectivity::VertexEdgeIter, OM::VertexHandle>(m, "VertexEdgeIter");
expose_circulator<OM::PolyConnectivity::VertexFaceIter, OM::VertexHandle>(m, "VertexFaceIter");
// expose_circulator<OpenMesh::PolyConnectivity::FaceVertexIter, FaceHandle>("FaceVertexIter");
// expose_circulator<OpenMesh::PolyConnectivity::FaceHalfedgeIter, FaceHandle>("FaceHalfedgeIter");
// expose_circulator<OpenMesh::PolyConnectivity::FaceEdgeIter, FaceHandle>("FaceEdgeIter");
// expose_circulator<OpenMesh::PolyConnectivity::FaceFaceIter, FaceHandle>("FaceFaceIter");
expose_circulator<OM::PolyConnectivity::FaceVertexIter, OM::FaceHandle>(m, "FaceVertexIter");
expose_circulator<OM::PolyConnectivity::FaceHalfedgeIter, OM::FaceHandle>(m, "FaceHalfedgeIter");
expose_circulator<OM::PolyConnectivity::FaceEdgeIter, OM::FaceHandle>(m, "FaceEdgeIter");
expose_circulator<OM::PolyConnectivity::FaceFaceIter, OM::FaceHandle>(m, "FaceFaceIter");
// expose_circulator<OpenMesh::PolyConnectivity::HalfedgeLoopIter, HalfedgeHandle>("HalfedgeLoopIter");
expose_circulator<OM::PolyConnectivity::HalfedgeLoopIter, OM::HalfedgeHandle>(m, "HalfedgeLoopIter");
// typedef IteratorWrapperT<PolyConnectivity::VertexIter, &ArrayKernel::n_vertices> VertexIterWrapper;
// typedef IteratorWrapperT<PolyConnectivity::HalfedgeIter, &ArrayKernel::n_halfedges> HalfedgeIterWrapper;
......
......@@ -3,8 +3,9 @@
#include "Bindings.hh"
namespace OpenMesh {
namespace Python {
#include <pybind11/pybind11.h>
namespace py = pybind11;
/**
* Wrapper for circulators.
......@@ -61,8 +62,7 @@ class CirculatorWrapperT {
return res;
}
else {
PyErr_SetString(PyExc_StopIteration, "No more data.");
boost::python::throw_error_already_set();
throw py::stop_iteration();
}
return typename Circulator::value_type();
}
......@@ -83,16 +83,14 @@ class CirculatorWrapperT {
* that are passed from %Python to C++ are instances of CirculatorWrapperT.
*/
template<class Circulator, class CenterEntityHandle>
void expose_circulator(const char *_name) {
class_<CirculatorWrapperT<Circulator, CenterEntityHandle> >(_name, init<TriMesh&, CenterEntityHandle>())
.def(init<PolyMesh&, CenterEntityHandle>())
void expose_circulator(py::module& m, const char *_name) {
py::class_<CirculatorWrapperT<Circulator, CenterEntityHandle> >(m, _name)
.def(py::init<TriMesh&, CenterEntityHandle>())
.def(py::init<PolyMesh&, CenterEntityHandle>())
.def("__iter__", &CirculatorWrapperT<Circulator, CenterEntityHandle>::iter)
.def("__next__", &CirculatorWrapperT<Circulator, CenterEntityHandle>::next)
.def("next", &CirculatorWrapperT<Circulator, CenterEntityHandle>::next)
;
}
} // namespace OpenMesh
} // namespace Python
#endif
......@@ -3,8 +3,9 @@
#include "Bindings.hh"
namespace OpenMesh {
namespace Python {
#include <pybind11/pybind11.h>
namespace py = pybind11;
/**
* Wrapper for mesh item iterators.
......@@ -69,8 +70,7 @@ class IteratorWrapperT {
return res;
}
else {
PyErr_SetString(PyExc_StopIteration, "No more data.");
boost::python::throw_error_already_set();
throw py::stop_iteration();
}
return typename Iterator::value_type();
}
......@@ -105,9 +105,12 @@ class IteratorWrapperT {
* that are passed from %Python to C++ are instances of IteratorWrapperT.
*/
template<class Iterator, size_t (OpenMesh::ArrayKernel::*n_items)() const>
void expose_iterator(const char *_name) {
class_<IteratorWrapperT<Iterator, n_items> >(_name, init<PolyMesh&, typename Iterator::value_type, optional<bool> >())
.def(init<TriMesh&, typename Iterator::value_type, optional<bool> >())
void expose_iterator(py::module& m, const char *_name) {
py::class_<IteratorWrapperT<Iterator, n_items> >(m, _name)
.def(py::init<PolyMesh&, typename Iterator::value_type>())
.def(py::init<PolyMesh&, typename Iterator::value_type, bool>())
.def(py::init<TriMesh&, typename Iterator::value_type>())
.def(py::init<TriMesh&, typename Iterator::value_type, bool>())
.def("__iter__", &IteratorWrapperT<Iterator, n_items>::iter)
.def("__next__", &IteratorWrapperT<Iterator, n_items>::next)
.def("__len__", &IteratorWrapperT<Iterator, n_items>::len)
......@@ -115,7 +118,4 @@ void expose_iterator(const char *_name) {
;
}
} // namespace OpenMesh
} // namespace Python
#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