Merge remote-tracking branch 'cgal/5.2.x-branch'

This commit is contained in:
Sébastien Loriot 2021-06-25 10:05:19 +02:00
commit bdec4360d3
4 changed files with 98 additions and 11 deletions

View File

@ -267,24 +267,29 @@ public:
}
inline Line_2 line() const
inline const Line_2& line() const
{
return l;
}
inline Point_2 center() const
inline const Point_2& center() const
{
return c;
}
inline const Point_2& origin() const
{
return o;
}
template< class Stream >
void draw(Stream& W) const
{
std::vector< Point_2 > p;
std::vector< Point_2 > pleft, pright;
pleft.push_back(o);
pright.push_back(o);
pleft.push_back(origin());
pright.push_back(origin());
const FT STEP(2);
for (int i = 1; i <= 100; i++) {
p = compute_points(i * i * STEP);
@ -311,7 +316,7 @@ public:
W << Segment_2(pright[i], pright[i+1]);
}
W << o;
W << origin();
}
};

View File

@ -26,6 +26,7 @@ endif()
# Creating entries for all .cpp/.C files with "main" routine
# ##########################################################
create_single_source_cgal_program("simplify_polygon_test.cpp")
create_single_source_cgal_program( "issue-5774.cpp" )
create_single_source_cgal_program( "simplify_polygon_test.cpp" )
create_single_source_cgal_program("simplify_polyline_with_duplicate_points.cpp")
create_single_source_cgal_program( "simplify_polyline_with_duplicate_points.cpp" )

View File

@ -0,0 +1,78 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyline_simplification_2/simplify.h>
#include <iostream>
#include <string>
#include <vector>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Point_2<K> Point;
typedef std::vector<Point> Polyline_2;
namespace PS = CGAL::Polyline_simplification_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 PS::Stop_below_count_ratio_threshold Stop;
typedef PS::Squared_distance_cost Cost;
void print_coords(Polyline_2 polyline) {
std::cout << std::endl;
std::cout << "Simplified coordinates:" << std::endl << std::endl;
// Print out the simplified coordinates
unsigned int i = 0;
for (Point coord : polyline) {
std::cout << "[ ";
std::cout << coord.x();
std::cout << ", ";
std::cout << coord.y();
std::cout << " ]";
if (i != polyline.size() - 1) std::cout << ",";
i++;
}
std::cout << std::endl << std::endl;
}
void simplify_test() {
// Hard code a minimum working example where running PS::simplify results in
// self-intersections. There are no self-intersections when {27, 9} is
// omitted.
std::vector<std::vector<int>> coords = {
{64, 20}, {33, 27}, {27, 9}, {33, 18}, {44, 18}, {44, 8},
{24, 0}, {0, 13}, {9, 49}, {84, 41}, {83, 29}, {64, 20},
};
// Simplification outputs:
// [ 64, 20 ],[ 27, 9 ],[ 44, 18 ],[ 24, 0 ],
// [ 9, 49 ],[ 83, 29 ],[ 64, 20 ],[ 64, 20 ]
// Create polyline for simplifying later
Polyline_2 polyline;
// Insert coordinates into polyline
for (std::vector<int> coord : coords) {
Point pt(coord[0], coord[1]);
polyline.push_back(pt);
}
// Insert polyline into ct and run simplify()
CT ct;
ct.insert_constraint(polyline.begin(), polyline.end());
PS::simplify(ct, Cost(), Stop(0.2));
Polyline_2 polyline_simplified;
// Transfer simplified coordinates from ct to polyline for easy handling
auto cit = ct.constraints_begin();
for (auto vit = ct.points_in_constraint_begin(*cit);
vit != ct.points_in_constraint_end(*cit); vit++) {
polyline_simplified.push_back(*vit);
}
print_coords(polyline_simplified);
assert(polyline_simplified.size() == 4);
}
int main() {
simplify_test();
}

View File

@ -46,12 +46,13 @@ private:
class Node {
public:
explicit Node(Vertex_handle vh, bool input = false)
: vertex_(vh), input(input)
: vertex_(vh), point_(vertex_->point()), input(input)
{}
const Point& point() const { return vertex_->point(); }
const Point& point() const { return point_; }
Vertex_handle vertex() const { return vertex_; }
private:
Vertex_handle vertex_;
Point point_;
public:
bool input;
};
@ -69,7 +70,7 @@ public:
>
{
public:
Point_it() : Vertex_it::iterator_adaptor_() {}
Point_it() : Point_it::iterator_adaptor_() {}
Point_it(typename Vertex_list::all_iterator it) : Point_it::iterator_adaptor_(it) {}
private:
friend class boost::iterator_core_access;
@ -645,10 +646,12 @@ Polyline_constraint_hierarchy_2<T,Compare,Point>::remove_points_without_correspo
{
std::size_t n = 0;
for(Point_it it = points_in_constraint_begin(cid);
it != points_in_constraint_end(cid); ++it) {
it != points_in_constraint_end(cid);) {
if(cid.vl_ptr()->is_skipped(it.base())) {
it = cid.vl_ptr()->erase(it.base());
++n;
}else{
++it;
}
}
return n;