Aleph-w 7.10.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
12Array<Segment> make_arrangement_segments()
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
22Polygon make_corridor(const Geom_Number & shift_x)
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()
54
55 const auto arrangement = scene.visualize_segment_arrangement(
56 make_arrangement_segments(),
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
66 DynList<Point> arrangement_points;
67 for (size_t i = 0; i < arrangement.vertices.size(); ++i)
68 arrangement_points.append(arrangement.vertices(i));
69
70 const Polygon hull = scene.visualize_convex_hull(
71 arrangement_points,
73 tikz_points_style("black"),
74 tikz_wire_style("red"),
75 tikz_points_style("red"),
78 true);
79
80 const Polygon corridor = make_corridor(0);
81 const Point source(72, 16);
82 const Point target(92, 16);
83
84 const ShortestPathDebugResult shortest =
86 corridor,
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}
int main()
size_t size_t int32_t * out
Definition ca-c-api.h:120
Andrew's monotonic chain convex hull algorithm.
Simple dynamic array with automatic resizing and functional operations.
Definition tpl_array.H:141
T & append(const T &data)
Append a copy of data
Definition tpl_array.H:331
Doubly-linked list (defined in tpl_dynList.H).
Definition htlist.H:1231
T & append(const T &item)
Definition htlist.H:1362
Represents a point with rectangular coordinates in a 2D plane.
Definition point.H:221
A general (irregular) 2D polygon defined by a sequence of vertices.
Definition polygon.H:247
void add_vertex(const Point &point)
Add a vertex to the polygon.
Definition polygon.H:686
void close()
Close the polygon.
Definition polygon.H:851
const size_t & size() const
Get the number of vertices.
Definition polygon.H:486
Compute the full planar subdivision induced by a set of segments.
Represents a line segment between two points.
Definition point.H:837
Compute the shortest Euclidean path between two points inside a simple polygon.
Represents a text string positioned at a 2D point.
Definition point.H:2817
static constexpr int Layer_Default
Definition tikzgeom.H:203
static constexpr int Layer_Foreground
Definition tikzgeom.H:204
static constexpr int Layer_Overlay
Definition tikzgeom.H:205
High-level scene wrapper to compose objects and algorithm visualizations.
void draw_standalone(std::ostream &output, const Tikz_Standalone_Document_Options &options={}) const
auto visualize_segment_arrangement(Args &&... args)
Tikz_Scene & put_cartesian_axis()
Tikz_Scene & add(const Geom &object)
Polygon visualize_convex_hull(const Points &points, HullAlgorithm &&algorithm, Args &&... args)
ShortestPathDebugResult visualize_shortest_path_with_portals(Args &&... args)
Tikz_Scene & set_point_radius_mm(const double radius_mm)
Main namespace for Aleph-w library functions.
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:172
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.
High-level scene management for TikZ geometry visualization.