Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tikz_funnel_animation_example.cc
Go to the documentation of this file.
1#include <fstream>
2#include <iostream>
3#include <string>
4
6
7using namespace Aleph;
8
9namespace
10{
11
13{
14 Polygon p;
15 p.add_vertex(Point(0, 0));
16 p.add_vertex(Point(24, 0));
17 p.add_vertex(Point(24, 20));
18 p.add_vertex(Point(14, 20));
19 p.add_vertex(Point(14, 8));
20 p.add_vertex(Point(10, 8));
21 p.add_vertex(Point(10, 20));
22 p.add_vertex(Point(0, 20));
23 p.close();
24 return p;
25}
26
27} // namespace
28
29int main(int argc, char * argv[])
30{
31 const std::string output_path =
32 argc > 1 ? argv[1] : "tikz_funnel_animation_example.tex";
33
34 std::ofstream out(output_path);
35 if (not out)
36 {
37 std::cerr << "Cannot open output file: " << output_path << '\n';
38 return 1;
39 }
40
41 const Polygon polygon = make_funnel_polygon();
42 const Point source(2, 16);
43 const Point target(22, 16);
44
46 compute_shortest_path_funnel_trace(polygon, source, target);
47
48 out << "\\documentclass[a4paper]{article}\n"
49 << "\\usepackage[margin=12mm]{geometry}\n"
50 << "\\usepackage{tikz}\n"
51 << "\\pagestyle{empty}\n"
52 << "\\begin{document}\n\n";
53
54 if (trace.steps.size() == 0)
55 {
56 Tikz_Plane frame(210, 115, 6, 6);
57 frame.put_cartesian_axis();
58 frame.set_point_radius_mm(0.75);
59
61 frame, polygon, source, target, ShortestPathInPolygon());
62
64 Text(Point(-1, 22),
65 "No funnel iterations (direct/degenerate case), portals=" +
66 std::to_string(debug.portals.size())),
67 make_tikz_draw_style("black"),
69
70 frame.draw(out, true);
71 out << "\n";
72 }
73 else
74 {
75 for (size_t i = 0; i < trace.steps.size(); ++i)
76 {
77 Tikz_Plane frame(210, 115, 6, 6);
78 frame.put_cartesian_axis();
79 frame.set_point_radius_mm(0.75);
80
82 frame,
83 polygon,
84 source,
85 target,
86 trace,
87 i,
88 tikz_area_style("black", "gray!15", 0.22),
89 tikz_points_style("green!50!black"),
90 tikz_points_style("blue"),
91 tikz_wire_style("purple", true),
92 tikz_path_style("purple"),
93 tikz_path_style("orange!90!black"),
94 tikz_path_style("red"),
95 true,
96 tikz_points_style("red"));
97
98 const FunnelTraceStep & step = trace.steps(i);
99 std::string event = "tighten";
100 if (step.emitted_left) event = "emit-left";
101 else if (step.emitted_right) event = "emit-right";
102 else if (step.tightened_left and step.tightened_right) event = "tighten-both";
103 else if (step.tightened_left) event = "tighten-left";
104 else if (step.tightened_right) event = "tighten-right";
105
107 Text(Point(-1, 22),
108 "Funnel step " + std::to_string(i + 1) +
109 "/" + std::to_string(trace.steps.size()) +
110 ", portal=" + std::to_string(step.portal_index) +
111 ", event=" + event),
112 make_tikz_draw_style("black"),
114
115 frame.draw(out, true);
116
117 if (i + 1 < trace.steps.size())
118 out << "\n\\newpage\n\n";
119 }
120
121 out << "\n\\newpage\n\n";
122
123 Tikz_Plane final_frame(210, 115, 6, 6);
124 final_frame.put_cartesian_axis();
125 final_frame.set_point_radius_mm(0.75);
126
128 final_frame, polygon, source, target, ShortestPathInPolygon());
129
131 Text(Point(-1, 22),
132 "Final shortest path with portals: path nodes=" +
133 std::to_string(debug.path.size())),
134 make_tikz_draw_style("black"),
136
137 final_frame.draw(out, true);
138 out << "\n";
139 }
140
141 out << "\\end{document}\n";
142
143 std::cout << "Generated " << output_path << '\n'
144 << "Frames: " << trace.steps.size() << " + final summary page" << '\n'
145 << "Compile with: pdflatex " << output_path << '\n';
146
147 return 0;
148}
Represents a point with rectangular coordinates in a 2D plane.
Definition point.H:229
A general (irregular) 2D polygon defined by a sequence of vertices.
Definition polygon.H:246
void add_vertex(const Point &point)
Add a vertex to the polygon.
Definition polygon.H:677
void close()
Close the polygon.
Definition polygon.H:840
Compute the shortest Euclidean path between two points inside a simple polygon.
Represents a text string positioned at a 2D point.
Definition point.H:2739
2D TikZ canvas storing geometry objects and emitting LaTeX output.
Definition tikzgeom.H:184
static constexpr int Layer_Overlay
Definition tikzgeom.H:189
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
and
Check uniqueness with explicit hash + equality functors.
void put_in_plane(Tikz_Plane &plane, const Geom &geom_obj)
Insert any supported geometry type in a Tikz_Plane.
Definition tikzgeom.H:1456
void put_funnel_trace_step(Tikz_Plane &plane, const Polygon &polygon, const Point &source, const Point &target, const FunnelTraceResult &trace, size_t step_index, const Tikz_Style &polygon_style=tikz_area_style("black", "gray!15", 0.22), const Tikz_Style &source_style=tikz_points_style("green!50!black"), const Tikz_Style &target_style=tikz_points_style("blue"), const Tikz_Style &all_portals_style=tikz_wire_style("purple", true), const Tikz_Style &active_portal_style=tikz_path_style("purple"), const Tikz_Style &funnel_leg_style=tikz_path_style("orange!90!black"), const Tikz_Style &committed_style=tikz_path_style("red"), const bool draw_waypoints=true, const Tikz_Style &waypoint_style=tikz_points_style("red"), const int polygon_layer=Tikz_Plane::Layer_Default, const int portal_layer=Tikz_Plane::Layer_Foreground, const int highlight_layer=Tikz_Plane::Layer_Overlay)
Render one funnel-trace frame in a plane.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
ShortestPathDebugResult visualize_shortest_path_with_portals(Tikz_Plane &plane, const Polygon &polygon, const Point &source, const Point &target, const ShortestPathInPolygon &algorithm={}, const Tikz_Style &polygon_style=tikz_area_style("black", "gray!15", 0.25), const Tikz_Style &source_style=tikz_points_style("green!50!black"), const Tikz_Style &target_style=tikz_points_style("blue"), const Tikz_Style &portal_style=tikz_wire_style("purple", true), const Tikz_Style &path_style=tikz_path_style("red"), const bool draw_waypoints=true, const Tikz_Style &waypoint_style=tikz_points_style("red"), const int polygon_layer=Tikz_Plane::Layer_Default, const int portal_layer=Tikz_Plane::Layer_Foreground, const int path_layer=Tikz_Plane::Layer_Overlay)
Visualize the shortest path plus funnel portals.
Tikz_Style tikz_path_style(const std::string &color="red", const bool with_arrow=false)
Creates a style optimized for polyline paths.
Tikz_Style make_tikz_draw_style(const std::string &draw_color)
Create a basic draw style with a custom color.
Definition tikzgeom.H:156
Tikz_Style tikz_wire_style(const std::string &color="black", const bool dashed=false, const bool with_arrow=false)
Creates a style optimized for wireframe segments and polygons.
FunnelTraceResult compute_shortest_path_funnel_trace(const Polygon &polygon, const Point &source, const Point &target)
Compute a full SSFA trace (portal-by-portal states).
Tikz_Style tikz_area_style(const std::string &draw_color="black", const std::string &fill_color="gray!25", const double opacity=0.6)
Creates a style for drawing filled polygons.
Tikz_Style tikz_points_style(const std::string &color="black", const double opacity=-1.0)
Creates a style optimized for point clouds.
Full trace for shortest-path funnel processing.
One SSFA (funnel) iteration snapshot.
Helpers to visualize computational-geometry algorithm results in TikZ.