From: geay Date: Mon, 17 Feb 2014 10:41:21 +0000 (+0100) Subject: lack of display of geo types in the tree in new MEDReader. Add methods for informatio... X-Git-Tag: V7_3_1b1^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0a847a1b6a16f602a5efd7832b81a44a51fa7150;p=tools%2Fmedcoupling.git lack of display of geo types in the tree in new MEDReader. Add methods for information only. --- diff --git a/src/MEDLoader/MEDFileFieldOverView.cxx b/src/MEDLoader/MEDFileFieldOverView.cxx index 4358d7305..241cd422e 100644 --- a/src/MEDLoader/MEDFileFieldOverView.cxx +++ b/src/MEDLoader/MEDFileFieldOverView.cxx @@ -1914,6 +1914,31 @@ MEDMeshMultiLev *MEDFileField1TSStructItem::buildFromScratchDataSetSupportOnCell return MEDMeshMultiLev::New(mst->getTheMesh(),a0,a1,a2); } +std::vector MEDFileField1TSStructItem::getGeoTypes(const MEDFileMesh *m) const +{ + std::vector ret; + if(_type==ON_NODES) + { + if(!_items.empty() && _items[0].getPflName().empty()) + { + if(m) + return m->getAllGeoTypes(); + else + return ret; + } + else + return ret; + } + for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++) + { + INTERP_KERNEL::NormalizedCellType elt((*it).getGeo()); + std::vector::iterator it2(std::find(ret.begin(),ret.end(),elt)); + if(it2==ret.end()) + ret.push_back(elt); + } + return ret; +} + MEDFileField1TSStructItem MEDFileField1TSStructItem::BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt) { TypeOfField atype; @@ -2096,6 +2121,24 @@ bool MEDFileField1TSStruct::isDataSetSupportFastlyEqualTo(const MEDFileField1TSS return true; } +std::vector MEDFileField1TSStruct::getGeoTypes(const MEDFileMesh *m) const +{ + std::vector ret; + for(std::vector::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++) + { + std::vector ret2((*it).getGeoTypes(m)); + for(std::vector::const_iterator it2=ret2.begin();it2!=ret2.end();it2++) + { + if(*it2==INTERP_KERNEL::NORM_ERROR) + continue; + std::vector::iterator it3(std::find(ret.begin(),ret.end(),*it2)); + if(it3==ret.end()) + ret.push_back(*it2); + } + } + return ret; +} + /*! * Returns true if presence in \a this of discretization ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE. * If true is returned the pos of the easiest is returned. The easiest is the first element in \a this having the less splitted subparts. @@ -2249,3 +2292,24 @@ bool MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne(int const MEDFileField1TSStruct *objRef(_f1ts_cmps[timeStepId-1]); return objRef->isDataSetSupportFastlyEqualTo(*obj,globs); } + +int MEDFileFastCellSupportComparator::getNumberOfTS() const +{ + return _f1ts_cmps.size(); +} + +std::vector MEDFileFastCellSupportComparator::getGeoTypesAt(int timeStepId, const MEDFileMesh *m) const +{ + if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size()) + { + std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::getGeoTypesAt : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const MEDFileField1TSStruct *elt(_f1ts_cmps[timeStepId]); + if(!elt) + { + std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::getGeoTypesAt : requested time step id #" << timeStepId << " points to a NULL pointer !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return elt->getGeoTypes(m); +} diff --git a/src/MEDLoader/MEDFileFieldOverView.hxx b/src/MEDLoader/MEDFileFieldOverView.hxx index ff683a84e..6ec36a1f3 100644 --- a/src/MEDLoader/MEDFileFieldOverView.hxx +++ b/src/MEDLoader/MEDFileFieldOverView.hxx @@ -249,6 +249,7 @@ namespace ParaMEDMEM MEDFileField1TSStructItem simplifyMeOnCellEntity(const MEDFileFieldGlobsReal *globs) const; bool isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobsReal *globs) const; bool isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const; + std::vector getGeoTypes(const MEDFileMesh *m) const; MEDLOADER_EXPORT MEDMeshMultiLev *buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const; MEDLOADER_EXPORT static MEDFileField1TSStructItem BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt); private: @@ -269,6 +270,7 @@ namespace ParaMEDMEM bool isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt); MEDLOADER_EXPORT MEDMeshMultiLev *buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const; bool isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const; + std::vector getGeoTypes(const MEDFileMesh *m) const; private: MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst); bool presenceOfCellDiscr(int& pos) const; @@ -283,6 +285,8 @@ namespace ParaMEDMEM MEDLOADER_EXPORT static MEDFileFastCellSupportComparator *New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref); MEDLOADER_EXPORT MEDMeshMultiLev *buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const; MEDLOADER_EXPORT bool isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const; + MEDLOADER_EXPORT int getNumberOfTS() const; + MEDLOADER_EXPORT std::vector getGeoTypesAt(int timeStepId, const MEDFileMesh *m) const; bool isEqual(const MEDFileAnyTypeFieldMultiTS *other); bool isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other); std::size_t getHeapMemorySizeWithoutChildren() const; diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 5723491e2..926f19dc0 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -1787,6 +1787,18 @@ void MEDFileMesh::appendFamilyEntries(const DataArrayInt *famIds, const std::vec } } +std::vector MEDFileMesh::getAllGeoTypes() const +{ + std::vector levs(getNonEmptyLevels()); + std::vector ret; + for(std::vector::const_iterator it=levs.begin();it!=levs.end();it++) + { + std::vector elts(getGeoTypesAtLevel(*it)); + ret.insert(ret.end(),elts.begin(),elts.end()); + } + return ret; +} + std::vector MEDFileMesh::getDistributionOfTypes(int meshDimRelToMax) const { MEDCouplingAutoRefCountObjectPtr mLev(getGenMeshAtLevel(meshDimRelToMax)); diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index e5474d9f1..ee996321b 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -64,6 +64,7 @@ namespace ParaMEDMEM MEDLOADER_EXPORT double getTimeValue() const { return _time; } MEDLOADER_EXPORT void setTimeUnit(const std::string& unit) { _dt_unit=unit; } MEDLOADER_EXPORT std::string getTimeUnit() const { return _dt_unit; } + MEDLOADER_EXPORT std::vector getAllGeoTypes() const; MEDLOADER_EXPORT virtual int getNumberOfNodes() const = 0; MEDLOADER_EXPORT virtual std::vector getGeoTypesAtLevel(int meshDimRelToMax) const = 0; MEDLOADER_EXPORT virtual std::vector getNonEmptyLevels() const = 0; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 78b8243a0..594c74967 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -624,6 +624,16 @@ namespace ParaMEDMEM return res; } + PyObject *getAllGeoTypes() const throw(INTERP_KERNEL::Exception) + { + std::vector result(self->getAllGeoTypes()); + 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; + } + PyObject *getGeoTypesAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception) { std::vector result(self->getGeoTypesAtLevel(meshDimRelToMax)); @@ -3029,7 +3039,21 @@ namespace ParaMEDMEM static MEDFileFastCellSupportComparator *New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref) throw(INTERP_KERNEL::Exception); MEDMeshMultiLev *buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception); bool isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception); + int getNumberOfTS() const throw(INTERP_KERNEL::Exception); protected: ~MEDFileFastCellSupportComparator(); + public: + %extend + { + PyObject *getGeoTypesAt(int timeStepId, const MEDFileMesh *m) const throw(INTERP_KERNEL::Exception) + { + std::vector< INTERP_KERNEL::NormalizedCellType > result(self->getGeoTypesAt(timeStepId,m)); + 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; + } + } }; } diff --git a/src/MEDLoader/Swig/MEDLoaderTest4.py b/src/MEDLoader/Swig/MEDLoaderTest4.py index dd5975fb8..164269087 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest4.py +++ b/src/MEDLoader/Swig/MEDLoaderTest4.py @@ -2728,6 +2728,7 @@ class MEDLoaderTest4(unittest.TestCase): mst=MEDFileMeshStruct.New(ms[0]) # fcscp=allFMTSLeavesPerCommonSupport1[0][1] + self.assertEqual([NORM_QUAD4],fcscp.getGeoTypesAt(0,ms[0])) mml=fcscp.buildFromScratchDataSetSupport(0,fields) mml2=mml.prepare() self.assertTrue(isinstance(mml2,MEDUMeshMultiLev)) @@ -3267,6 +3268,7 @@ class MEDLoaderTest4(unittest.TestCase): mst=MEDFileMeshStruct.New(ms[0]) # fcscp=allFMTSLeavesPerCommonSupport1[0][1] + self.assertEqual([NORM_TRI3,NORM_SEG2],fcscp.getGeoTypesAt(0,ms[0]))#contains all cell types of underlying mesh because only nodes with no profiles mml=fcscp.buildFromScratchDataSetSupport(0,fields) mml2=mml.prepare() self.assertTrue(isinstance(mml2,MEDUMeshMultiLev)) @@ -3582,6 +3584,7 @@ class MEDLoaderTest4(unittest.TestCase): mst=MEDFileMeshStruct.New(ms[0]) # emulate first click fcscp=allFMTSLeavesPerCommonSupport1[0][1] + self.assertEqual([NORM_SEG2],fcscp.getGeoTypesAt(0,ms[0])) mml=fcscp.buildFromScratchDataSetSupport(0,fields) mml2=mml.prepare() self.assertTrue(isinstance(mml2,MEDUMeshMultiLev)) @@ -3618,6 +3621,7 @@ class MEDLoaderTest4(unittest.TestCase): del fff0 # emulate second click fcscp=allFMTSLeavesPerCommonSupport1[1][1] + self.assertEqual([NORM_QUAD4],fcscp.getGeoTypesAt(0,ms[0])) mml=fcscp.buildFromScratchDataSetSupport(0,fields) mml2=mml.prepare() self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))