From: Anthony Geay Date: Mon, 23 Jan 2017 11:06:49 +0000 (+0100) Subject: Step 7 : start of filtering structure elements in fields X-Git-Tag: V8_3_0a2~38^2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a38a2d51ce92c3facb06f7f485ab26c9eac58888;p=tools%2Fmedcoupling.git Step 7 : start of filtering structure elements in fields --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index f04d3ba06..117d694b6 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -1976,6 +1976,45 @@ bool MEDFileFieldPerMesh::presenceOfMultiDiscPerGeoType() const return false; } +bool MEDFileFieldPerMesh::presenceOfStructureElements() const +{ + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + if((*it).isNotNull()) + { + const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast((const MEDFileFieldPerMeshPerTypeCommon *)*it)); + if(pt) + return true; + } + return false; +} + +bool MEDFileFieldPerMesh::onlyStructureElements() const +{ + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + if((*it).isNotNull()) + { + const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast((const MEDFileFieldPerMeshPerTypeCommon *)*it)); + if(!pt) + return false; + } + return true; +} + +void MEDFileFieldPerMesh::killStructureElements() +{ + std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res; + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + { + if((*it).isNotNull()) + { + const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast((const MEDFileFieldPerMeshPerTypeCommon *)*it)); + if(!pt) + res.push_back(*it); + } + } + _field_pm_pt=res; +} + DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() { if(!_father) @@ -4977,6 +5016,31 @@ bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const return false; } +bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfStructureElements() const +{ + for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++) + if((*it).isNotNull()) + if((*it)->presenceOfStructureElements()) + return true; + return false; +} + +bool MEDFileAnyTypeField1TSWithoutSDA::onlyStructureElements() const +{ + for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++) + if((*it).isNotNull()) + if(!(*it)->onlyStructureElements()) + return false; + return true; +} + +void MEDFileAnyTypeField1TSWithoutSDA::killStructureElements() +{ + for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++) + if((*it).isNotNull()) + (*it)->killStructureElements(); +} + MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto& arrOut, const MEDFileFieldNameScope& nasc) const { static const char MSG0[]="MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is too complex to be able to be extracted with \"field\" method ! Call getFieldOnMeshAtLevel method instead to deal with complexity !"; @@ -5406,17 +5470,17 @@ MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileField1TSTemplateWi { } -MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const +MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const { MCAuto ret(new MEDFileField1TSWithoutSDA(*this)); ret->deepCpyLeavesFrom(*this); return ret.retn(); } -MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const +MEDFileField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCopy() const { - MCAuto ret=static_cast(shallowCpy()); - if((const DataArrayDouble *)_arr) + MCAuto ret(shallowCpy()); + if(_arr.isNotNull()) ret->_arr=_arr->deepCopy(); return ret.retn(); } @@ -5505,17 +5569,17 @@ DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::v return getUndergroundDataArrayTemplate(); } -MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const +MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const { MCAuto ret(new MEDFileIntField1TSWithoutSDA(*this)); ret->deepCpyLeavesFrom(*this); return ret.retn(); } -MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const +MEDFileIntField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCopy() const { - MCAuto ret=static_cast(shallowCpy()); - if((const DataArrayInt *)_arr) + MCAuto ret(shallowCpy()); + if(_arr.isNotNull()) ret->_arr=_arr->deepCopy(); return ret.retn(); } @@ -6823,7 +6887,7 @@ void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const contentNotNull()->setFieldProfile(field,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull()); } -MEDFileAnyTypeField1TS *MEDFileField1TS::shallowCpy() const +MEDFileField1TS *MEDFileField1TS::shallowCpy() const { return new MEDFileField1TS(*this); } @@ -6935,7 +6999,7 @@ MEDFileIntField1TS::MEDFileIntField1TS(const MEDFileIntField1TSWithoutSDA& other { } -MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const +MEDFileIntField1TS *MEDFileIntField1TS::shallowCpy() const { return new MEDFileIntField1TS(*this); } @@ -7412,6 +7476,46 @@ MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileAnyTypeFieldMultiTSWithoutSDA::part return buildFromTimeStepIds(ids->begin(),ids->end()); } +bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfStructureElements() const +{ + for(std::vector< MCAuto >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) + if((*it).isNotNull()) + if((*it)->presenceOfStructureElements()) + return true; + return false; +} + +bool MEDFileAnyTypeFieldMultiTSWithoutSDA::onlyStructureElements() const +{ + for(std::vector< MCAuto >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) + if((*it).isNotNull()) + if(!(*it)->onlyStructureElements()) + return false; + return true; +} + +void MEDFileAnyTypeFieldMultiTSWithoutSDA::killStructureElements() +{ + std::vector< MCAuto > res; + for(std::vector< MCAuto >::iterator it=_time_steps.begin();it!=_time_steps.end();it++) + if((*it).isNotNull()) + { + if((*it)->presenceOfStructureElements()) + { + if(!(*it)->onlyStructureElements()) + { + (*it)->killStructureElements(); + res.push_back(*it); + } + } + else + { + res.push_back(*it); + } + } + _time_steps=res; +} + bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const { for(std::vector< MCAuto >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) @@ -10904,6 +11008,42 @@ MEDFileFields *MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps(const std:: return ret.retn(); } +bool MEDFileFields::presenceOfStructureElements() const +{ + for(std::vector< MCAuto >::const_iterator it=_fields.begin();it!=_fields.end();it++) + if((*it).isNotNull()) + if((*it)->presenceOfStructureElements()) + return true; + return false; +} + +void MEDFileFields::killStructureElements() +{ + std::vector< MCAuto > ret; + for(std::vector< MCAuto >::iterator it=_fields.begin();it!=_fields.end();it++) + if((*it).isNotNull()) + { + if((*it)->presenceOfStructureElements()) + { + if(!(*it)->onlyStructureElements()) + { + (*it)->killStructureElements(); + ret.push_back(*it); + } + } + } + else + { + ret.push_back(*it); + } + _fields=ret; +} + +MCAuto MEDFileFields::partOfThisOnStructureElements() const +{ + throw INTERP_KERNEL::Exception("partOfThisOnStructureElements : not implemented yet !"); +} + MEDFileFieldsIterator *MEDFileFields::iterator() { return new MEDFileFieldsIterator(this); diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 88d62aaf6..8995fc045 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -317,6 +317,9 @@ namespace MEDCoupling std::string getMeshName() const { return _mesh_name; } int getNumberOfComponents() const; bool presenceOfMultiDiscPerGeoType() const; + bool presenceOfStructureElements() const; + bool onlyStructureElements() const; + void killStructureElements(); DataArray *getOrCreateAndGetArray(); const DataArray *getOrCreateAndGetArray() const; const std::vector& getInfo() const; @@ -555,6 +558,9 @@ namespace MEDCoupling MEDLOADER_EXPORT const std::vector& getInfo() const; MEDLOADER_EXPORT std::vector& getInfo(); MEDLOADER_EXPORT bool presenceOfMultiDiscPerGeoType() const; + MEDLOADER_EXPORT bool presenceOfStructureElements() const; + MEDLOADER_EXPORT bool onlyStructureElements() const; + MEDLOADER_EXPORT void killStructureElements(); MEDLOADER_EXPORT void setInfo(const std::vector& infos); MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; MEDLOADER_EXPORT std::vector getDirectChildrenWithNull() const; @@ -651,8 +657,8 @@ namespace MEDCoupling public: MEDLOADER_EXPORT MEDFileField1TSWithoutSDA(); MEDLOADER_EXPORT MEDFileField1TSWithoutSDA(const std::string& fieldName, int csit, int iteration, int order, const std::vector& infos); - MEDLOADER_EXPORT MEDFileAnyTypeField1TSWithoutSDA *shallowCpy() const; - MEDLOADER_EXPORT MEDFileAnyTypeField1TSWithoutSDA *deepCopy() const; + MEDLOADER_EXPORT MEDFileField1TSWithoutSDA *shallowCpy() const; + MEDLOADER_EXPORT MEDFileField1TSWithoutSDA *deepCopy() const; MEDLOADER_EXPORT MEDFileIntField1TSWithoutSDA *convertToInt() const; public: static const char TYPE_STR[]; @@ -666,8 +672,8 @@ namespace MEDCoupling public: MEDLOADER_EXPORT MEDFileIntField1TSWithoutSDA(); MEDLOADER_EXPORT static MEDFileIntField1TSWithoutSDA *New(const std::string& fieldName, int csit, int iteration, int order, const std::vector& infos); - MEDLOADER_EXPORT MEDFileAnyTypeField1TSWithoutSDA *deepCopy() const; - MEDLOADER_EXPORT MEDFileAnyTypeField1TSWithoutSDA *shallowCpy() const; + MEDLOADER_EXPORT MEDFileIntField1TSWithoutSDA *deepCopy() const; + MEDLOADER_EXPORT MEDFileIntField1TSWithoutSDA *shallowCpy() const; MEDLOADER_EXPORT const char *getTypeStr() const; MEDLOADER_EXPORT DataArray *getUndergroundDataArrayExt(std::vector< std::pair,std::pair > >& entries) const; MEDLOADER_EXPORT DataArrayInt *getUndergroundDataArrayIntExt(std::vector< std::pair,std::pair > >& entries) const; @@ -802,7 +808,7 @@ namespace MEDCoupling MEDLOADER_EXPORT void setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile); // direct forwarding to MEDFileField1TSWithoutSDA instance _content public: - MEDLOADER_EXPORT MEDFileAnyTypeField1TS *shallowCpy() const; + MEDLOADER_EXPORT MEDFileField1TS *shallowCpy() const; MEDLOADER_EXPORT DataArrayDouble *getUndergroundDataArray() const; MEDLOADER_EXPORT DataArrayDouble *getUndergroundDataArrayExt(std::vector< std::pair,std::pair > >& entries) const; @@ -839,7 +845,7 @@ namespace MEDCoupling MEDLOADER_EXPORT static MEDFileIntField1TS *New(med_idt fid, const std::string& fieldName, int iteration, int order, bool loadAll=true); MEDLOADER_EXPORT static MEDFileIntField1TS *New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent); MEDLOADER_EXPORT MEDFileField1TS *convertToDouble(bool isDeepCpyGlobs=true) const; - MEDLOADER_EXPORT MEDFileAnyTypeField1TS *shallowCpy() const; + MEDLOADER_EXPORT MEDFileIntField1TS *shallowCpy() const; // MEDLOADER_EXPORT MEDCouplingFieldInt *field(const MEDFileMesh *mesh) const; MEDLOADER_EXPORT MEDCouplingFieldInt *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const; @@ -907,6 +913,9 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTSWithoutSDA *buildFromTimeStepIds2(int bg, int end, int step) const; MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTSWithoutSDA *partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair >& timeSteps) const; MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTSWithoutSDA *partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair >& timeSteps) const; + MEDLOADER_EXPORT bool presenceOfStructureElements() const; + MEDLOADER_EXPORT bool onlyStructureElements() const; + MEDLOADER_EXPORT void killStructureElements(); MEDLOADER_EXPORT int getPosOfTimeStep(int iteration, int order) const; MEDLOADER_EXPORT int getPosGivenTime(double time, double eps=1e-8) const; MEDLOADER_EXPORT std::vector< std::pair > getIterations() const; @@ -1057,6 +1066,7 @@ namespace MEDCoupling MEDLOADER_EXPORT bool changeMeshNames(const std::vector< std::pair >& modifTab); MEDLOADER_EXPORT const std::vector& getInfo() const; MEDLOADER_EXPORT bool presenceOfMultiDiscPerGeoType() const; + MEDLOADER_EXPORT void killStructureElements(); MEDLOADER_EXPORT void setInfo(const std::vector& info); MEDLOADER_EXPORT int getNumberOfComponents() const; MEDLOADER_EXPORT int getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector& levs) const; @@ -1234,6 +1244,9 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileFields *partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const; MEDLOADER_EXPORT MEDFileFields *partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair >& timeSteps) const; MEDLOADER_EXPORT MEDFileFields *partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair >& timeSteps) const; + MEDLOADER_EXPORT bool presenceOfStructureElements() const; + MEDLOADER_EXPORT void killStructureElements(); + MEDLOADER_EXPORT MCAuto partOfThisOnStructureElements() const; MEDLOADER_EXPORT MEDFileFieldsIterator *iterator(); MEDLOADER_EXPORT void destroyFieldAtPos(int i); MEDLOADER_EXPORT void destroyFieldsAtPos(const int *startIds, const int *endIds); diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 5e2e86c94..da768d905 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -150,6 +150,7 @@ using namespace MEDCoupling; %newobject MEDCoupling::MEDFileFields::partOfThisLyingOnSpecifiedMeshName; %newobject MEDCoupling::MEDFileFields::partOfThisLyingOnSpecifiedTimeSteps; %newobject MEDCoupling::MEDFileFields::partOfThisNotLyingOnSpecifiedTimeSteps; +%newobject MEDCoupling::MEDFileFields::partOfThisOnStructureElements; %newobject MEDCoupling::MEDFileFields::__iter__; %newobject MEDCoupling::MEDFileFields::extractPart; @@ -3020,6 +3021,8 @@ namespace MEDCoupling MEDFileAnyTypeFieldMultiTS *getFieldAtPos(int i) const throw(INTERP_KERNEL::Exception); MEDFileAnyTypeFieldMultiTS *getFieldWithName(const std::string& fieldName) const throw(INTERP_KERNEL::Exception); MEDFileFields *partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const throw(INTERP_KERNEL::Exception); + bool presenceOfStructureElements() const throw(INTERP_KERNEL::Exception); + void killStructureElements() throw(INTERP_KERNEL::Exception); void destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception); bool removeFieldsWithoutAnyTimeStep() throw(INTERP_KERNEL::Exception); %extend @@ -3049,7 +3052,13 @@ namespace MEDCoupling { return self->simpleRepr(); } - + + MEDFileFields *partOfThisOnStructureElements() const throw(INTERP_KERNEL::Exception) + { + MCAuto ret(self->partOfThisOnStructureElements()); + return ret.retn(); + } + static MEDFileFields *LoadSpecificEntities(const std::string& fileName, PyObject *entities, bool loadAll=true) throw(INTERP_KERNEL::Exception) { std::vector > tmp(convertTimePairIdsFromPy(entities));