| OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Iterator.hh
1 #ifndef OPENMESH_PYTHON_ITERATOR_HH
2 #define OPENMESH_PYTHON_ITERATOR_HH
3
4 #include "Python/Bindings.hh"
5
6 namespace OpenMesh {
7 namespace Python {
8
20 template<class Iterator, size_t (OpenMesh::ArrayKernel::*n_items)() const>
21 class IteratorWrapperT {
22 public:
23
31 IteratorWrapperT(const PolyMesh& _mesh, typename Iterator::value_type _hnd, bool _skip = false) :
32 mesh_(_mesh), n_items_(n_items),
33 iterator_(_mesh, _hnd, _skip),
34 iterator_end_(_mesh, typename Iterator::value_type(int((_mesh.*n_items)()))) {
35 }
36
44 IteratorWrapperT(const TriMesh& _mesh, typename Iterator::value_type _hnd, bool _skip = false) :
45 mesh_(_mesh), n_items_(n_items),
46 iterator_(_mesh, _hnd, _skip),
47 iterator_end_(_mesh, typename Iterator::value_type(int((_mesh.*n_items)()))) {
48 }
49
55 IteratorWrapperT iter() const {
56 return *this;
57 }
58
65 typename Iterator::value_type next() {
66 if (iterator_ != iterator_end_) {
67 typename Iterator::value_type res = *iterator_;
68 ++iterator_;
69 return res;
70 }
71 else {
72 PyErr_SetString(PyExc_StopIteration, "No more data.");
73 boost::python::throw_error_already_set();
74 }
75 return typename Iterator::value_type();
76 }
77
83 unsigned int len() const {
84 return (mesh_.*n_items_)();
85 }
86
87 private:
88 const OpenMesh::PolyConnectivity& mesh_;
89 size_t (OpenMesh::ArrayKernel::*n_items_)() const;
90 Iterator iterator_;
91 Iterator iterator_end_;
92 };
93
107 template<class Iterator, size_t (OpenMesh::ArrayKernel::*n_items)() const>
108 void expose_iterator(const char *_name) {
109 class_<IteratorWrapperT<Iterator, n_items> >(_name, init<PolyMesh&, typename Iterator::value_type, optional<bool> >())
110 .def(init<TriMesh&, typename Iterator::value_type, optional<bool> >())
111 .def("__iter__", &IteratorWrapperT<Iterator, n_items>::iter)
112 .def("__next__", &IteratorWrapperT<Iterator, n_items>::next)
113 .def("__len__", &IteratorWrapperT<Iterator, n_items>::len)
114 .def("next", &IteratorWrapperT<Iterator, n_items>::next)
115 ;
116 }
117
118 } // namespace OpenMesh
119 } // namespace Python
120
121 #endif
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
OpenMesh::PolyMesh_ArrayKernelT
Polygonal mesh based on the ArrayKernel.
Definition: PolyMesh_ArrayKernelT.hh:98
Bindings.hh
OpenMesh::ArrayKernel
Mesh kernel using arrays for mesh item storage.
Definition: ArrayKernel.hh:92
OpenMesh::Python::IteratorWrapperT::IteratorWrapperT
IteratorWrapperT(const TriMesh &_mesh, typename Iterator::value_type _hnd, bool _skip=false)
Constructor.
Definition: Iterator.hh:44
OpenMesh::Python::IteratorWrapperT
Wrapper for mesh item iterators.
Definition: Iterator.hh:21
OpenMesh::Python::IteratorWrapperT::len
unsigned int len() const
Implementation of Python's __len__ magic method.
Definition: Iterator.hh:83
OpenMesh::PolyConnectivity
Connectivity Class for polygonal meshes.
Definition: PolyConnectivity.hh:61
OpenMesh::Python::IteratorWrapperT::IteratorWrapperT
IteratorWrapperT(const PolyMesh &_mesh, typename Iterator::value_type _hnd, bool _skip=false)
Constructor.
Definition: Iterator.hh:31
OpenMesh::Python::IteratorWrapperT::next
Iterator::value_type next()
Implementation of Python's __next__ magic method.
Definition: Iterator.hh:65
OpenMesh::Python::IteratorWrapperT::iter
IteratorWrapperT iter() const
Implementation of Python's __iter__ magic method.
Definition: Iterator.hh:55
OpenMesh::TriMesh_ArrayKernelT
Triangle mesh based on the ArrayKernel.
Definition: TriMesh_ArrayKernelT.hh:98
OpenMesh::Python::expose_iterator
void expose_iterator(const char *_name)
Expose an iterator type to Python.
Definition: Iterator.hh:108