Commit 0a41f024 authored by Mike Kremer's avatar Mike Kremer

Added HexVertexIter that iterates over all vertices of a hexahedron in a specific order.

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@178 66977474-1d4b-4f09-8fe9-267525286df2
parent 3b265cf0
......@@ -266,4 +266,90 @@ OutsideNeighborHalfFaceIter& OutsideNeighborHalfFaceIter::operator++() {
return *this;
}
//================================================================================================
// HexVertexIter
//================================================================================================
HexVertexIter::HexVertexIter(const CellHandle& _ref_h,
const HexahedralMeshTopologyKernel* _mesh) :
BaseIter(_mesh, _ref_h) {
assert(_ref_h.is_valid());
assert(_mesh->cell(_ref_h).halffaces().size() == 6);
// Get first half-face
HalfFaceHandle curHF = *_mesh->cell(_ref_h).halffaces().begin();
assert(curHF.is_valid());
// Get first half-edge
assert(_mesh->halfface(curHF).halfedges().size() == 4);
HalfEdgeHandle curHE = *_mesh->halfface(curHF).halfedges().begin();
assert(curHE.is_valid());
vertices_.push_back(_mesh->halfedge(curHE).from_vertex());
curHE = _mesh->prev_halfedge_in_halfface(curHE, curHF);
vertices_.push_back(_mesh->halfedge(curHE).from_vertex());
curHE = _mesh->prev_halfedge_in_halfface(curHE, curHF);
vertices_.push_back(_mesh->halfedge(curHE).from_vertex());
curHE = _mesh->prev_halfedge_in_halfface(curHE, curHF);
vertices_.push_back(_mesh->halfedge(curHE).from_vertex());
curHE = _mesh->prev_halfedge_in_halfface(curHE, curHF);
curHF = _mesh->adjacent_halfface_in_cell(curHF, curHE);
curHE = _mesh->opposite_halfedge_handle(curHE);
curHE = _mesh->next_halfedge_in_halfface(curHE, curHF);
curHE = _mesh->next_halfedge_in_halfface(curHE, curHF);
curHF = _mesh->adjacent_halfface_in_cell(curHF, curHE);
curHE = _mesh->opposite_halfedge_handle(curHE);
vertices_.push_back(_mesh->halfedge(curHE).to_vertex());
curHE = _mesh->prev_halfedge_in_halfface(curHE, curHF);
vertices_.push_back(_mesh->halfedge(curHE).to_vertex());
curHE = _mesh->prev_halfedge_in_halfface(curHE, curHF);
vertices_.push_back(_mesh->halfedge(curHE).to_vertex());
vertices_.push_back(_mesh->halfedge(curHE).from_vertex());
cur_it_ = vertices_.begin();
BaseIter::valid(cur_it_ != vertices_.end());
if(BaseIter::valid()) {
BaseIter::cur_handle(*cur_it_);
}
}
HexVertexIter& HexVertexIter::operator--() {
--cur_it_;
if(cur_it_ >= vertices_.begin()) {
BaseIter::cur_handle(*cur_it_);
} else {
BaseIter::valid(false);
}
return *this;
}
HexVertexIter& HexVertexIter::operator++() {
++cur_it_;
if(cur_it_ != vertices_.end()) {
BaseIter::cur_handle(*cur_it_);
} else {
BaseIter::valid(false);
}
return *this;
}
} // Namespace OpenVolumeMesh
......@@ -244,6 +244,81 @@ private:
std::vector<EdgeHandle>::const_iterator edge_it_;
};
/** \brief Iterate over all vertices of a hexahedron in a specific order
*
* Vertices are addressed in the following order:
*
* 5-------6
* /| /|
* / | / |
* 3-------2 |
* | 4----|--7
* | / | /
* |/ |/
* 0-------1
*/
class HexVertexIter : public BaseIterator<CellHandle,
VertexHandle> {
private:
typedef BaseIterator<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;
}
// Post increment/decrement operator
HexVertexIter operator++(int) {
HexVertexIter cpy = *this;
++(*this);
return cpy;
}
HexVertexIter operator--(int) {
HexVertexIter cpy = *this;
--(*this);
return cpy;
}
HexVertexIter operator+(int _n) {
HexVertexIter cpy = *this;
for(int i = 0; i < _n; ++i) {
++cpy;
}
return cpy;
}
HexVertexIter operator-(int _n) {
HexVertexIter cpy = *this;
for(int i = 0; i < _n; ++i) {
--cpy;
}
return cpy;
}
HexVertexIter& operator+=(int _n) {
for(int i = 0; i < _n; ++i) {
++(*this);
}
return *this;
}
HexVertexIter& operator-=(int _n) {
for(int i = 0; i < _n; ++i) {
--(*this);
}
return *this;
}
HexVertexIter& operator++();
HexVertexIter& operator--();
private:
std::vector<VertexHandle> vertices_;
std::vector<VertexHandle>::const_iterator cur_it_;
};
} // Namespace OpenVolumeMesh
#endif /* HEXAHEDRALMESHITERATORS_HH */
......@@ -138,10 +138,12 @@ public:
friend class CellSheetCellIter;
friend class HalfFaceSheetHalfFaceIter;
friend class OutsideNeighborHalfFaceIter;
friend class HexVertexIter;
typedef class CellSheetCellIter CellSheetCellIter;
typedef class HalfFaceSheetHalfFaceIter HalfFaceSheetHalfFaceIter;
typedef class OutsideNeighborHalfFaceIter OutsideNeighborHalfFaceIter;
typedef class HexVertexIter HexVertexIter;
CellSheetCellIter csc_iter(const CellHandle& _ref_h, const unsigned char _orthDir) const {
return CellSheetCellIter(_ref_h, _orthDir, this);
......@@ -155,6 +157,10 @@ public:
return OutsideNeighborHalfFaceIter(_ref_h, this);
}
HexVertexIter hv_iter(const CellHandle& _ref_h) const {
return HexVertexIter(_ref_h, this);
}
// ======================= Connectivity functions =============================
inline HalfFaceHandle opposite_halfface_handle_in_cell(const HalfFaceHandle& _hfh, const CellHandle& _ch) {
......
......@@ -4,5 +4,22 @@
#include <gtest/gtest.h>
#include <Unittests/unittests_common.hh>
TEST_F(HexahedralMeshBase, HexVertexIterTest) {
generateHexahedralMesh(mesh_);
HexVertexIter hv_it = mesh_.hv_iter(CellHandle(0));
EXPECT_TRUE(hv_it.valid());
EXPECT_EQ(VertexHandle(0), *hv_it); ++hv_it;
EXPECT_EQ(VertexHandle(1), *hv_it); ++hv_it;
EXPECT_EQ(VertexHandle(2), *hv_it); ++hv_it;
EXPECT_EQ(VertexHandle(3), *hv_it); ++hv_it;
EXPECT_EQ(VertexHandle(4), *hv_it); ++hv_it;
EXPECT_EQ(VertexHandle(7), *hv_it); ++hv_it;
EXPECT_EQ(VertexHandle(6), *hv_it); ++hv_it;
EXPECT_EQ(VertexHandle(5), *hv_it);
}
#endif // INCLUDE GUARD
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