Salome HOME
cce28e644b8af8abb4a536c891162506d1fcd980
[tools/medcoupling.git] / src / INTERP_KERNELTest / ThreeDSurfProjectionTest.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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
20 #include "ThreeDSurfProjectionTest.hxx"
21 #include "PlanarIntersector.txx"
22
23 class MyMeshType
24 {
25 public:
26   static const int MY_SPACEDIM=3;
27   typedef int MyConnType;
28 };
29
30 class MyMatrixType
31 {
32 };
33
34 void INTERP_TEST::ThreeDSurfProjectionTest::test1()
35 {
36   // Two triangles coo and coo2 are perfectly // each others with a distance equal to 1e-6.
37   // A little rotation to make it more funny.
38   //coo=DataArrayDouble([0.,0.,0.,1.,0.,0.,0.,1.,0.],3,3)
39   //eps=1e-6
40   //coo2=DataArrayDouble([0.,0.,eps,1.,0.,eps,0.,1.,eps],3,3)
41   //MEDCouplingPointSet.Rotate3DAlg([0.,0.,0.],[2.,1.,3.],0.3,coo)
42   //MEDCouplingPointSet.Rotate3DAlg([0.,0.,0.],[2.,1.,3.],0.3,coo2)
43   const double coo[9]={0.,0.,0.,0.96809749223257568,0.24332379388106262,-0.059839592782071335,-0.23056279077409292,0.95852673990234838,0.16753294721527912};
44   const double coo2[9]={9.8122602102980502e-08,-1.4839144255482456e-7,9.8404874611628791e-7,0.96809759035517784,0.24332364548962007,-0.059838608733325221,-0.23056269265149082,0.9585265915109058,0.16753393126402524};
45   double *tmp0(new double[9]),*tmp1(new double[9]);
46   int ret;
47   //eps=1e-2. eps is a tolerance to detect that two points are the same or not in a same polygon.
48   // here the max 3D distance is 1e-5 > 1e-6 so 1 is expected
49   std::copy(coo,coo+9,tmp0);
50   std::copy(coo2,coo2+9,tmp1);
51   ret=INTERP_KERNEL::PlanarIntersector<MyMeshType,MyMatrixType>::Projection(tmp0,tmp1,3,3,1e-2,1e-5/* <- */,-1.,0.5,true);
52   CPPUNIT_ASSERT_EQUAL(1,ret);
53   const double expected0[9]={0.,0.,0.,1.,0.,0.,0.,1.,0.};
54   for(int i=0;i<9;i++)
55     {
56       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected0[i],tmp0[i],1e-15);
57       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected0[i],tmp1[i],1e-15);
58     }
59   // here the max 3D distance is 1e-8 < 1e-6 so 0 is expected
60   std::copy(coo,coo+9,tmp0);
61   std::copy(coo2,coo2+9,tmp1);
62   ret=INTERP_KERNEL::PlanarIntersector<MyMeshType,MyMatrixType>::Projection(tmp0,tmp1,3,3,1e-2,1e-8/* <- */,-1.,0.5,true);
63   CPPUNIT_ASSERT_EQUAL(0,ret);
64   // here testing when max 3D distance is 1e-5 > 1e-6 with inverted cells
65   std::copy(coo,coo+9,tmp0);
66   std::copy(coo2,coo2+3,tmp1+6); std::copy(coo2+3,coo2+6,tmp1+3); std::copy(coo2+6,coo2+9,tmp1);
67   ret=INTERP_KERNEL::PlanarIntersector<MyMeshType,MyMatrixType>::Projection(tmp0,tmp1,3,3,1e-2,1e-5/* <- */,-1.,0.5,true);
68   CPPUNIT_ASSERT_EQUAL(-1,ret);
69   const double expected1[9]={-0.7071067811865476,-0.7071067811865476,0.,0.,-1.4142135623730951,0.,-1.4142135623730951,-1.4142135623730951,0.};
70   const double expected2[9]={-1.4142135623730951,-1.4142135623730951,0.,0.,-1.4142135623730951,0.,-0.7071067811865476,-0.7071067811865476,0.};
71   for(int i=0;i<9;i++)
72     {
73       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],tmp0[i],1e-14);
74       CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],tmp1[i],1e-14);
75     }
76   //
77   delete [] tmp0;
78   delete [] tmp1;
79 }
80
81 void INTERP_TEST::ThreeDSurfProjectionTest::test2()
82 {// here the two triangles have their center of inertia very close (eps) but the angle between the two planes is "big"
83   //coo=DataArrayDouble([0.,0.,0.,1.,0.,0.,0.,1.,0.],3,3)
84   //coocpy=coo.deepCpy()
85   //MEDCouplingPointSet.Rotate3DAlg([0.,0.,0.],[-1,-1.,0.],pi/3,coocpy)
86   //coocpy+=[eps*sqrt(3)/2,eps/2,eps*0.]
87   //
88   const double coo[9]={0.,0.,0.,0.96809749223257568,0.24332379388106262,-0.059839592782071335,-0.23056279077409292,0.95852673990234838,0.16753294721527912};
89   const double coo2[9]={7.2311562622637225e-07,6.8998795679738294e-07,3.1943866106249849e-08,0.72852072144314628,0.33125439126063028,0.5996079016637561,0.0090154262465889021,0.87059752249869415,-0.49191448334281612};
90   double *tmp0(new double[9]),*tmp1(new double[9]);
91   int ret;
92   //eps=1e-2. eps is a tolerance to detect that two points are the same or not in a same polygon.
93   // here the max 3D distance is 1e-5 > 1e-6 so 1 is expected
94   std::copy(coo,coo+9,tmp0);
95   std::copy(coo2,coo2+9,tmp1);
96   ret=INTERP_KERNEL::PlanarIntersector<MyMeshType,MyMatrixType>::Projection(tmp0,tmp1,3,3,1e-2,1e-5/* <- */,-1.,0.5,true);
97   CPPUNIT_ASSERT_EQUAL(1,ret);
98   // here the max 3D distance is 1e-8 < 1e-6 so 0 is expected
99   std::copy(coo,coo+9,tmp0);
100   std::copy(coo2,coo2+9,tmp1);
101   ret=INTERP_KERNEL::PlanarIntersector<MyMeshType,MyMatrixType>::Projection(tmp0,tmp1,3,3,1e-2,1e-8/* <- */,-1.,0.5,true);
102   CPPUNIT_ASSERT_EQUAL(0,ret);
103   //
104   delete [] tmp0;
105   delete [] tmp1;
106 }