/orunav_motion_planner/include/orunav_motion_planner/DiscWorldVisualizer.h

https://github.com/OrebroUniversity/navigation_oru-release · C Header · 199 lines · 56 code · 33 blank · 110 comment · 0 complexity · b29fb00677e43a96e912dc86a736909b MD5 · raw file

  1. /**
  2. * @file DiscWorldVisualizer.h
  3. * @author Marcello Cirillo
  4. *
  5. * Created on: Mar 2, 2011
  6. * Author: marcello
  7. */
  8. #ifndef WORLDVISUALIZER_H_
  9. #define WORLDVISUALIZER_H_
  10. #include "opencv/cv.h"
  11. #include "opencv/highgui.h"
  12. #ifdef _WIN32 // windows
  13. #include <boost/thread/thread.hpp>
  14. #else // linux
  15. #include <boost/thread.hpp>
  16. #endif
  17. #include <boost/date_time.hpp>
  18. #include "WorldParameters.h"
  19. #include "LHDConfiguration.h"
  20. #include "CarConfiguration.h"
  21. #include "UnicycleConfiguration.h"
  22. #include "CarModel.h"
  23. #include "LHDModel.h"
  24. #include "UnicycleModel.h"
  25. #define AVAIL_COLORS 5
  26. /**
  27. * @class DiscWorldVisualizer
  28. * This class exports methods to visualize a discretized version of the world.
  29. * The display routines are run in a separate thread.
  30. */
  31. class DiscWorldVisualizer {
  32. private:
  33. /** define the colors for 5 different vehicles */
  34. static unsigned short int R[5];
  35. static unsigned short int G[5];
  36. static unsigned short int B[5];
  37. /** The image to be displayed */
  38. IplImage* worldDisplayImg_;
  39. /** Mutex to avoid deadlocks when two threads try to work on the image */
  40. boost::mutex update_mutex_;
  41. /** The number of cells on the x axis on the discretized representation of the World */
  42. int xTotCels_;
  43. /** the number of cells on the y axis on the discretized representation of the World */
  44. int yTotCels_;
  45. /** Size of the images */
  46. int imgXsize_;
  47. int imgYsize_;
  48. /** Scale factor for the world representation, in pixels per cell */
  49. int scaleFactor_;
  50. /** boolean to signal the display thread to stop */
  51. bool threadStop_;
  52. /** visualization thread */
  53. boost::thread visualizedThread_;
  54. /**
  55. * Stop the thread.
  56. */
  57. void stopVisualization();
  58. /**
  59. * Meta-method that selects the appropriate Configuration drawing
  60. * function
  61. * @param conf The configuration to draw
  62. * @param R,G,B Color
  63. */
  64. void drawConfiguration(Configuration* conf, int R, int G, int B);
  65. /**
  66. * Draw a Configuration: position (x,y) and orientation
  67. * @param conf The configuration to draw
  68. * @param R,G,B Color
  69. */
  70. void drawBaseConfiguration(Configuration* conf, int R, int G, int B);
  71. /**
  72. * Draw a CarConfiguration: position (x,y) and orientation
  73. * @todo CHECK wheels orientation static
  74. * @param conf The configuration to draw
  75. * @param R,G,B Color
  76. */
  77. void drawCarConfiguration(CarConfiguration* conf, int R, int G, int B);
  78. /**
  79. * Draw a waist actuated vehicle configuration
  80. * @todo CHECK waist actuation always equal to 0
  81. * @param conf The LHDConfiguration to draw
  82. * @param R,G,B Color
  83. */
  84. void drawLHDConfiguration(LHDConfiguration* conf, int R, int G, int B);
  85. /**
  86. * Draw a path composed by vehicleSimplePoint
  87. * @param path vehicleSimplePoint vector
  88. */
  89. void drawPath(std::vector<vehicleSimplePoint> path, int R, int G, int B);
  90. /**
  91. * Draw a dot in the position specified
  92. * @param x,y The coordinates of the centre
  93. * @param radius The radius of the filled circle
  94. * @param R,G,B Color
  95. */
  96. void drawDot(double x, double y, double radius, int R, int G, int B);
  97. /**
  98. * Draw a line between two points
  99. * @param xfrom,yfrom The coordinates of the line start
  100. * @param xto, yto The coordinates of the line end
  101. * @param R,G,B The color of the line
  102. */
  103. void drawLine(double xfrom, double yfrom, double xto, double yto, int R, int G, int B);
  104. /**
  105. * Draw a colour filled rectangle given x,y of two opposite corners
  106. * @param xfrom,yfrom The coordinates of the first corner
  107. * @param xto, yto The coordinates of the opposite corner
  108. * @param R,G,B The color of the rectangle
  109. */
  110. void drawFilledRectangle(double xfrom, double yfrom, double xto, double yto, int R, int G, int B);
  111. /**
  112. * Draw a rectangle given x,y of two opposite corners
  113. * @param xfrom,yfrom The coordinates of the first corner
  114. * @param xto, yto The coordinates of the opposite corner
  115. * @param R,G,B The color of the rectangle
  116. */
  117. void drawRectangle(double xfrom, double yfrom, double xto, double yto, int R, int G, int B);
  118. public:
  119. /**
  120. * The constructor
  121. * @param xCels Number of cells on the x axis
  122. * @param yCels Number of cells on the y axis
  123. * @param scale The scale factor for the visualization
  124. */
  125. DiscWorldVisualizer(int xCels, int yCels, int scale);
  126. virtual ~DiscWorldVisualizer();
  127. /**
  128. * Reset the visualization to the simple grid
  129. */
  130. void resetVisualizer();
  131. /**
  132. * Draw the occupancy map in different shades according to the occupancy value
  133. * @param map Pointer to the occupancy map
  134. */
  135. void drawOccupancy(std::vector<std::vector<double> > map);
  136. /**
  137. * Draw a start Configuration
  138. * @param conf The Configuration of the starting point
  139. * @param vehicleID The ID of the vehicle to draw
  140. */
  141. void drawStart(Configuration* conf, int vehicleID = 0);
  142. /**
  143. * Draw a goal Configuration
  144. * @param conf The Configuration representing the goal
  145. * @param vehicleID The ID of the vehicle to draw
  146. */
  147. void drawGoal(Configuration* conf, int vehicleID = 0);
  148. /**
  149. * Draw a vector of Configuration pointers color coded by vehicle ID
  150. * @param confs The vector of Configuration pointers to draw
  151. */
  152. void drawConfigurations(std::vector<Configuration*> confs);
  153. /**
  154. * Display the image of the world. This function is designed to be used in
  155. * separate thread using the DisplayDiscWorld_thread_wrapper
  156. */
  157. void display();
  158. };
  159. /**
  160. * Wrapper function that allows the display function of the visualizer
  161. * to be called as a thread
  162. */
  163. static inline void DisplayDiscWorld_thread_wrapper(DiscWorldVisualizer* v) {
  164. v->display();
  165. }
  166. #endif /* WORLDVISUALIZER_H_ */