]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
MEDCouplingPointSet::getNodeIdsNearPoints Python API simplification
authorageay <ageay>
Fri, 29 Jun 2012 08:42:30 +0000 (08:42 +0000)
committerageay <ageay>
Fri, 29 Jun 2012 08:42:30 +0000 (08:42 +0000)
src/MEDCoupling_Swig/MEDCoupling.i
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py

index f9696c42941d67d351da556699068264dd276480..8e4d6c97589fc29497b1b09a74d554885c1072a4 100644 (file)
@@ -1021,6 +1021,51 @@ namespace ParaMEDMEM
              return ret;
            }
 
+           PyObject *getNodeIdsNearPoints(PyObject *pt, double eps) const throw(INTERP_KERNEL::Exception)
+           {
+             std::vector<int> c,cI;
+             int spaceDim=self->getSpaceDimension();
+             void *da=0;
+             int res1=SWIG_ConvertPtr(pt,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, 0 |  0 );
+             if (!SWIG_IsOK(res1))
+               {
+                 int size;
+                 INTERP_KERNEL::AutoPtr<double> tmp=convertPyToNewDblArr2(pt,&size);
+                 int nbOfPoints=size/spaceDim;
+                 if(size%spaceDim!=0)
+                   {
+                     throw INTERP_KERNEL::Exception("MEDCouplingPointSet::getCellsContainingPoints : Invalid list length ! Must be a multiple of self.getSpaceDimension() !");
+                   }
+                 self->getNodeIdsNearPoints(tmp,nbOfPoints,eps,c,cI);
+               }
+             else
+               {
+                 DataArrayDouble *da2=reinterpret_cast< DataArrayDouble * >(da);
+                 if(!da2)
+                   throw INTERP_KERNEL::Exception("MEDCouplingPointSet::getCellsContainingPoints : Not null DataArrayDouble instance expected !");
+                 da2->checkAllocated();
+                 int size=da2->getNumberOfTuples();
+                 int nbOfCompo=da2->getNumberOfComponents();
+                 if(nbOfCompo!=spaceDim)
+                   {
+                     throw INTERP_KERNEL::Exception("MEDCouplingPointSet::getCellsContainingPoints : Invalid DataArrayDouble nb of components ! Expected same as self.getSpaceDimension() !");
+                   }
+                 self->getNodeIdsNearPoints(da2->getConstPointer(),size,eps,c,cI);
+               }
+             PyObject *ret=PyTuple_New(2);
+             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d0=DataArrayInt::New();
+             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> 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();
+             return ret;
+           }
+
            PyObject *getCellsInBoundingBox(PyObject *bbox, double eps) const throw(INTERP_KERNEL::Exception)
            {
              std::vector<int> elems;
index a12e517452e7c6785fa838f50d1db6e679ee88a8..9d0dd6711957407cd88396c602e57d61bcb70108 100644 (file)
@@ -4913,6 +4913,13 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         c,cI=mesh.getNodeIdsNearPoints(pts,3,1e-7);
         self.assertEqual([0,3,3,4],cI.getValues());
         self.assertEqual([4,9,11,6],c.getValues());
+        c,cI=mesh.getNodeIdsNearPoints(pts,1e-7);
+        self.assertEqual([0,3,3,4],cI.getValues());
+        self.assertEqual([4,9,11,6],c.getValues());
+        c,cI=mesh.getNodeIdsNearPoints(DataArrayDouble.New(pts,3,2),1e-7);
+        self.assertEqual([0,3,3,4],cI.getValues());
+        self.assertEqual([4,9,11,6],c.getValues());
+        self.assertRaises(InterpKernelException,mesh.getNodeIdsNearPoints,DataArrayDouble.New(pts,2,3),1e-7);
         pass
 
     def testFieldCopyTinyAttrFrom1(self):