Aleph-w 7.10.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)
27
28 Tikz_Style grid_style;
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
34 Tikz_Style route_style;
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
46 Tikz_Style hatch;
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";
52 scene.add(poly, hatch, Tikz_Plane::Layer_Background);
53
54 scene.add_legend_entry("Obstacle", hatch);
55
56 Tikz_Style named_route;
57 named_route.tikz_style_name = "route";
58 named_route.draw_color = "";
59 scene.add(Segment(Point(-12, -8), Point(12, 10)),
60 named_route, Tikz_Plane::Layer_Foreground);
61
62 scene.add_legend_entry("Route", route_style);
63
64 const Array<Point> points = []
65 {
66 Array<Point> pts;
67 pts.append(Point(-10, -2));
68 pts.append(Point(-2, 6));
69 pts.append(Point(6, -1));
70 return pts;
71 }();
72
73 Tikz_Style point_style = tikz_points_style("red");
74 scene.add_points(points, point_style, Tikz_Plane::Layer_Overlay);
75
76 Tikz_Style label_style = make_tikz_draw_style("black");
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
82 Tikz_Style bez_style = make_tikz_draw_style("purple");
83 bez_style.thick = true;
85 Point(-12, 9), Point(-4, 15),
86 Point(4, -12), Point(12, -6),
87 bez_style, Tikz_Plane::Layer_Overlay);
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}
int main()
size_t size_t int32_t * out
Definition ca-c-api.h:120
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
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
Represents a line segment between two points.
Definition point.H:837
Represents a text string positioned at a 2D point.
Definition point.H:2817
static constexpr int Layer_Foreground
Definition tikzgeom.H:204
static constexpr int Layer_Background
Definition tikzgeom.H:202
static constexpr int Layer_Overlay
Definition tikzgeom.H:205
High-level scene wrapper to compose objects and algorithm visualizations.
Tikz_Scene & put_coordinate_grid(const double step_x=1.0, const double step_y=1.0, const bool draw_ticks=true)
Tikz_Scene & enable_native_tikz_layers(const bool enabled=true)
Tikz_Plane & plane()
void draw_standalone(std::ostream &output, const Tikz_Standalone_Document_Options &options={}) const
Tikz_Scene & enable_auto_legend(const bool enabled=true)
Tikz_Scene & put_cartesian_axis()
Tikz_Scene & add_legend_entry(const std::string &label, const Tikz_Style &style)
Tikz_Scene & add(const Geom &object)
Tikz_Scene & register_tikz_style(const std::string &name, const Tikz_Style &style)
Tikz_Scene & add_points(const Array< Point > &points, const Tikz_Style &style=tikz_points_style("black"), const int layer=Tikz_Plane::Layer_Default)
Tikz_Scene & set_grid_style(const Tikz_Style &style)
Tikz_Scene & set_point_radius_mm(const double radius_mm)
Main namespace for Aleph-w library functions.
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:1603
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:1616
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_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:102
std::string text_anchor
TikZ node anchor (anchor=<value>)
Definition tikzgeom.H:109
std::string fill_color
TikZ fill color (fill=<color>)
Definition tikzgeom.H:105
std::string pattern
TikZ pattern (e.g. north east lines)
Definition tikzgeom.H:106
bool thick
Add thick
Definition tikzgeom.H:119
bool fill
Fill closed shapes (polygon/triangle/ellipse)
Definition tikzgeom.H:121
std::string tikz_style_name
Optional named style (from \tikzset)
Definition tikzgeom.H:103
double line_width_mm
line width=<value>mm when > 0
Definition tikzgeom.H:114
std::string draw_color
TikZ draw color (draw=<color>)
Definition tikzgeom.H:104
bool dotted
Add dotted
Definition tikzgeom.H:118
std::string pattern_color
TikZ pattern color (pattern color=<color>)
Definition tikzgeom.H:107
High-level scene management for TikZ geometry visualization.