OpenMesh
 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>
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 
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> >())
115  ;
116 }
117 
118 } // namespace OpenMesh
119 } // namespace Python
120 
121 #endif
IteratorWrapperT iter() const
Implementation of Python's __iter__ magic method.
Definition: Iterator.hh:55
Connectivity Class for polygonal meshes.
Definition: PolyConnectivity.hh:61
unsigned int len() const
Implementation of Python's __len__ magic method.
Definition: Iterator.hh:83
Mesh kernel using arrays for mesh item storage.
Definition: ArrayKernel.hh:92
Wrapper for mesh item iterators.
Definition: Iterator.hh:21
IteratorWrapperT(const PolyMesh &_mesh, typename Iterator::value_type _hnd, bool _skip=false)
Constructor.
Definition: Iterator.hh:31
void expose_iterator(const char *_name)
Expose an iterator type to Python.
Definition: Iterator.hh:108
Triangle mesh based on the ArrayKernel.
Definition: TriMesh_ArrayKernelT.hh:98
Polygonal mesh based on the ArrayKernel.
Definition: PolyMesh_ArrayKernelT.hh:98
IteratorWrapperT(const TriMesh &_mesh, typename Iterator::value_type _hnd, bool _skip=false)
Constructor.
Definition: Iterator.hh:44
Iterator::value_type next()
Implementation of Python's __next__ magic method.
Definition: Iterator.hh:65
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64

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