Commit bf1fb456 authored by Mike Kremer's avatar Mike Kremer

Added functions to fetch half-edges and half-faces by their respective incident vertices.

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@175 66977474-1d4b-4f09-8fe9-267525286df2
parent ed047e6c
......@@ -1020,6 +1020,49 @@ const HalfEdgeHandle TopologyKernel::halfedge(const VertexHandle& _vh1, const Ve
//========================================================================================
const HalfFaceHandle TopologyKernel::halfface(const std::vector<VertexHandle>& _vs) const {
assert(_vs.size() > 2);
VertexHandle v0 = _vs[0], v1 = _vs[1], v2 = _vs[2];
assert(v0.is_valid() && v1.is_valid() && v2.is_valid());
HalfEdgeHandle he0 = halfedge(v0, v1);
if(!he0.is_valid()) return InvalidHalfFaceHandle;
HalfEdgeHandle he1 = halfedge(v1, v2);
if(!he1.is_valid()) return InvalidHalfFaceHandle;
std::vector<HalfEdgeHandle> hes;
hes.push_back(he0);
hes.push_back(he1);
return halfface(hes);
}
//========================================================================================
const HalfFaceHandle TopologyKernel::halfface(const std::vector<HalfEdgeHandle>& _hes) const {
assert(_hes.size() >= 2);
HalfEdgeHandle he0 = _hes[0], he1 = _hes[1];
assert(he0.is_valid() && he1.is_valid());
for(HalfEdgeHalfFaceIter hehf_it = hehf_iter(he0); hehf_it.valid(); ++hehf_it) {
std::vector<HalfEdgeHandle> hes = halfface(*hehf_it).halfedges();
if(std::find(hes.begin(), hes.end(), he1) != hes.end()) {
return *hehf_it;
}
}
return InvalidHalfFaceHandle;
}
//========================================================================================
const HalfEdgeHandle TopologyKernel::next_halfedge_in_halfface(const HalfEdgeHandle& _heh, const HalfFaceHandle& _hfh) const {
assert((unsigned int)_hfh < faces_.size() * 2u);
......
......@@ -270,6 +270,14 @@ public:
// Get halfedge from vertex _vh1 to _vh2
const HalfEdgeHandle halfedge(const VertexHandle& _vh1, const VertexHandle& _vh2) const;
// Get half-face from list of incident vertices (in connected order)
// Note: Only the first three vertices are checked
const HalfFaceHandle halfface(const std::vector<VertexHandle>& _vs) const;
// Get half-face from list of incident half-edges
// Note: Only the first two half-edges are checked
const HalfFaceHandle halfface(const std::vector<HalfEdgeHandle>& _hes) const;
/// Get next halfedge within a halfface
const HalfEdgeHandle next_halfedge_in_halfface(const HalfEdgeHandle& _heh, const HalfFaceHandle& _hfh) const;
......
......@@ -1027,4 +1027,114 @@ TEST_F(HexahedralMeshBase, GarbageCollectionTestProps2) {
EXPECT_EQ(1, fprops_i.count(1));
}
TEST_F(HexahedralMeshBase, HalfEdgeFetchFunction1) {
generateHexahedralMesh(mesh_);
VertexHandle v0(0);
VertexHandle v1(1);
VertexHandle v2(2);
VertexHandle v3(3);
VertexHandle v5(5);
VertexHandle v6(6);
VertexHandle v7(7);
HalfEdgeHandle he0 = mesh_.halfedge(v0, v1);
HalfEdgeHandle he5 = mesh_.halfedge(v3, v2);
HalfEdgeHandle he10 = mesh_.halfedge(v5, v6);
HalfEdgeHandle heInv = mesh_.halfedge(v5, v7);
EXPECT_EQ(HalfEdgeHandle(0), he0);
EXPECT_EQ(HalfEdgeHandle(5), he5);
EXPECT_EQ(HalfEdgeHandle(10), he10);
EXPECT_EQ(HexahedralMesh::InvalidHalfEdgeHandle, heInv);
}
TEST_F(HexahedralMeshBase, HalfFaceFetchFunction1) {
generateHexahedralMesh(mesh_);
HalfEdgeHandle he0(0);
HalfEdgeHandle he2(2);
HalfEdgeHandle he4(4);
std::vector<HalfEdgeHandle> hes;
hes.push_back(he0); hes.push_back(he2);
HalfFaceHandle hf0_0 = mesh_.halfface(hes);
hes.clear();
hes.push_back(he0); hes.push_back(he4);
HalfFaceHandle hf0_1 = mesh_.halfface(hes);
HalfEdgeHandle he16(16);
HalfEdgeHandle he18(18);
hes.clear();
hes.push_back(he16); hes.push_back(he18);
HalfFaceHandle hf4_0 = mesh_.halfface(hes);
hes.clear();
hes.push_back(he0); hes.push_back(he18);
HalfFaceHandle hfInv = mesh_.halfface(hes);
HalfEdgeHandle he17(17);
HalfEdgeHandle he19(19);
hes.clear();
hes.push_back(he17); hes.push_back(he19);
HalfFaceHandle hf5_0 = mesh_.halfface(hes);
EXPECT_EQ(HalfFaceHandle(0), hf0_0);
EXPECT_EQ(HalfFaceHandle(0), hf0_1);
EXPECT_EQ(HalfFaceHandle(4), hf4_0);
EXPECT_EQ(HalfFaceHandle(5), hf5_0);
EXPECT_EQ(HexahedralMesh::InvalidHalfFaceHandle, hfInv);
}
TEST_F(HexahedralMeshBase, HalfFaceFetchFunction2) {
generateHexahedralMesh(mesh_);
VertexHandle v0(0);
VertexHandle v1(1);
VertexHandle v2(2);
VertexHandle v3(3);
VertexHandle v4(4);
VertexHandle v5(5);
VertexHandle v6(6);
VertexHandle v7(7);
std::vector<VertexHandle> vs;
vs.push_back(v0); vs.push_back(v1); vs.push_back(v2);
HalfFaceHandle hf0 = mesh_.halfface(vs); vs.clear();
vs.push_back(v2); vs.push_back(v1); vs.push_back(v0);
HalfFaceHandle hf1 = mesh_.halfface(vs); vs.clear();
vs.push_back(v2); vs.push_back(v1); vs.push_back(v5);
HalfFaceHandle hf4 = mesh_.halfface(vs); vs.clear();
vs.push_back(v6); vs.push_back(v5); vs.push_back(v4);
HalfFaceHandle hf3 = mesh_.halfface(vs); vs.clear();
vs.push_back(v4); vs.push_back(v5); vs.push_back(v6);
HalfFaceHandle hf2 = mesh_.halfface(vs); vs.clear();
vs.push_back(v0); vs.push_back(v1); vs.push_back(v4);
HalfFaceHandle hfInv0 = mesh_.halfface(vs); vs.clear();
vs.push_back(v0); vs.push_back(v1); vs.push_back(v6);
HalfFaceHandle hfInv1 = mesh_.halfface(vs); vs.clear();
EXPECT_EQ(HalfFaceHandle(0), hf0);
EXPECT_EQ(HalfFaceHandle(1), hf1);
EXPECT_EQ(HalfFaceHandle(4), hf4);
EXPECT_EQ(HalfFaceHandle(3), hf3);
EXPECT_EQ(HalfFaceHandle(2), hf2);
EXPECT_EQ(HexahedralMesh::InvalidHalfFaceHandle, hfInv0);
EXPECT_EQ(HexahedralMesh::InvalidHalfFaceHandle, hfInv1);
}
#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