Small changes plus a major bug fix (unless I misunderstood something)

The small changes make the models of distance function correspond to the concept

The bug:
The documentation of the distance functions states that one computes
a distance for the points on the original subcurve. Before the
fix we only looked at the points which are in the current subcurve.
This commit is contained in:
Andreas Fabri 2014-08-08 16:39:17 +02:00
parent 52e0f095dc
commit f31854ab1d
6 changed files with 67 additions and 51 deletions

View File

@ -24,7 +24,7 @@ public:
/*!
Given three consecutive polyline vertices `*vip, *viq, *vir`, calculates the cost of removing vertex `*viq`, replacing edges `(*vip,*viq)` and `(*viq,*vir)` with edge `(*vip,*vir)`.
\param pct The underlying polyline constrained triangulation which embeds the polyline set.
\param pct The underlying constrained triangulation which embeds the polyline set.
\param vip The first vertex
\param viq The second vertex
\param vir The third vertex
@ -32,11 +32,11 @@ Given three consecutive polyline vertices `*vip, *viq, *vir`, calculates the cos
`Tr::Geom_traits` must provide a functor `Compute_squared_distance` with an operator `Tr::Geom_traits::FT operator()(Tr::Point, Tr::Point)`.
*/
boost::optional<Polyline_constrained_triangulation_2<Tr>::Geom_traits::FT>
operator()(Polyline_constrained_triangulation_2<Tr> const& pct,
Polyline_constrained_triangulation_2<Tr>::Vertices_in_constraint_iterator vip,
Polyline_constrained_triangulation_2<Tr>::Vertices_in_constraint_iterator viq,
Polyline_constrained_triangulation_2<Tr>::Vertices_in_constraint_iterator vir) const;}
boost::optional<Constrained_triangulation_plus_2<Tr>::Geom_traits::FT>
operator()(Constrained_triangulation_plus_2<Tr> const& pct,
Constrained_triangulation_plus_2<Tr>::Vertices_in_constraint_iterator vip,
Constrained_triangulation_plus_2<Tr>::Vertices_in_constraint_iterator viq,
Constrained_triangulation_plus_2<Tr>::Vertices_in_constraint_iterator vir) const;}
}; /* end TriangulationVertexBase_2 */

View File

@ -3,7 +3,7 @@
\ingroup PkgPolylineSimplification2Concepts
\cgalConcept
Thr polyline simplification algorithm stores in the vertices
The polyline simplification algorithm stores in the vertices
whether a vertex can be removed, and the cost of the removal.
\cgalRefines `TriangulationVertexBase_2`
@ -15,7 +15,7 @@ Defines the same types as the `TriangulationVertexBase_2` concept
\cgalHasModel `CGAL::Polyline_simplification_2::Vertex_base_2<Vb>`
\sa `TriangulationFaceBase_2`
\sa `CGAL::Polyline_constrained_triangulation_2<CDT>`
\sa `CGAL::Constrained_triangulation_plus_2<Tr>`
*/

View File

