42 #include <gtest/gtest.h> 44 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh> 45 #include <ACG/Geometry/bsp/TriangleBSPT.hh> 46 #include <ACG/Geometry/Algorithms.hh> 61 virtual void SetUp() {
77 std::vector<Mesh::VertexHandle> face_vhandles;
79 face_vhandles.clear();
80 face_vhandles.push_back(vhandle[0]);
81 face_vhandles.push_back(vhandle[1]);
82 face_vhandles.push_back(vhandle[3]);
83 mesh_.add_face(face_vhandles);
85 face_vhandles.clear();
86 face_vhandles.push_back(vhandle[1]);
87 face_vhandles.push_back(vhandle[2]);
88 face_vhandles.push_back(vhandle[3]);
89 mesh_.add_face(face_vhandles);
93 face_vhandles.clear();
94 face_vhandles.push_back(vhandle[7]);
95 face_vhandles.push_back(vhandle[6]);
96 face_vhandles.push_back(vhandle[5]);
97 mesh_.add_face(face_vhandles);
99 face_vhandles.clear();
100 face_vhandles.push_back(vhandle[7]);
101 face_vhandles.push_back(vhandle[5]);
102 face_vhandles.push_back(vhandle[4]);
103 mesh_.add_face(face_vhandles);
107 face_vhandles.clear();
108 face_vhandles.push_back(vhandle[1]);
109 face_vhandles.push_back(vhandle[0]);
110 face_vhandles.push_back(vhandle[4]);
111 mesh_.add_face(face_vhandles);
113 face_vhandles.clear();
114 face_vhandles.push_back(vhandle[1]);
115 face_vhandles.push_back(vhandle[4]);
116 face_vhandles.push_back(vhandle[5]);
117 mesh_.add_face(face_vhandles);
121 face_vhandles.clear();
122 face_vhandles.push_back(vhandle[2]);
123 face_vhandles.push_back(vhandle[1]);
124 face_vhandles.push_back(vhandle[5]);
125 mesh_.add_face(face_vhandles);
127 face_vhandles.clear();
128 face_vhandles.push_back(vhandle[2]);
129 face_vhandles.push_back(vhandle[5]);
130 face_vhandles.push_back(vhandle[6]);
131 mesh_.add_face(face_vhandles);
136 face_vhandles.clear();
137 face_vhandles.push_back(vhandle[3]);
138 face_vhandles.push_back(vhandle[2]);
139 face_vhandles.push_back(vhandle[6]);
140 mesh_.add_face(face_vhandles);
142 face_vhandles.clear();
143 face_vhandles.push_back(vhandle[3]);
144 face_vhandles.push_back(vhandle[6]);
145 face_vhandles.push_back(vhandle[7]);
146 mesh_.add_face(face_vhandles);
150 face_vhandles.clear();
151 face_vhandles.push_back(vhandle[0]);
152 face_vhandles.push_back(vhandle[3]);
153 face_vhandles.push_back(vhandle[7]);
154 mesh_.add_face(face_vhandles);
156 face_vhandles.clear();
157 face_vhandles.push_back(vhandle[0]);
158 face_vhandles.push_back(vhandle[7]);
159 face_vhandles.push_back(vhandle[4]);
160 mesh_.add_face(face_vhandles);
198 bsp_ =
new BSP( mesh_ );
201 bsp_->reserve(mesh_.n_faces());
203 Mesh::FIter f_it = mesh_.faces_begin();
204 Mesh::FIter f_end = mesh_.faces_end();
206 for (; f_it!=f_end; ++f_it)
207 bsp_->push_back(*f_it);
209 bsp_->build(10, 100);
214 virtual void TearDown() {
232 EXPECT_EQ(8u, mesh_.n_vertices() ) <<
"Wrong number of vertices";
233 EXPECT_EQ(12u, mesh_.n_faces() ) <<
"Wrong number of faces";
241 EXPECT_FALSE(bsp_->empty()) <<
"BSP should not be empty !";
242 EXPECT_EQ(12u, bsp_->size()) <<
"Wrong number of triangles in BSP after construction";
274 BSP::NearestNeighbor nn = bsp_->nearest(p1);
276 EXPECT_EQ(5, nn.handle.idx()) <<
"Wrong Handle on closest face";
292 BSP::NearestNeighbor nn = bsp_->nearest(p1);
293 EXPECT_EQ(4, nn.handle.idx()) <<
"Wrong Handle on closest face";
309 BSP::NearestNeighbor nn = bsp_->nearest(p1);
310 EXPECT_EQ(4, nn.handle.idx()) <<
"Wrong Handle on closest face";
327 BSP::NearestNeighbor nn = bsp_->nearest(p1);
328 EXPECT_EQ(5, nn.handle.idx()) <<
"Wrong Handle on closest face";
332 TEST_F(
BSP_CUBE_BASE, RayIntersectionAboveSurface_NonDirectionalFunction_1 ) {
358 rc = bsp_->raycollision(p1,yDirection);
360 EXPECT_EQ(2u, rc.size() ) <<
"Wrong number of hit faces in ray collision test 1";
361 if ( rc.size() == 2u ) {
362 EXPECT_EQ(4, rc[0].first.idx() ) <<
"Wrong handle of first face in ray collision test 1";
363 EXPECT_EQ(9, rc[1].first.idx() ) <<
"Wrong handle of second face in ray collision test 1";
368 TEST_F(
BSP_CUBE_BASE, RayIntersectionAboveSurface_NonDirectionalFunction_NegativeDirection_1 ) {
392 rc = bsp_->raycollision(p1,nyDirection);
394 EXPECT_EQ(2u, rc.size() ) <<
"Wrong number of hit faces in ray collision test 1";
395 if ( rc.size() == 2u ) {
396 EXPECT_EQ(4, rc[0].first.idx() ) <<
"Wrong handle of first face in ray collision test 1";
397 EXPECT_EQ(9, rc[1].first.idx() ) <<
"Wrong handle of second face in ray collision test 1";
401 TEST_F(
BSP_CUBE_BASE, RayIntersectionAboveSurface_NonDirectionalFunction_2 ) {
421 rc = bsp_->raycollision(p1,yDirection);
423 EXPECT_EQ(2u, rc.size() ) <<
"Wrong number of hit faces in ray collision test 2";
424 if ( rc.size() == 2u ) {
425 EXPECT_EQ(5, rc[0].first.idx() ) <<
"Wrong handle of first face in ray collision test 2";
426 EXPECT_EQ(8, rc[1].first.idx() ) <<
"Wrong handle of second face in ray collision test 2";
431 TEST_F(
BSP_CUBE_BASE, RayIntersectionAboveSurface_NonDirectionalFunction_NegativeDirection_2 ) {
452 rc = bsp_->raycollision(p1,nyDirection);
454 EXPECT_EQ(2u, rc.size() ) <<
"Wrong number of hit faces in ray collision test 2";
455 if ( rc.size() == 2u ) {
456 EXPECT_EQ(5, rc[0].first.idx() ) <<
"Wrong handle of first face in ray collision test 2";
457 EXPECT_EQ(8, rc[1].first.idx() ) <<
"Wrong handle of second face in ray collision test 2";
464 TEST_F(
BSP_CUBE_BASE, RayIntersectionAboveSurface_DirectionalFunction_1 ) {
490 rc = bsp_->directionalRaycollision(origin,yDirection);
492 EXPECT_EQ(2u, rc.size() ) <<
"Wrong number of hit faces in ray collision test 1";
493 if ( rc.size() == 2u ) {
494 EXPECT_EQ(4, rc[0].first.idx() ) <<
"Wrong handle of first face in ray collision test 1";
495 EXPECT_EQ(9, rc[1].first.idx() ) <<
"Wrong handle of second face in ray collision test 1";
515 EXPECT_EQ(1.0f, distance ) <<
"Wrong distance";
516 EXPECT_EQ(0.25f, u ) <<
"Wrong u";
517 EXPECT_EQ(0.5f , v ) <<
"Wrong v";
523 TEST_F(
BSP_CUBE_BASE, RayIntersectionAboveSurface_DirectionalFunction_NegativeDirection_1 ) {
547 rc = bsp_->directionalRaycollision(p1,nyDirection);
549 EXPECT_EQ(0u, rc.size() ) <<
"Wrong number of hit faces in ray collision test 1";
Kernel::FaceVertexIter FaceVertexIter
Circulator.
Kernel::Point Point
Coordinate type.
std::vector< std::pair< Handle, Scalar > > RayCollision
Store nearest neighbor information.
bool triangleIntersection(const Vec &_o, const Vec &_dir, const Vec &_v0, const Vec &_v1, const Vec &_v2, typename Vec::value_type &_t, typename Vec::value_type &_u, typename Vec::value_type &_v)
Intersect a ray and a triangle.
SmartVertexHandle add_vertex(const Point &_p)
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.