From: Maximilien Siavelis Date: Thu, 28 Sep 2017 09:27:23 +0000 (+0200) Subject: add replacePacks and deletePacks in SkyLineArray X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=67034826bfd107260e57d626c391b7207a8170db;p=tools%2Fmedcoupling.git add replacePacks and deletePacks in SkyLineArray --- diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx index f270ddf16..fa64244d3 100644 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx @@ -20,6 +20,8 @@ #include "MEDCouplingSkyLineArray.hxx" #include +#include +#include using namespace MEDCoupling; @@ -408,6 +410,129 @@ void MEDCouplingSkyLineArray::deletePack(const int superIdx, const int idx) (siP[ii])--; } +void MEDCouplingSkyLineArray::deleteSimplePack(const int idx) +{ + using namespace std; + + validIndex("deleteSimplePack", idx); + + int* iP(_index->getPointer()); + const int start = iP[idx], end = iP[idx+1]; + + // _values + int initValSz = _values->getNbOfElems(); + int deltaSz = start-end; // should be negative + int *vP(_values->getPointer()); + if (deltaSz < 0){ + copy(vP+end, vP+initValSz, vP+start); + _values->reAlloc(initValSz+deltaSz); + } + else + throw INTERP_KERNEL::Exception("MEDCouplingSkyLineArray::deleteSimplePack"); + + // _index + int nt = _index->getNbOfElems(); + copy(iP+idx+1, iP+nt, iP+idx); + for(int ii = idx; ii < nt-1; ii++) + iP[ii] += deltaSz; + _index->reAlloc(nt-1); +} + +void MEDCouplingSkyLineArray::replaceSimplePacks(const DataArrayInt* idx, const std::vector& packs){ + + if (idx->empty()) + return; + + for (auto id = idx->begin(); id != idx->end(); id++) + validIndex("deleteSimplePacks", *id); + + if (idx->getNbOfElems() != packs.size()) + throw INTERP_KERNEL::Exception("MEDCouplingSkyLineArray::deleteSimplePacks: size of list of pack is incorrect"); + + // copy _index, _values into a deque> + std::deque> valuesByIdx; + int* vP(_values->getPointer()); + int* iP(_index->getPointer()); + int nt = _index->getNbOfElems(); + for (int ii = 0; ii < nt-1; ii++) + valuesByIdx.push_back(std::set(vP+iP[ii], vP+iP[ii+1])); + + // modify the deque> according to idx and packs + int ii = 0; + for (auto id = idx->begin(); id != idx->end(); id++){ + valuesByIdx[*id] = std::set(packs[ii]->begin(), packs[ii]->end()); + ii++; + } + + // copy back the deque> into _index, _values + int valSz = 0; + *iP = 0; + for (auto values : valuesByIdx){ + valSz += values.size(); + *(++iP) = valSz; + } + + _values->reAlloc(valSz); + iP = _index->getPointer(); + vP = _values->getPointer(); + for (auto values : valuesByIdx){ + copy(values.begin(), values.end(), vP+(*iP)); + iP++; + } + +} + +void MEDCouplingSkyLineArray::deleteSimplePacks(const DataArrayInt* idx){ + + using namespace std; + + for (auto id = idx->begin(); id != idx->end(); id++) + validIndex("deleteSimplePacks", *id); + + std::set packsToDelete(idx->begin(), idx->end()); + + // _values + int* iP(_index->getPointer()); + int initValSz = _values->getNbOfElems(); + int *vP(_values->getPointer()); + int end_prec = 0; + int start_prec = 0; + for (auto ii : packsToDelete){ + int start = iP[ii]; + if (end_prec != 0) + copy(vP+end_prec, vP+start, vP+start_prec); + start_prec += start-end_prec; + end_prec = iP[ii+1]; + } + if (end_prec != 0) + copy(vP+end_prec, vP+initValSz, vP+start_prec); + _values->reAlloc(initValSz-(end_prec-start_prec)); + + // _index + int nt = _index->getNbOfElems(); + int offset = 0; + end_prec = 0; + start_prec = 0; + int deleted = 0; + for (auto ii : packsToDelete){ + if (end_prec != 0){ + copy(iP+end_prec, iP+ii, iP+start_prec); + for (int i=start_prec; ireAlloc(nt-deleted); +} + /**! * Insert a new pack in super-pack at index 'superIdx'. The pack is inserted at the end of the pack list of the chosen super-pack. */ diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx index bf5d74cab..7c7d04a03 100644 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx @@ -90,11 +90,15 @@ namespace MEDCoupling std::vector& out) const; void deletePack(const int superIdx, const int idx); + void deleteSimplePack(const int idx); void pushBackPack(const int superIdx, const int * packBg, const int * packEnd); void replaceSimplePack(const int idx, const int * packBg, const int * packEnd); void replacePack(const int superIdx, const int idx, const int * packBg, const int * packEnd); + void deleteSimplePacks(const DataArrayInt* idx); + void replaceSimplePacks(const DataArrayInt* idx, const std::vector& packs); + void convertToPolyhedronConn( MCAuto& c, MCAuto& cI) const; private: diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index d97b69bbb..1941c29ea 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -1221,6 +1221,9 @@ namespace MEDCoupling void deletePack(const int i, const int j) throw(INTERP_KERNEL::Exception); + void deleteSimplePack(const int i) throw(INTERP_KERNEL::Exception); + void deleteSimplePacks(const DataArrayInt* idx) throw(INTERP_KERNEL::Exception); + %extend { MEDCouplingSkyLineArray() throw(INTERP_KERNEL::Exception) @@ -1304,6 +1307,13 @@ namespace MEDCoupling self->replaceSimplePack(idx, vpack.data(), vpack.data()+vpack.size()); } + void replaceSimplePacks(const DataArrayInt* idx, PyObject *listePacks) throw(INTERP_KERNEL::Exception) + { + std::vector packs; + convertFromPyObjVectorOfObj(listePacks,SWIGTYPE_p_MEDCoupling__DataArrayInt,"DataArrayInt",packs); + self->replaceSimplePacks(idx, packs); + } + void replacePack(const int superIdx, const int idx, PyObject *pack) throw(INTERP_KERNEL::Exception) { std::vector vpack;