mirror of https://github.com/CGAL/cgal
Merge pull request #3806 from afabri/Polyline_simplification-Fix_for_projection_traits-GF
Polyline_simplification_2: Fix for Projection_traits_xy_3
This commit is contained in:
commit
ea20dfd63f
|
|
@ -248,6 +248,8 @@ public:
|
|||
typedef typename R::Point_2 Point_2;
|
||||
typedef typename R::Line_3 Line_3;
|
||||
typedef typename R::Line_2 Line_2;
|
||||
typedef typename R::Segment_3 Segment_3;
|
||||
typedef typename R::Segment_2 Segment_2;
|
||||
typedef typename R::FT RT;
|
||||
typename R::FT x(const Point_3 &p) const { return Projector<R,dim>::x(p); }
|
||||
typename R::FT y(const Point_3 &p) const { return Projector<R,dim>::y(p); }
|
||||
|
|
@ -270,6 +272,13 @@ public:
|
|||
Line_2 l2(project(l.point(0)), project(l.point(1)));
|
||||
return squared_distance(p2, l2);
|
||||
}
|
||||
|
||||
RT operator()(const Segment_3& s, const Point_3& p) const
|
||||
{
|
||||
Point_2 p2(project(p));
|
||||
Segment_2 s2(project(s.source()), project(s.target()));
|
||||
return squared_distance(p2, s2);
|
||||
}
|
||||
};
|
||||
|
||||
template <class R,int dim>
|
||||
|
|
|
|||
|
|
@ -196,6 +196,12 @@ At the end we remove the points that were kept from the constraints.
|
|||
|
||||
\cgalExample{Polyline_simplification_2/points_and_vertices.cpp}
|
||||
|
||||
\subsection Subsection_PolylineSimplification_Terrain Simplification of a Terrain
|
||||
|
||||
It is possible to use the class `Projection_traits_xy_3` in order to simplify polylines in space.
|
||||
Note that the segment length is computed in the xy-plane, and the polyline must not have any vertical segment.
|
||||
|
||||
\cgalExample{Polyline_simplification_2/simplify_terrain.cpp}
|
||||
|
||||
\section Section_PolylineSimplification_History Design and Implementation History
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
/*!
|
||||
\example Polyline_simplification_2/simplify_polygon.cpp
|
||||
\example Polyline_simplification_2/simplify.cpp
|
||||
\example Polyline_simplification_2/simplify_terrain.cpp
|
||||
\example Polyline_simplification_2/points_and_vertices.cpp
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
4 0 0 0 1 0 0 2 4 0 3 10 0
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
#include <iostream>
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Projection_traits_xy_3.h>
|
||||
#include <CGAL/Polygon_2.h>
|
||||
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
|
||||
#include <CGAL/Constrained_triangulation_plus_2.h>
|
||||
#include <CGAL/Polyline_simplification_2/simplify.h>
|
||||
#include <CGAL/Polyline_simplification_2/Squared_distance_cost.h>
|
||||
|
||||
namespace PS = CGAL::Polyline_simplification_2;
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Epic;
|
||||
typedef CGAL::Projection_traits_xy_3<Epic> K;
|
||||
typedef CGAL::Polygon_2<K> Polygon_2;
|
||||
|
||||
typedef PS::Vertex_base_2<K> Vb;
|
||||
typedef CGAL::Constrained_triangulation_face_base_2<K> Fb;
|
||||
typedef CGAL::Triangulation_data_structure_2<Vb, Fb> TDS;
|
||||
typedef CGAL::Constrained_Delaunay_triangulation_2<K, TDS, CGAL::Exact_predicates_tag> CDT;
|
||||
typedef CGAL::Constrained_triangulation_plus_2<CDT> CT;
|
||||
typedef CT::Point Point;
|
||||
typedef CT::Constraint_iterator Constraint_iterator;
|
||||
typedef CT::Vertices_in_constraint_iterator Vertices_in_constraint_iterator;
|
||||
typedef CT::Points_in_constraint_iterator Points_in_constraint_iterator;
|
||||
typedef PS::Stop_below_count_ratio_threshold Stop;
|
||||
typedef PS::Squared_distance_cost Cost;
|
||||
|
||||
int main()
|
||||
{
|
||||
CT ct;
|
||||
Polygon_2 P;
|
||||
while(std::cin >> P){
|
||||
ct.insert_constraint(P);
|
||||
}
|
||||
PS::simplify(ct, Cost(), Stop(0.5));
|
||||
|
||||
for(Constraint_iterator cit = ct.constraints_begin();
|
||||
cit != ct.constraints_end();
|
||||
++cit) {
|
||||
std::cout << "simplified polyline" << std::endl;
|
||||
for(Points_in_constraint_iterator vit =
|
||||
ct.points_in_constraint_begin(*cit);
|
||||
vit != ct.points_in_constraint_end(*cit);
|
||||
++vit)
|
||||
std::cout << *vit << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue