KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
psi_visualize.h
Go to the documentation of this file.
1 /* $Id: psi_visualize.h 18278 2014-11-25 01:42:10Z ksimek $ */
2 /* {{{=========================================================================== *
3  |
4  | Copyright (c) 1994-2011 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Kyle Simek
18  * =========================================================================== }}}*/
19 
20 // vim: tabstop=4 shiftwidth=4 foldmethod=marker
21 
22 #ifndef KJB_PSI_VISUALIZE_V1_H
23 #define KJB_PSI_VISUALIZE_V1_H
24 
25 
26 #include <l_cpp/l_exception.h>
27 #include <m_cpp/m_vector_d.h>
28 #include <gr_cpp/gr_sprite.h>
29 #include <gr_cpp/gr_glut.h>
30 #include <gr_cpp/gr_opengl.h>
31 #include <video_cpp/video_player.h>
35 #include <psi_cpp/psi_model.h>
36 #include <psi_cpp/psi_util.h>
37 #include <psi_cpp/psi_metrics.h>
39 
40 #include <fstream>
41 #include <vector>
42 
43 #include <boost/bind.hpp>
44 #include <boost/function.hpp>
45 
46 namespace kjb
47 {
48 namespace psi
49 {
50 
51 #ifdef KJB_HAVE_GLUT
52 class Track_visualizer : public Video_player
53 {
54 
55 typedef Track_visualizer Self;
56 typedef Video_player Base;
57 
58 public:
59  Track_visualizer() :
60  Base(),
61  trajectories_(),
62  colors_()
63  {}
64 
65  void set_camera(const Perspective_camera& cam)
66  {
67  cam_ = cam;
68  }
69 
70  void set_trajectories(const pt::Trajectory_map& trajectories);
71 
72  virtual void render() const
73  {
74  Base::render();
75 
76  cam_.prepare_for_rendering(false);
77  render(trajectories_, colors_);
78  }
79 
82  void render(
83  const kjb::pt::Trajectory_map& trajectories,
84  const std::map<pt::Entity_id,
85  std::vector<Vector3> >& colors) const;
86 
91  void render(
92  const pt::Trajectory& traj,
93  int center,
94  int radius,
95  const std::vector<Vector3>& colors = std::vector<Vector3>()) const;
96 
97 protected:
98  const std::map<pt::Entity_id, std::vector<Vector3> >&
99  get_colors() const
100  {
101  return colors_;
102  }
103 
104  const pt::Trajectory_map& get_trajectories() const
105  {
106  return trajectories_;
107  }
108 
109 private:
110  pt::Trajectory_map trajectories_;
111  Perspective_camera cam_;
112  std::map<pt::Entity_id, std::vector<Vector3> > colors_;
113 
114 };
115 
116 
117 class Ground_truth_track_visualizer : public Track_visualizer
118 {
119 typedef Ground_truth_track_visualizer Self;
120 typedef Track_visualizer Base;
121 
122 public:
123  Ground_truth_track_visualizer(double threshold) :
124  Base(),
125  hyp_trajectories_(),
126  hyp_colors_(),
127  correspondences_(),
128  threshold_(threshold)
129  {}
130 
132  void set_trajectories(const pt::Trajectory_map& ground_truth, const pt::Trajectory_map& hypothesis);
133 
135  const std::map<pt::Entity_id, std::vector<Vector3> >&
136  gt_colors() const
137  {
138  return get_colors();
139  }
140 
142  const pt::Trajectory_map& gt_trajectories() const
143  {
144  return get_trajectories();
145  }
146 
148  virtual void render() const
149  {
150  glDisable(GL_LINE_STIPPLE);
151  Base::render();
152  render_correspondence_lines();
153 
154  glEnable(GL_LINE_STIPPLE);
155  glLineStipple(1, 0x00ff); // 0000 0000 1111 1111
156  Base::render(hyp_trajectories_, hyp_colors_);
157 
158  }
159 
160  void render_correspondence_lines() const;
161 
162 private:
163  pt::Trajectory_map hyp_trajectories_;
164  std::map<pt::Entity_id, std::vector<Vector3> > hyp_colors_;
165  std::vector<boost::bimap<pt::Entity_id, pt::Entity_id> > correspondences_;
166  double threshold_;
167 };
168 
169 class Cylinder_world_visualizer
170 {
171 typedef Cylinder_world_visualizer Self;
172 
173 public:
174  Cylinder_world_visualizer(double width, double height):
175  cam_(),
176  entities_frames_(),
177  num_frames_(0),
178  sample_period_(0.0),
179  cur_frame_(0),
180  width_(width),
181  height_(height),
182  wnd_(width, height),
183  animating_(true),
184  frame_sprites_(),
185  frame_thinning_(1),
186  frames_boxes_()
187  {
188  using namespace boost;
189 
190  wnd_.set_display_callback(bind(&Self::display, this));
191  wnd_.set_keyboard_callback(bind(&Self::key, this, _1, _2, _3));
192 
193  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
194  glEnable(GL_LINE_SMOOTH);
195  glEnable(GL_BLEND);
196  glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
197  glLineWidth(1.5);
198  }
199 
200 
201  Cylinder_world_visualizer(double width, double height, double sample_period):
202  cam_(),
203  entities_frames_(),
204  num_frames_(0),
205  sample_period_(sample_period *1000),
206  cur_frame_(0),
207  wnd_(width, height),
208  animating_(true),
209  frame_sprites_(),
210  frame_thinning_(1),
211  frames_boxes_()
212  {
213  using namespace boost;
214 
215  wnd_.set_display_callback(bind(&Self::display, this));
216  wnd_.set_keyboard_callback(bind(&Self::key, this, _1, _2, _3));
217 
218  init_animate_callback_();
219  }
220 
221  void set_frame_rate(double rate)
222  {
223  sample_period_ = rate;
224  init_animate_callback_();
225  }
226 
227  void set_frames(const std::vector<kjb::opengl::Sprite>& sprites, size_t thinning)
228  {
229  frame_sprites_ = sprites;
230  frame_thinning_ = thinning;
231  }
232 
233  void set_camera(const kjb::Perspective_camera& cam)
234  {
235  cam_ = cam;
236  }
237 
238  void display();
239 
240  void animate();
241 
242  void key(unsigned char k, int , int );
243 
244  void set_entities(const std::vector<std::vector<std::vector<Entity_state> > >& entities);
245 
252  void set_boxes(const std::vector<std::vector<std::vector<Bbox> > >& boxes, size_t thinning = 1)
253  {
254  frames_boxes_ = boxes;
255  box_thinning_ = thinning;
256  }
257 
262  void set_post_render_callback(const boost::function0<void> cb)
263  {
264  post_render_callback_ = cb;
265  }
266 protected:
267  void draw_xz_plane();
268 
269  void init_animate_callback_()
270  {
271  using namespace boost;
272 
273  kjb::opengl::Glut::add_timer_callback(sample_period_, bind(&Self::animate, this));
274  }
275 
276 protected:
278  std::vector<std::vector<std::vector<Entity_state> > > entities_frames_;
279  size_t num_frames_;
280 // std::vector<std::vector<Cuboid> > cuboids_frames_;
281  size_t sample_period_; // in milliseconds
282 
283  size_t cur_frame_;
284  double width_;
285  double height_;
286  kjb::opengl::Glut_window wnd_;
287  bool animating_;
288 
289  std::vector<kjb::opengl::Sprite> frame_sprites_;
290  size_t frame_thinning_;
291 
292  std::vector<std::vector<std::vector<Bbox> > > frames_boxes_;
293  size_t box_thinning_;
294 
295  boost::function0<void> post_render_callback_;
296 };
297 #endif
298 void render_ground_plane();
299 
300 } // namespace psi
301 } // namespace kjb
302 
303 #endif
for k
Definition: APPgetLargeConnectedEdges.m:61
height
Definition: APPgetLargeConnectedEdges.m:33
void render_ground_plane()
Definition: psi_visualize.cpp:30
St_perspective_camera for modeling a perspective camera using the classic Forsyth and Ponce parametri...
Definition: perspective_camera.h:93
void render(const Cuboid &c)
Definition: psi_weighted_box.cpp:56
Represents a set of trajectories; it is a map from entity to trajectory.
Definition: tracking_trajectory.h:53
Generic_trajectory< Complete_state > Trajectory
Definition: pt_complete_trajectory.h:42
Generic_trajectory_map< Complete_state > Trajectory_map
Definition: pt_complete_trajectory.h:43
Support for error handling exception classes in libKJB.