From: ageay Date: Tue, 25 Oct 2011 14:22:19 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V6_main_FINAL~922 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=11acfb1bba578f56091f7d54285ab836addbc3fb;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 9f842957b..1addb5ea2 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -3265,6 +3265,31 @@ DataArrayInt *DataArrayInt::getIdsNotEqual(int val) const throw(INTERP_KERNEL::E return ret; } +/*! + * This method expects that 'this' is allocated. If not an exception will be thrown. + * This method expect that the number of components is exactly equal to 1. If not an exception will be thrown. + * For each element in 'this' equal to 'oldValue' will take the value 'newValue'. + * @return number of elements impacted by the modification. + */ +int DataArrayInt::changeValue(int oldValue, int newValue) throw(INTERP_KERNEL::Exception) +{ + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::changeValue : the array must have only one component, you can call 'rearrange' method before !"); + checkAllocated(); + int *start=getPointer(); + int *end=start+getNbOfElems(); + int ret=0; + for(int *val=start;val!=end;val++) + { + if(*val==oldValue) + { + *val=newValue; + ret++; + } + } + return ret; +} + DataArrayInt *DataArrayInt::getIdsEqualList(const std::vector& vals) const throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()!=1) diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 55f3ab7f5..7af85fbd8 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -366,6 +366,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *getIdsNotEqual(int val) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *getIdsEqualList(const std::vector& vals) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *getIdsNotEqualList(const std::vector& vals) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT int changeValue(int oldValue, int newValue) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool presenceOfValue(const std::vector& vals) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getMaxValueInArray() const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index a1229a17a..907ef66b3 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -4773,8 +4773,11 @@ std::string MEDCouplingUMesh::getVTKDataSetType() const throw(INTERP_KERNEL::Exc return std::string("UnstructuredGrid"); } +/// @cond INTERNAL + MEDCouplingUMesh *MEDCouplingUMesh::Intersect2DMeshes(const MEDCouplingUMesh *m1, const MEDCouplingUMesh *m2, double eps, DataArrayInt *&cellNb1, DataArrayInt *&cellNb2) throw(INTERP_KERNEL::Exception) { + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::Intersect2DMeshes : functionnality not finished yet ! Will come soon !"); std::vector< std::vector > intersectEdge1, subDiv2; MEDCouplingUMesh *m1Desc=0,*m2Desc=0; DataArrayInt *desc1=0,*descIndx1=0,*revDesc1=0,*revDescIndx1=0,*desc2=0,*descIndx2=0,*revDesc2=0,*revDescIndx2=0; @@ -4814,6 +4817,8 @@ MEDCouplingUMesh *MEDCouplingUMesh::Intersect2DMeshes(const MEDCouplingUMesh *m1 return 0; } +/// @endcond + void MEDCouplingUMesh::BuildIntersecting2DCellsFromEdges(double eps, const MEDCouplingUMesh *m1, const std::vector& b1, const int *desc1, const int *descIndx1, const std::vector >& intesctEdges1, const MEDCouplingUMesh *m2, const std::vector& b2, const int *desc2, const int *descIndx2, const std::vector >& intesctEdges2, const std::vector& addCoords, diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index c85d8e9ba..d7b23a44a 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -181,7 +181,9 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static bool IsPolygonWellOriented(bool isQuadratic, const double *vec, const int *begin, const int *end, const double *coords); MEDCOUPLING_EXPORT static bool IsPolyhedronWellOriented(const int *begin, const int *end, const double *coords); MEDCOUPLING_EXPORT static void TryToCorrectPolyhedronOrientation(int *begin, int *end, const double *coords) throw(INTERP_KERNEL::Exception); +/// @cond INTERNAL MEDCOUPLING_EXPORT static MEDCouplingUMesh *Intersect2DMeshes(const MEDCouplingUMesh *m1, const MEDCouplingUMesh *m2, double eps, DataArrayInt *&cellNb1, DataArrayInt *&cellNb2) throw(INTERP_KERNEL::Exception); +/// @endcond private: MEDCouplingUMesh(); MEDCouplingUMesh(const MEDCouplingUMesh& other, bool deepCpy); diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 5dcfcd00d..42287be6c 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -387,6 +387,20 @@ void MEDFileMesh::changeGroupName(const char *oldName, const char *newName) thro _groups[newName]=cpy; } +void MEDFileMesh::changeFamilyId(int oldId, int newId) throw(INTERP_KERNEL::Exception) +{ + changeFamilyIdArr(oldId,newId); + std::map fam2; + for(std::map::const_iterator it=_families.begin();it!=_families.end();it++) + { + if((*it).second==oldId) + fam2[(*it).first]=newId; + else + fam2[(*it).first]=(*it).second; + } + _families=fam2; +} + void MEDFileMesh::changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception) { std::string oname(oldName); @@ -1643,6 +1657,21 @@ void MEDFileUMesh::synchronizeTinyInfoOnLeaves() const (*it)->synchronizeTinyInfo(*this); } +void MEDFileUMesh::changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception) +{ + DataArrayInt *arr=_fam_coords; + if(arr) + arr->changeValue(oldId,newId); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_ms.begin();it!=_ms.end();it++) + { + MEDFileUMeshSplitL1 *sp=(*it); + if(sp) + { + sp->changeFamilyIdArr(oldId,newId); + } + } +} + void MEDFileUMesh::computeRevNum() const { if((const DataArrayInt *)_num_coords) @@ -1826,8 +1855,6 @@ catch(INTERP_KERNEL::Exception& e) throw e; } - - void MEDFileCMesh::loadCMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) { MEDFileCMeshL2 loaderl2; @@ -1901,6 +1928,16 @@ void MEDFileCMesh::loadCMeshFromFile(med_idt fid, const char *mName, int dt, int } } +void MEDFileCMesh::changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception) +{ + DataArrayInt *arr=_fam_nodes; + if(arr) + arr->changeValue(oldId,newId); + arr=_fam_cells; + if(arr) + arr->changeValue(oldId,newId); +} + const MEDCouplingCMesh *MEDFileCMesh::getMesh() const { synchronizeTinyInfoOnLeaves(); diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index f90d0bd29..013fcb2b7 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -83,6 +83,7 @@ namespace ParaMEDMEM void removeFamily(const char *name) throw(INTERP_KERNEL::Exception); void changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception); void changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception); + void changeFamilyId(int oldId, int newId) throw(INTERP_KERNEL::Exception); int getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception); int getMaxFamilyId() const throw(INTERP_KERNEL::Exception); std::vector getFamiliesIds(const std::vector& famNames) const throw(INTERP_KERNEL::Exception); @@ -111,6 +112,7 @@ namespace ParaMEDMEM virtual void synchronizeTinyInfoOnLeaves() const = 0; void getFamilyRepr(std::ostream& oss) const; virtual void appendFamilyEntries(const std::set& famIds, const std::vector< std::vector >& fidsOfGrps, const std::vector& grpNames); + virtual void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception) = 0; static void TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector >& famIdsPerGrp); protected: int _order; @@ -192,6 +194,7 @@ namespace ParaMEDMEM DataArrayDouble *checkMultiMesh(const std::vector& ms) const throw(INTERP_KERNEL::Exception); void computeRevNum() const; void synchronizeTinyInfoOnLeaves() const; + void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception); private: std::vector< MEDCouplingAutoRefCountObjectPtr > _ms; MEDCouplingAutoRefCountObjectPtr _coords; @@ -230,6 +233,7 @@ namespace ParaMEDMEM void synchronizeTinyInfoOnLeaves() const; MEDFileCMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); void loadCMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); + void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception); private: MEDCouplingAutoRefCountObjectPtr _cmesh; MEDCouplingAutoRefCountObjectPtr _fam_nodes; diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 73f735047..6b9992bc9 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -692,6 +692,13 @@ void MEDFileUMeshSplitL1::write(med_idt fid, const char *mName, int mdim) const } } +void MEDFileUMeshSplitL1::changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception) +{ + DataArrayInt *arr=_fam; + if(arr) + arr->changeValue(oldId,newId); +} + void MEDFileUMeshSplitL1::setFamilyArr(DataArrayInt *famArr) { famArr->incrRef(); diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 3b1cf1eed..6c20a72f1 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -143,6 +143,7 @@ namespace ParaMEDMEM // void setFamilyArr(DataArrayInt *famArr); void setRenumArr(DataArrayInt *renumArr); + void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception); // static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp); static std::vector GetNewFamiliesNumber(int nb, const std::map& families); diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index b14c4b849..bc8b4323f 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -314,6 +314,7 @@ namespace ParaMEDMEM void removeFamily(const char *name) throw(INTERP_KERNEL::Exception); void changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception); void changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception); + void changeFamilyId(int oldId, int newId) throw(INTERP_KERNEL::Exception); void setFamilyInfo(const std::map& info); void setGroupInfo(const std::map >&info); int getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index c135a8e8a..935ebe005 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -903,6 +903,13 @@ class MEDLoaderTest(unittest.TestCase): self.assertEqual(('Family_2', 'Family_4'),mm.getFamiliesOnGroup('g1')) self.assertEqual(('Family_5',),mm.getFamiliesOnGroup('g2')) self.assertEqual(('Family_4','Family_5',),mm.getFamiliesOnGroup('g3')) + mm.changeFamilyId(5,6) + g=mm.getGroupArr(0,"g3") + self.assertTrue(g.isEqual(g3)); + g=mm.getGroupArr(0,"g2") + self.assertTrue(g.isEqual(g2)); + g=mm.getGroupArr(0,"g1") + self.assertTrue(g.isEqual(g1)); pass pass