adding cw and ccw circulators
closes #2406 git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@1227 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
@@ -226,4 +226,144 @@ TEST_F(OpenMeshTrimeshCirculatorHalfedgeLoop, HalfedgeLoopWithoutFace) {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Test CW and CCW iterators
|
||||
*/
|
||||
TEST_F(OpenMeshTrimeshCirculatorHalfedgeLoop, CWAndCCWCheck) {
|
||||
|
||||
mesh_.clear();
|
||||
|
||||
// Add some vertices
|
||||
Mesh::VertexHandle vhandle[6];
|
||||
|
||||
vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
|
||||
vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
|
||||
vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
|
||||
vhandle[3] = mesh_.add_vertex(Mesh::Point(3, 0, 0));
|
||||
vhandle[4] = mesh_.add_vertex(Mesh::Point(4, 1, 0));
|
||||
vhandle[5] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
|
||||
|
||||
// Add three faces
|
||||
std::vector<Mesh::VertexHandle> face_vhandles;
|
||||
|
||||
face_vhandles.push_back(vhandle[0]);
|
||||
face_vhandles.push_back(vhandle[1]);
|
||||
face_vhandles.push_back(vhandle[2]);
|
||||
mesh_.add_face(face_vhandles);
|
||||
|
||||
face_vhandles.clear();
|
||||
|
||||
face_vhandles.push_back(vhandle[2]);
|
||||
face_vhandles.push_back(vhandle[1]);
|
||||
face_vhandles.push_back(vhandle[3]);
|
||||
mesh_.add_face(face_vhandles);
|
||||
|
||||
face_vhandles.clear();
|
||||
|
||||
face_vhandles.push_back(vhandle[2]);
|
||||
face_vhandles.push_back(vhandle[3]);
|
||||
face_vhandles.push_back(vhandle[4]);
|
||||
mesh_.add_face(face_vhandles);
|
||||
|
||||
face_vhandles.clear();
|
||||
|
||||
face_vhandles.push_back(vhandle[1]);
|
||||
face_vhandles.push_back(vhandle[5]);
|
||||
face_vhandles.push_back(vhandle[3]);
|
||||
mesh_.add_face(face_vhandles);
|
||||
|
||||
/* Test setup:
|
||||
*
|
||||
* 0 ------ 2 ------ 4
|
||||
* \ / \ /
|
||||
* \ 0 / \ 2 /
|
||||
* \ / 1 \ /
|
||||
* 1 ------- 3
|
||||
* \ /
|
||||
* \ 3 /
|
||||
* \ /
|
||||
* \ /
|
||||
* 5
|
||||
*/
|
||||
|
||||
|
||||
int indices[4] = {3, 8, 6, 3};
|
||||
int rev_indices[4];
|
||||
std::reverse_copy(indices,indices+4,rev_indices);
|
||||
|
||||
//CCW
|
||||
Mesh::HalfedgeLoopCCWIter hl_ccwit = mesh_.hl_ccwbegin(mesh_.halfedge_handle(3));
|
||||
Mesh::HalfedgeLoopCCWIter hl_ccwend = mesh_.hl_ccwend(mesh_.halfedge_handle(3));
|
||||
size_t i = 0;
|
||||
for (;hl_ccwit != hl_ccwend; ++hl_ccwit, ++i)
|
||||
{
|
||||
EXPECT_EQ(indices[i], hl_ccwit->idx()) << "Index wrong in HalfedgeLoopCCWIter";
|
||||
}
|
||||
|
||||
EXPECT_FALSE(hl_ccwit.is_valid()) << "Iterator invalid in HalfedgeLoopCCWIter at end";
|
||||
EXPECT_TRUE( hl_ccwit == hl_ccwend ) << "End iterator for HalfedgeLoopCCWIter not matching";
|
||||
|
||||
//constant CCW
|
||||
Mesh::ConstHalfedgeLoopCCWIter chl_ccwit = mesh_.chl_ccwbegin(mesh_.halfedge_handle(3));
|
||||
Mesh::ConstHalfedgeLoopCCWIter chl_ccwend = mesh_.chl_ccwend(mesh_.halfedge_handle(3));
|
||||
i = 0;
|
||||
for (;chl_ccwit != chl_ccwend; ++chl_ccwit, ++i)
|
||||
{
|
||||
EXPECT_EQ(indices[i], chl_ccwit->idx()) << "Index wrong in ConstHalfedgeLoopCCWIter";
|
||||
}
|
||||
|
||||
EXPECT_FALSE(chl_ccwit.is_valid()) << "Iterator invalid in ConstHalfedgeLoopCCWIter at end";
|
||||
EXPECT_TRUE( chl_ccwit == chl_ccwend ) << "End iterator for ConstHalfedgeLoopCCWIter not matching";
|
||||
|
||||
//CW
|
||||
Mesh::HalfedgeLoopCWIter hl_cwit = mesh_.hl_cwbegin(mesh_.halfedge_handle(3));
|
||||
Mesh::HalfedgeLoopCWIter hl_cwend = mesh_.hl_cwend(mesh_.halfedge_handle(3));
|
||||
i = 0;
|
||||
for (;hl_cwit != hl_cwend; ++hl_cwit, ++i)
|
||||
{
|
||||
EXPECT_EQ(rev_indices[i], hl_cwit->idx()) << "Index wrong in HalfedgeLoopCWIter";
|
||||
}
|
||||
EXPECT_FALSE(hl_cwit.is_valid()) << "Iterator invalid in HalfedgeLoopCWIter at end";
|
||||
EXPECT_TRUE( hl_cwit == hl_cwend ) << "End iterator for HalfedgeLoopCWIter not matching";
|
||||
|
||||
//constant CW
|
||||
Mesh::ConstHalfedgeLoopCWIter chl_cwit = mesh_.chl_cwbegin(mesh_.halfedge_handle(3));
|
||||
Mesh::ConstHalfedgeLoopCWIter chl_cwend = mesh_.chl_cwend(mesh_.halfedge_handle(3));
|
||||
i = 0;
|
||||
for (;chl_cwit != chl_cwend; ++chl_cwit, ++i)
|
||||
{
|
||||
EXPECT_EQ(rev_indices[i], chl_cwit->idx()) << "Index wrong in ConstHalfedgeLoopCWIter";
|
||||
}
|
||||
EXPECT_FALSE(chl_cwit.is_valid()) << "Iterator invalid in ConstHalfedgeLoopCWIter at end";
|
||||
EXPECT_TRUE( chl_cwit == chl_cwend ) << "End iterator for ConstHalfedgeLoopCWIter not matching";
|
||||
|
||||
/*
|
||||
* conversion properties:
|
||||
* a) cw_begin == CWIter(ccw_begin())
|
||||
* b) cw_iter->idx() == CCWIter(cw_iter)->idx() for valid iterators
|
||||
* c) --cw_iter == CWIter(++ccwIter) for valid iterators
|
||||
* d) cw_end == CWIter(ccw_end()) => --cw_end != CWIter(++ccw_end()) *
|
||||
*/
|
||||
Mesh::HalfedgeLoopCWIter hl_cwIter = mesh_.hl_cwbegin(mesh_.halfedge_handle(3));
|
||||
// a)
|
||||
EXPECT_TRUE( hl_cwIter == Mesh::HalfedgeLoopCWIter(mesh_.hl_ccwbegin(mesh_.halfedge_handle(3))) ) << "ccw to cw conversion failed";
|
||||
EXPECT_TRUE( Mesh::HalfedgeLoopCCWIter(hl_cwIter) == mesh_.hl_ccwbegin(mesh_.halfedge_handle(3)) ) << "cw to ccw conversion failed";
|
||||
// b)
|
||||
EXPECT_EQ( hl_cwIter->idx(), Mesh::HalfedgeLoopCCWIter(hl_cwIter)->idx()) << "iterators doesnt point on the same element";
|
||||
// c)
|
||||
++hl_cwIter;
|
||||
hl_ccwend = mesh_.hl_ccwend(mesh_.halfedge_handle(3));
|
||||
--hl_ccwend;
|
||||
EXPECT_EQ(hl_cwIter->idx(),hl_ccwend->idx()) << "iteratoes are not equal after inc/dec";
|
||||
// additional conversion check
|
||||
hl_ccwend = Mesh::HalfedgeLoopCCWIter(hl_cwIter);
|
||||
EXPECT_EQ(hl_cwIter->idx(),hl_ccwend->idx())<< "iterators doesnt point on the same element";
|
||||
// d)
|
||||
hl_cwIter = Mesh::HalfedgeLoopCWIter(mesh_.hl_ccwend(mesh_.halfedge_handle(3)));
|
||||
EXPECT_FALSE(hl_cwIter.is_valid()) << "end iterator is not invalid";
|
||||
EXPECT_TRUE(Mesh::HalfedgeLoopCCWIter(mesh_.hl_cwend(mesh_.halfedge_handle(3))) == mesh_.hl_ccwend(mesh_.halfedge_handle(3))) << "end iterators are not equal";
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user