From: ageay Date: Wed, 19 Dec 2012 15:34:15 +0000 (+0000) Subject: DataArrayInt instead of vector to avoid copies X-Git-Tag: V6_main_FINAL~444 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9003c2f4d0055d6e56cd2a10d360e40395e00b99;p=tools%2Fmedcoupling.git DataArrayInt instead of vector to avoid copies --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index e91915af2..1094c4873 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -36,7 +36,7 @@ typedef double (*MYFUNCPTR)(double); using namespace ParaMEDMEM; template -void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, std::vector& c, std::vector& cI) const +void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, DataArrayInt *c, DataArrayInt *cI) const { const double *coordsPtr=getConstPointer(); BBTree myTree(bbox,0,0,nbNodes,prec/10); @@ -59,9 +59,9 @@ void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int l } if(!commonNodes.empty()) { - cI.push_back(cI.back()+(int)commonNodes.size()+1); - c.push_back(i); - c.insert(c.end(),commonNodes.begin(),commonNodes.end()); + cI->pushBackSilent(cI->back()+(int)commonNodes.size()+1); + c->pushBackSilent(i); + c->insertAtTheEnd(commonNodes.begin(),commonNodes.end()); } } } @@ -70,7 +70,7 @@ void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int l template void DataArrayDouble::FindTupleIdsNearTuplesAlg(const BBTree& myTree, const double *pos, int nbOfTuples, double eps, - std::vector& c, std::vector& cI) + DataArrayInt *c, DataArrayInt *cI) { for(int i=0;i& myTr std::vector commonNodes; for(std::vector::const_iterator it=intersectingElems.begin();it!=intersectingElems.end();it++) commonNodes.push_back(*it); - cI.push_back(cI.back()+(int)commonNodes.size()); - c.insert(c.end(),commonNodes.begin(),commonNodes.end()); + cI->pushBackSilent(cI->back()+(int)commonNodes.size()); + c->insertAtTheEnd(commonNodes.begin(),commonNodes.end()); } } @@ -555,8 +555,14 @@ void DataArrayDouble::reserve(int nbOfElems) throw(INTERP_KERNEL::Exception) void DataArrayDouble::pushBackSilent(double val) throw(INTERP_KERNEL::Exception) { - if(getNumberOfComponents()==1) + int nbCompo=getNumberOfComponents(); + if(nbCompo==1) _mem.pushBack(val); + else if(nbCompo==0) + { + _info_on_compo.resize(1); + _mem.pushBack(val); + } else throw INTERP_KERNEL::Exception("DataArrayDouble::pushBackSilent : not available for DataArrayDouble with number of components different than 1 !"); } @@ -1215,12 +1221,10 @@ void DataArrayDouble::findCommonTuples(double prec, int limitTupleId, DataArrayI throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : Unexpected spacedim of coords. Must be 1, 2 or 3."); int nbOfTuples=getNumberOfTuples(); - comm=DataArrayInt::New(); - commIndex=DataArrayInt::New(); // MEDCouplingAutoRefCountObjectPtr bbox=computeBBoxPerTuple(prec); // - std::vector c,cI(1); + MEDCouplingAutoRefCountObjectPtr c(DataArrayInt::New()),cI(DataArrayInt::New()); c->alloc(0,1); cI->pushBackSilent(0); switch(nbOfCompo) { case 3: @@ -1235,10 +1239,8 @@ void DataArrayDouble::findCommonTuples(double prec, int limitTupleId, DataArrayI default: throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : nb of components managed are 1,2 and 3 ! not implemented for other number of components !"); } - commIndex->alloc((int)cI.size(),1); - std::copy(cI.begin(),cI.end(),commIndex->getPointer()); - comm->alloc(cI.back(),1); - std::copy(c.begin(),c.end(),comm->getPointer()); + comm=c.retn(); + commIndex=cI.retn(); } /*! @@ -1763,7 +1765,7 @@ DataArrayDouble *DataArrayDouble::computeBBoxPerTuple(double epsilon)const throw * * \sa MEDCouplingPointSet::getNodeIdsNearPoints, DataArrayDouble::getDifferentValues */ -void DataArrayDouble::computeTupleIdsNearTuples(const DataArrayDouble *other, double eps, std::vector& c, std::vector& cI) const throw(INTERP_KERNEL::Exception) +void DataArrayDouble::computeTupleIdsNearTuples(const DataArrayDouble *other, double eps, DataArrayInt *& c, DataArrayInt *& cI) const throw(INTERP_KERNEL::Exception) { if(!other) throw INTERP_KERNEL::Exception("DataArrayDouble::computeTupleIdsNearTuples : input pointer other is null !"); @@ -1774,32 +1776,31 @@ void DataArrayDouble::computeTupleIdsNearTuples(const DataArrayDouble *other, do if(nbOfCompo!=otherNbOfCompo) throw INTERP_KERNEL::Exception("DataArrayDouble::computeTupleIdsNearTuples : number of components should be equal between this and other !"); int nbOfTuplesOther=other->getNumberOfTuples(); - std::vector ret; - c.clear(); - cI.resize(1); cI[0]=0; + MEDCouplingAutoRefCountObjectPtr cArr(DataArrayInt::New()),cIArr(DataArrayInt::New()); cArr->alloc(0,1); cIArr->pushBackSilent(0); switch(nbOfCompo) { case 3: { BBTree<3,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10); - FindTupleIdsNearTuplesAlg<3>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,c,cI); + FindTupleIdsNearTuplesAlg<3>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr); break; } case 2: { BBTree<2,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10); - FindTupleIdsNearTuplesAlg<2>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,c,cI); + FindTupleIdsNearTuplesAlg<2>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr); break; } case 1: { BBTree<1,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10); - FindTupleIdsNearTuplesAlg<1>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,c,cI); + FindTupleIdsNearTuplesAlg<1>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,cArr,cIArr); break; } default: throw INTERP_KERNEL::Exception("Unexpected spacedim of coords for computeTupleIdsNearTuples. Must be 1, 2 or 3."); } + c=cArr.retn(); cI=cIArr.retn(); } /*! @@ -3510,8 +3511,14 @@ void DataArrayInt::reserve(int nbOfElems) throw(INTERP_KERNEL::Exception) void DataArrayInt::pushBackSilent(int val) throw(INTERP_KERNEL::Exception) { - if(getNumberOfComponents()==1) + int nbCompo=getNumberOfComponents(); + if(nbCompo==1) _mem.pushBack(val); + else if(nbCompo==0) + { + _info_on_compo.resize(1); + _mem.pushBack(val); + } else throw INTERP_KERNEL::Exception("DataArrayInt::pushBackSilent : not available for DataArrayInt with number of components different than 1 !"); } diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 2ab3f47ee..aa9a0196f 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -80,6 +80,8 @@ namespace ParaMEDMEM void useArray(const T *array, bool ownership, DeallocType type, int nbOfElem); void useExternalArrayWithRWAccess(const T *array, int nbOfElem); void writeOnPlace(int id, T element0, const T *others, int sizeOfOthers); + template + void insertAtTheEnd(InputIterator first, InputIterator last); void pushBack(T elem) throw(INTERP_KERNEL::Exception); T popBack() throw(INTERP_KERNEL::Exception); void pack() const; @@ -118,7 +120,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getNumberOfComponents() const { return (int)_info_on_compo.size(); } MEDCOUPLING_EXPORT virtual int getNumberOfTuples() const = 0; - MEDCOUPLING_EXPORT int getNbOfElems() const { return ((int)_info_on_compo.size())*getNumberOfTuples(); } + MEDCOUPLING_EXPORT virtual int getNbOfElems() const = 0; MEDCOUPLING_EXPORT void checkNbOfTuples(int nbOfTuples, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception); @@ -155,6 +157,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT bool isAllocated() const; MEDCOUPLING_EXPORT void checkAllocated() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); } + MEDCOUPLING_EXPORT int getNbOfElems() const { return _mem.getNbOfElem(); } MEDCOUPLING_EXPORT void setInfoAndChangeNbOfCompo(const std::vector& info) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double doubleValue() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool empty() const throw(INTERP_KERNEL::Exception); @@ -234,11 +237,13 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT const double *end() const { return getConstPointer()+getNbOfElems(); } MEDCOUPLING_EXPORT void useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); MEDCOUPLING_EXPORT void useExternalArrayWithRWAccess(const double *array, int nbOfTuple, int nbOfCompo); + template + MEDCOUPLING_EXPORT void insertAtTheEnd(InputIterator first, InputIterator last) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void writeOnPlace(int id, double element0, const double *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } MEDCOUPLING_EXPORT void checkNoNullValues() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void getMinMaxPerComponent(double *bounds) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayDouble *computeBBoxPerTuple(double epsilon=0.0) const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void computeTupleIdsNearTuples(const DataArrayDouble *other, double eps, std::vector& c, std::vector& cI) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void computeTupleIdsNearTuples(const DataArrayDouble *other, double eps, DataArrayInt *& c, DataArrayInt *& cI) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void recenterForMaxPrecision(double eps) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double getMaxValueInArray() const throw(INTERP_KERNEL::Exception); @@ -304,10 +309,10 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoS); public: template - void findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, std::vector& c, std::vector& cI) const; + void findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, DataArrayInt *c, DataArrayInt *cI) const; template static void FindTupleIdsNearTuplesAlg(const BBTree& myTree, const double *pos, int nbOfTuples, double eps, - std::vector& c, std::vector& cI); + DataArrayInt *c, DataArrayInt *cI); private: DataArrayDouble() { } private: @@ -354,6 +359,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT bool isAllocated() const; MEDCOUPLING_EXPORT void checkAllocated() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); } + MEDCOUPLING_EXPORT int getNbOfElems() const { return _mem.getNbOfElem(); } MEDCOUPLING_EXPORT void setInfoAndChangeNbOfCompo(const std::vector& info) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int intValue() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getHashCode() const throw(INTERP_KERNEL::Exception); @@ -490,6 +496,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT std::vector partitionByDifferentValues(std::vector& differentIds) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); MEDCOUPLING_EXPORT void useExternalArrayWithRWAccess(const int *array, int nbOfTuple, int nbOfCompo); + template + MEDCOUPLING_EXPORT void insertAtTheEnd(InputIterator first, InputIterator last) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } MEDCOUPLING_EXPORT static DataArrayInt *Add(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void addEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); @@ -547,6 +555,36 @@ namespace ParaMEDMEM int *_pt; int _nb_of_compo; }; + + template + void DataArrayDouble::insertAtTheEnd(InputIterator first, InputIterator last) throw(INTERP_KERNEL::Exception) + { + int nbCompo=getNumberOfComponents(); + if(nbCompo==1) + _mem.insertAtTheEnd(first,last); + else if(nbCompo==0) + { + _info_on_compo.resize(1); + _mem.insertAtTheEnd(first,last); + } + else + throw INTERP_KERNEL::Exception("DataArrayDouble::insertAtTheEnd : not available for DataArrayDouble with number of components different than 1 !"); + } + + template + void DataArrayInt::insertAtTheEnd(InputIterator first, InputIterator last) throw(INTERP_KERNEL::Exception) + { + int nbCompo=getNumberOfComponents(); + if(nbCompo==1) + _mem.insertAtTheEnd(first,last); + else if(nbCompo==0) + { + _info_on_compo.resize(1); + _mem.insertAtTheEnd(first,last); + } + else + throw INTERP_KERNEL::Exception("DataArrayInt::insertAtTheEnd : not available for DataArrayInt with number of components different than 1 !"); + } } #endif diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 3ebd8c67f..35404431b 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -93,6 +93,22 @@ namespace ParaMEDMEM _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 || _nb_of_elem==0) + { + 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) throw(INTERP_KERNEL::Exception) { diff --git a/src/MEDCoupling/MEDCouplingPointSet.cxx b/src/MEDCoupling/MEDCouplingPointSet.cxx index 20d6d509a..3024822c4 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.cxx +++ b/src/MEDCoupling/MEDCouplingPointSet.cxx @@ -225,10 +225,11 @@ void MEDCouplingPointSet::findCommonNodes(double prec, int limitNodeId, DataArra _coords->findCommonTuples(prec,limitNodeId,comm,commIndex); } -std::vector MEDCouplingPointSet::getNodeIdsNearPoint(const double *pos, double eps) const throw(INTERP_KERNEL::Exception) +DataArrayInt *MEDCouplingPointSet::getNodeIdsNearPoint(const double *pos, double eps) const throw(INTERP_KERNEL::Exception) { - std::vector c,cI; + DataArrayInt *c=0,*cI=0; getNodeIdsNearPoints(pos,1,eps,c,cI); + MEDCouplingAutoRefCountObjectPtr cITmp(cI); return c; } @@ -237,7 +238,7 @@ std::vector MEDCouplingPointSet::getNodeIdsNearPoint(const double *pos, dou * Position 'pos' is expected to be of size getSpaceDimension()*nbOfNodes. If not the behabiour is not warranted. * This method throws an exception if no coordiantes are set. */ -void MEDCouplingPointSet::getNodeIdsNearPoints(const double *pos, int nbOfNodes, double eps, std::vector& c, std::vector& cI) const throw(INTERP_KERNEL::Exception) +void MEDCouplingPointSet::getNodeIdsNearPoints(const double *pos, int nbOfNodes, double eps, DataArrayInt *& c, DataArrayInt *& cI) const throw(INTERP_KERNEL::Exception) { if(!_coords) throw INTERP_KERNEL::Exception("MEDCouplingPointSet::getNodeIdsNearPoint : no coordiantes set !"); @@ -703,6 +704,12 @@ void MEDCouplingPointSet::unserialization(const std::vector& tinyInfoD, } } +void MEDCouplingPointSet::checkCoherency() const throw(INTERP_KERNEL::Exception) +{ + if(!_coords) + throw INTERP_KERNEL::Exception("MEDCouplingPointSet::checkCoherency : no coordinates set !"); +} + /*! * Intersect Bounding Box given 2 Bounding Boxes. */ diff --git a/src/MEDCoupling/MEDCouplingPointSet.hxx b/src/MEDCoupling/MEDCouplingPointSet.hxx index 4e00e4770..e06c91e21 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.hxx +++ b/src/MEDCoupling/MEDCouplingPointSet.hxx @@ -70,8 +70,8 @@ namespace ParaMEDMEM virtual DataArrayInt *mergeNodes2(double precision, bool& areNodesMerged, int& newNbOfNodes) = 0; void getCoordinatesOfNode(int nodeId, std::vector& coo) const throw(INTERP_KERNEL::Exception); DataArrayInt *buildPermArrayForMergeNode(double precision, int limitNodeId, bool& areNodesMerged, int& newNbOfNodes) const; - std::vector getNodeIdsNearPoint(const double *pos, double eps) const throw(INTERP_KERNEL::Exception); - void getNodeIdsNearPoints(const double *pos, int nbOfNodes, double eps, std::vector& c, std::vector& cI) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getNodeIdsNearPoint(const double *pos, double eps) const throw(INTERP_KERNEL::Exception); + void getNodeIdsNearPoints(const double *pos, int nbOfNodes, double eps, DataArrayInt *& c, DataArrayInt *& cI) const throw(INTERP_KERNEL::Exception); void findCommonNodes(double prec, int limitNodeId, DataArrayInt *&comm, DataArrayInt *&commIndex) const; DataArrayInt *buildNewNumberingFromCommonNodesFormat(const DataArrayInt *comm, const DataArrayInt *commIndex, int& newNbOfNodes) const; @@ -114,6 +114,7 @@ namespace ParaMEDMEM virtual void getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps, std::vector& elems) = 0; virtual DataArrayInt *zipCoordsTraducer() = 0; protected: + void checkCoherency() const throw(INTERP_KERNEL::Exception); virtual void checkFullyDefined() const throw(INTERP_KERNEL::Exception) = 0; static bool intersectsBoundingBox(const double* bb1, const double* bb2, int dim, double eps); static bool intersectsBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bb1, const double* bb2, int dim, double eps); diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index cc30e8117..6f05939cf 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -101,7 +101,9 @@ MEDCouplingUMesh::MEDCouplingUMesh():_mesh_dim(-2),_nodal_connec(0),_nodal_conne void MEDCouplingUMesh::checkCoherency() const throw(INTERP_KERNEL::Exception) { if(_mesh_dim<-1) - throw INTERP_KERNEL::Exception("No mesh dimension specified !"); + throw INTERP_KERNEL::Exception("No mesh dimension specified !"); + if(_mesh_dim!=-1) + MEDCouplingPointSet::checkCoherency(); for(std::set::const_iterator iter=_types.begin();iter!=_types.end();iter++) { if((int)INTERP_KERNEL::CellModel::GetCellModel(*iter).getDimension()!=_mesh_dim) @@ -414,13 +416,9 @@ void MEDCouplingUMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int ce pt=std::find_if(da->getConstPointer()+getNumberOfCells(),da->getConstPointer()+da->getNbOfElems(),std::bind2nd(std::greater(),maxId)); if(pt!=da->getConstPointer()+da->getNbOfElems()) throw INTERP_KERNEL::Exception("checkDeepEquivalWith : some cells in other are not in this !"); - MEDCouplingAutoRefCountObjectPtr cellCor2=DataArrayInt::New(); - cellCor2->alloc(otherC->getNumberOfCells(),1); - std::copy(da->getConstPointer()+getNumberOfCells(),da->getConstPointer()+da->getNbOfElems(),cellCor2->getPointer()); - bool nident=nodeCor2->isIdentity(); - bool cident=cellCor2->isIdentity(); - if(!nident) nodeCor=nodeCor2.retn(); else nodeCor=0; - if(!cident) cellCor=cellCor2.retn(); else cellCor=0; + MEDCouplingAutoRefCountObjectPtr cellCor2=da->selectByTupleId2(getNumberOfCells(),da->getNbOfElems(),1); + nodeCor=nodeCor2->isIdentity()?0:nodeCor2.retn(); + cellCor=cellCor2->isIdentity()?0:cellCor2.retn(); } /*! @@ -455,10 +453,8 @@ void MEDCouplingUMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *ot { throw INTERP_KERNEL::Exception("checkDeepEquivalOnSameNodesWith : some cells in other are not in this !"); } - MEDCouplingAutoRefCountObjectPtr cellCor2=DataArrayInt::New(); - cellCor2->alloc(otherC->getNumberOfCells(),1); - std::copy(da->getConstPointer()+getNumberOfCells(),da->getConstPointer()+da->getNbOfElems(),cellCor2->getPointer()); - if(!cellCor2->isIdentity()) cellCor=cellCor2.retn(); else cellCor=0; + MEDCouplingAutoRefCountObjectPtr cellCor2=da->selectByTupleId2(getNumberOfCells(),da->getNbOfElems(),1); + cellCor=cellCor2->isIdentity()?0:cellCor2.retn(); } /*! @@ -635,20 +631,17 @@ void MEDCouplingUMesh::ComputeNeighborsOfCellsAdv(const DataArrayInt *desc, cons MEDCouplingAutoRefCountObjectPtr out1=DataArrayInt::New(); out1->alloc(nbCells+1,1); int *out1Ptr=out1->getPointer(); *out1Ptr++=0; - std::vector out0v; - out0v.reserve(desc->getNumberOfTuples()); + out0->reserve(desc->getNumberOfTuples()); for(int i=0;i s(revDescPtr+revDescIPtr[*w1],revDescPtr+revDescIPtr[(*w1)+1]); s.erase(i); - out0v.insert(out0v.end(),s.begin(),s.end()); + out0->insertAtTheEnd(s.begin(),s.end()); } - *out1Ptr=out0v.size(); + *out1Ptr=out0->getNumberOfTuples(); } - out0->alloc((int)out0v.size(),1); - std::copy(out0v.begin(),out0v.end(),out0->getPointer()); neighbors=out0.retn(); neighborsIndx=out1.retn(); } @@ -1052,7 +1045,7 @@ void MEDCouplingUMesh::simplifyPolyhedra(double eps) throw(INTERP_KERNEL::Except MEDCouplingAutoRefCountObjectPtr connINew=DataArrayInt::New(); connINew->alloc(nbOfCells+1,1); int *connINewPtr=connINew->getPointer(); *connINewPtr++=0; - std::vector connNew; + MEDCouplingAutoRefCountObjectPtr connNew=DataArrayInt::New(); bool changed=false; for(int i=0;iinsertAtTheEnd(conn+index[i],conn+index[i+1]); + *connINewPtr=connNew->getNumberOfTuples(); } if(changed) - { - MEDCouplingAutoRefCountObjectPtr connNew2=DataArrayInt::New(); - connNew2->alloc((int)connNew.size(),1); - std::copy(connNew.begin(),connNew.end(),connNew2->getPointer()); - setConnectivity(connNew2,connINew,false); - } + setConnectivity(connNew,connINew,false); } /*! @@ -1085,17 +1073,26 @@ void MEDCouplingUMesh::simplifyPolyhedra(double eps) throw(INTERP_KERNEL::Except DataArrayInt *MEDCouplingUMesh::computeFetchedNodeIds() const throw(INTERP_KERNEL::Exception) { checkConnectivityFullyDefined(); - std::set retS; int nbOfCells=getNumberOfCells(); const int *connIndex=_nodal_connec_index->getConstPointer(); const int *conn=_nodal_connec->getConstPointer(); + const int *maxEltPt=std::max_element(_nodal_connec->begin(),_nodal_connec->end()); + int maxElt=maxEltPt==_nodal_connec->end()?0:std::abs(*maxEltPt)+1; + std::vector retS(maxElt,false); for(int i=0;i=0) - retS.insert(conn[j]); + retS[conn[j]]=true; + int sz=0; + for(int i=0;ialloc((int)retS.size(),1); - std::copy(retS.begin(),retS.end(),ret->getPointer()); + ret->alloc(sz,1); + int *retPtr=ret->getPointer(); + for(int i=0;i tmp=new int[sz1]; + int *work=std::copy(conn+connI[cell1]+1,conn+connI[cell1+1],(int *)tmp); std::copy(conn+connI[cell1]+1,conn+connI[cell1+1],work); - work=std::search(tmp,tmp+sz1,conn+connI[cell2]+1,conn+connI[cell2+1]); - delete [] tmp; + work=std::search((int *)tmp,(int *)tmp+sz1,conn+connI[cell2]+1,conn+connI[cell2+1]); return work!=tmp+sz1?1:0; } else @@ -1275,29 +1271,20 @@ int MEDCouplingUMesh::areCellsEqual7(int cell1, int cell2) const if(dim!=1) { int sz1=2*(sz-1); - int *tmp=new int[sz1]; - int *work=std::copy(conn+connI[cell1]+1,conn+connI[cell1+1],tmp); + INTERP_KERNEL::AutoPtr tmp=new int[sz1]; + int *work=std::copy(conn+connI[cell1]+1,conn+connI[cell1+1],(int *)tmp); std::copy(conn+connI[cell1]+1,conn+connI[cell1+1],work); - work=std::search(tmp,tmp+sz1,conn+connI[cell2]+1,conn+connI[cell2+1]); + work=std::search((int *)tmp,(int *)tmp+sz1,conn+connI[cell2]+1,conn+connI[cell2+1]); if(work!=tmp+sz1) - { - delete [] tmp; - return 1; - } + return 1; else { - std::reverse_iterator it1(tmp+sz1); - std::reverse_iterator it2(tmp); + std::reverse_iterator it1((int *)tmp+sz1); + std::reverse_iterator it2((int *)tmp); if(std::search(it1,it2,conn+connI[cell2]+1,conn+connI[cell2+1])!=it2) - { - delete [] tmp; - return 2; - } + return 2; else - { - delete [] tmp; - return 0; - } + return 0; } return work!=tmp+sz1?1:0; @@ -1365,7 +1352,7 @@ bool MEDCouplingUMesh::areCellsFrom2MeshEqual(const MEDCouplingUMesh *other, int * If in 'candidates' pool -1 value is considered as an empty value. * WARNING this method returns only ONE set of result ! */ -bool MEDCouplingUMesh::areCellsEqualInPool(const std::vector& candidates, int compType, std::vector& result) const +bool MEDCouplingUMesh::areCellsEqualInPool(const std::vector& candidates, int compType, DataArrayInt *result) const { if(candidates.size()<1) return false; @@ -1379,13 +1366,13 @@ bool MEDCouplingUMesh::areCellsEqualInPool(const std::vector& candidates, i { if(!ret) { - result.push_back(start); + result->pushBackSilent(start); ret=true; } if(status==1) - result.push_back(*iter); + result->pushBackSilent(*iter); else - result.push_back(status==2?(*iter+1):-(*iter+1)); + result->pushBackSilent(status==2?(*iter+1):-(*iter+1)); } } return ret; @@ -1407,12 +1394,12 @@ bool MEDCouplingUMesh::areCellsEqualInPool(const std::vector& candidates, i * \return the correspondance array old to new in a newly allocated array. * */ -void MEDCouplingUMesh::findCommonCells(int compType, int startCellId, std::vector& commonCells, std::vector& commonCellsI) const throw(INTERP_KERNEL::Exception) +void MEDCouplingUMesh::findCommonCells(int compType, int startCellId, DataArrayInt *& commonCellsArr, DataArrayInt *& commonCellsIArr) const throw(INTERP_KERNEL::Exception) { + MEDCouplingAutoRefCountObjectPtr commonCells=DataArrayInt::New(),commonCellsI=DataArrayInt::New(); checkConnectivityFullyDefined(); int nbOfCells=getNumberOfCells(); - commonCells.clear(); - commonCellsI.resize(1); commonCellsI[0]=0; + commonCellsI->reserve(1); commonCellsI->pushBackSilent(0); MEDCouplingAutoRefCountObjectPtr revNodal=DataArrayInt::New(),revNodalI=DataArrayInt::New(); getReverseNodalConnectivity(revNodal,revNodalI); const int *revNodalPtr=revNodal->getConstPointer(),*revNodalIPtr=revNodalI->getConstPointer(); @@ -1444,9 +1431,9 @@ void MEDCouplingUMesh::findCommonCells(int compType, int startCellId, std::vecto { if(areCellsEqualInPool(v2,compType,commonCells)) { - int pos=commonCellsI.back(); - commonCellsI.push_back((int)commonCells.size()); - for(std::vector::const_iterator it=commonCells.begin()+pos;it!=commonCells.end();it++) + int pos=commonCellsI->back(); + commonCellsI->pushBackSilent(commonCells->getNumberOfTuples()); + for(const int *it=commonCells->begin()+pos;it!=commonCells->end();it++) isFetched[*it]=true; } } @@ -1477,15 +1464,17 @@ void MEDCouplingUMesh::findCommonCells(int compType, int startCellId, std::vecto { if(areCellsEqualInPool(v2,compType,commonCells)) { - int pos=commonCellsI.back(); - commonCellsI.push_back((int)commonCells.size()); - for(std::vector::const_iterator it=commonCells.begin()+pos;it!=commonCells.end();it++) + int pos=commonCellsI->back(); + commonCellsI->pushBackSilent(commonCells->getNumberOfTuples()); + for(const int *it=commonCells->begin()+pos;it!=commonCells->end();it++) isFetched[*it]=true; } } } } } + commonCellsArr=commonCells.retn(); + commonCellsIArr=commonCellsI.retn(); } /*! @@ -1506,11 +1495,12 @@ void MEDCouplingUMesh::findCommonCells(int compType, int startCellId, std::vecto */ DataArrayInt *MEDCouplingUMesh::zipConnectivityTraducer(int compType, int startCellId) throw(INTERP_KERNEL::Exception) { - std::vector commonCells,commonCellsI; + DataArrayInt *commonCells=0,*commonCellsI=0; findCommonCells(compType,startCellId,commonCells,commonCellsI); + MEDCouplingAutoRefCountObjectPtr commonCellsTmp(commonCells),commonCellsITmp(commonCellsI); int newNbOfCells=-1; - MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(getNumberOfCells(),&commonCells[0],&commonCellsI[0], - &commonCellsI[0]+commonCellsI.size(),newNbOfCells); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(getNumberOfCells(),commonCells->begin(),commonCellsI->begin(), + commonCellsI->end(),newNbOfCells); MEDCouplingAutoRefCountObjectPtr ret2=ret->invertArrayO2N2N2O(newNbOfCells); MEDCouplingAutoRefCountObjectPtr self=static_cast(buildPartOfMySelf(ret2->begin(),ret2->end(),true)); setConnectivity(self->getNodalConnectivity(),self->getNodalConnectivityIndex(),true); @@ -1561,24 +1551,26 @@ bool MEDCouplingUMesh::areCellsIncludedIn(const MEDCouplingUMesh *other, int com bool MEDCouplingUMesh::areCellsIncludedIn2(const MEDCouplingUMesh *other, DataArrayInt *& arr) const throw(INTERP_KERNEL::Exception) { MEDCouplingAutoRefCountObjectPtr mesh=MergeUMeshesOnSameCoords(this,other); - std::vector commonCells,commonCellsI; + DataArrayInt *commonCells=0,*commonCellsI=0; int thisNbCells=getNumberOfCells(); mesh->findCommonCells(7,thisNbCells,commonCells,commonCellsI); + MEDCouplingAutoRefCountObjectPtr commonCellsTmp(commonCells),commonCellsITmp(commonCellsI); + const int *commonCellsPtr=commonCells->getConstPointer(),*commonCellsIPtr=commonCellsI->getConstPointer(); int otherNbCells=other->getNumberOfCells(); MEDCouplingAutoRefCountObjectPtr arr2=DataArrayInt::New(); arr2->alloc(otherNbCells,1); arr2->fillWithZero(); int *arr2Ptr=arr2->getPointer(); - int nbOfCommon=(int)commonCellsI.size()-1; + int nbOfCommon=commonCellsI->getNumberOfTuples()-1; for(int i=0;i0?1:-1; - int val=std::abs(commonCells[j])-1; + int sig=commonCellsPtr[j]>0?1:-1; + int val=std::abs(commonCellsPtr[j])-1; if(val>=thisNbCells) arr2Ptr[val-thisNbCells]=sig*(start+1); } @@ -1826,12 +1818,10 @@ void MEDCouplingUMesh::setPartOfMySelf2(int start, int end, int step, const MEDC DataArrayInt *MEDCouplingUMesh::getCellIdsFullyIncludedInNodeIds(const int *partBg, const int *partEnd) const { - std::vector cellIdsKept; + DataArrayInt *cellIdsKept=0; fillCellIdsToKeepFromNodeIds(partBg,partEnd,true,cellIdsKept); - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc((int)cellIdsKept.size(),1); - std::copy(cellIdsKept.begin(),cellIdsKept.end(),ret->getPointer()); - return ret; + cellIdsKept->setName(getName()); + return cellIdsKept; } /*! @@ -1840,13 +1830,14 @@ DataArrayInt *MEDCouplingUMesh::getCellIdsFullyIncludedInNodeIds(const int *part * Parameter 'fullyIn' specifies if a cell that has part of its nodes in ids array is kept or not. * If 'fullyIn' is true only cells whose ids are \b fully contained in ['begin','end') tab will be kept. * - * @param begin input start of array of node ids. - * @param end input end of array of node ids. - * @param fullyIn input that specifies if all node ids must be in ['begin','end') array to consider cell to be in. - * @param cellIdsKept in/out array where all candidate cell ids are put at the end. + * \param [in] begin input start of array of node ids. + * \param [in] end input end of array of node ids. + * \param [in] fullyIn input that specifies if all node ids must be in ['begin','end') array to consider cell to be in. + * \param [in,out] cellIdsKeptArr array where all candidate cell ids are put at the end. */ -void MEDCouplingUMesh::fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, std::vector& cellIdsKept) const +void MEDCouplingUMesh::fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const { + MEDCouplingAutoRefCountObjectPtr cellIdsKept=DataArrayInt::New(); checkConnectivityFullyDefined(); int tmp=-1; int sz=getNodalConnectivity()->getMaxValue(tmp); sz=std::max(sz,0)+1; @@ -1868,8 +1859,9 @@ void MEDCouplingUMesh::fillCellIdsToKeepFromNodeIds(const int *begin, const int nbOfHit++; } if((ref==nbOfHit && fullyIn) || (nbOfHit!=0 && !fullyIn)) - cellIdsKept.push_back(i); + cellIdsKept->pushBackSilent(i); } + cellIdsKeptArr=cellIdsKept.retn(); } /*! @@ -1877,13 +1869,10 @@ void MEDCouplingUMesh::fillCellIdsToKeepFromNodeIds(const int *begin, const int */ DataArrayInt *MEDCouplingUMesh::getCellIdsLyingOnNodes(const int *begin, const int *end, bool fullyIn) const { - std::vector cellIdsKept; + DataArrayInt *cellIdsKept=0; fillCellIdsToKeepFromNodeIds(begin,end,fullyIn,cellIdsKept); - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc((int)cellIdsKept.size(),1); - std::copy(cellIdsKept.begin(),cellIdsKept.end(),ret->getPointer()); - ret->setName(getName()); - return ret; + cellIdsKept->setName(getName()); + return cellIdsKept; } /*! @@ -1894,9 +1883,10 @@ DataArrayInt *MEDCouplingUMesh::getCellIdsLyingOnNodes(const int *begin, const i */ MEDCouplingPointSet *MEDCouplingUMesh::buildPartOfMySelfNode(const int *begin, const int *end, bool fullyIn) const { - std::vector cellIdsKept; + DataArrayInt *cellIdsKept=0; fillCellIdsToKeepFromNodeIds(begin,end,fullyIn,cellIdsKept); - return buildPartOfMySelf(&cellIdsKept[0],&cellIdsKept[0]+cellIdsKept.size(),true); + MEDCouplingAutoRefCountObjectPtr cellIdsKept2(cellIdsKept); + return buildPartOfMySelf(cellIdsKept->begin(),cellIdsKept->end(),true); } /*! @@ -1951,32 +1941,34 @@ MEDCouplingPointSet *MEDCouplingUMesh::buildBoundaryMesh(bool keepCoords) const DataArrayInt *MEDCouplingUMesh::findCellIdsOnBoundary() const throw(INTERP_KERNEL::Exception) { checkFullyDefined(); - DataArrayInt *desc=DataArrayInt::New(); - DataArrayInt *descIndx=DataArrayInt::New(); - DataArrayInt *revDesc=DataArrayInt::New(); - DataArrayInt *revDescIndx=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr desc=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr descIndx=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr revDesc=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr revDescIndx=DataArrayInt::New(); // - MEDCouplingUMesh *meshDM1=buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); - meshDM1->decrRef(); - desc->decrRef(); - descIndx->decrRef(); + buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx)->decrRef(); + desc=(DataArrayInt*)0; descIndx=(DataArrayInt*)0; // - DataArrayInt *tmp=revDescIndx->deltaShiftIndex(); - DataArrayInt *faceIds=tmp->getIdsEqual(1); - tmp->decrRef(); + MEDCouplingAutoRefCountObjectPtr tmp=revDescIndx->deltaShiftIndex(); + MEDCouplingAutoRefCountObjectPtr faceIds=tmp->getIdsEqual(1); tmp=(DataArrayInt*)0; int nbOfFaces=faceIds->getNumberOfTuples(); const int *faces=faceIds->getConstPointer(); - std::set ret; - for(const int *w=faces;w!=faces+nbOfFaces;w++) - ret.insert(revDesc->getIJ(revDescIndx->getIJ(*w,0),0)); - faceIds->decrRef(); - // - revDescIndx->decrRef(); - revDesc->decrRef(); + const int *revDescPtr=revDesc->getConstPointer(); + const int *revDescIndxPtr=revDescIndx->getConstPointer(); + int nbOfCells=getNumberOfCells(); + std::vector ret1(nbOfCells,false); + int sz=0; + for(const int *pt=faceIds->begin();pt!=faceIds->end();pt++) + if(!ret1[revDescPtr[revDescIndxPtr[*pt]]]) + { ret1[revDescPtr[revDescIndxPtr[*pt]]]=true; sz++; } // DataArrayInt *ret2=DataArrayInt::New(); - ret2->alloc((int)ret.size(),1); - std::copy(ret.begin(),ret.end(),ret2->getPointer()); + ret2->alloc(sz,1); + int *ret2Ptr=ret2->getPointer(); + sz=0; + for(std::vector::const_iterator it=ret1.begin();it!=ret1.end();it++,sz++) + if(*it) + *ret2Ptr++=sz; ret2->setName("BoundaryCells"); return ret2; } @@ -2456,12 +2448,13 @@ INTERP_KERNEL::NormalizedCellType MEDCouplingUMesh::getTypeOfCell(int cellId) co * The coordinates array is not considered here. * * \param [in] type the geometric type - * \return the + * \return cell ids in this having geometric type \a type. */ DataArrayInt *MEDCouplingUMesh::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception) { - std::vector v; + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); + ret->alloc(0,1); checkConnectivityFullyDefined(); int nbCells=getNumberOfCells(); int mdim=getMeshDimension(); @@ -2473,10 +2466,8 @@ DataArrayInt *MEDCouplingUMesh::giveCellsWithType(INTERP_KERNEL::NormalizedCellT for(int i=0;ipushBackSilent(i); } - MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc((int)v.size(),1); - std::copy(v.begin(),v.end(),ret->getPointer()); return ret.retn(); } @@ -3260,7 +3251,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildSlice3D(const double *origin, const dou if(candidates->empty()) throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildSlice3D : No 3D cells in this intercepts the specified plane considering bounding boxes !"); std::vector nodes; - std::vector cellIds2D,cellIds1D; + DataArrayInt *cellIds1D=0; MEDCouplingAutoRefCountObjectPtr subMesh=static_cast(buildPartOfMySelf(candidates->begin(),candidates->end(),false)); subMesh->findNodesOnPlane(origin,vec,eps,nodes); MEDCouplingAutoRefCountObjectPtr desc1=DataArrayInt::New(),desc2=DataArrayInt::New(); @@ -3269,32 +3260,28 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildSlice3D(const double *origin, const dou MEDCouplingAutoRefCountObjectPtr revDescIndx1=DataArrayInt::New(),revDescIndx2=DataArrayInt::New(); MEDCouplingAutoRefCountObjectPtr mDesc2=subMesh->buildDescendingConnectivity(desc2,descIndx2,revDesc2,revDescIndx2);//meshDim==2 spaceDim==3 revDesc2=0; revDescIndx2=0; - mDesc2->fillCellIdsToKeepFromNodeIds(&nodes[0],&nodes[0]+nodes.size(),true,cellIds2D); MEDCouplingAutoRefCountObjectPtr mDesc1=mDesc2->buildDescendingConnectivity(desc1,descIndx1,revDesc1,revDescIndx1);//meshDim==1 spaceDim==3 revDesc1=0; revDescIndx1=0; mDesc1->fillCellIdsToKeepFromNodeIds(&nodes[0],&nodes[0]+nodes.size(),true,cellIds1D); + MEDCouplingAutoRefCountObjectPtr cellIds1DTmp(cellIds1D); // std::vector cut3DCurve(mDesc1->getNumberOfCells(),-2); - for(std::vector::const_iterator it=cellIds1D.begin();it!=cellIds1D.end();it++) + for(const int *it=cellIds1D->begin();it!=cellIds1D->end();it++) cut3DCurve[*it]=-1; mDesc1->split3DCurveWithPlane(origin,vec,eps,cut3DCurve); std::vector< std::pair > cut3DSurf(mDesc2->getNumberOfCells()); AssemblyForSplitFrom3DCurve(cut3DCurve,nodes,mDesc2->getNodalConnectivity()->getConstPointer(),mDesc2->getNodalConnectivityIndex()->getConstPointer(), mDesc1->getNodalConnectivity()->getConstPointer(),mDesc1->getNodalConnectivityIndex()->getConstPointer(), desc1->getConstPointer(),descIndx1->getConstPointer(),cut3DSurf); - std::vector conn,connI,cellIds2; - connI.push_back(0); + MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()),connI(DataArrayInt::New()),cellIds2(DataArrayInt::New()); + connI->pushBackSilent(0); subMesh->assemblyForSplitFrom3DSurf(cut3DSurf,desc2->getConstPointer(),descIndx2->getConstPointer(),conn,connI,cellIds2); - if(cellIds2.empty()) + if(cellIds2->empty()) throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildSlice3D : No 3D cells in this intercepts the specified plane !"); MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingUMesh::New("Slice3D",2); ret->setCoords(mDesc1->getCoords()); - MEDCouplingAutoRefCountObjectPtr c=DataArrayInt::New(); - c->alloc((int)conn.size(),1); std::copy(conn.begin(),conn.end(),c->getPointer()); - MEDCouplingAutoRefCountObjectPtr cI=DataArrayInt::New(); - cI->alloc((int)connI.size(),1); std::copy(connI.begin(),connI.end(),cI->getPointer()); - ret->setConnectivity(c,cI,true); - cellIds=candidates->selectByTupleId(&cellIds2[0],&cellIds2[0]+cellIds2.size()); + ret->setConnectivity(conn,connI,true); + cellIds=candidates->selectByTupleId(cellIds2->begin(),cellIds2->end()); return ret.retn(); } @@ -3321,7 +3308,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildSlice3DSurf(const double *origin, const if(candidates->empty()) throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildSlice3DSurf : No 3D surf cells in this intercepts the specified plane considering bounding boxes !"); std::vector nodes; - std::vector cellIds1D; + DataArrayInt *cellIds1D=0; MEDCouplingAutoRefCountObjectPtr subMesh=static_cast(buildPartOfMySelf(candidates->begin(),candidates->end(),false)); subMesh->findNodesOnPlane(origin,vec,eps,nodes); MEDCouplingAutoRefCountObjectPtr desc1=DataArrayInt::New(); @@ -3330,9 +3317,10 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildSlice3DSurf(const double *origin, const MEDCouplingAutoRefCountObjectPtr revDescIndx1=DataArrayInt::New(); MEDCouplingAutoRefCountObjectPtr mDesc1=subMesh->buildDescendingConnectivity(desc1,descIndx1,revDesc1,revDescIndx1);//meshDim==1 spaceDim==3 mDesc1->fillCellIdsToKeepFromNodeIds(&nodes[0],&nodes[0]+nodes.size(),true,cellIds1D); + MEDCouplingAutoRefCountObjectPtr cellIds1DTmp(cellIds1D); // std::vector cut3DCurve(mDesc1->getNumberOfCells(),-2); - for(std::vector::const_iterator it=cellIds1D.begin();it!=cellIds1D.end();it++) + for(const int *it=cellIds1D->begin();it!=cellIds1D->end();it++) cut3DCurve[*it]=-1; mDesc1->split3DCurveWithPlane(origin,vec,eps,cut3DCurve); int ncellsSub=subMesh->getNumberOfCells(); @@ -3340,7 +3328,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildSlice3DSurf(const double *origin, const AssemblyForSplitFrom3DCurve(cut3DCurve,nodes,subMesh->getNodalConnectivity()->getConstPointer(),subMesh->getNodalConnectivityIndex()->getConstPointer(), mDesc1->getNodalConnectivity()->getConstPointer(),mDesc1->getNodalConnectivityIndex()->getConstPointer(), desc1->getConstPointer(),descIndx1->getConstPointer(),cut3DSurf); - std::vector conn,connI,cellIds2; connI.push_back(0); + MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()),connI(DataArrayInt::New()),cellIds2(DataArrayInt::New()); connI->pushBackSilent(0); const int *nodal=subMesh->getNodalConnectivity()->getConstPointer(); const int *nodalI=subMesh->getNodalConnectivityIndex()->getConstPointer(); for(int i=0;ipushBackSilent((int)INTERP_KERNEL::NORM_SEG2); conn->pushBackSilent(cut3DSurf[i].first); conn->pushBackSilent(cut3DSurf[i].second); + connI->pushBackSilent(conn->getNumberOfTuples()); + cellIds2->pushBackSilent(i); } else { @@ -3360,23 +3348,19 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildSlice3DSurf(const double *origin, const int nbOfEdges=nodalI[cellId3DSurf+1]-offset; for(int j=0;jpushBackSilent((int)INTERP_KERNEL::NORM_SEG2); conn->pushBackSilent(nodal[offset+j]); conn->pushBackSilent(nodal[offset+(j+1)%nbOfEdges]); + connI->pushBackSilent(conn->getNumberOfTuples()); + cellIds2->pushBackSilent(cellId3DSurf); } } } } - if(cellIds2.empty()) + if(cellIds2->empty()) throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildSlice3DSurf : No 3DSurf cells in this intercepts the specified plane !"); MEDCouplingAutoRefCountObjectPtr ret=MEDCouplingUMesh::New("Slice3DSurf",1); ret->setCoords(mDesc1->getCoords()); - MEDCouplingAutoRefCountObjectPtr c=DataArrayInt::New(); - c->alloc((int)conn.size(),1); std::copy(conn.begin(),conn.end(),c->getPointer()); - MEDCouplingAutoRefCountObjectPtr cI=DataArrayInt::New(); - cI->alloc((int)connI.size(),1); std::copy(connI.begin(),connI.end(),cI->getPointer()); - ret->setConnectivity(c,cI,true); - cellIds=candidates->selectByTupleId(&cellIds2[0],&cellIds2[0]+cellIds2.size()); + ret->setConnectivity(conn,connI,true); + cellIds=candidates->selectByTupleId(cellIds2->begin(),cellIds2->end()); return ret.retn(); } @@ -3785,31 +3769,26 @@ DataArrayInt *MEDCouplingUMesh::convexEnvelop2D() throw(INTERP_KERNEL::Exception int nbOfCells=getNumberOfCells(); MEDCouplingAutoRefCountObjectPtr nodalConnecIndexOut=DataArrayInt::New(); nodalConnecIndexOut->alloc(nbOfCells+1,1); - std::vector nodalConnecOut; + MEDCouplingAutoRefCountObjectPtr nodalConnecOut(DataArrayInt::New()); int *workIndexOut=nodalConnecIndexOut->getPointer(); *workIndexOut=0; const int *nodalConnecIn=_nodal_connec->getConstPointer(); const int *nodalConnecIndexIn=_nodal_connec_index->getConstPointer(); std::set types; - std::vector isChanged; + MEDCouplingAutoRefCountObjectPtr isChanged(DataArrayInt::New()); for(int i=0;igetNumberOfTuples(); if(BuildConvexEnvelopOf2DCellJarvis(coords,nodalConnecIn+nodalConnecIndexIn[i],nodalConnecIn+nodalConnecIndexIn[i+1],nodalConnecOut)) - isChanged.push_back(i); - types.insert((INTERP_KERNEL::NormalizedCellType)nodalConnecOut[pos]); - workIndexOut[1]=(int)nodalConnecOut.size(); + isChanged->pushBackSilent(i); + types.insert((INTERP_KERNEL::NormalizedCellType)nodalConnecOut->getIJ(pos,0)); + workIndexOut[1]=nodalConnecOut->getNumberOfTuples(); } - if(isChanged.empty()) + if(isChanged->empty()) return 0; - MEDCouplingAutoRefCountObjectPtr nodalConnecOut2=DataArrayInt::New(); - nodalConnecOut2->alloc((int)nodalConnecOut.size(),1); - std::copy(nodalConnecOut.begin(),nodalConnecOut.end(),nodalConnecOut2->getPointer()); - setConnectivity(nodalConnecOut2,nodalConnecIndexOut,false); + setConnectivity(nodalConnecOut,nodalConnecIndexOut,false); _types=types; - DataArrayInt *ret=DataArrayInt::New(); ret->alloc((int)isChanged.size(),1); - std::copy(isChanged.begin(),isChanged.end(),ret->getPointer()); - return ret; + return isChanged.retn(); } /*! @@ -3818,7 +3797,7 @@ DataArrayInt *MEDCouplingUMesh::convexEnvelop2D() throw(INTERP_KERNEL::Exception * If some extruded cells does not fulfill the MED norm for extruded cells (first face of 3D cell should be oriented to the exterior of the 3D cell). * Some viewers are very careful of that (SMESH), but ParaVis ignore that. */ -void MEDCouplingUMesh::findAndCorrectBadOriented3DExtrudedCells(std::vector& cells) throw(INTERP_KERNEL::Exception) +DataArrayInt *MEDCouplingUMesh::findAndCorrectBadOriented3DExtrudedCells() throw(INTERP_KERNEL::Exception) { const char msg[]="check3DCellsWellOriented detection works only for 3D cells !"; if(getMeshDimension()!=3) @@ -3832,6 +3811,7 @@ void MEDCouplingUMesh::findAndCorrectBadOriented3DExtrudedCells(std::vector const int *connI=_nodal_connec_index->getConstPointer(); const double *coo=getCoords()->getConstPointer(); double vec0[3],vec1[3]; + MEDCouplingAutoRefCountObjectPtr cells(DataArrayInt::New()); for(int i=0;i double dot=vec0[0]*vec1[0]+vec0[1]*vec1[1]+vec0[2]*vec1[2]; if(dot<0) { - cells.push_back(i); + cells->pushBackSilent(i); std::copy(conn+connI[i]+1,conn+connI[i+1],(int *)tmp); for(int j=1;j } } } + return cells.retn(); } /*! @@ -4347,8 +4328,8 @@ void MEDCouplingUMesh::tessellate2DCurve(double eps) throw(INTERP_KERNEL::Except const int *connI=_nodal_connec_index->getConstPointer(); const double *coords=_coords->getConstPointer(); std::vector addCoo; - std::vector newConn; - MEDCouplingAutoRefCountObjectPtr newConnI=DataArrayInt::New(); + std::vector newConn;//no direct DataArrayInt because interface with Geometric2D + MEDCouplingAutoRefCountObjectPtr newConnI(DataArrayInt::New()); newConnI->alloc(nbCells+1,1); int *newConnIPtr=newConnI->getPointer(); *newConnIPtr=0; @@ -5529,8 +5510,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::AggregateSortedByTypeMeshesOnSameCoords(cons std::vector m1ssmSingle; std::vector< MEDCouplingAutoRefCountObjectPtr > m1ssmSingleAuto; int fake=0,rk=0; - std::vector ret1Data; - std::vector ret2Data; + MEDCouplingAutoRefCountObjectPtr ret1(DataArrayInt::New()),ret2(DataArrayInt::New()); for(std::vector::const_iterator it=ms2.begin();it!=ms2.end();it++,rk++) { if(meshDim!=(*it)->getMeshDimension()) @@ -5545,11 +5525,9 @@ MEDCouplingUMesh *MEDCouplingUMesh::AggregateSortedByTypeMeshesOnSameCoords(cons MEDCouplingUMesh *singleCell=static_cast((*it2)->buildPartOfMySelf(&fake,&fake+1,true)); m1ssmSingleAuto.push_back(singleCell); m1ssmSingle.push_back(singleCell); - ret1Data.push_back((*it2)->getNumberOfCells()); ret2Data.push_back(rk); + ret1->pushBackSilent((*it2)->getNumberOfCells()); ret2->pushBackSilent(rk); } } - MEDCouplingAutoRefCountObjectPtr ret1=DataArrayInt::New(); ret1->alloc((int)m1ssmSingle.size(),1); std::copy(ret1Data.begin(),ret1Data.end(),ret1->getPointer()); - MEDCouplingAutoRefCountObjectPtr ret2=DataArrayInt::New(); ret2->alloc((int)m1ssmSingle.size(),1); std::copy(ret2Data.begin(),ret2Data.end(),ret2->getPointer()); MEDCouplingAutoRefCountObjectPtr m1ssmSingle2=MEDCouplingUMesh::MergeUMeshesOnSameCoords(m1ssmSingle); MEDCouplingAutoRefCountObjectPtr renum=m1ssmSingle2->sortCellsInMEDFileFrmt(); std::vector m1ssmfinal(m1ssm.size()); @@ -5568,16 +5546,13 @@ MEDCouplingUMesh *MEDCouplingUMesh::AggregateSortedByTypeMeshesOnSameCoords(cons DataArrayInt *MEDCouplingUMesh::keepCellIdsByType(INTERP_KERNEL::NormalizedCellType type, const int *begin, const int *end) const throw(INTERP_KERNEL::Exception) { checkFullyDefined(); - std::vector r; const int *conn=_nodal_connec->getConstPointer(); const int *connIndex=_nodal_connec_index->getConstPointer(); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); ret->alloc(0,1); for(const int *w=begin;w!=end;w++) if((INTERP_KERNEL::NormalizedCellType)conn[connIndex[*w]]==type) - r.push_back(*w); - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc((int)r.size(),1); - std::copy(r.begin(),r.end(),ret->getPointer()); - return ret; + ret->pushBackSilent(*w); + return ret.retn(); } /*! @@ -6221,9 +6196,9 @@ bool MEDCouplingUMesh::IsPolyhedronWellOriented(const int *begin, const int *end * \param [in] coords the coordinates with nb of components exactly equal to 3 * \param [in] begin begin of the nodal connectivity (geometric type included) of a single polyhedron cell * \param [in] end end of nodal connectivity of a single polyhedron cell (excluded) - * \param [out] the result is put at the end of the vector without any alteration of the data. + * \param [out] res the result is put at the end of the vector without any alteration of the data. */ -void MEDCouplingUMesh::SimplifyPolyhedronCell(double eps, const DataArrayDouble *coords, const int *begin, const int *end, std::vector& res) throw(INTERP_KERNEL::Exception) +void MEDCouplingUMesh::SimplifyPolyhedronCell(double eps, const DataArrayDouble *coords, const int *begin, const int *end, DataArrayInt *res) throw(INTERP_KERNEL::Exception) { int nbFaces=std::count(begin+1,end,-1)+1; MEDCouplingAutoRefCountObjectPtr v=DataArrayDouble::New(); v->alloc(nbFaces,3); @@ -6244,7 +6219,7 @@ void MEDCouplingUMesh::SimplifyPolyhedronCell(double eps, const DataArrayDouble const int *comm1Ptr=comm1->getConstPointer(); const int *commI1Ptr=commI1->getConstPointer(); int nbOfGrps1=commI1Auto->getNumberOfTuples()-1; - res.push_back((int)INTERP_KERNEL::NORM_POLYHED); + res->pushBackSilent((int)INTERP_KERNEL::NORM_POLYHED); // MEDCouplingAutoRefCountObjectPtr mm=MEDCouplingUMesh::New("",3); mm->setCoords(const_cast(coords)); mm->allocateCells(1); mm->insertNextCell(INTERP_KERNEL::NORM_POLYHED,(int)std::distance(begin+1,end),begin+1); @@ -6264,8 +6239,8 @@ void MEDCouplingUMesh::SimplifyPolyhedronCell(double eps, const DataArrayDouble { if(commI2Ptr[j+1]-commI2Ptr[j]<=1) { - res.insert(res.end(),begin,end); - res.push_back(-1); + res->insertAtTheEnd(begin,end); + res->pushBackSilent(-1); } else { @@ -6295,13 +6270,13 @@ void MEDCouplingUMesh::SimplifyPolyhedronCell(double eps, const DataArrayDouble { int l=0; for(const int *work=conn4+connI4[k]+1;work!=conn4+connI4[k+1];work++,l++) - res.push_back(idsNodePtr[*work]); - res.push_back(-1); + res->pushBackSilent(idsNodePtr[*work]); + res->pushBackSilent(-1); } } } } - res.pop_back(); + res->popBackSilent(); } /*! @@ -6627,8 +6602,8 @@ MEDCouplingUMesh *MEDCouplingUMesh::Intersect2DMeshes(const MEDCouplingUMesh *m1 std::vector< std::vector > intersectEdge2; BuildIntersectEdges(m1Desc,m2Desc,addCoo,subDiv2,intersectEdge2); subDiv2.clear(); dd5=0; dd6=0; - std::vector cr,crI; - std::vector cNb1,cNb2; + std::vector cr,crI; //no DataArrayInt because interface with Geometric2D + std::vector cNb1,cNb2; //no DataArrayInt because interface with Geometric2D BuildIntersecting2DCellsFromEdges(eps,m1,desc1->getConstPointer(),descIndx1->getConstPointer(),intersectEdge1,colinear2,m2,desc2->getConstPointer(),descIndx2->getConstPointer(),intersectEdge2,addCoo, /* outputs -> */addCoordsQuadratic,cr,crI,cNb1,cNb2); // @@ -6933,7 +6908,7 @@ void MEDCouplingUMesh::AssemblyForSplitFrom3DCurve(const std::vector& cut3D */ void MEDCouplingUMesh::assemblyForSplitFrom3DSurf(const std::vector< std::pair >& cut3DSurf, const int *desc, const int *descIndx, - std::vector& nodalRes, std::vector& nodalResIndx, std::vector& cellIds) const throw(INTERP_KERNEL::Exception) + DataArrayInt *nodalRes, DataArrayInt *nodalResIndx, DataArrayInt *cellIds) const throw(INTERP_KERNEL::Exception) { checkFullyDefined(); if(getMeshDimension()!=3 || getSpaceDimension()!=3) @@ -6999,9 +6974,9 @@ void MEDCouplingUMesh::assemblyForSplitFrom3DSurf(const std::vector< std::pair3) { - nodalRes.insert(nodalRes.end(),conn.begin(),conn.end()); - nodalResIndx.push_back((int)nodalRes.size()); - cellIds.push_back(i); + nodalRes->insertAtTheEnd(conn.begin(),conn.end()); + nodalResIndx->pushBackSilent(nodalRes->getNumberOfTuples()); + cellIds->pushBackSilent(i); } } } @@ -7015,7 +6990,7 @@ void MEDCouplingUMesh::assemblyForSplitFrom3DSurf(const std::vector< std::pair& nodalConnecOut) throw(INTERP_KERNEL::Exception) +bool MEDCouplingUMesh::BuildConvexEnvelopOf2DCellJarvis(const double *coords, const int *nodalConnBg, const int *nodalConnEnd, DataArrayInt *nodalConnecOut) throw(INTERP_KERNEL::Exception) { std::size_t sz=std::distance(nodalConnBg,nodalConnEnd); if(sz>=4) @@ -7081,18 +7056,18 @@ bool MEDCouplingUMesh::BuildConvexEnvelopOf2DCellJarvis(const double *coords, co std::copy(nodalConnBg+1,nodalConnEnd,it); if(std::search(tmp3.begin(),tmp3.end(),tmpOut.begin(),tmpOut.end())!=tmp3.end()) { - nodalConnecOut.insert(nodalConnecOut.end(),nodalConnBg,nodalConnEnd); + nodalConnecOut->insertAtTheEnd(nodalConnBg,nodalConnEnd); return false; } if(std::search(tmp3.rbegin(),tmp3.rend(),tmpOut.begin(),tmpOut.end())!=tmp3.rend()) { - nodalConnecOut.insert(nodalConnecOut.end(),nodalConnBg,nodalConnEnd); + nodalConnecOut->insertAtTheEnd(nodalConnBg,nodalConnEnd); return false; } else { - nodalConnecOut.push_back((int)INTERP_KERNEL::NORM_POLYGON); - nodalConnecOut.insert(nodalConnecOut.end(),tmpOut.begin(),tmpOut.end()); + nodalConnecOut->pushBackSilent((int)INTERP_KERNEL::NORM_POLYGON); + nodalConnecOut->insertAtTheEnd(tmpOut.begin(),tmpOut.end()); return true; } } @@ -7126,7 +7101,7 @@ bool MEDCouplingUMesh::RemoveIdsFromIndexedArrays(const int *idsToRemoveBg, cons *arrIPtr++=0; int previousArrI=0; const int *arrPtr=arr->getConstPointer(); - std::vector arrOut; + std::vector arrOut;//no utility to switch to DataArrayInt because copy always needed for(int i=0;ioffsetForRemoval) diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index e9fdd8005..dc7924915 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -109,7 +109,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *zipCoordsTraducer() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *zipConnectivityTraducer(int compType, int startCellId=0) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void findCommonCells(int compType, int startCellId, std::vector& commonCells, std::vector& commonCellsI) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void findCommonCells(int compType, int startCellId, DataArrayInt *& commonCellsArr, DataArrayInt *& commonCellsIArr) const 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); @@ -161,7 +161,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void getCellsContainingPoints(const double *pos, int nbOfPoints, double eps, std::vector& elts, std::vector& eltsIndex) const; MEDCOUPLING_EXPORT void checkButterflyCells(std::vector& cells, double eps=1e-12) const; MEDCOUPLING_EXPORT DataArrayInt *convexEnvelop2D() throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void findAndCorrectBadOriented3DExtrudedCells(std::vector& cells) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *findAndCorrectBadOriented3DExtrudedCells() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void getBoundingBoxForBBTree(std::vector& bbox) const; MEDCOUPLING_EXPORT MEDCouplingUMesh *buildExtrudedMesh(const MEDCouplingUMesh *mesh1D, int policy); MEDCOUPLING_EXPORT bool isFullyQuadratic() const; @@ -215,11 +215,11 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static void MergeNodesOnUMeshesSharingSameCoords(const std::vector& meshes, double eps) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static bool IsPolygonWellOriented(bool isQuadratic, const double *vec, const int *begin, const int *end, const double *coords); MEDCOUPLING_EXPORT static bool IsPolyhedronWellOriented(const int *begin, const int *end, const double *coords); - MEDCOUPLING_EXPORT static void SimplifyPolyhedronCell(double eps, const DataArrayDouble *coords, const int *begin, const int *end, std::vector& res) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static void SimplifyPolyhedronCell(double eps, const DataArrayDouble *coords, const int *begin, const int *end, DataArrayInt *res) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static void ComputeVecAndPtOfFace(double eps, const double *coords, const int *begin, const int *end, double *v, double *p) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static void TryToCorrectPolyhedronOrientation(int *begin, int *end, const double *coords) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static MEDCouplingUMesh *Intersect2DMeshes(const MEDCouplingUMesh *m1, const MEDCouplingUMesh *m2, double eps, DataArrayInt *&cellNb1, DataArrayInt *&cellNb2) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT static bool BuildConvexEnvelopOf2DCellJarvis(const double *coords, const int *nodalConnBg, const int *nodalConnEnd, std::vector& nodalConnecOut) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static bool BuildConvexEnvelopOf2DCellJarvis(const double *coords, const int *nodalConnBg, const int *nodalConnEnd, DataArrayInt *nodalConnecOut) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static bool RemoveIdsFromIndexedArrays(const int *idsToRemoveBg, const int *idsToRemoveEnd, DataArrayInt *arr, DataArrayInt *arrIndx, int offsetForRemoval=0) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static void ExtractFromIndexedArrays(const int *idsOfSelectBg, const int *idsOfSelectEnd, const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn, DataArrayInt* &arrOut, DataArrayInt* &arrIndexOut) throw(INTERP_KERNEL::Exception); @@ -245,14 +245,14 @@ namespace ParaMEDMEM DataArrayInt *simplexizePol0() throw(INTERP_KERNEL::Exception); DataArrayInt *simplexizePol1() throw(INTERP_KERNEL::Exception); void subDivide2DMesh(const int *nodeSubdived, const int *nodeIndxSubdived, const int *desc, const int *descIndex) throw(INTERP_KERNEL::Exception); - void fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, std::vector& cellIdsKept) const; + void fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const; void split3DCurveWithPlane(const double *origin, const double *vec, double eps, std::vector& cut3DCurve) throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *buildExtrudedMeshFromThisLowLev(int nbOfNodesOf1Lev, bool isQuad) const; DataArrayDouble *fillExtCoordsUsingTranslation(const MEDCouplingUMesh *mesh1D, bool isQuad) const; DataArrayDouble *fillExtCoordsUsingTranslAndAutoRotation(const MEDCouplingUMesh *mesh1D, bool isQuad) 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); - bool areCellsEqualInPool(const std::vector& candidates, int compType, std::vector& result) const; + bool areCellsEqualInPool(const std::vector& candidates, int compType, DataArrayInt *result) const; MEDCouplingUMesh *buildPartOfMySelfKeepCoords(const int *begin, const int *end) const; MEDCouplingUMesh *buildPartOfMySelfKeepCoords2(int start, int end, int step) const; template @@ -280,7 +280,7 @@ namespace ParaMEDMEM const int *nodal3DCurve, const int *nodalIndx3DCurve, const int *desc, const int *descIndx, std::vector< std::pair >& cut3DSurf) throw(INTERP_KERNEL::Exception); void assemblyForSplitFrom3DSurf(const std::vector< std::pair >& cut3DSurf, - const int *desc, const int *descIndx, std::vector& nodalRes, std::vector& nodalResIndx, std::vector& cellIds) const throw(INTERP_KERNEL::Exception); + const int *desc, const int *descIndx, DataArrayInt *nodalRes, DataArrayInt *nodalResIndx, DataArrayInt *cellIds) const throw(INTERP_KERNEL::Exception); public: MEDCOUPLING_EXPORT static DataArrayInt *ComputeRangesFromTypeDistribution(const std::vector& code) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static const int N_MEDMEM_ORDER=24; diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx index fcc86c4ac..230547686 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx @@ -1256,24 +1256,26 @@ void MEDCouplingBasicsTest3::testGetNodeIdsNearPoints1() mesh->setCoords(tmp2); tmp2->decrRef(); const double pts[6]={0.2,0.2,0.1,0.3,-0.3,0.7}; - std::vector c=mesh->getNodeIdsNearPoint(pts,1e-7); - CPPUNIT_ASSERT_EQUAL(3,(int)c.size()); - CPPUNIT_ASSERT_EQUAL(4,c[0]); - CPPUNIT_ASSERT_EQUAL(9,c[1]); - CPPUNIT_ASSERT_EQUAL(11,c[2]); - c.clear(); - std::vector cI; + DataArrayInt *c=mesh->getNodeIdsNearPoint(pts,1e-7); + CPPUNIT_ASSERT_EQUAL(3,c->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(4,c->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(9,c->getIJ(1,0)); + CPPUNIT_ASSERT_EQUAL(11,c->getIJ(2,0)); + c->decrRef(); + DataArrayInt *cI=0; mesh->getNodeIdsNearPoints(pts,3,1e-7,c,cI); - CPPUNIT_ASSERT_EQUAL(4,(int)cI.size()); - CPPUNIT_ASSERT_EQUAL(4,(int)c.size()); - CPPUNIT_ASSERT_EQUAL(4,c[0]); - CPPUNIT_ASSERT_EQUAL(9,c[1]); - CPPUNIT_ASSERT_EQUAL(11,c[2]); - CPPUNIT_ASSERT_EQUAL(6,c[3]); - CPPUNIT_ASSERT_EQUAL(0,cI[0]); - CPPUNIT_ASSERT_EQUAL(3,cI[1]); - CPPUNIT_ASSERT_EQUAL(3,cI[2]); - CPPUNIT_ASSERT_EQUAL(4,cI[3]); + CPPUNIT_ASSERT_EQUAL(4,cI->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(4,c->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(4,c->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(9,c->getIJ(1,0)); + CPPUNIT_ASSERT_EQUAL(11,c->getIJ(2,0)); + CPPUNIT_ASSERT_EQUAL(6,c->getIJ(3,0)); + CPPUNIT_ASSERT_EQUAL(0,cI->getIJ(0,0)); + CPPUNIT_ASSERT_EQUAL(3,cI->getIJ(1,0)); + CPPUNIT_ASSERT_EQUAL(3,cI->getIJ(2,0)); + CPPUNIT_ASSERT_EQUAL(4,cI->getIJ(3,0)); + c->decrRef(); + cI->decrRef(); mesh->decrRef(); } diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx index fe80e977c..3a9128e81 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx @@ -1589,11 +1589,11 @@ void MEDCouplingBasicsTest4::testFindAndCorrectBadOriented3DExtrudedCells1() m->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+48); m->finishInsertingCells(); // - std::vector v; - m->findAndCorrectBadOriented3DExtrudedCells(v); - CPPUNIT_ASSERT_EQUAL(4,(int)v.size()); - CPPUNIT_ASSERT(std::equal(v.begin(),v.end(),invalidCells)); + DataArrayInt *v=m->findAndCorrectBadOriented3DExtrudedCells(); + CPPUNIT_ASSERT_EQUAL(4,v->getNumberOfTuples()); + CPPUNIT_ASSERT(std::equal(v->begin(),v->end(),invalidCells)); CPPUNIT_ASSERT(std::equal(connExp,connExp+64,m->getNodalConnectivity()->getConstPointer())); + v->decrRef(); // m->decrRef(); } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 78d83f7d6..c467ed71e 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -10540,6 +10540,11 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(ff.isEqual(DataArrayDouble([4.]),1e-12)) self.assertEqual(ff.getNumberOfTuples(),1) self.assertEqual(ff.getNbOfElemAllocated(),1) + d=DataArrayDouble() + d.pushBackSilent(4.44) + d.pushBackSilent(5.55) + d.pushBackSilent(6.66) + self.assertTrue(d.isEqual(DataArrayDouble([4.44,5.55,6.66]),1e-12)) # d=DataArrayInt(0,1) for i in xrange(8): @@ -10569,6 +10574,11 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(ff.isEqual(DataArrayInt([4]))) self.assertEqual(ff.getNumberOfTuples(),1) self.assertEqual(ff.getNbOfElemAllocated(),1) + d=DataArrayInt() + d.pushBackSilent(444) + d.pushBackSilent(555) + d.pushBackSilent(666) + self.assertTrue(d.isEqual(DataArrayInt([444,555,666]))) pass def setUp(self): diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 28f407143..99b2c1f6e 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -294,6 +294,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingUMesh::buildPartOrthogonalField; %newobject ParaMEDMEM::MEDCouplingUMesh::keepCellIdsByType; %newobject ParaMEDMEM::MEDCouplingUMesh::Build0DMeshFromCoords; +%newobject ParaMEDMEM::MEDCouplingUMesh::findAndCorrectBadOriented3DExtrudedCells; %newobject ParaMEDMEM::MEDCouplingUMesh::findCellIdsOnBoundary; %newobject ParaMEDMEM::MEDCouplingUMesh::computeSkin; %newobject ParaMEDMEM::MEDCouplingUMesh::getCellIdsLyingOnNodes; @@ -1109,6 +1110,7 @@ namespace ParaMEDMEM std::copy(nodes.begin(),nodes.end(),ret->getPointer()); return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); } + PyObject *getNodeIdsNearPoint(PyObject *pt, double eps) const throw(INTERP_KERNEL::Exception) { double val; @@ -1119,16 +1121,13 @@ namespace ParaMEDMEM int spaceDim=self->getSpaceDimension(); const char msg[]="Python wrap of MEDCouplingPointSet::getNodeIdsNearPoint : "; const double *pos=convertObjToPossibleCpp5_Safe(pt,sw,val,a,aa,bb,msg,1,spaceDim,true); - std::vector tmp=self->getNodeIdsNearPoint(pos,eps); - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc((int)tmp.size(),1); - std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + DataArrayInt *ret=self->getNodeIdsNearPoint(pos,eps); return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); } PyObject *getNodeIdsNearPoints(PyObject *pt, int nbOfNodes, double eps) const throw(INTERP_KERNEL::Exception) { - std::vector c,cI; + DataArrayInt *c=0,*cI=0; // double val; DataArrayDouble *a; @@ -1140,22 +1139,14 @@ namespace ParaMEDMEM const double *pos=convertObjToPossibleCpp5_Safe(pt,sw,val,a,aa,bb,msg,nbOfNodes,spaceDim,true); self->getNodeIdsNearPoints(pos,nbOfNodes,eps,c,cI); PyObject *ret=PyTuple_New(2); - MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); - MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); - d0->alloc(c.size(),1); - d1->alloc(cI.size(),1); - std::copy(c.begin(),c.end(),d0->getPointer()); - std::copy(cI.begin(),cI.end(),d1->getPointer()); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - d0->incrRef(); - d1->incrRef(); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(c),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cI),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } PyObject *getNodeIdsNearPoints(PyObject *pt, double eps) const throw(INTERP_KERNEL::Exception) { - std::vector c,cI; + DataArrayInt *c=0,*cI=0; int spaceDim=self->getSpaceDimension(); void *da=0; int res1=SWIG_ConvertPtr(pt,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, 0 | 0 ); @@ -1185,16 +1176,8 @@ namespace ParaMEDMEM self->getNodeIdsNearPoints(da2->getConstPointer(),size,eps,c,cI); } PyObject *ret=PyTuple_New(2); - MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); - MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); - d0->alloc(c.size(),1); - d1->alloc(cI.size(),1); - std::copy(c.begin(),c.end(),d0->getPointer()); - std::copy(cI.begin(),cI.end(),d1->getPointer()); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - d0->incrRef(); - d1->incrRef(); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(c),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cI),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } @@ -1431,6 +1414,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getSkewField() const throw(INTERP_KERNEL::Exception); DataArrayInt *convexEnvelop2D() throw(INTERP_KERNEL::Exception); std::string cppRepr() const throw(INTERP_KERNEL::Exception); + DataArrayInt *findAndCorrectBadOriented3DExtrudedCells() throw(INTERP_KERNEL::Exception); static MEDCouplingUMesh *Build0DMeshFromCoords(DataArrayDouble *da) throw(INTERP_KERNEL::Exception); static MEDCouplingUMesh *MergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); static MEDCouplingUMesh *MergeUMeshesOnSameCoords(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); @@ -1679,14 +1663,11 @@ namespace ParaMEDMEM PyObject *findCommonCells(int compType, int startCellId=0) const throw(INTERP_KERNEL::Exception) { - std::vector v0,v1; + DataArrayInt *v0=0,*v1=0; self->findCommonCells(compType,startCellId,v0,v1); - DataArrayInt *v0a=DataArrayInt::New(),*v1a=DataArrayInt::New(); - v0a->alloc((int)v0.size(),1); std::copy(v0.begin(),v0.end(),v0a->getPointer()); - v1a->alloc((int)v1.size(),1); std::copy(v1.begin(),v1.end(),v1a->getPointer()); PyObject *res = PyList_New(2); - PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(v0a),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyList_SetItem(res,1,SWIG_NewPointerObj(SWIG_as_voidptr(v1a),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(v0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(res,1,SWIG_NewPointerObj(SWIG_as_voidptr(v1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return res; } @@ -2087,16 +2068,6 @@ namespace ParaMEDMEM return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); } - PyObject *findAndCorrectBadOriented3DExtrudedCells() throw(INTERP_KERNEL::Exception) - { - std::vector cells; - self->findAndCorrectBadOriented3DExtrudedCells(cells); - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc((int)cells.size(),1); - std::copy(cells.begin(),cells.end(),ret->getPointer()); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } - PyObject *getFastAveragePlaneOfThis() const throw(INTERP_KERNEL::Exception) { double vec[3]; @@ -3260,14 +3231,11 @@ namespace ParaMEDMEM const char msg[]="Python wrap of DataArrayDouble::computeTupleIdsNearTuples : "; const double *pos=convertObjToPossibleCpp5_Safe2(pt,sw,val,a,aa,bb,msg,nbComp,true,nbTuples); MEDCouplingAutoRefCountObjectPtr inpu=DataArrayDouble::New(); inpu->useArray(pos,false,CPP_DEALLOC,nbTuples,nbComp); - std::vector c,cI; + DataArrayInt *c=0,*cI=0; self->computeTupleIdsNearTuples(inpu,eps,c,cI); - DataArrayInt *ret0=DataArrayInt::New(),*ret1=DataArrayInt::New(); - ret0->alloc((int)c.size(),1); std::copy(c.begin(),c.end(),ret0->getPointer()); - ret1->alloc((int)cI.size(),1); std::copy(cI.begin(),cI.end(),ret1->getPointer()); PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(c),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cI),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } @@ -4190,20 +4158,12 @@ namespace ParaMEDMEM PyObject *computeTupleIdsNearTuples(const DataArrayDouble *other, double eps) { - std::vector c,cI; + DataArrayInt *c=0,*cI=0; // self->computeTupleIdsNearTuples(other,eps,c,cI); PyObject *ret=PyTuple_New(2); - MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); - MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); - d0->alloc(c.size(),1); - d1->alloc(cI.size(),1); - std::copy(c.begin(),c.end(),d0->getPointer()); - std::copy(cI.begin(),cI.end(),d1->getPointer()); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - d0->incrRef(); - d1->incrRef(); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(c),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cI),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } };