Commit 418e5494 authored by Max Lyon's avatar Max Lyon
Browse files

Merge branch 'iterators' into 'master'

Iterators

See merge request !65
parents 2782a7ef c1df4ffe
Pipeline #10930 passed with stage
in 6 minutes and 52 seconds
......@@ -18,6 +18,7 @@ Version X (?/?/?)
- Fix mesh copying by implementing copy constructors and clone methods
- Fix bug in edge split of tetrahedral meshes
- Ensure that halfface iterators start with a boundary halffaces when cells are deleted
- Added new iterators (VertexIHalfEdgeIter, VertexEdgeIter, VertexHalfFaceIter, EdgeHalfFaceIter, EdgeFaceIter, EdgeCellIter)
......
This diff is collapsed.
......@@ -47,6 +47,10 @@
#include <set>
#include <vector>
#ifndef NDEBUG
#include <iostream>
#endif
#include "OpenVolumeMeshHandle.hh"
namespace OpenVolumeMesh {
......@@ -371,7 +375,7 @@ public:
HalfFaceHandle> BaseIter;
HalfEdgeHalfFaceIter(const HalfEdgeHandle& _heIdx, const TopologyKernel* _mesh, int _max_laps);
HalfEdgeHalfFaceIter(const HalfEdgeHandle& _heIdx, const TopologyKernel* _mesh, int _max_laps = 1);
// Post increment/decrement operator
HalfEdgeHalfFaceIter operator++(int) {
......@@ -1154,60 +1158,453 @@ private:
//===========================================================================
class BoundaryFaceIter : public BaseIterator<FaceHandle> {
namespace Internal {
//===========================================================================
class VertexIHalfEdgeIterImpl : public BaseCirculator<VertexHandle, HalfEdgeHandle> {
public:
typedef BaseIterator<FaceHandle> BaseIter;
typedef BaseCirculator<VertexHandle, HalfEdgeHandle> BaseIter;
typedef VertexHandle CenterEntityHandle;
VertexIHalfEdgeIterImpl(const VertexHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
VertexIHalfEdgeIterImpl& operator++();
VertexIHalfEdgeIterImpl& operator--();
private:
VertexOHalfEdgeIter voh_iter_;
};
//===========================================================================
class VertexEdgeIterImpl : public BaseCirculator<VertexHandle, EdgeHandle> {
public:
typedef BaseCirculator<VertexHandle, EdgeHandle> BaseIter;
typedef VertexHandle CenterEntityHandle;
VertexEdgeIterImpl(const VertexHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
VertexEdgeIterImpl& operator++();
VertexEdgeIterImpl& operator--();
private:
VertexOHalfEdgeIter voh_iter_;
};
//===========================================================================
class VertexHalfFaceIterImpl : public BaseCirculator<VertexHandle, HalfFaceHandle> {
public:
typedef BaseCirculator<VertexHandle, HalfFaceHandle> BaseIter;
typedef VertexHandle CenterEntityHandle;
VertexHalfFaceIterImpl(const VertexHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
VertexHalfFaceIterImpl& operator++();
VertexHalfFaceIterImpl& operator--();
private:
std::vector<HalfFaceHandle> halffaces_;
size_t cur_index_;
};
//===========================================================================
class HalfEdgeFaceIterImpl : public BaseCirculator<HalfEdgeHandle, FaceHandle> {
public:
typedef BaseCirculator<HalfEdgeHandle, FaceHandle> BaseIter;
typedef HalfEdgeHandle CenterEntityHandle;
HalfEdgeFaceIterImpl(const HalfEdgeHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
HalfEdgeFaceIterImpl& operator++();
HalfEdgeFaceIterImpl& operator--();
private:
std::vector<FaceHandle> faces_;
size_t cur_index_;
};
//===========================================================================
class EdgeHalfFaceIterImpl : public BaseCirculator<EdgeHandle, HalfFaceHandle> {
public:
typedef BaseCirculator<EdgeHandle, HalfFaceHandle> BaseIter;
typedef EdgeHandle CenterEntityHandle;
EdgeHalfFaceIterImpl(const EdgeHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
EdgeHalfFaceIterImpl& operator++();
EdgeHalfFaceIterImpl& operator--();
private:
std::vector<HalfFaceHandle> halffaces_;
size_t cur_index_;
};
//===========================================================================
class EdgeFaceIterImpl : public HalfEdgeFaceIterImpl {
public:
typedef EdgeHandle CenterEntityHandle;
EdgeFaceIterImpl(const EdgeHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
};
//===========================================================================
class EdgeCellIterImpl : public HalfEdgeCellIter {
public:
typedef EdgeHandle CenterEntityHandle;
EdgeCellIterImpl(const EdgeHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
};
//===========================================================================
class HalfFaceHalfEdgeIterImpl : public BaseCirculator<HalfFaceHandle, HalfEdgeHandle> {
public:
typedef BaseCirculator<HalfFaceHandle, HalfEdgeHandle> BaseIter;
typedef HalfFaceHandle CenterEntityHandle;
HalfFaceHalfEdgeIterImpl(const HalfFaceHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
HalfFaceHalfEdgeIterImpl& operator++();
HalfFaceHalfEdgeIterImpl& operator--();
private:
size_t cur_index_;
};
//===========================================================================
class HalfFaceEdgeIterImpl : public BaseCirculator<HalfFaceHandle, EdgeHandle> {
public:
typedef BaseCirculator<HalfFaceHandle, EdgeHandle> BaseIter;
typedef HalfFaceHandle CenterEntityHandle;
HalfFaceEdgeIterImpl(const HalfFaceHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
HalfFaceEdgeIterImpl& operator++();
HalfFaceEdgeIterImpl& operator--();
private:
size_t cur_index_;
};
//===========================================================================
class FaceVertexIterImpl : public HalfFaceVertexIter {
public:
typedef FaceHandle CenterEntityHandle;
FaceVertexIterImpl(const FaceHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
};
//===========================================================================
class FaceHalfEdgeIterImpl : public HalfFaceHalfEdgeIterImpl {
public:
typedef FaceHandle CenterEntityHandle;
FaceHalfEdgeIterImpl(const FaceHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
};
//===========================================================================
class FaceEdgeIterImpl : public HalfFaceEdgeIterImpl {
public:
typedef FaceHandle CenterEntityHandle;
FaceEdgeIterImpl(const FaceHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
};
//===========================================================================
class CellHalfEdgeIterImpl : public BaseCirculator<CellHandle, HalfEdgeHandle> {
public:
typedef BaseCirculator<CellHandle, HalfEdgeHandle> BaseIter;
typedef CellHandle CenterEntityHandle;
CellHalfEdgeIterImpl(const CellHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
CellHalfEdgeIterImpl& operator++();
CellHalfEdgeIterImpl& operator--();
private:
std::vector<HalfEdgeHandle> halfedges_;
size_t cur_index_;
};
//===========================================================================
class CellEdgeIterImpl : public BaseCirculator<CellHandle, EdgeHandle> {
public:
typedef BaseCirculator<CellHandle, EdgeHandle> BaseIter;
typedef CellHandle CenterEntityHandle;
CellEdgeIterImpl(const CellHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
CellEdgeIterImpl& operator++();
CellEdgeIterImpl& operator--();
private:
std::vector<EdgeHandle> edges_;
size_t cur_index_;
};
//===========================================================================
class CellHalfFaceIterImpl : public BaseCirculator<CellHandle, HalfFaceHandle> {
public:
typedef BaseCirculator<CellHandle, HalfFaceHandle> BaseIter;
typedef CellHandle CenterEntityHandle;
CellHalfFaceIterImpl(const CellHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
CellHalfFaceIterImpl& operator++();
CellHalfFaceIterImpl& operator--();
private:
std::vector<HalfFaceHandle>::const_iterator hf_iter_;
};
//===========================================================================
class CellFaceIterImpl : public BaseCirculator<CellHandle, FaceHandle> {
public:
typedef BaseCirculator<CellHandle, FaceHandle> BaseIter;
typedef CellHandle CenterEntityHandle;
explicit BoundaryFaceIter(const TopologyKernel* _mesh);
CellFaceIterImpl(const CellHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1);
CellFaceIterImpl& operator++();
CellFaceIterImpl& operator--();
private:
std::vector<HalfFaceHandle>::const_iterator hf_iter_;
};
//===========================================================================
} // Namespace Internal
//===========================================================================
template <class CirculatorImpl>
class GenericCirculator : public CirculatorImpl {
public:
GenericCirculator(const typename CirculatorImpl::CenterEntityHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps = 1) :
CirculatorImpl(_ref_h, _mesh, _max_laps) {}
GenericCirculator& operator++() {
CirculatorImpl::operator++();
return *this;
}
GenericCirculator& operator--() {
CirculatorImpl::operator--();
return *this;
}
// Post increment/decrement operator
BoundaryFaceIter operator++(int) {
BoundaryFaceIter cpy = *this;
GenericCirculator operator++(int) {
GenericCirculator cpy = *this;
++(*this);
return cpy;
}
BoundaryFaceIter operator--(int) {
BoundaryFaceIter cpy = *this;
GenericCirculator operator--(int) {
GenericCirculator cpy = *this;
--(*this);
return cpy;
}
BoundaryFaceIter operator+(int _n) {
BoundaryFaceIter cpy = *this;
GenericCirculator operator+(int _n) {
GenericCirculator cpy = *this;
for(int i = 0; i < _n; ++i) {
++cpy;
}
return cpy;
}
BoundaryFaceIter operator-(int _n) {
BoundaryFaceIter cpy = *this;
GenericCirculator operator-(int _n) {
GenericCirculator cpy = *this;
for(int i = 0; i < _n; ++i) {
--cpy;
}
return cpy;
}
BoundaryFaceIter& operator+=(int _n) {
GenericCirculator& operator+=(int _n) {
for(int i = 0; i < _n; ++i) {
++(*this);
}
return *this;
}
BoundaryFaceIter& operator-=(int _n) {
GenericCirculator& operator-=(int _n) {
for(int i = 0; i < _n; ++i) {
--(*this);
}
return *this;
}
BoundaryFaceIter& operator++();
BoundaryFaceIter& operator--();
};
//===========================================================================
typedef GenericCirculator<Internal::VertexIHalfEdgeIterImpl> VertexIHalfEdgeIter;
typedef GenericCirculator<Internal::VertexEdgeIterImpl> VertexEdgeIter;
typedef GenericCirculator<Internal::VertexHalfFaceIterImpl> VertexHalfFaceIter;
typedef GenericCirculator<Internal::HalfEdgeFaceIterImpl> HalfEdgeFaceIter;
typedef GenericCirculator<Internal::EdgeHalfFaceIterImpl> EdgeHalfFaceIter;
typedef GenericCirculator<Internal::EdgeFaceIterImpl> EdgeFaceIter;
typedef GenericCirculator<Internal::EdgeCellIterImpl> EdgeCellIter;
typedef GenericCirculator<Internal::HalfFaceHalfEdgeIterImpl> HalfFaceHalfEdgeIter;
typedef GenericCirculator<Internal::HalfFaceEdgeIterImpl> HalfFaceEdgeIter;
typedef GenericCirculator<Internal::FaceVertexIterImpl> FaceVertexIter;
typedef GenericCirculator<Internal::FaceHalfEdgeIterImpl> FaceHalfEdgeIter;
typedef GenericCirculator<Internal::FaceEdgeIterImpl> FaceEdgeIter;
typedef GenericCirculator<Internal::CellHalfEdgeIterImpl> CellHalfEdgeIter;
typedef GenericCirculator<Internal::CellEdgeIterImpl> CellEdgeIter;
typedef GenericCirculator<Internal::CellHalfFaceIterImpl> CellHalfFaceIter;
typedef GenericCirculator<Internal::CellFaceIterImpl> CellFaceIter;
//===========================================================================
template <class Iter, class Handle>
class BoundaryItemIter : public BaseIterator<Handle> {
public:
typedef BaseIterator<Handle> BaseIter;
explicit BoundaryItemIter(const TopologyKernel* _mesh) :
BaseIter(_mesh),
it_(_mesh, Handle(0)),
it_begin_(_mesh, Handle(0)),
it_end_(_mesh, Handle((int)n_items())) {
if(!has_incidences()) {
#ifndef NDEBUG
std::cerr << "This iterator needs bottom-up incidences!" << std::endl;
#endif
BaseIter::valid(false);
return;
}
while(it_ != it_end_ && !BaseIter::mesh()->is_boundary(*it_)){
++it_;
}
BaseIter::valid(it_ != it_end_);
if(BaseIter::valid()) {
BaseIter::cur_handle(*it_);
}
}
// Post increment/decrement operator
BoundaryItemIter operator++(int) {
BoundaryItemIter cpy = *this;
++(*this);
return cpy;
}
BoundaryItemIter operator--(int) {
BoundaryItemIter cpy = *this;
--(*this);
return cpy;
}
BoundaryItemIter operator+(int _n) {
BoundaryItemIter cpy = *this;
for(int i = 0; i < _n; ++i) {
++cpy;
}
return cpy;
}
BoundaryItemIter operator-(int _n) {
BoundaryItemIter cpy = *this;
for(int i = 0; i < _n; ++i) {
--cpy;
}
return cpy;
}
BoundaryItemIter& operator+=(int _n) {
for(int i = 0; i < _n; ++i) {
++(*this);
}
return *this;
}
BoundaryItemIter& operator-=(int _n) {
for(int i = 0; i < _n; ++i) {
--(*this);
}
return *this;
}
BoundaryItemIter& operator--() {
--it_;
while(it_ >= it_begin_ && !BaseIter::mesh()->is_boundary(*it_)){
--it_;
}
if(it_ >= it_begin_) {
BaseIter::cur_handle(*it_);
} else {
BaseIter::valid(false);
}
return *this;
}
BoundaryItemIter& operator++() {
++it_;
while(it_ != it_end_ && !BaseIter::mesh()->is_boundary(*it_)){
++it_;
}
if(it_ != it_end_) {
BaseIter::cur_handle(*it_);
} else {
BaseIter::valid(false);
}
return *this;
}
private:
size_t n_items() const;
bool has_incidences() const;
private:
FaceIter bf_it_;
Iter it_;
const Iter it_begin_;
const Iter it_end_;
};
//===========================================================================
typedef BoundaryItemIter<VertexIter, VertexHandle> BoundaryVertexIter;
typedef BoundaryItemIter<HalfEdgeIter, HalfEdgeHandle> BoundaryHalfEdgeIter;
typedef BoundaryItemIter<EdgeIter, EdgeHandle> BoundaryEdgeIter;
typedef BoundaryItemIter<HalfFaceIter, HalfFaceHandle> BoundaryHalfFaceIter;
typedef BoundaryItemIter<FaceIter, FaceHandle> BoundaryFaceIter;
typedef BoundaryItemIter<CellIter, CellHandle> BoundaryCellIter;
//===========================================================================
} // Namespace OpenVolumeMesh
#endif /* ITERATORS_HH_ */
......@@ -93,7 +93,6 @@ public:
friend class CellCellIter;
friend class HalfFaceVertexIter;
friend class BoundaryHalfFaceHalfFaceIter;
friend class BoundaryFaceIter;
friend class VertexIter;
friend class EdgeIter;
friend class HalfEdgeIter;
......@@ -119,6 +118,15 @@ protected:
public:
VertexVertexIter vv_iter(const VertexHandle& _h, int _max_laps = 1) const {
return VertexVertexIter(_h, this, _max_laps);
}
std::pair<VertexVertexIter, VertexVertexIter> vertex_vertices(const VertexHandle& _h, int _max_laps = 1) const {
VertexVertexIter begin = vv_iter(_h, _max_laps);
return std::make_pair(begin, make_end_circulator(begin));
}
VertexOHalfEdgeIter voh_iter(const VertexHandle& _h, int _max_laps = 1) const {
return VertexOHalfEdgeIter(_h, this, _max_laps);
}
......@@ -128,21 +136,30 @@ public:
return std::make_pair(begin, make_end_circulator(begin));
}
VertexVertexIter vv_iter(const VertexHandle& _h, int _max_laps = 1) const {
return VertexVertexIter(_h, this, _max_laps);
VertexIHalfEdgeIter vih_iter(const VertexHandle& _h, int _max_laps = 1) const {
return VertexIHalfEdgeIter(_h, this, _max_laps);
}
std::pair<VertexVertexIter, VertexVertexIter> vertex_vertices(const VertexHandle& _h, int _max_laps = 1) const {
VertexVertexIter begin = vv_iter(_h, _max_laps);
std::pair<VertexIHalfEdgeIter, VertexIHalfEdgeIter> incoming_halfedges(const VertexHandle& _h, int _max_laps = 1) const {
VertexIHalfEdgeIter begin = vih_iter(_h, _max_laps);
return std::make_pair(begin, make_end_circulator(begin));
}
HalfEdgeHalfFaceIter hehf_iter(const HalfEdgeHandle& _h, int _max_laps = 1) const {
return HalfEdgeHalfFaceIter(_h, this, _max_laps);
VertexEdgeIter ve_iter(const VertexHandle& _h, int _max_laps = 1) const {
return VertexEdgeIter(_h, this, _max_laps);
}
std::pair<HalfEdgeHalfFaceIter, HalfEdgeHalfFaceIter> halfedge_halffaces(const HalfEdgeHandle& _h, int _max_laps = 1) const {
HalfEdgeHalfFaceIter begin = hehf_iter(_h, _max_laps);
std::pair<VertexEdgeIter, VertexEdgeIter> vertex_edges(const VertexHandle& _h, int _max_laps = 1) const {
VertexEdgeIter begin = ve_iter(_h, _max_laps);
return std::make_pair(begin, make_end_circulator(begin));
}
VertexHalfFaceIter vhf_iter(const VertexHandle& _h, int _max_laps = 1) const {
return VertexHalfFaceIter(_h, this, _max_laps);
}
std::pair<VertexHalfFaceIter, VertexHalfFaceIter> vertex_halffaces(const VertexHandle& _h, int _max_laps = 1) const {
VertexHalfFaceIter begin = vhf_iter(_h, _max_laps);
return std::make_pair(begin, make_end_circulator(begin));
}
......@@ -164,6 +181,24 @@ public:
return std::make_pair(begin, make_end_circulator(begin));
}
HalfEdgeHalfFaceIter hehf_iter(const HalfEdgeHandle& _h, int _max_laps = 1) const {
return HalfEdgeHalfFaceIter(_h, this, _max_laps);
}
std::pair<HalfEdgeHalfFaceIter, HalfEdgeHalfFaceIter> halfedge_halffaces(const HalfEdgeHandle& _h, int _max_laps = 1) const {
HalfEdgeHalfFaceIter begin = hehf_iter(_h, _max_laps);
return std::make_pair(begin, make_end_circulator(begin));
}
HalfEdgeFaceIter hef_iter(const HalfEdgeHandle& _h, int _max_laps = 1) const {
return HalfEdgeFaceIter(_h, this, _max_laps);
}
std::pair<HalfEdgeFaceIter, HalfEdgeFaceIter> halfedge_faces(const HalfEdgeHandle& _h, int _max_laps = 1) const {
HalfEdgeFaceIter begin = hef_iter(_h, _max_laps);
return std::make_pair(begin, make_end_circulator(begin));
}
HalfEdgeCellIter hec_iter(const HalfEdgeHandle& _h, int _max_laps = 1) const {
return HalfEdgeCellIter(_h, this, _max_laps);
}
......@@ -173,6 +208,78 @@ public:
return std::make_pair(begin, make_end_circulator(begin));
}
EdgeHalfFaceIter ehf_iter(const EdgeHandle& _h, int _max_laps = 1) const {
return EdgeHalfFaceIter(_h, this, _max_laps);
}
std::pair<EdgeHalfFaceIter, EdgeHalfFaceIter> edge_halffaces(const EdgeHandle& _h, int _max_laps = 1) const {
EdgeHalfFaceIter begin = ehf_iter(_h, _max_laps);
return std::make_pair(begin, make_end_circulator(begin));
}