Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / INTERP_KERNELTest / BBTreeTest.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include "BBTreeTest.hxx"
20 #include <iostream>
21 #include <vector>
22 namespace INTERP_TEST
23 {
24
25
26   void BBTreeTest::setUp() 
27   {
28   }
29
30  
31   void BBTreeTest::tearDown() 
32   {
33   }
34
35   /**
36    * Test that creates a tree in 2D and check that 
37    * the results are correct in three
38    * cases :
39    * a non matching search
40    * a standard case
41    * a bbox overlapping the bboxes of the tree
42    */
43   void BBTreeTest::test_BBTree() {
44     //bbox tree creation
45     const int N=10;
46     double* bbox=new double[4*N*N];
47     for (int i=0; i<N; i++)
48       for (int j=0; j<N; j++)
49         {
50           bbox[4*(i*N+j)]=i;
51           bbox[4*(i*N+j)+1]=i+1;
52           bbox[4*(i*N+j)+2]=j;
53           bbox[4*(i*N+j)+3]=j+1;
54         }
55     BBTree<2> tree(bbox,0,0,N*N);
56     std::vector <int> elems; 
57   
58     //box outside the tree
59     double bbox1[4]={-2.0, -1.0, 0.0, 1.0};
60     tree.getIntersectingElems(bbox1,elems);
61     CPPUNIT_ASSERT_EQUAL(0,(int)elems.size());
62     elems.clear();
63   
64     //box intersecting 4 tree elems
65     double bbox2[4]={2.5, 3.5, 0.5, 1.5};
66     tree.getIntersectingElems(bbox2,elems);
67     CPPUNIT_ASSERT_EQUAL(4,(int)elems.size());
68     elems.clear();
69   
70     //box exactly superimposed to two tree elems
71     double bbox3[4]={5.0,6.0,7.0,9.0};
72     tree.getIntersectingElems(bbox3,elems);
73     CPPUNIT_ASSERT_EQUAL(2,(int)elems.size());
74     elems.clear();
75
76     double xx[2]={1.0,1.0};
77     tree.getElementsAroundPoint(xx,elems);
78     CPPUNIT_ASSERT_EQUAL(4,(int)elems.size());
79
80     delete[] bbox;
81   }
82
83
84 }