/*===========================================================================*\ * * * OpenVolumeMesh * * Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen * * www.openmesh.org * * * *---------------------------------------------------------------------------* * This file is part of OpenVolumeMesh. * * * * OpenVolumeMesh is free software: you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * * published by the Free Software Foundation, either version 3 of * * the License, or (at your option) any later version with the * * following exceptions: * * * * If other files instantiate templates or use macros * * or inline functions from this file, or you compile this file and * * link it with other files to produce an executable, this file does * * not by itself cause the resulting executable to be covered by the * * GNU Lesser General Public License. This exception does not however * * invalidate any other reasons why the executable file might be * * covered by the GNU Lesser General Public License. * * * * OpenVolumeMesh is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU LesserGeneral Public * * License along with OpenVolumeMesh. If not, * * see . * * * \*===========================================================================*/ /*===========================================================================*\ * * * $Revision: 1 $ * * $Date: 2011-01-09 12:46:45 +0100 (Mo, 09. Jan 2011) $ * * $LastChangedBy: kremer $ * * * \*===========================================================================*/ #ifndef ITERATORS_HH_ #define ITERATORS_HH_ #include #include namespace OpenVolumeMesh { // Forward declaration template class OpenVolumeMesh; template class BaseIterator { public: // STL compliance typedef std::input_iterator_tag iterator_category; typedef int distance_type; typedef OH value_type; typedef OH* pointer; typedef OH& reference; BaseIterator(const OpenVolumeMesh* _mesh, const IH& _ih, const OH& _ch = -1) : valid_(true), cur_handle_(_ch), ref_handle_(_ih), mesh_(_mesh) {} // STL compliance (needs to have default constructor) BaseIterator() : valid_(false), mesh_(0) {} virtual ~BaseIterator() {} bool operator== (const BaseIterator& _c) const { return (this->cur_handle_ == _c.cur_handle() && this->ref_handle_ == _c.ref_handle() && this->mesh_ == _c.mesh()); } bool operator!= (const BaseIterator& _c) const { return !this->operator==(_c); } const OH* operator->() const { return &cur_handle_; } const OH& operator*() const { return cur_handle_; } BaseIterator& operator=(const BaseIterator& _c) { this->valid_ = _c.valid(); this->cur_handle_ = _c.cur_handle(); this->ref_handle_ = _c.ref_handle(); this->mesh_ = _c.mesh(); return *this; } // Increment/decrement operators to be overloaded // virtual BaseIterator& operator++() = 0; // virtual BaseIterator operator++(int) = 0; // virtual BaseIterator& operator--() = 0; // virtual BaseIterator operator--(int) = 0; // // virtual BaseIterator operator+ (int _n) = 0; // virtual BaseIterator& operator+=(int _n) = 0; // virtual BaseIterator operator- (int _n) = 0; // virtual BaseIterator& operator-=(int _n) = 0; // operator int() const { // return cur_handle_; // } operator bool() const { return valid_; } void valid(bool _valid) { valid_ = _valid; } bool valid() const { return valid_; } void cur_handle(const OH& _h) { cur_handle_ = _h; } const OH& cur_handle() const { return cur_handle_; } const IH& ref_handle() const { return ref_handle_; } const OpenVolumeMesh* mesh() const { return mesh_; } private: bool valid_; OH cur_handle_; IH ref_handle_; const OpenVolumeMesh* mesh_; }; //=========================================================================== template class VertexOHalfedgeIter : public BaseIterator::VertexHandle, typename OpenVolumeMesh::HalfEdgeHandle> { public: typedef BaseIterator::VertexHandle, typename OpenVolumeMesh::HalfEdgeHandle> BaseIter; typedef typename OpenVolumeMesh::VertexHandle VertexHandle; VertexOHalfedgeIter(const VertexHandle& _vIdx, const OpenVolumeMesh* _mesh); // Post increment/decrement operator VertexOHalfedgeIter operator++(int) { VertexOHalfedgeIter cpy = *this; ++(*this); return cpy; } VertexOHalfedgeIter operator--(int) { VertexOHalfedgeIter cpy = *this; --(*this); return cpy; } VertexOHalfedgeIter operator+(int _n) { VertexOHalfedgeIter cpy = *this; for(int i = 0; i < _n; ++i) { ++cpy; } return cpy; } VertexOHalfedgeIter operator-(int _n) { VertexOHalfedgeIter cpy = *this; for(int i = 0; i < _n; ++i) { --cpy; } return cpy; } VertexOHalfedgeIter& operator+=(int _n) { for(int i = 0; i < _n; ++i) { ++(*this); } return *this; } VertexOHalfedgeIter& operator-=(int _n) { for(int i = 0; i < _n; ++i) { --(*this); } return *this; } VertexOHalfedgeIter& operator++(); VertexOHalfedgeIter& operator--(); private: int cur_index_; }; //=========================================================================== template class HalfEdgeHalfFaceIter : public BaseIterator::HalfEdgeHandle, typename OpenVolumeMesh::HalfFaceHandle> { public: typedef BaseIterator::HalfEdgeHandle, typename OpenVolumeMesh::HalfFaceHandle> BaseIter; typedef typename OpenVolumeMesh::HalfEdgeHandle HalfEdgeHandle; HalfEdgeHalfFaceIter(const HalfEdgeHandle& _heIdx, const OpenVolumeMesh* _mesh); // Post increment/decrement operator HalfEdgeHalfFaceIter operator++(int) { HalfEdgeHalfFaceIter cpy = *this; ++(*this); return cpy; } HalfEdgeHalfFaceIter operator--(int) { HalfEdgeHalfFaceIter cpy = *this; --(*this); return cpy; } HalfEdgeHalfFaceIter operator+(int _n) { HalfEdgeHalfFaceIter cpy = *this; for(int i = 0; i < _n; ++i) { ++cpy; } return cpy; } HalfEdgeHalfFaceIter operator-(int _n) { HalfEdgeHalfFaceIter cpy = *this; for(int i = 0; i < _n; ++i) { --cpy; } return cpy; } HalfEdgeHalfFaceIter& operator+=(int _n) { for(int i = 0; i < _n; ++i) { ++(*this); } return *this; } HalfEdgeHalfFaceIter& operator-=(int _n) { for(int i = 0; i < _n; ++i) { --(*this); } return *this; } HalfEdgeHalfFaceIter& operator++(); HalfEdgeHalfFaceIter& operator--(); private: int cur_index_; }; //=========================================================================== template class VertexCellIter : public BaseIterator::VertexHandle, typename OpenVolumeMesh::CellHandle> { public: typedef BaseIterator::VertexHandle, typename OpenVolumeMesh::CellHandle> BaseIter; typedef typename OpenVolumeMesh::VertexHandle VertexHandle; typedef typename OpenVolumeMesh::CellHandle CellHandle; typedef typename OpenVolumeMesh::HalfEdgeHandle HalfEdgeHandle; typedef typename OpenVolumeMesh::HalfFaceHandle HalfFaceHandle; VertexCellIter(const VertexHandle& _vIdx, const OpenVolumeMesh* _mesh); VertexCellIter& operator=(const VertexCellIter& _c) { BaseIter::operator=(_c); cells_ = cells_; cell_iter_ = cells_.begin(); return *this; } // Post increment/decrement operator VertexCellIter operator++(int) { VertexCellIter cpy = *this; ++(*this); return cpy; } VertexCellIter operator--(int) { VertexCellIter cpy = *this; --(*this); return cpy; } VertexCellIter operator+(int _n) { VertexCellIter cpy = *this; for(int i = 0; i < _n; ++i) { ++cpy; } return cpy; } VertexCellIter operator-(int _n) { VertexCellIter cpy = *this; for(int i = 0; i < _n; ++i) { --cpy; } return cpy; } VertexCellIter& operator+=(int _n) { for(int i = 0; i < _n; ++i) { ++(*this); } return *this; } VertexCellIter& operator-=(int _n) { for(int i = 0; i < _n; ++i) { --(*this); } return *this; } VertexCellIter& operator++(); VertexCellIter& operator--(); private: std::set cells_; typename std::set::const_iterator cell_iter_; }; template class HalfedgeCellIter : public BaseIterator::HalfEdgeHandle, typename OpenVolumeMesh::CellHandle> { public: typedef BaseIterator::HalfEdgeHandle, typename OpenVolumeMesh::CellHandle> BaseIter; typedef typename OpenVolumeMesh::HalfEdgeHandle HalfEdgeHandle; HalfedgeCellIter(const HalfEdgeHandle& _heIdx, const OpenVolumeMesh* _mesh); // Post increment/decrement operator HalfedgeCellIter operator++(int) { HalfedgeCellIter cpy = *this; ++(*this); return cpy; } HalfedgeCellIter operator--(int) { HalfedgeCellIter cpy = *this; --(*this); return cpy; } HalfedgeCellIter operator+(int _n) { HalfedgeCellIter cpy = *this; for(int i = 0; i < _n; ++i) { ++cpy; } return cpy; } HalfedgeCellIter operator-(int _n) { HalfedgeCellIter cpy = *this; for(int i = 0; i < _n; ++i) { --cpy; } return cpy; } HalfedgeCellIter& operator+=(int _n) { for(int i = 0; i < _n; ++i) { ++(*this); } return *this; } HalfedgeCellIter& operator-=(int _n) { for(int i = 0; i < _n; ++i) { --(*this); } return *this; } HalfedgeCellIter& operator++(); HalfedgeCellIter& operator--(); private: int cur_index_; }; //=========================================================================== template class CellVertexIter : public BaseIterator::CellHandle, typename OpenVolumeMesh::VertexHandle> { public: typedef BaseIterator::CellHandle, typename OpenVolumeMesh::VertexHandle> BaseIter; typedef typename OpenVolumeMesh::CellHandle CellHandle; typedef typename OpenVolumeMesh::VertexHandle VertexHandle; typedef typename OpenVolumeMesh::HalfFaceHandle HalfFaceHandle; typedef typename OpenVolumeMesh::HalfEdgeHandle HalfEdgeHandle; CellVertexIter(const CellHandle& _cIdx, const OpenVolumeMesh* _mesh); CellVertexIter& operator=(const CellVertexIter& _c) { BaseIter::operator=(_c); incident_vertices_ = _c.incident_vertices_; v_iter_ = incident_vertices_.begin(); return *this; } // Post increment/decrement operator CellVertexIter operator++(int) { CellVertexIter cpy = *this; ++(*this); return cpy; } CellVertexIter operator--(int) { CellVertexIter cpy = *this; --(*this); return cpy; } CellVertexIter operator+(int _n) { CellVertexIter cpy = *this; for(int i = 0; i < _n; ++i) { ++cpy; } return cpy; } CellVertexIter operator-(int _n) { CellVertexIter cpy = *this; for(int i = 0; i < _n; ++i) { --cpy; } return cpy; } CellVertexIter& operator+=(int _n) { for(int i = 0; i < _n; ++i) { ++(*this); } return *this; } CellVertexIter& operator-=(int _n) { for(int i = 0; i < _n; ++i) { --(*this); } return *this; } CellVertexIter& operator++(); CellVertexIter& operator--(); private: std::set incident_vertices_; typename std::set::const_iterator v_iter_; }; //=========================================================================== template class CellCellIter : public BaseIterator::CellHandle, typename OpenVolumeMesh::CellHandle> { public: typedef BaseIterator::CellHandle, typename OpenVolumeMesh::CellHandle> BaseIter; typedef typename OpenVolumeMesh::CellHandle CellHandle; typedef typename OpenVolumeMesh::HalfFaceHandle HalfFaceHandle; CellCellIter(const CellHandle& _cIdx, const OpenVolumeMesh* _mesh); CellCellIter& operator=(const CellCellIter& _c) { BaseIter::operator=(_c); adjacent_cells_ = _c.adjacent_cells_; c_iter_ = adjacent_cells_.begin(); return *this; } // Post increment/decrement operator CellCellIter operator++(int) { CellCellIter cpy = *this; ++(*this); return cpy; } CellCellIter operator--(int) { CellCellIter cpy = *this; --(*this); return cpy; } CellCellIter operator+(int _n) { CellCellIter cpy = *this; for(int i = 0; i < _n; ++i) { ++cpy; } return cpy; } CellCellIter operator-(int _n) { CellCellIter cpy = *this; for(int i = 0; i < _n; ++i) { --cpy; } return cpy; } CellCellIter& operator+=(int _n) { for(int i = 0; i < _n; ++i) { ++(*this); } return *this; } CellCellIter& operator-=(int _n) { for(int i = 0; i < _n; ++i) { --(*this); } return *this; } CellCellIter& operator++(); CellCellIter& operator--(); private: std::set adjacent_cells_; typename std::set::const_iterator c_iter_; }; //=========================================================================== template class BoundaryFaceIter : public BaseIterator::FaceHandle, typename OpenVolumeMesh::FaceHandle> { public: typedef BaseIterator::FaceHandle, typename OpenVolumeMesh::FaceHandle> BaseIter; typedef typename OpenVolumeMesh::FaceHandle FaceHandle; BoundaryFaceIter(const OpenVolumeMesh* _mesh); // Post increment/decrement operator BoundaryFaceIter operator++(int) { BoundaryFaceIter cpy = *this; ++(*this); return cpy; } BoundaryFaceIter operator--(int) { BoundaryFaceIter cpy = *this; --(*this); return cpy; } BoundaryFaceIter operator+(int _n) { BoundaryFaceIter cpy = *this; for(int i = 0; i < _n; ++i) { ++cpy; } return cpy; } BoundaryFaceIter operator-(int _n) { BoundaryFaceIter cpy = *this; for(int i = 0; i < _n; ++i) { --cpy; } return cpy; } BoundaryFaceIter& operator+=(int _n) { for(int i = 0; i < _n; ++i) { ++(*this); } return *this; } BoundaryFaceIter& operator-=(int _n) { for(int i = 0; i < _n; ++i) { --(*this); } return *this; } BoundaryFaceIter& operator++(); BoundaryFaceIter& operator--(); private: typename std::vector::const_iterator bf_it_; }; //=========================================================================== template class VertexIter : public BaseIterator::VertexHandle, typename OpenVolumeMesh::VertexHandle> { public: typedef BaseIterator::VertexHandle, typename OpenVolumeMesh::VertexHandle> BaseIter; typedef typename OpenVolumeMesh::VertexHandle VertexHandle; VertexIter(const OpenVolumeMesh* _mesh, const VertexHandle& _vh = VertexHandle(0)); // Post increment/decrement operator VertexIter operator++(int) { VertexIter cpy = *this; ++(*this); return cpy; } VertexIter operator--(int) { VertexIter cpy = *this; --(*this); return cpy; } VertexIter operator+(int _n) { VertexIter cpy = *this; for(int i = 0; i < _n; ++i) { ++cpy; } return cpy; } VertexIter operator-(int _n) { VertexIter cpy = *this; for(int i = 0; i < _n; ++i) { --cpy; } return cpy; } VertexIter& operator+=(int _n) { for(int i = 0; i < _n; ++i) { ++(*this); } return *this; } VertexIter& operator-=(int _n) { for(int i = 0; i < _n; ++i) { --(*this); } return *this; } VertexIter& operator++(); VertexIter& operator--(); private: int cur_index_; }; //=========================================================================== template class EdgeIter : public BaseIterator::EdgeHandle, typename OpenVolumeMesh::EdgeHandle> { public: typedef BaseIterator::EdgeHandle, typename OpenVolumeMesh::EdgeHandle> BaseIter; typedef typename OpenVolumeMesh::EdgeHandle EdgeHandle; EdgeIter(const OpenVolumeMesh* _mesh, const EdgeHandle& _eh = EdgeHandle(0)); // Post increment/decrement operator EdgeIter operator++(int) { EdgeIter cpy = *this; ++(*this); return cpy; } EdgeIter operator--(int) { EdgeIter cpy = *this; --(*this); return cpy; } EdgeIter operator+(int _n) { EdgeIter cpy = *this; for(int i = 0; i < _n; ++i) { ++cpy; } return cpy; } EdgeIter operator-(int _n) { EdgeIter cpy = *this; for(int i = 0; i < _n; ++i) { --cpy; } return cpy; } EdgeIter& operator+=(int _n) { for(int i = 0; i < _n; ++i) { ++(*this); } return *this; } EdgeIter& operator-=(int _n) { for(int i = 0; i < _n; ++i) { --(*this); } return *this; } EdgeIter& operator++(); EdgeIter& operator--(); private: int cur_index_; }; //=========================================================================== template class HalfEdgeIter : public BaseIterator::HalfEdgeHandle, typename OpenVolumeMesh::HalfEdgeHandle> { public: typedef BaseIterator::HalfEdgeHandle, typename OpenVolumeMesh::HalfEdgeHandle> BaseIter; typedef typename OpenVolumeMesh::HalfEdgeHandle HalfEdgeHandle; HalfEdgeIter(const OpenVolumeMesh* _mesh, const HalfEdgeHandle& _heh = HalfEdgeHandle(0)); // Post increment/decrement operator HalfEdgeIter operator++(int) { HalfEdgeIter cpy = *this; ++(*this); return cpy; } HalfEdgeIter operator--(int) { HalfEdgeIter cpy = *this; --(*this); return cpy; } HalfEdgeIter operator+(int _n) { HalfEdgeIter cpy = *this; for(int i = 0; i < _n; ++i) { ++cpy; } return cpy; } HalfEdgeIter operator-(int _n) { HalfEdgeIter cpy = *this; for(int i = 0; i < _n; ++i) { --cpy; } return cpy; } HalfEdgeIter& operator+=(int _n) { for(int i = 0; i < _n; ++i) { ++(*this); } return *this; } HalfEdgeIter& operator-=(int _n) { for(int i = 0; i < _n; ++i) { --(*this); } return *this; } HalfEdgeIter& operator++(); HalfEdgeIter& operator--(); private: int cur_index_; }; //=========================================================================== template class FaceIter : public BaseIterator::FaceHandle, typename OpenVolumeMesh::FaceHandle> { public: typedef BaseIterator::FaceHandle, typename OpenVolumeMesh::FaceHandle> BaseIter; typedef typename OpenVolumeMesh::FaceHandle FaceHandle; FaceIter(const OpenVolumeMesh* _mesh, const FaceHandle& _fh = FaceHandle(0)); // Post increment/decrement operator FaceIter operator++(int) { FaceIter cpy = *this; ++(*this); return cpy; } FaceIter operator--(int) { FaceIter cpy = *this; --(*this); return cpy; } FaceIter operator+(int _n) { FaceIter cpy = *this; for(int i = 0; i < _n; ++i) { ++cpy; } return cpy; } FaceIter operator-(int _n) { FaceIter cpy = *this; for(int i = 0; i < _n; ++i) { --cpy; } return cpy; } FaceIter& operator+=(int _n) { for(int i = 0; i < _n; ++i) { ++(*this); } return *this; } FaceIter& operator-=(int _n) { for(int i = 0; i < _n; ++i) { --(*this); } return *this; } FaceIter& operator++(); FaceIter& operator--(); private: int cur_index_; }; //=========================================================================== template class HalfFaceIter : public BaseIterator::HalfFaceHandle, typename OpenVolumeMesh::HalfFaceHandle> { public: typedef BaseIterator::HalfFaceHandle, typename OpenVolumeMesh::HalfFaceHandle> BaseIter; typedef typename OpenVolumeMesh::HalfFaceHandle HalfFaceHandle; HalfFaceIter(const OpenVolumeMesh* _mesh, const HalfFaceHandle& _hfh = HalfFaceHandle(0)); // Post increment/decrement operator HalfFaceIter operator++(int) { HalfFaceIter cpy = *this; ++(*this); return cpy; } HalfFaceIter operator--(int) { HalfFaceIter cpy = *this; --(*this); return cpy; } HalfFaceIter operator+(int _n) { HalfFaceIter cpy = *this; for(int i = 0; i < _n; ++i) { ++cpy; } return cpy; } HalfFaceIter operator-(int _n) { HalfFaceIter cpy = *this; for(int i = 0; i < _n; ++i) { --cpy; } return cpy; } HalfFaceIter& operator+=(int _n) { for(int i = 0; i < _n; ++i) { ++(*this); } return *this; } HalfFaceIter& operator-=(int _n) { for(int i = 0; i < _n; ++i) { --(*this); } return *this; } HalfFaceIter& operator++(); HalfFaceIter& operator--(); private: int cur_index_; }; //=========================================================================== template class CellIter : public BaseIterator::CellHandle, typename OpenVolumeMesh::CellHandle> { public: typedef BaseIterator::CellHandle, typename OpenVolumeMesh::CellHandle> BaseIter; typedef typename OpenVolumeMesh::CellHandle CellHandle; CellIter(const OpenVolumeMesh* _mesh, const CellHandle& _ch = CellHandle(0)); // Post increment/decrement operator CellIter operator++(int) { CellIter cpy = *this; ++(*this); return cpy; } CellIter operator--(int) { CellIter cpy = *this; --(*this); return cpy; } CellIter operator+(int _n) { CellIter cpy = *this; for(int i = 0; i < _n; ++i) { ++cpy; } return cpy; } CellIter operator-(int _n) { CellIter cpy = *this; for(int i = 0; i < _n; ++i) { --cpy; } return cpy; } CellIter& operator+=(int _n) { for(int i = 0; i < _n; ++i) { ++(*this); } return *this; } CellIter& operator-=(int _n) { for(int i = 0; i < _n; ++i) { --(*this); } return *this; } CellIter& operator++(); CellIter& operator--(); private: int cur_index_; }; //=========================================================================== } // Namespace OpenVolumeMesh #if defined(INCLUDE_TEMPLATES) && !defined(ITERATORST_CC) #include "IteratorsT.cc" #endif #endif /* ITERATORS_HH_ */