File: parallel_Frechet_DS_2.cpp

package info (click to toggle)
cgal 6.1.1-2
  • 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 (50 lines) | stat: -rw-r--r-- 1,753 bytes parent folder | download
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
#include <CGAL/Frechet_distance.h>
#include <CGAL/Frechet_distance_traits_2.h>
#include <CGAL/Frechet_distance/Neighbor_search.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/IO/WKT.h>

#include <ostream>
#include <fstream>
#include <filesystem>

using Kernel = CGAL::Simple_cartesian<double>;
using Traits = CGAL::Frechet_distance_traits_2<Kernel>;
using Point = Traits::Point_d;
using Curve = std::vector<Point>;
using Curves = std::vector<Curve>;

int main()
{
    Curves curves;

    const std::filesystem::path data{"./data_2d"};
    std::vector<std::string> filenames;
    for (auto const& dir_entry : std::filesystem::directory_iterator{data}) {
        filenames.push_back(dir_entry.path().string());
    }
    std::sort(filenames.begin(), filenames.end());

    for (auto const& filename : filenames) {
        std::cout << filename << std::endl;
        std::ifstream in(filename);
        curves.push_back(Curve());
        CGAL::IO::read_linestring_WKT(in, curves.back());
    }

    // last curve is the query curve
    Curve query = curves.back();
    curves.pop_back();

    using Neighbor_search = CGAL::Frechet_distance::Neighbor_search<Curve, Traits>;
    Neighbor_search ds(curves, CGAL::Parallel_if_available_tag());

    for(const Curve& c : curves){
        std::pair<double, double> res = CGAL::bounded_error_Frechet_distance(c, query, 0.000001);
        std::cout << "The Frechet distance between the polylines is between " <<  res.first << " and " << res.second << std::endl;
    }
    double distance = 16;
    std::vector<std::size_t> result = ds.get_close_curves<CGAL::Parallel_if_available_tag>(query, distance);

    std::cout << result.size() << " curves at Frechet distance closer than " << distance << std::endl;
}