From: Anthony Geay Date: Thu, 2 Jan 2020 09:57:01 +0000 (+0100) Subject: Get rid of conversion array duplication X-Git-Tag: V9_5_0a1~16 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=892905eb7616b0626cd74b24c50b6ca5973a01f0;p=tools%2Fmedcoupling.git Get rid of conversion array duplication --- diff --git a/src/INTERP_KERNEL/CellModel.cxx b/src/INTERP_KERNEL/CellModel.cxx index cf71d3a61..acb6c0bfa 100644 --- a/src/INTERP_KERNEL/CellModel.cxx +++ b/src/INTERP_KERNEL/CellModel.cxx @@ -29,6 +29,8 @@ #include #include +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 diff --git a/src/INTERP_KERNEL/CellModel.hxx b/src/INTERP_KERNEL/CellModel.hxx index 369791950..a221be52e 100644 --- a/src/INTERP_KERNEL/CellModel.hxx +++ b/src/INTERP_KERNEL/CellModel.hxx @@ -28,6 +28,12 @@ #include +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; diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 05eaf2661..b764904fe 100755 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -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 medcoupling2vtkTypeTraducer_mcIdType(new mcIdType[MEDCOUPLING2VTKTYPETRADUCER_LGTH]); + for(auto ii = 0; iitransformWithIndArr(medcoupling2vtkTypeTraducer_mcIdType.get(),medcoupling2vtkTypeTraducer_mcIdType.get()+MEDCOUPLING2VTKTYPETRADUCER_LGTH); types->writeVTK(ofs,8,"UInt8","types",byteData); std::string vtkTypeName = Traits::VTKReprStr; offsets->writeVTK(ofs,8,vtkTypeName,"offsets",byteData); diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index 87a1c9a7d..35d0cc5fb 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -359,7 +359,6 @@ namespace MEDCoupling MEDCOUPLING_EXPORT static DataArrayIdType *ComputeRangesFromTypeDistribution(const std::vector& 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; diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index a79ce8306..184143765 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -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 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; } // diff --git a/src/MEDLoader/MEDFileEquivalence.cxx b/src/MEDLoader/MEDFileEquivalence.cxx index bbc44b6df..61316181e 100644 --- a/src/MEDLoader/MEDFileEquivalence.cxx +++ b/src/MEDLoader/MEDFileEquivalence.cxx @@ -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; diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 61bceea4a..0193d138d 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -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; diff --git a/src/MEDLoader/MEDFileFieldInternal.cxx b/src/MEDLoader/MEDFileFieldInternal.cxx index 1d687b19d..d482dce60 100644 --- a/src/MEDLoader/MEDFileFieldInternal.cxx +++ b/src/MEDLoader/MEDFileFieldInternal.cxx @@ -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,§iongeotype); _dim=FromMedInt(dim); _nb_gauss_pt=FromMedInt(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(); } diff --git a/src/MEDLoader/MEDFileFieldOverView.cxx b/src/MEDLoader/MEDFileFieldOverView.cxx index 79545ebf8..0a8265e72 100644 --- a/src/MEDLoader/MEDFileFieldOverView.cxx +++ b/src/MEDLoader/MEDFileFieldOverView.cxx @@ -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}; diff --git a/src/MEDLoader/MEDFileFieldOverView.hxx b/src/MEDLoader/MEDFileFieldOverView.hxx index b59d3cccb..f6a382b42 100644 --- a/src/MEDLoader/MEDFileFieldOverView.hxx +++ b/src/MEDLoader/MEDFileFieldOverView.hxx @@ -120,8 +120,8 @@ namespace MEDCoupling MCAuto _node_fam_ids; MCAuto _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]; }; diff --git a/src/MEDLoader/MEDFileJoint.cxx b/src/MEDLoader/MEDFileJoint.cxx index af5ea9d17..2bfb1a880 100644 --- a/src/MEDLoader/MEDFileJoint.cxx +++ b/src/MEDLoader/MEDFileJoint.cxx @@ -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; diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index b45e6f7e8..b74224efb 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -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; diff --git a/src/MEDLoader/MEDFileMeshElt.cxx b/src/MEDLoader/MEDFileMeshElt.cxx index 96982a4b1..83bf15a2a 100644 --- a/src/MEDLoader/MEDFileMeshElt.cxx +++ b/src/MEDLoader/MEDFileMeshElt.cxx @@ -31,7 +31,7 @@ #include -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; diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index 07d3e9393..5a1124b89 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -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;