Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] Natural neighbor interpolation

Subject: CGAL users discussion list

List archive

[cgal-discuss] Natural neighbor interpolation


Chronological Thread 
  • From: Adam Laža <>
  • To:
  • Cc: Martin Landa <>
  • Subject: [cgal-discuss] Natural neighbor interpolation
  • Date: Tue, 19 May 2015 18:56:24 +0200

Hi all,

I write a module for GRASS GIS that provide natural neighbor interpolation using CGAL. I have measured points saved in vector "points".

Also I have a vector "function_values" for these points:

function_values.insert(std::make_pair(Point(x,y),z));


I'd like to save into a grid values interpolated within the region containing these points.

So far I have code that works but is quite slow, because I have to go throw the grid step-by-step by cols and rows to define point p K::Point_2 p(coor_x,coor_y) and call the CGAL::natural_neighbor_coordinates_2 for each single step.


Is there any option how to fill the grid in different way?


Thanks in advance


Adam Laza

CTU Prague



/* perform NN interpolation */

G_message(_("Computing..."));


Delaunay_triangulation T;

typedef CGAL::Data_access< std::map<Point, Coord_type, K::Less_xy_2 > >

Value_access;


T.insert(points.begin(), points.end());



//coordinate computation in grid

double coor_x, coor_y;

coor_x = window.west;

coor_y = window.north;


for (int rows=0 ; rows<window.rows ; rows++) {

    G_percent(rows, window.rows, 2);


    coor_x = window.west;

    for (int cols=0 ; cols<window.cols ; cols++) {

        K::Point_2 p(coor_x,coor_y);

        std::vector< std::pair< Point, Coord_type > > coords;

        Coord_type norm = CGAL::natural_neighbor_coordinates_2(T, p,std::back_inserter(coords)).second;

        Coord_type res = CGAL::linear_interpolation(coords.begin(), coords.end(), norm, Value_access(function_values));

        G_debug(5, "x: %f y: %f -> res: %f (row=%d; col=%d)",

        coor_x, coor_y, res, rows, cols);

        coor_x += ewres;

        std::cout << res << " ";

}

    coor_y -= nsres;

    std::cout << std::endl;

}

G_percent(1, 1, 1);




  • [cgal-discuss] Natural neighbor interpolation, Adam Laža, 05/19/2015

Archive powered by MHonArc 2.6.18.

Top of Page