From: ageay Date: Thu, 22 Aug 2013 09:57:56 +0000 (+0000) Subject: Optimization and ease of usage. MEDCouplingMesh::buildPartRange returns this when... X-Git-Tag: V7_3_1b1~183 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5455df9fd088945f6e1cc778b812723ab5647b80;p=tools%2Fmedcoupling.git Optimization and ease of usage. MEDCouplingMesh::buildPartRange returns this when all cells are specified in input slice. --- diff --git a/src/MEDCoupling/MEDCouplingMesh.cxx b/src/MEDCoupling/MEDCouplingMesh.cxx index a9b28d585..4e26cff42 100644 --- a/src/MEDCoupling/MEDCouplingMesh.cxx +++ b/src/MEDCoupling/MEDCouplingMesh.cxx @@ -252,13 +252,26 @@ bool MEDCouplingMesh::areCompatibleForMerge(const MEDCouplingMesh *other) const /*! * This method is equivalent to MEDCouplingMesh::buildPart method except that here the cell ids are specified using slice \a beginCellIds \a endCellIds and \a stepCellIds. + * \b WARNING , there is a big difference compared to MEDCouplingMesh::buildPart method. + * If the input range is equal all cells in \a this, \a this is returned ! + * + * \return a new ref to be managed by the caller. Warning this ref can be equal to \a this if input slice is exactly equal to the whole cells in the same order. * * \sa MEDCouplingMesh::buildPart */ MEDCouplingMesh *MEDCouplingMesh::buildPartRange(int beginCellIds, int endCellIds, int stepCellIds) const throw(INTERP_KERNEL::Exception) { - MEDCouplingAutoRefCountObjectPtr cellIds=DataArrayInt::Range(beginCellIds,endCellIds,stepCellIds); - return buildPart(cellIds->begin(),cellIds->end()); + if(beginCellIds==0 && endCellIds==getNumberOfCells() && stepCellIds==1) + { + MEDCouplingMesh *ret(const_cast(this)); + ret->incrRef(); + return ret; + } + else + { + MEDCouplingAutoRefCountObjectPtr cellIds=DataArrayInt::Range(beginCellIds,endCellIds,stepCellIds); + return buildPart(cellIds->begin(),cellIds->end()); + } } /*! diff --git a/src/MEDCoupling/MEDCouplingPointSet.cxx b/src/MEDCoupling/MEDCouplingPointSet.cxx index 6d90de508..2ecfdeb06 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.cxx +++ b/src/MEDCoupling/MEDCouplingPointSet.cxx @@ -1101,13 +1101,28 @@ MEDCouplingMesh *MEDCouplingPointSet::buildPartAndReduceNodes(const int *start, } /*! - * This method specialized the MEDCouplingMesh::buildPartRange + * This method specialized the MEDCouplingMesh::buildPartRange. + * This method is equivalent to MEDCouplingMesh::buildPart method except that here the cell ids are specified using slice + * \a beginCellIds \a endCellIds and \a stepCellIds. + * \b WARNING , there is a big difference compared to MEDCouplingMesh::buildPart method. + * If the input range is equal all cells in \a this, \a this is returned ! + * + * \return a new ref to be managed by the caller. Warning this ref can be equal to \a this if input slice is exactly equal to the whole cells in the same order. * * \sa MEDCouplingUMesh::buildPartOfMySelf2 */ MEDCouplingMesh *MEDCouplingPointSet::buildPartRange(int beginCellIds, int endCellIds, int stepCellIds) const throw(INTERP_KERNEL::Exception) { - return buildPartOfMySelf2(beginCellIds,endCellIds,stepCellIds,true); + if(beginCellIds==0 && endCellIds==getNumberOfCells() && stepCellIds==1) + { + MEDCouplingMesh *ret(const_cast(this)); + ret->incrRef(); + return ret; + } + else + { + return buildPartOfMySelf2(beginCellIds,endCellIds,stepCellIds,true); + } } /*! diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 61ebab008..90d84834f 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -13798,6 +13798,21 @@ class MEDCouplingBasicsTest(unittest.TestCase): pass # pass + + # test the when input slice is all the same object is return by MEDCouplingMesh.buildPartRange + def testSwig2MeshPartSlice1(self): + a=DataArrayDouble(4) ; a.iota() + c=MEDCouplingCMesh() ; c.setCoords(a,a) ; m=c.buildUnstructured() + fc0=c.getMeasureField(False) ; fc1=fc0[:] ; fc2=fc0*fc1 ; fc2.setName(fc0.getName()) + self.assertEqual(fc0.getMesh().getHiddenCppPointer(),fc1.getMesh().getHiddenCppPointer()) + self.assertEqual(fc2.getMesh().getHiddenCppPointer(),fc1.getMesh().getHiddenCppPointer()) + self.assertTrue(fc2.isEqual(fc1,1e-12,1e-12)) + # + fm0=m.getMeasureField(False) ; fm1=fm0[:] ; fm2=fm0*fm1 ; fm2.setName(fm0.getName()) + self.assertEqual(fm0.getMesh().getHiddenCppPointer(),fm1.getMesh().getHiddenCppPointer()) + self.assertEqual(fm2.getMesh().getHiddenCppPointer(),fm1.getMesh().getHiddenCppPointer()) + self.assertTrue(fm2.isEqual(fm1,1e-12,1e-12)) + pass def setUp(self): pass