#include "MEDCouplingSkyLineArray.hxx"
#include <sstream>
+#include <deque>
+#include <set>
using namespace MEDCoupling;
(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<const DataArrayInt*>& 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<set<int>>
+ std::deque<std::set<int>> 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<int>(vP+iP[ii], vP+iP[ii+1]));
+
+ // modify the deque<set<int>> according to idx and packs
+ int ii = 0;
+ for (auto id = idx->begin(); id != idx->end(); id++){
+ valuesByIdx[*id] = std::set<int>(packs[ii]->begin(), packs[ii]->end());
+ ii++;
+ }
+
+ // copy back the deque<set<int>> 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<int> 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; i<ii; i++)
+ iP[i] -= offset;
+ }
+ offset += iP[ii+1] - iP[ii];
+ start_prec = ii-deleted;
+ end_prec = ii+1;
+ deleted += 1;
+ }
+ if (end_prec != 0){
+ copy(iP+end_prec, iP+nt, iP+start_prec);
+ for (int i=start_prec; i<nt; i++)
+ iP[i] -= offset;
+ }
+ _index->reAlloc(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.
*/
std::vector<int>& 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<const DataArrayInt*>& packs);
+
void convertToPolyhedronConn( MCAuto<DataArrayInt>& c, MCAuto<DataArrayInt>& cI) const;
private:
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)
self->replaceSimplePack(idx, vpack.data(), vpack.data()+vpack.size());
}
+ void replaceSimplePacks(const DataArrayInt* idx, PyObject *listePacks) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<const DataArrayInt*> packs;
+ convertFromPyObjVectorOfObj<const MEDCoupling::DataArrayInt*>(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<int> vpack;