File: linear_interpolation_2.cpp

package info (click to toggle)
cgal 6.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 141,840 kB
  • sloc: cpp: 797,081; ansic: 203,398; sh: 490; python: 411; makefile: 286; javascript: 174
file content (44 lines) | stat: -rw-r--r-- 1,572 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>

#include <CGAL/Interpolation_traits_2.h>
#include <CGAL/natural_neighbor_coordinates_2.h>
#include <CGAL/interpolation_functions.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K>                   Delaunay_triangulation;
typedef CGAL::Interpolation_traits_2<K>                     Traits;
typedef K::FT                                               Coord_type;
typedef K::Point_2                                          Point;

int main()
{
  Delaunay_triangulation T;

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

  Coord_map value_function;
  Coord_type a(0.25), bx(1.3), by(-0.7);

  for (int y=0 ; y<3 ; y++){
    for (int x=0 ; x<3 ; x++){
      K::Point_2 p(x,y);
      T.insert(p);
      value_function.insert(std::make_pair(p, a + bx*x + by*y));
    }
  }

  //coordinate computation
  K::Point_2 p(1.3, 0.34);
  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(value_function));

  std::cout << "Tested interpolation on " << p << " interpolation: "
            << res << " exact: " << a + bx*p.x() + by*p.y() << std::endl;

  return EXIT_SUCCESS;
}