1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "BBTreeTest.hxx"
23 #include "DirectedBoundingBox.hxx"
29 void BBTreeTest::setUp()
34 void BBTreeTest::tearDown()
39 * Test that creates a tree in 2D and check that
40 * the results are correct in three
42 * a non matching search
44 * a bbox overlapping the bboxes of the tree
46 void BBTreeTest::test_BBTree() {
49 double* bbox=new double[4*N*N];
50 for (int i=0; i<N; i++)
51 for (int j=0; j<N; j++)
54 bbox[4*(i*N+j)+1]=i+1;
56 bbox[4*(i*N+j)+3]=j+1;
58 BBTree<2> tree(bbox,0,0,N*N);
59 std::vector <int> elems;
61 //box outside the tree
62 double bbox1[4]={-2.0, -1.0, 0.0, 1.0};
63 tree.getIntersectingElems(bbox1,elems);
64 CPPUNIT_ASSERT_EQUAL(0,(int)elems.size());
67 //box intersecting 4 tree elems
68 double bbox2[4]={2.5, 3.5, 0.5, 1.5};
69 tree.getIntersectingElems(bbox2,elems);
70 CPPUNIT_ASSERT_EQUAL(4,(int)elems.size());
73 //box exactly superimposed to two tree elems
74 double bbox3[4]={5.0,6.0,7.0,9.0};
75 tree.getIntersectingElems(bbox3,elems);
76 CPPUNIT_ASSERT_EQUAL(2,(int)elems.size());
79 double xx[2]={1.0,1.0};
80 tree.getElementsAroundPoint(xx,elems);
81 CPPUNIT_ASSERT_EQUAL(4,(int)elems.size());
86 void BBTreeTest::test_DirectedBB_3D()
88 // a rectangle 1x2 extruded along vector (10,0,10)
89 const int nbP = 8, dim = 3;
90 double coords[nbP*dim] =
92 0,0,0, 2,0,0, 2,1,0, 0,1,0,
93 10,0,10, 12,0,10, 12,1,10, 10,1,10
95 INTERP_KERNEL::DirectedBoundingBox bb( coords, nbP, dim);
98 // corners of extrusion are IN
99 for ( int i = 0; i < nbP*dim; i+=dim )
100 CPPUNIT_ASSERT( !bb.isOut( coords + i ));
102 // points near corners of extrusion are OUT
105 0,0,3, 6,0,3, 5,1,2, 0,1,2,
106 8,0,9, 11,0,8, 11,0.5,8, 8,0.5,9
108 for ( int i = 0; i < nbP*dim; i+=dim )
109 CPPUNIT_ASSERT( bb.isOut( p + i ));
111 // the extrusions shifted by 3 in XOY plane are OUT
112 double shifted_X[nbP*dim] =
114 3,0,0, 5,0,0, 5,1,0, 3,1,0,
115 13,0,10, 15,0,10, 15,1,10, 13,1,10
117 double shifted_x[nbP*dim] =
119 -3,0,0, -1,0,0, -1,1,0, -3,1,0,
120 7,0,10, 9,0,10, 9,1,10, 7,1,10
122 double shifted_Y[nbP*dim] =
124 0,3,0, 2,3,0, 2,4,0, 0,4,0,
125 10,3,10, 12,3,10, 12,4,10, 10,4,10
127 double shifted_y[nbP*dim] =
129 0,-3,0, 2,-3,0, 2,-2,0, 0,-2,0,
130 10,-3,10, 12,-3,10, 12,-2,10, 10,-2,10
132 INTERP_KERNEL::DirectedBoundingBox shiftedBB_x( shifted_x, nbP, dim);
133 INTERP_KERNEL::DirectedBoundingBox shiftedBB_X( shifted_X, nbP, dim);
134 INTERP_KERNEL::DirectedBoundingBox shiftedBB_y( shifted_y, nbP, dim);
135 INTERP_KERNEL::DirectedBoundingBox shiftedBB_Y( shifted_Y, nbP, dim);
137 CPPUNIT_ASSERT( bb.isDisjointWith( shiftedBB_x ));
138 CPPUNIT_ASSERT( bb.isDisjointWith( shiftedBB_X ));
139 CPPUNIT_ASSERT( bb.isDisjointWith( shiftedBB_y ));
140 CPPUNIT_ASSERT( bb.isDisjointWith( shiftedBB_Y ));
142 // intersecting box is IN
143 double inters_coords[nbP*dim] =
145 0,0,0, 2,0,0, 2,1,0, 0,1,0,
146 0,0,2, 2,0,2, 2,1,2, 0,1,2
148 INTERP_KERNEL::DirectedBoundingBox ibb( inters_coords, nbP, dim);
149 CPPUNIT_ASSERT( !bb.isDisjointWith( ibb ));
151 // overlapping non-directed BB
152 double overlappingBB[2*dim] =
156 CPPUNIT_ASSERT( !bb.isDisjointWith( overlappingBB ));
158 // non-overlapping non-directed BB
159 double nonoverlappingBB_1[2*dim] =
163 CPPUNIT_ASSERT( bb.isDisjointWith( nonoverlappingBB_1 ));
164 double nonoverlappingBB_2[2*dim] =
168 CPPUNIT_ASSERT( bb.isDisjointWith( nonoverlappingBB_2 ));
171 void BBTreeTest::test_DirectedBB_2D()
173 // a segment of length 2 extruded along vector (10,10)
174 const int nbP = 4, dim = 2;
175 double coords[nbP*dim] =
180 INTERP_KERNEL::DirectedBoundingBox bb( coords, nbP, dim);
183 // corners of extrusion are IN
184 for ( int i = 0; i < nbP*dim; i+=dim )
185 CPPUNIT_ASSERT( !bb.isOut( coords + i ));
187 // points near corners of extrusion are OUT
193 for ( int i = 0; i < nbP*dim; i+=dim )
194 CPPUNIT_ASSERT( bb.isOut( p + i ));
196 // the extrusions shifted by 3 along OX are OUT
197 double shifted_X[nbP*dim] =
202 double shifted_x[nbP*dim] =
207 INTERP_KERNEL::DirectedBoundingBox shiftedBB_x( shifted_x, nbP, dim);
208 INTERP_KERNEL::DirectedBoundingBox shiftedBB_X( shifted_X, nbP, dim);
210 CPPUNIT_ASSERT( bb.isDisjointWith( shiftedBB_x ));
211 CPPUNIT_ASSERT( bb.isDisjointWith( shiftedBB_X ));
213 // intersecting box is IN
214 double inters_coords[nbP*dim] =
219 INTERP_KERNEL::DirectedBoundingBox ibb( inters_coords, nbP, dim);
220 CPPUNIT_ASSERT( !bb.isDisjointWith( ibb ));
222 // overlapping non-directed BB
223 double overlappingBB[2*dim] =
227 CPPUNIT_ASSERT( !bb.isDisjointWith( overlappingBB ));
229 // non-overlapping non-directed BB
230 double nonoverlappingBB_1[2*dim] =
234 CPPUNIT_ASSERT( bb.isDisjointWith( nonoverlappingBB_1 ));
235 double nonoverlappingBB_2[2*dim] =
239 CPPUNIT_ASSERT( bb.isDisjointWith( nonoverlappingBB_2 ));
242 void BBTreeTest::test_DirectedBB_1D()
244 const int nbP = 2, dim = 1;
245 double coords[nbP*dim] =
249 INTERP_KERNEL::DirectedBoundingBox bb( coords, nbP, dim);
253 for ( int i = 0; i < nbP*dim; i+=dim )
254 CPPUNIT_ASSERT( !bb.isOut( coords + i ));
256 // points near ends are OUT
261 for ( int i = 0; i < nbP*dim; i+=dim )
262 CPPUNIT_ASSERT( bb.isOut( p + i ));
264 // shifted boxes are OUT
265 double shifted_X[nbP*dim] =
269 double shifted_x[nbP*dim] =
273 INTERP_KERNEL::DirectedBoundingBox shiftedBB_x( shifted_x, nbP, dim);
274 INTERP_KERNEL::DirectedBoundingBox shiftedBB_X( shifted_X, nbP, dim);
276 CPPUNIT_ASSERT( bb.isDisjointWith( shiftedBB_x ));
277 CPPUNIT_ASSERT( bb.isDisjointWith( shiftedBB_X ));
279 // intersecting box is IN
280 double inters_coords[nbP*dim] =
284 INTERP_KERNEL::DirectedBoundingBox ibb( inters_coords, nbP, dim);
285 CPPUNIT_ASSERT( !bb.isDisjointWith( ibb ));
287 // overlapping non-directed BB
288 double overlappingBB[2*dim] =
292 CPPUNIT_ASSERT( !bb.isDisjointWith( overlappingBB ));
294 // non-overlapping non-directed BB
295 double nonoverlappingBB_1[2*dim] =
299 CPPUNIT_ASSERT( bb.isDisjointWith( nonoverlappingBB_1 ));
300 double nonoverlappingBB_2[2*dim] =
304 CPPUNIT_ASSERT( bb.isDisjointWith( nonoverlappingBB_2 ));