X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingMemArray.txx;h=5df4f7150b71637dd40bcf3af923036533ed8d9b;hb=b7e277ad50223814bc479c5bd64cf12abe8fc959;hp=16ba939e2a67f29bdfcb351510df170d7936a55a;hpb=1327e26c56f6f295388a4d742b08c3d4e1b894d4;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 16ba939e2..5df4f7150 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -25,6 +25,8 @@ #include "NormalizedUnstructuredMesh.hxx" #include "InterpKernelException.hxx" #include "InterpolationUtils.hxx" +#include "MEDCouplingPartDefinition.hxx" +#include "InterpKernelAutoPtr.hxx" #include "MCAuto.hxx" #include @@ -95,22 +97,6 @@ namespace MEDCoupling _nb_of_elem=std::max(_nb_of_elem,id+sizeOfOthers+1); } - template - template - void MemArray::insertAtTheEnd(InputIterator first, InputIterator last) - { - T *pointer=_pointer.getPointer(); - while(first!=last) - { - if(_nb_of_elem>=_nb_of_elem_alloc) - { - reserve(_nb_of_elem_alloc>0?2*_nb_of_elem_alloc:1); - pointer=_pointer.getPointer(); - } - pointer[_nb_of_elem++]=*first++; - } - } - template void MemArray::pushBack(T elem) { @@ -493,6 +479,41 @@ namespace MEDCoupling } ////////////////////////////////// + + template + MCAuto< typename Traits::ArrayTypeCh > DataArrayTemplate::NewFromStdVector(const typename std::vector& v) + { + std::size_t sz(v.size()); + MCAuto< typename Traits::ArrayTypeCh > ret(Traits::ArrayTypeCh::New()); + ret->alloc(sz,1); + T *pt(ret->getPointer()); + std::copy(v.begin(),v.end(),pt); + return ret; + } + + template + std::vector< MCAuto< typename Traits::ArrayTypeCh > > DataArrayTemplate::explodeComponents() const + { + checkAllocated(); + std::size_t sz(getNumberOfComponents()); + int nbTuples(getNumberOfTuples()); + std::string name(getName()); + std::vector compNames(getInfoOnComponents()); + std::vector< MCAuto< typename Traits::ArrayTypeCh > > ret(sz); + const T *thisPt(begin()); + for(std::size_t i=0;i::ArrayTypeCh > part(Traits::ArrayTypeCh::New()); + part->alloc(nbTuples,1); + part->setName(name); + part->setInfoOnComponent(0,compNames[i]); + T *otherPt(part->getPointer()); + for(int j=0;j std::size_t DataArrayTemplate::getHeapMemorySizeWithoutChildren() const @@ -1028,6 +1049,41 @@ namespace MEDCoupling { return DataArrayTemplate::mySelectByTupleId(di.begin(),di.end()); } + + template + MCAuto::ArrayTypeCh> DataArrayTemplate::selectPartDef(const PartDefinition *pd) const + { + if(!pd) + throw INTERP_KERNEL::Exception("DataArrayTemplate::selectPartDef : null input pointer !"); + MCAuto::ArrayTypeCh> ret(Traits::ArrayTypeCh::New()); + const SlicePartDefinition *spd(dynamic_cast(pd)); + if(spd) + { + int a,b,c; + spd->getSlice(a,b,c); + if(a==0 && b==getNumberOfTuples() && c==1) + { + DataArrayTemplate *directRet(const_cast *>(this)); + directRet->incrRef(); + MCAuto > ret(directRet); + return DynamicCastSafe,typename Traits::ArrayTypeCh>(ret); + } + else + { + MCAuto ret(selectByTupleIdSafeSlice(a,b,c)); + return DynamicCastSafe::ArrayTypeCh>(ret); + } + } + const DataArrayPartDefinition *dpd(dynamic_cast(pd)); + if(dpd) + { + MCAuto arr(dpd->toDAI()); + MCAuto ret(selectByTupleIdSafe(arr->begin(),arr->end())); + return DynamicCastSafe::ArrayTypeCh>(ret); + + } + throw INTERP_KERNEL::Exception("DataArrayTemplate::selectPartDef : unrecognized part def !"); + } /*! * Returns a shorten and permuted copy of \a this array. The new DataArrayDouble is @@ -2124,6 +2180,78 @@ namespace MEDCoupling return *loc; } + template + void DataArrayTemplate::circularPermutation(int nbOfShift) + { + checkAllocated(); + int nbOfCompo(getNumberOfComponents()),nbTuples(getNumberOfTuples()); + int effNbSh(EffectiveCircPerm(nbOfShift,nbTuples)); + if(effNbSh==0) + return ; + T *work(getPointer()); + if(effNbSh buf(new T[effNbSh*nbOfCompo]); + std::copy(work,work+effNbSh*nbOfCompo,(T *)buf); + std::copy(work+effNbSh*nbOfCompo,work+nbTuples*nbOfCompo,work);// ze big shift + std::copy((T *)buf,(T *)buf+effNbSh*nbOfCompo,work+(nbTuples-effNbSh)*nbOfCompo); + } + else + { + typename INTERP_KERNEL::AutoPtr buf(new T[(nbTuples-effNbSh)*nbOfCompo]); + std::copy(work+effNbSh*nbOfCompo,work+nbTuples*nbOfCompo,(T *)buf); + std::copy(work,work+effNbSh*nbOfCompo,work+(nbTuples-effNbSh)*nbOfCompo);// ze big shift + std::copy((T*)buf,(T *)buf+(nbTuples-effNbSh)*nbOfCompo,work); + } + } + + template + void DataArrayTemplate::circularPermutationPerTuple(int nbOfShift) + { + checkAllocated(); + int nbOfCompo(getNumberOfComponents()),nbTuples(getNumberOfTuples()); + int effNbSh(EffectiveCircPerm(nbOfShift,nbOfCompo)); + if(effNbSh==0) + return ; + T *work(getPointer()); + if(effNbSh buf(new T[effNbSh]); + for(int i=0;i buf(new T[nbOfCompo-effNbSh]); + for(int i=0;i sts(nbOfCompo); + for(int i=0;i + void DataArrayTemplate::reversePerTuple() + { + checkAllocated(); + int nbOfCompo(getNumberOfComponents()),nbTuples(getNumberOfTuples()); + if(nbOfCompo<=1) + return ; + T *work(getPointer()); + for(int i=0;i