findCommonTuples(prec,limitTupleId,c0,cI0);
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(c0),cI(cI0);
int newNbOfTuples=-1;
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(getNumberOfTuples(),c0,cI0,newNbOfTuples);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(getNumberOfTuples(),c0->begin(),cI0->begin(),cI0->end(),newNbOfTuples);
return renumberAndReduce(o2n->getConstPointer(),newNbOfTuples);
}
*
* @param nbOfOldTuples is the number of tuples in initial array.
* @param arr is the list of tuples ids grouped by 'arrI' array
- * @param arrI is the entry point of 'arr' array. arrI->getNumberOfTuples()-1 is the number of common groups > 1 tuple.
+ * @param arrIBg is the entry point of 'arr' array. arrI->getNumberOfTuples()-1 is the number of common groups > 1 tuple.
+ * @param arrIEnd is the entry point of 'arr' array (end not included)
* @param newNbOfTuples output parameter that retrieves the new number of tuples after surjection application
*/
-DataArrayInt *DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, const DataArrayInt *arr, const DataArrayInt *arrI, int &newNbOfTuples) throw(INTERP_KERNEL::Exception)
+DataArrayInt *DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, const int *arr, const int *arrIBg, const int *arrIEnd, int &newNbOfTuples) throw(INTERP_KERNEL::Exception)
{
- if(!arr || !arrI)
+ if(!arr || !arrIBg || !arrIEnd)
throw INTERP_KERNEL::Exception("DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2 : presence of NULL ref of DataArrayInt in input !");
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
ret->alloc(nbOfOldTuples,1);
int *pt=ret->getPointer();
std::fill(pt,pt+nbOfOldTuples,-1);
- int nbOfGrps=arrI->getNumberOfTuples()-1;
- const int *cIPtr=arrI->getConstPointer();
- const int *cPtr=arr->getConstPointer();
+ int nbOfGrps=((int)std::distance(arrIBg,arrIEnd))-1;
+ const int *cIPtr=arrIBg;
for(int i=0;i<nbOfGrps;i++)
- pt[cPtr[cIPtr[i]]]=-(i+2);
+ pt[arr[cIPtr[i]]]=-(i+2);
int newNb=0;
for(int iNode=0;iNode<nbOfOldTuples;iNode++)
{
int grpId=-(pt[iNode]+2);
for(int j=cIPtr[grpId];j<cIPtr[grpId+1];j++)
{
- if(cPtr[j]>=0 && cPtr[j]<nbOfOldTuples)
- pt[cPtr[j]]=newNb;
+ if(arr[j]>=0 && arr[j]<nbOfOldTuples)
+ pt[arr[j]]=newNb;
else
{
- std::ostringstream oss; oss << "DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2 : With element #" << j << " value is " << cPtr[j] << " should be in [0," << nbOfOldTuples << ") !";
+ std::ostringstream oss; oss << "DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2 : With element #" << j << " value is " << arr[j] << " should be in [0," << nbOfOldTuples << ") !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
MEDCOUPLING_EXPORT DataArrayInt *selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayInt *checkAndPreparePermutation() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void changeSurjectiveFormat(int targetNb, DataArrayInt *&arr, DataArrayInt *&arrI) const throw(INTERP_KERNEL::Exception);
- MEDCOUPLING_EXPORT static DataArrayInt *BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, const DataArrayInt *arr, const DataArrayInt *arrI, int &newNbOfTuples) throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT static DataArrayInt *BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, const int *arr, const int *arrIBg, const int *arrIEnd, int &newNbOfTuples) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayInt *buildPermArrPerLevel() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT bool isIdentity() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT bool isUniform(int val) const throw(INTERP_KERNEL::Exception);
{
if(!_coords)
throw INTERP_KERNEL::Exception("MEDCouplingPointSet::buildNewNumberingFromCommonNodesFormat : no coords specified !");
- return DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(getNumberOfNodes(),comm,commIndex,newNbOfNodes);
+ return DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(getNumberOfNodes(),comm->begin(),commIndex->begin(),commIndex->end(),newNbOfNodes);
}
/*
*/
bool MEDCouplingUMesh::areCellsEqualInPool(const std::vector<int>& candidates, int compType, std::vector<int>& result) const
{
- std::set<int> cand(candidates.begin(),candidates.end());
- cand.erase(-1);
- if(cand.size()<=1)
+ if(candidates.size()<1)
return false;
bool ret=false;
- std::set<int>::const_iterator iter=cand.begin();
+ std::vector<int>::const_iterator iter=candidates.begin();
int start=(*iter++);
- for(;iter!=cand.end();iter++)
+ for(;iter!=candidates.end();iter++)
{
int status=areCellsEqual(start,*iter,compType);
if(status!=0)
* The nth set is [res.begin()+resI[n];res.begin()+resI[n+1]) with 0<=n<resI.size()-1
*/
template<int SPACEDIM>
-void MEDCouplingUMesh::findCommonCellsBase(int compType, std::vector<int>& res, std::vector<int>& resI) const
+void MEDCouplingUMesh::findCommonCellsBase(int startCellId, int compType, std::vector<int>& res, std::vector<int>& resI) const
{
res.clear(); resI.clear();
resI.push_back(0);
const int *connI=getNodalConnectivityIndex()->getConstPointer();
const double *coords=getCoords()->getConstPointer();
std::vector<bool> isFetched(nbOfCells);
- for(int k=0;k<nbOfCells;k++)
+ for(int k=startCellId;k<nbOfCells;k++)
{
if(!isFetched[k])
{
* \warning This method modifies can modify significantly the geometric type order in \a this.
* In view of the MED file writing, a renumbering of cells in \a this (using MEDCouplingUMesh::sortCellsInMEDFileFrmt) should be necessary.
*/
-DataArrayInt *MEDCouplingUMesh::zipConnectivityTraducer(int compType) throw(INTERP_KERNEL::Exception)
+DataArrayInt *MEDCouplingUMesh::zipConnectivityTraducer(int compType, int startCellId) throw(INTERP_KERNEL::Exception)
{
- int spaceDim=getSpaceDimension();
+ checkConnectivityFullyDefined();
int nbOfCells=getNumberOfCells();
std::vector<int> commonCells;
- std::vector<int> commonCellsI;
- switch(spaceDim)
+ std::vector<int> commonCellsI(1,0);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> revNodal=DataArrayInt::New(),revNodalI=DataArrayInt::New();
+ getReverseNodalConnectivity(revNodal,revNodalI);
+ const int *revNodalPtr=revNodal->getConstPointer(),*revNodalIPtr=revNodalI->getConstPointer();
+ const int *connPtr=getNodalConnectivity()->getConstPointer(),*connIPtr=getNodalConnectivityIndex()->getConstPointer();
+ std::vector<bool> isFetched(nbOfCells,false);
+ if(startCellId==0)
{
- case 3:
- {
- findCommonCellsBase<3>(compType,commonCells,commonCellsI);
- break;
- }
- case 2:
- {
- findCommonCellsBase<2>(compType,commonCells,commonCellsI);
- break;
- }
- case 1:
- {
- findCommonCellsBase<1>(compType,commonCells,commonCellsI);
- break;
- }
- default:
- throw INTERP_KERNEL::Exception("Invalid spaceDimension : must be 1, 2 or 3.");
+ for(int i=0;i<nbOfCells;i++)
+ {
+ if(!isFetched[i])
+ {
+ const int *connOfNode=std::find_if(connPtr+connIPtr[i]+1,connPtr+connIPtr[i+1],std::bind2nd(std::not_equal_to<int>(),-1));
+ std::vector<int> v,v2;
+ if(connOfNode!=connPtr+connIPtr[i+1])
+ {
+ const int *locRevNodal=std::find(revNodalPtr+revNodalIPtr[*connOfNode],revNodalPtr+revNodalIPtr[*connOfNode+1],i);
+ v2.insert(v2.end(),locRevNodal,revNodalPtr+revNodalIPtr[*connOfNode+1]);
+ connOfNode++;
+ }
+ for(;connOfNode!=connPtr+connIPtr[i+1] && v2.size()>1;connOfNode++)
+ if(*connOfNode>=0)
+ {
+ v=v2;
+ const int *locRevNodal=std::find(revNodalPtr+revNodalIPtr[*connOfNode],revNodalPtr+revNodalIPtr[*connOfNode+1],i);
+ std::vector<int>::iterator it=std::set_intersection(v.begin(),v.end(),locRevNodal,revNodalPtr+revNodalIPtr[*connOfNode+1],v2.begin());
+ v2.resize(std::distance(v2.begin(),it));
+ }
+ if(v2.size()>1)
+ {
+ if(areCellsEqualInPool(v2,compType,commonCells))
+ {
+ int pos=commonCellsI.back();
+ commonCellsI.push_back((int)commonCells.size());
+ for(std::vector<int>::const_iterator it=commonCells.begin()+pos;it!=commonCells.end();it++)
+ isFetched[*it]=true;
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ for(int i=startCellId;i<nbOfCells;i++)
+ {
+ if(!isFetched[i])
+ {
+ const int *connOfNode=std::find_if(connPtr+connIPtr[i]+1,connPtr+connIPtr[i+1],std::bind2nd(std::not_equal_to<int>(),-1));
+ std::vector<int> v,v2;
+ if(connOfNode!=connPtr+connIPtr[i+1])
+ {
+ v2.insert(v2.end(),revNodalPtr+revNodalIPtr[*connOfNode],revNodalPtr+revNodalIPtr[*connOfNode+1]);
+ connOfNode++;
+ }
+ for(;connOfNode!=connPtr+connIPtr[i+1] && v2.size()>1;connOfNode++)
+ if(*connOfNode>=0)
+ {
+ v=v2;
+ std::vector<int>::iterator it=std::set_intersection(v.begin(),v.end(),revNodalPtr+revNodalIPtr[*connOfNode],revNodalPtr+revNodalIPtr[*connOfNode+1],v2.begin());
+ v2.resize(std::distance(v2.begin(),it));
+ }
+ if(v2.size()>1)
+ {
+ if(areCellsEqualInPool(v2,compType,commonCells))
+ {
+ int pos=commonCellsI.back();
+ commonCellsI.push_back((int)commonCells.size());
+ for(std::vector<int>::const_iterator it=commonCells.begin()+pos;it!=commonCells.end();it++)
+ isFetched[*it]=true;
+ }
+ }
+ }
+ }
}
+ // BuildOld2NewArrayFromSurjectiveFormat2();
DataArrayInt *ret=DataArrayInt::New();
ret->alloc(nbOfCells,1);
int *retPtr=ret->getPointer();
bool MEDCouplingUMesh::areCellsIncludedIn(const MEDCouplingUMesh *other, int compType, DataArrayInt *& arr) const throw(INTERP_KERNEL::Exception)
{
MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh=MergeUMeshesOnSameCoords(this,other);
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=mesh->zipConnectivityTraducer(compType);
int nbOfCells=getNumberOfCells();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=mesh->zipConnectivityTraducer(compType,nbOfCells);
arr=o2n->substr(nbOfCells);
arr->setName(other->getName());
int tmp;
int spaceDim=mesh->getSpaceDimension();
std::vector<int> commonCells;
std::vector<int> commonCellsI;
+ int thisNbCells=getNumberOfCells();
switch(spaceDim)
{
case 3:
{
- findCommonCellsBase<3>(7,commonCells,commonCellsI);
+ findCommonCellsBase<3>(thisNbCells,7,commonCells,commonCellsI);
break;
}
case 2:
{
- findCommonCellsBase<2>(7,commonCells,commonCellsI);
+ findCommonCellsBase<2>(thisNbCells,7,commonCells,commonCellsI);
break;
}
case 1:
{
- findCommonCellsBase<1>(7,commonCells,commonCellsI);
+ findCommonCellsBase<1>(thisNbCells,7,commonCells,commonCellsI);
break;
}
default:
throw INTERP_KERNEL::Exception("Invalid spaceDimension : must be 1, 2 or 3.");
}
- int thisNbCells=getNumberOfCells();
int otherNbCells=other->getNumberOfCells();
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=DataArrayInt::New();
arr2->alloc(otherNbCells,1);
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp1(comm),tmp2(commI);
int oldNbOfNodes=coo->getNumberOfTuples();
int newNbOfNodes;
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(oldNbOfNodes,comm,commI,newNbOfNodes);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(oldNbOfNodes,comm->begin(),commI->begin(),commI->end(),newNbOfNodes);
if(oldNbOfNodes==newNbOfNodes)
return ;
MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> newCoords=coo->renumberAndReduce(o2n->getConstPointer(),newNbOfNodes);
MEDCOUPLING_EXPORT DataArrayInt *getNodeIdsInUse(int& nbrOfNodesInUse) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayInt *computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayInt *zipCoordsTraducer() throw(INTERP_KERNEL::Exception);
- MEDCOUPLING_EXPORT DataArrayInt *zipConnectivityTraducer(int compType) throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT DataArrayInt *zipConnectivityTraducer(int compType, int startCellId=0) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT bool areCellsIncludedIn(const MEDCouplingUMesh *other, int compType, DataArrayInt *& arr) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT bool areCellsIncludedIn2(const MEDCouplingUMesh *other, DataArrayInt *& arr) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const throw(INTERP_KERNEL::Exception);
DataArrayDouble *fillExtCoordsUsingTranslAndAutoRotation2D(const MEDCouplingUMesh *mesh1D, bool isQuad) const throw(INTERP_KERNEL::Exception);
DataArrayDouble *fillExtCoordsUsingTranslAndAutoRotation3D(const MEDCouplingUMesh *mesh1D, bool isQuad) const throw(INTERP_KERNEL::Exception);
template<int SPACEDIM>
- void findCommonCellsBase(int compType, std::vector<int>& res, std::vector<int>& resI) const;
+ void findCommonCellsBase(int startCellId, int compType, std::vector<int>& res, std::vector<int>& resI) const;
bool areCellsEqualInPool(const std::vector<int>& candidates, int compType, std::vector<int>& result) const;
MEDCouplingUMesh *buildPartOfMySelfKeepCoords(const int *begin, const int *end) const;
MEDCouplingUMesh *buildPartOfMySelfKeepCoords2(int start, int end, int step) const;
b->alloc(3,1);
std::copy(arrI,arrI+3,b->getPointer());
int newNbTuple=-1;
- DataArrayInt *ret=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(10,a,b,newNbTuple);
+ DataArrayInt *ret=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(10,a->begin(),b->begin(),b->end(),newNbTuple);
const int expected[10]={0,1,2,0,3,4,5,4,6,4};
CPPUNIT_ASSERT_EQUAL(10,ret->getNbOfElems());
CPPUNIT_ASSERT_EQUAL(7,newNbTuple);
CPPUNIT_ASSERT_EQUAL(1,ret->getNumberOfComponents());
CPPUNIT_ASSERT(std::equal(expected,expected+10,ret->getConstPointer()));
- CPPUNIT_ASSERT_THROW(DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(9,a,b,newNbTuple),INTERP_KERNEL::Exception);
+ CPPUNIT_ASSERT_THROW(DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(9,a->begin(),b->begin(),b->end(),newNbTuple),INTERP_KERNEL::Exception);
ret->decrRef();
b->decrRef();
a->decrRef();
DataArrayInt *sortCellsInMEDFileFrmt() throw(INTERP_KERNEL::Exception);
DataArrayInt *convertCellArrayPerGeoType(const DataArrayInt *da) const throw(INTERP_KERNEL::Exception);
DataArrayInt *computeFetchedNodeIds() const throw(INTERP_KERNEL::Exception);
- DataArrayInt *zipConnectivityTraducer(int compType) throw(INTERP_KERNEL::Exception);
+ DataArrayInt *zipConnectivityTraducer(int compType, int startCellId=0) throw(INTERP_KERNEL::Exception);
DataArrayInt *computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception);
MEDCouplingUMesh *buildDescendingConnectivity(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const throw(INTERP_KERNEL::Exception);
MEDCouplingUMesh *buildDescendingConnectivity2(DataArrayInt *desc, DataArrayInt *descIndx, DataArrayInt *revDesc, DataArrayInt *revDescIndx) const throw(INTERP_KERNEL::Exception);
return self->iterator();
}
- static PyObject *BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, const DataArrayInt *arr, const DataArrayInt *arrI) throw(INTERP_KERNEL::Exception)
+ static PyObject *BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, PyObject *arr, PyObject *arrI) throw(INTERP_KERNEL::Exception)
{
int newNbOfTuples=-1;
- DataArrayInt *ret0=ParaMEDMEM::DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(nbOfOldTuples,arr,arrI,newNbOfTuples);
+ int szArr,szArrI,sw,iTypppArr,iTypppArrI;
+ std::vector<int> stdvecTyyppArr,stdvecTyyppArrI;
+ const int *arrPtr=convertObjToPossibleCpp1_Safe(arr,sw,szArr,iTypppArr,stdvecTyyppArr);
+ const int *arrIPtr=convertObjToPossibleCpp1_Safe(arrI,sw,szArrI,iTypppArrI,stdvecTyyppArrI);
+ DataArrayInt *ret0=ParaMEDMEM::DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(nbOfOldTuples,arrPtr,arrIPtr,arrIPtr+szArrI,newNbOfTuples);
PyObject *ret=PyTuple_New(2);
PyTuple_SetItem(ret,0,SWIG_NewPointerObj((void*)ret0,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0));
PyTuple_SetItem(ret,1,PyInt_FromLong(newNbOfTuples));