File: wachspress_coordinates.cpp

package info (click to toggle)
cgal 6.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (53 lines) | stat: -rw-r--r-- 1,703 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
45
46
47
48
49
50
51
52
53
#include <CGAL/convex_hull_2.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/Barycentric_coordinates_2/Wachspress_coordinates_2.h>

// Typedefs.
using Kernel = CGAL::Simple_cartesian<double>;

using FT      = Kernel::FT;
using Point_2 = Kernel::Point_2;

using Creator   = CGAL::Creator_uniform_2<FT, Point_2>;
using Generator = CGAL::Random_points_in_square_2<Point_2, Creator>;

int main() {

  // Choose how many query points we want to generate.
  const std::size_t num_queries = 100;

  // Create vectors to store query points and polygon vertices.
  std::vector<Point_2> queries, convex;

  // Generate a set of query points.
  queries.reserve(num_queries);
  Generator generator(1.0);
  std::copy_n(generator, num_queries, std::back_inserter(queries));

  // Find the convex hull of the generated query points.
  // This convex hull gives the vertices of a convex polygon
  // that contains all the generated points.
  CGAL::convex_hull_2(
    queries.begin(), queries.end(), std::back_inserter(convex));

  // Compute Wachspress coordinates for all query points.
  std::cout << std::endl << "Wachspress coordinates (interior + boundary): " << std::endl << std::endl;

  std::vector<FT> coordinates;
  coordinates.reserve(convex.size());

  for (const auto& query : queries) {
    coordinates.clear();
    CGAL::Barycentric_coordinates::wachspress_coordinates_2(
      convex, query, std::back_inserter(coordinates));

    for (std::size_t i = 0; i < coordinates.size() - 1; ++i) {
      std::cout << coordinates[i] << ", ";
    }
    std::cout << coordinates[coordinates.size() - 1] << std::endl;
  }
  std::cout << std::endl;

  return EXIT_SUCCESS;
}