From: ageay Date: Wed, 29 Feb 2012 07:41:54 +0000 (+0000) Subject: Correction of big bug on 3DSurf cell orientation. X-Git-Tag: V6_main_FINAL~817 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=08a5e2b53de3924419fb6e374a0036ed6442fd2d;p=tools%2Fmedcoupling.git Correction of big bug on 3DSurf cell orientation. --- diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 1af037e16..af2004fae 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -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.; } /*! diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx index 87ed986e5..9c0e8fcbc 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx @@ -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 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 ids2(ids1,ids1+5); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx index a324e1f2f..79b351c66 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx @@ -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(m1->deepCpy()); + m1Cpy->translate(vec2); + std::vector 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(); +} diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx index e7ec0077e..1252226e3 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx @@ -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(); }; } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 5f0fd796a..53b0d568e 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -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