From a947a90405270027ae6e654856dddaca709259f4 Mon Sep 17 00:00:00 2001 From: ageay Date: Wed, 29 Feb 2012 09:21:05 +0000 Subject: [PATCH] More general method API MEDCouplingUMesh::convertToPolyTypes --- src/MEDCoupling/MEDCouplingUMesh.cxx | 78 ++++++++++++------- src/MEDCoupling/MEDCouplingUMesh.hxx | 2 +- .../Test/MEDCouplingBasicsTest1.cxx | 16 ++-- .../Test/MEDCouplingBasicsTest2.cxx | 4 +- .../Test/MEDCouplingBasicsTest3.cxx | 16 ++-- .../Test/MEDCouplingBasicsTest4.cxx | 4 +- .../Test/MEDCouplingBasicsTestInterp.cxx | 22 +++--- 7 files changed, 82 insertions(+), 60 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index af2004fae..c2d6d1d78 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -685,30 +685,43 @@ struct MEDCouplingAccVisit /*! - * This method convert this into dynamic types without changing geometry. + * This method convert cell with ids in ['cellIdsToConvertBg','cellIdsToConvertEnd') into 'this' into dynamic types without changing geometry. * That is to say if 'this' is a 2D, mesh after the invocation of this method it will contain only polygons. * If 'this' is a 3D mesh after the invocation of this method it will contain only polyhedra. * If mesh dimension is not in [2,3] an exception is thrown. * Of course pay attention that the resulting mesh is slower than previous one. + * If in ['cellIdsToConvertBg','cellIdsToConvertEnd') there is a cell id not in [0,'this->getNumberOfCells()') an exception will be thrown. + * In this case if meshDim==2 the mesh is still valid and only cells treated before throw will be converted into polygon. + * If mesh==3, after throw the mesh is \b unconsistent ! * This method is above all designed to test more extensively algorithms able to deal with polygons/polyhedra. */ -void MEDCouplingUMesh::convertToPolyTypes(const std::vector& cellIdsToConvert) +void MEDCouplingUMesh::convertToPolyTypes(const int *cellIdsToConvertBg, const int *cellIdsToConvertEnd) { checkFullyDefined(); int dim=getMeshDimension(); if(dim<2 || dim>3) throw INTERP_KERNEL::Exception("Invalid mesh dimension : must be 2 or 3 !"); + int nbOfCells=getNumberOfCells(); if(dim==2) { const int *connIndex=_nodal_connec_index->getConstPointer(); int *conn=_nodal_connec->getPointer(); - for(std::vector::const_iterator iter=cellIdsToConvert.begin();iter!=cellIdsToConvert.end();iter++) + for(const int *iter=cellIdsToConvertBg;iter!=cellIdsToConvertEnd;iter++) { - const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel((INTERP_KERNEL::NormalizedCellType)conn[connIndex[*iter]]); - if(!cm.isDynamic()) - conn[connIndex[*iter]]=INTERP_KERNEL::NORM_POLYGON; + if(*iter>=0 && *iter& cellIdsToConve const int *connOld=_nodal_connec->getConstPointer(); int connOldLgth=_nodal_connec->getNbOfElems(); std::vector connNew(connOld,connOld+connOldLgth); - for(std::vector::const_iterator iter=cellIdsToConvert.begin();iter!=cellIdsToConvert.end();iter++) + for(const int *iter=cellIdsToConvertBg;iter!=cellIdsToConvertEnd;iter++) { - int pos=connIndex[*iter]; - int posP1=connIndex[(*iter)+1]; - int lgthOld=posP1-pos-1; - const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel((INTERP_KERNEL::NormalizedCellType)connNew[pos]); - connNew[pos]=INTERP_KERNEL::NORM_POLYHED; - unsigned nbOfFaces=cm.getNumberOfSons2(&connNew[pos+1],lgthOld); - int *tmp=new int[nbOfFaces*lgthOld]; - int *work=tmp; - for(int j=0;j<(int)nbOfFaces;j++) + if(*iter>=0 && *iter(),delta)); + connNew.insert(connNew.begin()+posP1,tmp+lgthOld,tmp+newLgth); + std::copy(tmp,tmp+lgthOld,connNew.begin()+pos+1); + delete [] tmp; + } + else + { + std::ostringstream oss; oss << "MEDCouplingUMesh::convertToPolyTypes : On rank #" << std::distance(cellIdsToConvertBg,iter) << " value is " << *iter << " which is not"; + oss << " in range [0," << nbOfCells << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); } - std::size_t newLgth=std::distance(tmp,work)-1; - std::size_t delta=newLgth-lgthOld; - std::transform(connIndex+(*iter)+1,connIndex+connIndexLgth,connIndex+(*iter)+1,std::bind2nd(std::plus(),delta)); - connNew.insert(connNew.begin()+posP1,tmp+lgthOld,tmp+newLgth); - std::copy(tmp,tmp+lgthOld,connNew.begin()+pos+1); - delete [] tmp; } _nodal_connec->alloc((int)connNew.size(),1); int *newConnPtr=_nodal_connec->getPointer(); @@ -760,7 +782,7 @@ void MEDCouplingUMesh::convertAllToPoly() std::vector cellIds(nbOfCells); for(int i=0;i& cellIdsToConvert); + MEDCOUPLING_EXPORT void convertToPolyTypes(const int *cellIdsToConvertBg, const int *cellIdsToConvertEnd); MEDCOUPLING_EXPORT void convertAllToPoly(); MEDCOUPLING_EXPORT void convertExtrudedPolyhedra() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void unPolyze(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx index 6c68a4e4b..00e68c5b0 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx @@ -373,7 +373,7 @@ void MEDCouplingBasicsTest1::testConvertToPolyTypes() // const int elts[2]={1,3}; std::vector eltsV(elts,elts+2); - mesh->convertToPolyTypes(eltsV); + mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size()); mesh->checkCoherency(); CPPUNIT_ASSERT_EQUAL(5,mesh->getNumberOfCells()); CPPUNIT_ASSERT_EQUAL(23,mesh->getNodalConnectivity()->getNumberOfTuples()); @@ -384,11 +384,11 @@ void MEDCouplingBasicsTest1::testConvertToPolyTypes() mesh->decrRef(); ////// 3D mesh=build3DTargetMesh_1(); - mesh->convertToPolyTypes(eltsV); + mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size()); mesh->checkCoherency(); CPPUNIT_ASSERT_EQUAL(8,mesh->getNumberOfCells()); CPPUNIT_ASSERT_EQUAL(114,mesh->getNodalConnectivity()->getNumberOfTuples()); - mesh->convertToPolyTypes(eltsV); + mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size()); mesh->checkCoherency(); CPPUNIT_ASSERT_EQUAL(8,mesh->getNumberOfCells()); CPPUNIT_ASSERT_EQUAL(114,mesh->getNodalConnectivity()->getNumberOfTuples()); @@ -435,7 +435,7 @@ void MEDCouplingBasicsTest1::testDescConn2D() // const int elts[2]={1,3}; std::vector eltsV(elts,elts+2); - mesh->convertToPolyTypes(eltsV); + mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size()); mesh->checkCoherency(); // desc=DataArrayInt::New(); @@ -513,7 +513,7 @@ void MEDCouplingBasicsTest1::testDescConn3D() // const int elts[2]={1,3}; std::vector eltsV(elts,elts+2); - mesh->convertToPolyTypes(eltsV); + mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size()); mesh->checkCoherency(); desc=DataArrayInt::New(); descIndx=DataArrayInt::New(); @@ -1086,7 +1086,7 @@ void MEDCouplingBasicsTest1::testExtrudedMesh3() m3->decrRef(); //play with polygons and polyedrons std::vector cells(2); cells[0]=2; cells[1]=3; - m1->convertToPolyTypes(cells); + m1->convertToPolyTypes(&cells[0],&cells[0]+cells.size()); m3=m1->buildExtrudedMesh(m2,0); CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_HEXA8,(int)m3->getTypeOfCell(0)); CPPUNIT_ASSERT_EQUAL((int)INTERP_KERNEL::NORM_PENTA6,(int)m3->getTypeOfCell(1)); @@ -1116,7 +1116,7 @@ void MEDCouplingBasicsTest1::testExtrudedMesh4() { MEDCouplingUMesh *m1=build2DTargetMesh_1(); std::vector cells(2); cells[0]=2; cells[1]=4; - m1->convertToPolyTypes(cells); + m1->convertToPolyTypes(&cells[0],&cells[0]+cells.size()); m1->changeSpaceDimension(3); MEDCouplingUMesh *m2=buildCU1DMesh_U(); m2->changeSpaceDimension(3); @@ -1317,7 +1317,7 @@ void MEDCouplingBasicsTest1::testMergeMeshOnSameCoords1() std::vector cells(5); for(int i=0;i<5;i++) cells[i]=i; - m2->convertToPolyTypes(cells); + m2->convertToPolyTypes(&cells[0],&cells[0]+cells.size()); m1->tryToShareSameCoords(*m2,1e-12); MEDCouplingUMesh *m3=build2DTargetMesh_1(); m3->tryToShareSameCoords(*m2,1e-12); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx index 9c0e8fcbc..c3a10c5ee 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx @@ -199,7 +199,7 @@ void MEDCouplingBasicsTest2::testCellOrientation2() CPPUNIT_ASSERT_EQUAL(18,m2->getNumberOfCells()); int cellIds[3]={0,6,12}; std::vector cellIds2(cellIds,cellIds+3); - m2->convertToPolyTypes(cellIds2); + m2->convertToPolyTypes(&cellIds2[0],&cellIds2[0]+cellIds2.size()); m2->orientCorrectlyPolyhedrons(); res1.clear(); m2->arePolyhedronsNotCorrectlyOriented(res1); @@ -211,7 +211,7 @@ void MEDCouplingBasicsTest2::testCellOrientation2() m3->changeSpaceDimension(3); const int ids1[5]={0,1,2,3,4}; std::vector ids2(ids1,ids1+5); - m3->convertToPolyTypes(ids2); + m3->convertToPolyTypes(&ids2[0],&ids2[0]+ids2.size()); m3->orientCorrectly2DCells(vec,false); MEDCouplingUMesh *m4=buildCU1DMesh_U(); m4->changeSpaceDimension(3); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx index 19cc8c9eb..b0ed88eed 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx @@ -1169,12 +1169,12 @@ void MEDCouplingBasicsTest3::testUnPolyze1() const int elts[8]={0,1,2,3,4,5,6,7}; std::vector eltsV(elts,elts+8); MEDCouplingUMesh *mesh=build3DTargetMesh_1(); - mesh->convertToPolyTypes(eltsV); + mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size()); mesh->unPolyze(); MEDCouplingUMesh *mesh2=build3DTargetMesh_1(); mesh->checkCoherency(); CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12)); - mesh->convertToPolyTypes(eltsV); + mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size()); CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12)); mesh->getNodalConnectivity()->setIJ(0,6,10); mesh->getNodalConnectivity()->setIJ(0,7,9); @@ -1182,14 +1182,14 @@ void MEDCouplingBasicsTest3::testUnPolyze1() mesh->getNodalConnectivity()->setIJ(0,9,13); mesh->unPolyze(); CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12)); - mesh->convertToPolyTypes(eltsV); + mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size()); mesh->getNodalConnectivity()->setIJ(0,6,12); mesh->getNodalConnectivity()->setIJ(0,7,13); mesh->getNodalConnectivity()->setIJ(0,8,10); mesh->getNodalConnectivity()->setIJ(0,9,9); mesh->unPolyze(); CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12)); - mesh->convertToPolyTypes(eltsV); + mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size()); mesh->getNodalConnectivity()->setIJ(0,6,12); mesh->getNodalConnectivity()->setIJ(0,7,10); mesh->getNodalConnectivity()->setIJ(0,8,13); @@ -1202,7 +1202,7 @@ void MEDCouplingBasicsTest3::testUnPolyze1() mesh=build2DTargetMesh_1(); mesh2=build2DTargetMesh_1(); eltsV.resize(5); - mesh->convertToPolyTypes(eltsV); + mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size()); CPPUNIT_ASSERT(!mesh->isEqual(mesh2,1e-12)); mesh->unPolyze(); CPPUNIT_ASSERT(mesh->isEqual(mesh2,1e-12)); @@ -1550,7 +1550,7 @@ void MEDCouplingBasicsTest3::testSimplexize1() MEDCouplingUMesh *m=build3DSurfTargetMesh_1(); std::vector v(1); v[0]=3; - m->convertToPolyTypes(v); + m->convertToPolyTypes(&v[0],&v[0]+v.size()); DataArrayInt *da=m->simplexize(0); CPPUNIT_ASSERT_EQUAL(7,da->getNumberOfTuples()); CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents()); @@ -1580,7 +1580,7 @@ void MEDCouplingBasicsTest3::testSimplexize1() // m=build3DSurfTargetMesh_1(); v[0]=3; - m->convertToPolyTypes(v); + m->convertToPolyTypes(&v[0],&v[0]+v.size()); da=m->simplexize(1); CPPUNIT_ASSERT_EQUAL(7,da->getNumberOfTuples()); CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents()); @@ -1612,7 +1612,7 @@ void MEDCouplingBasicsTest3::testSimplexize2() MEDCouplingUMesh *m=build3DSurfTargetMesh_1(); std::vector v(1); v[0]=3; - m->convertToPolyTypes(v); + m->convertToPolyTypes(&v[0],&v[0]+v.size()); MEDCouplingFieldDouble *f1=MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME); f1->setMesh(m); DataArrayDouble *arr=DataArrayDouble::New(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx index ad4c6097e..1075bcb9f 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx @@ -906,7 +906,7 @@ void MEDCouplingBasicsTest4::testCheckCoherencyDeeper1() m->checkCoherency1(); const int elts[2]={1,5}; std::vector eltsV(elts,elts+2); - m->convertToPolyTypes(eltsV); + m->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size()); m->checkCoherency(); m->checkCoherency1(); m->getNodalConnectivity()->setIJ(2,0,9);//9>=NbOfNodes @@ -948,7 +948,7 @@ void MEDCouplingBasicsTest4::testUnPolyze2() std::vector ms(4,m); MEDCouplingUMesh *m2=MEDCouplingUMesh::MergeUMeshesOnSameCoords(ms); std::vector temp(1,2); - m2->convertToPolyTypes(temp); + m2->convertToPolyTypes(&temp[0],&temp[0]+temp.size()); m2->unPolyze(); CPPUNIT_ASSERT(INTERP_KERNEL::NORM_TETRA4==m2->getTypeOfCell(2)); CPPUNIT_ASSERT_EQUAL(40,m2->getMeshLength()); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTestInterp.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTestInterp.cxx index e37858cc1..3194bf28c 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTestInterp.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTestInterp.cxx @@ -107,7 +107,7 @@ void MEDCouplingBasicsTestInterp::test2DInterpP0P0PL_2() std::vector cellsIds(targetMesh->getNumberOfCells()); for(int i=0;igetNumberOfCells();i++) cellsIds[i]=i; - targetMesh->convertToPolyTypes(cellsIds); + targetMesh->convertToPolyTypes(&cellsIds[0],&cellsIds[0]+cellsIds.size()); // MEDCouplingNormalizedUnstructuredMesh<2,2> sourceWrapper(sourceMesh); MEDCouplingNormalizedUnstructuredMesh<2,2> targetWrapper(targetMesh); @@ -138,7 +138,7 @@ void MEDCouplingBasicsTestInterp::test2DInterpP0P0PL_3() std::vector cellsIds(sourceMesh->getNumberOfCells()); for(int i=0;igetNumberOfCells();i++) cellsIds[i]=i; - sourceMesh->convertToPolyTypes(cellsIds); + sourceMesh->convertToPolyTypes(&cellsIds[0],&cellsIds[0]+cellsIds.size()); // MEDCouplingNormalizedUnstructuredMesh<2,2> sourceWrapper(sourceMesh); MEDCouplingNormalizedUnstructuredMesh<2,2> targetWrapper(targetMesh); @@ -169,11 +169,11 @@ void MEDCouplingBasicsTestInterp::test2DInterpP0P0PL_4() std::vector cellsIds(sourceMesh->getNumberOfCells()); for(int i=0;igetNumberOfCells();i++) cellsIds[i]=i; - sourceMesh->convertToPolyTypes(cellsIds); + sourceMesh->convertToPolyTypes(&cellsIds[0],&cellsIds[0]+cellsIds.size()); cellsIds.resize(targetMesh->getNumberOfCells()); for(int i=0;igetNumberOfCells();i++) cellsIds[i]=i; - targetMesh->convertToPolyTypes(cellsIds); + targetMesh->convertToPolyTypes(&cellsIds[0],&cellsIds[0]+cellsIds.size()); // MEDCouplingNormalizedUnstructuredMesh<2,2> sourceWrapper(sourceMesh); MEDCouplingNormalizedUnstructuredMesh<2,2> targetWrapper(targetMesh); @@ -272,12 +272,12 @@ void MEDCouplingBasicsTestInterp::test2DInterpP0P1PL_2() std::vector cellsIds(sourceMesh->getNumberOfCells()); for(int i=0;igetNumberOfCells();i++) cellsIds[i]=i; - sourceMesh->convertToPolyTypes(cellsIds); + sourceMesh->convertToPolyTypes(&cellsIds[0],&cellsIds[0]+cellsIds.size()); // cellsIds.resize(targetMesh->getNumberOfCells()); for(int i=0;igetNumberOfCells();i++) cellsIds[i]=i; - targetMesh->convertToPolyTypes(cellsIds); + targetMesh->convertToPolyTypes(&cellsIds[0],&cellsIds[0]+cellsIds.size()); // MEDCouplingNormalizedUnstructuredMesh<2,2> sourceWrapper(sourceMesh); MEDCouplingNormalizedUnstructuredMesh<2,2> targetWrapper(targetMesh); @@ -384,7 +384,7 @@ void MEDCouplingBasicsTestInterp::test2DInterpP1P0PL_2() std::vectorcellsIds(targetMesh->getNumberOfCells()); for(int i=0;igetNumberOfCells();i++) cellsIds[i]=i; - targetMesh->convertToPolyTypes(cellsIds); + targetMesh->convertToPolyTypes(&cellsIds[0],&cellsIds[0]+cellsIds.size()); // MEDCouplingNormalizedUnstructuredMesh<2,2> sourceWrapper(sourceMesh); MEDCouplingNormalizedUnstructuredMesh<2,2> targetWrapper(targetMesh); @@ -1039,7 +1039,7 @@ void MEDCouplingBasicsTestInterp::test3DInterpP0P0PL_2() std::vector cellsIds(targetMesh->getNumberOfCells()); for(int i=0;igetNumberOfCells();i++) cellsIds[i]=i; - targetMesh->convertToPolyTypes(cellsIds); + targetMesh->convertToPolyTypes(&cellsIds[0],&cellsIds[0]+cellsIds.size()); // MEDCouplingNormalizedUnstructuredMesh<3,3> sourceWrapper(sourceMesh); MEDCouplingNormalizedUnstructuredMesh<3,3> targetWrapper(targetMesh); @@ -1089,7 +1089,7 @@ void MEDCouplingBasicsTestInterp::test3DInterpP0P0PL_3() std::vector cellsIds(sourceMesh->getNumberOfCells()); for(int i=0;igetNumberOfCells();i++) cellsIds[i]=i; - sourceMesh->convertToPolyTypes(cellsIds); + sourceMesh->convertToPolyTypes(&cellsIds[0],&cellsIds[0]+cellsIds.size()); // MEDCouplingNormalizedUnstructuredMesh<3,3> sourceWrapper(sourceMesh); MEDCouplingNormalizedUnstructuredMesh<3,3> targetWrapper(targetMesh); @@ -1139,11 +1139,11 @@ void MEDCouplingBasicsTestInterp::test3DInterpP0P0PL_4() std::vector cellsIds(sourceMesh->getNumberOfCells()); for(int i=0;igetNumberOfCells();i++) cellsIds[i]=i; - sourceMesh->convertToPolyTypes(cellsIds); + sourceMesh->convertToPolyTypes(&cellsIds[0],&cellsIds[0]+cellsIds.size()); cellsIds.resize(targetMesh->getNumberOfCells()); for(int j=0;jgetNumberOfCells();j++) cellsIds[j]=j; - targetMesh->convertToPolyTypes(cellsIds); + targetMesh->convertToPolyTypes(&cellsIds[0],&cellsIds[0]+cellsIds.size()); // MEDCouplingNormalizedUnstructuredMesh<3,3> sourceWrapper(sourceMesh); MEDCouplingNormalizedUnstructuredMesh<3,3> targetWrapper(targetMesh); -- 2.39.2