2013-01-11 14:48:48 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
#include <Unittests/unittests_common.hh>
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
2013-09-20 14:21:08 +00:00
|
|
|
namespace {
|
|
|
|
|
|
2013-01-11 14:48:48 +00:00
|
|
|
class OpenMeshTrimeshCirculatorVertexVertex : public OpenMeshBase {
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
// This function is called before each test is run
|
|
|
|
|
virtual void SetUp() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This function is called after all tests are through
|
|
|
|
|
virtual void TearDown() {
|
|
|
|
|
|
|
|
|
|
// Do some final stuff with the member data here...
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Member already defined in OpenMeshBase
|
|
|
|
|
//Mesh mesh_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* ====================================================================
|
|
|
|
|
* Define tests below
|
|
|
|
|
* ====================================================================
|
|
|
|
|
*/
|
|
|
|
|
|
2013-01-11 15:46:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Small VertexFaceOutgoingHalfedgeIterator Test without holes in it
|
|
|
|
|
*/
|
|
|
|
|
TEST_F(OpenMeshTrimeshCirculatorVertexVertex, VertexVertexIncrement) {
|
|
|
|
|
|
|
|
|
|
mesh_.clear();
|
|
|
|
|
|
|
|
|
|
// Add some vertices
|
|
|
|
|
Mesh::VertexHandle vhandle[5];
|
|
|
|
|
|
|
|
|
|
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(0,-1, 0));
|
|
|
|
|
vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
|
|
|
|
|
|
|
|
|
|
// Add two 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[1]);
|
|
|
|
|
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[0]);
|
|
|
|
|
face_vhandles.push_back(vhandle[3]);
|
|
|
|
|
face_vhandles.push_back(vhandle[1]);
|
|
|
|
|
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[4]);
|
|
|
|
|
mesh_.add_face(face_vhandles);
|
|
|
|
|
|
|
|
|
|
/* Test setup:
|
|
|
|
|
0 ==== 2
|
|
|
|
|
|\ 0 /|
|
|
|
|
|
| \ / |
|
|
|
|
|
|2 1 3|
|
|
|
|
|
| / \ |
|
|
|
|
|
|/ 1 \|
|
|
|
|
|
3 ==== 4 */
|
|
|
|
|
// Starting vertex is 1->4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Iterate around vertex 1 at the middle (with holes in between)
|
|
|
|
|
Mesh::VertexVertexIter vv_it = mesh_.vv_begin(vhandle[1]);
|
|
|
|
|
Mesh::VertexVertexIter vv_end = mesh_.vv_end(vhandle[1]);
|
|
|
|
|
|
2013-08-07 09:28:18 +00:00
|
|
|
EXPECT_EQ(4, vv_it->idx() ) << "Index wrong in VertexVertexIter begin at initialization";
|
|
|
|
|
EXPECT_EQ(4, vv_end->idx() ) << "Index wrong in VertexVertexIter end at initialization";
|
2013-08-07 12:44:52 +00:00
|
|
|
EXPECT_TRUE(vv_it.is_valid()) << "Iterator invalid in VertexVertexIter at initialization";
|
2013-01-11 15:46:30 +00:00
|
|
|
|
|
|
|
|
++vv_it ;
|
|
|
|
|
|
2013-08-07 09:28:18 +00:00
|
|
|
EXPECT_EQ(3, vv_it->idx() ) << "Index wrong in VertexVertexIter step 1";
|
2013-08-07 12:44:52 +00:00
|
|
|
EXPECT_TRUE(vv_it.is_valid()) << "Iterator invalid in VertexVertexIter at step 1";
|
2013-01-11 15:46:30 +00:00
|
|
|
|
|
|
|
|
++vv_it ;
|
|
|
|
|
|
2013-08-07 09:28:18 +00:00
|
|
|
EXPECT_EQ(0, vv_it->idx() ) << "Index wrong in VertexVertexIter step 2";
|
2013-08-07 12:44:52 +00:00
|
|
|
EXPECT_TRUE(vv_it.is_valid()) << "Iterator invalid in VertexVertexIter at step 2";
|
2013-01-11 15:46:30 +00:00
|
|
|
|
|
|
|
|
++vv_it ;
|
|
|
|
|
|
2013-08-07 09:28:18 +00:00
|
|
|
EXPECT_EQ(2, vv_it->idx() ) << "Index wrong in VertexVertexIter step 3";
|
2013-08-07 12:44:52 +00:00
|
|
|
EXPECT_TRUE(vv_it.is_valid()) << "Iterator invalid in VertexVertexIter at step 3";
|
2013-01-11 15:46:30 +00:00
|
|
|
|
|
|
|
|
++vv_it ;
|
|
|
|
|
|
2013-08-07 09:28:18 +00:00
|
|
|
EXPECT_EQ(4, vv_it->idx() ) << "Index wrong in VertexVertexIter step 4";
|
2013-08-07 12:44:52 +00:00
|
|
|
EXPECT_FALSE(vv_it.is_valid()) << "Iterator still valid in VertexVertexIter at step 4";
|
2013-01-11 15:46:30 +00:00
|
|
|
EXPECT_TRUE( vv_it == vv_end ) << "Miss matched end iterator";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Small VertexFaceOutgoingHalfedgeIterator Test at boundary vertex
|
|
|
|
|
*/
|
|
|
|
|
TEST_F(OpenMeshTrimeshCirculatorVertexVertex, VertexVertexBoundaryIncrement) {
|
|
|
|
|
|
|
|
|
|
mesh_.clear();
|
|
|
|
|
|
|
|
|
|
// Add some vertices
|
|
|
|
|
Mesh::VertexHandle vhandle[5];
|
|
|
|
|
|
|
|
|
|
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(0,-1, 0));
|
|
|
|
|
vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
|
|
|
|
|
|
|
|
|
|
// Add two 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[1]);
|
|
|
|
|
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[0]);
|
|
|
|
|
face_vhandles.push_back(vhandle[3]);
|
|
|
|
|
face_vhandles.push_back(vhandle[1]);
|
|
|
|
|
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[4]);
|
|
|
|
|
mesh_.add_face(face_vhandles);
|
|
|
|
|
|
|
|
|
|
/* Test setup:
|
|
|
|
|
0 ==== 2
|
|
|
|
|
|\ 0 /|
|
|
|
|
|
| \ / |
|
|
|
|
|
|2 1 3|
|
|
|
|
|
| / \ |
|
|
|
|
|
|/ 1 \|
|
|
|
|
|
3 ==== 4 */
|
|
|
|
|
// Starting vertex is 1->4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Iterate around vertex 1 at the middle (with holes in between)
|
|
|
|
|
Mesh::VertexVertexIter vv_it = mesh_.vv_begin(vhandle[2]);
|
|
|
|
|
Mesh::VertexVertexIter vv_end = mesh_.vv_end(vhandle[2]);
|
|
|
|
|
|
2013-08-07 09:28:18 +00:00
|
|
|
EXPECT_EQ(4, vv_it->idx() ) << "Index wrong in VertexVertexIter begin at initialization";
|
|
|
|
|
EXPECT_EQ(4, vv_end->idx() ) << "Index wrong in VertexVertexIter end at initialization";
|
2013-08-07 12:44:52 +00:00
|
|
|
EXPECT_TRUE(vv_it.is_valid()) << "Iterator invalid in VertexVertexIter at initialization";
|
2013-01-11 15:46:30 +00:00
|
|
|
|
|
|
|
|
++vv_it ;
|
|
|
|
|
|
2013-08-07 09:28:18 +00:00
|
|
|
EXPECT_EQ(1, vv_it->idx() ) << "Index wrong in VertexVertexIter step 1";
|
2013-08-07 12:44:52 +00:00
|
|
|
EXPECT_TRUE(vv_it.is_valid()) << "Iterator invalid in VertexVertexIter at step 1";
|
2013-01-11 15:46:30 +00:00
|
|
|
|
|
|
|
|
++vv_it ;
|
|
|
|
|
|
2013-08-07 09:28:18 +00:00
|
|
|
EXPECT_EQ(0, vv_it->idx() ) << "Index wrong in VertexVertexIter step 2";
|
2013-08-07 12:44:52 +00:00
|
|
|
EXPECT_TRUE(vv_it.is_valid()) << "Iterator invalid in VertexVertexIter at step 2";
|
2013-01-11 15:46:30 +00:00
|
|
|
|
|
|
|
|
++vv_it ;
|
|
|
|
|
|
2013-08-07 09:28:18 +00:00
|
|
|
EXPECT_EQ(4, vv_it->idx() ) << "Index wrong in VertexVertexIter step 3";
|
2013-08-07 12:44:52 +00:00
|
|
|
EXPECT_FALSE(vv_it.is_valid()) << "Iterator invalid in VertexVertexIter at step 3";
|
2013-01-11 15:46:30 +00:00
|
|
|
EXPECT_TRUE( vv_it == vv_end ) << "Miss matched end iterator";
|
2013-09-20 14:21:08 +00:00
|
|
|
}
|
2015-02-19 09:58:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Test if the end iterator stays invalid after one lap
|
|
|
|
|
*/
|
|
|
|
|
TEST_F(OpenMeshTrimeshCirculatorVertexVertex, VertexVertexIterCheckInvalidationAtEnds) {
|
|
|
|
|
|
|
|
|
|
mesh_.clear();
|
|
|
|
|
|
|
|
|
|
// Add some vertices
|
|
|
|
|
Mesh::VertexHandle vhandle[5];
|
|
|
|
|
|
|
|
|
|
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(0,-1, 0));
|
|
|
|
|
vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
|
|
|
|
|
|
|
|
|
|
// Add two 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::FaceHandle fh0 = mesh_.add_face(face_vhandles);
|
|
|
|
|
|
|
|
|
|
face_vhandles.clear();
|
|
|
|
|
|
|
|
|
|
face_vhandles.push_back(vhandle[1]);
|
|
|
|
|
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[0]);
|
|
|
|
|
face_vhandles.push_back(vhandle[3]);
|
|
|
|
|
face_vhandles.push_back(vhandle[1]);
|
|
|
|
|
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[4]);
|
|
|
|
|
mesh_.add_face(face_vhandles);
|
|
|
|
|
|
|
|
|
|
/* Test setup:
|
|
|
|
|
0 ==== 2
|
|
|
|
|
|\ 0 /|
|
|
|
|
|
| \ / |
|
|
|
|
|
|2 1 3|
|
|
|
|
|
| / \ |
|
|
|
|
|
|/ 1 \|
|
|
|
|
|
3 ==== 4 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if the end iterator stays invalid after end
|
|
|
|
|
Mesh::VertexVertexIter endIter = mesh_.vv_end(vhandle[1]);
|
|
|
|
|
EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid";
|
|
|
|
|
++endIter ;
|
|
|
|
|
EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid after increment";
|
|
|
|
|
|
2015-02-19 15:47:21 +00:00
|
|
|
// Check if the end iterators becomes valid after decrement
|
|
|
|
|
endIter = mesh_.vv_end(vhandle[1]);
|
|
|
|
|
EXPECT_FALSE(endIter.is_valid()) << "EndIter is not invalid";
|
|
|
|
|
--endIter;
|
|
|
|
|
EXPECT_TRUE(endIter.is_valid()) << "EndIter is invalid after decrement";
|
|
|
|
|
EXPECT_EQ(2,endIter->idx()) << "EndIter points on the wrong element";
|
|
|
|
|
|
2015-02-19 09:58:00 +00:00
|
|
|
|
|
|
|
|
// Check if the start iterator decrement is invalid
|
|
|
|
|
Mesh::VertexVertexIter startIter = mesh_.vv_begin(vhandle[1]);
|
|
|
|
|
EXPECT_TRUE(startIter.is_valid()) << "StartIter is not valid";
|
|
|
|
|
--startIter;
|
|
|
|
|
EXPECT_FALSE(startIter.is_valid()) << "StartIter decrement is not invalid";
|
|
|
|
|
|
2015-02-19 15:47:21 +00:00
|
|
|
// Check if the start iterator becomes valid
|
|
|
|
|
++startIter;
|
|
|
|
|
EXPECT_TRUE(startIter.is_valid()) << "StartIter is invalid after re-incrementing";
|
|
|
|
|
EXPECT_EQ(startIter->idx(), mesh_.vv_begin(vhandle[1])->idx()) << "StartIter points on the wrong element";
|
|
|
|
|
|
2015-02-19 09:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 15:46:30 +00:00
|
|
|
}
|