]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Get rid of conversion array duplication
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 2 Jan 2020 09:57:01 +0000 (10:57 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 2 Jan 2020 09:57:01 +0000 (10:57 +0100)
14 files changed:
src/INTERP_KERNEL/CellModel.cxx
src/INTERP_KERNEL/CellModel.hxx
src/MEDCoupling/MEDCouplingUMesh.cxx
src/MEDCoupling/MEDCouplingUMesh.hxx
src/MEDCoupling_Swig/MEDCouplingCommon.i
src/MEDLoader/MEDFileEquivalence.cxx
src/MEDLoader/MEDFileField.cxx
src/MEDLoader/MEDFileFieldInternal.cxx
src/MEDLoader/MEDFileFieldOverView.cxx
src/MEDLoader/MEDFileFieldOverView.hxx
src/MEDLoader/MEDFileJoint.cxx
src/MEDLoader/MEDFileMesh.cxx
src/MEDLoader/MEDFileMeshElt.cxx
src/MEDLoader/MEDLoader.cxx

index cf71d3a61eadc5e3cc4e65f1fc513d7b330a1842..acb6c0bfa4e37f8df8a9a81ade01f5badc1e6cfa 100644 (file)
@@ -29,6 +29,8 @@
 #include <vector>
 #include <limits>
 
+unsigned char MEDCOUPLING2VTKTYPETRADUCER[INTERP_KERNEL::NORM_MAXTYPE+1]={1,3,21,5,9,7,22,34,23,28,35,MEDCOUPLING2VTKTYPETRADUCER_NONE,MEDCOUPLING2VTKTYPETRADUCER_NONE,MEDCOUPLING2VTKTYPETRADUCER_NONE,10,14,13,MEDCOUPLING2VTKTYPETRADUCER_NONE,12,MEDCOUPLING2VTKTYPETRADUCER_NONE,24,MEDCOUPLING2VTKTYPETRADUCER_NONE,16,27,MEDCOUPLING2VTKTYPETRADUCER_NONE,26,MEDCOUPLING2VTKTYPETRADUCER_NONE,29,32,MEDCOUPLING2VTKTYPETRADUCER_NONE,25,42,36,4};
+
 namespace INTERP_KERNEL
 {
   const char *CellModel::CELL_TYPES_REPR[]={"NORM_POINT1", "NORM_SEG2", "NORM_SEG3", "NORM_TRI3", "NORM_QUAD4",// 0->4
index 369791950074854412c68b14ebb60d528f4c22b3..a221be52e6ac452afab26c24aa109c9273e14ce0 100644 (file)
 
 #include <map>
 
+constexpr int MEDCOUPLING2VTKTYPETRADUCER_LGTH=INTERP_KERNEL::NORM_MAXTYPE+1;
+
+constexpr unsigned char MEDCOUPLING2VTKTYPETRADUCER_NONE = 255;
+
+INTERPKERNEL_EXPORT extern unsigned char MEDCOUPLING2VTKTYPETRADUCER[INTERP_KERNEL::NORM_MAXTYPE+1];
+
 namespace INTERP_KERNEL
 {
   class DiameterCalculator;
index 05eaf2661ff20381fc6c6d5738560d04e8cd5249..b764904fee4c0823f8c1fea2ba7542b27b4b679c 100755 (executable)
@@ -47,6 +47,7 @@
 #include <sstream>
 #include <fstream>
 #include <numeric>
+#include <memory>
 #include <cstring>
 #include <limits>
 #include <list>
@@ -56,8 +57,8 @@ using namespace MEDCoupling;
 double MEDCouplingUMesh::EPS_FOR_POLYH_ORIENTATION=1.e-14;
 
 /// @cond INTERNAL
+
 const INTERP_KERNEL::NormalizedCellType MEDCouplingUMesh::MEDMEM_ORDER[N_MEDMEM_ORDER] = { INTERP_KERNEL::NORM_POINT1, INTERP_KERNEL::NORM_SEG2, INTERP_KERNEL::NORM_SEG3, INTERP_KERNEL::NORM_SEG4, INTERP_KERNEL::NORM_POLYL, INTERP_KERNEL::NORM_TRI3, INTERP_KERNEL::NORM_QUAD4, INTERP_KERNEL::NORM_TRI6, INTERP_KERNEL::NORM_TRI7, INTERP_KERNEL::NORM_QUAD8, INTERP_KERNEL::NORM_QUAD9, INTERP_KERNEL::NORM_POLYGON, INTERP_KERNEL::NORM_QPOLYG, INTERP_KERNEL::NORM_TETRA4, INTERP_KERNEL::NORM_PYRA5, INTERP_KERNEL::NORM_PENTA6, INTERP_KERNEL::NORM_HEXA8, INTERP_KERNEL::NORM_HEXGP12, INTERP_KERNEL::NORM_TETRA10, INTERP_KERNEL::NORM_PYRA13, INTERP_KERNEL::NORM_PENTA15, INTERP_KERNEL::NORM_PENTA18, INTERP_KERNEL::NORM_HEXA20, INTERP_KERNEL::NORM_HEXA27, INTERP_KERNEL::NORM_POLYHED };
-const mcIdType MEDCouplingUMesh::MEDCOUPLING2VTKTYPETRADUCER[INTERP_KERNEL::NORM_MAXTYPE+1]={1,3,21,5,9,7,22,34,23,28,-1,-1,-1,-1,10,14,13,-1,12,-1,24,-1,16,27,-1,26,-1,29,32,-1,25,42,36,4};
 /// @endcond
 
 MEDCouplingUMesh *MEDCouplingUMesh::New()
@@ -7562,7 +7563,10 @@ void MEDCouplingUMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData
           w4=std::copy(c.begin(),c.end(),w4);
         }
     }
-  types->transformWithIndArr(MEDCOUPLING2VTKTYPETRADUCER,MEDCOUPLING2VTKTYPETRADUCER+INTERP_KERNEL::NORM_MAXTYPE+1);
+  std::unique_ptr<mcIdType[]> medcoupling2vtkTypeTraducer_mcIdType(new mcIdType[MEDCOUPLING2VTKTYPETRADUCER_LGTH]);
+  for(auto ii = 0; ii<MEDCOUPLING2VTKTYPETRADUCER_LGTH ; ++ii)
+    medcoupling2vtkTypeTraducer_mcIdType[ii] = MEDCOUPLING2VTKTYPETRADUCER[ii]!=MEDCOUPLING2VTKTYPETRADUCER_NONE?MEDCOUPLING2VTKTYPETRADUCER[ii] : -1;
+  types->transformWithIndArr(medcoupling2vtkTypeTraducer_mcIdType.get(),medcoupling2vtkTypeTraducer_mcIdType.get()+MEDCOUPLING2VTKTYPETRADUCER_LGTH);
   types->writeVTK(ofs,8,"UInt8","types",byteData);
   std::string vtkTypeName = Traits<mcIdType>::VTKReprStr;
   offsets->writeVTK(ofs,8,vtkTypeName,"offsets",byteData);
index 87a1c9a7d8a2c9d08013e9119fe22ff39805a2ed..35d0cc5fb3c22f95461e5e3e2e0514b3066ea478 100644 (file)
@@ -359,7 +359,6 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT static DataArrayIdType *ComputeRangesFromTypeDistribution(const std::vector<mcIdType>& code);
     MEDCOUPLING_EXPORT static const int N_MEDMEM_ORDER=25;
     MEDCOUPLING_EXPORT static const INTERP_KERNEL::NormalizedCellType MEDMEM_ORDER[N_MEDMEM_ORDER];
-    MEDCOUPLING_EXPORT static const mcIdType MEDCOUPLING2VTKTYPETRADUCER[INTERP_KERNEL::NORM_MAXTYPE+1];
     /// @endcond
   private:
     int _mesh_dim;
index a79ce8306208a0c04ffe58d7adee8db14cbd86d2..184143765e704762cd0d6f3faae20a6174eb4d16 100644 (file)
@@ -529,25 +529,26 @@ typedef DataArrayInt64 DataArrayIdType;
 {
   PyObject *med2vtk_cell_types()
   {
-    Py_ssize_t sz(sizeof(MEDCouplingUMesh::MEDCOUPLING2VTKTYPETRADUCER)/sizeof(decltype(MEDCouplingUMesh::MEDCOUPLING2VTKTYPETRADUCER[0])));
+    Py_ssize_t sz(sizeof(MEDCOUPLING2VTKTYPETRADUCER)/sizeof(decltype(MEDCOUPLING2VTKTYPETRADUCER[0])));
     PyObject *ret(PyList_New(sz));
     for(Py_ssize_t i=0;i<sz;i++)
       {
-        PyList_SetItem(ret,i,PyInt_FromLong(MEDCouplingUMesh::MEDCOUPLING2VTKTYPETRADUCER[i]));
+        mcIdType elt = MEDCOUPLING2VTKTYPETRADUCER[i]!=255 ? MEDCOUPLING2VTKTYPETRADUCER[i] : -1;
+        PyList_SetItem(ret,i,PyInt_FromLong(elt));
       }
     return ret;
   }
 
   PyObject *vtk2med_cell_types()
   {
-    Py_ssize_t sz(sizeof(MEDCouplingUMesh::MEDCOUPLING2VTKTYPETRADUCER)/sizeof(decltype(MEDCouplingUMesh::MEDCOUPLING2VTKTYPETRADUCER[0])));
-    auto maxElt(*std::max_element(MEDCouplingUMesh::MEDCOUPLING2VTKTYPETRADUCER,MEDCouplingUMesh::MEDCOUPLING2VTKTYPETRADUCER+sz));
+    Py_ssize_t sz(sizeof(MEDCOUPLING2VTKTYPETRADUCER)/sizeof(decltype(MEDCOUPLING2VTKTYPETRADUCER[0])));
+    auto maxElt(*std::max_element(MEDCOUPLING2VTKTYPETRADUCER,MEDCOUPLING2VTKTYPETRADUCER+sz,[](unsigned char a, unsigned char b) { if(b==MEDCOUPLING2VTKTYPETRADUCER_NONE) return false; else return a<b; } ));
     auto szOut(maxElt+1);
     std::vector< mcIdType > retCpp(szOut,-1);
     mcIdType id(0);
-    for(const mcIdType *it=MEDCouplingUMesh::MEDCOUPLING2VTKTYPETRADUCER;it!=MEDCouplingUMesh::MEDCOUPLING2VTKTYPETRADUCER+sz;it++,id++)
+    for(const unsigned char *it=MEDCOUPLING2VTKTYPETRADUCER;it!=MEDCOUPLING2VTKTYPETRADUCER+sz;it++,id++)
       {
-        if(*it!=-1)
+        if(*it!=MEDCOUPLING2VTKTYPETRADUCER_NONE)
           retCpp[*it]=id;
       }
     //
index bbc44b6dfb8dd69d96ee8d8f7fe44a83a8fc24b5..61316181e7c7cf3327effb76e29c9db677e129b8 100644 (file)
@@ -28,7 +28,7 @@
 
 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
-extern med_geometry_type typmai3[34];
+extern med_geometry_type typmai3[INTERP_KERNEL::NORM_MAXTYPE];
 extern med_geometry_type typmainoeud[1];
 
 using namespace MEDCoupling;
index 61bceea4a2f4fdfac553130a40434921ef92c64d..0193d138d7e5a3d400d046559b447f07b46b4313 100644 (file)
@@ -37,7 +37,7 @@
 
 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
 extern med_geometry_type typmainoeud[1];
-extern med_geometry_type typmai3[34];
+extern med_geometry_type typmai3[INTERP_KERNEL::NORM_MAXTYPE];
 
 using namespace MEDCoupling;
 
index 1d687b19db204755af87c619e53b1e5ebebe4ca6..d482dce60c47d3d70f0fbd6d63cbb014e52179b3 100644 (file)
@@ -34,7 +34,7 @@
 
 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
-extern med_geometry_type typmai3[34];
+extern med_geometry_type typmai3[INTERP_KERNEL::NORM_MAXTYPE];
 
 using namespace MEDCoupling;
 
@@ -127,7 +127,7 @@ MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const std::string& locName):_name(
   MEDlocalizationInfoByName(fid,locName.c_str(),&geotype,&dim,&nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,&sectiongeotype);
   _dim=FromMedInt<int>(dim);
   _nb_gauss_pt=FromMedInt<int>(nb_gauss_pt);
-  _gt=new MEDFileGTKeeperSta((INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype))));
+  _gt=new MEDFileGTKeeperSta((INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+INTERP_KERNEL::NORM_MAXTYPE,geotype))));
   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
   _nb_node_per_cell=cm.getNumberOfNodes();
   _ref_coo.resize(_dim*_nb_node_per_cell);
