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());
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.
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;
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;
};
}
}
}
+
+ 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
CPPUNIT_TEST( testDADFromSpherToCart1 );
CPPUNIT_TEST( testUnPolyze1 );
CPPUNIT_TEST( testConvertDegeneratedCells1 );
+ CPPUNIT_TEST( testGetNodeIdsNearPoints1 );
//MEDCouplingBasicsTestInterp.cxx
CPPUNIT_TEST( test2DInterpP0P0_1 );
CPPUNIT_TEST( test2DInterpP0P0PL_1 );
void testDADFromSpherToCart1();
void testUnPolyze1();
void testConvertDegeneratedCells1();
+ void testGetNodeIdsNearPoints1();
//MEDCouplingBasicsTestInterp.cxx
void test2DInterpP0P0_1();
void test2DInterpP0P0PL_1();
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();
+}
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
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;