Subject: CGAL users discussion list
List archive
- From:
- To:
- Subject: Indexing Points in a nearest-neighbor search using Point-Set
- Date: Sat, 5 Jan 2008 15:55:34 +0100
Hello,
I wanted to index the Points
in a point-Set so that the nearest-neighbor query return me the neighbor index
in addition to the points (in the vertex_handle). For example in the following
example (taken from example/Point-Set_2/nearest_nbr_tr.C),
---------------------------------------------------------------------------------------
Vertex_handle v = PSet.nearest_neighbor(actual);
std::cout << "Nearest neighbor:" << v->point() << "\n";
if (v->point() == p4) w1=0; else w1=1;
-------------------------------------------------------------------------------------
We are testing whether v->point() == p4, I like to have v->point() return
me 4 in addition of the point p4. One way might be to extend point class to
have an extra parameter like "id" so that we can call something like below:
std::cout << "Nearest neighbor:" << (v->point()).getid() << endl;
I tried that but could not make it work.
My template knowledge is not good, can someone help me out here.
Thank you very much and I appreciate your time.
-Hasan
The main method (partial) of nearest_nb1 below:
int main()
{
std::list<Point> Lr;
int w1,w2;
Point p1(12,14);
Point p2(-12,14);
Point p3(2,11);
Point p4(5,6);
Point p5(6.7,3.8);
Point p6(11,20);
Point p7(-5,6);
Point p8(12,0);
Point p9(4,31);
Point p10(-10,-10);
Lr.push_back(p1); Lr.push_back(p2); Lr.push_back(p3);
Lr.push_back(p4); Lr.push_back(p5); Lr.push_back(p6);
Lr.push_back(p7); Lr.push_back(p8); Lr.push_back(p9);
Lr.push_back(p10);
PSet.insert(Lr.begin(),Lr.end());
// init
ar1[0]=p4; ar1[1]=p5; ar1[2]=p3; ar1[3]=p7; ar1[4]=p8;
Point actual(30,45,10);
// nearest neighbor ...
Vertex_handle v = PSet.nearest_neighbor(actual);
std::cout << "Nearest neighbor:" << v->point() << "\n";
if (v->point() == p4) w1=0; else w1=1;
-----------------------------------------------------------------------------
- Indexing Points in a nearest-neighbor search using Point-Set, mohammad . alhasan, 01/05/2008
Archive powered by MHonArc 2.6.16.