39std::string fmt_point(
const Point & p)
41 std::ostringstream ss;
42 ss <<
"(" << std::fixed << std::setprecision(2)
48std::string render_trace_step_tikz(
const Polygon & polygon,
52 const size_t step_index)
55 plane.put_cartesian_axis();
56 plane.set_point_radius_mm(0.70);
75 std::ostringstream ss;
80std::string render_final_tikz(
const Polygon & polygon,
85 plane.put_cartesian_axis();
86 plane.set_point_radius_mm(0.70);
91 std::ostringstream ss;
97 const size_t step_index)
101 std::ostringstream ss;
102 ss <<
"\\small\\textbf{Step " << (step_index + 1) <<
"/" <<
trace.steps.size()
104 <<
"\\footnotesize event: \\texttt{" << step_event(step) <<
"}\\\\\n"
106 <<
"\\begin{tabular}{@{}ll@{}}\n"
107 <<
"Apex & " << fmt_point(step.
apex) <<
"\\\\\n"
110 <<
"L-portal & " << fmt_point(step.
portal_left) <<
"\\\\\n"
111 <<
"R-portal & " << fmt_point(step.
portal_right) <<
"\\\\\n"
120 std::ostringstream ss;
121 ss <<
"\\small\\textbf{Final Path}\\\\\n"
122 <<
"\\footnotesize frames: " << (
trace.steps.size() + 1) <<
"\\\\\n"
123 <<
"portals: " <<
trace.portals.size() <<
"\\\\\n"
124 <<
"path nodes: " <<
trace.final_path.size() <<
"\\\\[1.2mm]\n"
125 <<
"\\begin{tabular}{@{}ll@{}}\n";
127 if (
trace.final_path.is_empty())
129 ss <<
"Source & N/A\\\\\n"
130 <<
"Target & N/A\\\\\n";
134 ss <<
"Source & " << fmt_point(
trace.final_path(0)) <<
"\\\\\n"
135 <<
"Target & " << fmt_point(
trace.final_path(
trace.final_path.size() - 1))
139 ss <<
"\\end{tabular}";
144void write_twocol_frame(std::ostream &
out,
145 const std::string & title,
146 const std::string & left,
147 const std::string & right)
149 out <<
"\\begin{frame}[t]{" << title <<
"}\n"
150 <<
"\\begin{columns}[T,totalwidth=\\textwidth]\n"
151 <<
"\\begin{column}{0.70\\textwidth}\n"
154 <<
"\\begin{column}{0.29\\textwidth}\n"
157 <<
"\\end{columns}\n"
158 <<
"\\end{frame}\n\n";
163int main(
int argc,
char * argv[])
165 const std::string output_path =
166 argc > 1 ? argv[1] :
"tikz_funnel_beamer_handout_example.tex";
168 std::ofstream
out(output_path);
171 std::cerr <<
"Cannot open output file: " << output_path <<
'\n';
175 const Polygon polygon = make_funnel_polygon();
176 const Point source(2, 16);
177 const Point target(22, 16);
182 out <<
"\\documentclass[handout]{beamer}\n"
183 <<
"\\usepackage{tikz}\n"
184 <<
"\\setbeamertemplate{navigation symbols}{}\n"
185 <<
"\\begin{document}\n\n";
187 if (trace.steps.size() == 0)
191 "Shortest Path Funnel Trace (Handout)",
192 render_final_tikz(polygon, source, target),
193 "\\small\\textbf{No funnel iterations}\\\\\\n"
194 "Direct/degenerate case");
198 for (
size_t i = 0; i < trace.steps.size(); ++i)
200 const std::string title =
201 "Shortest Path Funnel Trace (Handout) - Step " +
202 std::to_string(i + 1);
206 render_trace_step_tikz(polygon, source, target, trace, i),
207 render_trace_step_panel(trace, i));
212 "Shortest Path Funnel Trace (Handout) - Final",
213 render_final_tikz(polygon, source, target),
214 render_final_panel(trace));
217 out <<
"\\end{document}\n";
219 std::cout <<
"Generated " << output_path <<
'\n'
220 <<
"Frames: " << (trace.steps.size() + 1) <<
'\n'
221 <<
"Compile with: pdflatex " << output_path <<
'\n';
size_t size_t int32_t * out
Represents a point with rectangular coordinates in a 2D plane.
const Geom_Number & get_x() const noexcept
Gets the x-coordinate value.
const Geom_Number & get_y() const noexcept
Gets the y-coordinate value.
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.
Compute the shortest Euclidean path between two points inside a simple polygon.
2D TikZ canvas storing geometry objects and emitting LaTeX output.
Main namespace for Aleph-w library functions.
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.
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.
double geom_number_to_double(const Geom_Number &n)
Converts a Geom_Number to its double precision representation.
Tikz_Style tikz_path_style(const std::string &color="red", const bool with_arrow=false)
Creates a style optimized for polyline paths.
and
Check uniqueness with explicit hash + equality functors.
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.
Aleph::Array< Frame > trace(const std::string_view input)
Record an actual online round trip, starting with the empty model.
Full trace for shortest-path funnel processing.
One SSFA (funnel) iteration snapshot.
Array< Point > committed_path
Helpers to visualize computational-geometry algorithm results in TikZ.