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<int>::max(); maxValue=-std::numeric_limits<int>::max();
+ for(int i=0;i<nbTuples;i++,pt++)
+ {
+ if(*pt<minValue)
+ minValue=*pt;
+ if(*pt>maxValue)
+ 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
*
* \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
{
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<bool> b(maxVal-minVal+1,false);
+ const int *ptBg(begin()),*endBg(end());
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> 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
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);
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();
}
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<DataArrayInt> idsNonColPerCell(elts->getIdsEqual(*it));
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())
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))
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)
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:
%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;
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);
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)
{