From: ageay Date: Tue, 25 Jun 2013 11:21:11 +0000 (+0000) Subject: On the road of reimplementation of basic MEDLoader API with advanced one. X-Git-Tag: B4CMakeModifs~38 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8f69e2c7d5bd838a9ed47e707e8496165c0dc90e;p=modules%2Fmed.git On the road of reimplementation of basic MEDLoader API with advanced one. --- diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 798b8f2bb..1cdd440bf 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -484,6 +484,8 @@ bool MEDCouplingFieldDouble::areCompatibleForMeld(const MEDCouplingFieldDouble * * renumbering. The underlying mesh is deeply copied and its cells are also permuted. * The number of cells remains the same; for that the permutation array \a old2NewBg * should not contain equal ids. + * ** Warning, this method modifies the mesh aggreagated by \a this (by performing a deep copy ) **. + * * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is * to be equal to \a this->getMesh()->getNumberOfCells(). * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index aa04149d7..3d923508d 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -1786,6 +1786,32 @@ void DataArrayDouble::meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL copyPartOfStringInfoFrom2(compIds,*other); } +/*! + * This method checks that all tuples in \a other are in \a this. + * If true, the output param \a tupleIds contains the tuples ids of \a this that correspond to tupes in \a this. + * For each i in [ 0 , other->getNumberOfTuples() ) tuple #i in \a other is equal ( regarding input precision \a prec ) to tuple tupleIds[i] in \a this. + * + * \param [in] other - the array having the same number of components than \a this. + * \param [out] tupleIds - the tuple ids containing the same number of tuples than \a other has. + * \sa DataArrayDouble::findCommonTuples + */ +bool DataArrayDouble::areIncludedInMe(const DataArrayDouble *other, double prec, DataArrayInt *&tupleIds) const throw(INTERP_KERNEL::Exception) +{ + if(!other) + throw INTERP_KERNEL::Exception("DataArrayDouble::areIncludedInMe : input array is NULL !"); + checkAllocated(); other->checkAllocated(); + if(getNumberOfComponents()!=other->getNumberOfComponents()) + throw INTERP_KERNEL::Exception("DataArrayDouble::areIncludedInMe : the number of components does not match !"); + MEDCouplingAutoRefCountObjectPtr a=DataArrayDouble::Aggregate(this,other); + DataArrayInt *c=0,*ci=0; + a->findCommonTuples(prec,getNumberOfTuples(),c,ci); + int newNbOfTuples=-1; + MEDCouplingAutoRefCountObjectPtr ids=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(a->getNumberOfTuples(),c->begin(),ci->begin(),ci->end(),newNbOfTuples); + MEDCouplingAutoRefCountObjectPtr ret1=ids->selectByTupleId2(getNumberOfTuples(),a->getNumberOfTuples(),1); + tupleIds=ret1.retn(); + return newNbOfTuples==getNumberOfTuples(); +} + /*! * Searches for tuples coincident within \a prec tolerance. Each tuple is considered * as coordinates of a point in getNumberOfComponents()-dimensional space. The @@ -1815,7 +1841,7 @@ void DataArrayDouble::meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL * \ref cpp_mcdataarraydouble_findcommontuples "Here is a C++ example". * * \ref py_mcdataarraydouble_findcommontuples "Here is a Python example". - * \sa DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(). + * \sa DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(), DataArrayDouble::areIncludedInMe */ void DataArrayDouble::findCommonTuples(double prec, int limitTupleId, DataArrayInt *&comm, DataArrayInt *&commIndex) const throw(INTERP_KERNEL::Exception) { diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index ec19ea017..416caf8ee 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -245,6 +245,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayDouble *changeNbOfComponents(int newNbOfComp, double dftValue) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArray *keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT bool areIncludedInMe(const DataArrayDouble *other, double prec, DataArrayInt *&tupleIds) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void findCommonTuples(double prec, int limitTupleId, DataArrayInt *&comm, DataArrayInt *&commIndex) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double minimalDistanceTo(const DataArrayDouble *other, int& thisTupleId, int& otherTupleId) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayDouble *duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index c8d01311f..941be3ae3 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -13356,6 +13356,19 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(b is None) pass + def testSwig2DADAreIncludedInMe1(self): + a=DataArrayDouble(30) ; a.iota() ; a.rearrange(3) + p=DataArrayInt([5,2,1,9]) + b,c=a.areIncludedInMe(a[p],1e-12) + self.assertTrue(b) + self.assertTrue(c.isEqual(p)) + d=a[p] + d.setIJ(3,1,28.1) + b,c=a.areIncludedInMe(d,1e-12) + self.assertTrue(not b) + self.assertTrue(c.isEqual(DataArrayInt([5,2,1,10]))) + pass + def setUp(self): pass pass diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 53fbb05e5..a4deec3bd 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -873,6 +873,18 @@ namespace ParaMEDMEM return ret; } + PyObject *areIncludedInMe(const DataArrayDouble *other, double prec) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *ret1=0; + bool ret0=self->areIncludedInMe(other,prec,ret1); + PyObject *ret=PyTuple_New(2); + PyObject *ret0Py=ret0?Py_True:Py_False; + Py_XINCREF(ret0Py); + PyTuple_SetItem(ret,0,ret0Py); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) { const char msg[]="Unexpected situation in DataArrayDouble::__getitem__ !";