Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] nearest points

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] nearest points


Chronological Thread 
  • From: "Sebastien Loriot (GeometryFactory)" <>
  • To:
  • Subject: Re: [cgal-discuss] nearest points
  • Date: Wed, 02 Feb 2011 08:23:57 +0100

Currently, the class Point_set_2 inherits from Delaunay_triangulation_2.

The only solution I can propose right now, is to use a TDS with a vertex_with_info
(see example Adding colors here:
http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Triangulation_2/Chapter_main.html#Section_35.11
but use as vertex type Vertex_base_with_info_2, see also:
http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Point_set_2_ref/Class_Point_set_2.html)

Then use for example:
Vertex_handle vi=PSet.insert(pi);
vi->info()= i;

A better solution should come up with CGAL 3.9

S.





Battalgazi YILDIRIM wrote:

Hi,

I am looking following example under examples/Point_set_2/nearest_neighborhood.cpp. I want to
assign some values to each points. After I found nearest points, I would like to reach
nearest points' values. I can do this through std::map, but I don't feel that it is the
right way.

As an example, you have temperature field over 2D domain (x,y). Each point
you have some temperature value such as (x,y,T). When I ask nearest
points around (x0,y0), I also want to get T values, in addition to (x,y)s , of nearest locations.


Could you help me out?

Thanks,
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Point_set_2.h>
#include <list>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;

typedef CGAL::Point_set_2<K>::Edge_iterator Edge_iterator;
typedef CGAL::Point_set_2<K>::Vertex_handle Vertex_handle;
typedef K::Point_2 Point_2;

CGAL::Point_set_2<K> PSet;
Point_2 ar1[5];


int main()
{
std::list<Point_2> Lr;

Point_2 p1(12,14);
Point_2 p2(-12,14);
Point_2 p3(2,11);
Point_2 p4(5,6);
Point_2 p5(6.7,3.8);
Point_2 p6(11,20);
Point_2 p7(-5,6);
Point_2 p8(12,0);
Point_2 p9(4,31);
Point_2 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_2 actual(3.0,4.5);

// nearest neighbor ...
Vertex_handle v = PSet.nearest_neighbor(actual);
std::cout << "Nearest neighbor:" << v->point() << "\n";

// k nearest neighbors ...
std::list<Vertex_handle> L;
std::list<Vertex_handle>::const_iterator it;

PSet.nearest_neighbors(actual,7, std::back_inserter(L));
std::cout << "actual point: " << actual << "\n";

for (it=L.begin();it != L.end(); it++)
std::cout << (*it)->point() << " infor = " << (*it)->info() << "\n";

return 0;
}


--
B. Gazi YILDIRIM



  • [cgal-discuss] nearest points, Battalgazi YILDIRIM, 02/02/2011
    • Re: [cgal-discuss] nearest points, Sebastien Loriot (GeometryFactory), 02/02/2011

Archive powered by MHonArc 2.6.16.

Top of Page