]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
MEDCouplingUMesh::getAllGeoTypesSorted
authorageay <ageay>
Fri, 29 Nov 2013 15:29:35 +0000 (15:29 +0000)
committerageay <ageay>
Fri, 29 Nov 2013 15:29:35 +0000 (15:29 +0000)
src/MEDCoupling/MEDCouplingUMesh.cxx
src/MEDCoupling/MEDCouplingUMesh.hxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
src/MEDCoupling_Swig/MEDCouplingCommon.i

index f6f92895cff3a0877b8694879fdf0cdf3c4e2cb2..d53794748336f7e20a66328b38fe5098d304f6f7 100644 (file)
@@ -419,12 +419,39 @@ MEDCouplingUMeshCellByTypeEntry *MEDCouplingUMesh::cellsByType()
  * Returns a set of all cell types available in \a this mesh.
  * \return std::set<INTERP_KERNEL::NormalizedCellType> - 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<INTERP_KERNEL::NormalizedCellType> 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<INTERP_KERNEL::NormalizedCellType> MEDCouplingUMesh::getAllGeoTypesSorted() const
+{
+  std::vector<INTERP_KERNEL::NormalizedCellType> 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<nbOfCells;i++,ci++)
+    if(ret.back()!=((INTERP_KERNEL::NormalizedCellType)c[*ci]))
+      ret.push_back((INTERP_KERNEL::NormalizedCellType)c[*ci]);
+  return ret;
+}
+
 /*!
  * This method is a method that compares \a this and \a other.
  * This method compares \b all attributes, even names and component names.
index 24e8583dc34d8ccec3ad6f1a72756af40e795b8e..75b0a7ceaf24266830701fd61eef8f3c0cc1466b 100644 (file)
@@ -62,6 +62,7 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT MEDCouplingUMeshCellIterator *cellIterator();
     MEDCOUPLING_EXPORT MEDCouplingUMeshCellByTypeEntry *cellsByType();
     MEDCOUPLING_EXPORT std::set<INTERP_KERNEL::NormalizedCellType> getAllGeoTypes() const;
+    MEDCOUPLING_EXPORT std::vector<INTERP_KERNEL::NormalizedCellType> getAllGeoTypesSorted() const;
     MEDCOUPLING_EXPORT std::set<INTERP_KERNEL::NormalizedCellType> 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; }
index 9d42c86b74eed2aa7f086fea0943472fb7f7441c..cb3168eedd3cae273750a319c034fd7ffa28aa7c 100644 (file)
@@ -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.]
index 94f2be6aa2f3de893083e38cf6911e0c1d71fd10..250d034f49baa418bf5b74084f26a442a0bac734 100644 (file)
@@ -1566,6 +1566,16 @@ namespace ParaMEDMEM
       {
         return self->cellIterator();
       }
+
+      PyObject *getAllGeoTypesSorted() const throw(INTERP_KERNEL::Exception)
+      {
+        std::vector<INTERP_KERNEL::NormalizedCellType> result=self->getAllGeoTypesSorted();
+        std::vector<INTERP_KERNEL::NormalizedCellType>::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)
       {