Skip to content

Commit

Permalink
enable filtering for Epick_d
Browse files Browse the repository at this point in the history
  • Loading branch information
sloriot committed Nov 14, 2024
1 parent 5bb5aa9 commit 759fc87
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <CGAL/Epick_d.h>
#include <CGAL/Frechet_distance.h>
#include <CGAL/Frechet_distance_traits_d.h>
#include <CGAL/Epick_d.h>


#include <iostream>
#include <vector>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
#include <CGAL/STL_Extension/internal/Has_nested_type_Has_filtered_predicates_tag.h>
#include <CGAL/Frechet_distance_traits_2.h>
#include <CGAL/Frechet_distance_traits_3.h>
#include <CGAL/Frechet_distance_traits_d.h>
#include <CGAL/Frechet_distance_traits.h>
#include <CGAL/Simple_cartesian.h>
// #include <CGAL/Epick_d.h>
#include <CGAL/Exact_rational.h>
#include <CGAL/Interval_nt.h>
#include <CGAL/Lazy.h>
Expand Down Expand Up @@ -74,12 +73,19 @@ auto toCurve(const PointRange& point_range, const Traits& traits)
}
else
{
// using AK = Kernel_d_interface<Cartesian_base_d<distance_t,Dimension_tag<dimension>>>;
// using EK = typename CGAL::Frechet_distance_::internal::Get_exact_kernel<Kernel>::type;
// using Filtered_traits = std::pair<Frechet_distance_traits_d<AK>, Frechet_distance_traits_d<EK>>;
#if 0
using Base_kernel = typename Kernel_traits<typename Traits::Point_d>::Kernel;

// return Curve<Filtered_traits, true>(point_range);
return Curve<Traits, false>(point_range, traits);
using AK = Kernel_d_interface<typename Base_kernel::AK>;
using EK = Kernel_d_interface<typename Base_kernel::EK>;
//using EK = typename CGAL::Frechet_distance_::internal::Get_exact_kernel<Kernel>::type;
#endif
using AT = Frechet_distance_traits<CGAL::Interval_nt_advanced, Traits::Dimension::value>;
using ET = Frechet_distance_traits<CGAL::Exact_rational, Traits::Dimension::value>;
using Filtered_traits = std::pair<AT,ET>;

return Curve<Filtered_traits, true>(point_range, traits);
//return Curve<Traits, false>(point_range, traits);
}
}
else
Expand All @@ -104,11 +110,7 @@ auto toCurve(const PointRange& point_range, const Traits& traits)
}
else
{
// using AK = Kernel_d_interface<Cartesian_base_d<distance_t,Dimension_tag<dimension>>>;
// using EK = typename CGAL::Frechet_distance_::internal::Get_exact_kernel<Kernel>::type;
// using Filtered_traits = std::pair<Frechet_distance_traits_d<AK>, Frechet_distance_traits_d<EK>>;

// return Curve<Filtered_traits, true>(point_range);
//TODO: not implemented
return Curve<Traits, false>(point_range, traits);
}
}
Expand Down Expand Up @@ -139,11 +141,7 @@ auto toCurve(const PointRange& point_range, const Traits& traits)
}
else
{
// using AK = Kernel_d_interface<Cartesian_base_d<distance_t,Dimension_tag<dimension>>>;
// using EK = typename CGAL::Frechet_distance_::internal::Get_exact_kernel<Kernel>::type;
// using Filtered_traits = std::pair<Frechet_distance_traits_d<AK>, Frechet_distance_traits_d<EK>>;

// return Curve<Filtered_traits, true>(point_range);
//TODO: not implemented
return Curve<Traits, false>(point_range, traits);
}
}
Expand All @@ -169,11 +167,7 @@ auto toCurve(const PointRange& point_range, const Traits& traits)
}
else
{
// using AK = Kernel_d_interface<Cartesian_base_d<distance_t,Dimension_tag<dimension>>>;
// using EK = typename CGAL::Frechet_distance_::internal::Get_exact_kernel<Kernel>::type;
// using Filtered_traits = std::pair<Frechet_distance_traits_d<AK>, Frechet_distance_traits_d<EK>>;

// return Curve<Filtered_traits, true>(point_range);
//TODO: not implemented
return Curve<Traits, false>(point_range, traits);
}
}
Expand Down
42 changes: 26 additions & 16 deletions Frechet_distance/include/CGAL/Frechet_distance/internal/curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,8 @@ class Curve<std::pair<Approximate_traits,Rational_traits>, true>
using AT = Approximate_traits;
using ET = Rational_traits;

// TODO: this assumes that input interval are all tight --> need a PM!
using I2R = Cartesian_converter< typename Kernel_traits<Point>::Kernel,
typename Kernel_traits<Rational_point>::Kernel, NT_converter<distance_t,double>>;

Curve() = default;


