Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tikz_funnel_beamer_example.cc
Go to the documentation of this file.
1#include <fstream>
2#include <iostream>
3#include <string>
4#include <vector>
5
6#include <tikzgeom_scene.H>
7
8using namespace Aleph;
9
10namespace
11{
12
14{
15 Polygon p;
16 p.add_vertex(Point(0, 0));
17 p.add_vertex(Point(24, 0));
18 p.add_vertex(Point(24, 20));
19 p.add_vertex(Point(14, 20));
20 p.add_vertex(Point(14, 8));
21 p.add_vertex(Point(10, 8));
22 p.add_vertex(Point(10, 20));
23 p.add_vertex(Point(0, 20));
24 p.close();
25 return p;
26}
27
28std::string step_event(const FunnelTraceStep & step)
29{
30 if (step.emitted_left) return "emit-left";
31 if (step.emitted_right) return "emit-right";
32 if (step.tightened_left and step.tightened_right) return "tighten-both";
33 if (step.tightened_left) return "tighten-left";
34 if (step.tightened_right) return "tighten-right";
35 return "noop";
36}
37
39{
40 Tikz_Scene scene(210, 115, 6, 6, true);
41 scene.put_cartesian_axis();
42 scene.set_point_radius_mm(0.75);
43 return scene;
44}
45
47 const Point & source,
48 const Point & target,
50 const size_t step_index)
51{
53
54 scene.put_funnel_trace_step(
55 polygon,
56 source,
57 target,
58 trace,
60 tikz_area_style("black", "gray!15", 0.22),
61 tikz_points_style("green!50!black"),
62 tikz_points_style("blue"),
63 tikz_wire_style("purple", true),
64 tikz_path_style("purple"),
65 tikz_path_style("orange!90!black"),
66 tikz_path_style("red"),
67 true,
68 tikz_points_style("red"));
69
70 const FunnelTraceStep & step = trace.steps(step_index);
71 scene.add(Text(Point(-1, 22),
72 "Step " + std::to_string(step_index + 1) +
73 "/" + std::to_string(trace.steps.size()) +
74 ", portal=" + std::to_string(step.portal_index) +
75 ", event=" + step_event(step)),
76 make_tikz_draw_style("black"),
78
79 return scene;
80}
81
83 const Point & source,
84 const Point & target)
85{
87
88 const auto debug = scene.visualize_shortest_path_with_portals(
89 polygon, source, target, ShortestPathInPolygon());
90
91 scene.add(Text(Point(-1, 22),
92 "Final shortest path with portals: path nodes=" +
93 std::to_string(debug.path.size())),
94 make_tikz_draw_style("black"),
96
97 return scene;
98}
99
100} // namespace
101
102int main(int argc, char * argv[])
103{
104 const std::string output_path =
105 argc > 1 ? argv[1] : "tikz_funnel_beamer_example.tex";
106
107 std::ofstream out(output_path);
108 if (not out)
109 {
110 std::cerr << "Cannot open output file: " << output_path << '\n';
111 return 1;
112 }
113
114 const Polygon polygon = make_funnel_polygon();
115 const Point source(2, 16);
116 const Point target(22, 16);
117
119 compute_shortest_path_funnel_trace(polygon, source, target);
120
121 std::vector<Tikz_Scene> overlays;
122 overlays.reserve(trace.steps.size() + 1);
123
124 for (size_t i = 0; i < trace.steps.size(); ++i)
125 overlays.push_back(render_trace_step_scene(polygon, source, target, trace, i));
126
127 overlays.push_back(render_final_scene(polygon, source, target));
128
130 opts.class_options = "aspectratio=169";
131 opts.frame_options = "t";
132 opts.frame_title = "Shortest Path Funnel Trace (SSFA)";
133
135
136 std::cout << "Generated " << output_path << '\n'
137 << "Overlays: " << overlays.size() << '\n'
138 << "Compile with: pdflatex " << output_path << '\n';
139
140 return 0;
141}
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
static constexpr int Layer_Overlay
Definition tikzgeom.H:189
High-level scene wrapper to compose objects and algorithm visualizations.
static void draw_beamer_overlays(std::ostream &output, const std::vector< Tikz_Scene > &steps, const Tikz_Beamer_Document_Options &options={})
Export multiple scenes as beamer overlays (\\only<k>{...}) in one frame.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
and
Check uniqueness with explicit hash + equality functors.
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.
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.
Options used by Tikz_Scene beamer/handout export helpers.
std::string class_options
beamer class options (for example aspectratio=169).