49 #include <gtest/gtest.h> 51 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh> 52 #include <ACG/Geometry/bsp/TriangleBSPT.hh> 53 #include <ACG/Geometry/Algorithms.hh> 68 virtual void SetUp() {
84 std::vector<Mesh::VertexHandle> face_vhandles;
86 face_vhandles.clear();
87 face_vhandles.push_back(vhandle[0]);
88 face_vhandles.push_back(vhandle[1]);
89 face_vhandles.push_back(vhandle[3]);
90 mesh_.add_face(face_vhandles);
92 face_vhandles.clear();
93 face_vhandles.push_back(vhandle[1]);
94 face_vhandles.push_back(vhandle[2]);
95 face_vhandles.push_back(vhandle[3]);
96 mesh_.add_face(face_vhandles);
100 face_vhandles.clear();
101 face_vhandles.push_back(vhandle[7]);
102 face_vhandles.push_back(vhandle[6]);
103 face_vhandles.push_back(vhandle[5]);
104 mesh_.add_face(face_vhandles);
106 face_vhandles.clear();
107 face_vhandles.push_back(vhandle[7]);
108 face_vhandles.push_back(vhandle[5]);
109 face_vhandles.push_back(vhandle[4]);
110 mesh_.add_face(face_vhandles);
114 face_vhandles.clear();
115 face_vhandles.push_back(vhandle[1]);
116 face_vhandles.push_back(vhandle[0]);
117 face_vhandles.push_back(vhandle[4]);
118 mesh_.add_face(face_vhandles);
120 face_vhandles.clear();
121 face_vhandles.push_back(vhandle[1]);
122 face_vhandles.push_back(vhandle[4]);
123 face_vhandles.push_back(vhandle[5]);
124 mesh_.add_face(face_vhandles);
128 face_vhandles.clear();
129 face_vhandles.push_back(vhandle[2]);
130 face_vhandles.push_back(vhandle[1]);
131 face_vhandles.push_back(vhandle[5]);
132 mesh_.add_face(face_vhandles);
134 face_vhandles.clear();
135 face_vhandles.push_back(vhandle[2]);
136 face_vhandles.push_back(vhandle[5]);
137 face_vhandles.push_back(vhandle[6]);
138 mesh_.add_face(face_vhandles);
143 face_vhandles.clear();
144 face_vhandles.push_back(vhandle[3]);
145 face_vhandles.push_back(vhandle[2]);
146 face_vhandles.push_back(vhandle[6]);
147 mesh_.add_face(face_vhandles);
149 face_vhandles.clear();
150 face_vhandles.push_back(vhandle[3]);
151 face_vhandles.push_back(vhandle[6]);
152 face_vhandles.push_back(vhandle[7]);
153 mesh_.add_face(face_vhandles);
157 face_vhandles.clear();
158 face_vhandles.push_back(vhandle[0]);
159 face_vhandles.push_back(vhandle[3]);
160 face_vhandles.push_back(vhandle[7]);
161 mesh_.add_face(face_vhandles);
163 face_vhandles.clear();
164 face_vhandles.push_back(vhandle[0]);
165 face_vhandles.push_back(vhandle[7]);
166 face_vhandles.push_back(vhandle[4]);
167 mesh_.add_face(face_vhandles);
205 bsp_ =
new BSP( mesh_ );
208 bsp_->reserve(mesh_.n_faces());
210 Mesh::FIter f_it = mesh_.faces_begin();
211 Mesh::FIter f_end = mesh_.faces_end();
213 for (; f_it!=f_end; ++f_it)
214 bsp_->push_back(*f_it);
216 bsp_->build(10, 100);
221 virtual void TearDown() {
239 EXPECT_EQ(8u, mesh_.n_vertices() ) <<
"Wrong number of vertices";
240 EXPECT_EQ(12u, mesh_.n_faces() ) <<
"Wrong number of faces";
248 EXPECT_FALSE(bsp_->empty()) <<
"BSP should not be empty !";
249 EXPECT_EQ(12u, bsp_->size()) <<
"Wrong number of triangles in BSP after construction";
281 BSP::NearestNeighbor nn = bsp_->nearest(p1);
283 EXPECT_EQ(5, nn.handle.idx()) <<
"Wrong Handle on closest face";
299 BSP::NearestNeighbor nn = bsp_->nearest(p1);
300 EXPECT_EQ(4, nn.handle.idx()) <<
"Wrong Handle on closest face";
316 BSP::NearestNeighbor nn = bsp_->nearest(p1);
317 EXPECT_EQ(4, nn.handle.idx()) <<
"Wrong Handle on closest face";
334 BSP::NearestNeighbor nn = bsp_->nearest(p1);
335 EXPECT_EQ(5, nn.handle.idx()) <<
"Wrong Handle on closest face";
339 TEST_F(
BSP_CUBE_BASE, RayIntersectionAboveSurface_NonDirectionalFunction_1 ) {
365 rc = bsp_->raycollision(p1,yDirection);
367 EXPECT_EQ(2u, rc.size() ) <<
"Wrong number of hit faces in ray collision test 1";
368 if ( rc.size() == 2u ) {
369 EXPECT_EQ(4, rc[0].first.idx() ) <<
"Wrong handle of first face in ray collision test 1";
370 EXPECT_EQ(9, rc[1].first.idx() ) <<
"Wrong handle of second face in ray collision test 1";
375 TEST_F(
BSP_CUBE_BASE, RayIntersectionAboveSurface_NonDirectionalFunction_NegativeDirection_1 ) {
399 rc = bsp_->raycollision(p1,nyDirection);
401 EXPECT_EQ(2u, rc.size() ) <<
"Wrong number of hit faces in ray collision test 1";
402 if ( rc.size() == 2u ) {
403 EXPECT_EQ(4, rc[0].first.idx() ) <<
"Wrong handle of first face in ray collision test 1";
404 EXPECT_EQ(9, rc[1].first.idx() ) <<
"Wrong handle of second face in ray collision test 1";
408 TEST_F(
BSP_CUBE_BASE, RayIntersectionAboveSurface_NonDirectionalFunction_2 ) {
428 rc = bsp_->raycollision(p1,yDirection);
430 EXPECT_EQ(2u, rc.size() ) <<
"Wrong number of hit faces in ray collision test 2";
431 if ( rc.size() == 2u ) {
432 EXPECT_EQ(5, rc[0].first.idx() ) <<
"Wrong handle of first face in ray collision test 2";
433 EXPECT_EQ(8, rc[1].first.idx() ) <<
"Wrong handle of second face in ray collision test 2";
438 TEST_F(
BSP_CUBE_BASE, RayIntersectionAboveSurface_NonDirectionalFunction_NegativeDirection_2 ) {
459 rc = bsp_->raycollision(p1,nyDirection);
461 EXPECT_EQ(2u, rc.size() ) <<
"Wrong number of hit faces in ray collision test 2";
462 if ( rc.size() == 2u ) {
463 EXPECT_EQ(5, rc[0].first.idx() ) <<
"Wrong handle of first face in ray collision test 2";
464 EXPECT_EQ(8, rc[1].first.idx() ) <<
"Wrong handle of second face in ray collision test 2";
471 TEST_F(
BSP_CUBE_BASE, RayIntersectionAboveSurface_DirectionalFunction_1 ) {
497 rc = bsp_->directionalRaycollision(origin,yDirection);
499 EXPECT_EQ(2u, rc.size() ) <<
"Wrong number of hit faces in ray collision test 1";
500 if ( rc.size() == 2u ) {
501 EXPECT_EQ(4, rc[0].first.idx() ) <<
"Wrong handle of first face in ray collision test 1";
502 EXPECT_EQ(9, rc[1].first.idx() ) <<
"Wrong handle of second face in ray collision test 1";
522 EXPECT_EQ(1.0f, distance ) <<
"Wrong distance";
523 EXPECT_EQ(0.25f, u ) <<
"Wrong u";
524 EXPECT_EQ(0.5f , v ) <<
"Wrong v";
530 TEST_F(
BSP_CUBE_BASE, RayIntersectionAboveSurface_DirectionalFunction_NegativeDirection_1 ) {
554 rc = bsp_->directionalRaycollision(p1,nyDirection);
556 EXPECT_EQ(0u, rc.size() ) <<
"Wrong number of hit faces in ray collision test 1";
std::vector< std::pair< Handle, Scalar > > RayCollision
Store nearest neighbor information.
Kernel::FaceVertexIter FaceVertexIter
Circulator.
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.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Kernel::Point Point
Coordinate type.