20 #ifndef GRIDPLOTTER_H_
21 #define GRIDPLOTTER_H_
28 #include <fast_methods/ndgridmap/fmcell.h>
29 #include <fast_methods/ndgridmap/ndgridmap.hpp>
32 using namespace cimg_library;
38 typedef typename std::array<unsigned int, 2>
Coord2D;
41 typedef typename std::array<double, 2>
Point2D;
44 typedef typename std::vector <Point2D>
Path2D;
47 typedef typename std::vector <Path2D>
Paths2D;
59 template<
class T,
size_t ndims>
63 CImg<bool> img(d[0],d[1],1,1,0);
65 cimg_forXY(img,x,y) {img(x,y) = !grid[img.width()*(img.height()-y-1)+x].isOccupied(); }
70 img.display(name.c_str(),
false);
82 template<
class T,
size_t ndims>
83 static void plotOccupancyMap
86 CImg<double> img(d[0],d[1],1,1,0);
88 cimg_forXY(img,x,y) { img(x,y) = grid[img.width()*(img.height()-y-1)+x].getOccupancy()*255; }
89 name +=
" Occupancy Map";
90 img.display(name.c_str(),
false);
102 template<
class T,
size_t ndims = 2>
103 static void plotArrivalTimes
107 CImg<double> img(d[0],d[1],1,1,0);
109 cimg_forXY(img,x,y) { img(x,y) = grid[img.width()*(img.height()-y-1)+x].getValue()/max_val*255; }
110 img.map( CImg<double>::jet_LUT256() );
111 name +=
" Grid values";
112 img.display(name.c_str(),
false);
124 template<
class T,
size_t ndims = 2>
125 static void plotMapPath
128 CImg<double> img(d[0],d[1],1,3,0);
131 cimg_forXYZC(img,x,y,z,c) { img(x,y,z,c) = (!grid[img.width()*(img.height()-y-1)+x].isOccupied())*255; }
133 for (
unsigned int i = 0; i< path.size(); ++i)
135 img(static_cast<unsigned int>(path[i][0]), (img.height()-
static_cast<unsigned int>(path[i][1])-1), 0, 1) = 0;
136 img(static_cast<unsigned int>(path[i][0]), (img.height()-
static_cast<unsigned int>(path[i][1])-1), 0, 2) = 0;
139 name +=
" Map and Path";
140 img.display(name.c_str(),
false);
152 template<
class T,
size_t ndims = 2>
153 static void plotOccupancyPath
156 CImg<double> img(d[0],d[1],1,3,0);
158 cimg_forXYZC(img,x,y,z,c) { img(x,y,z,c) = grid[img.width()*(img.height()-y-1)+x].getOccupancy()*255; }
160 for (
unsigned int i = 0; i< path.size(); ++i)
162 img(static_cast<unsigned int>(path[i][0]), (img.height()-
static_cast<unsigned int>(path[i][1])-1), 0, 1) = 0;
163 img(static_cast<unsigned int>(path[i][0]), (img.height()-
static_cast<unsigned int>(path[i][1])-1), 0, 2) = 0;
165 name +=
" Map and Path";
166 img.display(name.c_str(),
false);
178 template<
class T,
size_t ndims = 2>
179 static void plotMapPaths
182 CImg<double> img(d[0],d[1],1,3,0);
185 cimg_forXYZC(img,x,y,z,c) { img(x,y,z,c) = (!grid[img.width()*(img.height()-y-1)+x].isOccupied())*255; }
188 for (
unsigned int j = 0; j < paths.size(); ++j)
191 for (
unsigned int i = 0; i< path.size(); ++i)
193 img(static_cast<unsigned int>(path[i][0]), (img.height()-
static_cast<unsigned int>(path[i][1])-1), 0, j) = 0;
194 img(static_cast<unsigned int>(path[i][0]), (img.height()-
static_cast<unsigned int>(path[i][1])-1), 0, j+1) = 0;
197 name +=
" Map and Paths";
198 img.display(name.c_str(),
false);
210 template<
class T,
size_t ndims = 2>
211 static void plotArrivalTimesPath
215 CImg<double> img(d[0],d[1],1,1,0);
218 cimg_forXY(img,x,y) { img(x,y) = grid[img.width()*(img.height()-y-1)+x].getValue()/max_val*255; }
220 for (
unsigned int i = 0; i< path.size(); ++i)
221 img(static_cast<unsigned int>(path[i][0]), (img.height()-
static_cast<unsigned int>(path[i][1])-1)) = 255;
223 img.map( CImg<double>::jet_LUT256() );
224 name +=
" Values and Path";
225 img.display(name.c_str(),
false);
234 template<
class T,
size_t ndims = 2>
235 static void plotFMStates
239 CImg<unsigned int> img(d[0],d[1],1,1,0);
241 cimg_forXY(img,x,y) {
242 FMState state = grid[img.width()*(img.height()-y-1)+x].getState();
243 unsigned int val = 0;
244 if (state == FMState::NARROW)
246 else if (state == FMState::OPEN)
252 img.display(name.c_str(),
false);
double getMaxValue() const
Returns the maximum value of the cells in the grid.
Templated class which represents a n-dimensional grid map. Its cells are assumed to be cubic...
std::vector< Path2D > Paths2D
Shorthand for vector of 2D paths of real points.
std::vector< Point2D > Path2D
Shorthand for 2D paths of real points.
std::array< unsigned int, ndims > getDimSizes() const
Returns the size of each dimension.
std::array< unsigned int, 2 > Coord2D
Shorthand for 2D coordinates.
Auxiliar class which helps to visualise Fast Marching steps and results.
std::array< double, 2 > Point2D
Shorthand for 2D real points.