1 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
2 #include <CGAL/Optimal_transportation_reconstruction_2.h>
3
4 #include <fstream>
5 #include <iostream>
6 #include <string>
7 #include <iterator>
8 #include <utility> // std::pair
9 #include <vector>
10
11 #include <CGAL/property_map.h>
12
13 typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
14 typedef K::FT FT;
15 typedef K::Point_2 Point;
16 typedef K::Segment_2 Segment;
17
18 typedef std::pair<Point, FT> PointMassPair;
19 typedef std::vector<PointMassPair> PointMassList;
20
21 typedef CGAL::First_of_pair_property_map <PointMassPair> Point_property_map;
22 typedef CGAL::Second_of_pair_property_map <PointMassPair> Mass_property_map;
23
24 typedef CGAL::Optimal_transportation_reconstruction_2<
25 K, Point_property_map, Mass_property_map> Otr_2;
26
load_xym_file(const std::string & filename,PointMassList & points)27 void load_xym_file(const std::string& filename, PointMassList& points)
28 {
29 std::ifstream ifs(filename.c_str());
30
31 Point point;
32 FT mass;
33
34 while (ifs >> point && ifs >> mass)
35 points.push_back(std::make_pair(point, mass));
36
37 ifs.close();
38 }
39
main()40 int main ()
41 {
42 PointMassList points;
43
44 load_xym_file("data/stair.xym", points);
45
46 Point_property_map point_pmap;
47 Mass_property_map mass_pmap;
48
49 Otr_2 otr2(points, point_pmap, mass_pmap);
50
51 otr2.run(100); // 100 steps
52
53 std::vector<Point> isolated_vertices;
54 std::vector<Segment> edges;
55
56 otr2.list_output(
57 std::back_inserter(isolated_vertices), std::back_inserter(edges));
58
59 std::cout << "Isolated vertices:" << std::endl;
60 std::vector<Point>::iterator vit;
61 for (vit = isolated_vertices.begin(); vit != isolated_vertices.end(); vit++)
62 std::cout << *vit << std::endl;
63
64 std::cerr << "Edges:" << std::endl;
65 std::vector<Segment>::iterator eit;
66 for (eit = edges.begin(); eit != edges.end(); eit++)
67 std::cout << *eit << std::endl;
68
69 return 0;
70 }
71