Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tikz_scene_example.cc
Go to the documentation of this file.
1#include <fstream>
2#include <iostream>
3#include <string>
4
5#include <tikzgeom_scene.H>
6
7using namespace Aleph;
8
9namespace
10{
11
13{
14 Array<Segment> segments;
15 segments.append(Segment(Point(-30, 0), Point(30, 0)));
16 segments.append(Segment(Point(0, -24), Point(0, 24)));
17 segments.append(Segment(Point(-26, -18), Point(26, 18)));
18 segments.append(Segment(Point(-26, 18), Point(26, -18)));
19 return segments;
20}
21
23{
24 Polygon p;
25 p.add_vertex(Point(70 + shift_x, 0));
26 p.add_vertex(Point(94 + shift_x, 0));
27 p.add_vertex(Point(94 + shift_x, 20));
28 p.add_vertex(Point(84 + shift_x, 20));
29 p.add_vertex(Point(84 + shift_x, 8));
30 p.add_vertex(Point(80 + shift_x, 8));
31 p.add_vertex(Point(80 + shift_x, 20));
32 p.add_vertex(Point(70 + shift_x, 20));
33 p.close();
34 return p;
35}
36
37} // namespace
38
39int main(int argc, char * argv[])
40{
41 const std::string output_path =
42 argc > 1 ? argv[1] : "tikz_scene_example.tex";
43
44 std::ofstream out(output_path);
45 if (not out)
46 {
47 std::cerr << "Cannot open output file: " << output_path << '\n';
48 return 1;
49 }
50
51 Tikz_Scene scene(230, 130, 6, 6, true);
52 scene.put_cartesian_axis()
53 .set_point_radius_mm(0.65);
54
55 const auto arrangement = scene.visualize_segment_arrangement(
58 true,
59 true,
60 false,
61 tikz_area_style("teal!60!black", "teal!12", 0.32),
62 tikz_wire_style("teal!70!black"),
63 tikz_points_style("teal!80!black"),
64 true);
65
67 for (size_t i = 0; i < arrangement.vertices.size(); ++i)
69
70 const Polygon hull = scene.visualize_convex_hull(
73 tikz_points_style("black"),
74 tikz_wire_style("red"),
75 tikz_points_style("red"),
78 true);
79
81 const Point source(72, 16);
82 const Point target(92, 16);
83
85 scene.visualize_shortest_path_with_portals(
87 source,
88 target,
90 tikz_area_style("black", "gray!15", 0.26),
91 tikz_points_style("green!50!black"),
92 tikz_points_style("blue"),
93 tikz_wire_style("purple", true),
94 tikz_path_style("orange!90!black"),
95 true,
96 tikz_points_style("orange!90!black"),
99
100 scene.add(Text(Point(-35, 27),
101 "Scene API: arrangement + hull + shortest path"),
102 make_tikz_draw_style("black"),
104
105 scene.add(Text(Point(66, 24),
106 "Portals=" + std::to_string(shortest.portals.size()) +
107 ", Hull vertices=" + std::to_string(hull.size())),
108 make_tikz_draw_style("black"),
110
111 scene.draw_standalone(out);
112
113 std::cout << "Generated " << output_path << '\n'
114 << "Arrangement vertices: " << arrangement.vertices.size() << '\n'
115 << "Hull vertices: " << hull.size() << '\n'
116 << "Portals: " << shortest.portals.size() << '\n'
117 << "Compile with: pdflatex " << output_path << '\n';
118
119 return 0;
120}
Andrew's monotonic chain convex hull algorithm.
Simple dynamic array with automatic resizing and functional operations.
Definition tpl_array.H:139
T & append(const T &data)
Append a copy of data
Definition tpl_array.H:245
Dynamic singly linked list with functional programming support.
Definition htlist.H:1155
T & append(const T &item)
Definition htlist.H:1271
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 full planar subdivision induced by a set of segments.
Represents a line segment between two points.
Definition point.H:827
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_Default
Definition tikzgeom.H:187
static constexpr int Layer_Foreground
Definition tikzgeom.H:188
static constexpr int Layer_Overlay
Definition tikzgeom.H:189
High-level scene wrapper to compose objects and algorithm visualizations.
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 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.
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.
Result bundle for shortest-path + funnel portal visualization.