32#include "CoverageControl/extern/gnuplot/gnuplot-iostream.h"
37[[nodiscard]]
bool Plotter::GnuplotCommands(Gnuplot &gp) {
38 std::filesystem::path map_filename{
39 std::filesystem::weakly_canonical(dir +
"/" + plot_name)};
40 std::filesystem::path dir_path{map_filename.parent_path()};
41 if (!std::filesystem::exists(dir_path)) {
42 std::cerr <<
"Directory does not exist: " << dir_path << std::endl;
45 gp <<
"set o '" << map_filename.string() <<
"'\n";
46 gp <<
"set terminal pngcairo enhanced font 'Times," << font_sz <<
"' size "
47 << image_sz <<
"," << image_sz <<
"\n";
48 gp <<
"set palette defined (-5 'black', -1 '" << color_unknown
49 <<
"', 0 'white', 1 '" << color_idf <<
"')\n";
50 gp <<
"set cbrange [-5:1]\n";
51 gp <<
"set size ratio -1\n";
52 gp <<
"set xrange [0:" << range_max <<
"]\n";
53 gp <<
"set yrange [0:" << range_max <<
"]\n";
54 gp <<
"set border linewidth 1.5\n";
55 if (unset_colorbox) gp <<
"unset colorbox\n";
59void Plotter::StreamMap(Gnuplot &gp,
MapType const &map) {
60 for (
int i = 0; i < map.rows(); ++i) {
61 for (
int j = 0; j < map.cols(); ++j) {
62 gp << map(i, j) <<
" ";
66 gp <<
"e" << std::endl;
69void Plotter::PlotMap(Gnuplot &gp,
bool begin) {
74 gp <<
"'-' matrix using ($2*" << resolution <<
"):($1*" << resolution
75 <<
"):3 with image notitle ";
78void Plotter::PlotLine(Gnuplot &gp,
int marker_size, std::string color,
84 gp <<
"'-' with line lw " << marker_size <<
" lc rgb '" << color
88void Plotter::PlotPoints(Gnuplot &gp,
int point_type,
int marker_size,
89 std::string color,
bool begin) {
94 gp <<
"'-' with points pt " << point_type <<
" ps " << marker_size
95 <<
" lc rgb '" << color <<
"' notitle";
98void Plotter::PlotMap(
MapType const &map) {
100 if (GnuplotCommands(gp)) {
101 std::cerr <<
"Error in GnuplotCommands" << std::endl;
111 if (GnuplotCommands(gp)) {
112 std::cerr <<
"Error in GnuplotCommands" << std::endl;
116 PlotPoints(gp, 7, marker_sz, color_robot);
121 for (
auto const &pos : positions) {
122 gp << pos[0] <<
" " << pos[1] << std::endl;
124 gp <<
"e" << std::endl;
128 std::vector<std::list<Point2>>
const &trajectories,
129 std::vector<int>
const &robot_status) {
131 if (GnuplotCommands(gp)) {
132 std::cerr <<
"Error in GnuplotCommands" << std::endl;
137 for (
size_t i = 0; i < positions.size(); ++i) {
138 if (robot_status[i] == 0) {
139 PlotLine(gp, marker_sz, color_robot,
false);
141 PlotLine(gp, marker_sz, color_robot_alt,
false);
144 for (
size_t i = 0; i < positions.size(); ++i) {
145 if (robot_status[i] == 0) {
146 PlotPoints(gp, 7, marker_sz, color_robot,
false);
148 PlotPoints(gp, 7, marker_sz, color_robot_alt,
false);
154 for (
auto const &trajectory : trajectories) {
155 for (
auto const &pos : trajectory) {
156 gp << pos[0] <<
" " << pos[1] << std::endl;
158 gp <<
"e" << std::endl;
161 for (
auto const &pos : positions) {
162 gp << pos[0] <<
" " << pos[1] << std::endl;
163 gp <<
"e" << std::endl;
168 std::vector<std::list<Point2>>
const &trajectories,
169 std::vector<int>
const &robot_status,
170 double const &communication_range) {
172 if (GnuplotCommands(gp)) {
173 std::cerr <<
"Error in GnuplotCommands" << std::endl;
178 for (
size_t i = 0; i < positions.size(); ++i) {
179 if (robot_status[i] == 0) {
180 PlotLine(gp, marker_sz, color_robot,
false);
182 PlotLine(gp, marker_sz, color_robot_alt,
false);
185 PlotLine(gp, half_marker_sz, color_communication_links,
false);
186 for (
size_t i = 0; i < positions.size(); ++i) {
187 if (robot_status[i] == 0) {
188 PlotPoints(gp, 7, marker_sz, color_robot,
false);
190 PlotPoints(gp, 7, marker_sz, color_robot_alt,
false);
196 for (
auto const &trajectory : trajectories) {
197 for (
auto const &pos : trajectory) {
198 gp << pos[0] <<
" " << pos[1] << std::endl;
200 gp <<
"e" << std::endl;
203 for (
size_t i = 0; i < positions.size(); ++i) {
204 for (
size_t j = i + 1; j < positions.size(); ++j) {
205 if ((positions[i] - positions[j]).norm() < communication_range) {
206 gp << positions[i][0] <<
" " << positions[i][1] <<
"\n";
207 gp << positions[j][0] <<
" " << positions[j][1] <<
"\n";
212 gp <<
"e" << std::endl;
213 for (
auto const &pos : positions) {
214 gp << pos[0] <<
" " << pos[1] << std::endl;
215 gp <<
"e" << std::endl;
220 std::vector<std::list<Point2>>
const &voronoi,
221 std::vector<std::list<Point2>>
const &trajectories) {
223 if (GnuplotCommands(gp)) {
224 std::cerr <<
"Error in GnuplotCommands" << std::endl;
229 PlotLine(gp, marker_sz, color_robot,
false);
230 PlotLine(gp, half_marker_sz, color_voronoi,
false);
231 PlotPoints(gp, 7, marker_sz, color_robot,
false);
236 for (
auto const &trajectory : trajectories) {
237 for (
auto const &pos : trajectory) {
238 gp << pos[0] <<
" " << pos[1] <<
"\n";
242 gp <<
"e" << std::endl;
244 for (
auto const &vcell : voronoi) {
245 for (
auto const &pos : vcell) {
246 gp << pos[0] <<
" " << pos[1] <<
"\n";
250 gp <<
"e" << std::endl;
252 for (
auto const &pos : positions) {
253 gp << pos[0] <<
" " << pos[1] <<
"\n";
255 gp <<
"e" << std::endl;
260 std::vector<std::list<Point2>>
const &trajectories) {
262 if (GnuplotCommands(gp)) {
263 std::cerr <<
"Error in GnuplotCommands" << std::endl;
268 PlotLine(gp, marker_sz, color_robot,
false);
269 PlotLine(gp, half_marker_sz, color_voronoi,
false);
270 PlotPoints(gp, 7, marker_sz, color_robot,
false);
275 for (
auto const &trajectory : trajectories) {
276 for (
auto const &pos : trajectory) {
277 gp << pos[0] <<
" " << pos[1] <<
"\n";
281 gp <<
"e" << std::endl;
284 for (
auto const &vcell : voronoi_cells) {
285 for (
auto const &pos : vcell.cell) {
286 gp << pos[0] <<
" " << pos[1] <<
"\n";
288 auto const &pos = vcell.cell.front();
289 gp << pos[0] <<
" " << pos[1] <<
"\n";
292 gp <<
"e" << std::endl;
294 for (
auto const &pos : positions) {
295 gp << pos[0] <<
" " << pos[1] <<
"\n";
297 gp <<
"e" << std::endl;
303 if (GnuplotCommands(gp)) {
304 std::cerr <<
"Error in GnuplotCommands" << std::endl;
309 PlotLine(gp, half_marker_sz, color_voronoi,
false);
310 PlotLine(gp, half_marker_sz, color_robot,
false);
311 PlotPoints(gp, 28, marker_sz, color_robot,
false);
312 PlotPoints(gp, 7, marker_sz, color_robot,
false);
318 for (
auto const &vcell : voronoi_cells) {
319 for (
auto const &pos : vcell.cell) {
320 gp << pos[0] <<
" " << pos[1] << std::endl;
322 auto const &pos = vcell.cell.front();
323 gp << pos[0] <<
" " << pos[1] << std::endl;
326 gp <<
"e" << std::endl;
328 for (
size_t i = 0; i < positions.size(); ++i) {
329 auto const &pos = positions[i];
330 auto const &goal = goals[i];
331 gp << pos[0] <<
" " << pos[1] << std::endl;
332 gp << goal[0] <<
" " << goal[1] << std::endl;
335 gp <<
"e" << std::endl;
337 for (
auto const &pos : goals) {
338 gp << pos[0] <<
" " << pos[1] << std::endl;
340 gp <<
"e" << std::endl;
342 for (
auto const &pos : positions) {
343 gp << pos[0] <<
" " << pos[1] << std::endl;
345 gp <<
"e" << std::endl;
349 std::vector<std::list<Point2>>
const &trajectories,
352 if (GnuplotCommands(gp)) {
353 std::cerr <<
"Error in GnuplotCommands" << std::endl;
358 PlotLine(gp, marker_sz, color_robot);
359 PlotPoints(gp, 7, marker_sz, color_robot);
360 PlotPoints(gp, 1, half_marker_sz, color_robot);
365 for (
auto const &trajectory : trajectories) {
366 for (
auto const &pos : trajectory) {
367 gp << pos[0] <<
" " << pos[1] << std::endl;
371 gp <<
"e" << std::endl;
373 for (
auto const &pos : positions) {
374 gp << pos[0] <<
" " << pos[1] << std::endl;
376 gp <<
"e" << std::endl;
378 for (
auto const &pos : frontiers) {
379 gp << pos[0] <<
" " << pos[1] << std::endl;
381 gp <<
"e" << std::endl;
Class for computing Voronoi cells.
auto GetVoronoiCells() const
Eigen::Matrix< float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MapType
std::vector< Point2 > PointVector
Namespace for the CoverageControl library.