@ -41,21 +41,22 @@ public:
/// Initializes the cost function with the specified `ratio`
Hybrid_squared_distance_cost( FT ratio ) : mSquaredRatio(ratio*ratio) {}
/// Returns the maximal square distances between each point along the original subpolyline,
/// given by the range `[original_subpolyline_vertices_begin,original_subpolyline_vertices_end)`,
/// Returns the maximal square distance between each point along the original subpolyline,
/// between `p` and `r`,
/// and the straight line segment `p->r` divided by the smallest of
/// - the square of the ratio given to the constructor of the cost function,
/// - and the shortest squared distance between that segment and each of the vertices adjacent to `q`.
template<class PolylineConstraintTriangulation, class CVI>
boost::optional<typename PolylineConstraintTriangulation::Geom_traits::FT>
operator()( PolylineConstraintTriangulation const& pct
, CVI p
, CVI q
, CVI r) const
template<class Tr>
boost::optional<typename CGAL::Constrained_triangulation_plus_2<Tr>::Geom_traits::FT>
operator()( const CGAL::Constrained_triangulation_plus_2<Tr>& pct
, typename CGAL::Constrained_triangulation_plus_2<Tr>::Vertices_in_constraint_iterator p
, typename CGAL::Constrained_triangulation_plus_2<Tr>::Vertices_in_constraint_iterator q
, typename CGAL::Constrained_triangulation_plus_2<Tr>::Vertices_in_constraint_iterator r) const
{
typedef typename PolylineConstraintTriangulation::Vertex_handle Vertex_handle;
typedef typename PolylineConstraintTriangulation::Vertex_circulator Vertex_circulator;
typedef typename PolylineConstraintTriangulation::Geom_traits Geom_traits ;
typedef typename CGAL::Constrained_triangulation_plus_2<Tr>::Points_in_constraint_iterator Points_in_constraint_iterator;
typedef typename CGAL::Constrained_triangulation_plus_2<Tr>::Vertex_handle Vertex_handle;
typedef typename CGAL::Constrained_triangulation_plus_2<Tr>::Vertex_circulator Vertex_circulator;
typedef typename CGAL::Constrained_triangulation_plus_2<Tr>::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;
@ -71,10 +72,11 @@ public:
Segment lP_R = construct_segment(lP, lR) ;
FT d1 = 0.0;
++p;
Points_in_constraint_iterator pp(p), rr(r);
++pp;
for ( ;p != r; ++p )
d1 = (std::max)(d1, compute_squared_distance( lP_R, (*p)->point() ) ) ;
for ( ;pp != rr; ++pp )
d1 = (std::max)(d1, compute_squared_distance( lP_R, *pp ) ) ;
FT d2 = (std::numeric_limits<double>::max)() ;

View File

@ -39,20 +39,21 @@ public:
/// Initializes the cost function.
Scaled_squared_distance_cost() {}
/// Returns the maximal square distances between each point along the original subpolyline,
/// given by the range `[original_subpolyline_vertices_begin,original_subpolyline_vertices_end)`,
/// Returns the maximum of the square distances between each point along the original subpolyline
/// between `p` and `r`,
/// and the straight line segment `p->r` divided by the shortest squared distance between
/// that segment and each of the vertices adjacent to `q`.
template<class PolylineConstraintTriangulation, class CVI>
boost::optional<typename PolylineConstraintTriangulation::Geom_traits::FT>
operator()( PolylineConstraintTriangulation const& pct
, CVI p
, CVI q
, CVI r) const
template<class Tr>
boost::optional<typename CGAL::Constrained_triangulation_plus_2<Tr>::Geom_traits::FT>
operator()(const CGAL::Constrained_triangulation_plus_2<Tr>& pct
, typename CGAL::Constrained_triangulation_plus_2<Tr>::Vertices_in_constraint_iterator p
, typename CGAL::Constrained_triangulation_plus_2<Tr>::Vertices_in_constraint_iterator q
, typename CGAL::Constrained_triangulation_plus_2<Tr>::Vertices_in_constraint_iterator r) const
{
typedef typename PolylineConstraintTriangulation::Vertex_handle Vertex_handle;
typedef typename PolylineConstraintTriangulation::Vertex_circulator Vertex_circulator;
typedef typename PolylineConstraintTriangulation::Geom_traits Geom_traits ;
typedef typename CGAL::Constrained_triangulation_plus_2<Tr>::Points_in_constraint_iterator Points_in_constraint_iterator;
typedef typename CGAL::Constrained_triangulation_plus_2<Tr>::Vertex_handle Vertex_handle;
typedef typename CGAL::Constrained_triangulation_plus_2<Tr>::Vertex_circulator Vertex_circulator;
typedef typename CGAL::Constrained_triangulation_plus_2<Tr>::Geom_traits Geom_traits ;
typedef typename Geom_traits::FT FT;
typedef typename Geom_traits::Compute_squared_distance_2 Compute_squared_distance;
typedef typename Geom_traits::Construct_segment_2 Construct_segment;
@ -68,10 +69,11 @@ public:
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() ) ) ;
Points_in_constraint_iterator pp(p), rr(r);
++pp;
for ( ;pp != rr; ++pp )
d1 = (std::max)(d1, compute_squared_distance( lP_R, *pp ) ) ;
double d2 = (std::numeric_limits<double>::max)() ;

View File

@ -23,6 +23,13 @@
namespace CGAL {
#ifndef DOXYGEN_RUNNING
template < class Tr >
class Constrained_triangulation_plus_2;
#endif
namespace Polyline_simplification_2
{
@ -39,19 +46,18 @@ public:
/// Initializes the cost function
Squared_distance_cost() {}
/// Returns the maximal square distances between each point along the original subpolyline,
/// given by the range `[original_subpolyline_vertices_begin,original_subpolyline_vertices_end)`,
/// and the straight line segment `p->r`.
/// Returns the maximum of the square distances between each point along the original subpolyline,
/// between `p` and `r`, and the straight line segment `p->r`.
template<class PolylineConstraintTriangulation, class CVI>
boost::optional<typename PolylineConstraintTriangulation::Geom_traits::FT>
operator()( PolylineConstraintTriangulation const& pct
, CVI p
, CVI q
, CVI r) const
template<class Tr>
boost::optional<typename CGAL::Constrained_triangulation_plus_2<Tr>::Geom_traits::FT>
operator()(const CGAL::Constrained_triangulation_plus_2<Tr>& pct
, typename CGAL::Constrained_triangulation_plus_2<Tr>::Vertices_in_constraint_iterator p
, typename CGAL::Constrained_triangulation_plus_2<Tr>::Vertices_in_constraint_iterator q
, typename CGAL::Constrained_triangulation_plus_2<Tr>::Vertices_in_constraint_iterator r) const
{
typedef typename PolylineConstraintTriangulation::Geom_traits Geom_traits ;
typedef typename CGAL::Constrained_triangulation_plus_2<Tr>::Points_in_constraint_iterator Points_in_constraint_iterator;
typedef typename CGAL::Constrained_triangulation_plus_2<Tr>::Geom_traits Geom_traits ;
typedef typename Geom_traits::FT FT;
typedef typename Geom_traits::Compute_squared_distance_2 Compute_squared_distance ;
typedef typename Geom_traits::Construct_segment_2 Construct_segment ;
@ -67,10 +73,11 @@ public:
Segment lP_R = construct_segment(lP, lR) ;
FT d1 = 0.0;
++p;
Points_in_constraint_iterator pp(p), rr(r);
++pp;
for ( ;p != r; ++p )
d1 = (std::max)(d1, compute_squared_distance( lP_R, (*p)->point() ) ) ;
for ( ;pp != rr; ++pp )
d1 = (std::max)(d1, compute_squared_distance( lP_R, *pp ) ) ;
return d1 ;
}

View File

@ -22,9 +22,14 @@
namespace CGAL {
#ifndef DOXYGEN_RUNNING
template < class Tr >
class Constrained_triangulation_plus_2;
#endif
namespace Polyline_simplification_2 {
/*!