49 uniform_real_distribution<double> dist(-noise, noise);
52 for (
size_t i = 0; i < n; ++i)
54 double angle = 2.0 * M_PI * i / n;
55 double r = radius + dist(
rng);
67 cout <<
"Original: " << orig_verts.size() <<
" vertices" << endl;
76 cout <<
"DP mild: " << dpv_mild.size() <<
" vertices" << endl;
77 cout <<
"DP aggressive: " << dpv_aggr.size() <<
" vertices" << endl;
86 cout <<
"VW mild: " << vwv_mild.size() <<
" vertices" << endl;
87 cout <<
"VW aggressive: " << vwv_aggr.size() <<
" vertices" << endl;
92 for (
size_t i = 0; i < sub.size(); ++i)
95 for (
size_t j = 0; j < orig_verts.size(); ++j)
96 if (orig_verts(j) == sub(i))
97 { found =
true;
break; }
98 assert(found &&
"Simplified vertex not in original");
105 cout <<
"All simplified vertices are subsets of original. OK" << endl;
108 ofstream tex(
"polygon_simplification_output.tex");
109 tex <<
"\\documentclass[border=5mm]{standalone}\n"
110 <<
"\\usepackage{tikz}\n"
111 <<
"\\usepackage{subcaption}\n"
112 <<
"\\begin{document}\n"
113 <<
"\\begin{figure}\n";
115 auto draw_subfig = [&](
const char * caption,
const Polygon & simplified)
119 tex <<
"\\begin{minipage}{0.45\\textwidth}\\centering\n";
121 tex <<
"\\captionof{subfigure}{" << caption <<
"}\n"
122 <<
"\\end{minipage}\\hfill\n";
125 draw_subfig(
"Original (40 pts)", original);
126 draw_subfig(
"DP mild (eps=0.5)", dp_mild);
127 tex <<
"\n\\medskip\n\n";
128 draw_subfig(
"DP aggressive (eps=3)", dp_aggressive);
129 draw_subfig(
"VW aggressive (area=10)", vw_aggressive);
131 tex <<
"\\end{figure}\n"
132 <<
"\\end{document}\n";
134 cout <<
"TikZ output written to polygon_simplification_output.tex" << endl;
Simple dynamic array with automatic resizing and functional operations.
Douglas-Peucker polyline simplification.
Polygon simplify_polygon(const Polygon &poly, const Geom_Number &epsilon) const
Simplify a closed polygon.
static Array< Point > extract_vertices(const Polygon &poly)
Extract vertices from a polygon into an array for indexed access.
Represents a point with rectangular coordinates in a 2D plane.
A general (irregular) 2D polygon defined by a sequence of vertices.
void add_vertex(const Point &point)
Add a vertex to the polygon.
void close()
Close the polygon.
2D TikZ canvas storing geometry objects and emitting LaTeX output.
void draw(std::ostream &output, const bool squarize=true) const
Emit a complete tikzpicture with all inserted objects.
Visvalingam-Whyatt polyline simplification.
static Polygon simplify_polygon(const Polygon &poly, const Geom_Number &area_threshold)
Simplify a closed polygon.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_cos_function > > cos(const __gmp_expr< T, U > &expr)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_sin_function > > sin(const __gmp_expr< T, U > &expr)
Main namespace for Aleph-w library functions.
void put_simplification_result(Tikz_Plane &plane, const Polygon &original, const Polygon &simplified, const Tikz_Style &original_style=tikz_wire_style("gray!50"), const Tikz_Style &simplified_style=tikz_bold_wire_style("blue!80"), const bool draw_vertices=true, const Tikz_Style &vertex_style=tikz_points_style("red"))
Draw original and simplified polygons overlaid.
mpq_class Geom_Number
Numeric type used by the geometry module.
static Polygon make_noisy_circle(size_t n, double radius, double noise, unsigned seed=42)
Helpers to visualize computational-geometry algorithm results in TikZ.