Commit 60dc9da4 authored by Max Lyon's avatar Max Lyon

Updated OVM Iterators:

    Circulators will now circulate as often as desired
    added functions in topology kernel to receive pair of begin and end iterator

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@261 66977474-1d4b-4f09-8fe9-267525286df2
parent 4eccc31d
This diff is collapsed.
This diff is collapsed.
......@@ -100,38 +100,100 @@ public:
friend class HalfFaceIter;
friend class CellIter;
VertexOHalfEdgeIter voh_iter(const VertexHandle& _h) const {
return VertexOHalfEdgeIter(_h, this);
/*
* Circulators
*/
protected:
template <class Circulator>
static Circulator make_end_circulator(const Circulator& _circ)
{
Circulator end = _circ;
if (end.valid()) {
end.lap(_circ.max_laps());
end.valid(false);
}
return end;
}
public:
VertexOHalfEdgeIter voh_iter(const VertexHandle& _h, int _max_laps = 1) const {
return VertexOHalfEdgeIter(_h, this, _max_laps);
}
std::pair<VertexOHalfEdgeIter, VertexOHalfEdgeIter> outgoing_halfedges(const VertexHandle& _h, int _max_laps = 1) const {
VertexOHalfEdgeIter begin = voh_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);
}
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));
}
VertexCellIter vc_iter(const VertexHandle& _h, int _max_laps = 1) const {
return VertexCellIter(_h, this, _max_laps);
}
std::pair<VertexCellIter, VertexCellIter> vertex_cells(const VertexHandle& _h, int _max_laps = 1){
VertexCellIter begin = vc_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);
}
std::pair<HalfEdgeCellIter, HalfEdgeCellIter> halfedge_cells(const HalfEdgeHandle& _h, int _max_laps = 1){
HalfEdgeCellIter begin = hec_iter(_h, _max_laps);
return std::make_pair(begin, make_end_circulator(begin));
}
CellVertexIter cv_iter(const CellHandle& _h, int _max_laps = 1) const {
return CellVertexIter(_h, this, _max_laps);
}
HalfEdgeHalfFaceIter hehf_iter(const HalfEdgeHandle& _h) const {
return HalfEdgeHalfFaceIter(_h, this);
std::pair<CellVertexIter, CellVertexIter> cell_vertices(const CellHandle& _h, int _max_laps = 1) const {
CellVertexIter begin = cv_iter(_h, _max_laps);
return std::make_pair(begin, make_end_circulator(begin));
}
VertexCellIter vc_iter(const VertexHandle& _h) const {
return VertexCellIter(_h, this);
CellCellIter cc_iter(const CellHandle& _h, int _max_laps = 1) const {
return CellCellIter(_h, this, _max_laps);
}
HalfEdgeCellIter hec_iter(const HalfEdgeHandle& _h) const {
return HalfEdgeCellIter(_h, this);
std::pair<CellCellIter, CellCellIter> cell_cells(const CellHandle& _h, int _max_laps = 1) const {
CellCellIter begin = cc_iter(_h, _max_laps);
return std::make_pair(begin, make_end_circulator(begin));
}
CellVertexIter cv_iter(const CellHandle& _h) const {
return CellVertexIter(_h, this);
HalfFaceVertexIter hfv_iter(const HalfFaceHandle& _h, int _max_laps = 1) const {
return HalfFaceVertexIter(_h, this, _max_laps);
}
CellCellIter cc_iter(const CellHandle& _h) const {
return CellCellIter(_h, this);
std::pair<HalfFaceVertexIter, HalfFaceVertexIter> halfface_vertices(const HalfFaceHandle& _h, int _max_laps = 1) const {
HalfFaceVertexIter begin = hfv_iter(_h, _max_laps);
return std::make_pair(begin, make_end_circulator(begin));
}
HalfFaceVertexIter hfv_iter(const HalfFaceHandle& _h) const {
return HalfFaceVertexIter(_h, this);
BoundaryHalfFaceHalfFaceIter bhfhf_iter(const HalfFaceHandle& _ref_h, int _max_laps = 1) const {
return BoundaryHalfFaceHalfFaceIter(_ref_h, this, _max_laps);
}
BoundaryHalfFaceHalfFaceIter bhfhf_iter(const HalfFaceHandle& _ref_h) const {
return BoundaryHalfFaceHalfFaceIter(_ref_h, this);
std::pair<BoundaryHalfFaceHalfFaceIter, BoundaryHalfFaceHalfFaceIter> boundary_halfface_halffaces(const HalfFaceHandle& _h, int _max_laps = 1) const {
BoundaryHalfFaceHalfFaceIter begin = bhfhf_iter(_h, _max_laps);
return std::make_pair(begin, make_end_circulator(begin));
}
/*
* Iterators
*/
BoundaryFaceIter bf_iter() const {
return BoundaryFaceIter(this);
}
......@@ -148,6 +210,10 @@ public:
return VertexIter(this, VertexHandle(n_vertices()));
}
std::pair<VertexIter, VertexIter> vertices() const {
return std::make_pair(vertices_begin(), vertices_end());
}
EdgeIter e_iter() const {
return EdgeIter(this);
}
......@@ -160,6 +226,10 @@ public:
return EdgeIter(this, EdgeHandle(edges_.size()));
}
std::pair<EdgeIter, EdgeIter> edges() const {
return std::make_pair(edges_begin(), edges_end());
}
HalfEdgeIter he_iter() const {
return HalfEdgeIter(this);
}
......@@ -172,6 +242,10 @@ public:
return HalfEdgeIter(this, HalfEdgeHandle(edges_.size() * 2));
}
std::pair<HalfEdgeIter, HalfEdgeIter> halfedges() const {
return std::make_pair(halfedges_begin(), halfedges_end());
}
FaceIter f_iter() const {
return FaceIter(this);
}
......@@ -184,6 +258,10 @@ public:
return FaceIter(this, FaceHandle(faces_.size()));
}
std::pair<FaceIter, FaceIter> faces() const {
return std::make_pair(faces_begin(), faces_end());
}
HalfFaceIter hf_iter() const {
return HalfFaceIter(this);
}
......@@ -196,6 +274,10 @@ public:
return HalfFaceIter(this, HalfFaceHandle(faces_.size() * 2));
}
std::pair<HalfFaceIter, HalfFaceIter> halffaces() const {
return std::make_pair(halffaces_begin(), halffaces_end());
}
CellIter c_iter() const {
return CellIter(this);
}
......@@ -208,6 +290,10 @@ public:
return CellIter(this, CellHandle(cells_.size()));
}
std::pair<CellIter, CellIter> cells() const {
return std::make_pair(cells_begin(), cells_end());
}
/*
* Virtual functions with implementation
*/
......
......@@ -54,8 +54,8 @@ namespace OpenVolumeMesh {
CellSheetCellIter::CellSheetCellIter(const CellHandle& _ref_h,
const unsigned char _orthDir, const HexahedralMeshTopologyKernel* _mesh) :
BaseIter(_mesh, _ref_h) {
const unsigned char _orthDir, const HexahedralMeshTopologyKernel* _mesh, int _max_laps) :
BaseIter(_mesh, _ref_h, _max_laps) {
if(!_mesh->has_face_bottom_up_incidences()) {
#ifndef NDEBUG
......@@ -74,40 +74,53 @@ BaseIter(_mesh, _ref_h) {
_mesh->orientation(*hf_it, _ref_h) != _mesh->opposite_orientation(_orthDir)) {
CellHandle ch = _mesh->incident_cell(_mesh->opposite_halfface_handle(*hf_it));
if(ch != TopologyKernel::InvalidCellHandle) {
neighb_sheet_cell_hs_.insert(ch);
neighb_sheet_cell_hs_.push_back(ch);
}
}
}
cur_it_ = neighb_sheet_cell_hs_.begin();
BaseIter::valid(cur_it_ != neighb_sheet_cell_hs_.end());
// Remove all duplicate entries
std::sort(neighb_sheet_cell_hs_.begin(), neighb_sheet_cell_hs_.end());
neighb_sheet_cell_hs_.resize(std::unique(neighb_sheet_cell_hs_.begin(), neighb_sheet_cell_hs_.end()) - neighb_sheet_cell_hs_.begin());
cur_index_ = 0;
BaseIter::valid(neighb_sheet_cell_hs_.size() > 0);
if(BaseIter::valid()) {
BaseIter::cur_handle(*cur_it_);
BaseIter::cur_handle(neighb_sheet_cell_hs_[cur_index_]);
}
}
CellSheetCellIter& CellSheetCellIter::operator--() {
if(cur_it_ == neighb_sheet_cell_hs_.begin()) {
BaseIter::valid(false);
if (cur_index_ == 0) {
cur_index_ = neighb_sheet_cell_hs_.size() - 1;
--lap_;
if (lap_ < 0)
BaseIter::valid(false);
} else {
--cur_it_;
BaseIter::cur_handle(*cur_it_);
--cur_index_;
}
BaseIter::cur_handle(neighb_sheet_cell_hs_[cur_index_]);
return *this;
}
CellSheetCellIter& CellSheetCellIter::operator++() {
++cur_it_;
if(cur_it_ != neighb_sheet_cell_hs_.end()) {
BaseIter::cur_handle(*cur_it_);
} else {
BaseIter::valid(false);
++cur_index_;
if(cur_index_ == neighb_sheet_cell_hs_.size()) {
cur_index_ = 0;
++lap_;
if (lap_ >= max_laps_)
BaseIter::valid(false);
}
return *this;
BaseIter::cur_handle(neighb_sheet_cell_hs_[cur_index_]);
return *this;
}
//================================================================================================
......@@ -116,8 +129,8 @@ CellSheetCellIter& CellSheetCellIter::operator++() {
HalfFaceSheetHalfFaceIter::HalfFaceSheetHalfFaceIter(const HalfFaceHandle& _ref_h,
const HexahedralMeshTopologyKernel* _mesh) :
BaseIter(_mesh, _ref_h) {
const HexahedralMeshTopologyKernel* _mesh, int _max_laps) :
BaseIter(_mesh, _ref_h, _max_laps) {
if(!_mesh->has_face_bottom_up_incidences()) {
#ifndef NDEBUG
......@@ -173,38 +186,44 @@ BaseIter(_mesh, _ref_h) {
}
}
cur_it_ = adjacent_halffaces_.begin();
edge_it_ = common_edges_.begin();
BaseIter::valid(cur_it_ != adjacent_halffaces_.end());
cur_index_ = 0;
BaseIter::valid(adjacent_halffaces_.size() > 0);
if(BaseIter::valid()) {
BaseIter::cur_handle(*cur_it_);
BaseIter::cur_handle(adjacent_halffaces_[cur_index_]);
}
}
HalfFaceSheetHalfFaceIter& HalfFaceSheetHalfFaceIter::operator--() {
--cur_it_;
--edge_it_;
if(cur_it_ >= adjacent_halffaces_.begin()) {
BaseIter::cur_handle(*cur_it_);
} else {
BaseIter::valid(false);
}
if (cur_index_ == 0) {
cur_index_ = adjacent_halffaces_.size() - 1;
--lap_;
if (lap_ < 0)
BaseIter::valid(false);
} else {
--cur_index_;
}
BaseIter::cur_handle(adjacent_halffaces_[cur_index_]);
return *this;
}
HalfFaceSheetHalfFaceIter& HalfFaceSheetHalfFaceIter::operator++() {
++cur_it_;
++edge_it_;
if(cur_it_ != adjacent_halffaces_.end()) {
BaseIter::cur_handle(*cur_it_);
} else {
BaseIter::valid(false);
}
return *this;
++cur_index_;
if(cur_index_ == adjacent_halffaces_.size()) {
cur_index_ = 0;
++lap_;
if (lap_ >= max_laps_)
BaseIter::valid(false);
}
BaseIter::cur_handle(adjacent_halffaces_[cur_index_]);
return *this;
}
//================================================================================================
......@@ -213,8 +232,8 @@ HalfFaceSheetHalfFaceIter& HalfFaceSheetHalfFaceIter::operator++() {
HexVertexIter::HexVertexIter(const CellHandle& _ref_h,
const HexahedralMeshTopologyKernel* _mesh) :
BaseIter(_mesh, _ref_h) {
const HexahedralMeshTopologyKernel* _mesh, int _max_laps) :
BaseIter(_mesh, _ref_h, _max_laps) {
assert(_ref_h.is_valid());
assert(_mesh->cell(_ref_h).halffaces().size() == 6);
......@@ -262,34 +281,43 @@ BaseIter(_mesh, _ref_h) {
vertices_.push_back(_mesh->halfedge(curHE).from_vertex());
cur_it_ = vertices_.begin();
BaseIter::valid(cur_it_ != vertices_.end());
cur_index_ = 0;
BaseIter::valid(vertices_.size() > 0);
if(BaseIter::valid()) {
BaseIter::cur_handle(*cur_it_);
BaseIter::cur_handle(vertices_[cur_index_]);
}
}
HexVertexIter& HexVertexIter::operator--() {
--cur_it_;
if(cur_it_ >= vertices_.begin()) {
BaseIter::cur_handle(*cur_it_);
if (cur_index_ == 0) {
cur_index_ = vertices_.size() - 1;
--lap_;
if (lap_ < 0)
BaseIter::valid(false);
} else {
BaseIter::valid(false);
--cur_index_;
}
BaseIter::cur_handle(vertices_[cur_index_]);
return *this;
}
HexVertexIter& HexVertexIter::operator++() {
++cur_it_;
if(cur_it_ != vertices_.end()) {
BaseIter::cur_handle(*cur_it_);
} else {
BaseIter::valid(false);
++cur_index_;
if(cur_index_ == vertices_.size()) {
cur_index_ = 0;
++lap_;
if (lap_ >= max_laps_)
BaseIter::valid(false);
}
BaseIter::cur_handle(vertices_[cur_index_]);
return *this;
}
......
......@@ -50,21 +50,12 @@ namespace OpenVolumeMesh {
class HexahedralMeshTopologyKernel;
class CellSheetCellIter : public BaseIterator<CellHandle,
CellHandle> {
class CellSheetCellIter : public BaseCirculator<CellHandle, CellHandle> {
private:
typedef BaseIterator<CellHandle,
CellHandle> BaseIter;
typedef BaseCirculator<CellHandle, CellHandle> BaseIter;
public:
CellSheetCellIter(const CellHandle& _ref_h, const unsigned char _orthDir,
const HexahedralMeshTopologyKernel* _mesh);
CellSheetCellIter& operator=(const CellSheetCellIter& _c) {
BaseIter::operator=(_c);
neighb_sheet_cell_hs_ = _c.neighb_sheet_cell_hs_;
cur_it_ = neighb_sheet_cell_hs_.begin();
return *this;
}
const HexahedralMeshTopologyKernel* _mesh, int _max_laps = 1);
// Post increment/decrement operator
CellSheetCellIter operator++(int) {
......@@ -108,25 +99,17 @@ public:
CellSheetCellIter& operator--();
private:
std::set<CellHandle> neighb_sheet_cell_hs_;
std::set<CellHandle>::const_iterator cur_it_;
std::vector<CellHandle> neighb_sheet_cell_hs_;
size_t cur_index_;
};
class HalfFaceSheetHalfFaceIter : public BaseIterator<HalfFaceHandle,
HalfFaceHandle> {
class HalfFaceSheetHalfFaceIter : public BaseCirculator<HalfFaceHandle,HalfFaceHandle> {
private:
typedef BaseIterator<HalfFaceHandle,
HalfFaceHandle> BaseIter;
typedef BaseCirculator<HalfFaceHandle, HalfFaceHandle> BaseIter;
public:
HalfFaceSheetHalfFaceIter(const HalfFaceHandle& _ref_h,
const HexahedralMeshTopologyKernel* _mesh);
HalfFaceSheetHalfFaceIter& operator=(const HalfFaceSheetHalfFaceIter& _c) {
BaseIter::operator=(_c);
adjacent_halffaces_ = _c.adjacent_halffaces_;
cur_it_ = adjacent_halffaces_.begin();
return *this;
}
const HexahedralMeshTopologyKernel* _mesh, int _max_laps = 1);
// Post increment/decrement operator
HalfFaceSheetHalfFaceIter operator++(int) {
......@@ -169,13 +152,12 @@ public:
HalfFaceSheetHalfFaceIter& operator++();
HalfFaceSheetHalfFaceIter& operator--();
const EdgeHandle& common_edge() const { return *edge_it_; }
const EdgeHandle& common_edge() const { return common_edges_[cur_index_]; }
private:
std::vector<HalfFaceHandle> adjacent_halffaces_;
std::vector<HalfFaceHandle>::const_iterator cur_it_;
std::vector<EdgeHandle> common_edges_;
std::vector<EdgeHandle>::const_iterator edge_it_;
std::vector<EdgeHandle> common_edges_;
size_t cur_index_;
};
/** \brief Iterate over all vertices of a hexahedron in a specific order
......@@ -192,20 +174,15 @@ private:
* 0-------1
*/
class HexVertexIter : public BaseIterator<CellHandle,
class HexVertexIter : public BaseCirculator<CellHandle,
VertexHandle> {
private:
typedef BaseIterator<CellHandle,
typedef BaseCirculator<CellHandle,
VertexHandle> BaseIter;
public:
HexVertexIter(const CellHandle& _ref_h,
const HexahedralMeshTopologyKernel* _mesh);
HexVertexIter& operator=(const HexVertexIter& _c) {
BaseIter::operator=(_c);
vertices_ = _c.vertices_;
cur_it_ = vertices_.begin();
return *this;
}
const HexahedralMeshTopologyKernel* _mesh,
int _max_laps = 1);
// Post increment/decrement operator
HexVertexIter operator++(int) {
......@@ -250,7 +227,7 @@ public:
private:
std::vector<VertexHandle> vertices_;
std::vector<VertexHandle>::const_iterator cur_it_;
size_t cur_index_;
};
} // Namespace OpenVolumeMesh
......
......@@ -152,16 +152,34 @@ public:
typedef class HalfFaceSheetHalfFaceIter HalfFaceSheetHalfFaceIter;
typedef class HexVertexIter HexVertexIter;
CellSheetCellIter csc_iter(const CellHandle& _ref_h, const unsigned char _orthDir) const {
return CellSheetCellIter(_ref_h, _orthDir, this);
CellSheetCellIter csc_iter(const CellHandle& _ref_h, const unsigned char _orthDir, int _max_laps = 1) const {
return CellSheetCellIter(_ref_h, _orthDir, this, _max_laps);
}
HalfFaceSheetHalfFaceIter hfshf_iter(const HalfFaceHandle& _ref_h) const {
return HalfFaceSheetHalfFaceIter(_ref_h, this);
std::pair<CellSheetCellIter,CellSheetCellIter> cell_sheet_cells(const CellHandle& _ref_h, const unsigned char _orthDir, int _max_laps = 1) const {
CellSheetCellIter begin = csc_iter(_ref_h, _orthDir, _max_laps);
CellSheetCellIter end = make_end_circulator(begin);
return std::make_pair(begin, end);
}
HexVertexIter hv_iter(const CellHandle& _ref_h) const {
return HexVertexIter(_ref_h, this);
HalfFaceSheetHalfFaceIter hfshf_iter(const HalfFaceHandle& _ref_h, int _max_laps = 1) const {
return HalfFaceSheetHalfFaceIter(_ref_h, this, _max_laps);
}
std::pair<HalfFaceSheetHalfFaceIter,HalfFaceSheetHalfFaceIter> halfface_sheet_halffaces(const HalfFaceHandle& _ref_h, int _max_laps = 1) const {
HalfFaceSheetHalfFaceIter begin = hfshf_iter(_ref_h, _max_laps);
HalfFaceSheetHalfFaceIter end = make_end_circulator(begin);
return std::make_pair(begin, end);
}
HexVertexIter hv_iter(const CellHandle& _ref_h, int _max_laps = 1) const {
return HexVertexIter(_ref_h, this, _max_laps);
}
std::pair<HexVertexIter,HexVertexIter> hex_vertices(const CellHandle& _ref_h, int _max_laps = 1) const {
HexVertexIter begin = hv_iter(_ref_h, _max_laps);
HexVertexIter end = make_end_circulator(begin);
return std::make_pair(begin, end);
}
// ======================= Connectivity functions =============================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment