From 90009ac7ae46507d437a546fb362f1de0b4c8bf7 Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 3 Jan 2013 07:40:15 +0000 Subject: [PATCH] API modif of getCellsInBoundingBox to avoid copies. --- src/MEDCoupling/MEDCouplingPointSet.hxx | 4 +-- src/MEDCoupling/MEDCouplingUMesh.cxx | 43 +++++++++++------------- src/MEDCoupling/MEDCouplingUMesh.hxx | 4 +-- src/MEDCoupling/MEDCouplingUMeshDesc.cxx | 19 ++++++----- src/MEDCoupling/MEDCouplingUMeshDesc.hxx | 4 +-- src/MEDCoupling_Swig/MEDCouplingCommon.i | 13 +++---- src/ParaMEDMEM/ElementLocator.cxx | 8 ++--- src/ParaMEDMEM/OverlapElementLocator.cxx | 5 ++- 8 files changed, 45 insertions(+), 55 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingPointSet.hxx b/src/MEDCoupling/MEDCouplingPointSet.hxx index e06c91e21..400e47b1d 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.hxx +++ b/src/MEDCoupling/MEDCouplingPointSet.hxx @@ -110,8 +110,8 @@ namespace ParaMEDMEM void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const; void unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector& littleStrings); - virtual void getCellsInBoundingBox(const double *bbox, double eps, std::vector& elems) const = 0; - virtual void getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps, std::vector& elems) = 0; + virtual DataArrayInt *getCellsInBoundingBox(const double *bbox, double eps) const = 0; + virtual DataArrayInt *getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps) = 0; virtual DataArrayInt *zipCoordsTraducer() = 0; protected: void checkCoherency() const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index d05f0a011..7e881423b 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -2325,15 +2325,16 @@ void MEDCouplingUMesh::renumberCells(const int *old2NewBg, bool check) throw(INT * Warning 'elems' is incremented during the call so if elems is not empty before call returned elements will be * added in 'elems' parameter. */ -void MEDCouplingUMesh::getCellsInBoundingBox(const double *bbox, double eps, std::vector& elems) const +DataArrayInt *MEDCouplingUMesh::getCellsInBoundingBox(const double *bbox, double eps) const { + MEDCouplingAutoRefCountObjectPtr elems=DataArrayInt::New(); elems->alloc(0,1); if(getMeshDimension()==-1) { - elems.push_back(0); - return; + elems->pushBackSilent(0); + return elems.retn(); } int dim=getSpaceDimension(); - double* elem_bb=new double[2*dim]; + INTERP_KERNEL::AutoPtr elem_bb=new double[2*dim]; const int* conn = getNodalConnectivity()->getConstPointer(); const int* conn_index= getNodalConnectivityIndex()->getConstPointer(); const double* coords = getCoords()->getConstPointer(); @@ -2365,11 +2366,9 @@ void MEDCouplingUMesh::getCellsInBoundingBox(const double *bbox, double eps, std } } if (intersectsBoundingBox(elem_bb, bbox, dim, eps)) - { - elems.push_back(ielem); - } + elems->pushBackSilent(ielem); } - delete [] elem_bb; + return elems.retn(); } /*! @@ -2377,15 +2376,16 @@ void MEDCouplingUMesh::getCellsInBoundingBox(const double *bbox, double eps, std * Warning 'elems' is incremented during the call so if elems is not empty before call returned elements will be * added in 'elems' parameter. */ -void MEDCouplingUMesh::getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps, std::vector& elems) +DataArrayInt *MEDCouplingUMesh::getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps) { + MEDCouplingAutoRefCountObjectPtr elems=DataArrayInt::New(); elems->alloc(0,1); if(getMeshDimension()==-1) { - elems.push_back(0); - return; + elems->pushBackSilent(0); + return elems.retn(); } int dim=getSpaceDimension(); - double* elem_bb=new double[2*dim]; + INTERP_KERNEL::AutoPtr elem_bb=new double[2*dim]; const int* conn = getNodalConnectivity()->getConstPointer(); const int* conn_index= getNodalConnectivityIndex()->getConstPointer(); const double* coords = getCoords()->getConstPointer(); @@ -2416,12 +2416,10 @@ void MEDCouplingUMesh::getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundi } } } - if (intersectsBoundingBox(bbox, elem_bb, dim, eps)) - { - elems.push_back(ielem); - } + if(intersectsBoundingBox(bbox, elem_bb, dim, eps)) + elems->pushBackSilent(ielem); } - delete [] elem_bb; + return elems.retn(); } /*! @@ -3379,7 +3377,7 @@ DataArrayInt *MEDCouplingUMesh::getCellIdsCrossingPlane(const double *origin, co double vec2[3]; vec2[0]=vec[1]; vec2[1]=-vec[0]; vec2[2]=0.;//vec2 is the result of cross product of vec with (0,0,1) double angle=acos(vec[2]/normm); - std::vector cellIds; + MEDCouplingAutoRefCountObjectPtr cellIds; double bbox[6]; if(angle>eps) { @@ -3389,18 +3387,15 @@ DataArrayInt *MEDCouplingUMesh::getCellIdsCrossingPlane(const double *origin, co mw->setCoords(coo); mw->getBoundingBox(bbox); bbox[4]=origin[2]-eps; bbox[5]=origin[2]+eps; - mw->getCellsInBoundingBox(bbox,eps,cellIds); + cellIds=mw->getCellsInBoundingBox(bbox,eps); } else { getBoundingBox(bbox); bbox[4]=origin[2]-eps; bbox[5]=origin[2]+eps; - getCellsInBoundingBox(bbox,eps,cellIds); + cellIds=getCellsInBoundingBox(bbox,eps); } - MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); - ret->alloc((int)cellIds.size(),1); - std::copy(cellIds.begin(),cellIds.end(),ret->getPointer()); - return ret.retn(); + return cellIds.retn(); } /*! diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index dc7924915..68845a62c 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -143,8 +143,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void shiftNodeNumbersInConn(int delta) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void duplicateNodesInConn(const int *nodeIdsToDuplicateBg, const int *nodeIdsToDuplicateEnd, int offset) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void renumberCells(const int *old2NewBg, bool check=true) throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT void getCellsInBoundingBox(const double *bbox, double eps, std::vector& elems) const; - MEDCOUPLING_EXPORT void getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps, std::vector& elems); + MEDCOUPLING_EXPORT DataArrayInt *getCellsInBoundingBox(const double *bbox, double eps) const; + MEDCOUPLING_EXPORT DataArrayInt *getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps); MEDCOUPLING_EXPORT MEDCouplingFieldDouble *getMeasureField(bool isAbs) const; MEDCOUPLING_EXPORT DataArrayDouble *getPartMeasureField(bool isAbs, const int *begin, const int *end) const; MEDCOUPLING_EXPORT MEDCouplingFieldDouble *getMeasureFieldOnNode(bool isAbs) const; diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx index 22905de85..eec0e4bc7 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.cxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.cxx @@ -21,6 +21,7 @@ #include "MEDCouplingUMeshDesc.hxx" #include "CellModel.hxx" #include "MEDCouplingMemArray.hxx" +#include "MEDCouplingAutoRefCountObjectPtr.hxx" #include #include @@ -266,8 +267,9 @@ void MEDCouplingUMeshDesc::unserialization(const std::vector& tinyInfoD, setMeshDimension(tinyInfo[2]); } -void MEDCouplingUMeshDesc::getCellsInBoundingBox(const double *bbox, double eps, std::vector& elems) const +DataArrayInt *MEDCouplingUMeshDesc::getCellsInBoundingBox(const double *bbox, double eps) const { + MEDCouplingAutoRefCountObjectPtr elems=DataArrayInt::New(); elems->alloc(0,1); int dim=getSpaceDimension(); double* elem_bb=new double[2*dim]; const int* conn = _desc_connec->getConstPointer(); @@ -303,16 +305,16 @@ void MEDCouplingUMeshDesc::getCellsInBoundingBox(const double *bbox, double eps, } } } - if (intersectsBoundingBox(elem_bb, bbox, dim, eps)) - { - elems.push_back(ielem); - } + if(intersectsBoundingBox(elem_bb, bbox, dim, eps)) + elems->pushBackSilent(ielem); } delete [] elem_bb; + return elems.retn(); } -void MEDCouplingUMeshDesc::getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox &bbox, double eps, std::vector& elems) +DataArrayInt *MEDCouplingUMeshDesc::getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox &bbox, double eps) { + MEDCouplingAutoRefCountObjectPtr elems=DataArrayInt::New(); elems->alloc(0,1); int dim=getSpaceDimension(); double* elem_bb=new double[2*dim]; const int* conn = _desc_connec->getConstPointer(); @@ -349,11 +351,10 @@ void MEDCouplingUMeshDesc::getCellsInBoundingBox(const INTERP_KERNEL::DirectedBo } } if (intersectsBoundingBox(bbox, elem_bb, dim, eps)) - { - elems.push_back(ielem); - } + elems->pushBackSilent(ielem); } delete [] elem_bb; + return elems.retn(); } DataArrayInt *MEDCouplingUMeshDesc::mergeNodes(double precision, bool& areNodesMerged, int& newNbOfNodes) diff --git a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx index 37e27e1f3..490aae5a3 100644 --- a/src/MEDCoupling/MEDCouplingUMeshDesc.hxx +++ b/src/MEDCoupling/MEDCouplingUMeshDesc.hxx @@ -65,8 +65,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const; MEDCOUPLING_EXPORT void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const; MEDCOUPLING_EXPORT void unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector& littleStrings); - MEDCOUPLING_EXPORT void getCellsInBoundingBox(const double *bbox, double eps, std::vector& elems) const; - MEDCOUPLING_EXPORT void getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox &bbox, double eps, std::vector& elems); + MEDCOUPLING_EXPORT DataArrayInt *getCellsInBoundingBox(const double *bbox, double eps) const; + MEDCOUPLING_EXPORT DataArrayInt *getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox &bbox, double eps); MEDCOUPLING_EXPORT DataArrayInt *mergeNodes(double precision, bool& areNodesMerged, int& newNbOfNodes); MEDCOUPLING_EXPORT DataArrayInt *mergeNodes2(double precision, bool& areNodesMerged, int& newNbOfNodes); MEDCOUPLING_EXPORT void tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 99b2c1f6e..b56086f28 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -256,6 +256,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingMesh::buildUnstructured; %newobject ParaMEDMEM::MEDCouplingMesh::MergeMeshes; %newobject ParaMEDMEM::MEDCouplingPointSet::zipCoordsTraducer; +%newobject ParaMEDMEM::MEDCouplingPointSet::getCellsInBoundingBox; %newobject ParaMEDMEM::MEDCouplingPointSet::findBoundaryNodes; %newobject ParaMEDMEM::MEDCouplingPointSet::buildBoundaryMesh; %newobject ParaMEDMEM::MEDCouplingPointSet::MergeNodesArray; @@ -931,7 +932,7 @@ namespace ParaMEDMEM void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const throw(INTERP_KERNEL::Exception); void unserialization(const std::vector& tinyInfoD, const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector& littleStrings) throw(INTERP_KERNEL::Exception); - virtual void getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps, std::vector& elems) throw(INTERP_KERNEL::Exception); + virtual DataArrayInt *getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps) throw(INTERP_KERNEL::Exception); virtual DataArrayInt *zipCoordsTraducer() throw(INTERP_KERNEL::Exception); virtual DataArrayInt *findBoundaryNodes() const; %extend @@ -1183,9 +1184,6 @@ namespace ParaMEDMEM PyObject *getCellsInBoundingBox(PyObject *bbox, double eps) const throw(INTERP_KERNEL::Exception) { - std::vector elems; - // - // double val; DataArrayDouble *a; DataArrayDoubleTuple *aa; @@ -1195,11 +1193,8 @@ namespace ParaMEDMEM const char msg[]="Python wrap of MEDCouplingPointSet::getCellsInBoundingBox : "; const double *tmp=convertObjToPossibleCpp5_Safe(bbox,sw,val,a,aa,bb,msg,spaceDim,2,true); // - self->getCellsInBoundingBox(tmp,eps,elems); - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc((int)elems.size(),1); - std::copy(elems.begin(),elems.end(),ret->getPointer()); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + DataArrayInt *elems=self->getCellsInBoundingBox(tmp,eps); + return SWIG_NewPointerObj(SWIG_as_voidptr(elems),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); } void duplicateNodesInCoords(PyObject *li) throw(INTERP_KERNEL::Exception) diff --git a/src/ParaMEDMEM/ElementLocator.cxx b/src/ParaMEDMEM/ElementLocator.cxx index 8e15db02d..9709745d2 100644 --- a/src/ParaMEDMEM/ElementLocator.cxx +++ b/src/ParaMEDMEM/ElementLocator.cxx @@ -88,19 +88,19 @@ namespace ParaMEDMEM if (find(_distant_proc_ids.begin(), _distant_proc_ids.end(),rank)==_distant_proc_ids.end()) return; - vector elems; + MEDCouplingAutoRefCountObjectPtr elems; #ifdef USE_DIRECTED_BB INTERP_KERNEL::DirectedBoundingBox dbb; double* distant_bb = _domain_bounding_boxes+rank*dbb.dataSize(_local_cell_mesh_space_dim); dbb.setData(distant_bb); - _local_cell_mesh->getCellsInBoundingBox(dbb,getBoundingBoxAdjustment(),elems); + elems=_local_cell_mesh->getCellsInBoundingBox(dbb,getBoundingBoxAdjustment()); #else double* distant_bb = _domain_bounding_boxes+rank*2*_local_cell_mesh_space_dim; - _local_cell_mesh->getCellsInBoundingBox(distant_bb,getBoundingBoxAdjustment(),elems); + elems=_local_cell_mesh->getCellsInBoundingBox(distant_bb,getBoundingBoxAdjustment()); #endif DataArrayInt *distant_ids_send; - MEDCouplingPointSet *send_mesh = (MEDCouplingPointSet *)_local_para_field.getField()->buildSubMeshData(&elems[0],&elems[elems.size()],distant_ids_send); + MEDCouplingPointSet *send_mesh = (MEDCouplingPointSet *)_local_para_field.getField()->buildSubMeshData(elems->begin(),elems->end(),distant_ids_send); _exchangeMesh(send_mesh, distant_mesh, idistantrank, distant_ids_send, distant_ids); distant_ids_send->decrRef(); diff --git a/src/ParaMEDMEM/OverlapElementLocator.cxx b/src/ParaMEDMEM/OverlapElementLocator.cxx index 417c50e0f..ab27b9273 100644 --- a/src/ParaMEDMEM/OverlapElementLocator.cxx +++ b/src/ParaMEDMEM/OverlapElementLocator.cxx @@ -270,7 +270,6 @@ namespace ParaMEDMEM */ void OverlapElementLocator::sendLocalMeshTo(int procId, bool sourceOrTarget, OverlapInterpolationMatrix& matrix) const { - vector elems; //int myProcId=_group.myRank(); const double *distant_bb=0; MEDCouplingPointSet *local_mesh=0; @@ -287,9 +286,9 @@ namespace ParaMEDMEM local_mesh=_local_target_mesh; field=_local_target_field; } - local_mesh->getCellsInBoundingBox(distant_bb,getBoundingBoxAdjustment(),elems); + MEDCouplingAutoRefCountObjectPtr elems=local_mesh->getCellsInBoundingBox(distant_bb,getBoundingBoxAdjustment()); DataArrayInt *idsToSend; - MEDCouplingPointSet *send_mesh=static_cast(field->getField()->buildSubMeshData(&elems[0],&elems[elems.size()],idsToSend)); + MEDCouplingPointSet *send_mesh=static_cast(field->getField()->buildSubMeshData(elems->begin(),elems->end(),idsToSend)); if(sourceOrTarget) matrix.keepTracksOfSourceIds(procId,idsToSend);//Case#1 in Step2 of main algorithm. else -- 2.39.2