visualizer.h
Go to the documentation of this file.
1 //=============================================================================
2 // Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 // Author: Gonzalo Mier
4 // BSD-3 License
5 //=============================================================================
6 
7 #pragma once
8 #ifndef FIELDS2COVER_UTILS_VISUALIZER_H_
9 #define FIELDS2COVER_UTILS_VISUALIZER_H_
10 
11 
12 #include <vector>
13 #include <string>
14 #include <type_traits>
15 #include "fields2cover/types.h"
16 
17 namespace f2c {
18 
20 class Visualizer {
21  public:
22  static double getLineWidth() {return 1.0;}
23 
24  static void plot(double x, double y, const std::vector<double>& color = {});
25  static void plot(const F2CPoint& p, const std::vector<double>& color = {});
26  static void plot(
27  const F2CSwath& s, const std::vector<double>& color = {});
28  static void plot(const F2CSwaths& s,
29  const std::vector<std::vector<double>>& color = {});
30  static void plot(const F2CSwathsByCells& s,
31  const std::vector<std::vector<double>>& color = {});
32  static void plot(const std::vector<F2CSwathsByCells>& vs,
33  const std::vector<std::vector<double>>& color = {});
34  static void plot(const F2CLineString& line,
35  const std::vector<double>& color = {});
36  static void plot(const F2CLinearRing& ring,
37  const std::vector<double>& color = {});
38  static void plot(const F2CMultiPoint& multipoint,
39  const std::vector<double>& color = {});
40  static void plot(const F2CMultiLineString& multiline,
41  const std::vector<double>& color = {});
42  static void plot(const F2CCell& cell,
43  const std::vector<double>& color = {});
44  static void plot(const F2CCells& cells,
45  const std::vector<double>& color = {});
46  static void plot(const F2CRoute& route,
47  const std::vector<std::vector<double>>& color = {});
48  static void plot(const std::vector<F2CRoute>& route,
49  const std::vector<std::vector<double>>& color = {});
50  static void plot(const F2CPath& path,
51  const std::vector<std::vector<double>>& color = {});
52  static void plot(const F2CField& field,
53  const std::vector<double>& color = {});
54 
55  static void plotFilled(const F2CField& field,
56  const std::vector<double>& color = {});
57  static void plotFilled(
58  const F2CLinearRing& ring, const std::vector<double>& color);
59  static void plotFilled(const F2CCell& cell,
60  const std::vector<double>& poly_color,
61  const std::vector<double>& holes_color);
62  static void plotFilled(const F2CCells& cells,
63  const std::vector<double>& poly_color,
64  const std::vector<double>& holes_color);
65  static void plotFilled(const F2CCell& cell,
66  const std::vector<double>& color);
67  static void plotFilled(const F2CCells& cells,
68  const std::vector<double>& poly_color);
69 
70  static void plot(const std::vector<double>& t,
71  const std::vector<double>& d, const std::vector<double>& color);
72 
74  template<class T>
75  static void plot(const std::vector<T>& v_t, const std::vector<double>& color);
76  template<class T>
77  static void plot(
78  const std::vector<T>& v_t,
79  const std::vector<std::vector<double>>& color = {});
80 
82  static void figure();
83 
85  static void figure_size(unsigned int width, unsigned int height);
86 
87  static void axis_equal();
88 
92  static void show();
93 
96  static void save(const std::string& file);
97 
100  static void title(const std::string& text);
101 
102  static void xlim(double min, double max);
103  static void ylim(double min, double max);
104 
105  private:
106  template<class T>
107  static std::vector<F2CPoint> data2vector(const T& t);
108 
109  static std::vector<std::vector<double>> getComponents(
110  const std::vector<F2CPoint>& points);
111 
112  static std::vector<double> linspace(double min, double max, size_t N);
113  static std::vector<std::vector<double>> color_linspace(
114  const std::vector<int>& min,
115  const std::vector<int>& max,
116  size_t N);
117 };
118 
119 template<class T>
120 std::vector<F2CPoint> Visualizer::data2vector(const T& t) {
121  if constexpr (std::is_same<T, F2CPoint>::value) {
122  return std::vector<F2CPoint>{t};
123  } else {
124  std::vector<F2CPoint> res;
125  for (auto&& i : t) {
126  auto v = data2vector(i);
127  res.insert(res.end(), v.begin(), v.end());
128  }
129  return res;
130  }
131 }
132 
133 template<class T>
135  const std::vector<T>& v_t,
136  const std::vector<double>& color) {
137  if constexpr (std::is_same<T, F2CPoint>::value) {
138  auto comp = getComponents(v_t);
139  plot(comp[0], comp[1], color);
140  } else if constexpr (std::is_same<T, double>::value) {
141  std::vector<double> t(v_t.size());
142  std::iota(std::begin(t), std::end(t), 0.0);
143  plot(t, v_t, color);
144  } else {
145  for (auto&& t : v_t) {
146  plot(t, color);
147  }
148  }
149 }
150 
151 } // namespace f2c
152 
153 
154 #endif // FIELDS2COVER_UTILS_VISUALIZER_H_
1_basic_types.cells
cells
Definition: 1_basic_types.py:93
f2c::Visualizer::getLineWidth
static double getLineWidth()
Definition: visualizer.h:22
f2c::Visualizer::plot
static void plot(double x, double y, const std::vector< double > &color={})
Definition: visualizer.cpp:23
types.h
2_objective_functions.path
path
Definition: 2_objective_functions.py:88
f2c::Visualizer::linspace
static std::vector< double > linspace(double min, double max, size_t N)
Definition: visualizer.cpp:298
1_basic_types.points
points
Definition: 1_basic_types.py:97
f2c::types::Field
Definition: Field.h:18
1_basic_types.cell
cell
Definition: 1_basic_types.py:88
f2c::Visualizer::data2vector
static std::vector< F2CPoint > data2vector(const T &t)
Definition: visualizer.h:120
f2c::Visualizer::title
static void title(const std::string &text)
Definition: visualizer.cpp:276
f2c::types::Swath
Definition: Swath.h:23
1_basic_types.end
end
Definition: 1_basic_types.py:76
f2c::Visualizer::xlim
static void xlim(double min, double max)
Definition: visualizer.cpp:280
f2c::Visualizer::axis_equal
static void axis_equal()
Definition: visualizer.cpp:250
f2c::types::MultiLineString
Definition: MultiLineString.h:18
f2c::Visualizer::getComponents
static std::vector< std::vector< double > > getComponents(const std::vector< F2CPoint > &points)
Definition: visualizer.cpp:288
f2c::types::LinearRing
Definition: LinearRing.h:18
f2c::Visualizer
Class to plot Fields2Cover data structures.
Definition: visualizer.h:20
5_route_planning.route
route
Definition: 5_route_planning.py:29
f2c::types::Cell
Definition: Cell.h:32
f2c::Visualizer::figure_size
static void figure_size(unsigned int width, unsigned int height)
Change size of current figure.
Definition: visualizer.cpp:260
1_basic_types.ring
ring
Definition: 1_basic_types.py:68
f2c::types::Path
Definition: Path.h:23
2_objective_functions.width
float width
Definition: 2_objective_functions.py:29
f2c::types::MultiPoint
Definition: MultiPoint.h:18
f2c::types::LineString
Definition: LineString.h:19
f2c::types::Cells
Definition: Cells.h:21
f2c::types::Route
Definition: Route.h:23
f2c::types::Point
Definition: Point.h:21
2_objective_functions.field
field
Definition: 2_objective_functions.py:16
f2c::Visualizer::show
static void show()
Definition: visualizer.cpp:268
f2c
Main namespace of the fields2cover library.
Definition: boustrophedon_decomp.h:14
f2c::types::SwathsByCells
Definition: SwathsByCells.h:17
f2c::Visualizer::plotFilled
static void plotFilled(const F2CField &field, const std::vector< double > &color={})
Definition: visualizer.cpp:200
f2c::Visualizer::figure
static void figure()
Create figure to plot on.
Definition: visualizer.cpp:254
f2c::Visualizer::save
static void save(const std::string &file)
Definition: visualizer.cpp:272
f2c::types::Swaths
Definition: Swaths.h:20
f2c::Visualizer::ylim
static void ylim(double min, double max)
Definition: visualizer.cpp:284
f2c::Visualizer::color_linspace
static std::vector< std::vector< double > > color_linspace(const std::vector< int > &min, const std::vector< int > &max, size_t N)
Definition: visualizer.cpp:307


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31