template <class PointRange, class Input_traits>
Curve(const PointRange& point_range, const Input_traits& in_traits, const Rational_traits& rt = Rational_traits())
: rational_traits_(rt)
Expand All @@ -119,16 +114,32 @@ class Curve<std::pair<Approximate_traits,Rational_traits>, true>
else if constexpr (dim==3)
this->points.emplace_back(coords[0], coords[1], coords[2]);
else
this->points.emplace_back(coords.begin(), coords.end());
this->points.emplace_back(coords);
}

this->init();
}

Rational_point rpoint(PointID const& i) const
{
I2R convert;
return convert(this->point(i));
if constexpr (Approximate_traits::Dimension::value<=3)
{
// TODO: this assumes that input interval are all tight --> need a PM!
using I2R = Cartesian_converter< typename Kernel_traits<Point>::Kernel,
typename Kernel_traits<Rational_point>::Kernel, NT_converter<distance_t,double>>;
I2R convert;
return convert(this->point(i));
}
else
{
Rational_point rp;
for(int d=0; d<Approximate_traits::Dimension::value; ++d)
{
CGAL_assertion(this->point(i)[d].inf()==this->point(i)[d].sup());
rp[d]=Rational(this->point(i)[d].inf());
}
return rp;
}
}

const Rational_traits& rational_traits() const { return rational_traits_; }
Expand Down Expand Up @@ -214,14 +225,11 @@ class Curve<T, false>
public:
using Traits = T;

//TODO: we expect Dimension_tag for now.
static constexpr int dimension = Traits::Dimension::value;
using Bbox = std::conditional_t<dimension==2,
Bbox_2, std::conditional_t<dimension==3,
Bbox_3, ::CGAL::Bbox<typename Traits::Dimension, double>>>;
static constexpr int dimension = Traits::Dimension::value;
using Bbox = std::conditional_t<dimension==2,
Bbox_2, std::conditional_t<dimension==3,
Bbox_3, ::CGAL::Bbox<typename Traits::Dimension, double>>>;


//////
using FT = typename Traits::FT;
using IFT = std::conditional_t<std::is_floating_point_v<FT>, FT, CGAL::Interval_nt<false>>;
using distance_t = FT;
Expand Down Expand Up @@ -297,7 +305,9 @@ class Curve<T, false>

private:
// private as it will do nasty things if p is a temporary
static auto begin(const Point& p, const Traits& traits)
template <class P>
static auto begin(const P& p, const Traits& traits,
std::enable_if_t<!std::is_same_v<P,std::array<FT,dimension>>>)
{
Construct_cartesian_const_iterator_d ccci = traits.construct_cartesian_const_iterator_d_object();
return ccci(p);
Expand Down
80 changes: 80 additions & 0 deletions Frechet_distance/include/CGAL/Frechet_distance_traits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (c) 2024 Max-Planck-Institute Saarbruecken (Germany), GeometryFactory (France)
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL$
// $Id$
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
// Author(s) : André Nusser <[email protected]>
// Marvin Künnemann <[email protected]>
// Karl Bringmann <[email protected]>
// Andreas Fabri
// =============================================================================

#ifndef CGAL_FRECHET_DISTANCE_TRAITS_H
#define CGAL_FRECHET_DISTANCE_TRAITS_H

#include <CGAL/license/Frechet_distance.h>

#include <CGAL/Bbox.h>
#include <array>

namespace CGAL
{
/*
* \ingroup PkgFrechetDistanceRef
*
* \cgalModels{FrechetDistanceTraits}
* \tparam NT number type
* \tparam dimension point dimension
*/
template <class NT, int dimension>
class Frechet_distance_traits
{
public:
using Dimension = Dimension_tag<dimension>;

using FT = NT;
using Point_d = std::array<FT, dimension>;
using Cartesian_const_iterator_d = typename Point_d::const_iterator;

struct Construct_bbox_d
{
Bbox<Dimension, double> operator()(const Point_d& p) const
{
Bbox<Dimension, double> bb;
for (int i=0;i<dimension; ++i)
{
bb.min(i)=to_interval(p[i]).first;
bb.max(i)=to_interval(p[i]).second;
}

return bb;
}
};

struct Construct_cartesian_const_iterator_d
{
Cartesian_const_iterator_d operator()(const Point_d& p) const
{
return p.begin();
}
Cartesian_const_iterator_d operator()(const Point_d& p, int) const
{
return p.end();
}
};

Construct_bbox_d construct_bbox_d_object() const { return Construct_bbox_d(); }

Construct_cartesian_const_iterator_d construct_cartesian_const_iterator_d_object() const
{
return Construct_cartesian_const_iterator_d();
}
};

} // end of namespace CGAL

#endif // CGAL_FRECHET_DISTANCE_TRAITS_H

0 comments on commit 759fc87

Please sign in to comment.