mirror of https://github.com/CGAL/cgal
WIP: Add Compare_squared_distance to NewKernel_d
This commit is contained in:
parent
33b35abaea
commit
0bd09ea2db
|
|
@ -16,6 +16,9 @@ create_single_source_cgal_program( "Frechet_DS_2.cpp" )
|
|||
create_single_source_cgal_program( "Frechet_DS_3.cpp" )
|
||||
|
||||
if(TARGET CGAL::Eigen3_support)
|
||||
create_single_source_cgal_program( "Frechet_DS_d.cpp" )
|
||||
target_link_libraries(Frechet_DS_d PUBLIC CGAL::Eigen3_support)
|
||||
|
||||
create_single_source_cgal_program( "Frechet_distance_d.cpp" )
|
||||
target_link_libraries(Frechet_distance_d PUBLIC CGAL::Eigen3_support)
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
#include <CGAL/Frechet_distance.h>
|
||||
#include <CGAL/Frechet_distance_traits_d.h>
|
||||
#include <CGAL/Frechet_distance/Neighbor_search.h>
|
||||
#include <CGAL/Epick_d.h>
|
||||
#include <CGAL/IO/WKT.h>
|
||||
|
||||
#include <ostream>
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
|
||||
using Kernel = CGAL::Epick_d<CGAL::Dimension_tag<2>>;
|
||||
using Traits = CGAL::Frechet_distance_traits_d<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();
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
@ -40,6 +40,7 @@ public:
|
|||
using Construct_bbox_d = typename Kernel::Construct_bbox_d;
|
||||
using Cartesian_const_iterator_d = typename Kernel::Cartesian_const_iterator_d;
|
||||
using Construct_cartesian_const_iterator_d = typename Kernel::Construct_cartesian_const_iterator_d;
|
||||
using Compare_squared_distance_d = typename Kernel::Compare_squared_distance_d;
|
||||
|
||||
Construct_bbox_d construct_bbox_d_object() const {
|
||||
return Construct_bbox_d();
|
||||
|
|
@ -48,6 +49,10 @@ public:
|
|||
Construct_cartesian_const_iterator_d construct_cartesian_const_iterator_d_object() const {
|
||||
return Construct_cartesian_const_iterator_d();
|
||||
}
|
||||
|
||||
Compare_squared_distance_d construct_compare_squared_distance_d_object() const {
|
||||
return Compare_squared_distance_d();
|
||||
}
|
||||
};
|
||||
|
||||
} // end of namespace CGAL
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ template <class Base_> struct Kernel_d_interface : public Base_ {
|
|||
typedef typename Get_type<Base, Weighted_point_tag>::type Weighted_point_d;
|
||||
typedef typename Get_functor<Base, Compute_point_cartesian_coordinate_tag>::type Compute_coordinate_d;
|
||||
typedef typename Get_functor<Base, Compare_lexicographically_tag>::type Compare_lexicographically_d;
|
||||
typedef typename Get_functor<Base, Compare_squared_distance_tag>::type Compare_squared_distance_d;
|
||||
typedef typename Get_functor<Base, Equal_points_tag>::type Equal_d;
|
||||
typedef typename Get_functor<Base, Less_lexicographically_tag>::type Less_lexicographically_d;
|
||||
typedef typename Get_functor<Base, Less_or_equal_lexicographically_tag>::type Less_or_equal_lexicographically_d;
|
||||
|
|
@ -230,6 +231,7 @@ template <class Base_> struct Kernel_d_interface : public Base_ {
|
|||
Compute_coordinate_d compute_coordinate_d_object()const{ return Compute_coordinate_d(*this); }
|
||||
Has_on_positive_side_d has_on_positive_side_d_object()const{ return Has_on_positive_side_d(*this); }
|
||||
Compare_lexicographically_d compare_lexicographically_d_object()const{ return Compare_lexicographically_d(*this); }
|
||||
Compare_squared_distance_d compare_squared_distance_d_object()const{ return Compare_squared_distance_d(*this); }
|
||||
Equal_d equal_d_object()const{ return Equal_d(*this); }
|
||||
Less_lexicographically_d less_lexicographically_d_object()const{ return Less_lexicographically_d(*this); }
|
||||
Less_or_equal_lexicographically_d less_or_equal_lexicographically_d_object()const{ return Less_or_equal_lexicographically_d(*this); }
|
||||
|
|
|
|||
|
|
@ -1194,6 +1194,40 @@ template<class R_> struct Compare_lexicographically : private Store_kernel<R_> {
|
|||
|
||||
CGAL_KD_DEFAULT_FUNCTOR(Compare_lexicographically_tag,(CartesianDKernelFunctors::Compare_lexicographically<K>),(),(Construct_ttag<Point_cartesian_const_iterator_tag>));
|
||||
|
||||
namespace CartesianDKernelFunctors {
|
||||
template<class R_> struct Compare_squared_distance : private Store_kernel<R_> {
|
||||
CGAL_FUNCTOR_INIT_STORE(Compare_squared_distance)
|
||||
typedef R_ R;
|
||||
typedef typename Get_type<R, Comparison_result_tag>::type result_type;
|
||||
typedef typename Get_functor<R, Construct_ttag<Point_cartesian_const_iterator_tag> >::type CI;
|
||||
// TODO: This is_exact thing should be reengineered.
|
||||
// the goal is to have a way to tell: don't filter this
|
||||
typedef typename CGAL::Uses_no_arithmetic<CI> Uses_no_arithmetic;
|
||||
|
||||
template<class V,class W>
|
||||
result_type operator()(V const&a, V const&b, W const&c)const{ // Point, Point. FT
|
||||
#if 0
|
||||
CI c(this->kernel());
|
||||
|
||||
|
||||
auto a_begin=c(a,Begin_tag());
|
||||
auto b_begin=c(b,Begin_tag());
|
||||
auto a_end=c(a,End_tag());
|
||||
result_type res;
|
||||
// can't we do slightly better for Uncertain<*> ?
|
||||
// after res=...; if(is_uncertain(res))return indeterminate<result_type>();
|
||||
do res=CGAL_NTS compare(*a_begin++,*b_begin++);
|
||||
while(a_begin!=a_end && res==EQUAL);
|
||||
return res;
|
||||
#endif
|
||||
return EQUAL;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
CGAL_KD_DEFAULT_FUNCTOR(Compare_squared_distance_tag,(CartesianDKernelFunctors::Compare_squared_distance<K>),(),(Construct_ttag<Point_cartesian_const_iterator_tag>));
|
||||
|
||||
|
||||
namespace CartesianDKernelFunctors {
|
||||
template<class R_> struct Less_lexicographically : private Store_kernel<R_> {
|
||||
CGAL_FUNCTOR_INIT_STORE(Less_lexicographically)
|
||||
|
|
|
|||
|
|
@ -278,6 +278,7 @@ namespace CGAL {
|
|||
CGAL_DECL_PREDICATE(Compare_point_cartesian_coordinate);
|
||||
CGAL_DECL_PREDICATE(Compare_distance);
|
||||
CGAL_DECL_PREDICATE(Compare_lexicographically);
|
||||
CGAL_DECL_PREDICATE(Compare_squared_distance);
|
||||
CGAL_DECL_PREDICATE(Less_lexicographically);
|
||||
CGAL_DECL_PREDICATE(Less_or_equal_lexicographically);
|
||||
CGAL_DECL_PREDICATE(Equal_points);
|
||||
|
|
|
|||
Loading…
Reference in New Issue