From: ageay Date: Mon, 29 Nov 2010 16:34:43 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4f7973f4305d561b1e1b14fe83643d49f8d10470;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDCoupling/MEDCouplingPointSet.cxx b/src/MEDCoupling/MEDCouplingPointSet.cxx index 87964cbdf..4b8a17cc0 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.cxx +++ b/src/MEDCoupling/MEDCouplingPointSet.cxx @@ -209,7 +209,7 @@ void MEDCouplingPointSet::findCommonNodes(int limitNodeId, double prec, DataArra findCommonNodesAlg<1>(bbox,nbNodesOld,limitNodeId,prec,c,cI); break; default: - throw INTERP_KERNEL::Exception("Unexpected spacedim of coords. Must be 1,2 or 3."); + throw INTERP_KERNEL::Exception("Unexpected spacedim of coords. Must be 1, 2 or 3."); } commIndex->alloc(cI.size(),1); std::copy(cI.begin(),cI.end(),commIndex->getPointer()); @@ -217,6 +217,55 @@ void MEDCouplingPointSet::findCommonNodes(int limitNodeId, double prec, DataArra std::copy(c.begin(),c.end(),comm->getPointer()); } +std::vector MEDCouplingPointSet::getNodeIdsNearPoint(const double *pos, double eps) const throw(INTERP_KERNEL::Exception) +{ + std::vector c,cI; + getNodeIdsNearPoints(pos,1,eps,c,cI); + return c; +} + +/*! + * Given a point given by its position 'pos' this method finds the set of node ids that are a a distance lower than eps. + * Position 'pos' is expected to be of size getSpaceDimension(). 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) +{ + if(!_coords) + throw INTERP_KERNEL::Exception("MEDCouplingPointSet::getNodeIdsNearPoint : no coordiantes set !"); + const double *coordsPtr=_coords->getConstPointer(); + if(!coordsPtr) + throw INTERP_KERNEL::Exception("MEDCouplingPointSet::getNodeIdsNearPoint : coordiante array set but no data inside it !"); + int spaceDim=getSpaceDimension(); + int nbNodes=getNumberOfNodes(); + std::vector bbox(2*nbNodes*spaceDim); + for(int i=0;i ret; + c.clear(); + cI.resize(1); cI[0]=0; + switch(spaceDim) + { + case 3: + findNodeIdsNearPointAlg<3>(bbox,pos,nbOfNodes,eps,c,cI); + break; + case 2: + findNodeIdsNearPointAlg<2>(bbox,pos,nbOfNodes,eps,c,cI); + break; + case 1: + findNodeIdsNearPointAlg<1>(bbox,pos,nbOfNodes,eps,c,cI); + break; + default: + throw INTERP_KERNEL::Exception("Unexpected spacedim of coords for getNodeIdsNearPoint. Must be 1, 2 or 3."); + } +} + /*! * @param comm in param in the same format than one returned by findCommonNodes method. * @param commI in param in the same format than one returned by findCommonNodes method. diff --git a/src/MEDCoupling/MEDCouplingPointSet.hxx b/src/MEDCoupling/MEDCouplingPointSet.hxx index 87a4c04ec..21cb749b4 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.hxx +++ b/src/MEDCoupling/MEDCouplingPointSet.hxx @@ -55,6 +55,8 @@ namespace ParaMEDMEM bool areCoordsEqualWithoutConsideringStr(const MEDCouplingPointSet& other, double prec) const; virtual DataArrayInt *mergeNodes(double precision, bool& areNodesMerged, int& newNbOfNodes) = 0; DataArrayInt *buildPermArrayForMergeNode(int limitNodeId, double precision, 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); void findCommonNodes(int limitNodeId, double prec, DataArrayInt *&comm, DataArrayInt *&commIndex) const; DataArrayInt *buildNewNumberingFromCommonNodesFormat(const DataArrayInt *comm, const DataArrayInt *commIndex, int& newNbOfNodes) const; @@ -101,6 +103,9 @@ namespace ParaMEDMEM template void findCommonNodesAlg(std::vector& bbox, int nbNodes, int limitNodeId, double prec, std::vector& c, std::vector& cI) const; + template + void findNodeIdsNearPointAlg(std::vector& bbox, const double *pos, int nbNodes, double eps, + std::vector& c, std::vector& cI) const; protected: DataArrayDouble *_coords; }; diff --git a/src/MEDCoupling/MEDCouplingPointSet.txx b/src/MEDCoupling/MEDCouplingPointSet.txx index bae195566..658d6d9c5 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.txx +++ b/src/MEDCoupling/MEDCouplingPointSet.txx @@ -64,6 +64,32 @@ namespace ParaMEDMEM } } } + + template + void MEDCouplingPointSet::findNodeIdsNearPointAlg(std::vector& bbox, const double *pos, int nbNodes, double eps, + std::vector& c, std::vector& cI) const + { + const double *coordsPtr=_coords->getConstPointer(); + BBTree myTree(&bbox[0],0,0,getNumberOfNodes(),-eps); + double bb[2*SPACEDIM]; + double eps2=eps*eps; + for(int i=0;i intersectingElems; + myTree.getIntersectingElems(bb,intersectingElems); + std::vector commonNodes; + for(std::vector::const_iterator it=intersectingElems.begin();it!=intersectingElems.end();it++) + if(INTERP_KERNEL::distance2(pos+SPACEDIM*i,coordsPtr+SPACEDIM*(*it))decrRef(); mesh->decrRef(); } + +void MEDCouplingBasicsTest::testGetNodeIdsNearPoints1() +{ + MEDCouplingUMesh *mesh=build2DTargetMesh_1(); + DataArrayDouble *coords=mesh->getCoords(); + DataArrayDouble *tmp=DataArrayDouble::New(); + tmp->alloc(3,2); + const double vals[6]={0.2,0.2,0.1,0.2,0.2,0.2}; + std::copy(vals,vals+6,tmp->getPointer()); + DataArrayDouble *tmp2=DataArrayDouble::aggregate(coords,tmp); + tmp->decrRef(); + 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; + 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]); + mesh->decrRef(); +} diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 0d73bad2e..51537f9ee 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -4856,6 +4856,22 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertAlmostEqual(f1.getArray().getIJ(0,i),f2.getArray().getIJ(0,i),5); pass pass + + def testGetNodeIdsNearPoints1(self): + mesh=MEDCouplingDataForTest.build2DTargetMesh_1(); + coords=mesh.getCoords(); + tmp=DataArrayDouble.New(); + vals=[0.2,0.2,0.1,0.2,0.2,0.2] + tmp.setValues(vals,3,2); + tmp2=DataArrayDouble.aggregate(coords,tmp); + mesh.setCoords(tmp2); + pts=[0.2,0.2,0.1,0.3,-0.3,0.7] + c=mesh.getNodeIdsNearPoint(pts,1e-7); + self.assertEqual([4,9,11],c); + c,cI=mesh.getNodeIdsNearPoints(pts,3,1e-7); + self.assertEqual([0,3,3,4],cI); + self.assertEqual([4,9,11,6],c); + pass def setUp(self): pass diff --git a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i index 445f023b4..fb0129d6e 100644 --- a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i +++ b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i @@ -458,6 +458,55 @@ namespace ParaMEDMEM delete [] p; return convertIntArrToPyList2(nodes); } + PyObject *getNodeIdsNearPoint(PyObject *pt, double eps) const throw(INTERP_KERNEL::Exception) + { + int size; + double *pos=convertPyToNewDblArr2(pt,&size); + if(sizegetSpaceDimension()) + { + delete [] pos; + throw INTERP_KERNEL::Exception("getNodeIdsNearPoint : to tiny array ! must be at least of size SpaceDim !"); + } + std::vector tmp; + try + { + tmp=self->getNodeIdsNearPoint(pos,eps); + } + catch(INTERP_KERNEL::Exception& e) + { + delete [] pos; + throw e; + } + delete [] pos; + return convertIntArrToPyList2(tmp); + } + + PyObject *getNodeIdsNearPoints(PyObject *pt, int nbOfNodes, double eps) const throw(INTERP_KERNEL::Exception) + { + std::vector c,cI; + int size; + double *pos=convertPyToNewDblArr2(pt,&size); + if(sizegetSpaceDimension()*nbOfNodes) + { + delete [] pos; + throw INTERP_KERNEL::Exception("getNodeIdsNearPoints : to tiny array ! must be at least of size SpaceDim*nbOfNodes !"); + } + try + { + self->getNodeIdsNearPoints(pos,nbOfNodes,eps,c,cI); + } + catch(INTERP_KERNEL::Exception& e) + { + delete [] pos; + throw e; + } + delete [] pos; + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,convertIntArrToPyList2(c)); + PyTuple_SetItem(ret,1,convertIntArrToPyList2(cI)); + return ret; + } + static void rotate2DAlg(PyObject *center, double angle, int nbNodes, PyObject *coords) { int sz;