n-Dimensional Fast Methods  0.7
 All Classes Functions Variables Typedefs Pages
gridpoints.hpp
1 
20 #ifndef GRIDPOINTS_H_
21 #define GRIDPOINTS_H_
22 
23 #include <string>
24 #include <array>
25 
26 #include <CImg.h>
27 
28 #include <fast_methods/ndgridmap/ndgridmap.hpp>
29 
30 
31 using namespace cimg_library;
32 
33 // TODO: include checks which ensure that the grids are adecuate for the functions used.
34 class GridPoints {
35 
36  typedef typename std::array<unsigned int, 2> Coord2D;
37  typedef typename std::array<double, 2> Point2D;
38  typedef typename std::vector <Point2D> Path2D;
39  typedef typename std::vector <Path2D> Paths2D;
40 
41  public:
53  template<class T, size_t ndims>
54  static void selectMapPoints
55  (nDGridMap<T, ndims> & grid, std::array<unsigned int,ndims> & coords_init, std::array<unsigned int,ndims> & coords_goal, const bool flipY = 1) {
56  unsigned int y = 0, x = 0;
57  // TODO: image checking: B/W, correct reading, etc.
58  std::array<unsigned int,2> d = grid.getDimSizes();
59  CImg<double> img(d[0],d[1],1,1,0);
60  if (flipY)
61  // Filling the image flipping Y dim. We want now top left to be the (0,0).
62  cimg_forXY(img,x,y) { img(x,y) = grid[img.width()*(img.height()-y-1)+x].getOccupancy()*255; }
63  else
64  cimg_forXY(img,x,y) { img(x,y) = grid[img.width()*y+x].getOccupancy(); }
65 
66  CImgDisplay main_disp(img,"Click a point");
67 
68  // Detect click of the mouse
69  while (x == 0) {
70  main_disp.wait();
71  if (main_disp.button() && main_disp.mouse_y()>=0) {
72  if (flipY)
73  y = img.height()- 1- main_disp.mouse_y();
74  else
75  y = main_disp.mouse_y();
76  x = main_disp.mouse_x();
77  }
78  }
79 
80  coords_init = {x,y};
81 
82  // Detect second click of the mouse
83  x=0;
84  while (x == 0) {
85  main_disp.wait();
86  if (main_disp.button() && main_disp.mouse_y()>=0) {
87  if (flipY)
88  y = img.height()- 1- main_disp.mouse_y();
89  else
90  y = main_disp.mouse_y();
91  x = main_disp.mouse_x();
92  }
93  }
94 
95  coords_goal = {x,y};
96  }
97 };
98 
99 #endif /* GRIDPLOTTER_H_ */
Templated class which represents a n-dimensional grid map. Its cells are assumed to be cubic...
Definition: ndgridmap.hpp:47
std::array< unsigned int, ndims > getDimSizes() const
Returns the size of each dimension.
Definition: ndgridmap.hpp:115
Auxiliar class which helps to select initial and goal points in a 2D grid.
Definition: gridpoints.hpp:34