From: Anthony Geay Date: Tue, 16 Dec 2014 16:55:16 +0000 (+0100) Subject: All the 14 tests are OK for Intersect2DMeshWith1DLine. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=265e7a81bb000a5f5f01c64ef7a27ebe0604f3a0;p=tools%2Fmedcoupling.git All the 14 tests are OK for Intersect2DMeshWith1DLine. --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index eca5fe45b..e9058f908 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -9272,6 +9272,32 @@ int DataArrayInt::getMinValueInArray() const return *loc; } +/*! + * Returns in a single walk in \a this the min value and the max value in \a this. + * \a this is expected to be single component array. + * + * \param [out] minValue - the min value in \a this. + * \param [out] maxValue - the max value in \a this. + * + * \sa getMinValueInArray, getMinValue, getMaxValueInArray, getMaxValue + */ +void DataArrayInt::getMinMaxValues(int& minValue, int& maxValue) const +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::getMinMaxValues : must be applied on DataArrayInt with only one component !"); + int nbTuples(getNumberOfTuples()); + const int *pt(begin()); + minValue=std::numeric_limits::max(); maxValue=-std::numeric_limits::max(); + for(int i=0;imaxValue) + maxValue=*pt; + } +} + /*! * Converts every value of \a this array to its absolute value. * \b WARNING this method is non const. If a new DataArrayInt instance should be built containing the result of abs DataArrayInt::computeAbs @@ -10082,6 +10108,7 @@ DataArrayInt *DataArrayInt::buildIntersection(const DataArrayInt *other) const * * \return a newly allocated array that contain the result of the unique operation applied on \a this. * \throw if \a this is not allocated or if \a this has not exactly one component. + * \sa DataArrayInt::buildUniqueNotSorted */ DataArrayInt *DataArrayInt::buildUnique() const { @@ -10098,6 +10125,38 @@ DataArrayInt *DataArrayInt::buildUnique() const return ret.retn(); } +/*! + * This method can be applied on allocated with one component DataArrayInt instance. + * This method keep elements only once by keeping the same order in \a this that is not expected to be sorted. + * + * \return a newly allocated array that contain the result of the unique operation applied on \a this. + * + * \throw if \a this is not allocated or if \a this has not exactly one component. + * + * \sa DataArrayInt::buildUnique + */ +DataArrayInt *DataArrayInt::buildUniqueNotSorted() const +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::buildUniqueNotSorted : only single component allowed !"); + int minVal,maxVal; + getMinMaxValues(minVal,maxVal); + std::vector b(maxVal-minVal+1,false); + const int *ptBg(begin()),*endBg(end()); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); ret->alloc(0,1); + for(const int *pt=ptBg;pt!=endBg;pt++) + { + if(!b[*pt-minVal]) + { + ret->pushBackSilent(*pt); + b[*pt-minVal]=true; + } + } + ret->copyStringInfoFrom(*this); + return ret.retn(); +} + /*! * Returns a new DataArrayInt which contains size of every of groups described by \a this * "index" array. Such "index" array is returned for example by diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index a5b1a3101..b47a14ebc 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -556,6 +556,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT int getMaxValueInArray() const; MEDCOUPLING_EXPORT int getMinValue(int& tupleId) const; MEDCOUPLING_EXPORT int getMinValueInArray() const; + MEDCOUPLING_EXPORT void getMinMaxValues(int& minValue, int& maxValue) const; MEDCOUPLING_EXPORT void abs(); MEDCOUPLING_EXPORT DataArrayInt *computeAbs() const; MEDCOUPLING_EXPORT void applyLin(int a, int b, int compoId); @@ -588,6 +589,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *buildUnion(const DataArrayInt *other) const; MEDCOUPLING_EXPORT DataArrayInt *buildIntersection(const DataArrayInt *other) const; MEDCOUPLING_EXPORT DataArrayInt *buildUnique() const; + MEDCOUPLING_EXPORT DataArrayInt *buildUniqueNotSorted() const; MEDCOUPLING_EXPORT DataArrayInt *deltaShiftIndex() const; MEDCOUPLING_EXPORT void computeOffsets(); MEDCOUPLING_EXPORT void computeOffsets2(); diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 322bf3a2d..f83650cfa 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -9693,6 +9693,7 @@ void MEDCouplingUMesh::Intersect2DMeshWith1DLine(const MEDCouplingUMesh *mesh2D, } ret3->setPartOfValues3(partOfRet3,idsInRet1Colinear->begin(),idsInRet1Colinear->end(),0,2,1,true); } + cellsToBeModified=cellsToBeModified->buildUniqueNotSorted(); for(const int *it=cellsToBeModified->begin();it!=cellsToBeModified->end();it++) { MEDCouplingAutoRefCountObjectPtr idsNonColPerCell(elts->getIdsEqual(*it)); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 07b298c28..d0908fb5b 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -15896,7 +15896,6 @@ class MEDCouplingBasicsTest(unittest.TestCase): m_line = MEDCouplingUMesh.New("seg", 1) m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2)) m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2)) - a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m, m_line, eps) self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer()) self.assertEqual([32,9,11,2,3,12,10,29,30,31,32,33,34,32,0,10,12,35,36,37,32,1,11,9,26,27,28],a.getNodalConnectivity().getValues()) @@ -15956,7 +15955,6 @@ class MEDCouplingBasicsTest(unittest.TestCase): m_line = MEDCouplingUMesh("seg", 1) m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2)) m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2)) - a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m, m_line, eps) self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer()) self.assertTrue(a.getCoords()[:m.getNumberOfNodes()].isEqual(m.getCoords(),1e-12)) @@ -15971,7 +15969,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): pass #class MEDCouplingBasicsTest(unittest.TestCase): - def tessSwig2Intersect2DMeshWith1DLine14(self): + def testSwig2Intersect2DMeshWith1DLine14(self): """ A circle in a circle intersected by a simple horizontal line, not tangent to the circles """ eps = 1.0e-8 m = MEDCouplingUMesh("boxcircle", 2) @@ -15989,31 +15987,21 @@ class MEDCouplingBasicsTest(unittest.TestCase): m_line = MEDCouplingUMesh.New("seg", 1) m_line.setCoords(DataArrayDouble(coords2, len(coords2)/2, 2)) m_line.setConnectivity(DataArrayInt(connec2), DataArrayInt(cI2)) -# m_line2 = m_line.deepCpy() -# m2 = m.deepCpy() -# m_line2.tessellate2DCurve(0.1) -# m2.tessellate2D(0.1) -# m_line2.writeVTK("/tmp/m1d_14.vtu") -# m2.writeVTK("/tmp/m2d_14.vtu") + m_line2 = m_line.deepCpy() + #m2 = m.deepCpy() + #m_line2.tessellate2DCurve(0.1) + #m2.tessellate2D(0.1) + #m_line2.writeVTK("/tmp/m1d_14.vtu") + #m2.writeVTK("/tmp/m2d_14.vtu") a, b, c, d = MEDCouplingUMesh.Intersect2DMeshWith1DLine(m, m_line, eps) -# a.mergeNodes(1.0e-8) -# a.tessellate2D(0.1) -# b.tessellate2DCurve(0.1) -# a.writeVTK("/tmp/m2d_fine_14.vtu") -# b.writeVTK("/tmp/m1d_fine_14.vtu") - - self.assertEqual([], a.getNodalConnectivity().getValues()) - self.assertEqual([], a.getNodalConnectivityIndex().getValues()) - self.assertEqual([], b.getNodalConnectivity().getValues()) - self.assertEqual([], b.getNodalConnectivityIndex().getValues()) - self.assertTrue(a.getCoords()[:8].isEqual(m.getCoords(),1e-12)) - self.assertTrue(a.getCoords()[8:10].isEqual(m_line.getCoords(),1e-12)) - coo_tgt = DataArrayDouble([]) - self.assertTrue(a.getCoords().isEqualWithoutConsideringStr(coo_tgt, 1.0e-12)) - self.assertTrue(a.getCoords().getHiddenCppPointer()==b.getCoords().getHiddenCppPointer()) - self.assertEqual([], c.getValues()) - self.assertEqual([], d.getValues()) + self.assertTrue(c.isEqual(DataArrayInt([1,2,2,2,0,0]))) + self.assertTrue(d.isEqual(DataArrayInt([(1,3),(4,5),(1,2)]))) + #a.mergeNodes(1.0e-8) + #a.tessellate2D(0.1) + #b.tessellate2DCurve(0.1) + #a.writeVTK("/tmp/m2d_fine_14.vtu") + #b.writeVTK("/tmp/m1d_fine_14.vtu") pass class MEDCouplingBasicsTest2: diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index a71654bee..be570417e 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -93,6 +93,7 @@ %newobject ParaMEDMEM::DataArrayInt::buildSubstractionOptimized; %newobject ParaMEDMEM::DataArrayInt::buildIntersection; %newobject ParaMEDMEM::DataArrayInt::buildUnique; +%newobject ParaMEDMEM::DataArrayInt::buildUniqueNotSorted; %newobject ParaMEDMEM::DataArrayInt::deltaShiftIndex; %newobject ParaMEDMEM::DataArrayInt::buildExplicitArrByRanges; %newobject ParaMEDMEM::DataArrayInt::buildExplicitArrOfSliceOnScaledArr; @@ -2584,6 +2585,7 @@ namespace ParaMEDMEM DataArrayInt *buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); DataArrayInt *buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); DataArrayInt *buildUnique() const throw(INTERP_KERNEL::Exception); + DataArrayInt *buildUniqueNotSorted() const throw(INTERP_KERNEL::Exception); DataArrayInt *deltaShiftIndex() const throw(INTERP_KERNEL::Exception); void computeOffsets() throw(INTERP_KERNEL::Exception); void computeOffsets2() throw(INTERP_KERNEL::Exception); @@ -2785,6 +2787,16 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrOfSliceOnScaledArr (wrap) : the input slice contains some unknowns that can't be determined in static method ! Call DataArray::getSlice (non static) instead !"); return self->buildExplicitArrOfSliceOnScaledArr(strt,stp,step); } + + PyObject *getMinMaxValues() const throw(INTERP_KERNEL::Exception) + { + int a,b; + self->getMinMaxValues(a,b); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,PyInt_FromLong(a)); + PyTuple_SetItem(ret,1,PyInt_FromLong(b)); + return ret; + } static PyObject *BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, PyObject *arr, PyObject *arrI) throw(INTERP_KERNEL::Exception) {