Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tikz_render_features_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
9int main(int argc, char * argv[])
10{
11 const std::string output_path =
12 argc > 1 ? argv[1] : "tikz_render_features_example.tex";
13
14 std::ofstream out(output_path);
15 if (not out)
16 {
17 std::cerr << "Cannot open output file: " << output_path << '\n';
18 return 1;
19 }
20
21 Tikz_Scene scene(220, 130, 6, 6, true);
22 scene.put_cartesian_axis()
23 .put_coordinate_grid(2.0, 2.0, true)
24 .enable_native_tikz_layers(true)
25 .enable_auto_legend(true)
26 .set_point_radius_mm(0.75);
27
29 grid_style.draw_color = "gray!45";
30 grid_style.dotted = true;
31 grid_style.line_width_mm = 0.2;
32 scene.set_grid_style(grid_style);
33
35 route_style.draw_color = "blue!70!black";
36 route_style.thick = true;
37 scene.register_tikz_style("route", route_style);
38
39 Polygon poly;
40 poly.add_vertex(Point(-8, -4));
41 poly.add_vertex(Point(8, -4));
42 poly.add_vertex(Point(11, 5));
43 poly.add_vertex(Point(-5, 9));
44 poly.close();
45
47 hatch.draw_color = "black";
48 hatch.fill = true;
49 hatch.fill_color = "orange!18";
50 hatch.pattern = "north east lines";
51 hatch.pattern_color = "orange!80!black";
53
54 scene.add_legend_entry("Obstacle", hatch);
55
58 named_route.draw_color = "";
59 scene.add(Segment(Point(-12, -8), Point(12, 10)),
61
62 scene.add_legend_entry("Route", route_style);
63
64 const Array<Point> points = []
65 {
67 pts.append(Point(-10, -2));
68 pts.append(Point(-2, 6));
69 pts.append(Point(6, -1));
70 return pts;
71 }();
72
74 scene.add_points(points, point_style, Tikz_Plane::Layer_Overlay);
75
77 label_style.text_anchor = "west";
78 put_point_label_in_plane(scene.plane(), points(0), "A", "above right", label_style);
79 put_point_label_in_plane(scene.plane(), points(1), "B", "below left", label_style);
80 put_point_label_in_plane(scene.plane(), points(2), "C", "above", label_style);
81
83 bez_style.thick = true;
85 Point(-12, 9), Point(-4, 15),
86 Point(4, -12), Point(12, -6),
88
89 scene.add_legend_entry("Bezier", bez_style);
90
91 scene.add(Text(Point(-15, 16), "Render features demo"),
92 make_tikz_draw_style("black"),
94
95 scene.draw_standalone(out);
96
97 std::cout << "Generated " << output_path << '\n';
98 std::cout << "Compile with: pdflatex " << output_path << '\n';
99 return 0;
100}
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
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 line segment between two points.
Definition point.H:827
Represents a text string positioned at a 2D point.
Definition point.H:2739
static constexpr int Layer_Foreground
Definition tikzgeom.H:188
static constexpr int Layer_Background
Definition tikzgeom.H:186
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
void put_cubic_bezier_native_in_plane(Tikz_Plane &plane, const Point &p0, const Point &p1, const Point &p2, const Point &p3, const Tikz_Style &style={}, const int layer=Tikz_Plane::Layer_Default)
Insert a cubic Bézier using native TikZ controls syntax.
Definition tikzgeom.H:1548
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.
void put_point_label_in_plane(Tikz_Plane &plane, const Point &point, const std::string &label, const std::string &placement="above", const Tikz_Style &style=make_tikz_draw_style("black"), const int layer=Tikz_Plane::Layer_Overlay)
Insert a point label with configurable placement (above, etc.).
Definition tikzgeom.H:1561
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_points_style(const std::string &color="black", const double opacity=-1.0)
Creates a style optimized for point clouds.
Style descriptor for TikZ primitives.
Definition tikzgeom.H:86
std::string tikz_style_name
Optional named style (from \tikzset)
Definition tikzgeom.H:87
std::string draw_color
TikZ draw color (draw=<color>)
Definition tikzgeom.H:88