Point Cloud Library (PCL)  1.12.1-dev
image_viewer.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2012, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  */
38 
39 #pragma once
40 
41 #include <pcl/memory.h>
42 #include <pcl/pcl_macros.h>
43 #include <pcl/point_types.h>
44 #include <pcl/console/print.h>
45 #include <pcl/visualization/interactor_style.h>
46 #include <pcl/visualization/vtk/pcl_image_canvas_source_2d.h>
47 #include <pcl/visualization/vtk/pcl_context_item.h>
48 #include <pcl/geometry/planar_polygon.h>
49 #include <pcl/correspondence.h>
50 
51 #include <boost/shared_array.hpp>
52 
53 #include <vtkVersion.h>
54 #include <vtkInteractorStyleImage.h>
55 #include <vtkRenderWindowInteractor.h>
56 
57 class vtkImageSlice;
58 class vtkContextActor;
59 class vtkImageViewer;
60 class vtkImageFlip;
61 
62 namespace pcl
63 {
64  namespace visualization
65  {
66  using Vector3ub = Eigen::Array<unsigned char, 3, 1>;
67  static const Vector3ub green_color (0, 255, 0);
68  static const Vector3ub red_color (255, 0, 0);
69  static const Vector3ub blue_color (0, 0, 255);
70 
71  /** \brief An image viewer interactor style, tailored for ImageViewer.
72  * \author Radu B. Rusu
73  * \ingroup visualization
74  */
75  class PCL_EXPORTS ImageViewerInteractorStyle : public vtkInteractorStyleImage
76  {
77  public:
80 
81  void OnMouseWheelForward () override {}
82  void OnMouseWheelBackward () override {}
83  void OnMiddleButtonDown () override {}
84  void OnRightButtonDown () override {}
85  void OnLeftButtonDown () override;
86 
87  void
88  OnChar () override;
89 
90  void
91  adjustCamera (vtkImageData *image, vtkRenderer *ren);
92 
93  void
94  adjustCamera (vtkRenderer *ren);
95  };
96 
97  /** \brief ImageViewer is a class for 2D image visualization.
98  *
99  * Features include:
100  * - add and remove different layers with different opacity (transparency) values
101  * - add 2D geometric shapes (circles, boxes, etc) in separate layers
102  * - display RGB, monochrome, float, angle images
103  *
104  * Simple usage example:
105  * \code
106  * pcl::visualization::ImageViewer iv;
107  * iv.addCircle (10, 10, 5, 1.0, 0.0, 0.0, "circles", 1.0); // add a red, fully opaque circle with radius 5 pixels at (10,10) in layer "circles"
108  * iv.addFilledRectangle (10, 20, 10, 20, 0.0, 1.0, 0.0, "boxes", 0.5); // add a green, 50% transparent box at (10,10->20,20) in layer "boxes"
109  * iv.addRGBImage<pcl::PointXYZRGBA> (cloud); // add a RGB image from a point cloud dataset in an "rgb_image" default layer
110  * iv.spin (); // press 'q' to exit
111  * iv.removeLayer ("circles"); // remove layer "circles"
112  * iv.spin (); // press 'q' to exit
113  * \endcode
114  *
115  * \author Radu B. Rusu, Suat Gedikli
116  * \ingroup visualization
117  */
119  {
120  public:
121  using Ptr = shared_ptr<ImageViewer>;
122  using ConstPtr = shared_ptr<const ImageViewer>;
123 
124  /** \brief Constructor.
125  * \param[in] window_title the title of the window
126  */
127  ImageViewer (const std::string& window_title = "");
128 
129  /** \brief Destructor. */
130  virtual ~ImageViewer ();
131 
132  /** \brief Set up the interactor style. By default the interactor style is set to
133  * vtkInteractorStyleImage you can use this to set it to another type.
134  * \param[in] style user set interactor style.
135  */
136  void
137  setInteractorStyle (vtkInteractorObserver *style)
138  {
139  interactor_->SetInteractorStyle (style);
140  }
141 
142  /** \brief Show a monochrome 2D image on screen.
143  * \param[in] data the input data representing the image
144  * \param[in] width the width of the image
145  * \param[in] height the height of the image
146  * \param[in] layer_id the name of the layer (default: "image")
147  * \param[in] opacity the opacity of the layer (default: 1.0)
148  */
149  void
150  showMonoImage (const unsigned char* data, unsigned width, unsigned height,
151  const std::string &layer_id = "mono_image", double opacity = 1.0);
152 
153  /** \brief Add a monochrome 2D image layer, but do not render it (use spin/spinOnce to update).
154  * \param[in] data the input data representing the image
155  * \param[in] width the width of the image
156  * \param[in] height the height of the image
157  * \param[in] layer_id the name of the layer (default: "image")
158  * \param[in] opacity the opacity of the layer (default: 1.0)
159  */
160  void
161  addMonoImage (const unsigned char* data, unsigned width, unsigned height,
162  const std::string &layer_id = "mono_image", double opacity = 1.0);
163 
164  /** \brief Show a monochrome 2D image on screen.
165  * \param[in] cloud the input data representing the grayscale point cloud
166  * \param[in] layer_id the name of the layer (default: "image")
167  * \param[in] opacity the opacity of the layer (default: 1.0)
168  */
169  inline void
171  const std::string &layer_id = "mono_image", double opacity = 1.0)
172  {
173  return (showMonoImage (*cloud, layer_id, opacity));
174  }
175 
176  /** \brief Add a monochrome 2D image layer, but do not render it (use spin/spinOnce to update).
177  * \param[in] cloud the input data representing the grayscale point cloud
178  * \param[in] layer_id the name of the layer (default: "image")
179  * \param[in] opacity the opacity of the layer (default: 1.0)
180  */
181  inline void
183  const std::string &layer_id = "mono_image", double opacity = 1.0)
184  {
185  return (addMonoImage (*cloud, layer_id, opacity));
186  }
187 
188  /** \brief Show a monochrome 2D image on screen.
189  * \param[in] cloud the input data representing the grayscale point cloud
190  * \param[in] layer_id the name of the layer (default: "image")
191  * \param[in] opacity the opacity of the layer (default: 1.0)
192  */
193  void
195  const std::string &layer_id = "mono_image", double opacity = 1.0);
196 
197  /** \brief Add a monochrome 2D image layer, but do not render it (use spin/spinOnce to update).
198  * \param[in] cloud the input data representing the RGB point cloud
199  * \param[in] layer_id the name of the layer (default: "image")
200  * \param[in] opacity the opacity of the layer (default: 1.0)
201  */
202  void
204  const std::string &layer_id = "mono_image", double opacity = 1.0);
205 
206  /** \brief Show a monochrome 2D image on screen.
207  * \param[in] cloud the input data representing the grayscale point cloud
208  * \param[in] layer_id the name of the layer (default: "image")
209  * \param[in] opacity the opacity of the layer (default: 1.0)
210  */
211  inline void
213  const std::string &layer_id = "mono_image", double opacity = 1.0)
214  {
215  return (showMonoImage (*cloud, layer_id, opacity));
216  }
217 
218  /** \brief Add a monochrome 2D image layer, but do not render it (use spin/spinOnce to update).
219  * \param[in] cloud the input data representing the grayscale point cloud
220  * \param[in] layer_id the name of the layer (default: "image")
221  * \param[in] opacity the opacity of the layer (default: 1.0)
222  */
223  inline void
225  const std::string &layer_id = "mono_image", double opacity = 1.0)
226  {
227  return (addMonoImage (*cloud, layer_id, opacity));
228  }
229 
230  /** \brief Show a monochrome 2D image on screen.
231  * \param[in] cloud the input data representing the grayscale point cloud
232  * \param[in] layer_id the name of the layer (default: "image")
233  * \param[in] opacity the opacity of the layer (default: 1.0)
234  */
235  void
237  const std::string &layer_id = "mono_image", double opacity = 1.0);
238 
239  /** \brief Add a monochrome 2D image layer, but do not render it (use spin/spinOnce to update).
240  * \param[in] cloud the input data representing the RGB point cloud
241  * \param[in] layer_id the name of the layer (default: "image")
242  * \param[in] opacity the opacity of the layer (default: 1.0)
243  */
244  void
246  const std::string &layer_id = "mono_image", double opacity = 1.0);
247 
248  /** \brief Show a 2D RGB image on screen.
249  * \param[in] data the input data representing the image
250  * \param[in] width the width of the image
251  * \param[in] height the height of the image
252  * \param[in] layer_id the name of the layer (default: "image")
253  * \param[in] opacity the opacity of the layer (default: 1.0)
254  */
255  void
256  showRGBImage (const unsigned char* data, unsigned width, unsigned height,
257  const std::string &layer_id = "rgb_image", double opacity = 1.0);
258 
259  /** \brief Add an RGB 2D image layer, but do not render it (use spin/spinOnce to update).
260  * \param[in] data the input data representing the image
261  * \param[in] width the width of the image
262  * \param[in] height the height of the image
263  * \param[in] layer_id the name of the layer (default: "image")
264  * \param[in] opacity the opacity of the layer (default: 1.0)
265  * \param[in] autoresize flag to enable window to adapt to image size (default true)
266  */
267  void
268  addRGBImage (const unsigned char* data, unsigned width, unsigned height,
269  const std::string &layer_id = "rgb_image", double opacity = 1.0,
270  bool autoresize = true);
271 
272  /** \brief Show a 2D image on screen, obtained from the RGB channel of a point cloud.
273  * \param[in] cloud the input data representing the RGB point cloud
274  * \param[in] layer_id the name of the layer (default: "image")
275  * \param[in] opacity the opacity of the layer (default: 1.0)
276  */
277  template <typename T> inline void
279  const std::string &layer_id = "rgb_image", double opacity = 1.0)
280  {
281  return (showRGBImage<T> (*cloud, layer_id, opacity));
282  }
283 
284  /** \brief Add an RGB 2D image layer, but do not render it (use spin/spinOnce to update).
285  * \param[in] cloud the input data representing the RGB point cloud
286  * \param[in] layer_id the name of the layer (default: "image")
287  * \param[in] opacity the opacity of the layer (default: 1.0)
288  */
289  template <typename T> inline void
291  const std::string &layer_id = "rgb_image", double opacity = 1.0)
292  {
293  return (addRGBImage<T> (*cloud, layer_id, opacity));
294  }
295 
296  /** \brief Show a 2D image on screen, obtained from the RGB channel of a point cloud.
297  * \param[in] cloud the input data representing the RGB point cloud
298  * \param[in] layer_id the name of the layer (default: "image")
299  * \param[in] opacity the opacity of the layer (default: 1.0)
300  */
301  template <typename T> void
302  showRGBImage (const pcl::PointCloud<T> &cloud,
303  const std::string &layer_id = "rgb_image", double opacity = 1.0);
304 
305  /** \brief Add an RGB 2D image layer, but do not render it (use spin/spinOnce to update).
306  * \param[in] cloud the input data representing the RGB point cloud
307  * \param[in] layer_id the name of the layer (default: "image")
308  * \param[in] opacity the opacity of the layer (default: 1.0)
309  */
310  template <typename T> void
311  addRGBImage (const pcl::PointCloud<T> &cloud,
312  const std::string &layer_id = "rgb_image", double opacity = 1.0);
313 
314  /** \brief Show a 2D image (float) on screen.
315  * \param[in] data the input data representing the image in float format
316  * \param[in] width the width of the image
317  * \param[in] height the height of the image
318  * \param[in] min_value filter all values in the image to be larger than this minimum value
319  * \param[in] max_value filter all values in the image to be smaller than this maximum value
320  * \param[in] grayscale show data as grayscale (true) or not (false). Default: false
321  * \param[in] layer_id the name of the layer (default: "image")
322  * \param[in] opacity the opacity of the layer (default: 1.0)
323  */
324  void
325  showFloatImage (const float* data, unsigned int width, unsigned int height,
326  float min_value = std::numeric_limits<float>::min (),
327  float max_value = std::numeric_limits<float>::max (), bool grayscale = false,
328  const std::string &layer_id = "float_image", double opacity = 1.0);
329 
330  /** \brief Add a float 2D image layer, but do not render it (use spin/spinOnce to update).
331  * \param[in] data the input data representing the image in float format
332  * \param[in] width the width of the image
333  * \param[in] height the height of the image
334  * \param[in] min_value filter all values in the image to be larger than this minimum value
335  * \param[in] max_value filter all values in the image to be smaller than this maximum value
336  * \param[in] grayscale show data as grayscale (true) or not (false). Default: false
337  * \param[in] layer_id the name of the layer (default: "image")
338  * \param[in] opacity the opacity of the layer (default: 1.0)
339  */
340  void
341  addFloatImage (const float* data, unsigned int width, unsigned int height,
342  float min_value = std::numeric_limits<float>::min (),
343  float max_value = std::numeric_limits<float>::max (), bool grayscale = false,
344  const std::string &layer_id = "float_image", double opacity = 1.0);
345 
346  /** \brief Show a 2D image (unsigned short) on screen.
347  * \param[in] short_image the input data representing the image in unsigned short format
348  * \param[in] width the width of the image
349  * \param[in] height the height of the image
350  * \param[in] min_value filter all values in the image to be larger than this minimum value
351  * \param[in] max_value filter all values in the image to be smaller than this maximum value
352  * \param[in] grayscale show data as grayscale (true) or not (false). Default: false
353  * \param[in] layer_id the name of the layer (default: "image")
354  * \param[in] opacity the opacity of the layer (default: 1.0)
355  */
356  void
357  showShortImage (const unsigned short* short_image, unsigned int width, unsigned int height,
358  unsigned short min_value = std::numeric_limits<unsigned short>::min (),
359  unsigned short max_value = std::numeric_limits<unsigned short>::max (), bool grayscale = false,
360  const std::string &layer_id = "short_image", double opacity = 1.0);
361 
362  /** \brief Add a short 2D image layer, but do not render it (use spin/spinOnce to update).
363  * \param[in] short_image the input data representing the image in unsigned short format
364  * \param[in] width the width of the image
365  * \param[in] height the height of the image
366  * \param[in] min_value filter all values in the image to be larger than this minimum value
367  * \param[in] max_value filter all values in the image to be smaller than this maximum value
368  * \param[in] grayscale show data as grayscale (true) or not (false). Default: false
369  * \param[in] layer_id the name of the layer (default: "image")
370  * \param[in] opacity the opacity of the layer (default: 1.0)
371  */
372  void
373  addShortImage (const unsigned short* short_image, unsigned int width, unsigned int height,
374  unsigned short min_value = std::numeric_limits<unsigned short>::min (),
375  unsigned short max_value = std::numeric_limits<unsigned short>::max (), bool grayscale = false,
376  const std::string &layer_id = "short_image", double opacity = 1.0);
377 
378  /** \brief Show a 2D image on screen representing angle data.
379  * \param[in] data the input data representing the image
380  * \param[in] width the width of the image
381  * \param[in] height the height of the image
382  * \param[in] layer_id the name of the layer (default: "image")
383  * \param[in] opacity the opacity of the layer (default: 1.0)
384  */
385  void
386  showAngleImage (const float* data, unsigned width, unsigned height,
387  const std::string &layer_id = "angle_image", double opacity = 1.0);
388 
389  /** \brief Add an angle 2D image layer, but do not render it (use spin/spinOnce to update).
390  * \param[in] data the input data representing the image
391  * \param[in] width the width of the image
392  * \param[in] height the height of the image
393  * \param[in] layer_id the name of the layer (default: "image")
394  * \param[in] opacity the opacity of the layer (default: 1.0)
395  */
396  void
397  addAngleImage (const float* data, unsigned width, unsigned height,
398  const std::string &layer_id = "angle_image", double opacity = 1.0);
399 
400  /** \brief Show a 2D image on screen representing half angle data.
401  * \param[in] data the input data representing the image
402  * \param[in] width the width of the image
403  * \param[in] height the height of the image
404  * \param[in] layer_id the name of the layer (default: "image")
405  * \param[in] opacity the opacity of the layer (default: 1.0)
406  */
407  void
408  showHalfAngleImage (const float* data, unsigned width, unsigned height,
409  const std::string &layer_id = "half_angle_image", double opacity = 1.0);
410 
411  /** \brief Add a half angle 2D image layer, but do not render it (use spin/spinOnce to update).
412  * \param[in] data the input data representing the image
413  * \param[in] width the width of the image
414  * \param[in] height the height of the image
415  * \param[in] layer_id the name of the layer (default: "image")
416  * \param[in] opacity the opacity of the layer (default: 1.0)
417  */
418  void
419  addHalfAngleImage (const float* data, unsigned width, unsigned height,
420  const std::string &layer_id = "half_angle_image", double opacity = 1.0);
421 
422  /** \brief Sets the pixel at coordinates(u,v) to color while setting the neighborhood to another
423  * \param[in] u the u/x coordinate of the pixel
424  * \param[in] v the v/y coordinate of the pixel
425  * \param[in] fg_color the pixel color
426  * \param[in] bg_color the neighborhood color
427  * \param[in] radius the circle radius around the pixel
428  * \param[in] layer_id the name of the layer (default: "points")
429  * \param[in] opacity the opacity of the layer (default: 1.0)
430  */
431  void
432  markPoint (std::size_t u, std::size_t v, Vector3ub fg_color, Vector3ub bg_color = red_color, double radius = 3.0,
433  const std::string &layer_id = "points", double opacity = 1.0);
434 
435  /** \brief Sets the pixel at coordinates(u,v) to color while setting the neighborhood to another
436  * \param[in] uv the u/x, v/y coordinate of the pixels to be marked
437  * \param[in] fg_color the pixel color
438  * \param[in] bg_color the neighborhood color
439  * \param[in] size edge of the square surrounding each pixel
440  * \param[in] layer_id the name of the layer (default: "markers")
441  * \param[in] opacity the opacity of the layer (default: 1.0)
442  */
443  void
444  markPoints (const std::vector<int>& uv, Vector3ub fg_color, Vector3ub bg_color = red_color, double size = 3.0,
445  const std::string &layer_id = "markers", double opacity = 1.0);
446 
447  /** \brief Sets the pixel at coordinates(u,v) to color while setting the neighborhood to another (float coordinates version).
448  * \param[in] uv the u/x, v/y coordinate of the pixels to be marked
449  * \param[in] fg_color the pixel color
450  * \param[in] bg_color the neighborhood color
451  * \param[in] size edge of the square surrounding each pixel
452  * \param[in] layer_id the name of the layer (default: "markers")
453  * \param[in] opacity the opacity of the layer (default: 1.0)
454  */
455  void
456  markPoints (const std::vector<float>& uv, Vector3ub fg_color, Vector3ub bg_color = red_color, double size = 3.0,
457  const std::string &layer_id = "markers", double opacity = 1.0);
458 
459  /** \brief Set the window title name
460  * \param[in] name the window title
461  */
462  void
463  setWindowTitle (const std::string& name);
464 
465  /** \brief Spin method. Calls the interactor and runs an internal loop. */
466  void
467  spin ();
468 
469  /** \brief Spin once method. Calls the interactor and updates the screen once.
470  * \param[in] time - How long (in ms) should the visualization loop be allowed to run.
471  * \param[in] force_redraw - if false it might return without doing anything if the
472  * interactor's framerate does not require a redraw yet.
473  */
474  void
475  spinOnce (int time = 1, bool force_redraw = true);
476 
477  /** \brief Register a callback function for keyboard events
478  * \param[in] callback the function that will be registered as a callback for a keyboard event
479  * \param[in] cookie user data that is passed to the callback
480  * \return a connection object that allows to disconnect the callback function.
481  */
482  boost::signals2::connection
484  void* cookie = nullptr)
485  {
486  return (registerKeyboardCallback ([=] (const pcl::visualization::KeyboardEvent& e) { (*callback) (e, cookie); }));
487  }
488 
489  /** \brief Register a callback function for keyboard events
490  * \param[in] callback the member function that will be registered as a callback for a keyboard event
491  * \param[in] instance instance to the class that implements the callback function
492  * \param[in] cookie user data that is passed to the callback
493  * \return a connection object that allows to disconnect the callback function.
494  */
495  template<typename T> boost::signals2::connection
496  registerKeyboardCallback (void (T::*callback) (const pcl::visualization::KeyboardEvent&, void*),
497  T& instance, void* cookie = nullptr)
498  {
499  return (registerKeyboardCallback ([=, &instance] (const pcl::visualization::KeyboardEvent& e) { (instance.*callback) (e, cookie); }));
500  }
501 
502  /** \brief Register a callback std::function for keyboard events
503  * \param[in] cb the boost function that will be registered as a callback for a keyboard event
504  * \return a connection object that allows to disconnect the callback function.
505  */
506  boost::signals2::connection
508 
509  /** \brief Register a callback std::function for mouse events
510  * \param[in] callback the function that will be registered as a callback for a mouse event
511  * \param[in] cookie user data that is passed to the callback
512  * \return a connection object that allows to disconnect the callback function.
513  */
514  boost::signals2::connection
515  registerMouseCallback (void (*callback) (const pcl::visualization::MouseEvent&, void*),
516  void* cookie = nullptr)
517  {
518  return (registerMouseCallback ([=] (const pcl::visualization::MouseEvent& e) { (*callback) (e, cookie); }));
519  }
520 
521  /** \brief Register a callback function for mouse events
522  * \param[in] callback the member function that will be registered as a callback for a mouse event
523  * \param[in] instance instance to the class that implements the callback function
524  * \param[in] cookie user data that is passed to the callback
525  * \return a connection object that allows to disconnect the callback function.
526  */
527  template<typename T> boost::signals2::connection
528  registerMouseCallback (void (T::*callback) (const pcl::visualization::MouseEvent&, void*),
529  T& instance, void* cookie = nullptr)
530  {
531  return (registerMouseCallback ([=, &instance] (const pcl::visualization::MouseEvent& e) { (instance.*callback) (e, cookie); }));
532  }
533 
534  /** \brief Register a callback function for mouse events
535  * \param[in] cb the boost function that will be registered as a callback for a mouse event
536  * \return a connection object that allows to disconnect the callback function.
537  */
538  boost::signals2::connection
539  registerMouseCallback (std::function<void (const pcl::visualization::MouseEvent&)> cb);
540 
541  /** \brief Set the position in screen coordinates.
542  * \param[in] x where to move the window to (X)
543  * \param[in] y where to move the window to (Y)
544  */
545  void
546  setPosition (int x, int y);
547 
548  /** \brief Set the window size in screen coordinates.
549  * \param[in] xw window size in horizontal (pixels)
550  * \param[in] yw window size in vertical (pixels)
551  */
552  void
553  setSize (int xw, int yw);
554 
555  /** \brief Return the window size in pixels. */
556  int*
558 
559  /** \brief Returns true when the user tried to close the window */
560  bool
561  wasStopped () const { return (stopped_); }
562 
563  /** \brief Stop the interaction and close the visualizaton window. */
564  void
565  close ()
566  {
567  stopped_ = true;
568  // This tends to close the window...
569  interactor_->TerminateApp ();
570  }
571 
572  /** \brief Add a circle shape from a point and a radius
573  * \param[in] x the x coordinate of the circle center
574  * \param[in] y the y coordinate of the circle center
575  * \param[in] radius the radius of the circle
576  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
577  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
578  */
579  bool
580  addCircle (unsigned int x, unsigned int y, double radius,
581  const std::string &layer_id = "circles", double opacity = 1.0);
582 
583  /** \brief Add a circle shape from a point and a radius
584  * \param[in] x the x coordinate of the circle center
585  * \param[in] y the y coordinate of the circle center
586  * \param[in] radius the radius of the circle
587  * \param[in] r the red channel of the color that the sphere should be rendered with (0.0 -> 1.0)
588  * \param[in] g the green channel of the color that the sphere should be rendered with (0.0 -> 1.0)
589  * \param[in] b the blue channel of the color that the sphere should be rendered with (0.0 -> 1.0)
590  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
591  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
592  */
593  bool
594  addCircle (unsigned int x, unsigned int y, double radius,
595  double r, double g, double b,
596  const std::string &layer_id = "circles", double opacity = 1.0);
597 
598  /** \brief Add a 2D box and color its edges with a given color
599  * \param[in] min_pt the X,Y min coordinate
600  * \param[in] max_pt the X,Y max coordinate
601  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
602  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
603  */
604  bool
605  addRectangle (const pcl::PointXY &min_pt, const pcl::PointXY &max_pt,
606  const std::string &layer_id = "rectangles", double opacity = 1.0);
607 
608  /** \brief Add a 2D box and color its edges with a given color
609  * \param[in] min_pt the X,Y min coordinate
610  * \param[in] max_pt the X,Y max coordinate
611  * \param[in] r the red channel of the color that the box should be rendered with (0.0 -> 1.0)
612  * \param[in] g the green channel of the color that the box should be rendered with (0.0 -> 1.0)
613  * \param[in] b the blue channel of the color that the box should be rendered with (0.0 -> 1.0)
614  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
615  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
616  */
617  bool
618  addRectangle (const pcl::PointXY &min_pt, const pcl::PointXY &max_pt,
619  double r, double g, double b,
620  const std::string &layer_id = "rectangles", double opacity = 1.0);
621 
622  /** \brief Add a 2D box and color its edges with a given color
623  * \param[in] x_min the X min coordinate
624  * \param[in] x_max the X max coordinate
625  * \param[in] y_min the Y min coordinate
626  * \param[in] y_max the Y max coordinate
627  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
628  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
629  */
630  bool
631  addRectangle (unsigned int x_min, unsigned int x_max, unsigned int y_min, unsigned int y_max,
632  const std::string &layer_id = "rectangles", double opacity = 1.0);
633 
634  /** \brief Add a 2D box and color its edges with a given color
635  * \param[in] x_min the X min coordinate
636  * \param[in] x_max the X max coordinate
637  * \param[in] y_min the Y min coordinate
638  * \param[in] y_max the Y max coordinate
639  * \param[in] r the red channel of the color that the box should be rendered with (0.0 -> 1.0)
640  * \param[in] g the green channel of the color that the box should be rendered with (0.0 -> 1.0)
641  * \param[in] b the blue channel of the color that the box should be rendered with (0.0 -> 1.0)
642  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
643  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
644  */
645  bool
646  addRectangle (unsigned int x_min, unsigned int x_max, unsigned int y_min, unsigned int y_max,
647  double r, double g, double b,
648  const std::string &layer_id = "rectangles", double opacity = 1.0);
649 
650  /** \brief Add a 2D box and color its edges with a given color
651  * \param[in] image the organized point cloud dataset containing the image data
652  * \param[in] min_pt the X,Y min coordinate
653  * \param[in] max_pt the X,Y max coordinate
654  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
655  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
656  */
657  template <typename T> bool
658  addRectangle (const typename pcl::PointCloud<T>::ConstPtr &image,
659  const T &min_pt, const T &max_pt,
660  const std::string &layer_id = "rectangles", double opacity = 1.0);
661 
662  /** \brief Add a 2D box and color its edges with a given color
663  * \param[in] image the organized point cloud dataset containing the image data
664  * \param[in] min_pt the X,Y min coordinate
665  * \param[in] max_pt the X,Y max coordinate
666  * \param[in] r the red channel of the color that the box should be rendered with (0.0 -> 1.0)
667  * \param[in] g the green channel of the color that the box should be rendered with (0.0 -> 1.0)
668  * \param[in] b the blue channel of the color that the box should be rendered with (0.0 -> 1.0)
669  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
670  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
671  */
672  template <typename T> bool
673  addRectangle (const typename pcl::PointCloud<T>::ConstPtr &image,
674  const T &min_pt, const T &max_pt,
675  double r, double g, double b,
676  const std::string &layer_id = "rectangles", double opacity = 1.0);
677 
678  /** \brief Add a 2D box that contains a given image mask and color its edges
679  * \param[in] image the organized point cloud dataset containing the image data
680  * \param[in] mask the point data representing the mask that we want to draw
681  * \param[in] r the red channel of the color that the mask should be rendered with
682  * \param[in] g the green channel of the color that the mask should be rendered with
683  * \param[in] b the blue channel of the color that the mask should be rendered with
684  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
685  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
686  */
687  template <typename T> bool
688  addRectangle (const typename pcl::PointCloud<T>::ConstPtr &image, const pcl::PointCloud<T> &mask,
689  double r, double g, double b,
690  const std::string &layer_id = "rectangles", double opacity = 1.0);
691 
692  /** \brief Add a 2D box that contains a given image mask and color its edges in red
693  * \param[in] image the organized point cloud dataset containing the image data
694  * \param[in] mask the point data representing the mask that we want to draw
695  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
696  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
697  */
698  template <typename T> bool
699  addRectangle (const typename pcl::PointCloud<T>::ConstPtr &image, const pcl::PointCloud<T> &mask,
700  const std::string &layer_id = "image_mask", double opacity = 1.0);
701 
702  /** \brief Add a 2D box and fill it in with a given color
703  * \param[in] x_min the X min coordinate
704  * \param[in] x_max the X max coordinate
705  * \param[in] y_min the Y min coordinate
706  * \param[in] y_max the Y max coordinate
707  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
708  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 0.5)
709  */
710  bool
711  addFilledRectangle (unsigned int x_min, unsigned int x_max, unsigned int y_min, unsigned int y_max,
712  const std::string &layer_id = "boxes", double opacity = 0.5);
713 
714  /** \brief Add a 2D box and fill it in with a given color
715  * \param[in] x_min the X min coordinate
716  * \param[in] x_max the X max coordinate
717  * \param[in] y_min the Y min coordinate
718  * \param[in] y_max the Y max coordinate
719  * \param[in] r the red channel of the color that the box should be rendered with (0.0 -> 1.0)
720  * \param[in] g the green channel of the color that the box should be rendered with (0.0 -> 1.0)
721  * \param[in] b the blue channel of the color that the box should be rendered with (0.0 -> 1.0)
722  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
723  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 0.5)
724  */
725  bool
726  addFilledRectangle (unsigned int x_min, unsigned int x_max, unsigned int y_min, unsigned int y_max,
727  double r, double g, double b,
728  const std::string &layer_id = "boxes", double opacity = 0.5);
729 
730  /** \brief Add a 2D line with a given color
731  * \param[in] x_min the X min coordinate
732  * \param[in] y_min the Y min coordinate
733  * \param[in] x_max the X max coordinate
734  * \param[in] y_max the Y max coordinate
735  * \param[in] r the red channel of the color that the line should be rendered with (0.0 -> 1.0)
736  * \param[in] g the green channel of the color that the line should be rendered with (0.0 -> 1.0)
737  * \param[in] b the blue channel of the color that the line should be rendered with (0.0 -> 1.0)
738  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
739  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
740  */
741  bool
742  addLine (unsigned int x_min, unsigned int y_min, unsigned int x_max, unsigned int y_max,
743  double r, double g, double b,
744  const std::string &layer_id = "line", double opacity = 1.0);
745 
746  /** \brief Add a 2D line with a given color
747  * \param[in] x_min the X min coordinate
748  * \param[in] y_min the Y min coordinate
749  * \param[in] x_max the X max coordinate
750  * \param[in] y_max the Y max coordinate
751  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
752  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
753  */
754  bool
755  addLine (unsigned int x_min, unsigned int y_min, unsigned int x_max, unsigned int y_max,
756  const std::string &layer_id = "line", double opacity = 1.0);
757 
758  /** \brief Add a 2D text with a given color
759  * \param[in] x the X coordinate
760  * \param[in] y the Y coordinate
761  * \param[in] text the text string to be displayed
762  * \param[in] r the red channel of the color that the line should be rendered with (0.0 -> 1.0)
763  * \param[in] g the green channel of the color that the line should be rendered with (0.0 -> 1.0)
764  * \param[in] b the blue channel of the color that the line should be rendered with (0.0 -> 1.0)
765  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
766  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
767  */
768  bool
769  addText (unsigned int x, unsigned int y, const std::string& text,
770  double r, double g, double b,
771  const std::string &layer_id = "line", double opacity = 1.0);
772 
773  /** \brief Add a 2D text with a given color
774  * \param[in] x the X coordinate
775  * \param[in] y the Y coordinate
776  * \param[in] text the text string to be displayed
777  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
778  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
779  */
780  bool
781  addText (unsigned int x, unsigned int y, const std::string& text,
782  const std::string &layer_id = "line", double opacity = 1.0);
783 
784  /** \brief Add a generic 2D mask to an image
785  * \param[in] image the organized point cloud dataset containing the image data
786  * \param[in] mask the point data representing the mask that we want to draw
787  * \param[in] r the red channel of the color that the mask should be rendered with
788  * \param[in] g the green channel of the color that the mask should be rendered with
789  * \param[in] b the blue channel of the color that the mask should be rendered with
790  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
791  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 0.5)
792  */
793  template <typename T> bool
794  addMask (const typename pcl::PointCloud<T>::ConstPtr &image, const pcl::PointCloud<T> &mask,
795  double r, double g, double b,
796  const std::string &layer_id = "image_mask", double opacity = 0.5);
797 
798  /** \brief Add a generic 2D mask to an image (colored in red)
799  * \param[in] image the organized point cloud dataset containing the image data
800  * \param[in] mask the point data representing the mask that we want to draw
801  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
802  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 0.5)
803  */
804  template <typename T> bool
805  addMask (const typename pcl::PointCloud<T>::ConstPtr &image, const pcl::PointCloud<T> &mask,
806  const std::string &layer_id = "image_mask", double opacity = 0.5);
807 
808  /** \brief Add a generic 2D planar polygon to an image
809  * \param[in] image the organized point cloud dataset containing the image data
810  * \param[in] polygon the point data representing the polygon that we want to draw.
811  * A line will be drawn from each point to the next in the dataset.
812  * \param[in] r the red channel of the color that the polygon should be rendered with
813  * \param[in] g the green channel of the color that the polygon should be rendered with
814  * \param[in] b the blue channel of the color that the polygon should be rendered with
815  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
816  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
817  */
818  template <typename T> bool
819  addPlanarPolygon (const typename pcl::PointCloud<T>::ConstPtr &image, const pcl::PlanarPolygon<T> &polygon,
820  double r, double g, double b,
821  const std::string &layer_id = "planar_polygon", double opacity = 1.0);
822 
823  /** \brief Add a generic 2D planar polygon to an image
824  * \param[in] image the organized point cloud dataset containing the image data
825  * \param[in] polygon the point data representing the polygon that we want to draw.
826  * A line will be drawn from each point to the next in the dataset.
827  * \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
828  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
829  */
830  template <typename T> bool
831  addPlanarPolygon (const typename pcl::PointCloud<T>::ConstPtr &image, const pcl::PlanarPolygon<T> &polygon,
832  const std::string &layer_id = "planar_polygon", double opacity = 1.0);
833 
834  /** \brief Add a new 2D rendering layer to the viewer.
835  * \param[in] layer_id the name of the layer
836  * \param[in] width the width of the layer
837  * \param[in] height the height of the layer
838  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 0.5)
839  */
840  bool
841  addLayer (const std::string &layer_id, int width, int height, double opacity = 0.5);
842 
843  /** \brief Remove a 2D layer given by its ID.
844  * \param[in] layer_id the name of the layer
845  */
846  void
847  removeLayer (const std::string &layer_id);
848 
849  /** \brief Add the specified correspondences to the display.
850  * \param[in] source_img The source RGB image
851  * \param[in] target_img The target RGB image
852  * \param[in] correspondences The list of correspondences to display.
853  * \param[in] nth display only the Nth correspondence (e.g., skip the rest)
854  * \param[in] layer_id the layer id (default: "correspondences")
855  */
856  template <typename PointT> bool
857  showCorrespondences (const pcl::PointCloud<PointT> &source_img,
858  const pcl::PointCloud<PointT> &target_img,
859  const pcl::Correspondences &correspondences,
860  int nth = 1,
861  const std::string &layer_id = "correspondences");
862 
863  protected:
864  /** \brief Trigger a render call. */
865  void
866  render ();
867 
868  /** \brief Convert the Intensity information in a PointCloud<Intensity> to an unsigned char array
869  * \param[in] cloud the input cloud containing the grayscale intensity information
870  * \param[out] data a boost shared array of unsigned char type
871  * \note The method assumes that the data array has already been allocated and
872  * contains enough space to copy all the data from cloud!
873  */
874  void
876  boost::shared_array<unsigned char> data);
877 
878  /** \brief Convert the Intensity8u information in a PointCloud<Intensity8u> to an unsigned char array
879  * \param[in] cloud the input cloud containing the grayscale intensity information
880  * \param[out] data a boost shared array of unsigned char type
881  * \note The method assumes that the data array has already been allocated and
882  * contains enough space to copy all the data from cloud!
883  */
884  void
886  boost::shared_array<unsigned char> data);
887 
888  /** \brief Convert the RGB information in a PointCloud<T> to an unsigned char array
889  * \param[in] cloud the input cloud containing the RGB information
890  * \param[out] data a boost shared array of unsigned char type
891  * \note The method assumes that the data array has already been allocated and
892  * contains enough space to copy all the data from cloud!
893  */
894  template <typename T> void
895  convertRGBCloudToUChar (const pcl::PointCloud<T> &cloud,
896  boost::shared_array<unsigned char> &data);
897 
898  /** \brief Set the stopped flag back to false */
899  void
900  resetStoppedFlag () { stopped_ = false; }
901 
902  /** \brief Fire up a mouse event with a specified event ID
903  * \param[in] event_id the id of the event
904  */
905  void
906  emitMouseEvent (unsigned long event_id);
907 
908  /** \brief Fire up a keyboard event with a specified event ID
909  * \param[in] event_id the id of the event
910  */
911  void
912  emitKeyboardEvent (unsigned long event_id);
913 
914  // Callbacks used to register for vtk command
915  static void
916  MouseCallback (vtkObject*, unsigned long eid, void* clientdata, void *calldata);
917  static void
918  KeyboardCallback (vtkObject*, unsigned long eid, void* clientdata, void *calldata);
919 
920  protected: // types
921  struct ExitMainLoopTimerCallback : public vtkCommand
922  {
923  ExitMainLoopTimerCallback () : right_timer_id (), window () {}
924 
926  {
927  return (new ExitMainLoopTimerCallback);
928  }
929  void
930  Execute (vtkObject* vtkNotUsed (caller), unsigned long event_id, void* call_data) override
931  {
932  if (event_id != vtkCommand::TimerEvent)
933  return;
934  int timer_id = *static_cast<int*> (call_data);
935  if (timer_id != right_timer_id)
936  return;
937  window->interactor_->TerminateApp ();
938  }
941  };
942  struct ExitCallback : public vtkCommand
943  {
944  ExitCallback () : window () {}
945 
946  static ExitCallback* New ()
947  {
948  return (new ExitCallback);
949  }
950  void
951  Execute (vtkObject*, unsigned long event_id, void*) override
952  {
953  if (event_id != vtkCommand::ExitEvent)
954  return;
955  window->stopped_ = true;
956  window->interactor_->TerminateApp ();
957  }
959  };
960 
961  private:
962  /** \brief Internal structure describing a layer. */
963  struct Layer
964  {
965  Layer () = default;
967  std::string layer_name;
968  };
969 
970  using LayerMap = std::vector<Layer>;
971 
972  /** \brief Add a new 2D rendering layer to the viewer.
973  * \param[in] layer_id the name of the layer
974  * \param[in] width the width of the layer
975  * \param[in] height the height of the layer
976  * \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 0.5)
977  * \param[in] fill_box set to true to fill in the image with one black box before starting
978  */
979  LayerMap::iterator
980  createLayer (const std::string &layer_id, int width, int height, double opacity = 0.5, bool fill_box = true);
981 
982  boost::signals2::signal<void (const pcl::visualization::MouseEvent&)> mouse_signal_;
983  boost::signals2::signal<void (const pcl::visualization::KeyboardEvent&)> keyboard_signal_;
984 
987  vtkSmartPointer<vtkCallbackCommand> keyboard_command_;
988 
989  /** \brief Callback object enabling us to leave the main loop, when a timer fires. */
990  vtkSmartPointer<ExitMainLoopTimerCallback> exit_main_loop_timer_callback_;
991  vtkSmartPointer<ExitCallback> exit_callback_;
992 
993  /** \brief The ImageViewer widget. */
994  vtkSmartPointer<vtkImageViewer> image_viewer_;
995 
996  /** \brief The render window. */
998 
999  /** \brief The renderer. */
1001 
1002  /** \brief Global prop. This is the actual "actor". */
1004 
1005  /** \brief The interactor style. */
1007 
1008  /** \brief The data array representing the image. Used internally. */
1009  boost::shared_array<unsigned char> data_;
1010 
1011  /** \brief The data array (representing the image) size. Used internally. */
1012  std::size_t data_size_;
1013 
1014  /** \brief Set to false if the interaction loop is running. */
1015  bool stopped_;
1016 
1017  /** \brief Global timer ID. Used in destructor only. */
1018  int timer_id_;
1019 
1020  // /** \brief Internal blender used to overlay 2D geometry over the image. */
1021  // vtkSmartPointer<vtkImageBlend> blend_;
1022 
1023  /** \brief Internal list with different 2D layers shapes. */
1024  LayerMap layer_map_;
1025 
1026  /** \brief Image reslice, used for flipping the image. */
1028 
1029  /** \brief Internal data array. Used everytime add***Image is called.
1030  * Cleared, everytime the render loop is executed.
1031  */
1032  std::vector<unsigned char*> image_data_;
1033 
1034  struct LayerComparator
1035  {
1036  LayerComparator (const std::string &str) : str_ (str) {}
1037  const std::string &str_;
1038 
1039  bool
1040  operator () (const Layer &layer)
1041  {
1042  return (layer.layer_name == str_);
1043  }
1044  };
1045 
1046  public:
1048  };
1049  }
1050 }
1051 
1052 #include <pcl/visualization/impl/image_viewer.hpp>
PlanarPolygon represents a planar (2D) polygon, potentially in a 3D space.
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
ImageViewer is a class for 2D image visualization.
Definition: image_viewer.h:119
void markPoints(const std::vector< float > &uv, Vector3ub fg_color, Vector3ub bg_color=red_color, double size=3.0, const std::string &layer_id="markers", double opacity=1.0)
Sets the pixel at coordinates(u,v) to color while setting the neighborhood to another (float coordina...
bool addRectangle(unsigned int x_min, unsigned int x_max, unsigned int y_min, unsigned int y_max, const std::string &layer_id="rectangles", double opacity=1.0)
Add a 2D box and color its edges with a given color.
void setWindowTitle(const std::string &name)
Set the window title name.
bool addRectangle(const pcl::PointXY &min_pt, const pcl::PointXY &max_pt, const std::string &layer_id="rectangles", double opacity=1.0)
Add a 2D box and color its edges with a given color.
void resetStoppedFlag()
Set the stopped flag back to false.
Definition: image_viewer.h:900
bool addLine(unsigned int x_min, unsigned int y_min, unsigned int x_max, unsigned int y_max, const std::string &layer_id="line", double opacity=1.0)
Add a 2D line with a given color.
boost::signals2::connection registerKeyboardCallback(void(T::*callback)(const pcl::visualization::KeyboardEvent &, void *), T &instance, void *cookie=nullptr)
Register a callback function for keyboard events.
Definition: image_viewer.h:496
void showAngleImage(const float *data, unsigned width, unsigned height, const std::string &layer_id="angle_image", double opacity=1.0)
Show a 2D image on screen representing angle data.
shared_ptr< const ImageViewer > ConstPtr
Definition: image_viewer.h:122
boost::signals2::connection registerMouseCallback(void(*callback)(const pcl::visualization::MouseEvent &, void *), void *cookie=nullptr)
Register a callback std::function for mouse events.
Definition: image_viewer.h:515
void showRGBImage(const unsigned char *data, unsigned width, unsigned height, const std::string &layer_id="rgb_image", double opacity=1.0)
Show a 2D RGB image on screen.
void convertIntensityCloudToUChar(const pcl::PointCloud< pcl::Intensity > &cloud, boost::shared_array< unsigned char > data)
Convert the Intensity information in a PointCloud<Intensity> to an unsigned char array.
void addMonoImage(const pcl::PointCloud< pcl::Intensity8u >::ConstPtr &cloud, const std::string &layer_id="mono_image", double opacity=1.0)
Add a monochrome 2D image layer, but do not render it (use spin/spinOnce to update).
Definition: image_viewer.h:224
void showRGBImage(const typename pcl::PointCloud< T >::ConstPtr &cloud, const std::string &layer_id="rgb_image", double opacity=1.0)
Show a 2D image on screen, obtained from the RGB channel of a point cloud.
Definition: image_viewer.h:278
bool addFilledRectangle(unsigned int x_min, unsigned int x_max, unsigned int y_min, unsigned int y_max, const std::string &layer_id="boxes", double opacity=0.5)
Add a 2D box and fill it in with a given color.
void spinOnce(int time=1, bool force_redraw=true)
Spin once method.
static void MouseCallback(vtkObject *, unsigned long eid, void *clientdata, void *calldata)
void addMonoImage(const pcl::PointCloud< pcl::Intensity > &cloud, const std::string &layer_id="mono_image", double opacity=1.0)
Add a monochrome 2D image layer, but do not render it (use spin/spinOnce to update).
bool addRectangle(const pcl::PointXY &min_pt, const pcl::PointXY &max_pt, double r, double g, double b, const std::string &layer_id="rectangles", double opacity=1.0)
Add a 2D box and color its edges with a given color.
bool addRectangle(unsigned int x_min, unsigned int x_max, unsigned int y_min, unsigned int y_max, double r, double g, double b, const std::string &layer_id="rectangles", double opacity=1.0)
Add a 2D box and color its edges with a given color.
bool addLayer(const std::string &layer_id, int width, int height, double opacity=0.5)
Add a new 2D rendering layer to the viewer.
void removeLayer(const std::string &layer_id)
Remove a 2D layer given by its ID.
void addHalfAngleImage(const float *data, unsigned width, unsigned height, const std::string &layer_id="half_angle_image", double opacity=1.0)
Add a half angle 2D image layer, but do not render it (use spin/spinOnce to update).
boost::signals2::connection registerKeyboardCallback(void(*callback)(const pcl::visualization::KeyboardEvent &, void *), void *cookie=nullptr)
Register a callback function for keyboard events.
Definition: image_viewer.h:483
bool addText(unsigned int x, unsigned int y, const std::string &text, double r, double g, double b, const std::string &layer_id="line", double opacity=1.0)
Add a 2D text with a given color.
void addMonoImage(const unsigned char *data, unsigned width, unsigned height, const std::string &layer_id="mono_image", double opacity=1.0)
Add a monochrome 2D image layer, but do not render it (use spin/spinOnce to update).
void showFloatImage(const float *data, unsigned int width, unsigned int height, float min_value=std::numeric_limits< float >::min(), float max_value=std::numeric_limits< float >::max(), bool grayscale=false, const std::string &layer_id="float_image", double opacity=1.0)
Show a 2D image (float) on screen.
void showMonoImage(const pcl::PointCloud< pcl::Intensity8u >::ConstPtr &cloud, const std::string &layer_id="mono_image", double opacity=1.0)
Show a monochrome 2D image on screen.
Definition: image_viewer.h:212
void markPoints(const std::vector< int > &uv, Vector3ub fg_color, Vector3ub bg_color=red_color, double size=3.0, const std::string &layer_id="markers", double opacity=1.0)
Sets the pixel at coordinates(u,v) to color while setting the neighborhood to another.
void showHalfAngleImage(const float *data, unsigned width, unsigned height, const std::string &layer_id="half_angle_image", double opacity=1.0)
Show a 2D image on screen representing half angle data.
bool addLine(unsigned int x_min, unsigned int y_min, unsigned int x_max, unsigned int y_max, double r, double g, double b, const std::string &layer_id="line", double opacity=1.0)
Add a 2D line with a given color.
void addMonoImage(const pcl::PointCloud< pcl::Intensity8u > &cloud, const std::string &layer_id="mono_image", double opacity=1.0)
Add a monochrome 2D image layer, but do not render it (use spin/spinOnce to update).
void showShortImage(const unsigned short *short_image, unsigned int width, unsigned int height, unsigned short min_value=std::numeric_limits< unsigned short >::min(), unsigned short max_value=std::numeric_limits< unsigned short >::max(), bool grayscale=false, const std::string &layer_id="short_image", double opacity=1.0)
Show a 2D image (unsigned short) on screen.
boost::signals2::connection registerMouseCallback(void(T::*callback)(const pcl::visualization::MouseEvent &, void *), T &instance, void *cookie=nullptr)
Register a callback function for mouse events.
Definition: image_viewer.h:528
void emitMouseEvent(unsigned long event_id)
Fire up a mouse event with a specified event ID.
void addShortImage(const unsigned short *short_image, unsigned int width, unsigned int height, unsigned short min_value=std::numeric_limits< unsigned short >::min(), unsigned short max_value=std::numeric_limits< unsigned short >::max(), bool grayscale=false, const std::string &layer_id="short_image", double opacity=1.0)
Add a short 2D image layer, but do not render it (use spin/spinOnce to update).
static void KeyboardCallback(vtkObject *, unsigned long eid, void *clientdata, void *calldata)
virtual ~ImageViewer()
Destructor.
void showMonoImage(const pcl::PointCloud< pcl::Intensity8u > &cloud, const std::string &layer_id="mono_image", double opacity=1.0)
Show a monochrome 2D image on screen.
void showMonoImage(const unsigned char *data, unsigned width, unsigned height, const std::string &layer_id="mono_image", double opacity=1.0)
Show a monochrome 2D image on screen.
void emitKeyboardEvent(unsigned long event_id)
Fire up a keyboard event with a specified event ID.
ImageViewer(const std::string &window_title="")
Constructor.
void close()
Stop the interaction and close the visualizaton window.
Definition: image_viewer.h:565
void setSize(int xw, int yw)
Set the window size in screen coordinates.
bool addText(unsigned int x, unsigned int y, const std::string &text, const std::string &layer_id="line", double opacity=1.0)
Add a 2D text with a given color.
void addRGBImage(const typename pcl::PointCloud< T >::ConstPtr &cloud, const std::string &layer_id="rgb_image", double opacity=1.0)
Add an RGB 2D image layer, but do not render it (use spin/spinOnce to update).
Definition: image_viewer.h:290
boost::signals2::connection registerMouseCallback(std::function< void(const pcl::visualization::MouseEvent &)> cb)
Register a callback function for mouse events.
void addFloatImage(const float *data, unsigned int width, unsigned int height, float min_value=std::numeric_limits< float >::min(), float max_value=std::numeric_limits< float >::max(), bool grayscale=false, const std::string &layer_id="float_image", double opacity=1.0)
Add a float 2D image layer, but do not render it (use spin/spinOnce to update).
shared_ptr< ImageViewer > Ptr
Definition: image_viewer.h:121
void showMonoImage(const pcl::PointCloud< pcl::Intensity > &cloud, const std::string &layer_id="mono_image", double opacity=1.0)
Show a monochrome 2D image on screen.
void setPosition(int x, int y)
Set the position in screen coordinates.
void markPoint(std::size_t u, std::size_t v, Vector3ub fg_color, Vector3ub bg_color=red_color, double radius=3.0, const std::string &layer_id="points", double opacity=1.0)
Sets the pixel at coordinates(u,v) to color while setting the neighborhood to another.
void addMonoImage(const pcl::PointCloud< pcl::Intensity >::ConstPtr &cloud, const std::string &layer_id="mono_image", double opacity=1.0)
Add a monochrome 2D image layer, but do not render it (use spin/spinOnce to update).
Definition: image_viewer.h:182
void addAngleImage(const float *data, unsigned width, unsigned height, const std::string &layer_id="angle_image", double opacity=1.0)
Add an angle 2D image layer, but do not render it (use spin/spinOnce to update).
boost::signals2::connection registerKeyboardCallback(std::function< void(const pcl::visualization::KeyboardEvent &)> cb)
Register a callback std::function for keyboard events.
int * getSize()
Return the window size in pixels.
bool addFilledRectangle(unsigned int x_min, unsigned int x_max, unsigned int y_min, unsigned int y_max, double r, double g, double b, const std::string &layer_id="boxes", double opacity=0.5)
Add a 2D box and fill it in with a given color.
void render()
Trigger a render call.
void convertIntensityCloud8uToUChar(const pcl::PointCloud< pcl::Intensity8u > &cloud, boost::shared_array< unsigned char > data)
Convert the Intensity8u information in a PointCloud<Intensity8u> to an unsigned char array.
bool addCircle(unsigned int x, unsigned int y, double radius, const std::string &layer_id="circles", double opacity=1.0)
Add a circle shape from a point and a radius.
void addRGBImage(const unsigned char *data, unsigned width, unsigned height, const std::string &layer_id="rgb_image", double opacity=1.0, bool autoresize=true)
Add an RGB 2D image layer, but do not render it (use spin/spinOnce to update).
bool wasStopped() const
Returns true when the user tried to close the window.
Definition: image_viewer.h:561
bool addCircle(unsigned int x, unsigned int y, double radius, double r, double g, double b, const std::string &layer_id="circles", double opacity=1.0)
Add a circle shape from a point and a radius.
void showMonoImage(const pcl::PointCloud< pcl::Intensity >::ConstPtr &cloud, const std::string &layer_id="mono_image", double opacity=1.0)
Show a monochrome 2D image on screen.
Definition: image_viewer.h:170
void setInteractorStyle(vtkInteractorObserver *style)
Set up the interactor style.
Definition: image_viewer.h:137
An image viewer interactor style, tailored for ImageViewer.
Definition: image_viewer.h:76
static ImageViewerInteractorStyle * New()
void adjustCamera(vtkImageData *image, vtkRenderer *ren)
/brief Class representing key hit/release events
Defines all the PCL implemented PointT point type structures.
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
Defines functions, macros and traits for allocating and using memory.
Eigen::Array< unsigned char, 3, 1 > Vector3ub
Definition: image_viewer.h:66
static const Vector3ub red_color(255, 0, 0)
static const Vector3ub blue_color(0, 0, 255)
static const Vector3ub green_color(0, 255, 0)
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
Defines all the PCL and non-PCL macros used.
#define PCL_EXPORTS
Definition: pcl_macros.h:323
A 2D point structure representing Euclidean xy coordinates.
void Execute(vtkObject *, unsigned long event_id, void *) override
Definition: image_viewer.h:951
void Execute(vtkObject *vtkNotUsed(caller), unsigned long event_id, void *call_data) override
Definition: image_viewer.h:930