mirror of https://github.com/CGAL/cgal
hide force filtering and the traits in NP
This commit is contained in:
parent
f78f51450b
commit
9296fe78c2
|
|
@ -5,3 +5,4 @@ STL_Extension
|
|||
Algebraic_foundations
|
||||
Circulator
|
||||
Stream_support
|
||||
BGL
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
#include <CGAL/basic.h>
|
||||
#include <CGAL/Frechet_distance/internal/Frechet_distance.h>
|
||||
|
||||
#include <CGAL/Named_function_parameters.h>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
namespace CGAL
|
||||
|
|
@ -29,24 +31,37 @@ namespace CGAL
|
|||
* \ingroup PkgFrechetDistanceFunctions
|
||||
* determines if the Frechet distance between two polylines is larger than a given distance.
|
||||
*
|
||||
* \tparam Traits a model of `FrechetDistanceTraits`
|
||||
* \tparam PointRange a model of the concept `RandomAccessContainer` with `Traits::Point_d` as value type.
|
||||
* \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
|
||||
*
|
||||
* \param polyline1 the first polyline defined by a sequence of consecutive points
|
||||
* \param polyline2 the second polyline defined by a sequence of consecutive points
|
||||
* \param distance the distance to compare against
|
||||
* \param traits the geometric traits object
|
||||
* \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below:
|
||||
*
|
||||
* \tparam Traits a model of `FrechetDistanceTraits`
|
||||
* \tparam force_filtering if `true`, interval arithmetic combined with exact rational will be used internally
|
||||
* \tparam PointRange a model of the concept `RandomAccessContainer`
|
||||
* with `Traits::Point_d` as value type.
|
||||
* \cgalNamedParamsBegin
|
||||
* \cgalParamNBegin{geom_traits}
|
||||
* \cgalParamDescription{an instance of a geometric traits class}
|
||||
* \cgalParamType{Traits}
|
||||
* \cgalParamDefault{`Traits()`}
|
||||
* \cgalParamNEnd
|
||||
* \cgalNamedParamsEnd
|
||||
*
|
||||
* \pre the polylines must not be empty
|
||||
* \pre the polylines must not be empty
|
||||
*/
|
||||
template < class Traits, bool force_filtering = false, class PointRange>
|
||||
template <class Traits, class PointRange, class NamedParameters = parameters::Default_named_parameters>
|
||||
bool is_Frechet_distance_larger(const PointRange& polyline1,
|
||||
const PointRange& polyline2,
|
||||
const double distance,
|
||||
const Traits& traits = Traits())
|
||||
const NamedParameters& np = parameters::default_values())
|
||||
{
|
||||
constexpr bool force_filtering =
|
||||
internal_np::Lookup_named_param_def<internal_np::force_filtering_t, NamedParameters, std::false_type>::type::value;
|
||||
|
||||
Traits traits = parameters::choose_parameter<Traits>(
|
||||
parameters::get_parameter(np, internal_np::geom_traits));
|
||||
|
||||
constexpr bool filtered = force_filtering ||
|
||||
std::is_same_v<typename decltype(Frechet_distance_::internal::toCurve<force_filtering>(polyline1, traits))::IFT,
|
||||
Interval_nt<false>>;
|
||||
|
|
@ -65,27 +80,41 @@ bool is_Frechet_distance_larger(const PointRange& polyline1,
|
|||
* approximates the Fréchet distance between two polylines up to an additive error
|
||||
* of `precision`.
|
||||
*
|
||||
* \tparam Traits a model of `FrechetDistanceTraits`
|
||||
* \tparam PointRange a model of the concept `RandomAccessContainer` with `Traits::Point_d` as value type.
|
||||
* \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
|
||||
*
|
||||
* \param polyline1 the first polyline defined by a sequence of consecutive points
|
||||
* \param polyline2 the second polyline defined by a sequence of consecutive points
|
||||
* \param precision the precision of the approximation
|
||||
* \param traits the geometric traits object
|
||||
* \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below:
|
||||
*
|
||||
* \tparam Traits a model of `FrechetDistanceTraits`
|
||||
* \tparam force_filtering if `true`, interval arithmetic combined with exact rational will be used internally
|
||||
* \tparam PointRange a model of the concept `RandomAccessContainer`
|
||||
* with `Traits::Point_d` as value type.
|
||||
* \cgalNamedParamsBegin
|
||||
* \cgalParamNBegin{geom_traits}
|
||||
* \cgalParamDescription{an instance of a geometric traits class}
|
||||
* \cgalParamType{Traits}
|
||||
* \cgalParamDefault{`Traits()`}
|
||||
* \cgalParamNEnd
|
||||
* \cgalNamedParamsEnd
|
||||
*
|
||||
* \pre the polylines must not be empty
|
||||
* \pre the polylines must not be empty
|
||||
*
|
||||
* @return an interval enclosing the exact result, the difference between the upper and
|
||||
* the lower bound being less than `precision`.
|
||||
*/
|
||||
template <class Traits, bool force_filtering = false, class PointRange>
|
||||
template <class Traits, class PointRange, class NamedParameters = parameters::Default_named_parameters>
|
||||
std::pair<double,double> approximate_Frechet_distance(const PointRange& polyline1,
|
||||
const PointRange& polyline2,
|
||||
const double precision,
|
||||
const Traits& traits = Traits())
|
||||
const NamedParameters& np = parameters::default_values())
|
||||
{
|
||||
constexpr bool force_filtering =
|
||||
internal_np::Lookup_named_param_def<internal_np::force_filtering_t, NamedParameters, std::false_type>::type::value;
|
||||
|
||||
Traits traits = parameters::choose_parameter<Traits>(
|
||||
parameters::get_parameter(np, internal_np::geom_traits));
|
||||
|
||||
|
||||
constexpr bool filtered = force_filtering ||
|
||||
std::is_same_v<typename decltype(Frechet_distance_::internal::toCurve<force_filtering>(polyline1, traits))::IFT,
|
||||
Interval_nt<false>>;
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ auto FrechetDistanceNearNeighborsDS<PointRange, Traits>::get_close_curves(
|
|||
|
||||
auto predicate = [&](PolylineID id) {
|
||||
CGAL_assertion(id < curves.size());
|
||||
return is_Frechet_distance_larger<Traits, false, PointRange>(
|
||||
return is_Frechet_distance_larger<Traits>(
|
||||
curve, curves[id], distance);
|
||||
};
|
||||
auto new_end = std::remove_if(result.begin(), result.end(), predicate);
|
||||
|
|
|
|||
|
|
@ -53,16 +53,18 @@ struct MinimalFrechetTraits {
|
|||
|
||||
int main()
|
||||
{
|
||||
namespace params = CGAL::parameters;
|
||||
|
||||
{
|
||||
using Traits = MinimalFrechetTraits<double>;
|
||||
std::vector<Traits::Point_d> curve;
|
||||
/* bool decision = */ CGAL::is_Frechet_distance_larger<Traits, true>(curve, curve, 0.1);
|
||||
/* bool decision = */ CGAL::is_Frechet_distance_larger<Traits>(curve, curve, 0.1, params::force_filtering(std::true_type()));
|
||||
}
|
||||
|
||||
{
|
||||
using Traits = MinimalFrechetTraits<CGAL::Exact_rational>;
|
||||
std::vector<Traits::Point_d> curve;
|
||||
/* bool decision = */ CGAL::is_Frechet_distance_larger<Traits, true>(curve, curve, 0.1);
|
||||
/* bool decision = */ CGAL::is_Frechet_distance_larger<Traits>(curve, curve, 0.1, params::force_filtering(std::true_type()));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ static FrechetDistanceNearNeighborsDSQueries readFrechetDistanceNearNeighborsDSQ
|
|||
template<bool force_filtering=false>
|
||||
static double testFrechetDistance()
|
||||
{
|
||||
namespace params = CGAL::parameters;
|
||||
std::string curve_directory = "./data/curves/";
|
||||
std::string query_directory = "./data/queries/";
|
||||
std::vector<std::string> datasets;
|
||||
|
|
@ -181,8 +182,9 @@ static double testFrechetDistance()
|
|||
*/
|
||||
timer.start();
|
||||
auto decision =
|
||||
! CGAL::is_Frechet_distance_larger<TestTraits, force_filtering>(
|
||||
curves[query.id1], curves[query.id2], query.distance);
|
||||
! CGAL::is_Frechet_distance_larger<TestTraits>(
|
||||
curves[query.id1], curves[query.id2], query.distance,
|
||||
params::force_filtering(std::bool_constant<force_filtering>()));
|
||||
timer.stop();
|
||||
|
||||
if (decision != query.decision) {
|
||||
|
|
|
|||
|
|
@ -178,6 +178,7 @@ CGAL_add_named_parameter(do_lock_mesh_t, do_lock_mesh, do_lock_mesh)
|
|||
CGAL_add_named_parameter(do_simplify_border_t, do_simplify_border, do_simplify_border)
|
||||
CGAL_add_named_parameter(algorithm_t, algorithm, algorithm)
|
||||
CGAL_add_named_parameter(use_smoothing_t, use_smoothing, use_smoothing)
|
||||
CGAL_add_named_parameter(force_filtering_t, force_filtering, force_filtering)
|
||||
|
||||
//internal
|
||||
CGAL_add_named_parameter(weight_calculator_t, weight_calculator, weight_calculator)
|
||||
|
|
|
|||
Loading…
Reference in New Issue