Skip to content

Commit

Permalink
Add 2D example of data structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
André Nusser committed Jan 22, 2025
1 parent 7e868bc commit 4859df3
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Frechet_distance/examples/Frechet_distance/Frechet_DS_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#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"};
for (auto const& dir_entry : std::filesystem::directory_iterator{data}){
std::ifstream in(dir_entry.path());
curves.push_back(Curve());
CGAL::IO::read_linestring_WKT(in, curves.back());
}

Curve query = curves.back();

curves.pop_back();

CGAL::Frechet_distance::Neighbor_search<Curve, Traits> ds;
ds.insert(curves);

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(query, distance);

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

0 comments on commit 4859df3

Please sign in to comment.