/*!
- * 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<int>& 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<int>::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<nbOfCells)
+ {
+ 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;
+ else
+ conn[connIndex[*iter]]=INTERP_KERNEL::NORM_QPOLYG;
+ }
else
- conn[connIndex[*iter]]=INTERP_KERNEL::NORM_QPOLYG;
+ {
+ 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());
+ }
}
}
else
const int *connOld=_nodal_connec->getConstPointer();
int connOldLgth=_nodal_connec->getNbOfElems();
std::vector<int> connNew(connOld,connOld+connOldLgth);
- for(std::vector<int>::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<nbOfCells)
{
- INTERP_KERNEL::NormalizedCellType type;
- unsigned offset=cm.fillSonCellNodalConnectivity2(j,&connNew[pos+1],lgthOld,work,type);
- work+=offset;
- *work++=-1;
+ 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++)
+ {
+ INTERP_KERNEL::NormalizedCellType type;
+ unsigned offset=cm.fillSonCellNodalConnectivity2(j,&connNew[pos+1],lgthOld,work,type);
+ work+=offset;
+ *work++=-1;
+ }
+ 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<int>(),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<int>(),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();
std::vector<int> cellIds(nbOfCells);
for(int i=0;i<nbOfCells;i++)
cellIds[i]=i;
- convertToPolyTypes(cellIds);
+ convertToPolyTypes(&cellIds[0],&cellIds[0]+cellIds.size());
}
/*!
MEDCOUPLING_EXPORT bool areCellsEqual1(int cell1, int cell2) const;
MEDCOUPLING_EXPORT bool areCellsEqual2(int cell1, int cell2) const;
MEDCOUPLING_EXPORT bool areCellsFrom2MeshEqual(const MEDCouplingUMesh *other, int cellId, double prec) const;
- MEDCOUPLING_EXPORT void convertToPolyTypes(const std::vector<int>& 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();
//
const int elts[2]={1,3};
std::vector<int> 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());
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());
//
const int elts[2]={1,3};
std::vector<int> eltsV(elts,elts+2);
- mesh->convertToPolyTypes(eltsV);
+ mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
mesh->checkCoherency();
//
desc=DataArrayInt::New();
//
const int elts[2]={1,3};
std::vector<int> eltsV(elts,elts+2);
- mesh->convertToPolyTypes(eltsV);
+ mesh->convertToPolyTypes(&eltsV[0],&eltsV[0]+eltsV.size());
mesh->checkCoherency();
desc=DataArrayInt::New();
descIndx=DataArrayInt::New();
m3->decrRef();
//play with polygons and polyedrons
std::vector<int> 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));
{
MEDCouplingUMesh *m1=build2DTargetMesh_1();
std::vector<int> 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);
std::vector<int> 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);
CPPUNIT_ASSERT_EQUAL(18,m2->getNumberOfCells());
int cellIds[3]={0,6,12};
std::vector<int> cellIds2(cellIds,cellIds+3);
- m2->convertToPolyTypes(cellIds2);
+ m2->convertToPolyTypes(&cellIds2[0],&cellIds2[0]+cellIds2.size());
m2->orientCorrectlyPolyhedrons();
res1.clear();
m2->arePolyhedronsNotCorrectlyOriented(res1);
m3->changeSpaceDimension(3);
const int ids1[5]={0,1,2,3,4};
std::vector<int> 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);
const int elts[8]={0,1,2,3,4,5,6,7};
std::vector<int> 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);
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);
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));
MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
std::vector<int> 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());
//
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());
MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
std::vector<int> 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();
m->checkCoherency1();
const int elts[2]={1,5};
std::vector<int> 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
std::vector<const MEDCouplingUMesh *> ms(4,m);
MEDCouplingUMesh *m2=MEDCouplingUMesh::MergeUMeshesOnSameCoords(ms);
std::vector<int> 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());
std::vector<int> cellsIds(targetMesh->getNumberOfCells());
for(int i=0;i<targetMesh->getNumberOfCells();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);
std::vector<int> cellsIds(sourceMesh->getNumberOfCells());
for(int i=0;i<sourceMesh->getNumberOfCells();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);
std::vector<int> cellsIds(sourceMesh->getNumberOfCells());
for(int i=0;i<sourceMesh->getNumberOfCells();i++)
cellsIds[i]=i;
- sourceMesh->convertToPolyTypes(cellsIds);
+ sourceMesh->convertToPolyTypes(&cellsIds[0],&cellsIds[0]+cellsIds.size());
cellsIds.resize(targetMesh->getNumberOfCells());
for(int i=0;i<targetMesh->getNumberOfCells();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);
std::vector<int> cellsIds(sourceMesh->getNumberOfCells());
for(int i=0;i<sourceMesh->getNumberOfCells();i++)
cellsIds[i]=i;
- sourceMesh->convertToPolyTypes(cellsIds);
+ sourceMesh->convertToPolyTypes(&cellsIds[0],&cellsIds[0]+cellsIds.size());
//
cellsIds.resize(targetMesh->getNumberOfCells());
for(int i=0;i<targetMesh->getNumberOfCells();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);
std::vector<int >cellsIds(targetMesh->getNumberOfCells());
for(int i=0;i<targetMesh->getNumberOfCells();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);
std::vector<int> cellsIds(targetMesh->getNumberOfCells());
for(int i=0;i<targetMesh->getNumberOfCells();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);
std::vector<int> cellsIds(sourceMesh->getNumberOfCells());
for(int i=0;i<sourceMesh->getNumberOfCells();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);
std::vector<int> cellsIds(sourceMesh->getNumberOfCells());
for(int i=0;i<sourceMesh->getNumberOfCells();i++)
cellsIds[i]=i;
- sourceMesh->convertToPolyTypes(cellsIds);
+ sourceMesh->convertToPolyTypes(&cellsIds[0],&cellsIds[0]+cellsIds.size());
cellsIds.resize(targetMesh->getNumberOfCells());
for(int j=0;j<targetMesh->getNumberOfCells();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);