Commit 3cd0c981 authored by Alexander Dielen's avatar Alexander Dielen
Browse files

Added two new iterators and six convenience functions

- HalfEdgeFaceIter
- FaceVertexIter

- halfedge_vertices
- edge_halfedges
- face_halfedges
- face_cells
- from_vertex_handle
- to_vertex_handle
parent 0c18a4e8
Pipeline #6462 passed with stage
in 11 minutes and 48 seconds
......@@ -1061,6 +1061,55 @@ CellIter& CellIter::operator++() {
namespace Internal {
////================================================================================================
//// HalfEdgeFaceIterImpl
////================================================================================================
HalfEdgeFaceIterImpl::HalfEdgeFaceIterImpl(const HalfEdgeHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps) :
BaseIter(_mesh, _ref_h, _max_laps),
cur_index_(0)
{
for (HalfEdgeHalfFaceIter hehf_iter = _mesh->hehf_iter(_ref_h); hehf_iter.valid(); ++hehf_iter) {
faces_.push_back(_mesh->face_handle(*hehf_iter));
}
// Remove all duplicate entries
std::sort(faces_.begin(), faces_.end());
faces_.resize(std::unique(faces_.begin(), faces_.end()) - faces_.begin());
BaseIter::valid(faces_.size() > 0);
if (BaseIter::valid()) {
BaseIter::cur_handle(faces_[cur_index_]);
}
}
HalfEdgeFaceIterImpl& HalfEdgeFaceIterImpl::operator--() {
if (cur_index_ == 0) {
cur_index_ = faces_.size() - 1;
--lap_;
if (lap_ < 0)
BaseIter::valid(false);
}
else {
--cur_index_;
}
BaseIter::cur_handle(faces_[cur_index_]);
return *this;
}
HalfEdgeFaceIterImpl& HalfEdgeFaceIterImpl::operator++() {
++cur_index_;
if (cur_index_ >= faces_.size()) {
cur_index_ = 0;
++lap_;
if (lap_ >= max_laps_)
BaseIter::valid(false);
}
BaseIter::cur_handle(faces_[cur_index_]);
return *this;
}
////================================================================================================
//// HalfFaceHalfEdgeIterImpl
////================================================================================================
......@@ -1151,6 +1200,13 @@ HalfFaceEdgeIterImpl& HalfFaceEdgeIterImpl::operator++() {
return *this;
}
////================================================================================================
//// FaceVertexIterImpl
////================================================================================================
FaceVertexIterImpl::FaceVertexIterImpl(const FaceHandle& _ref_h, const TopologyKernel* _mesh, int _max_laps) :
HalfFaceVertexIter(_mesh->halfface_handle(_ref_h, 0), _mesh, _max_laps) {}
////================================================================================================
//// FaceHalfEdgeIterImpl
////================================================================================================
......
......@@ -1162,6 +1162,24 @@ namespace Internal {
//===========================================================================
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 HalfFaceHalfEdgeIterImpl : public BaseCirculator<HalfFaceHandle, HalfEdgeHandle> {
public:
......@@ -1196,6 +1214,16 @@ private:
//===========================================================================
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:
......@@ -1349,9 +1377,12 @@ public:
//===========================================================================
typedef GenericCirculator<Internal::HalfEdgeFaceIterImpl> HalfEdgeFaceIter;
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;
......
......@@ -137,15 +137,6 @@ 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));
}
VertexFaceIter vf_iter(const VertexHandle& _h, int _max_laps = 1) const {
return VertexFaceIter(_h, this, _max_laps);
}
......@@ -164,6 +155,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);
}
......@@ -191,6 +200,15 @@ public:
return std::make_pair(begin, make_end_circulator(begin));
}
FaceVertexIter fv_iter(const FaceHandle& _h, int _max_laps = 1) const {
return FaceVertexIter(_h, this, _max_laps);
}
std::pair<FaceVertexIter, FaceVertexIter> face_vertices(const FaceHandle& _h, int _max_laps = 1) const {
FaceVertexIter begin = fv_iter(_h, _max_laps);
return std::make_pair(begin, make_end_circulator(begin));
}
FaceHalfEdgeIter fhe_iter(const FaceHandle& _h, int _max_laps = 1) const {
return FaceHalfEdgeIter(_h, this, _max_laps);
}
......@@ -405,6 +423,38 @@ public:
return std::make_pair(cells_begin(), cells_end());
}
/*
* Convenience functions
*/
std::vector<VertexHandle> halfedge_vertices(const HalfEdgeHandle& _h) const {
std::vector<VertexHandle> res(2);
res[0] = from_vertex_handle(_h);
res[1] = to_vertex_handle(_h);
return res;
}
std::vector<HalfEdgeHandle> edge_halfedges(const EdgeHandle& _h) const {
std::vector<HalfEdgeHandle> res(2);
res[0] = halfedge_handle(_h, 0);
res[1] = halfedge_handle(_h, 1);
return res;
}
std::vector<HalfFaceHandle> face_halffaces(const FaceHandle& _h) const {
std::vector<HalfFaceHandle> res(2);
res[0] = halfface_handle(_h, 0);
res[1] = halfface_handle(_h, 1);
return res;
}
std::vector<CellHandle> face_cells(const FaceHandle& _h) const {
std::vector<CellHandle> res(2);
res[0] = incident_cell(halfface_handle(_h, 0));
res[1] = incident_cell(halfface_handle(_h, 1));
return res;
}
/*
* Virtual functions with implementation
*/
......@@ -539,6 +589,16 @@ public:
/// Get previous halfedge within a halfface
HalfEdgeHandle prev_halfedge_in_halfface(const HalfEdgeHandle& _heh, const HalfFaceHandle& _hfh) const;
/// Get the vertex the halfedge starts from
VertexHandle from_vertex_handle(const HalfEdgeHandle& _h) const {
return halfedge(_h).from_vertex();
}
/// Get the vertex the halfedge points to
VertexHandle to_vertex_handle(const HalfEdgeHandle& _h) const {
return halfedge(_h).to_vertex();
}
/// Get valence of vertex (number of incident edges)
inline size_t valence(const VertexHandle& _vh) const {
assert(has_vertex_bottom_up_incidences());
......
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