@@ -151,7 +151,7 @@ MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, int id, const MEDFileEntities *ent
   std::string sectionName(MEDLoaderBase::buildStringFromFortran(sectionmeshname,MED_NAME_SIZE));
   if(sectionName.empty())
     {
-      _gt=new MEDFileGTKeeperSta((INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+34,geotype))));
+      _gt=new MEDFileGTKeeperSta((INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+INTERP_KERNEL::NORM_MAXTYPE,geotype))));
       const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getGeoType()));
       _nb_node_per_cell=cm.getNumberOfNodes();
     }
index 79545ebf86365279d87b68a358fd954f2f97a5e6..0a8265e7279c24524cddc2024146d043c4e115bf 100644 (file)
@@ -27,8 +27,7 @@
 
 using namespace MEDCoupling;
 
-const unsigned char MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE[MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE_LGTH]=
-{1,3,21,5,9,7,22,34,23,28,35,255,255,255,10,14,13,255,12,255,24,255,16,27,255,26,255,29,32,255,25,42,36,4};
+const unsigned char *MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE=MEDCOUPLING2VTKTYPETRADUCER;
 
 const unsigned char MEDMeshMultiLev::HEXA27_PERM_ARRAY[27]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,24,22,21,23,20,25,26};
 
index b59d3cccb2f8b3e7231364d578098963377c55aa..f6a382b42207ab50b860bfa00d4d11183cc4b5ea 100644 (file)
@@ -120,8 +120,8 @@ namespace MEDCoupling
     MCAuto<DataArrayIdType> _node_fam_ids;
     MCAuto<DataArrayIdType> _node_num_ids;
   public:
