]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
*** empty log message ***
authorageay <ageay>
Mon, 29 Nov 2010 16:34:43 +0000 (16:34 +0000)
committerageay <ageay>
Mon, 29 Nov 2010 16:34:43 +0000 (16:34 +0000)
src/MEDCoupling/MEDCouplingPointSet.cxx
src/MEDCoupling/MEDCouplingPointSet.hxx
src/MEDCoupling/MEDCouplingPointSet.txx
src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
src/MEDCoupling_Swig/libMEDCoupling_Swig.i

index 87964cbdf0be8ba4989a6cccad2315e61d172bac..4b8a17cc0846f406754bde71a54a454e864c3fef 100644 (file)
@@ -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<int> MEDCouplingPointSet::getNodeIdsNearPoint(const double *pos, double eps) const throw(INTERP_KERNEL::Exception)
+{
+  std::vector<int> 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<int>& c, std::vector<int>& 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<double> bbox(2*nbNodes*spaceDim);
+  for(int i=0;i<nbNodes;i++)
+    {
+      for(int j=0;j<spaceDim;j++)
+        {
+          bbox[2*spaceDim*i+2*j]=coordsPtr[spaceDim*i+j];
+          bbox[2*spaceDim*i+2*j+1]=coordsPtr[spaceDim*i+j];
+        }
+    }
+  std::vector<int> 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.
index 87a4c04ec89c1c6105ca639fc34c326a8054a0e5..21cb749b4b2c70c151222a364dc0cba207ccda7b 100644 (file)
@@ -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<int> getNodeIdsNearPoint(const double *pos, double eps) const throw(INTERP_KERNEL::Exception);
+    void getNodeIdsNearPoints(const double *pos, int nbOfNodes, double eps, std::vector<int>& c, std::vector<int>& 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<int SPACEDIM>
     void findCommonNodesAlg(std::vector<double>& bbox,
                             int nbNodes, int limitNodeId, double prec, std::vector<int>& c, std::vector<int>& cI) const;
+    template<int SPACEDIM>
+    void findNodeIdsNearPointAlg(std::vector<double>& bbox, const double *pos, int nbNodes, double eps,
+                                 std::vector<int>& c, std::vector<int>& cI) const;
   protected:
     DataArrayDouble *_coords;
   };
index bae1955669521d800191c474531e4e76168d8ce1..658d6d9c5dab25bbd52ec29d12e7df7d6e9b7b7e 100644 (file)
@@ -64,6 +64,32 @@ namespace ParaMEDMEM
           }
       }
   }
+  
+  template<int SPACEDIM>
+  void MEDCouplingPointSet::findNodeIdsNearPointAlg(std::vector<double>& bbox, const double *pos, int nbNodes, double eps,
+                                                    std::vector<int>& c, std::vector<int>& cI) const
+  {
+    const double *coordsPtr=_coords->getConstPointer();
+    BBTree<SPACEDIM,int> myTree(&bbox[0],0,0,getNumberOfNodes(),-eps);
+    double bb[2*SPACEDIM];
+    double eps2=eps*eps;
+    for(int i=0;i<nbNodes;i++)
+      {
+        for(int j=0;j<SPACEDIM;j++)
+          {
+            bb[2*j]=pos[SPACEDIM*i+j];
+            bb[2*j+1]=pos[SPACEDIM*i+j];
+          }
+        std::vector<int> intersectingElems;
+        myTree.getIntersectingElems(bb,intersectingElems);
+        std::vector<int> commonNodes;
+        for(std::vector<int>::const_iterator it=intersectingElems.begin();it!=intersectingElems.end();it++)
+          if(INTERP_KERNEL::distance2<SPACEDIM>(pos+SPACEDIM*i,coordsPtr+SPACEDIM*(*it))<eps2)
+            commonNodes.push_back(*it);
+        cI.push_back(cI.back()+commonNodes.size());
+        c.insert(c.end(),commonNodes.begin(),commonNodes.end());
+      }
+  }
 }
 
 #endif
index a17bc7fa319367c106b1db100c91bf19fe3c5f6d..163380099d4cae8402c7d4a0bd732f8e3ba61b3d 100644 (file)
@@ -153,6 +153,7 @@ namespace ParaMEDMEM
     CPPUNIT_TEST( testDADFromSpherToCart1 );
     CPPUNIT_TEST( testUnPolyze1 );
     CPPUNIT_TEST( testConvertDegeneratedCells1 );
+    CPPUNIT_TEST( testGetNodeIdsNearPoints1 );
     //MEDCouplingBasicsTestInterp.cxx
     CPPUNIT_TEST( test2DInterpP0P0_1 );
     CPPUNIT_TEST( test2DInterpP0P0PL_1 );
@@ -334,6 +335,7 @@ namespace ParaMEDMEM
     void testDADFromSpherToCart1();
     void testUnPolyze1();
     void testConvertDegeneratedCells1();
+    void testGetNodeIdsNearPoints1();
     //MEDCouplingBasicsTestInterp.cxx
     void test2DInterpP0P0_1();
     void test2DInterpP0P0PL_1();
index 0911a268c2bcdb065969485f51e61960105fa6bf..8f58aabd3a8a40e6eaf05214c392892fffc66406 100644 (file)
@@ -3224,3 +3224,37 @@ void MEDCouplingBasicsTest::testConvertDegeneratedCells1()
   f2->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<int> 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<int> 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();
+}
index 0d73bad2e96c424b84ecf30cb35c3b27689c351c..51537f9ee363ebc54642df9450bf51c7ffa17851 100644 (file)
@@ -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
index 445f023b4d2fcd9af3742201d76da93377edecef..fb0129d6ec67b0edf5eee25fa9d5634e98f31a93 100644 (file)
@@ -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(size<self->getSpaceDimension())
+               {
+                 delete [] pos;
+                 throw INTERP_KERNEL::Exception("getNodeIdsNearPoint : to tiny array ! must be at least of size SpaceDim !");
+               }
+             std::vector<int> 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<int> c,cI;
+             int size;
+             double *pos=convertPyToNewDblArr2(pt,&size);
+             if(size<self->getSpaceDimension()*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;