3131
3232namespace CoverageControl {
3333
34- void Plotter::GnuplotCommands (Gnuplot &gp) {
35- std::filesystem::path path{dir};
36- if (not std::filesystem::exists (path)) {
37- std::cerr << " Directory does not exist" << std::endl;
38- throw std::runtime_error{" Directory does not exist" };
34+ [[nodiscard]] bool Plotter::GnuplotCommands (Gnuplot &gp) {
35+
36+ std::filesystem::path map_filename{std::filesystem::weakly_canonical (dir + " /" + plot_name)};
37+ std::filesystem::path dir_path{map_filename.parent_path ()};
38+ if (!std::filesystem::exists (dir_path)) {
39+ std::cerr << " Directory does not exist: " << dir_path << std::endl;
40+ return 1 ;
3941 }
40- std::string map_filename{std::filesystem::absolute (path / plot_name)};
41- gp << " set o '" << map_filename << " '\n " ;
42+ gp << " set o '" << map_filename.string () << " '\n " ;
4243 gp << " set terminal pngcairo enhanced font 'Times," << font_sz << " ' size "
4344 << image_sz << " ," << image_sz << " \n " ;
4445 gp << " set palette defined (-5 'black', -1 '" << color_unknown
@@ -48,6 +49,7 @@ void Plotter::GnuplotCommands(Gnuplot &gp) {
4849 gp << " set xrange [0:" << range_max << " ]\n " ;
4950 gp << " set yrange [0:" << range_max << " ]\n " ;
5051 if (unset_colorbox) gp << " unset colorbox\n " ;
52+ return 0 ;
5153}
5254
5355void Plotter::StreamMap (Gnuplot &gp, MapType const &map) {
@@ -91,15 +93,21 @@ void Plotter::PlotPoints(Gnuplot &gp, int point_type, int marker_size,
9193
9294void Plotter::PlotMap (MapType const &map) {
9395 Gnuplot gp;
94- GnuplotCommands (gp);
96+ if (GnuplotCommands (gp)) {
97+ std::cerr << " Error in GnuplotCommands" << std::endl;
98+ return ;
99+ }
95100 PlotMap (gp);
96101 gp << " \n " ;
97102 StreamMap (gp, map);
98103}
99104
100105void Plotter::PlotMap (MapType const &map, PointVector const &positions) {
101106 Gnuplot gp;
102- GnuplotCommands (gp);
107+ if (GnuplotCommands (gp)) {
108+ std::cerr << " Error in GnuplotCommands" << std::endl;
109+ return ;
110+ }
103111 PlotMap (gp);
104112 PlotPoints (gp, 7 , marker_sz, color_robot);
105113 gp << " \n " ;
@@ -116,7 +124,10 @@ void Plotter::PlotMap(MapType const &map, PointVector const &positions,
116124 std::vector<std::list<Point2>> const &trajectories,
117125 std::vector<int > const &robot_status) {
118126 Gnuplot gp;
119- GnuplotCommands (gp);
127+ if (GnuplotCommands (gp)) {
128+ std::cerr << " Error in GnuplotCommands" << std::endl;
129+ return ;
130+ }
120131 PlotMap (gp);
121132
122133 for (size_t i = 0 ; i < positions.size (); ++i) {
@@ -154,7 +165,10 @@ void Plotter::PlotMap(MapType const &map, PointVector const &positions,
154165 std::vector<int > const &robot_status,
155166 double const &communication_range) {
156167 Gnuplot gp;
157- GnuplotCommands (gp);
168+ if (GnuplotCommands (gp)) {
169+ std::cerr << " Error in GnuplotCommands" << std::endl;
170+ return ;
171+ }
158172 PlotMap (gp);
159173
160174 for (size_t i = 0 ; i < positions.size (); ++i) {
@@ -202,7 +216,10 @@ void Plotter::PlotMap(MapType const &map, PointVector const &positions,
202216 std::vector<std::list<Point2>> const &voronoi,
203217 std::vector<std::list<Point2>> const &trajectories) {
204218 Gnuplot gp;
205- GnuplotCommands (gp);
219+ if (GnuplotCommands (gp)) {
220+ std::cerr << " Error in GnuplotCommands" << std::endl;
221+ return ;
222+ }
206223 PlotMap (gp);
207224
208225 PlotLine (gp, marker_sz, color_robot, false );
@@ -238,7 +255,10 @@ void Plotter::PlotMap(MapType const &map, PointVector const &positions,
238255 Voronoi const &voronoi,
239256 std::vector<std::list<Point2>> const &trajectories) {
240257 Gnuplot gp;
241- GnuplotCommands (gp);
258+ if (GnuplotCommands (gp)) {
259+ std::cerr << " Error in GnuplotCommands" << std::endl;
260+ return ;
261+ }
242262 PlotMap (gp);
243263
244264 PlotLine (gp, marker_sz, color_robot, false );
@@ -276,7 +296,10 @@ void Plotter::PlotMap(MapType const &map, PointVector const &positions,
276296void Plotter::PlotMap (MapType const &map, PointVector const &positions,
277297 PointVector const &goals, Voronoi const &voronoi) {
278298 Gnuplot gp;
279- GnuplotCommands (gp);
299+ if (GnuplotCommands (gp)) {
300+ std::cerr << " Error in GnuplotCommands" << std::endl;
301+ return ;
302+ }
280303 PlotMap (gp);
281304
282305 PlotLine (gp, half_marker_sz, color_voronoi, false ); // voronoi
@@ -322,7 +345,10 @@ void Plotter::PlotMap(MapType const &map, PointVector const &positions,
322345 std::vector<std::list<Point2>> const &trajectories,
323346 PointVector const &frontiers) {
324347 Gnuplot gp;
325- GnuplotCommands (gp);
348+ if (GnuplotCommands (gp)) {
349+ std::cerr << " Error in GnuplotCommands" << std::endl;
350+ return ;
351+ }
326352
327353 PlotMap (gp);
328354 PlotLine (gp, marker_sz, color_robot);
0 commit comments