-    MEDLOADER_EXPORT static const int PARAMEDMEM_2_VTKTYPE_LGTH=34;
-    MEDLOADER_EXPORT static const unsigned char PARAMEDMEM_2_VTKTYPE[PARAMEDMEM_2_VTKTYPE_LGTH];
+    MEDLOADER_EXPORT static const int PARAMEDMEM_2_VTKTYPE_LGTH=MEDCOUPLING2VTKTYPETRADUCER_LGTH;
+    MEDLOADER_EXPORT static const unsigned char *PARAMEDMEM_2_VTKTYPE;
     MEDLOADER_EXPORT static const unsigned char HEXA27_PERM_ARRAY[27];
   };
 
index af5ea9d17360c4f6a0ab69dd5d2bfd4cc927fe0d..2bfb1a880e0dd9792b2350299fd5d3074861685b 100644 (file)
@@ -28,7 +28,7 @@
 
 extern med_geometry_type                 typmai[MED_N_CELL_FIXED_GEO];
 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
-extern med_geometry_type                 typmai3[34];
+extern med_geometry_type                 typmai3[INTERP_KERNEL::NORM_MAXTYPE];
 
 using namespace MEDCoupling;
 
index b45e6f7e80b7d50411c06558277a41e199f31aac..b74224efbbad74f6a07f1a98d3301ff4445e04b2 100644 (file)
@@ -37,7 +37,7 @@
 
 extern med_geometry_type                 typmai[MED_N_CELL_FIXED_GEO];
 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
