📄 iteratorst.hh
字号:
/// Construct with mesh and a target handle. ConstEdgeIterT(mesh_ref _mesh, value_handle _hnd, bool _skip=false) : mesh_(&_mesh), hnd_(_hnd), skip_bits_(0) { if (_skip) enable_skipping(); } /// Copy constructor ConstEdgeIterT(const ConstEdgeIterT& _rhs) : mesh_(_rhs.mesh_), hnd_(_rhs.hnd_), skip_bits_(_rhs.skip_bits_) {} /// Assignment operator ConstEdgeIterT& operator=(const ConstEdgeIterT<Mesh>& _rhs) { mesh_ = _rhs.mesh_; hnd_ = _rhs.hnd_; skip_bits_ = _rhs.skip_bits_; return *this; }#if 1 /// Construct from a non-const iterator ConstEdgeIterT(const EdgeIterT<Mesh>& _rhs) : mesh_(_rhs.mesh_), hnd_(_rhs.hnd_), skip_bits_(_rhs.skip_bits_) {} /// Assignment from non-const iterator ConstEdgeIterT& operator=(const EdgeIterT<Mesh>& _rhs) { mesh_ = _rhs.mesh_; hnd_ = _rhs.hnd_; skip_bits_ = _rhs.skip_bits_; return *this; }#else friend class ConstEdgeIterT<Mesh>;#endif /// Standard dereferencing operator. reference operator*() const { return mesh_->deref(hnd_); } /// Standard pointer operator. pointer operator->() const { return &(mesh_->deref(hnd_)); } /// Get the handle of the item the iterator refers to. value_handle handle() const { return hnd_; } /// Cast to the handle of the item the iterator refers to. operator value_handle() const { return hnd_; } /// Are two iterators equal? Only valid if they refer to the same mesh! bool operator==(const ConstEdgeIterT& _rhs) const { return ((mesh_ == _rhs.mesh_) && (hnd_ == _rhs.hnd_)); } /// Not equal? bool operator!=(const ConstEdgeIterT& _rhs) const { return !operator==(_rhs); } /// Standard pre-increment operator ConstEdgeIterT& operator++() { hnd_.__increment(); if (skip_bits_) skip_fwd(); return *this; } /// Standard pre-decrement operator ConstEdgeIterT& operator--() { hnd_.__decrement(); if (skip_bits_) skip_bwd(); return *this; } /// Turn on skipping: automatically skip deleted/hidden elements void enable_skipping() { if (mesh_ && mesh_->has_edge_status()) { Attributes::StatusInfo status; status.set_deleted(true); status.set_hidden(true); skip_bits_ = status.bits(); skip_fwd(); } else skip_bits_ = 0; } /// Turn on skipping: automatically skip deleted/hidden elements void disable_skipping() { skip_bits_ = 0; }private: void skip_fwd() { assert(mesh_ && skip_bits_); while ((hnd_.idx() < (signed) mesh_->n_edges()) && (mesh_->status(hnd_).bits() & skip_bits_)) hnd_.__increment(); } void skip_bwd() { assert(mesh_ && skip_bits_); while ((hnd_.idx() >= 0) && (mesh_->status(hnd_).bits() & skip_bits_)) hnd_.__decrement(); }private: mesh_ptr mesh_; value_handle hnd_; unsigned int skip_bits_;};//== CLASS DEFINITION ========================================================= /** \class FaceIterT IteratorsT.hh <OpenMesh/Mesh/Iterators/IteratorsT.hh> Linear iterator.*/template <class Mesh>class FaceIterT{public: //--- Typedefs --- typedef typename Mesh::Face value_type; typedef typename Mesh::FaceHandle value_handle;#if 0 typedef const value_type& reference; typedef const value_type* pointer; typedef const Mesh* mesh_ptr; typedef const Mesh& mesh_ref;#else typedef value_type& reference; typedef value_type* pointer; typedef Mesh* mesh_ptr; typedef Mesh& mesh_ref;#endif /// Default constructor. FaceIterT() : mesh_(0), skip_bits_(0) {} /// Construct with mesh and a target handle. FaceIterT(mesh_ref _mesh, value_handle _hnd, bool _skip=false) : mesh_(&_mesh), hnd_(_hnd), skip_bits_(0) { if (_skip) enable_skipping(); } /// Copy constructor FaceIterT(const FaceIterT& _rhs) : mesh_(_rhs.mesh_), hnd_(_rhs.hnd_), skip_bits_(_rhs.skip_bits_) {} /// Assignment operator FaceIterT& operator=(const FaceIterT<Mesh>& _rhs) { mesh_ = _rhs.mesh_; hnd_ = _rhs.hnd_; skip_bits_ = _rhs.skip_bits_; return *this; }#if 0 /// Construct from a non-const iterator FaceIterT(const FaceIterT<Mesh>& _rhs) : mesh_(_rhs.mesh_), hnd_(_rhs.hnd_), skip_bits_(_rhs.skip_bits_) {} /// Assignment from non-const iterator FaceIterT& operator=(const FaceIterT<Mesh>& _rhs) { mesh_ = _rhs.mesh_; hnd_ = _rhs.hnd_; skip_bits_ = _rhs.skip_bits_; return *this; }#else friend class ConstFaceIterT<Mesh>;#endif /// Standard dereferencing operator. reference operator*() const { return mesh_->deref(hnd_); } /// Standard pointer operator. pointer operator->() const { return &(mesh_->deref(hnd_)); } /// Get the handle of the item the iterator refers to. value_handle handle() const { return hnd_; } /// Cast to the handle of the item the iterator refers to. operator value_handle() const { return hnd_; } /// Are two iterators equal? Only valid if they refer to the same mesh! bool operator==(const FaceIterT& _rhs) const { return ((mesh_ == _rhs.mesh_) && (hnd_ == _rhs.hnd_)); } /// Not equal? bool operator!=(const FaceIterT& _rhs) const { return !operator==(_rhs); } /// Standard pre-increment operator FaceIterT& operator++() { hnd_.__increment(); if (skip_bits_) skip_fwd(); return *this; } /// Standard pre-decrement operator FaceIterT& operator--() { hnd_.__decrement(); if (skip_bits_) skip_bwd(); return *this; } /// Turn on skipping: automatically skip deleted/hidden elements void enable_skipping() { if (mesh_ && mesh_->has_face_status()) { Attributes::StatusInfo status; status.set_deleted(true); status.set_hidden(true); skip_bits_ = status.bits(); skip_fwd(); } else skip_bits_ = 0; } /// Turn on skipping: automatically skip deleted/hidden elements void disable_skipping() { skip_bits_ = 0; }private: void skip_fwd() { assert(mesh_ && skip_bits_); while ((hnd_.idx() < (signed) mesh_->n_faces()) && (mesh_->status(hnd_).bits() & skip_bits_)) hnd_.__increment(); } void skip_bwd() { assert(mesh_ && skip_bits_); while ((hnd_.idx() >= 0) && (mesh_->status(hnd_).bits() & skip_bits_)) hnd_.__decrement(); }private: mesh_ptr mesh_; value_handle hnd_; unsigned int skip_bits_;};//== CLASS DEFINITION ========================================================= /** \class ConstFaceIterT IteratorsT.hh <OpenMesh/Mesh/Iterators/IteratorsT.hh> Linear iterator.*/template <class Mesh>class ConstFaceIterT{public: //--- Typedefs --- typedef typename Mesh::Face value_type; typedef typename Mesh::FaceHandle value_handle;#if 1 typedef const value_type& reference; typedef const value_type* pointer; typedef const Mesh* mesh_ptr; typedef const Mesh& mesh_ref;#else typedef value_type& reference; typedef value_type* pointer; typedef Mesh* mesh_ptr; typedef Mesh& mesh_ref;#endif /// Default constructor. ConstFaceIterT() : mesh_(0), skip_bits_(0) {} /// Construct with mesh and a target handle. ConstFaceIterT(mesh_ref _mesh, value_handle _hnd, bool _skip=false) : mesh_(&_mesh), hnd_(_hnd), skip_bits_(0) { if (_skip) enable_skipping(); } /// Copy constructor ConstFaceIterT(const ConstFaceIterT& _rhs) : mesh_(_rhs.mesh_), hnd_(_rhs.hnd_), skip_bits_(_rhs.skip_bits_) {} /// Assignment operator ConstFaceIterT& operator=(const ConstFaceIterT<Mesh>& _rhs) { mesh_ = _rhs.mesh_; hnd_ = _rhs.hnd_; skip_bits_ = _rhs.skip_bits_; return *this; }#if 1 /// Construct from a non-const iterator ConstFaceIterT(const FaceIterT<Mesh>& _rhs) : mesh_(_rhs.mesh_), hnd_(_rhs.hnd_), skip_bits_(_rhs.skip_bits_) {} /// Assignment from non-const iterator ConstFaceIterT& operator=(const FaceIterT<Mesh>& _rhs) { mesh_ = _rhs.mesh_; hnd_ = _rhs.hnd_; skip_bits_ = _rhs.skip_bits_; return *this; }#else friend class ConstFaceIterT<Mesh>;#endif /// Standard dereferencing operator. reference operator*() const { return mesh_->deref(hnd_); } /// Standard pointer operator. pointer operator->() const { return &(mesh_->deref(hnd_)); } /// Get the handle of the item the iterator refers to. value_handle handle() const { return hnd_; } /// Cast to the handle of the item the iterator refers to. operator value_handle() const { return hnd_; } /// Are two iterators equal? Only valid if they refer to the same mesh! bool operator==(const ConstFaceIterT& _rhs) const { return ((mesh_ == _rhs.mesh_) && (hnd_ == _rhs.hnd_)); } /// Not equal? bool operator!=(const ConstFaceIterT& _rhs) const { return !operator==(_rhs); } /// Standard pre-increment operator ConstFaceIterT& operator++() { hnd_.__increment(); if (skip_bits_) skip_fwd(); return *this; } /// Standard pre-decrement operator ConstFaceIterT& operator--() { hnd_.__decrement(); if (skip_bits_) skip_bwd(); return *this; } /// Turn on skipping: automatically skip deleted/hidden elements void enable_skipping() { if (mesh_ && mesh_->has_face_status()) { Attributes::StatusInfo status; status.set_deleted(true); status.set_hidden(true); skip_bits_ = status.bits(); skip_fwd(); } else skip_bits_ = 0; } /// Turn on skipping: automatically skip deleted/hidden elements void disable_skipping() { skip_bits_ = 0; }private: void skip_fwd() { assert(mesh_ && skip_bits_); while ((hnd_.idx() < (signed) mesh_->n_faces()) && (mesh_->status(hnd_).bits() & skip_bits_)) hnd_.__increment(); } void skip_bwd() { assert(mesh_ && skip_bits_); while ((hnd_.idx() >= 0) && (mesh_->status(hnd_).bits() & skip_bits_)) hnd_.__decrement(); }private: mesh_ptr mesh_; value_handle hnd_; unsigned int skip_bits_;};//=============================================================================} // namespace Iterators} // namespace OpenMesh//=============================================================================#endif //=============================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -