Salome HOME
MEDCouplingUMesh::computePlaneEquationOf3DFaces method to localize warpped faces
authorageay <ageay>
Wed, 9 Oct 2013 15:30:21 +0000 (15:30 +0000)
committerageay <ageay>
Wed, 9 Oct 2013 15:30:21 +0000 (15:30 +0000)
DataArrayDouble::sumPerTuple, DataArrayInt::sumPerTuple

src/MEDCoupling/MEDCouplingMemArray.cxx
src/MEDCoupling/MEDCouplingMemArray.hxx
src/MEDCoupling_Swig/MEDCouplingMemArray.i

index ca8343508e47afbb028b5ee5e479200e2b84917b..fec8fe9db520b8e9bbe5902367af9d9e2a34c4cb 100644 (file)
@@ -3818,6 +3818,28 @@ DataArrayDouble *DataArrayDouble::magnitude() const
   return ret;
 }
 
+/*!
+ * Computes for each tuple the sum of number of components values in the tuple and return it.
+ * 
+ * \return DataArrayDouble * - the new instance of DataArrayDouble containing the
+ *          same number of tuples as \a this array and one component.
+ *          The caller is to delete this result array using decrRef() as it is no more
+ *          needed.
+ *  \throw If \a this is not allocated.
+ */
+DataArrayDouble *DataArrayDouble::sumPerTuple() const
+{
+  checkAllocated();
+  int nbOfComp(getNumberOfComponents()),nbOfTuple(getNumberOfTuples());
+  MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret(DataArrayDouble::New());
+  ret->alloc(nbOfTuple,1);
+  const double *src(getConstPointer());
+  double *dest(ret->getPointer());
+  for(int i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
+    *dest=std::accumulate(src,src+nbOfComp,0.);
+  return ret.retn();
+}
+
 /*!
  * Computes the maximal value within every tuple of \a this array.
  *  \return DataArrayDouble * - the new instance of DataArrayDouble containing the
@@ -6456,6 +6478,28 @@ void DataArrayInt::sort(bool asc)
   declareAsNew();
 }
 
+/*!
+ * Computes for each tuple the sum of number of components values in the tuple and return it.
+ * 
+ * \return DataArrayInt * - the new instance of DataArrayInt containing the
+ *          same number of tuples as \a this array and one component.
+ *          The caller is to delete this result array using decrRef() as it is no more
+ *          needed.
+ *  \throw If \a this is not allocated.
+ */
+DataArrayInt *DataArrayInt::sumPerTuple() const
+{
+  checkAllocated();
+  int nbOfComp(getNumberOfComponents()),nbOfTuple(getNumberOfTuples());
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
+  ret->alloc(nbOfTuple,1);
+  const int *src(getConstPointer());
+  int *dest(ret->getPointer());
+  for(int i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
+    *dest=std::accumulate(src,src+nbOfComp,0);
+  return ret.retn();
+}
+
 /*!
  * Reverse the array values.
  *  \throw If \a this->getNumberOfComponents() < 1.
index 9fcd96654c43fbfac4df1be7b962fc282a6ab8ce..1fa5194fbdb7849b0e328df229bfef4202c97798 100644 (file)
@@ -324,6 +324,7 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT DataArrayDouble *trace() const;
     MEDCOUPLING_EXPORT DataArrayDouble *deviator() const;
     MEDCOUPLING_EXPORT DataArrayDouble *magnitude() const;
+    MEDCOUPLING_EXPORT DataArrayDouble *sumPerTuple() const;
     MEDCOUPLING_EXPORT DataArrayDouble *maxPerTuple() const;
     MEDCOUPLING_EXPORT DataArrayDouble *maxPerTupleWithCompoId(DataArrayInt* &compoIdOfMaxPerTuple) const;
     MEDCOUPLING_EXPORT DataArrayDouble *buildEuclidianDistanceDenseMatrix() const;
@@ -448,6 +449,7 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const;
     MEDCOUPLING_EXPORT bool isFittingWith(const std::vector<bool>& v) const;
     MEDCOUPLING_EXPORT DataArrayInt *buildPermutationArr(const DataArrayInt& other) const;
+    MEDCOUPLING_EXPORT DataArrayInt *sumPerTuple() const;
     MEDCOUPLING_EXPORT void sort(bool asc=true);
     MEDCOUPLING_EXPORT void reverse();
     MEDCOUPLING_EXPORT void checkMonotonic(bool increasing) const;
index b2b572045edbc918fc50dbb5eea060b8918f410b..f3e7a7655c2f61abbfa2dde91cd48ebaf0190eb3 100644 (file)
@@ -67,6 +67,7 @@
 %newobject ParaMEDMEM::DataArrayInt::getIdsNotEqual;
 %newobject ParaMEDMEM::DataArrayInt::getIdsEqualList;
 %newobject ParaMEDMEM::DataArrayInt::getIdsNotEqualList;
+%newobject ParaMEDMEM::DataArrayInt::sumPerTuple;
 %newobject ParaMEDMEM::DataArrayInt::negate;
 %newobject ParaMEDMEM::DataArrayInt::getIdsInRange;
 %newobject ParaMEDMEM::DataArrayInt::Aggregate;
 %newobject ParaMEDMEM::DataArrayDouble::deviator;
 %newobject ParaMEDMEM::DataArrayDouble::magnitude;
 %newobject ParaMEDMEM::DataArrayDouble::maxPerTuple;
+%newobject ParaMEDMEM::DataArrayDouble::sumPerTuple;
 %newobject ParaMEDMEM::DataArrayDouble::computeBBoxPerTuple;
 %newobject ParaMEDMEM::DataArrayDouble::buildEuclidianDistanceDenseMatrix;
 %newobject ParaMEDMEM::DataArrayDouble::buildEuclidianDistanceDenseMatrixWith;
@@ -553,6 +555,7 @@ namespace ParaMEDMEM
     DataArrayDouble *deviator() const throw(INTERP_KERNEL::Exception);
     DataArrayDouble *magnitude() const throw(INTERP_KERNEL::Exception);
     DataArrayDouble *maxPerTuple() const throw(INTERP_KERNEL::Exception);
+    DataArrayDouble *sumPerTuple() const throw(INTERP_KERNEL::Exception);
     DataArrayDouble *buildEuclidianDistanceDenseMatrix() const throw(INTERP_KERNEL::Exception);
     DataArrayDouble *buildEuclidianDistanceDenseMatrixWith(const DataArrayDouble *other) const throw(INTERP_KERNEL::Exception);
     void sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception);
@@ -2488,6 +2491,7 @@ namespace ParaMEDMEM
     bool isEqualWithoutConsideringStr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception);
     bool isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception);
     DataArrayInt *buildPermutationArr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception);
+    DataArrayInt *sumPerTuple() const throw(INTERP_KERNEL::Exception);
     void sort(bool asc=true) throw(INTERP_KERNEL::Exception);
     void reverse() throw(INTERP_KERNEL::Exception);
     void checkMonotonic(bool increasing) const throw(INTERP_KERNEL::Exception);