mirror of https://github.com/CGAL/cgal
Add an error function for polyline simplification
This commit is contained in:
parent
4f268bfcde
commit
271f52dbd4
|
|
@ -0,0 +1,86 @@
|
||||||
|
// Copyright (c) 2012 INRIA Sophia-Antipolis (France).
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// This file is part of CGAL (www.cgal.org).
|
||||||
|
// You can redistribute it and/or modify it under the terms of the GNU
|
||||||
|
// General Public License as published by the Free Software Foundation,
|
||||||
|
// either version 3 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Licensees holding a valid commercial license may use this file in
|
||||||
|
// accordance with the commercial license agreement provided with the software.
|
||||||
|
//
|
||||||
|
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||||
|
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
//
|
||||||
|
// $URL$
|
||||||
|
// $Id$
|
||||||
|
//
|
||||||
|
// Author(s) : Fernando Cacciola <fernando.cacciola@geometryfactory.com>
|
||||||
|
//
|
||||||
|
#ifndef CGAL_POLYLINE_SIMPLIFICATION_2_SQUARED_DISTANCE_COST_H
|
||||||
|
#define CGAL_POLYLINE_SIMPLIFICATION_2_SQUARED_DISTANCE_COST_H
|
||||||
|
|
||||||
|
#include <CGAL/squared_distance_2.h>
|
||||||
|
|
||||||
|
namespace CGAL {
|
||||||
|
|
||||||
|
namespace Polyline_simplification_2
|
||||||
|
{
|
||||||
|
|
||||||
|
/// This class is a cost function which calculates the cost as the square of the distance between the original and simplified polylines.
|
||||||
|
///
|
||||||
|
/// @heading Is Model for the Concepts: 'PolylineSimplificationCostFunction'.
|
||||||
|
template<class FT>
|
||||||
|
class Squared_distance_cost
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/// Initializes the cost function
|
||||||
|
Squared_distance_cost() {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<class PolylineConstraintTriangulation, class CVI>
|
||||||
|
boost::optional<FT> operator()( PolylineConstraintTriangulation const& pct
|
||||||
|
, CVI p
|
||||||
|
, CVI q
|
||||||
|
, CVI r) const
|
||||||
|
{
|
||||||
|
|
||||||
|
typedef typename PolylineConstraintTriangulation::Geom_traits Geom_traits ;
|
||||||
|
|
||||||
|
typedef typename Geom_traits::Compute_squared_distance_2 Compute_squared_distance ;
|
||||||
|
typedef typename Geom_traits::Construct_segment_2 Construct_segment ;
|
||||||
|
typedef typename Geom_traits::Segment_2 Segment ;
|
||||||
|
typedef typename Geom_traits::Point_2 Point ;
|
||||||
|
|
||||||
|
Compute_squared_distance compute_squared_distance = pct.geom_traits().compute_squared_distance_2_object() ;
|
||||||
|
Construct_segment construct_segment = pct.geom_traits().construct_segment_2_object() ;
|
||||||
|
|
||||||
|
Point const& lP = p->point;
|
||||||
|
Point const& lR = r->point;
|
||||||
|
|
||||||
|
Segment lP_R = construct_segment(lP, lR) ;
|
||||||
|
|
||||||
|
FT d1 = 0.0;
|
||||||
|
++p;
|
||||||
|
|
||||||
|
for ( ;p != r; ++p )
|
||||||
|
d1 = (std::max)(d1, compute_squared_distance( lP_R, p->point ) ) ;
|
||||||
|
|
||||||
|
return d1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Polyline_simplification_2
|
||||||
|
|
||||||
|
|
||||||
|
} //namespace CGAL
|
||||||
|
|
||||||
|
#endif // CGAL_POLYLINE_SIMPLIFICATION_2_SQUARED_DISTANCE_COST_H
|
||||||
|
// EOF //
|
||||||
|
|
||||||
Loading…
Reference in New Issue