Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tikz_scene_overlays_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(-20, -8));
17 p.add_vertex(Point(12, -12));
18 p.add_vertex(Point(22, 6));
19 p.add_vertex(Point(-6, 20));
20 p.close();
21 return p;
22}
23
25{
26 Polygon p;
27 p.add_vertex(Point(-14, -18));
28 p.add_vertex(Point(24, -4));
29 p.add_vertex(Point(10, 24));
30 p.add_vertex(Point(-24, 8));
31 p.close();
32 return p;
33}
34
36{
37 Tikz_Scene scene(178, 108, 0, 0, true);
38 scene.put_cartesian_axis()
39 .set_point_radius_mm(0.70);
40 return scene;
41}
42
43void put_step_title(Tikz_Scene & scene, const std::string & text)
44{
45 scene.add(Text(Point(-30, 28), text),
46 make_tikz_draw_style("black"),
48}
49
50} // namespace
51
52int main(int argc, char * argv[])
53{
54 std::string output_path = "tikz_scene_overlays_example.tex";
55 bool handout = false;
56
57 for (int i = 1; i < argc; ++i)
58 {
59 const std::string arg = argv[i];
60 if (arg == "--handout")
61 handout = true;
62 else
64 }
65
66 std::ofstream out(output_path);
67 if (not out)
68 {
69 std::cerr << "Cannot open output file: " << output_path << '\n';
70 return 1;
71 }
72
73 const Polygon a = make_polygon_a();
74 const Polygon b = make_polygon_b();
75
76 std::vector<Tikz_Scene> steps;
77 steps.reserve(3);
78
79 {
81 scene.add(a, tikz_area_style("blue", "blue!15", 0.42), Tikz_Plane::Layer_Default);
82 scene.add(b, tikz_area_style("orange", "orange!20", 0.42), Tikz_Plane::Layer_Default + 1);
83 put_step_title(scene, "Step 1/3: input polygons A and B");
84 steps.push_back(scene);
85 }
86
87 {
89 const Polygon inter = scene.visualize_convex_intersection(
90 a,
91 b,
93 tikz_area_style("blue", "blue!15", 0.42),
94 tikz_area_style("orange", "orange!20", 0.42),
95 tikz_area_style("red", "red!35", 0.62));
97 scene,
98 "Step 2/3: convex intersection, vertices=" + std::to_string(inter.size()));
99 steps.push_back(scene);
100 }
101
102 {
104 const Array<Polygon> united = scene.visualize_boolean_operation(
105 a,
106 b,
107 BooleanPolygonOperations::Op::UNION,
109 tikz_area_style("blue", "blue!10", 0.34),
110 tikz_area_style("green!60!black", "green!15", 0.34),
111 tikz_area_style("purple!70!black", "purple!30", 0.56));
113 scene,
114 "Step 3/3: boolean union, components=" + std::to_string(united.size()));
115 steps.push_back(scene);
116 }
117
119 opts.class_options = "aspectratio=169";
120 opts.frame_options = "t";
121 opts.frame_title = handout ? "TikZ Scene Overlays (Handout)"
122 : "TikZ Scene Overlays (Beamer)";
123
124 if (handout)
126 else
128
129 std::cout << "Generated " << output_path << '\n'
130 << "Mode: " << (handout ? "handout" : "beamer") << '\n'
131 << "Overlays: " << steps.size() << '\n'
132 << "Compile with: pdflatex " << output_path << '\n';
133
134 return 0;
135}
Simple dynamic array with automatic resizing and functional operations.
Definition tpl_array.H:139
Boolean operations on simple polygons (union, intersection, difference) using the Greiner-Hormann alg...
Basic exact intersection for closed convex polygons.
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
Represents a text string positioned at a 2D point.
Definition point.H:2739
static constexpr int Layer_Default
Definition tikzgeom.H:187
static constexpr int Layer_Overlay
Definition tikzgeom.H:189
High-level scene wrapper to compose objects and algorithm visualizations.
static void draw_handout_overlays(std::ostream &output, const std::vector< Tikz_Scene > &steps, const Tikz_Beamer_Document_Options &options={})
Export multiple scenes as handout overlays (forces beamer[handout]).
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
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 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_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.
Options used by Tikz_Scene beamer/handout export helpers.
std::string class_options
beamer class options (for example aspectratio=169).