]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Correction of big bug on 3DSurf cell orientation.
authorageay <ageay>
Wed, 29 Feb 2012 07:41:54 +0000 (07:41 +0000)
committerageay <ageay>
Wed, 29 Feb 2012 07:41:54 +0000 (07:41 +0000)
src/MEDCoupling/MEDCouplingUMesh.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index 1af037e16ada0573c0295e977e0b2257dd3492cd..af2004fae9186126398e9d4520e1167c6d90f467 100644 (file)
@@ -5096,7 +5096,7 @@ bool MEDCouplingUMesh::IsPolygonWellOriented(bool isQuadratic, const double *vec
       v[1]+=coords[3*begin[i]+2]*coords[3*begin[(i+1)%sz]]-coords[3*begin[i]]*coords[3*begin[(i+1)%sz]+2];
       v[2]+=coords[3*begin[i]]*coords[3*begin[(i+1)%sz]+1]-coords[3*begin[i]+1]*coords[3*begin[(i+1)%sz]];
     }
-  return vec[0]*v[0]+vec[1]*v[1]+vec[2]*v[2]<0.;
+  return vec[0]*v[0]+vec[1]*v[1]+vec[2]*v[2]>0.;
 }
 
 /*!
index 87ed986e5ac8e99dfec13a2102786137e919f35b..9c0e8fcbc4e1b39fe5c5991527d3bb0fab71af0f 100644 (file)
@@ -150,19 +150,19 @@ void MEDCouplingBasicsTest2::testGaussPointNEField1()
 void MEDCouplingBasicsTest2::testCellOrientation1()
 {
   MEDCouplingUMesh *m=build2DTargetMesh_1();
-  double vec[3]={0.,0.,1.};
+  double vec[3]={0.,0.,-1.};
   std::vector<int> res1;
   CPPUNIT_ASSERT_THROW(m->are2DCellsNotCorrectlyOriented(vec,false,res1),INTERP_KERNEL::Exception);
   m->changeSpaceDimension(3);
   res1.clear();
   m->are2DCellsNotCorrectlyOriented(vec,false,res1);
   CPPUNIT_ASSERT(res1.empty());
-  vec[2]=-1;
+  vec[2]=1;
   m->are2DCellsNotCorrectlyOriented(vec,false,res1);
   CPPUNIT_ASSERT_EQUAL(5,(int)res1.size());
   res1.clear();
   //
-  vec[2]=1.;
+  vec[2]=-1.;
   // connectivity inversion
   int *conn=m->getNodalConnectivity()->getPointer();
   int tmp=conn[11];
@@ -207,7 +207,7 @@ void MEDCouplingBasicsTest2::testCellOrientation2()
   MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
   //Test to check global reverse in MEDCouplingUMesh::tryToCorrectPolyhedronOrientation
   MEDCouplingUMesh *m3=build2DTargetMesh_1();
-  double vec[3]={0.,0.,-1.};//<- important for the test
+  double vec[3]={0.,0.,1.};
   m3->changeSpaceDimension(3);
   const int ids1[5]={0,1,2,3,4};
   std::vector<int> ids2(ids1,ids1+5);
index a324e1f2f5239c4b53fca0d92691306180c52e91..79b351c66316311fbdbddfef4fdf771e11c84142 100644 (file)
@@ -531,3 +531,40 @@ void MEDCouplingBasicsTest5::testBuildDescendingConnec2Of3DMesh1()
   mesh2->decrRef();
   mesh->decrRef();
 }
+
+void MEDCouplingBasicsTest5::testAre2DCellsNotCorrectlyOriented1()
+{
+  double m1Coords[8]={1.,1.,-1.,-1.,-1.,-1.,1.,-1.};
+  int m1Conn[4]={0,3,1,2};
+  MEDCouplingUMesh *m1=MEDCouplingUMesh::New();
+  m1->setMeshDimension(2);
+  m1->allocateCells(1);
+  m1->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,m1Conn);
+  m1->finishInsertingCells();
+  DataArrayDouble *myCoords1=DataArrayDouble::New();
+  myCoords1->alloc(4,2);
+  std::copy(m1Coords,m1Coords+8,myCoords1->getPointer());
+  m1->setCoords(myCoords1);
+  myCoords1->decrRef();
+  //
+  double vec1[3]={0.,0.,1.};
+  double *vec2=new double[2];
+  for(int i=0;i<18;i++)
+    {
+      vec2[0]=3.*cos(M_PI/9.*i);
+      vec2[1]=3.*sin(M_PI/9.*i);
+      MEDCouplingUMesh *m1Cpy=static_cast<MEDCouplingUMesh *>(m1->deepCpy());
+      m1Cpy->translate(vec2);
+      std::vector<int> res;
+      CPPUNIT_ASSERT_THROW(m1Cpy->are2DCellsNotCorrectlyOriented(vec1,false,res),INTERP_KERNEL::Exception);
+      res.clear();
+      m1Cpy->changeSpaceDimension(3);
+      m1Cpy->are2DCellsNotCorrectlyOriented(vec1,false,res);
+      CPPUNIT_ASSERT_EQUAL(1,(int)res.size());
+      CPPUNIT_ASSERT_EQUAL(0,res[0]);
+      m1Cpy->decrRef();
+    }
+  delete [] vec2;
+  //
+  m1->decrRef();
+}
index e7ec0077eba1f2ac28524bcfcde142172feee7d1..1252226e37668a96a54dc4adcf2a0715c860c8f3 100644 (file)
@@ -43,6 +43,7 @@ namespace ParaMEDMEM
     CPPUNIT_TEST( testDataArrayDoubleAdvSetting1 );
     CPPUNIT_TEST( testDataArrayIntAdvSetting1 );
     CPPUNIT_TEST( testBuildDescendingConnec2Of3DMesh1 );
+    CPPUNIT_TEST( testAre2DCellsNotCorrectlyOriented1 );
     CPPUNIT_TEST_SUITE_END();
   public:
     void testUMeshTessellate2D1();
@@ -53,6 +54,7 @@ namespace ParaMEDMEM
     void testDataArrayDoubleAdvSetting1();
     void testDataArrayIntAdvSetting1();
     void testBuildDescendingConnec2Of3DMesh1();
+    void testAre2DCellsNotCorrectlyOriented1();
   };
 }
 
index 5f0fd796ac76f524e755cf8de2cc209c5af37e05..53b0d568e65d1630d4af8df72bbb8510b5b3ae45 100644 (file)
@@ -20,7 +20,7 @@
 
 from MEDCoupling import *
 import unittest
-from math import pi,e,sqrt
+from math import pi,e,sqrt,cos,sin
 from MEDCouplingDataForTest import MEDCouplingDataForTest
 
 class MEDCouplingBasicsTest(unittest.TestCase):
@@ -2079,16 +2079,16 @@ class MEDCouplingBasicsTest(unittest.TestCase):
 
     def testCellOrientation1(self):
         m=MEDCouplingDataForTest.build2DTargetMesh_1();
-        vec=[0.,0.,1.]
+        vec=[0.,0.,-1.]
         self.assertRaises(InterpKernelException,m.are2DCellsNotCorrectlyOriented,vec,False);
         m.changeSpaceDimension(3);
         res1=m.are2DCellsNotCorrectlyOriented(vec,False);
         self.assertTrue(len(res1)==0);
-        vec[2]=-1.;
+        vec[2]=1.;
         res1=m.are2DCellsNotCorrectlyOriented(vec,False);
         self.assertEqual(5,len(res1));
         #
-        vec[2]=1.;
+        vec[2]=-1.;
         # connectivity inversion
         conn=m.getNodalConnectivity().getValues();
         tmp=conn[11];
@@ -2124,7 +2124,7 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         f2Ptr=f2.getArray().getValues();
         #Test to check global reverse in MEDCouplingUMesh::tryToCorrectPolyhedronOrientation
         m3=MEDCouplingDataForTest.build2DTargetMesh_1();
-        vec=[0.,0.,-1.]
+        vec=[0.,0.,1.]
         m3.changeSpaceDimension(3);
         ids2=[0,1,2,3,4]
         m3.convertToPolyTypes(ids2);
@@ -8932,6 +8932,30 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         expected6=[3,8,1,7,3,8,3,1,3,1,3,7,3,7,3,8,3,6,0,8,3,6,2,0,3,0,2,8,3,8,2,6,3,7,4,5,3,7,8,4,3,4,8,5,3,5,8,7,3,6,8,4,3,6,7,8,3,4,7,6,3,8,4,0,3,0,4,6,3,6,3,8,3,7,3,6,3,8,0,1,3,1,0,3,3,3,0,8,3,4,1,5,3,4,8,1,3,1,8,5,3,1,7,5,3,0,2,3,3,3,2,8,3,1,4,0,3,3,2,6]
         self.assertEqual(expected6,conn.getValues());
         pass
+
+    def testAre2DCellsNotCorrectlyOriented1(self):
+        m1Coords=[1.,1.,-1.,-1.,-1.,-1.,1.,-1.]
+        m1Conn=[0,3,1,2]
+        m1=MEDCouplingUMesh.New();
+        m1.setMeshDimension(2);
+        m1.allocateCells(1);
+        m1.insertNextCell(NORM_QUAD4,4,m1Conn[0:4])
+        m1.finishInsertingCells();
+        myCoords1=DataArrayDouble.New();
+        myCoords1.setValues(m1Coords,4,2);
+        m1.setCoords(myCoords1);
+        #
+        vec1=[0.,0.,1.]
+        for i in xrange(18):
+            vec2=[3.*cos(pi/9.*i),3.*sin(pi/9.*i)];
+            m1Cpy=m1.deepCpy();
+            m1Cpy.translate(vec2);
+            self.assertRaises(InterpKernelException,m1Cpy.are2DCellsNotCorrectlyOriented,vec1,False);
+            m1Cpy.changeSpaceDimension(3);
+            res=m1Cpy.are2DCellsNotCorrectlyOriented(vec1,False)
+            self.assertEqual([0],res);
+            pass
+        pass
     
     def setUp(self):
         pass