Salome HOME
Clarification: 'Triangulation' intersection type is the only valid choice
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingMemArray.cxx
index 658d78727d407f86abcfbc2ce3509f7e987c12b3..4d4fed46d4d31e4f7bfb79a9b02beaff89b075f1 100644 (file)
 #include "InterpKernelAutoPtr.hxx"
 #include "InterpKernelExprParser.hxx"
 
+#include "InterpKernelAutoPtr.hxx"
+#include "InterpKernelGeo2DEdgeArcCircle.hxx"
+#include "InterpKernelAutoPtr.hxx"
+#include "InterpKernelGeo2DNode.hxx"
+#include "InterpKernelGeo2DEdgeLin.hxx"
+
 #include <set>
 #include <cmath>
 #include <limits>
@@ -572,7 +578,7 @@ void DataArray::setInfoAndChangeNbOfCompo(const std::vector<std::string>& info)
 
 void DataArray::checkNbOfTuples(int nbOfTuples, const std::string& msg) const
 {
-  if(getNumberOfTuples()!=nbOfTuples)
+  if((int)getNumberOfTuples()!=nbOfTuples)
     {
       std::ostringstream oss; oss << msg << " : mismatch number of tuples : expected " <<  nbOfTuples << " having " << getNumberOfTuples() << " !";
       throw INTERP_KERNEL::Exception(oss.str().c_str());
@@ -631,7 +637,7 @@ void DataArray::CheckValueInRange(int ref, int value, const std::string& msg)
 
 /*!
  * This method checks that [\b start, \b end) is compliant with ref length \b value.
- * typicaly start in [0,\b value) and end in [0,\b value). If value==start and start==end, it is supported.
+ * typically start in [0,\b value) and end in [0,\b value). If value==start and start==end, it is supported.
  */
 void DataArray::CheckValueInRangeEx(int value, int start, int end, const std::string& msg)
 {
@@ -665,9 +671,9 @@ void DataArray::CheckClosingParInRange(int ref, int value, const std::string& ms
  *
  * The input \a sliceId should be an id in [0, \a nbOfSlices) that specifies the slice of work.
  *
- * \param [in] start - the start of the input slice of the whole work to perform splitted into slices.
- * \param [in] stop - the stop of the input slice of the whole work to perform splitted into slices.
- * \param [in] step - the step (that can be <0) of the input slice of the whole work to perform splitted into slices.
+ * \param [in] start - the start of the input slice of the whole work to perform split into slices.
+ * \param [in] stop - the stop of the input slice of the whole work to perform split into slices.
+ * \param [in] step - the step (that can be <0) of the input slice of the whole work to perform split into slices.
  * \param [in] sliceId - the slice id considered
  * \param [in] nbOfSlices - the number of slices (typically the number of cores on which the work is expected to be sliced)
  * \param [out] startSlice - the start of the slice considered
@@ -1267,21 +1273,21 @@ DataArrayInt *DataArrayDouble::computeNbOfInteractionsWith(const DataArrayDouble
     case 3:
       {
         BBTree<3,int> bbt(otherBBoxFrmt->begin(),0,0,otherBBoxFrmt->getNumberOfTuples(),eps);
-        for(int i=0;i<nbOfTuples;i++,retPtr++,thisBBPtr+=nbOfComp)
+        for(std::size_t i=0;i<nbOfTuples;i++,retPtr++,thisBBPtr+=nbOfComp)
           *retPtr=bbt.getNbOfIntersectingElems(thisBBPtr);
         break;
       }
     case 2:
       {
         BBTree<2,int> bbt(otherBBoxFrmt->begin(),0,0,otherBBoxFrmt->getNumberOfTuples(),eps);
-        for(int i=0;i<nbOfTuples;i++,retPtr++,thisBBPtr+=nbOfComp)
+        for(std::size_t i=0;i<nbOfTuples;i++,retPtr++,thisBBPtr+=nbOfComp)
           *retPtr=bbt.getNbOfIntersectingElems(thisBBPtr);
         break;
       }
     case 1:
       {
         BBTree<1,int> bbt(otherBBoxFrmt->begin(),0,0,otherBBoxFrmt->getNumberOfTuples(),eps);
-        for(int i=0;i<nbOfTuples;i++,retPtr++,thisBBPtr+=nbOfComp)
+        for(std::size_t i=0;i<nbOfTuples;i++,retPtr++,thisBBPtr+=nbOfComp)
           *retPtr=bbt.getNbOfIntersectingElems(thisBBPtr);
         break;
       }
@@ -1517,7 +1523,7 @@ void DataArrayDouble::recenterForMaxPrecision(double eps)
 
 /*!
  * Returns the maximal value and all its locations within \a this one-dimensional array.
- *  \param [out] tupleIds - a new instance of DataArrayInt containg indices of
+ *  \param [out] tupleIds - a new instance of DataArrayInt containing indices of
  *               tuples holding the maximal value. The caller is to delete it using
  *               decrRef() as it is no more needed.
  *  \return double - the maximal value among all values of \a this array.
@@ -1535,7 +1541,7 @@ double DataArrayDouble::getMaxValue2(DataArrayInt*& tupleIds) const
 
 /*!
  * Returns the minimal value and all its locations within \a this one-dimensional array.
- *  \param [out] tupleIds - a new instance of DataArrayInt containg indices of
+ *  \param [out] tupleIds - a new instance of DataArrayInt containing indices of
  *               tuples holding the minimal value. The caller is to delete it using
  *               decrRef() as it is no more needed.
  *  \return double - the minimal value among all values of \a this array.
@@ -1611,7 +1617,7 @@ double DataArrayDouble::norm2() const
 
 /*!
  * Returns the maximum norm of the vector defined by \a this array.
- * This method works even if the number of components is diferent from one.
+ * This method works even if the number of components is different from one.
  * If the number of elements in \a this is 0, -1. is returned.
  *  \return double - the value of the maximum norm, i.e.
  *          the maximal absolute value among values of \a this array (whatever its number of components).
@@ -1634,7 +1640,7 @@ double DataArrayDouble::normMax() const
 
 /*!
  * Returns the minimum norm (absolute value) of the vector defined by \a this array.
- * This method works even if the number of components is diferent from one.
+ * This method works even if the number of components is different from one.
  * If the number of elements in \a this is 0, std::numeric_limits<double>::max() is returned.
  *  \return double - the value of the minimum norm, i.e.
  *          the minimal absolute value among values of \a this array (whatever its number of components).
@@ -2041,7 +2047,7 @@ DataArrayDouble *DataArrayDouble::fromCartToCylGiven(const DataArrayDouble *coor
     throw INTERP_KERNEL::Exception("DataArrayDouble::fromCartToCylGiven : input coords are NULL !");
   MCAuto<DataArrayDouble> ret(DataArrayDouble::New());
   checkAllocated(); coords->checkAllocated();
-  int nbOfComp(getNumberOfComponents()),nbTuples(getNumberOfTuples());
+  std::size_t nbOfComp(getNumberOfComponents()),nbTuples(getNumberOfTuples());
   if(nbOfComp!=3)
     throw INTERP_KERNEL::Exception("DataArrayDouble::fromCartToCylGiven : must be an array with exactly 3 components !");
   if(coords->getNumberOfComponents()!=3)
@@ -2489,6 +2495,38 @@ DataArrayDouble *DataArrayDouble::buildEuclidianDistanceDenseMatrixWith(const Da
   return ret.retn();
 }
 
+/*!
+ * This method expects that \a this stores 3 tuples containing 2 components each.
+ * Each of this tuples represent a point into 2D space.
+ * This method tries to find an arc of circle starting from first point (tuple) to 2nd and middle point (tuple) along 3nd and last point (tuple).
+ * If such arc of circle exists, the corresponding center, radius of circle is returned. And additionnaly the length of arc expressed with an \a ang output variable in ]0,2*pi[.
+ *  
+ *  \throw If \a this is not allocated.
+ *  \throw If \a this has not 3 tuples of 2 components
+ *  \throw If tuples/points in \a this are aligned
+ */
+void DataArrayDouble::asArcOfCircle(double center[2], double& radius, double& ang) const
+{
+  checkAllocated();
+  INTERP_KERNEL::QuadraticPlanarArcDetectionPrecision arcPrec(1e-14);
+  if(getNumberOfTuples()!=3 && getNumberOfComponents()!=2)
+    throw INTERP_KERNEL::Exception("DataArrayDouble::asArcCircle : this method expects");
+  const double *pt(begin());
+  MCAuto<INTERP_KERNEL::Node> n0(new INTERP_KERNEL::Node(pt[0],pt[1])),n1(new INTERP_KERNEL::Node(pt[2],pt[3])),n2(new INTERP_KERNEL::Node(pt[4],pt[5]));
+  {
+    INTERP_KERNEL::AutoCppPtr<INTERP_KERNEL::EdgeLin> e1(new INTERP_KERNEL::EdgeLin(n0,n2)),e2(new INTERP_KERNEL::EdgeLin(n2,n1));
+    INTERP_KERNEL::SegSegIntersector inters(*e1,*e2);
+    bool colinearity(inters.areColinears());
+    if(colinearity)
+      throw INTERP_KERNEL::Exception("DataArrayDouble::asArcOfCircle : 3 points in this have been detected as colinear !");
+  }
+  INTERP_KERNEL::AutoCppPtr<INTERP_KERNEL::EdgeArcCircle> ret(new INTERP_KERNEL::EdgeArcCircle(n0,n2,n1));
+  const double *c(ret->getCenter());
+  center[0]=c[0]; center[1]=c[1];
+  radius=ret->getRadius();
+  ang=ret->getAngle();
+}
+
 /*!
  * Sorts value within every tuple of \a this array.
  *  \param [in] asc - if \a true, the values are sorted in ascending order, else,
@@ -3005,7 +3043,7 @@ DataArrayDoubleIterator *DataArrayDouble::iterator()
 }
 
 /*!
- * Returns a new DataArrayInt contating indices of tuples of \a this one-dimensional
+ * Returns a new DataArrayInt containing indices of tuples of \a this one-dimensional
  * array whose values are within a given range. Textual data is not copied.
  *  \param [in] vmin - a lowest acceptable value (included).
  *  \param [in] vmax - a greatest acceptable value (included).
@@ -3036,7 +3074,7 @@ DataArrayInt *DataArrayDouble::findIdsInRange(double vmin, double vmax) const
 }
 
 /*!
- * Returns a new DataArrayInt contating indices of tuples of \a this one-dimensional
+ * Returns a new DataArrayInt containing indices of tuples of \a this one-dimensional
  * array whose values are not within a given range. Textual data is not copied.
  *  \param [in] vmin - a lowest not acceptable value (excluded).
  *  \param [in] vmax - a greatest not acceptable value (excluded).
@@ -3148,15 +3186,14 @@ DataArrayDouble *DataArrayDouble::Dot(const DataArrayDouble *a1, const DataArray
   std::size_t nbOfComp(a1->getNumberOfComponents());
   if(nbOfComp!=a2->getNumberOfComponents())
     throw INTERP_KERNEL::Exception("Nb of components mismatch for array Dot !");
-  int nbOfTuple=a1->getNumberOfTuples();
+  std::size_t nbOfTuple(a1->getNumberOfTuples());
   if(nbOfTuple!=a2->getNumberOfTuples())
     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Dot !");
   DataArrayDouble *ret=DataArrayDouble::New();
   ret->alloc(nbOfTuple,1);
   double *retPtr=ret->getPointer();
-  const double *a1Ptr=a1->getConstPointer();
-  const double *a2Ptr=a2->getConstPointer();
-  for(int i=0;i<nbOfTuple;i++)
+  const double *a1Ptr=a1->begin(),*a2Ptr(a2->begin());
+  for(std::size_t i=0;i<nbOfTuple;i++)
     {
       double sum=0.;
       for(std::size_t j=0;j<nbOfComp;j++)
@@ -3194,15 +3231,14 @@ DataArrayDouble *DataArrayDouble::CrossProduct(const DataArrayDouble *a1, const
     throw INTERP_KERNEL::Exception("Nb of components mismatch for array crossProduct !");
   if(nbOfComp!=3)
     throw INTERP_KERNEL::Exception("Nb of components must be equal to 3 for array crossProduct !");
-  int nbOfTuple=a1->getNumberOfTuples();
+  std::size_t nbOfTuple(a1->getNumberOfTuples());
   if(nbOfTuple!=a2->getNumberOfTuples())
     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array crossProduct !");
   DataArrayDouble *ret=DataArrayDouble::New();
   ret->alloc(nbOfTuple,3);
   double *retPtr=ret->getPointer();
-  const double *a1Ptr=a1->getConstPointer();
-  const double *a2Ptr=a2->getConstPointer();
-  for(int i=0;i<nbOfTuple;i++)
+  const double *a1Ptr(a1->begin()),*a2Ptr(a2->begin());
+  for(std::size_t i=0;i<nbOfTuple;i++)
     {
       retPtr[3*i]=a1Ptr[3*i+1]*a2Ptr[3*i+2]-a1Ptr[3*i+2]*a2Ptr[3*i+1];
       retPtr[3*i+1]=a1Ptr[3*i+2]*a2Ptr[3*i]-a1Ptr[3*i]*a2Ptr[3*i+2];
@@ -3232,19 +3268,18 @@ DataArrayDouble *DataArrayDouble::Max(const DataArrayDouble *a1, const DataArray
   std::size_t nbOfComp(a1->getNumberOfComponents());
   if(nbOfComp!=a2->getNumberOfComponents())
     throw INTERP_KERNEL::Exception("Nb of components mismatch for array Max !");
-  int nbOfTuple=a1->getNumberOfTuples();
+  std::size_t nbOfTuple(a1->getNumberOfTuples());
   if(nbOfTuple!=a2->getNumberOfTuples())
     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Max !");
-  DataArrayDouble *ret=DataArrayDouble::New();
+  MCAuto<DataArrayDouble> ret(DataArrayDouble::New());
   ret->alloc(nbOfTuple,nbOfComp);
-  double *retPtr=ret->getPointer();
-  const double *a1Ptr=a1->getConstPointer();
-  const double *a2Ptr=a2->getConstPointer();
-  int nbElem=nbOfTuple*nbOfComp;
-  for(int i=0;i<nbElem;i++)
+  double *retPtr(ret->getPointer());
+  const double *a1Ptr(a1->begin()),*a2Ptr(a2->begin());
+  std::size_t nbElem(nbOfTuple*nbOfComp);
+  for(std::size_t i=0;i<nbElem;i++)
     retPtr[i]=std::max(a1Ptr[i],a2Ptr[i]);
   ret->copyStringInfoFrom(*a1);
-  return ret;
+  return ret.retn();
 }
 
 /*!
@@ -3267,19 +3302,18 @@ DataArrayDouble *DataArrayDouble::Min(const DataArrayDouble *a1, const DataArray
   std::size_t nbOfComp(a1->getNumberOfComponents());
   if(nbOfComp!=a2->getNumberOfComponents())
     throw INTERP_KERNEL::Exception("Nb of components mismatch for array min !");
-  int nbOfTuple=a1->getNumberOfTuples();
+  std::size_t nbOfTuple(a1->getNumberOfTuples());
   if(nbOfTuple!=a2->getNumberOfTuples())
     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array min !");
-  DataArrayDouble *ret=DataArrayDouble::New();
+  MCAuto<DataArrayDouble> ret(DataArrayDouble::New());
   ret->alloc(nbOfTuple,nbOfComp);
-  double *retPtr=ret->getPointer();
-  const double *a1Ptr=a1->getConstPointer();
-  const double *a2Ptr=a2->getConstPointer();
-  int nbElem=nbOfTuple*nbOfComp;
-  for(int i=0;i<nbElem;i++)
+  double *retPtr(ret->getPointer());
+  const double *a1Ptr(a1->begin()),*a2Ptr(a2->begin());
+  std::size_t nbElem(nbOfTuple*nbOfComp);
+  for(std::size_t i=0;i<nbElem;i++)
     retPtr[i]=std::min(a1Ptr[i],a2Ptr[i]);
   ret->copyStringInfoFrom(*a1);
-  return ret;
+  return ret.retn();
 }
 
 /*!
@@ -3959,7 +3993,7 @@ bool DataArrayInt::isRange(int& strt, int& sttoopp, int& stteepp) const
  *  \throw If any value of \a this can't be used as a valid index for 
  *         [\a indArrBg, \a indArrEnd).
  *
- *  \sa changeValue
+ *  \sa changeValue, findIdForEach
  */
 void DataArrayInt::transformWithIndArr(const int *indArrBg, const int *indArrEnd)
 {
@@ -3974,7 +4008,7 @@ void DataArrayInt::transformWithIndArr(const int *indArrBg, const int *indArrEnd
       else
         {
           std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " of this value is " << *pt << ", should be in [0," << nbElemsIn << ") !";
-          throw INTERP_KERNEL::Exception(oss.str().c_str());
+          throw INTERP_KERNEL::Exception(oss.str());
         }
     }
   this->declareAsNew();
@@ -3985,7 +4019,7 @@ void DataArrayInt::transformWithIndArr(const MapKeyVal<int>& m)
   this->checkAllocated();
   if(this->getNumberOfComponents()!=1)
     throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !");
-  const std::map<int,int> dat(m.data());
+  const std::map<int,int>& dat(m.data());
   int nbOfTuples(getNumberOfTuples()),*pt(getPointer());
   for(int i=0;i<nbOfTuples;i++,pt++)
     {
@@ -3995,7 +4029,7 @@ void DataArrayInt::transformWithIndArr(const MapKeyVal<int>& m)
       else
         {
           std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " of this value is " << *pt << " not in map !";
-          throw INTERP_KERNEL::Exception(oss.str().c_str());
+          throw INTERP_KERNEL::Exception(oss.str());
         }
     }
   this->declareAsNew();
@@ -4173,14 +4207,16 @@ DataArrayInt *DataArrayInt::invertArrayN2O2O2N(int oldNbOfElem) const
  *  \sa invertArrayN2O2O2N
  *  \endif
  */
-MCAuto< MapKeyVal<int> > DataArrayInt::invertArrayN2O2O2NOptimized() const
+MCAuto< MapKeyVal<int> > DataArrayInt32::invertArrayN2O2O2NOptimized() const
 {
   checkAllocated();
+  if(getNumberOfComponents()!=1)
+    throw INTERP_KERNEL::Exception("DataArrayInt32::invertArrayN2O2O2NOptimized : single component expected !");
   MCAuto< MapKeyVal<int> > ret(MapKeyVal<int>::New());
   std::map<int,int>& m(ret->data());
   const int *new2Old(begin());
-  int nbOfNewElems(this->getNumberOfTuples());
-  for(int i=0;i<nbOfNewElems;i++)
+  std::size_t nbOfNewElems(this->getNumberOfTuples());
+  for(std::size_t i=0;i<nbOfNewElems;i++)
     {
       int v(new2Old[i]);
       m[v]=i;
@@ -4216,17 +4252,25 @@ DataArrayInt *DataArrayInt::checkAndPreparePermutation() const
 }
 
 /*!
- * This method tries to find the permutation to apply to the first input \a ids1 to obtain the same array (without considering strings informations) the second
+ * This method tries to find the permutation to apply to the first input \a ids1 to obtain the same array (without considering strings information) the second
  * input array \a ids2.
  * \a ids1 and \a ids2 are expected to be both a list of ids (both with number of components equal to one) not sorted and with values that can be negative.
  * This method will throw an exception is no such permutation array can be obtained. It is typically the case if there is some ids in \a ids1 not in \a ids2 or
  * inversely.
- * In case of success (no throw) : \c ids1->renumber(ret)->isEqual(ids2) where \a ret is the return of this method.
+ * In case of success both assertion will be true (no throw) :
+ * \c ids1->renumber(ret)->isEqual(ids2) where \a ret is the return of this method.
+ * \c ret->transformWithIndArr(ids2)->isEqual(ids1)
+ *
+ * \b Example:
+ * - \a ids1 : [3,1,103,4,6,10,-7,205]
+ * - \a ids2 : [-7,1,205,10,6,3,103,4]
+ * - \a return is : [5,1,6,7,4,3,0,2] because ids2[5]==ids1[0], ids2[1]==ids1[1], ids2[6]==ids1[2]...
  *
  * \return DataArrayInt * - a new instance of DataArrayInt. The caller is to delete this
  *          array using decrRef() as it is no more needed.
  * \throw If either ids1 or ids2 is null not allocated or not with one components.
  * 
+ * \sa DataArrayInt32::findIdForEach
  */
 DataArrayInt *DataArrayInt::FindPermutationFromFirstToSecond(const DataArrayInt *ids1, const DataArrayInt *ids2)
 {
@@ -4526,7 +4570,7 @@ bool DataArrayInt::hasUniqueValues() const
   checkAllocated();
   if(getNumberOfComponents()!=1)
     throw INTERP_KERNEL::Exception("DataArrayInt::hasOnlyUniqueValues: must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
-  int nbOfTuples(getNumberOfTuples());
+  std::size_t nbOfTuples(getNumberOfTuples());
   std::set<int> s(begin(),end());  // in C++11, should use unordered_set (O(1) complexity)
   if (s.size() != nbOfTuples)
     return false;
@@ -4635,7 +4679,7 @@ DataArrayInt *DataArrayInt::findIdsEqualTuple(const int *tupleBg, const int *tup
 {
   std::size_t nbOfCompoExp(std::distance(tupleBg,tupleEnd));
   checkAllocated();
-  if(getNumberOfComponents()!=(int)nbOfCompoExp)
+  if(getNumberOfComponents()!=nbOfCompoExp)
     {
       std::ostringstream oss; oss << "DataArrayInt::findIdsEqualTuple : mismatch of number of components. Input tuple has " << nbOfCompoExp << " whereas this array has " << getNumberOfComponents() << " components !";
       throw INTERP_KERNEL::Exception(oss.str().c_str());
@@ -4658,6 +4702,47 @@ DataArrayInt *DataArrayInt::findIdsEqualTuple(const int *tupleBg, const int *tup
   return ret.retn();
 }
 
+/*!
+ * This method finds for each element \a ELT in [valsBg,valsEnd) elements in \a this equal to it. Associated to ELT
+ * this method will return the tuple id of last element found. If there is no element in \a this equal to ELT
+ * an exception will be thrown.
+ *
+ * In case of success this[ret]==vals. Samely ret->transformWithIndArr(this->begin(),this->end())==vals.
+ * Where \a vals is the [valsBg,valsEnd) array and \a ret the array returned by this method.
+ * This method can be seen as an extension of FindPermutationFromFirstToSecond.
+ * <br>
+ * \b Example: <br>
+ * - \a this: [17,27,2,10,-4,3,12,27,16]
+ * - \a val : [3,16,-4,27,17]
+ * - result: [5,8,4,7,0]
+ *
+ * \return - An array of size std::distance(valsBg,valsEnd)
+ *
+ * \sa DataArrayInt32::FindPermutationFromFirstToSecond
+ */
+MCAuto<DataArrayInt32> DataArrayInt32::findIdForEach(const int *valsBg, const int *valsEnd) const
+{
+  MCAuto<DataArrayInt32> ret(DataArrayInt32::New());
+  std::size_t nbOfTuplesOut(std::distance(valsBg,valsEnd));
+  ret->alloc(nbOfTuplesOut,1);
+  MCAuto< MapKeyVal<int> > zeMap(invertArrayN2O2O2NOptimized());
+  const std::map<int,int>& dat(zeMap->data());
+  int *ptToFeed(ret->getPointer());
+  for(const int *pt=valsBg;pt!=valsEnd;pt++)
+    {
+      std::map<int,int>::const_iterator it(dat.find(*pt));
+      if(it!=dat.end())
+        *ptToFeed++=(*it).second;
+      else
+        {
+          std::ostringstream oss; oss << "DataArrayInt32::findIdForEach : error for element at place " << std::distance(valsBg,pt);
+          oss << " of input array value is " << *pt << " which is not in this !";
+          throw INTERP_KERNEL::Exception(oss.str());
+        }
+    }
+  return ret;
+}
+
 /*!
  * Assigns \a newValue to all elements holding \a oldValue within \a this
  * one-dimensional array.
@@ -5010,17 +5095,16 @@ DataArrayInt *DataArrayInt::Aggregate(const DataArrayInt *a1, const DataArrayInt
 {
   if(!a1 || !a2)
     throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : input DataArrayInt instance is NULL !");
-  int nbOfComp=a1->getNumberOfComponents();
+  std::size_t nbOfComp(a1->getNumberOfComponents());
   if(nbOfComp!=a2->getNumberOfComponents())
     throw INTERP_KERNEL::Exception("Nb of components mismatch for array Aggregation !");
-  int nbOfTuple1=a1->getNumberOfTuples();
-  int nbOfTuple2=a2->getNumberOfTuples();
-  DataArrayInt *ret=DataArrayInt::New();
+  std::size_t nbOfTuple1(a1->getNumberOfTuples()),nbOfTuple2(a2->getNumberOfTuples());
+  MCAuto<DataArrayInt> ret(DataArrayInt::New());
   ret->alloc(nbOfTuple1+nbOfTuple2-offsetA2,nbOfComp);
-  int *pt=std::copy(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple1*nbOfComp,ret->getPointer());
+  int *pt=std::copy(a1->begin(),a1->end(),ret->getPointer());
   std::copy(a2->getConstPointer()+offsetA2*nbOfComp,a2->getConstPointer()+nbOfTuple2*nbOfComp,pt);
   ret->copyStringInfoFrom(*a1);
-  return ret;
+  return ret.retn();
 }
 
 /*!
@@ -5047,8 +5131,7 @@ DataArrayInt *DataArrayInt::Aggregate(const std::vector<const DataArrayInt *>& a
   if(a.empty())
     throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : input list must be NON EMPTY !");
   std::vector<const DataArrayInt *>::const_iterator it=a.begin();
-  int nbOfComp=(*it)->getNumberOfComponents();
-  int nbt=(*it++)->getNumberOfTuples();
+  std::size_t nbOfComp((*it)->getNumberOfComponents()),nbt((*it++)->getNumberOfTuples());
   for(int i=1;it!=a.end();it++,i++)
     {
       if((*it)->getNumberOfComponents()!=nbOfComp)
@@ -5573,7 +5656,7 @@ DataArrayInt *DataArrayInt::BuildListOfSwitchedOff(const std::vector<bool>& v)
 }
 
 /*!
- * This method allows to put a vector of vector of integer into a more compact data stucture (skyline). 
+ * This method allows to put a vector of vector of integer into a more compact data structure (skyline). 
  * This method is not available into python because no available optimized data structure available to map std::vector< std::vector<int> >.
  *
  * \param [in] v the input data structure to be translate into skyline format.
@@ -5797,7 +5880,7 @@ DataArrayInt *DataArrayInt::buildUniqueNotSorted() const
  * "MEDCouplingUMesh::buildDescendingConnectivity" and
  * \ref MEDCoupling::MEDCouplingUMesh::getNodalConnectivityIndex
  * "MEDCouplingUMesh::getNodalConnectivityIndex" etc.
- * This method preforms the reverse operation of DataArrayInt::computeOffsetsFull.
+ * This method performs the reverse operation of DataArrayInt::computeOffsetsFull.
  *  \return DataArrayInt * - a new instance of DataArrayInt, whose number of tuples
  *          equals to \a this->getNumberOfComponents() - 1, and number of components is 1.
  *          The caller is to delete this array using decrRef() as it is no more needed. 
@@ -5873,7 +5956,7 @@ void DataArrayInt::computeOffsets()
  * components remains the same and number of tuples is inceamented by one.<br>
  * This method is useful for allToAllV in MPI with contiguous policy. This method
  * differs from computeOffsets() in that the number of tuples is changed by this one.
- * This method preforms the reverse operation of DataArrayInt::deltaShiftIndex.
+ * This method performs the reverse operation of DataArrayInt::deltaShiftIndex.
  *  \throw If \a this is not allocated.
  *  \throw If \a this->getNumberOfComponents() != 1.
  *