-extern med_geometry_type typmai3[34];
+extern med_geometry_type typmai3[INTERP_KERNEL::NORM_MAXTYPE];
 
 using namespace MEDCoupling;
 
index 96982a4b18adf18907c2486887fe8432768df9ad..83bf15a2a08d78685f95ec74ed270b4725f31147 100644 (file)
@@ -31,7 +31,7 @@
 
 #include <iostream>
 
-extern med_geometry_type typmai3[34];
+extern med_geometry_type typmai3[INTERP_KERNEL::NORM_MAXTYPE];
 
 using namespace MEDCoupling;
 
@@ -108,7 +108,7 @@ MEDFileUMeshPerType *MEDFileUMeshPerType::New(med_idt fid, const char *mName, in
 MEDFileUMeshPerType *MEDFileUMeshPerType::NewPart(med_idt fid, const char *mName, int dt, int it, int mdim, INTERP_KERNEL::NormalizedCellType geoElt2, mcIdType strt, mcIdType stp, mcIdType step, MEDFileMeshReadSelector *mrs)
 {
   int geoElt2i((int)geoElt2);
-  if(geoElt2i<0 || geoElt2i>=34)
+  if(geoElt2i<0 || geoElt2i>=INTERP_KERNEL::NORM_MAXTYPE)
     throw INTERP_KERNEL::Exception("MEDFileUMeshPerType::NewPart : Not recognized MEDCoupling/MEDLoader geometric type !");
   med_geometry_type geoElt(typmai3[geoElt2]);
   med_entity_type whichEntity;
index 07d3e939303ae91c27ad3f7c39bae035f8d70f48..5a1124b894f5ddfdb6c1970b8bda87146b75a806 100644 (file)
@@ -101,7 +101,7 @@ INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNE
   INTERP_KERNEL::NORM_QPOLYG,
   INTERP_KERNEL::NORM_POLYHED };
 
-med_geometry_type typmai3[34] = { MED_POINT1,//0
+med_geometry_type typmai3[INTERP_KERNEL::NORM_MAXTYPE] = { MED_POINT1,//0
   MED_SEG2,//1
   MED_SEG3,//2
   MED_TRIA3,//3
@@ -133,8 +133,7 @@ med_geometry_type typmai3[34] = { MED_POINT1,//0
   MED_NONE,//29
   MED_HEXA20,//30
   MED_POLYHEDRON,//31
-  MED_POLYGON2,//32
-  MED_NONE//33
+  MED_POLYGON2//32
 };
 
 double _EPS_FOR_NODE_COMP=1.e-12;