X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingMemArray.cxx;h=5006c10a8a7d002d5288c10e1a800c69207c5520;hb=9abc40a840f69fd7f07b356cd31876b64dc81e14;hp=baa8dbd292b300f3a4fae94592de66549ec7c953;hpb=740f93fb5c29f8a2b5439f25381c0963d854272e;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index baa8dbd29..5006c10a8 100755 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2019 CEA/DEN, EDF R&D +// Copyright (C) 2007-2022 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -67,7 +67,7 @@ void MEDCoupling::DACheckNbOfTuplesAndComp(const DataArray *da, mcIdType nbOfTup da->checkNbOfTuplesAndComp(nbOfTuples,nbOfCompo,msg); } -template +template void DataArrayDouble::findCommonTuplesAlg(const double *bbox, mcIdType nbNodes, mcIdType limitNodeId, double prec, DataArrayIdType *c, DataArrayIdType *cI) const { const double *coordsPtr=getConstPointer(); @@ -100,7 +100,7 @@ void DataArrayDouble::findCommonTuplesAlg(const double *bbox, mcIdType nbNodes, } } -template +template void DataArrayDouble::FindTupleIdsNearTuplesAlg(const BBTreePts& myTree, const double *pos, mcIdType nbOfTuples, double eps, DataArrayIdType *c, DataArrayIdType *cI) { @@ -116,10 +116,10 @@ void DataArrayDouble::FindTupleIdsNearTuplesAlg(const BBTreePts +template void DataArrayDouble::FindClosestTupleIdAlg(const BBTreePts& myTree, double dist, const double *pos, mcIdType nbOfTuples, const double *thisPt, mcIdType thisNbOfTuples, mcIdType *res) { - double distOpt(dist); + double distOpt = std::max(dist, std::numeric_limits::epsilon()); const double *p(pos); mcIdType *r(res); for(mcIdType i=0;i=nbOfCompoOth || compoIds[i]<0) + if(compoIds[i]>=nbOfCompoOth) { std::ostringstream oss; oss << "Specified component id is out of range (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompoOth << ")"; throw INTERP_KERNEL::Exception(oss.str().c_str()); @@ -220,7 +220,7 @@ void DataArray::copyPartOfStringInfoFrom2(const std::vector& compoI std::size_t partOfCompoToSet=compoIds.size(); std::size_t nbOfCompo=getNumberOfComponents(); for(std::size_t i=0;i=nbOfCompo || compoIds[i]<0) + if(compoIds[i]>=nbOfCompo) { std::ostringstream oss; oss << "Specified component id is out of range (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompo << ")"; throw INTERP_KERNEL::Exception(oss.str().c_str()); @@ -423,6 +423,29 @@ std::string DataArray::getUnitOnComponent(std::size_t i) const } } +/*! + * Split \a st string into chunks of sz characters each. + * Size of input \a st must a be a multiple of \a sz. If not an exception is thrown. + */ +std::vector DataArray::SplitStringInChuncks(const std::string st, std::size_t sz) +{ + std::size_t len = st.length(); + std::size_t nbOfCompo(len/sz); + if( nbOfCompo*sz != len) + { + THROW_IK_EXCEPTION("DataArray::SplitStringInChuncks : Length of input string (" << len << ") is not equal to " << nbOfCompo << "*" << sz << " !"); + } + std::vector ret(nbOfCompo); + for(std::size_t i = 0 ; i < nbOfCompo ; ++i) + { + std::string part = st.substr(i*sz,sz); + std::size_t p3=part.find_last_not_of(" \t"); + part = part.substr(0,p3+1); + ret[i] = part; + } + return ret; +} + /*! * Returns the var part of the full component information. * For example, if \a info == "SIGXY [N/m^2]", then this method returns "SIGXY". @@ -1880,6 +1903,7 @@ DataArrayDouble *DataArrayDouble::cartesianize(MEDCouplingAxisType atOfThis) con { case AX_CART: ret=deepCopy(); + break; case AX_CYL: if(nbOfComp==3) { @@ -2011,13 +2035,13 @@ DataArrayDouble *DataArrayDouble::fromCartToCylGiven(const DataArrayDouble *coor throw INTERP_KERNEL::Exception("DataArrayDouble::fromCartToCylGiven : magnitude of vect is too low !"); double Ur[3],Uteta[3],Uz[3],*retPtr(ret->getPointer()); const double *coo(coords->begin()),*vectField(begin()); - std::transform(vect,vect+3,Uz,std::bind2nd(std::multiplies(),1./magOfVect)); + std::transform(vect,vect+3,Uz,std::bind(std::multiplies(),std::placeholders::_1,1./magOfVect)); for(mcIdType i=0;i()); Uteta[0]=Uz[1]*Ur[2]-Uz[2]*Ur[1]; Uteta[1]=Uz[2]*Ur[0]-Uz[0]*Ur[2]; Uteta[2]=Uz[0]*Ur[1]-Uz[1]*Ur[0]; double magOfTeta(sqrt(Uteta[0]*Uteta[0]+Uteta[1]*Uteta[1]+Uteta[2]*Uteta[2])); - std::transform(Uteta,Uteta+3,Uteta,std::bind2nd(std::multiplies(),1./magOfTeta)); + std::transform(Uteta,Uteta+3,Uteta,std::bind(std::multiplies(),std::placeholders::_1,1./magOfTeta)); Ur[0]=Uteta[1]*Uz[2]-Uteta[2]*Uz[1]; Ur[1]=Uteta[2]*Uz[0]-Uteta[0]*Uz[2]; Ur[2]=Uteta[0]*Uz[1]-Uteta[1]*Uz[0]; retPtr[0]=Ur[0]*vectField[0]+Ur[1]*vectField[1]+Ur[2]*vectField[2]; retPtr[1]=Uteta[0]*vectField[0]+Uteta[1]*vectField[1]+Uteta[2]*vectField[2]; @@ -2092,7 +2116,13 @@ DataArrayDouble *DataArrayDouble::determinant() const /*! * Computes 3 eigenvalues of every upper triangular matrix defined by the tuple of - * \a this array, which contains 6 components. + * \a this array, which contains 6 components. The 6 components of tuples are expected to be stored as follow :
+ * \a tuple[0] = \c matrix_XX
+ * \a tuple[1] = \c matrix_YY
+ * \a tuple[2] = \c matrix_ZZ
+ * \a tuple[3] = \c matrix_XY
+ * \a tuple[4] = \c matrix_YZ
+ * \a tuple[5] = \c matrix_XZ
* \return DataArrayDouble * - the new instance of DataArrayDouble containing 3 * components, whose each tuple contains the eigenvalues of the matrix of * corresponding tuple of \a this array. @@ -2118,7 +2148,13 @@ DataArrayDouble *DataArrayDouble::eigenValues() const /*! * Computes 3 eigenvectors of every upper triangular matrix defined by the tuple of - * \a this array, which contains 6 components. + * \a this array, which contains 6 components. The 6 components of tuples are expected to be stored as follow :
+ * \a tuple[0] = \c matrix_XX
+ * \a tuple[1] = \c matrix_YY
+ * \a tuple[2] = \c matrix_ZZ
+ * \a tuple[3] = \c matrix_XY
+ * \a tuple[4] = \c matrix_YZ
+ * \a tuple[5] = \c matrix_XZ
* \return DataArrayDouble * - the new instance of DataArrayDouble containing 9 * components, whose each tuple contains 3 eigenvectors of the matrix of * corresponding tuple of \a this array. @@ -2301,16 +2337,7 @@ DataArrayDouble *DataArrayDouble::magnitude() const return ret; } -/*! - * Computes the maximal value within every tuple of \a this array. - * \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. - * \sa DataArrayDouble::maxPerTupleWithCompoId - */ -DataArrayDouble *DataArrayDouble::maxPerTuple() const +DataArrayDouble *DataArrayDouble::operatePerTuple(std::function func) const { checkAllocated(); std::size_t nbOfComp(getNumberOfComponents()); @@ -2320,10 +2347,38 @@ DataArrayDouble *DataArrayDouble::maxPerTuple() const const double *src=getConstPointer(); double *dest=ret->getPointer(); for(mcIdType i=0;ioperatePerTuple([](const double *bg, const double *endd) { return *std::max_element(bg,endd); }); +} + +/*! + * Computes the minimal value within every tuple of \a this array. + * \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. + * \sa DataArrayDouble::maxPerTuple + */ +DataArrayDouble *DataArrayDouble::minPerTuple() const +{ + return this->operatePerTuple([](const double *bg, const double *endd) { return *std::min_element(bg,endd); }); +} + /*! * Computes the maximal value within every tuple of \a this array and it returns the first component * id for each tuple that corresponds to the maximal value within the tuple. @@ -3464,18 +3519,18 @@ void DataArrayDouble::Rotate3DAlg(const double *center, const double *vect, doub double norm(sqrt(vect[0]*vect[0]+vect[1]*vect[1]+vect[2]*vect[2])); if(norm::min()) throw INTERP_KERNEL::Exception("DataArrayDouble::Rotate3DAlg : magnitude of input vector is too close of 0. !"); - std::transform(vect,vect+3,vectorNorm,std::bind2nd(std::multiplies(),1/norm)); + std::transform(vect,vect+3,vectorNorm,std::bind(std::multiplies(),std::placeholders::_1,1/norm)); //rotation matrix computation matrix[0]=cosa; matrix[1]=0.; matrix[2]=0.; matrix[3]=0.; matrix[4]=cosa; matrix[5]=0.; matrix[6]=0.; matrix[7]=0.; matrix[8]=cosa; matrixTmp[0]=vectorNorm[0]*vectorNorm[0]; matrixTmp[1]=vectorNorm[0]*vectorNorm[1]; matrixTmp[2]=vectorNorm[0]*vectorNorm[2]; matrixTmp[3]=vectorNorm[1]*vectorNorm[0]; matrixTmp[4]=vectorNorm[1]*vectorNorm[1]; matrixTmp[5]=vectorNorm[1]*vectorNorm[2]; matrixTmp[6]=vectorNorm[2]*vectorNorm[0]; matrixTmp[7]=vectorNorm[2]*vectorNorm[1]; matrixTmp[8]=vectorNorm[2]*vectorNorm[2]; - std::transform(matrixTmp,matrixTmp+9,matrixTmp,std::bind2nd(std::multiplies(),1-cosa)); + std::transform(matrixTmp,matrixTmp+9,matrixTmp,std::bind(std::multiplies(),std::placeholders::_1,1-cosa)); std::transform(matrix,matrix+9,matrixTmp,matrix,std::plus()); matrixTmp[0]=0.; matrixTmp[1]=-vectorNorm[2]; matrixTmp[2]=vectorNorm[1]; matrixTmp[3]=vectorNorm[2]; matrixTmp[4]=0.; matrixTmp[5]=-vectorNorm[0]; matrixTmp[6]=-vectorNorm[1]; matrixTmp[7]=vectorNorm[0]; matrixTmp[8]=0.; - std::transform(matrixTmp,matrixTmp+9,matrixTmp,std::bind2nd(std::multiplies(),sina)); + std::transform(matrixTmp,matrixTmp+9,matrixTmp,std::bind(std::multiplies(),std::placeholders::_1,sina)); std::transform(matrix,matrix+9,matrixTmp,matrix,std::plus()); //rotation matrix computed. double tmp[3]; @@ -3612,6 +3667,17 @@ DataArrayInt32 *DataArrayInt32::deepCopy() const return new DataArrayInt32(*this); } +MCAuto DataArrayInt32::convertToInt64Arr() const +{ + this->checkAllocated(); + MCAuto ret(DataArrayInt64::New()); + ret->alloc(this->getNumberOfTuples(),this->getNumberOfComponents()); + ret->copyStringInfoFrom(*this); + const std::int32_t *pt(this->begin()); + std::for_each(ret->getPointer(),ret->getPointer()+ret->getNbOfElems(),[&pt](std::int64_t& val) { val = std::int64_t(*pt++); }); + return ret; +} + DataArrayInt32Iterator *DataArrayInt32::iterator() { return new DataArrayInt32Iterator(this); @@ -3651,6 +3717,17 @@ DataArrayInt32 *DataArrayInt32Tuple::buildDAInt(std::size_t nbOfTuples, std::siz return this->buildDA(nbOfTuples,nbOfCompo); } +MCAuto DataArrayInt64::convertToInt32Arr() const +{ + this->checkAllocated(); + MCAuto ret(DataArrayInt32::New()); + ret->alloc(this->getNumberOfTuples(),this->getNumberOfComponents()); + ret->copyStringInfoFrom(*this); + const std::int64_t *pt(this->begin()); + std::for_each(ret->getPointer(),ret->getPointer()+ret->getNbOfElems(),[&pt](std::int32_t& val) { val = std::int32_t(*pt++); }); + return ret; +} + DataArrayInt64Iterator *DataArrayInt64::iterator() { return new DataArrayInt64Iterator(this);