#include "MEDCouplingSkyLineArray.hxx"
#include <sstream>
+#include <deque>
+#include <set>
using namespace MEDCoupling;
*/
void MEDCouplingSkyLineArray::deletePack(const int superIdx, const int idx)
{
- using namespace std;
-
checkSuperIndex("deletePack");
validSuperIndexAndIndex("deletePack", superIdx, idx);
int * siP(_super_index->getPointer()), *iP(_index->getPointer());
const int start = iP[siP[superIdx]+idx], end = iP[siP[superIdx]+idx+1];
// _values
- copy(vP+end, vP+_values->getNbOfElems(), vP+start);
+ std::copy(vP+end, vP+_values->getNbOfElems(), vP+start);
_values->reAlloc(_values->getNbOfElems() - (end-start));
// _index
int nt = _index->getNbOfElems();
- copy(iP+siP[superIdx]+idx+1, iP+nt, iP+siP[superIdx]+idx);
+ std::copy(iP+siP[superIdx]+idx+1, iP+nt, iP+siP[superIdx]+idx);
_index->reAlloc(nt-1); iP = _index->getPointer(); // better not forget this ...
for(int ii = siP[superIdx]+idx; ii < nt-1; ii++)
iP[ii] -= (end-start);
(siP[ii])--;
}
+void MEDCouplingSkyLineArray::deleteSimplePack(const int idx)
+{
+ 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)
+ {
+ std::copy(vP+end, vP+initValSz, vP+start);
+ _values->reAlloc(initValSz+deltaSz);
+ }
+ else
+ throw INTERP_KERNEL::Exception("MEDCouplingSkyLineArray::deleteSimplePack");
+ // _index
+ int nt(_index->getNbOfElems());
+ std::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 (const int * 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());
+ std::size_t 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 (const int *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 (std::deque< std::set<int> >::const_iterator values=valuesByIdx.begin();values!=valuesByIdx.end();values++)
+ {
+ valSz += (*values).size();
+ *(++iP) = valSz;
+ }
+ _values->reAlloc(valSz);
+ iP = _index->getPointer();
+ vP = _values->getPointer();
+ for (auto values : valuesByIdx)
+ {
+ std::copy(values.begin(), values.end(), vP+(*iP));
+ iP++;
+ }
+}
+
+void MEDCouplingSkyLineArray::deleteSimplePacks(const DataArrayInt* idx)
+{
+ 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),start_prec(0);
+ for(std::set<int>::const_iterator ii=packsToDelete.begin();ii!=packsToDelete.end();ii++)
+ {
+ int start = iP[*ii];
+ if (end_prec != 0)
+ std::copy(vP+end_prec, vP+start, vP+start_prec);
+ start_prec += start-end_prec;
+ end_prec = iP[*ii+1];
+ }
+ if (end_prec != 0)
+ std::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(std::set<int>::const_iterator ii=packsToDelete.begin();ii!=packsToDelete.end();ii++)
+ {
+ if (end_prec != 0)
+ {
+ std::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)
+ {
+ std::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.
*/
*/
void MEDCouplingSkyLineArray::replaceSimplePack(const int idx, const int * packBg, const int * packEnd)
{
- using namespace std;
-
validIndex("replaceSimplePack", idx);
int * iP(_index->getPointer());
- int newSz = distance(packBg, packEnd);
+ int newSz = std::distance(packBg, packEnd);
const int start = iP[idx], end = iP[idx+1];
// _values
if (deltaSz > 0)
_values->reAlloc(initValSz+deltaSz);
int *vP(_values->getPointer());
- copy(vP+end, vP+initValSz, vP+end+deltaSz);
+ std::copy(vP+end, vP+initValSz, vP+end+deltaSz);
if (deltaSz < 0)
_values->reAlloc(initValSz+deltaSz);
}
// copy new pack
- copy(packBg, packEnd, _values->getPointer()+start);
+ std::copy(packBg, packEnd, _values->getPointer()+start);
// _index
for(int ii = idx+1; ii < (int)_index->getNbOfElems(); ii++)
* Replace pack with super index 'superIdx' and index 'idx' with the provided new pack.
* Function can be used only for 3-level SkyLine.
*/
-void MEDCouplingSkyLineArray::replacePack(const int superIdx, const int idx, const int * packBg, const int * packEnd)
+void MEDCouplingSkyLineArray::replacePack(const int superIdx, const int idx, const int *packBg, const int *packEnd)
{
- using namespace std;
-
checkSuperIndex("replacePack");
validSuperIndexAndIndex("replacePack", superIdx, idx);
int * siP(_super_index->getPointer()), *iP(_index->getPointer());
- int newSz = distance(packBg, packEnd);
+ int newSz = std::distance(packBg, packEnd);
const int start = iP[siP[superIdx]+idx], end = iP[siP[superIdx]+idx+1];
// _values
if (deltaSz > 0)
_values->reAlloc(initValSz+deltaSz);
int *vP(_values->getPointer());
- copy(vP+end, vP+initValSz, vP+end+deltaSz);
+ std::copy(vP+end, vP+initValSz, vP+end+deltaSz);
if (deltaSz < 0)
_values->reAlloc(initValSz+deltaSz);
}
// copy new pack
- copy(packBg, packEnd, _values->getPointer()+start);
+ std::copy(packBg, packEnd, _values->getPointer()+start);
// _index
for(int ii = siP[superIdx]+idx+1; ii < (int)_index->getNbOfElems(); ii++)
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:
{
int *neighIdx(neighborsIdx->getPointer());
for(std::vector< std::set<int> >::const_iterator it=st0.begin();it!=st0.end();it++,neighIdx++)
- neighIdx[1]=neighIdx[0]+(*it).size()-1;
+ {
+ if ((*it).empty())
+ neighIdx[1]=neighIdx[0];
+ else
+ neighIdx[1]=neighIdx[0]+(*it).size()-1;
+ }
}
neighbors=DataArrayInt::New(); neighbors->alloc(neighborsIdx->back(),1);
{
def testUMeshComputeEnlargedNeighborsOfNodes(self):
m=MEDCouplingCMesh() ; arr=DataArrayDouble(4) ; arr.iota() ; m.setCoords(arr,arr) ; m=m.buildUnstructured()
a,b=m.computeEnlargedNeighborsOfNodes()
- self.assertTrue(a.isEqual(DataArrayInt([1,4,5,0,2,4,5,6,1,3,5,6,7,2,6,7,0,1,5,8,9,0,1,2,4,6,8,9,10,1,2,3,5,7,9,10,11,2,3,6,10,11,4,5,9,12,13,4,5,6,8,10,12,13,14,5,6,7,9,11,13,14,15,6,7,10,14,15,8,9,13,8,9,10,12,14,9,10,11,13,15,10,11,14])))
- self.assertTrue(b.isEqual(DataArrayInt([0,3,8,13,16,21,29,37,42,47,55,63,68,71,76,81,84])))
+ aExp=DataArrayInt([1,4,5,0,2,4,5,6,1,3,5,6,7,2,6,7,0,1,5,8,9,0,1,2,4,6,8,9,10,1,2,3,5,7,9,10,11,2,3,6,10,11,4,5,9,12,13,4,5,6,8,10,12,13,14,5,6,7,9,11,13,14,15,6,7,10,14,15,8,9,13,8,9,10,12,14,9,10,11,13,15,10,11,14])
+ bExp=DataArrayInt([0,3,8,13,16,21,29,37,42,47,55,63,68,71,76,81,84])
+ self.assertTrue(a.isEqual(aExp))
+ self.assertTrue(b.isEqual(bExp))
+ m2=m[[1,2,3]]
+ c,d=m2.computeEnlargedNeighborsOfNodes()
+ cExp=DataArrayInt([2,5,6,1,3,5,6,7,2,6,7,5,8,9,1,2,4,6,8,9,1,2,3,5,7,2,3,6,4,5,9,4,5,8])
+ dExp=DataArrayInt([0,0,3,8,11,14,20,25,28,31,34,34,34,34,34,34,34])
+ self.assertTrue(c.isEqual(cExp))
+ self.assertTrue(d.isEqual(dExp))
pass
def testDAIfindIdsExt1(self):
f2.setArray(DataArrayDouble(list(range(18))))
f2.checkConsistencyLight()
pass
-
+
+ def testSKLAReplaceDeletePacks(self):
+ index=DataArrayInt([0,3,5,6,6])
+ value=DataArrayInt([1,2,3, 2,3, 3 ])
+ sla=MEDCouplingSkyLineArray(index,value)
+ idx=DataArrayInt([0,3])
+ packs=[DataArrayInt([4,5]),DataArrayInt([6,7,8])]
+ sla.replaceSimplePacks(idx,packs)
+ self.assertTrue(sla.getIndexArray().isEqual(DataArrayInt([0,2,4,5,8])))
+ self.assertTrue(sla.getValuesArray().isEqual(DataArrayInt([4,5, 2,3, 3, 6,7,8])))
+ sla.deleteSimplePacks(idx)
+ self.assertTrue(sla.getIndexArray().isEqual(DataArrayInt([0,2,3])))
+ self.assertTrue(sla.getValuesArray().isEqual(DataArrayInt([2,3, 3])))
+ sla.deleteSimplePack(1)
+ self.assertTrue(sla.getIndexArray().isEqual(DataArrayInt([0,2])))
+ self.assertTrue(sla.getValuesArray().isEqual(DataArrayInt([2,3])))
+ pass
pass
if __name__ == '__main__':
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;