From: ageay Date: Fri, 29 Nov 2013 15:29:35 +0000 (+0000) Subject: MEDCouplingUMesh::getAllGeoTypesSorted X-Git-Tag: V7_3_0b1~17 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=de4d3ca57902ce21362c7c8f4d441cd16fd7e31f;p=modules%2Fmed.git MEDCouplingUMesh::getAllGeoTypesSorted --- diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index f6f92895c..d53794748 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -419,12 +419,39 @@ MEDCouplingUMeshCellByTypeEntry *MEDCouplingUMesh::cellsByType() * Returns a set of all cell types available in \a this mesh. * \return std::set - the set of cell types. * \warning this method does not throw any exception even if \a this is not defined. + * \sa MEDCouplingUMesh::getAllGeoTypesSorted */ std::set MEDCouplingUMesh::getAllGeoTypes() const { return _types; } +/*! + * This method returns the sorted list of geometric types in \a this. + * Sorted means in the same order than the cells in \a this. A single entry in return vector means the maximal chunk of consecutive cells in \a this + * having the same geometric type. So a same geometric type can appear more than once if the cells are not sorted per geometric type. + * + * \throw if connectivity in \a this is not correctly defined. + * + * \sa MEDCouplingMesh::getAllGeoTypes + */ +std::vector MEDCouplingUMesh::getAllGeoTypesSorted() const +{ + std::vector ret; + checkConnectivityFullyDefined(); + int nbOfCells(getNumberOfCells()); + if(nbOfCells==0) + return ret; + if(getMeshLength()<1) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::getAllGeoTypesSorted : the connectivity in this seems invalid !"); + const int *c(_nodal_connec->begin()),*ci(_nodal_connec_index->begin()); + ret.push_back((INTERP_KERNEL::NormalizedCellType)c[*ci++]); + for(int i=1;i getAllGeoTypes() const; + MEDCOUPLING_EXPORT std::vector getAllGeoTypesSorted() const; MEDCOUPLING_EXPORT std::set getTypesOfPart(const int *begin, const int *end) const; MEDCOUPLING_EXPORT void setConnectivity(DataArrayInt *conn, DataArrayInt *connIndex, bool isComputingTypes=true); MEDCOUPLING_EXPORT const DataArrayInt *getNodalConnectivity() const { return _nodal_connec; } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 9d42c86b7..cb3168eed 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -11046,9 +11046,13 @@ class MEDCouplingBasicsTest(unittest.TestCase): m=MEDCouplingUMesh("toto",3) m.allocateCells(0) m.insertNextCell(NORM_TETRA4,[0,1,2,3]) + self.assertEqual([NORM_TETRA4],m.getAllGeoTypesSorted()) m.insertNextCell(NORM_HEXA8,[4,5,6,7,8,9,10,11]) + self.assertEqual([NORM_TETRA4,NORM_HEXA8],m.getAllGeoTypesSorted()) m.insertNextCell(NORM_HEXA8,[12,13,14,15,16,17,18,19]) + self.assertEqual([NORM_TETRA4,NORM_HEXA8],m.getAllGeoTypesSorted()) m.insertNextCell(NORM_TETRA4,[20,21,22,23]) + self.assertEqual([NORM_TETRA4,NORM_HEXA8,NORM_TETRA4],m.getAllGeoTypesSorted()) c1=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,0.,0.,0.,0.,1.],4,3) c2=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,1.,0.,1.,0.,0., 0.,0.,1.,0.,1.,1.,1.,1.,1.,1.,0.,1.],8,3) ; c2+=[2.,0.,0.] c3=c2+[2.,0.,0.] diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 94f2be6aa..250d034f4 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -1566,6 +1566,16 @@ namespace ParaMEDMEM { return self->cellIterator(); } + + PyObject *getAllGeoTypesSorted() const throw(INTERP_KERNEL::Exception) + { + std::vector result=self->getAllGeoTypesSorted(); + std::vector::const_iterator iL=result.begin(); + PyObject *res=PyList_New(result.size()); + for(int i=0;iL!=result.end(); i++, iL++) + PyList_SetItem(res,i,PyInt_FromLong(*iL)); + return res; + } void setPartOfMySelf(PyObject *li, const MEDCouplingUMesh& otherOnSameCoordsThanThis) throw(INTERP_KERNEL::Exception) {