diff --git a/Interpolation/doc/Interpolation/examples.txt b/Interpolation/doc/Interpolation/examples.txt index 4f47c8da83a..ee47a57c90d 100644 --- a/Interpolation/doc/Interpolation/examples.txt +++ b/Interpolation/doc/Interpolation/examples.txt @@ -1,5 +1,6 @@ /*! \example Interpolation/nn_coordinates_2.cpp +\example Interpolation/nn_coordinates_with_info_2.cpp \example Interpolation/rn_coordinates_2.cpp \example Interpolation/surface_neighbor_coordinates_3.cpp \example Interpolation/linear_interpolation_2.cpp diff --git a/Interpolation/examples/Interpolation/README b/Interpolation/examples/Interpolation/README index dfb5a3e9242..3cccf701b0d 100644 --- a/Interpolation/examples/Interpolation/README +++ b/Interpolation/examples/Interpolation/README @@ -4,6 +4,10 @@ To compile and run only some of them type : make name-of_wanted_example nn_coordinates_2: shows how to compute 2D natural coordinates given a 2D Delaunay triangulation and a query point. +nn_coordinates_with_info_2: same as above, using a functor to + change the default option and store the coordinates + in the vertices. + nn_coordinates_3: shows how to compute 3D natural coordinates given a 3D Delaunay triangulation and a query point. diff --git a/Interpolation/examples/Interpolation/nn_coordinates_with_info_2.cpp b/Interpolation/examples/Interpolation/nn_coordinates_with_info_2.cpp new file mode 100644 index 00000000000..f48b9d3d791 --- /dev/null +++ b/Interpolation/examples/Interpolation/nn_coordinates_with_info_2.cpp @@ -0,0 +1,58 @@ +#include + +#include +#include +#include + +#include +#include +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; + +typedef K::FT Coord_type; +typedef CGAL::Triangulation_vertex_base_with_info_2 Vb; +typedef CGAL::Triangulation_data_structure_2 Tds; +typedef CGAL::Delaunay_triangulation_2 Delaunay_triangulation; + +// The functor 'Identity' matches anything to itself +typedef Delaunay_triangulation::Vertex_handle Vertex_handle; +typedef CGAL::Identity > Identity; + +// Resulting points-coordinates pairs are here stored in an object of this type: +typedef std::vector > Point_coordinate_vector; + +int main() +{ + Delaunay_triangulation dt; + + for(int y=0; y<3; ++y) + for(int x=0; x<3; ++x) + dt.insert(K::Point_2(x, y)); + + // coordinates computation + K::Point_2 p(1.2, 0.7); // query point + Point_coordinate_vector coords; + + // The functor Identity is passed to the method + CGAL::Triple, K::FT, bool> result = + CGAL::natural_neighbor_coordinates_2(dt, p, std::back_inserter(coords), Identity()); + + if(!result.third) + { + std::cout << "The coordinate computation was not successful." << std::endl; + std::cout << "The point (" << p << ") lies outside the convex hull." << std::endl; + } + + // Assign the coordinates to the vertices + std::cout << "Coordinates for point: (" << p << ") are the following: " << std::endl; + for(std::size_t i=0; iinfo() = coords[i].second; + std::cout << " Vertex: (" << vh->point() << ") coeff: " << vh->info() << std::endl; + } + + return EXIT_SUCCESS; +}