1 // Copyright (C) 2007-2013 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.
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 "PointLocatorTest.hxx"
21 #include "PointLocator.hxx"
22 #include "MEDMeshMaker.hxx"
23 #include "MEDMEM_Mesh.hxx"
32 void PointLocatorTest::setUp()
37 void PointLocatorTest::tearDown()
42 * Test that creates a tree in 2D and check that
43 * the results are correct in three
45 * a non matching search
47 * a bbox overlapping the bboxes of the tree
49 void PointLocatorTest::test_PointLocator() {
50 MEDMEM::MESH* mesh2D= MEDMeshMaker(2,2,MED_EN::MED_QUAD4);
51 MEDMEM::PointLocator pl(*mesh2D) ;
52 double x[2]={0.0,0.0};
53 std::list<int> elems = pl.locate(x);
54 CPPUNIT_ASSERT_EQUAL(1,(int)elems.size());
55 CPPUNIT_ASSERT_EQUAL(1,(int)(*(elems.begin())));
58 double x2[2]={0.25,0.25};
59 elems = pl.locate(x2);
60 CPPUNIT_ASSERT_EQUAL(1,(int)elems.size());
61 CPPUNIT_ASSERT_EQUAL(1,(int)(*(elems.begin())));
64 double x3[2]={0.5,0.5};
65 elems = pl.locate(x3);
66 CPPUNIT_ASSERT_EQUAL(4,(int)elems.size());
69 double x4[2]={-1.0,0.0};
70 elems = pl.locate(x4);
71 CPPUNIT_ASSERT_EQUAL(0,(int)elems.size());
75 MEDMEM::MESH* mesh3D= MEDMeshMaker(3,2,MED_EN::MED_HEXA8);
76 MEDMEM::PointLocator pl3(*mesh3D);
77 double xx[3]={0.0,0.0,0.0};
78 elems = pl3.locate(xx);
79 CPPUNIT_ASSERT_EQUAL(1,(int)elems.size());
80 CPPUNIT_ASSERT_EQUAL(1,(int)*(elems.begin()));
83 double xx2[3]={0.25,0.25,0.25};
84 elems = pl3.locate(xx2);
85 CPPUNIT_ASSERT_EQUAL(1,(int)elems.size());
86 CPPUNIT_ASSERT_EQUAL(1,(int)*(elems.begin()));
89 double xx3[3]={0.5,0.5,0.5};
90 elems = pl3.locate(xx3);
91 CPPUNIT_ASSERT_EQUAL(8,(int)elems.size());
94 double xx4[3]={-1.0,0.0,0.0};
95 elems = pl3.locate(xx4);
96 CPPUNIT_ASSERT_EQUAL(0,(int)elems.size());
103 * Test that the results are correct in three
105 * a non matching search
107 * a bbox overlapping the bboxes of the tree
109 void PointLocatorTest::test_PointLocatorInSimplex()
111 MEDMEM::MESH* mesh2D= MEDMeshMaker(2,2,MED_EN::MED_QUAD4);
112 // mesh is a quadrangle (0.0-1.0 x 0.0-1.0 )
118 MEDMEM::PointLocatorInSimplex pl(*mesh2D) ;
119 std::list<int> elems;
120 std::list<int>::iterator elem;
122 double x[2]={0.0,0.25};
123 elems = pl.locate(x);
124 elem = elems.begin();
125 CPPUNIT_ASSERT_EQUAL(3,(int)elems.size());
126 CPPUNIT_ASSERT_EQUAL(1,*elem++);
127 CPPUNIT_ASSERT_EQUAL(2,*elem++);
128 CPPUNIT_ASSERT_EQUAL(5,*elem++);
131 double x[2]={0.25,0.0};
132 elems = pl.locate(x);
133 elem = elems.begin();
134 CPPUNIT_ASSERT_EQUAL(3,(int)elems.size());
135 CPPUNIT_ASSERT_EQUAL(1,*elem++);
136 CPPUNIT_ASSERT_EQUAL(2,*elem++);
137 CPPUNIT_ASSERT_EQUAL(4,*elem++);
140 double x[2]={0.25,1.0};
141 elems = pl.locate(x);
142 elem = elems.begin();
143 CPPUNIT_ASSERT_EQUAL(3,(int)elems.size());
144 CPPUNIT_ASSERT_EQUAL(2,*elem++);
145 CPPUNIT_ASSERT_EQUAL(3,*elem++);
146 CPPUNIT_ASSERT_EQUAL(6,*elem++);
149 double x[2]={0.4,0.75};
150 elems = pl.locate(x);
151 elem = elems.begin();
152 CPPUNIT_ASSERT_EQUAL(3,(int)elems.size());
153 CPPUNIT_ASSERT_EQUAL(3,*elem++);
154 CPPUNIT_ASSERT_EQUAL(6,*elem++);
155 CPPUNIT_ASSERT_EQUAL(5,*elem++);
158 double x[2]={-1.0,0.0};
159 elems = pl.locate(x);
160 CPPUNIT_ASSERT_EQUAL(0,(int)elems.size());
163 MEDMEM::MESH* mesh3D= MEDMeshMaker(3,2,MED_EN::MED_HEXA8);
168 // 2 -- 5 -- 8 12 --15 --18
170 // 1 -- 4 -- 7->Y 11 --14 --17 21 --24 --27
172 // \ X 10 --13 --16 20 --23 --26
176 MEDMEM::PointLocatorInSimplex pl3(*mesh3D);
178 double x[3]={0.0,0.0,0.0};
179 elems = pl3.locate(x);
180 elem = elems.begin();
181 CPPUNIT_ASSERT_EQUAL(4,(int)elems.size());
182 CPPUNIT_ASSERT_EQUAL(1,*elem++);
183 CPPUNIT_ASSERT_EQUAL(10,*elem++);
184 CPPUNIT_ASSERT_EQUAL(13,*elem++);
185 CPPUNIT_ASSERT_EQUAL(2,*elem++);
188 double x[3]={0.0,0.4,0.3};
189 elems = pl3.locate(x);
190 elem = elems.begin();
191 CPPUNIT_ASSERT_EQUAL(4,(int)elems.size());
192 CPPUNIT_ASSERT_EQUAL(1,*elem++);
193 CPPUNIT_ASSERT_EQUAL(10,*elem++);
194 CPPUNIT_ASSERT_EQUAL(4,*elem++);
195 CPPUNIT_ASSERT_EQUAL(5,*elem++);
198 double x[3]={0.5,0.5,0.5};
199 elems = pl3.locate(x);
200 elem = elems.begin();
201 CPPUNIT_ASSERT_EQUAL(4,(int)elems.size());
202 CPPUNIT_ASSERT_EQUAL(1,*elem++);
203 CPPUNIT_ASSERT_EQUAL(10,*elem++);
204 CPPUNIT_ASSERT_EQUAL(13,*elem++);
205 CPPUNIT_ASSERT_EQUAL(14,*elem++);
208 double x[3]={-1.0,0.0,0.0};
209 elems = pl3.locate(x);
210 CPPUNIT_ASSERT_EQUAL(0,(int)elems.size());