Point Cloud Library (PCL)  1.11.1
pcl_visualizer.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, 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 // PCL includes
42 #include <pcl/correspondence.h>
43 #include <pcl/ModelCoefficients.h>
44 #include <pcl/PolygonMesh.h>
45 #include <pcl/TextureMesh.h>
46 //
47 #include <pcl/console/print.h>
48 #include <pcl/visualization/common/actor_map.h>
49 #include <pcl/visualization/common/common.h>
50 #include <pcl/visualization/point_cloud_geometry_handlers.h>
51 #include <pcl/visualization/point_cloud_color_handlers.h>
52 #include <pcl/visualization/point_picking_event.h>
53 #include <pcl/visualization/area_picking_event.h>
54 #include <pcl/visualization/interactor_style.h>
55 
56 #include <vtkOrientationMarkerWidget.h>
57 #include <vtkRenderWindowInteractor.h>
58 
59 // VTK includes
60 class vtkPolyData;
61 class vtkTextActor;
62 class vtkRenderWindow;
63 class vtkAppendPolyData;
64 class vtkRenderWindow;
65 class vtkTransform;
66 class vtkInteractorStyle;
67 class vtkLODActor;
68 class vtkProp;
69 class vtkActor;
70 class vtkDataSet;
71 class vtkUnstructuredGrid;
72 class vtkCellArray;
73 
74 namespace pcl
75 {
76  template <typename T> class PointCloud;
77  template <typename T> class PlanarPolygon;
78 
79  namespace visualization
80  {
81  namespace details
82  {
83  vtkIdType fillCells(std::vector<int>& lookup, const std::vector<pcl::Vertices>& vertices, vtkSmartPointer<vtkCellArray> cell_array, int max_size_of_polygon);
84  }
85 
86  /** \brief PCL Visualizer main class.
87  * \author Radu B. Rusu
88  * \ingroup visualization
89  * \note This class can NOT be used across multiple threads. Only call functions of objects of this class
90  * from the same thread that they were created in! Some methods, e.g. addPointCloud, will crash if called
91  * from other threads.
92  */
94  {
95  public:
96  using Ptr = shared_ptr<PCLVisualizer>;
97  using ConstPtr = shared_ptr<const PCLVisualizer>;
98 
102 
106 
107  /** \brief PCL Visualizer constructor.
108  * \param[in] name the window name (empty by default)
109  * \param[in] create_interactor if true (default), create an interactor, false otherwise
110  */
111  PCLVisualizer (const std::string &name = "", const bool create_interactor = true);
112 
113  /** \brief PCL Visualizer constructor. It looks through the passed argv arguments to find the "-cam *.cam" argument.
114  * If the search failed, the name for cam file is calculated with boost uuid. If there is no such file, camera is not initilalized.
115  * \param[in] argc
116  * \param[in] argv
117  * \param[in] name the window name (empty by default)
118  * \param[in] style interactor style (defaults to PCLVisualizerInteractorStyle)
119  * \param[in] create_interactor if true (default), create an interactor, false otherwise
120  */
121  PCLVisualizer (int &argc, char **argv, const std::string &name = "",
122  PCLVisualizerInteractorStyle* style = PCLVisualizerInteractorStyle::New (), const bool create_interactor = true);
123 
124  /** \brief PCL Visualizer constructor.
125  * \param[in] ren custom vtk renderer
126  * \param[in] wind custom vtk render window
127  * \param[in] create_interactor if true (default), create an interactor, false otherwise
128  */
129  PCLVisualizer (vtkSmartPointer<vtkRenderer> ren, vtkSmartPointer<vtkRenderWindow> wind, const std::string &name = "", const bool create_interactor = true);
130 
131  /** \brief PCL Visualizer constructor.
132  * \param[in] argc
133  * \param[in] argv
134  * \param[in] ren custom vtk renderer
135  * \param[in] wind custom vtk render window
136  * \param[in] style interactor style (defaults to PCLVisualizerInteractorStyle)
137  * \param[in] create_interactor if true (default), create an interactor, false otherwise
138  */
139  PCLVisualizer (int &argc, char **argv, vtkSmartPointer<vtkRenderer> ren, vtkSmartPointer<vtkRenderWindow> wind, const std::string &name = "",
141  const bool create_interactor = true);
142 
143 
144  /** \brief PCL Visualizer destructor. */
145  virtual ~PCLVisualizer ();
146 
147  /** \brief Enables/Disabled the underlying window mode to full screen.
148  * \note This might or might not work, depending on your window manager.
149  * See the VTK documentation for additional details.
150  * \param[in] mode true for full screen, false otherwise
151  */
152  void
153  setFullScreen (bool mode);
154 
155  /** \brief Set the visualizer window name.
156  * \param[in] name the name of the window
157  */
158  void
159  setWindowName (const std::string &name);
160 
161  /** \brief Enables or disable the underlying window borders.
162  * \note This might or might not work, depending on your window manager.
163  * See the VTK documentation for additional details.
164  * \param[in] mode true for borders, false otherwise
165  */
166  void
167  setWindowBorders (bool mode);
168 
169  /** \brief Register a callback std::function for keyboard events
170  * \param[in] cb a std function that will be registered as a callback for a keyboard event
171  * \return a connection object that allows to disconnect the callback function.
172  */
173  boost::signals2::connection
174  registerKeyboardCallback (std::function<void (const pcl::visualization::KeyboardEvent&)> cb);
175 
176  /** \brief Register a callback function for keyboard events
177  * \param[in] callback the function that will be registered as a callback for a keyboard event
178  * \param[in] cookie user data that is passed to the callback
179  * \return a connection object that allows to disconnect the callback function.
180  */
181  inline boost::signals2::connection
182  registerKeyboardCallback (void (*callback) (const pcl::visualization::KeyboardEvent&, void*), void* cookie = nullptr)
183  {
184  return (registerKeyboardCallback ([=] (const pcl::visualization::KeyboardEvent& e) { (*callback) (e, cookie); }));
185  }
186 
187  /** \brief Register a callback function for keyboard events
188  * \param[in] callback the member function that will be registered as a callback for a keyboard event
189  * \param[in] instance instance to the class that implements the callback function
190  * \param[in] cookie user data that is passed to the callback
191  * \return a connection object that allows to disconnect the callback function.
192  */
193  template<typename T> inline boost::signals2::connection
194  registerKeyboardCallback (void (T::*callback) (const pcl::visualization::KeyboardEvent&, void*), T& instance, void* cookie = nullptr)
195  {
196  return (registerKeyboardCallback ([=, &instance] (const pcl::visualization::KeyboardEvent& e) { (instance.*callback) (e, cookie); }));
197  }
198 
199  /** \brief Register a callback function for mouse events
200  * \param[in] cb a std function that will be registered as a callback for a mouse event
201  * \return a connection object that allows to disconnect the callback function.
202  */
203  boost::signals2::connection
204  registerMouseCallback (std::function<void (const pcl::visualization::MouseEvent&)> cb);
205 
206  /** \brief Register a callback function for mouse events
207  * \param[in] callback the function that will be registered as a callback for a mouse event
208  * \param[in] cookie user data that is passed to the callback
209  * \return a connection object that allows to disconnect the callback function.
210  */
211  inline boost::signals2::connection
212  registerMouseCallback (void (*callback) (const pcl::visualization::MouseEvent&, void*), void* cookie = nullptr)
213  {
214  return (registerMouseCallback ([=] (const pcl::visualization::MouseEvent& e) { (*callback) (e, cookie); }));
215  }
216 
217  /** \brief Register a callback function for mouse events
218  * \param[in] callback the member function that will be registered as a callback for a mouse event
219  * \param[in] instance instance to the class that implements the callback function
220  * \param[in] cookie user data that is passed to the callback
221  * \return a connection object that allows to disconnect the callback function.
222  */
223  template<typename T> inline boost::signals2::connection
224  registerMouseCallback (void (T::*callback) (const pcl::visualization::MouseEvent&, void*), T& instance, void* cookie = nullptr)
225  {
226  return (registerMouseCallback ([=, &instance] (const pcl::visualization::MouseEvent& e) { (instance.*callback) (e, cookie); }));
227  }
228 
229  /** \brief Register a callback function for point picking events
230  * \param[in] cb a std function that will be registered as a callback for a point picking event
231  * \return a connection object that allows to disconnect the callback function.
232  */
233  boost::signals2::connection
234  registerPointPickingCallback (std::function<void (const pcl::visualization::PointPickingEvent&)> cb);
235 
236  /** \brief Register a callback function for point picking events
237  * \param[in] callback the function that will be registered as a callback for a point picking event
238  * \param[in] cookie user data that is passed to the callback
239  * \return a connection object that allows to disconnect the callback function.
240  */
241  boost::signals2::connection
242  registerPointPickingCallback (void (*callback) (const pcl::visualization::PointPickingEvent&, void*), void* cookie = nullptr);
243 
244  /** \brief Register a callback function for point picking events
245  * \param[in] callback the member function that will be registered as a callback for a point picking event
246  * \param[in] instance instance to the class that implements the callback function
247  * \param[in] cookie user data that is passed to the callback
248  * \return a connection object that allows to disconnect the callback function.
249  */
250  template<typename T> inline boost::signals2::connection
251  registerPointPickingCallback (void (T::*callback) (const pcl::visualization::PointPickingEvent&, void*), T& instance, void* cookie = nullptr)
252  {
253  return (registerPointPickingCallback ([=, &instance] (const pcl::visualization::PointPickingEvent& e) { (instance.*callback) (e, cookie); }));
254  }
255 
256  /** \brief Register a callback function for area picking events
257  * \param[in] cb a std function that will be registered as a callback for an area picking event
258  * \return a connection object that allows to disconnect the callback function.
259  */
260  boost::signals2::connection
261  registerAreaPickingCallback (std::function<void (const pcl::visualization::AreaPickingEvent&)> cb);
262 
263  /** \brief Register a callback function for area picking events
264  * \param[in] callback the function that will be registered as a callback for an area picking event
265  * \param[in] cookie user data that is passed to the callback
266  * \return a connection object that allows to disconnect the callback function.
267  */
268  boost::signals2::connection
269  registerAreaPickingCallback (void (*callback) (const pcl::visualization::AreaPickingEvent&, void*), void* cookie = nullptr);
270 
271  /** \brief Register a callback function for area picking events
272  * \param[in] callback the member function that will be registered as a callback for an area picking event
273  * \param[in] instance instance to the class that implements the callback function
274  * \param[in] cookie user data that is passed to the callback
275  * \return a connection object that allows to disconnect the callback function.
276  */
277  template<typename T> inline boost::signals2::connection
278  registerAreaPickingCallback (void (T::*callback) (const pcl::visualization::AreaPickingEvent&, void*), T& instance, void* cookie = nullptr)
279  {
280  return (registerAreaPickingCallback ([=, &instance] (const pcl::visualization::AreaPickingEvent& e) { (instance.*callback) (e, cookie); }));
281  }
282 
283  /** \brief Spin method. Calls the interactor and runs an internal loop. */
284  void
285  spin ();
286 
287  /** \brief Spin once method. Calls the interactor and updates the screen once.
288  * \param[in] time - How long (in ms) should the visualization loop be allowed to run.
289  * \param[in] force_redraw - if false it might return without doing anything if the
290  * interactor's framerate does not require a redraw yet.
291  */
292  void
293  spinOnce (int time = 1, bool force_redraw = false);
294 
295  /** \brief Adds a widget which shows an interactive axes display for orientation
296  * \param[in] interactor - Pointer to the vtk interactor object used by the PCLVisualizer window
297  */
298  void
299  addOrientationMarkerWidgetAxes (vtkRenderWindowInteractor* interactor);
300 
301  /** \brief Disables the Orientatation Marker Widget so it is removed from the renderer */
302  void
303  removeOrientationMarkerWidgetAxes ();
304 
305  /** \brief Adds 3D axes describing a coordinate system to screen at 0,0,0.
306  * \param[in] scale the scale of the axes (default: 1)
307  * \param[in] id the coordinate system object id (default: reference)
308  * \param[in] viewport the view port where the 3D axes should be added (default: all)
309  */
310  void
311  addCoordinateSystem (double scale = 1.0, const std::string& id = "reference", int viewport = 0);
312 
313  /** \brief Adds 3D axes describing a coordinate system to screen at x, y, z
314  * \param[in] scale the scale of the axes (default: 1)
315  * \param[in] x the X position of the axes
316  * \param[in] y the Y position of the axes
317  * \param[in] z the Z position of the axes
318  * \param[in] id the coordinate system object id (default: reference)
319  * \param[in] viewport the view port where the 3D axes should be added (default: all)
320  */
321  void
322  addCoordinateSystem (double scale, float x, float y, float z, const std::string &id = "reference", int viewport = 0);
323 
324  /** \brief Adds 3D axes describing a coordinate system to screen at x, y, z, Roll,Pitch,Yaw
325  *
326  * \param[in] scale the scale of the axes (default: 1)
327  * \param[in] t transformation matrix
328  * \param[in] id the coordinate system object id (default: reference)
329  * \param[in] viewport the view port where the 3D axes should be added (default: all)
330  *
331  * RPY Angles
332  * Rotate the reference frame by the angle roll about axis x
333  * Rotate the reference frame by the angle pitch about axis y
334  * Rotate the reference frame by the angle yaw about axis z
335  *
336  * Description:
337  * Sets the orientation of the Prop3D. Orientation is specified as
338  * X,Y and Z rotations in that order, but they are performed as
339  * RotateZ, RotateX, and finally RotateY.
340  *
341  * All axies use right hand rule. x=red axis, y=green axis, z=blue axis
342  * z direction is point into the screen.
343  * \code
344  * z
345  * \
346  * \
347  * \
348  * -----------> x
349  * |
350  * |
351  * |
352  * |
353  * |
354  * |
355  * y
356  * \endcode
357  */
358 
359  void
360  addCoordinateSystem (double scale, const Eigen::Affine3f& t, const std::string &id = "reference", int viewport = 0);
361 
362  /** \brief Removes a previously added 3D axes (coordinate system)
363  * \param[in] id the coordinate system object id (default: reference)
364  * \param[in] viewport view port where the 3D axes should be removed from (default: all)
365  */
366  bool
367  removeCoordinateSystem (const std::string &id = "reference", int viewport = 0);
368 
369  /** \brief Removes a Point Cloud from screen, based on a given ID.
370  * \param[in] id the point cloud object id (i.e., given on \a addPointCloud)
371  * \param[in] viewport view port from where the Point Cloud should be removed (default: all)
372  * \return true if the point cloud is successfully removed and false if the point cloud is
373  * not actually displayed
374  */
375  bool
376  removePointCloud (const std::string &id = "cloud", int viewport = 0);
377 
378  /** \brief Removes a PolygonMesh from screen, based on a given ID.
379  * \param[in] id the polygon object id (i.e., given on \a addPolygonMesh)
380  * \param[in] viewport view port from where the PolygonMesh should be removed (default: all)
381  */
382  inline bool
383  removePolygonMesh (const std::string &id = "polygon", int viewport = 0)
384  {
385  // Polygon Meshes are represented internally as point clouds with special cell array structures since 1.4
386  return (removePointCloud (id, viewport));
387  }
388 
389  /** \brief Removes an added shape from screen (line, polygon, etc.), based on a given ID
390  * \note This methods also removes PolygonMesh objects and PointClouds, if they match the ID
391  * \param[in] id the shape object id (i.e., given on \a addLine etc.)
392  * \param[in] viewport view port from where the Point Cloud should be removed (default: all)
393  */
394  bool
395  removeShape (const std::string &id = "cloud", int viewport = 0);
396 
397  /** \brief Removes an added 3D text from the scene, based on a given ID
398  * \param[in] id the 3D text id (i.e., given on \a addText3D etc.)
399  * \param[in] viewport view port from where the 3D text should be removed (default: all)
400  */
401  bool
402  removeText3D (const std::string &id = "cloud", int viewport = 0);
403 
404  /** \brief Remove all point cloud data on screen from the given viewport.
405  * \param[in] viewport view port from where the clouds should be removed (default: all)
406  */
407  bool
408  removeAllPointClouds (int viewport = 0);
409 
410  /** \brief Remove all 3D shape data on screen from the given viewport.
411  * \param[in] viewport view port from where the shapes should be removed (default: all)
412  */
413  bool
414  removeAllShapes (int viewport = 0);
415 
416  /** \brief Removes all existing 3D axes (coordinate systems)
417  * \param[in] viewport view port where the 3D axes should be removed from (default: all)
418  */
419  bool
420  removeAllCoordinateSystems (int viewport = 0);
421 
422  /** \brief Set the viewport's background color.
423  * \param[in] r the red component of the RGB color
424  * \param[in] g the green component of the RGB color
425  * \param[in] b the blue component of the RGB color
426  * \param[in] viewport the view port (default: all)
427  */
428  void
429  setBackgroundColor (const double &r, const double &g, const double &b, int viewport = 0);
430 
431  /** \brief Add a text to screen
432  * \param[in] text the text to add
433  * \param[in] xpos the X position on screen where the text should be added
434  * \param[in] ypos the Y position on screen where the text should be added
435  * \param[in] id the text object id (default: equal to the "text" parameter)
436  * \param[in] viewport the view port (default: all)
437  */
438  bool
439  addText (const std::string &text,
440  int xpos, int ypos,
441  const std::string &id = "", int viewport = 0);
442 
443  /** \brief Add a text to screen
444  * \param[in] text the text to add
445  * \param[in] xpos the X position on screen where the text should be added
446  * \param[in] ypos the Y position on screen where the text should be added
447  * \param[in] r the red color value
448  * \param[in] g the green color value
449  * \param[in] b the blue color value
450  * \param[in] id the text object id (default: equal to the "text" parameter)
451  * \param[in] viewport the view port (default: all)
452  */
453  bool
454  addText (const std::string &text, int xpos, int ypos, double r, double g, double b,
455  const std::string &id = "", int viewport = 0);
456 
457  /** \brief Add a text to screen
458  * \param[in] text the text to add
459  * \param[in] xpos the X position on screen where the text should be added
460  * \param[in] ypos the Y position on screen where the text should be added
461  * \param[in] fontsize the fontsize of the text
462  * \param[in] r the red color value
463  * \param[in] g the green color value
464  * \param[in] b the blue color value
465  * \param[in] id the text object id (default: equal to the "text" parameter)
466  * \param[in] viewport the view port (default: all)
467  */
468  bool
469  addText (const std::string &text, int xpos, int ypos, int fontsize, double r, double g, double b,
470  const std::string &id = "", int viewport = 0);
471 
472 
473  /** \brief Update a text to screen
474  * \param[in] text the text to update
475  * \param[in] xpos the new X position on screen
476  * \param[in] ypos the new Y position on screen
477  * \param[in] id the text object id (default: equal to the "text" parameter)
478  */
479  bool
480  updateText (const std::string &text,
481  int xpos, int ypos,
482  const std::string &id = "");
483 
484  /** \brief Update a text to screen
485  * \param[in] text the text to update
486  * \param[in] xpos the new X position on screen
487  * \param[in] ypos the new Y position on screen
488  * \param[in] r the red color value
489  * \param[in] g the green color value
490  * \param[in] b the blue color value
491  * \param[in] id the text object id (default: equal to the "text" parameter)
492  */
493  bool
494  updateText (const std::string &text,
495  int xpos, int ypos, double r, double g, double b,
496  const std::string &id = "");
497 
498  /** \brief Update a text to screen
499  * \param[in] text the text to update
500  * \param[in] xpos the new X position on screen
501  * \param[in] ypos the new Y position on screen
502  * \param[in] fontsize the fontsize of the text
503  * \param[in] r the red color value
504  * \param[in] g the green color value
505  * \param[in] b the blue color value
506  * \param[in] id the text object id (default: equal to the "text" parameter)
507  */
508  bool
509  updateText (const std::string &text,
510  int xpos, int ypos, int fontsize, double r, double g, double b,
511  const std::string &id = "");
512 
513  /** \brief Set the pose of an existing shape.
514  *
515  * Returns false if the shape doesn't exist, true if the pose was successfully
516  * updated.
517  *
518  * \param[in] id the shape or cloud object id (i.e., given on \a addLine etc.)
519  * \param[in] pose the new pose
520  * \return false if no shape or cloud with the specified ID was found
521  */
522  bool
523  updateShapePose (const std::string &id, const Eigen::Affine3f& pose);
524 
525  /** \brief Set the pose of an existing coordinate system.
526  *
527  * Returns false if the coordinate system doesn't exist, true if the pose was successfully
528  * updated.
529  *
530  * \param[in] id the point cloud object id (i.e., given on \a addCoordinateSystem etc.)
531  * \param[in] pose the new pose
532  * \return false if no coordinate system with the specified ID was found
533  */
534  bool
535  updateCoordinateSystemPose (const std::string &id, const Eigen::Affine3f& pose);
536 
537  /** \brief Set the pose of an existing point cloud.
538  *
539  * Returns false if the point cloud doesn't exist, true if the pose was successfully
540  * updated.
541  *
542  * \param[in] id the point cloud object id (i.e., given on \a addPointCloud etc.)
543  * \param[in] pose the new pose
544  * \return false if no point cloud with the specified ID was found
545  */
546  bool
547  updatePointCloudPose (const std::string &id, const Eigen::Affine3f& pose);
548 
549  /** \brief Add a 3d text to the scene
550  * \param[in] text the text to add
551  * \param[in] position the world position where the text should be added
552  * \param[in] textScale the scale of the text to render
553  * \param[in] r the red color value
554  * \param[in] g the green color value
555  * \param[in] b the blue color value
556  * \param[in] id the text object id (default: equal to the "text" parameter)
557  * \param[in] viewport the view port (default: all)
558  */
559  template <typename PointT> bool
560  addText3D (const std::string &text,
561  const PointT &position,
562  double textScale = 1.0,
563  double r = 1.0, double g = 1.0, double b = 1.0,
564  const std::string &id = "", int viewport = 0);
565 
566  /** \brief Add a 3d text to the scene
567  * \param[in] text the text to add
568  * \param[in] position the world position where the text should be added
569  * \param[in] orientation the angles of rotation of the text around X, Y and Z axis,
570  in this order. The way the rotations are effectively done is the
571  Z-X-Y intrinsic rotations:
572  https://en.wikipedia.org/wiki/Euler_angles#Definition_by_intrinsic_rotations
573  * \param[in] textScale the scale of the text to render
574  * \param[in] r the red color value
575  * \param[in] g the green color value
576  * \param[in] b the blue color value
577  * \param[in] id the text object id (default: equal to the "text" parameter)
578  * \param[in] viewport the view port (default: all)
579  */
580  template <typename PointT> bool
581  addText3D (const std::string &text,
582  const PointT &position,
583  double orientation[3],
584  double textScale = 1.0,
585  double r = 1.0, double g = 1.0, double b = 1.0,
586  const std::string &id = "", int viewport = 0);
587 
588  /** \brief Check if the cloud, shape, or coordinate with the given id was already added to this visualizer.
589  * \param[in] id the id of the cloud, shape, or coordinate to check
590  * \return true if a cloud, shape, or coordinate with the specified id was found
591  */
592  inline bool
593  contains(const std::string &id) const
594  {
595  return (cloud_actor_map_->find (id) != cloud_actor_map_->end () ||
596  shape_actor_map_->find (id) != shape_actor_map_->end () ||
597  coordinate_actor_map_->find (id) != coordinate_actor_map_-> end());
598  }
599 
600  /** \brief Add the estimated surface normals of a Point Cloud to screen.
601  * \param[in] cloud the input point cloud dataset containing XYZ data and normals
602  * \param[in] level display only every level'th point (default: 100)
603  * \param[in] scale the normal arrow scale (default: 0.02m)
604  * \param[in] id the point cloud object id (default: cloud)
605  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
606  */
607  template <typename PointNT> bool
608  addPointCloudNormals (const typename pcl::PointCloud<PointNT>::ConstPtr &cloud,
609  int level = 100, float scale = 0.02f,
610  const std::string &id = "cloud", int viewport = 0);
611 
612  /** \brief Add the estimated surface normals of a Point Cloud to screen.
613  * \param[in] cloud the input point cloud dataset containing the XYZ data
614  * \param[in] normals the input point cloud dataset containing the normal data
615  * \param[in] level display only every level'th point (default: 100)
616  * \param[in] scale the normal arrow scale (default: 0.02m)
617  * \param[in] id the point cloud object id (default: cloud)
618  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
619  */
620  template <typename PointT, typename PointNT> bool
621  addPointCloudNormals (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
622  const typename pcl::PointCloud<PointNT>::ConstPtr &normals,
623  int level = 100, float scale = 0.02f,
624  const std::string &id = "cloud", int viewport = 0);
625 
626  /** \brief Add the estimated principal curvatures of a Point Cloud to screen.
627  * \param[in] cloud the input point cloud dataset containing the XYZ data and normals
628  * \param[in] pcs the input point cloud dataset containing the principal curvatures data
629  * \param[in] level display only every level'th point. Default: 100
630  * \param[in] scale the normal arrow scale. Default: 1.0
631  * \param[in] id the point cloud object id. Default: "cloud"
632  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
633  */
634  template <typename PointNT> bool
635  addPointCloudPrincipalCurvatures (
636  const typename pcl::PointCloud<PointNT>::ConstPtr &cloud,
638  int level = 100, float scale = 1.0f,
639  const std::string &id = "cloud", int viewport = 0);
640 
641  /** \brief Add the estimated principal curvatures of a Point Cloud to screen.
642  * \param[in] cloud the input point cloud dataset containing the XYZ data
643  * \param[in] normals the input point cloud dataset containing the normal data
644  * \param[in] pcs the input point cloud dataset containing the principal curvatures data
645  * \param[in] level display only every level'th point. Default: 100
646  * \param[in] scale the normal arrow scale. Default: 1.0
647  * \param[in] id the point cloud object id. Default: "cloud"
648  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
649  */
650  template <typename PointT, typename PointNT> bool
651  addPointCloudPrincipalCurvatures (
652  const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
653  const typename pcl::PointCloud<PointNT>::ConstPtr &normals,
655  int level = 100, float scale = 1.0f,
656  const std::string &id = "cloud", int viewport = 0);
657 
658  /** \brief Add the estimated surface intensity gradients of a Point Cloud to screen.
659  * \param[in] cloud the input point cloud dataset containing the XYZ data
660  * \param[in] gradients the input point cloud dataset containing the intensity gradient data
661  * \param[in] level display only every level'th point (default: 100)
662  * \param[in] scale the intensity gradient arrow scale (default: 1e-6m)
663  * \param[in] id the point cloud object id (default: cloud)
664  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
665  */
666  template <typename PointT, typename GradientT> bool
667  addPointCloudIntensityGradients (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
668  const typename pcl::PointCloud<GradientT>::ConstPtr &gradients,
669  int level = 100, double scale = 1e-6,
670  const std::string &id = "cloud", int viewport = 0);
671 
672  /** \brief Add a Point Cloud (templated) to screen.
673  * \param[in] cloud the input point cloud dataset
674  * \param[in] id the point cloud object id (default: cloud)
675  * \param viewport the view port where the Point Cloud should be added (default: all)
676  */
677  template <typename PointT> bool
678  addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
679  const std::string &id = "cloud", int viewport = 0);
680 
681  /** \brief Updates the XYZ data for an existing cloud object id on screen.
682  * \param[in] cloud the input point cloud dataset
683  * \param[in] id the point cloud object id to update (default: cloud)
684  * \return false if no cloud with the specified ID was found
685  */
686  template <typename PointT> bool
687  updatePointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
688  const std::string &id = "cloud");
689 
690  /** \brief Updates the XYZ data for an existing cloud object id on screen.
691  * \param[in] cloud the input point cloud dataset
692  * \param[in] geometry_handler the geometry handler to use
693  * \param[in] id the point cloud object id to update (default: cloud)
694  * \return false if no cloud with the specified ID was found
695  */
696  template <typename PointT> bool
697  updatePointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
698  const PointCloudGeometryHandler<PointT> &geometry_handler,
699  const std::string &id = "cloud");
700 
701  /** \brief Updates the XYZ data for an existing cloud object id on screen.
702  * \param[in] cloud the input point cloud dataset
703  * \param[in] color_handler the color handler to use
704  * \param[in] id the point cloud object id to update (default: cloud)
705  * \return false if no cloud with the specified ID was found
706  */
707  template <typename PointT> bool
708  updatePointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
709  const PointCloudColorHandler<PointT> &color_handler,
710  const std::string &id = "cloud");
711 
712  /** \brief Add a Point Cloud (templated) to screen.
713  * \param[in] cloud the input point cloud dataset
714  * \param[in] geometry_handler use a geometry handler object to extract the XYZ data
715  * \param[in] id the point cloud object id (default: cloud)
716  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
717  */
718  template <typename PointT> bool
719  addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
720  const PointCloudGeometryHandler<PointT> &geometry_handler,
721  const std::string &id = "cloud", int viewport = 0);
722 
723  /** \brief Add a Point Cloud (templated) to screen.
724  *
725  * Because the geometry handler is given as a pointer, it will be pushed back to the list of available
726  * handlers, rather than replacing the current active geometric handler. This makes it possible to
727  * switch between different geometric handlers 'on-the-fly' at runtime, from the PCLVisualizer
728  * interactor interface (using Alt+0..9).
729  *
730  * \param[in] cloud the input point cloud dataset
731  * \param[in] geometry_handler use a geometry handler object to extract the XYZ data
732  * \param[in] id the point cloud object id (default: cloud)
733  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
734  */
735  template <typename PointT> bool
736  addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
737  const GeometryHandlerConstPtr &geometry_handler,
738  const std::string &id = "cloud", int viewport = 0);
739 
740  /** \brief Add a Point Cloud (templated) to screen.
741  * \param[in] cloud the input point cloud dataset
742  * \param[in] color_handler a specific PointCloud visualizer handler for colors
743  * \param[in] id the point cloud object id (default: cloud)
744  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
745  */
746  template <typename PointT> bool
747  addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
748  const PointCloudColorHandler<PointT> &color_handler,
749  const std::string &id = "cloud", int viewport = 0);
750 
751  /** \brief Add a Point Cloud (templated) to screen.
752  *
753  * Because the color handler is given as a pointer, it will be pushed back to the list of available
754  * handlers, rather than replacing the current active color handler. This makes it possible to
755  * switch between different color handlers 'on-the-fly' at runtime, from the PCLVisualizer
756  * interactor interface (using 0..9).
757  *
758  * \param[in] cloud the input point cloud dataset
759  * \param[in] color_handler a specific PointCloud visualizer handler for colors
760  * \param[in] id the point cloud object id (default: cloud)
761  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
762  */
763  template <typename PointT> bool
764  addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
765  const ColorHandlerConstPtr &color_handler,
766  const std::string &id = "cloud", int viewport = 0);
767 
768  /** \brief Add a Point Cloud (templated) to screen.
769  *
770  * Because the geometry/color handler is given as a pointer, it will be pushed back to the list of
771  * available handlers, rather than replacing the current active handler. This makes it possible to
772  * switch between different handlers 'on-the-fly' at runtime, from the PCLVisualizer interactor
773  * interface (using [Alt+]0..9).
774  *
775  * \param[in] cloud the input point cloud dataset
776  * \param[in] geometry_handler a specific PointCloud visualizer handler for geometry
777  * \param[in] color_handler a specific PointCloud visualizer handler for colors
778  * \param[in] id the point cloud object id (default: cloud)
779  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
780  */
781  template <typename PointT> bool
782  addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
783  const GeometryHandlerConstPtr &geometry_handler,
784  const ColorHandlerConstPtr &color_handler,
785  const std::string &id = "cloud", int viewport = 0);
786 
787  /** \brief Add a binary blob Point Cloud to screen.
788  *
789  * Because the geometry/color handler is given as a pointer, it will be pushed back to the list of
790  * available handlers, rather than replacing the current active handler. This makes it possible to
791  * switch between different handlers 'on-the-fly' at runtime, from the PCLVisualizer interactor
792  * interface (using [Alt+]0..9).
793  *
794  * \param[in] cloud the input point cloud dataset
795  * \param[in] geometry_handler a specific PointCloud visualizer handler for geometry
796  * \param[in] color_handler a specific PointCloud visualizer handler for colors
797  * \param[in] sensor_origin the origin of the cloud data in global coordinates (defaults to 0,0,0)
798  * \param[in] sensor_orientation the orientation of the cloud data in global coordinates (defaults to 1,0,0,0)
799  * \param[in] id the point cloud object id (default: cloud)
800  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
801  */
802  bool
803  addPointCloud (const pcl::PCLPointCloud2::ConstPtr &cloud,
804  const GeometryHandlerConstPtr &geometry_handler,
805  const ColorHandlerConstPtr &color_handler,
806  const Eigen::Vector4f& sensor_origin,
807  const Eigen::Quaternion<float>& sensor_orientation,
808  const std::string &id = "cloud", int viewport = 0);
809 
810  /** \brief Add a binary blob Point Cloud to screen.
811  *
812  * Because the geometry/color handler is given as a pointer, it will be pushed back to the list of
813  * available handlers, rather than replacing the current active handler. This makes it possible to
814  * switch between different handlers 'on-the-fly' at runtime, from the PCLVisualizer interactor
815  * interface (using [Alt+]0..9).
816  *
817  * \param[in] cloud the input point cloud dataset
818  * \param[in] geometry_handler a specific PointCloud visualizer handler for geometry
819  * \param[in] sensor_origin the origin of the cloud data in global coordinates (defaults to 0,0,0)
820  * \param[in] sensor_orientation the orientation of the cloud data in global coordinates (defaults to 1,0,0,0)
821  * \param[in] id the point cloud object id (default: cloud)
822  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
823  */
824  bool
825  addPointCloud (const pcl::PCLPointCloud2::ConstPtr &cloud,
826  const GeometryHandlerConstPtr &geometry_handler,
827  const Eigen::Vector4f& sensor_origin,
828  const Eigen::Quaternion<float>& sensor_orientation,
829  const std::string &id = "cloud", int viewport = 0);
830 
831  /** \brief Add a binary blob Point Cloud to screen.
832  *
833  * Because the geometry/color handler is given as a pointer, it will be pushed back to the list of
834  * available handlers, rather than replacing the current active handler. This makes it possible to
835  * switch between different handlers 'on-the-fly' at runtime, from the PCLVisualizer interactor
836  * interface (using [Alt+]0..9).
837  *
838  * \param[in] cloud the input point cloud dataset
839  * \param[in] color_handler a specific PointCloud visualizer handler for colors
840  * \param[in] sensor_origin the origin of the cloud data in global coordinates (defaults to 0,0,0)
841  * \param[in] sensor_orientation the orientation of the cloud data in global coordinates (defaults to 1,0,0,0)
842  * \param[in] id the point cloud object id (default: cloud)
843  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
844  */
845  bool
846  addPointCloud (const pcl::PCLPointCloud2::ConstPtr &cloud,
847  const ColorHandlerConstPtr &color_handler,
848  const Eigen::Vector4f& sensor_origin,
849  const Eigen::Quaternion<float>& sensor_orientation,
850  const std::string &id = "cloud", int viewport = 0);
851 
852  /** \brief Add a Point Cloud (templated) to screen.
853  * \param[in] cloud the input point cloud dataset
854  * \param[in] color_handler a specific PointCloud visualizer handler for colors
855  * \param[in] geometry_handler use a geometry handler object to extract the XYZ data
856  * \param[in] id the point cloud object id (default: cloud)
857  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
858  */
859  template <typename PointT> bool
860  addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
861  const PointCloudColorHandler<PointT> &color_handler,
862  const PointCloudGeometryHandler<PointT> &geometry_handler,
863  const std::string &id = "cloud", int viewport = 0);
864 
865  /** \brief Add a PointXYZ Point Cloud to screen.
866  * \param[in] cloud the input point cloud dataset
867  * \param[in] id the point cloud object id (default: cloud)
868  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
869  */
870  inline bool
872  const std::string &id = "cloud", int viewport = 0)
873  {
874  return (addPointCloud<pcl::PointXYZ> (cloud, id, viewport));
875  }
876 
877 
878  /** \brief Add a PointXYZRGB Point Cloud to screen.
879  * \param[in] cloud the input point cloud dataset
880  * \param[in] id the point cloud object id (default: cloud)
881  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
882  */
883  inline bool
885  const std::string &id = "cloud", int viewport = 0)
886  {
888  return (addPointCloud<pcl::PointXYZRGB> (cloud, color_handler, id, viewport));
889  }
890 
891  /** \brief Add a PointXYZRGBA Point Cloud to screen.
892  * \param[in] cloud the input point cloud dataset
893  * \param[in] id the point cloud object id (default: cloud)
894  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
895  */
896  inline bool
898  const std::string &id = "cloud", int viewport = 0)
899  {
901  return (addPointCloud<pcl::PointXYZRGBA> (cloud, color_handler, id, viewport));
902  }
903 
904  /** \brief Add a PointXYZL Point Cloud to screen.
905  * \param[in] cloud the input point cloud dataset
906  * \param[in] id the point cloud object id (default: cloud)
907  * \param[in] viewport the view port where the Point Cloud should be added (default: all)
908  */
909  inline bool
911  const std::string &id = "cloud", int viewport = 0)
912  {
914  return (addPointCloud<pcl::PointXYZL> (cloud, color_handler, id, viewport));
915  }
916 
917  /** \brief Updates the XYZ data for an existing cloud object id on screen.
918  * \param[in] cloud the input point cloud dataset
919  * \param[in] id the point cloud object id to update (default: cloud)
920  * \return false if no cloud with the specified ID was found
921  */
922  inline bool
924  const std::string &id = "cloud")
925  {
926  return (updatePointCloud<pcl::PointXYZ> (cloud, id));
927  }
928 
929  /** \brief Updates the XYZRGB data for an existing cloud object id on screen.
930  * \param[in] cloud the input point cloud dataset
931  * \param[in] id the point cloud object id to update (default: cloud)
932  * \return false if no cloud with the specified ID was found
933  */
934  inline bool
936  const std::string &id = "cloud")
937  {
939  return (updatePointCloud<pcl::PointXYZRGB> (cloud, color_handler, id));
940  }
941 
942  /** \brief Updates the XYZRGBA data for an existing cloud object id on screen.
943  * \param[in] cloud the input point cloud dataset
944  * \param[in] id the point cloud object id to update (default: cloud)
945  * \return false if no cloud with the specified ID was found
946  */
947  inline bool
949  const std::string &id = "cloud")
950  {
952  return (updatePointCloud<pcl::PointXYZRGBA> (cloud, color_handler, id));
953  }
954 
955  /** \brief Updates the XYZL data for an existing cloud object id on screen.
956  * \param[in] cloud the input point cloud dataset
957  * \param[in] id the point cloud object id to update (default: cloud)
958  * \return false if no cloud with the specified ID was found
959  */
960  inline bool
962  const std::string &id = "cloud")
963  {
965  return (updatePointCloud<pcl::PointXYZL> (cloud, color_handler, id));
966  }
967 
968  /** \brief Add a PolygonMesh object to screen
969  * \param[in] polymesh the polygonal mesh
970  * \param[in] id the polygon object id (default: "polygon")
971  * \param[in] viewport the view port where the PolygonMesh should be added (default: all)
972  */
973  bool
974  addPolygonMesh (const pcl::PolygonMesh &polymesh,
975  const std::string &id = "polygon",
976  int viewport = 0);
977 
978  /** \brief Add a PolygonMesh object to screen
979  * \param[in] cloud the polygonal mesh point cloud
980  * \param[in] vertices the polygonal mesh vertices
981  * \param[in] id the polygon object id (default: "polygon")
982  * \param[in] viewport the view port where the PolygonMesh should be added (default: all)
983  */
984  template <typename PointT> bool
985  addPolygonMesh (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
986  const std::vector<pcl::Vertices> &vertices,
987  const std::string &id = "polygon",
988  int viewport = 0);
989 
990  /** \brief Update a PolygonMesh object on screen
991  * \param[in] cloud the polygonal mesh point cloud
992  * \param[in] vertices the polygonal mesh vertices
993  * \param[in] id the polygon object id (default: "polygon")
994  * \return false if no polygonmesh with the specified ID was found
995  */
996  template <typename PointT> bool
997  updatePolygonMesh (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
998  const std::vector<pcl::Vertices> &vertices,
999  const std::string &id = "polygon");
1000 
1001  /** \brief Update a PolygonMesh object on screen
1002  * \param[in] polymesh the polygonal mesh
1003  * \param[in] id the polygon object id (default: "polygon")
1004  * \return false if no polygonmesh with the specified ID was found
1005  */
1006  bool
1007  updatePolygonMesh (const pcl::PolygonMesh &polymesh,
1008  const std::string &id = "polygon");
1009 
1010  /** \brief Add a Polygonline from a polygonMesh object to screen
1011  * \param[in] polymesh the polygonal mesh from where the polylines will be extracted
1012  * \param[in] id the polygon object id (default: "polygon")
1013  * \param[in] viewport the view port where the PolygonMesh should be added (default: all)
1014  */
1015  bool
1016  addPolylineFromPolygonMesh (const pcl::PolygonMesh &polymesh,
1017  const std::string &id = "polyline",
1018  int viewport = 0);
1019 
1020  /** \brief Add the specified correspondences to the display.
1021  * \param[in] source_points The source points
1022  * \param[in] target_points The target points
1023  * \param[in] correspondences The mapping from source points to target points. Each element must be an index into target_points
1024  * \param[in] id the polygon object id (default: "correspondences")
1025  * \param[in] viewport the view port where the correspondences should be added (default: all)
1026  */
1027  template <typename PointT> bool
1028  addCorrespondences (const typename pcl::PointCloud<PointT>::ConstPtr &source_points,
1029  const typename pcl::PointCloud<PointT>::ConstPtr &target_points,
1030  const std::vector<int> & correspondences,
1031  const std::string &id = "correspondences",
1032  int viewport = 0);
1033 
1034  /** \brief Add a TextureMesh object to screen
1035  * \param[in] polymesh the textured polygonal mesh
1036  * \param[in] id the texture mesh object id (default: "texture")
1037  * \param[in] viewport the view port where the TextureMesh should be added (default: all)
1038  */
1039  bool
1040  addTextureMesh (const pcl::TextureMesh &polymesh,
1041  const std::string &id = "texture",
1042  int viewport = 0);
1043 
1044  /** \brief Add the specified correspondences to the display.
1045  * \param[in] source_points The source points
1046  * \param[in] target_points The target points
1047  * \param[in] correspondences The mapping from source points to target points. Each element must be an index into target_points
1048  * \param[in] nth display only the Nth correspondence (e.g., skip the rest)
1049  * \param[in] id the polygon object id (default: "correspondences")
1050  * \param[in] viewport the view port where the correspondences should be added (default: all)
1051  * \param[in] overwrite allow to overwrite already existing correspondences
1052  */
1053  template <typename PointT> bool
1054  addCorrespondences (const typename pcl::PointCloud<PointT>::ConstPtr &source_points,
1055  const typename pcl::PointCloud<PointT>::ConstPtr &target_points,
1056  const pcl::Correspondences &correspondences,
1057  int nth,
1058  const std::string &id = "correspondences",
1059  int viewport = 0,
1060  bool overwrite = false);
1061 
1062  /** \brief Add the specified correspondences to the display.
1063  * \param[in] source_points The source points
1064  * \param[in] target_points The target points
1065  * \param[in] correspondences The mapping from source points to target points. Each element must be an index into target_points
1066  * \param[in] id the polygon object id (default: "correspondences")
1067  * \param[in] viewport the view port where the correspondences should be added (default: all)
1068  */
1069  template <typename PointT> bool
1071  const typename pcl::PointCloud<PointT>::ConstPtr &target_points,
1072  const pcl::Correspondences &correspondences,
1073  const std::string &id = "correspondences",
1074  int viewport = 0)
1075  {
1076  // If Nth not given, display all correspondences
1077  return (addCorrespondences<PointT> (source_points, target_points,
1078  correspondences, 1, id, viewport));
1079  }
1080 
1081  /** \brief Update the specified correspondences to the display.
1082  * \param[in] source_points The source points
1083  * \param[in] target_points The target points
1084  * \param[in] correspondences The mapping from source points to target points. Each element must be an index into target_points
1085  * \param[in] nth display only the Nth correspondence (e.g., skip the rest)
1086  * \param[in] id the polygon object id (default: "correspondences")
1087  * \param[in] viewport the view port where the correspondences should be updated (default: all)
1088  */
1089  template <typename PointT> bool
1090  updateCorrespondences (
1091  const typename pcl::PointCloud<PointT>::ConstPtr &source_points,
1092  const typename pcl::PointCloud<PointT>::ConstPtr &target_points,
1093  const pcl::Correspondences &correspondences,
1094  int nth,
1095  const std::string &id = "correspondences",
1096  int viewport = 0);
1097 
1098  /** \brief Update the specified correspondences to the display.
1099  * \param[in] source_points The source points
1100  * \param[in] target_points The target points
1101  * \param[in] correspondences The mapping from source points to target points. Each element must be an index into target_points
1102  * \param[in] id the polygon object id (default: "correspondences")
1103  * \param[in] viewport the view port where the correspondences should be updated (default: all)
1104  */
1105  template <typename PointT> bool
1107  const typename pcl::PointCloud<PointT>::ConstPtr &source_points,
1108  const typename pcl::PointCloud<PointT>::ConstPtr &target_points,
1109  const pcl::Correspondences &correspondences,
1110  const std::string &id = "correspondences",
1111  int viewport = 0)
1112  {
1113  // If Nth not given, display all correspondences
1114  return (updateCorrespondences<PointT> (source_points, target_points,
1115  correspondences, 1, id, viewport));
1116  }
1117 
1118  /** \brief Remove the specified correspondences from the display.
1119  * \param[in] id the polygon correspondences object id (i.e., given on \ref addCorrespondences)
1120  * \param[in] viewport view port from where the correspondences should be removed (default: all)
1121  */
1122  void
1123  removeCorrespondences (const std::string &id = "correspondences", int viewport = 0);
1124 
1125  /** \brief Get the color handler index of a rendered PointCloud based on its ID
1126  * \param[in] id the point cloud object id
1127  */
1128  int
1129  getColorHandlerIndex (const std::string &id);
1130 
1131  /** \brief Get the geometry handler index of a rendered PointCloud based on its ID
1132  * \param[in] id the point cloud object id
1133  */
1134  int
1135  getGeometryHandlerIndex (const std::string &id);
1136 
1137  /** \brief Update/set the color index of a rendered PointCloud based on its ID
1138  * \param[in] id the point cloud object id
1139  * \param[in] index the color handler index to use
1140  */
1141  bool
1142  updateColorHandlerIndex (const std::string &id, int index);
1143 
1144  /** \brief Set the rendering properties of a PointCloud (3x values - e.g., RGB)
1145  * \param[in] property the property type
1146  * \param[in] val1 the first value to be set
1147  * \param[in] val2 the second value to be set
1148  * \param[in] val3 the third value to be set
1149  * \param[in] id the point cloud object id (default: cloud)
1150  * \param[in] viewport the view port where the Point Cloud's rendering properties should be modified (default: all)
1151  * \note The list of properties can be found in \ref pcl::visualization::LookUpTableRepresentationProperties.
1152  */
1153  bool
1154  setPointCloudRenderingProperties (int property, double val1, double val2, double val3,
1155  const std::string &id = "cloud", int viewport = 0);
1156 
1157  /** \brief Set the rendering properties of a PointCloud (2x values - e.g., LUT minmax values)
1158  * \param[in] property the property type
1159  * \param[in] val1 the first value to be set
1160  * \param[in] val2 the second value to be set
1161  * \param[in] id the point cloud object id (default: cloud)
1162  * \param[in] viewport the view port where the Point Cloud's rendering properties should be modified (default: all)
1163  * \note The list of properties can be found in \ref pcl::visualization::LookUpTableRepresentationProperties.
1164  */
1165  bool
1166  setPointCloudRenderingProperties (int property, double val1, double val2,
1167  const std::string &id = "cloud", int viewport = 0);
1168 
1169  /** \brief Set the rendering properties of a PointCloud
1170  * \param[in] property the property type
1171  * \param[in] value the value to be set
1172  * \param[in] id the point cloud object id (default: cloud)
1173  * \param[in] viewport the view port where the Point Cloud's rendering properties should be modified (default: all)
1174  * \note The list of properties can be found in \ref pcl::visualization::LookUpTableRepresentationProperties.
1175  */
1176  bool
1177  setPointCloudRenderingProperties (int property, double value,
1178  const std::string &id = "cloud", int viewport = 0);
1179 
1180  /** \brief Get the rendering properties of a PointCloud
1181  * \param[in] property the property type
1182  * \param[in] value the resultant property value
1183  * \param[in] id the point cloud object id (default: cloud)
1184  * \note The list of properties can be found in \ref pcl::visualization::LookUpTableRepresentationProperties.
1185  */
1186  bool
1187  getPointCloudRenderingProperties (int property, double &value,
1188  const std::string &id = "cloud");
1189 
1190  /** \brief Get the rendering properties of a PointCloud
1191  * \param[in] property the property type
1192  * \param[out] val1 the resultant property value
1193  * \param[out] val2 the resultant property value
1194  * \param[out] val3 the resultant property value
1195  * \param[in] id the point cloud object id (default: cloud)
1196  * \return True if the property is effectively retrieved.
1197  * \note The list of properties can be found in \ref pcl::visualization::LookUpTableRepresentationProperties.
1198  */
1199  bool
1200  getPointCloudRenderingProperties (RenderingProperties property, double &val1, double &val2, double &val3,
1201  const std::string &id = "cloud");
1202 
1203  /** \brief Set whether the point cloud is selected or not
1204  * \param[in] selected whether the cloud is selected or not (true = selected)
1205  * \param[in] id the point cloud object id (default: cloud)
1206  */
1207  bool
1208  setPointCloudSelected (const bool selected, const std::string &id = "cloud" );
1209 
1210  /** \brief Set the rendering properties of a shape
1211  * \param[in] property the property type
1212  * \param[in] value the value to be set
1213  * \param[in] id the shape object id
1214  * \param[in] viewport the view port where the shape's properties should be modified (default: all)
1215  * \note When using \ref addPolygonMesh you you should use \ref setPointCloudRenderingProperties
1216  * \note The list of properties can be found in \ref pcl::visualization::LookUpTableRepresentationProperties.
1217  */
1218  bool
1219  setShapeRenderingProperties (int property, double value,
1220  const std::string &id, int viewport = 0);
1221 
1222  /** \brief Set the rendering properties of a shape (2x values - e.g., LUT minmax values)
1223  * \param[in] property the property type
1224  * \param[in] val1 the first value to be set
1225  * \param[in] val2 the second value to be set
1226  * \param[in] id the shape object id
1227  * \param[in] viewport the view port where the shape's properties should be modified (default: all)
1228  * \note When using \ref addPolygonMesh you you should use \ref setPointCloudRenderingProperties
1229  */
1230  bool
1231  setShapeRenderingProperties (int property, double val1, double val2,
1232  const std::string &id, int viewport = 0);
1233 
1234  /** \brief Set the rendering properties of a shape (3x values - e.g., RGB)
1235  * \param[in] property the property type
1236  * \param[in] val1 the first value to be set
1237  * \param[in] val2 the second value to be set
1238  * \param[in] val3 the third value to be set
1239  * \param[in] id the shape object id
1240  * \param[in] viewport the view port where the shape's properties should be modified (default: all)
1241  * \note When using \ref addPolygonMesh you you should use \ref setPointCloudRenderingProperties
1242  */
1243  bool
1244  setShapeRenderingProperties (int property, double val1, double val2, double val3,
1245  const std::string &id, int viewport = 0);
1246 
1247  /** \brief Returns true when the user tried to close the window */
1248  bool
1249  wasStopped () const;
1250 
1251  /** \brief Set the stopped flag back to false */
1252  void
1253  resetStoppedFlag ();
1254 
1255  /** \brief Stop the interaction and close the visualizaton window. */
1256  void
1257  close ();
1258 
1259  /** \brief Create a new viewport from [xmin,ymin] -> [xmax,ymax].
1260  * \param[in] xmin the minimum X coordinate for the viewport (0.0 <= 1.0)
1261  * \param[in] ymin the minimum Y coordinate for the viewport (0.0 <= 1.0)
1262  * \param[in] xmax the maximum X coordinate for the viewport (0.0 <= 1.0)
1263  * \param[in] ymax the maximum Y coordinate for the viewport (0.0 <= 1.0)
1264  * \param[in] viewport the id of the new viewport
1265  *
1266  * \note If no renderer for the current window exists, one will be created, and
1267  * the viewport will be set to 0 ('all'). In case one or multiple renderers do
1268  * exist, the viewport ID will be set to the total number of renderers - 1.
1269  */
1270  void
1271  createViewPort (double xmin, double ymin, double xmax, double ymax, int &viewport);
1272 
1273  /** \brief Create a new separate camera for the given viewport.
1274  * \param[in] viewport the viewport to create a new camera for.
1275  */
1276  void
1277  createViewPortCamera (const int viewport);
1278 
1279  /** \brief Add a polygon (polyline) that represents the input point cloud (connects all
1280  * points in order)
1281  * \param[in] cloud the point cloud dataset representing the polygon
1282  * \param[in] r the red channel of the color that the polygon should be rendered with
1283  * \param[in] g the green channel of the color that the polygon should be rendered with
1284  * \param[in] b the blue channel of the color that the polygon should be rendered with
1285  * \param[in] id (optional) the polygon id/name (default: "polygon")
1286  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1287  */
1288  template <typename PointT> bool
1289  addPolygon (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
1290  double r, double g, double b,
1291  const std::string &id = "polygon", int viewport = 0);
1292 
1293  /** \brief Add a polygon (polyline) that represents the input point cloud (connects all
1294  * points in order)
1295  * \param[in] cloud the point cloud dataset representing the polygon
1296  * \param[in] id the polygon id/name (default: "polygon")
1297  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1298  */
1299  template <typename PointT> bool
1300  addPolygon (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
1301  const std::string &id = "polygon",
1302  int viewport = 0);
1303 
1304  /** \brief Add a planar polygon that represents the input point cloud (connects all points in order)
1305  * \param[in] polygon the polygon to draw
1306  * \param[in] r the red channel of the color that the polygon should be rendered with
1307  * \param[in] g the green channel of the color that the polygon should be rendered with
1308  * \param[in] b the blue channel of the color that the polygon should be rendered with
1309  * \param[in] id the polygon id/name (default: "polygon")
1310  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1311  */
1312  template <typename PointT> bool
1313  addPolygon (const pcl::PlanarPolygon<PointT> &polygon,
1314  double r, double g, double b,
1315  const std::string &id = "polygon",
1316  int viewport = 0);
1317 
1318  /** \brief Add a line segment from two points
1319  * \param[in] pt1 the first (start) point on the line
1320  * \param[in] pt2 the second (end) point on the line
1321  * \param[in] id the line id/name (default: "line")
1322  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1323  */
1324  template <typename P1, typename P2> bool
1325  addLine (const P1 &pt1, const P2 &pt2, const std::string &id = "line",
1326  int viewport = 0);
1327 
1328  /** \brief Add a line segment from two points
1329  * \param[in] pt1 the first (start) point on the line
1330  * \param[in] pt2 the second (end) point on the line
1331  * \param[in] r the red channel of the color that the line should be rendered with
1332  * \param[in] g the green channel of the color that the line should be rendered with
1333  * \param[in] b the blue channel of the color that the line should be rendered with
1334  * \param[in] id the line id/name (default: "line")
1335  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1336  */
1337  template <typename P1, typename P2> bool
1338  addLine (const P1 &pt1, const P2 &pt2, double r, double g, double b,
1339  const std::string &id = "line", int viewport = 0);
1340 
1341  /** \brief Add a line arrow segment between two points, and display the distance between them
1342  *
1343  * Arrow heads are attached to both end points of the arrow.
1344  *
1345  * \param[in] pt1 the first (start) point on the line
1346  * \param[in] pt2 the second (end) point on the line
1347  * \param[in] r the red channel of the color that the line should be rendered with
1348  * \param[in] g the green channel of the color that the line should be rendered with
1349  * \param[in] b the blue channel of the color that the line should be rendered with
1350  * \param[in] id the arrow id/name (default: "arrow")
1351  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1352  */
1353  template <typename P1, typename P2> bool
1354  addArrow (const P1 &pt1, const P2 &pt2, double r, double g, double b,
1355  const std::string &id = "arrow", int viewport = 0);
1356 
1357  /** \brief Add a line arrow segment between two points, and (optionally) display the distance between them
1358  *
1359  * Arrow head is attached on the **start** point (\c pt1) of the arrow.
1360  *
1361  * \param[in] pt1 the first (start) point on the line
1362  * \param[in] pt2 the second (end) point on the line
1363  * \param[in] r the red channel of the color that the line should be rendered with
1364  * \param[in] g the green channel of the color that the line should be rendered with
1365  * \param[in] b the blue channel of the color that the line should be rendered with
1366  * \param[in] display_length true if the length should be displayed on the arrow as text
1367  * \param[in] id the line id/name (default: "arrow")
1368  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1369  */
1370  template <typename P1, typename P2> bool
1371  addArrow (const P1 &pt1, const P2 &pt2, double r, double g, double b, bool display_length,
1372  const std::string &id = "arrow", int viewport = 0);
1373 
1374  /** \brief Add a line arrow segment between two points, and display the distance between them in a given color
1375  *
1376  * Arrow heads are attached to both end points of the arrow.
1377  *
1378  * \param[in] pt1 the first (start) point on the line
1379  * \param[in] pt2 the second (end) point on the line
1380  * \param[in] r_line the red channel of the color that the line should be rendered with
1381  * \param[in] g_line the green channel of the color that the line should be rendered with
1382  * \param[in] b_line the blue channel of the color that the line should be rendered with
1383  * \param[in] r_text the red channel of the color that the text should be rendered with
1384  * \param[in] g_text the green channel of the color that the text should be rendered with
1385  * \param[in] b_text the blue channel of the color that the text should be rendered with
1386  * \param[in] id the line id/name (default: "arrow")
1387  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1388  */
1389  template <typename P1, typename P2> bool
1390  addArrow (const P1 &pt1, const P2 &pt2,
1391  double r_line, double g_line, double b_line,
1392  double r_text, double g_text, double b_text,
1393  const std::string &id = "arrow", int viewport = 0);
1394 
1395 
1396  /** \brief Add a sphere shape from a point and a radius
1397  * \param[in] center the center of the sphere
1398  * \param[in] radius the radius of the sphere
1399  * \param[in] id the sphere id/name (default: "sphere")
1400  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1401  */
1402  template <typename PointT> bool
1403  addSphere (const PointT &center, double radius, const std::string &id = "sphere",
1404  int viewport = 0);
1405 
1406  /** \brief Add a sphere shape from a point and a radius
1407  * \param[in] center the center of the sphere
1408  * \param[in] radius the radius of the sphere
1409  * \param[in] r the red channel of the color that the sphere should be rendered with
1410  * \param[in] g the green channel of the color that the sphere should be rendered with
1411  * \param[in] b the blue channel of the color that the sphere should be rendered with
1412  * \param[in] id the sphere id/name (default: "sphere")
1413  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1414  */
1415  template <typename PointT> bool
1416  addSphere (const PointT &center, double radius, double r, double g, double b,
1417  const std::string &id = "sphere", int viewport = 0);
1418 
1419  /** \brief Update an existing sphere shape from a point and a radius
1420  * \param[in] center the center of the sphere
1421  * \param[in] radius the radius of the sphere
1422  * \param[in] r the red channel of the color that the sphere should be rendered with
1423  * \param[in] g the green channel of the color that the sphere should be rendered with
1424  * \param[in] b the blue channel of the color that the sphere should be rendered with
1425  * \param[in] id the sphere id/name (default: "sphere")
1426  */
1427  template <typename PointT> bool
1428  updateSphere (const PointT &center, double radius, double r, double g, double b,
1429  const std::string &id = "sphere");
1430 
1431  /** \brief Add a vtkPolydata as a mesh
1432  * \param[in] polydata vtkPolyData
1433  * \param[in] id the model id/name (default: "PolyData")
1434  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1435  */
1436  bool
1437  addModelFromPolyData (vtkSmartPointer<vtkPolyData> polydata,
1438  const std::string & id = "PolyData",
1439  int viewport = 0);
1440 
1441  /** \brief Add a vtkPolydata as a mesh
1442  * \param[in] polydata vtkPolyData
1443  * \param[in] transform transformation to apply
1444  * \param[in] id the model id/name (default: "PolyData")
1445  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1446  */
1447  bool
1448  addModelFromPolyData (vtkSmartPointer<vtkPolyData> polydata,
1450  const std::string &id = "PolyData",
1451  int viewport = 0);
1452 
1453  /** \brief Add a PLYmodel as a mesh
1454  * \param[in] filename of the ply file
1455  * \param[in] id the model id/name (default: "PLYModel")
1456  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1457  */
1458  bool
1459  addModelFromPLYFile (const std::string &filename,
1460  const std::string &id = "PLYModel",
1461  int viewport = 0);
1462 
1463  /** \brief Add a PLYmodel as a mesh and applies given transformation
1464  * \param[in] filename of the ply file
1465  * \param[in] transform transformation to apply
1466  * \param[in] id the model id/name (default: "PLYModel")
1467  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1468  */
1469  bool
1470  addModelFromPLYFile (const std::string &filename,
1472  const std::string &id = "PLYModel",
1473  int viewport = 0);
1474 
1475  /** \brief Add a cylinder from a set of given model coefficients
1476  * \param[in] coefficients the model coefficients (point_on_axis, axis_direction, radius)
1477  * \param[in] id the cylinder id/name (default: "cylinder")
1478  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1479  *
1480  * \code
1481  * // The following are given (or computed using sample consensus techniques)
1482  * // See SampleConsensusModelCylinder for more information.
1483  * // Eigen::Vector3f pt_on_axis, axis_direction;
1484  * // float radius;
1485  *
1486  * pcl::ModelCoefficients cylinder_coeff;
1487  * cylinder_coeff.values.resize (7); // We need 7 values
1488  * cylinder_coeff.values[0] = pt_on_axis.x ();
1489  * cylinder_coeff.values[1] = pt_on_axis.y ();
1490  * cylinder_coeff.values[2] = pt_on_axis.z ();
1491  *
1492  * cylinder_coeff.values[3] = axis_direction.x ();
1493  * cylinder_coeff.values[4] = axis_direction.y ();
1494  * cylinder_coeff.values[5] = axis_direction.z ();
1495  *
1496  * cylinder_coeff.values[6] = radius;
1497  *
1498  * addCylinder (cylinder_coeff);
1499  * \endcode
1500  */
1501  bool
1502  addCylinder (const pcl::ModelCoefficients &coefficients,
1503  const std::string &id = "cylinder",
1504  int viewport = 0);
1505 
1506  /** \brief Add a sphere from a set of given model coefficients
1507  * \param[in] coefficients the model coefficients (sphere center, radius)
1508  * \param[in] id the sphere id/name (default: "sphere")
1509  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1510  *
1511  * \code
1512  * // The following are given (or computed using sample consensus techniques)
1513  * // See SampleConsensusModelSphere for more information
1514  * // Eigen::Vector3f sphere_center;
1515  * // float radius;
1516  *
1517  * pcl::ModelCoefficients sphere_coeff;
1518  * sphere_coeff.values.resize (4); // We need 4 values
1519  * sphere_coeff.values[0] = sphere_center.x ();
1520  * sphere_coeff.values[1] = sphere_center.y ();
1521  * sphere_coeff.values[2] = sphere_center.z ();
1522  *
1523  * sphere_coeff.values[3] = radius;
1524  *
1525  * addSphere (sphere_coeff);
1526  * \endcode
1527  */
1528  bool
1529  addSphere (const pcl::ModelCoefficients &coefficients,
1530  const std::string &id = "sphere",
1531  int viewport = 0);
1532 
1533  /** \brief Add a line from a set of given model coefficients
1534  * \param[in] coefficients the model coefficients (point_on_line, direction)
1535  * \param[in] id the line id/name (default: "line")
1536  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1537  *
1538  * \code
1539  * // The following are given (or computed using sample consensus techniques)
1540  * // See SampleConsensusModelLine for more information
1541  * // Eigen::Vector3f point_on_line, line_direction;
1542  *
1543  * pcl::ModelCoefficients line_coeff;
1544  * line_coeff.values.resize (6); // We need 6 values
1545  * line_coeff.values[0] = point_on_line.x ();
1546  * line_coeff.values[1] = point_on_line.y ();
1547  * line_coeff.values[2] = point_on_line.z ();
1548  *
1549  * line_coeff.values[3] = line_direction.x ();
1550  * line_coeff.values[4] = line_direction.y ();
1551  * line_coeff.values[5] = line_direction.z ();
1552  *
1553  * addLine (line_coeff);
1554  * \endcode
1555  */
1556  bool
1557  addLine (const pcl::ModelCoefficients &coefficients,
1558  const std::string &id = "line",
1559  int viewport = 0);
1560 
1561  /** \brief Add a line from a set of given model coefficients
1562  * \param[in] coefficients the model coefficients (point_on_line, direction)
1563  * \param[in] id the line id/name (default: "line")
1564  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1565  *
1566  * \code
1567  * // The following are given (or computed using sample consensus techniques)
1568  * // See SampleConsensusModelLine for more information
1569  * // Eigen::Vector3f point_on_line, line_direction;
1570  *
1571  * pcl::ModelCoefficients line_coeff;
1572  * line_coeff.values.resize (6); // We need 6 values
1573  * line_coeff.values[0] = point_on_line.x ();
1574  * line_coeff.values[1] = point_on_line.y ();
1575  * line_coeff.values[2] = point_on_line.z ();
1576  *
1577  * line_coeff.values[3] = line_direction.x ();
1578  * line_coeff.values[4] = line_direction.y ();
1579  * line_coeff.values[5] = line_direction.z ();
1580  *
1581  * addLine (line_coeff);
1582  * \endcode
1583  */
1584  bool
1585  addLine (const pcl::ModelCoefficients &coefficients,
1586  const char *id = "line",
1587  int viewport = 0)
1588  {
1589  return addLine (coefficients, std::string (id), viewport);
1590  }
1591 
1592  /** \brief Add a plane from a set of given model coefficients
1593  * \param[in] coefficients the model coefficients (a, b, c, d with ax+by+cz+d=0)
1594  * \param[in] id the plane id/name (default: "plane")
1595  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1596  *
1597  * \code
1598  * // The following are given (or computed using sample consensus techniques)
1599  * // See SampleConsensusModelPlane for more information
1600  * // Eigen::Vector4f plane_parameters;
1601  *
1602  * pcl::ModelCoefficients plane_coeff;
1603  * plane_coeff.values.resize (4); // We need 4 values
1604  * plane_coeff.values[0] = plane_parameters.x ();
1605  * plane_coeff.values[1] = plane_parameters.y ();
1606  * plane_coeff.values[2] = plane_parameters.z ();
1607  * plane_coeff.values[3] = plane_parameters.w ();
1608  *
1609  * addPlane (plane_coeff);
1610  * \endcode
1611  */
1612  bool
1613  addPlane (const pcl::ModelCoefficients &coefficients,
1614  const std::string &id = "plane",
1615  int viewport = 0);
1616 
1617  bool
1618  addPlane (const pcl::ModelCoefficients &coefficients, double x, double y, double z,
1619  const std::string &id = "plane",
1620  int viewport = 0);
1621  /** \brief Add a circle from a set of given model coefficients
1622  * \param[in] coefficients the model coefficients (x, y, radius)
1623  * \param[in] id the circle id/name (default: "circle")
1624  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1625  *
1626  * \code
1627  * // The following are given (or computed using sample consensus techniques)
1628  * // See SampleConsensusModelCircle2D for more information
1629  * // float x, y, radius;
1630  *
1631  * pcl::ModelCoefficients circle_coeff;
1632  * circle_coeff.values.resize (3); // We need 3 values
1633  * circle_coeff.values[0] = x;
1634  * circle_coeff.values[1] = y;
1635  * circle_coeff.values[2] = radius;
1636  *
1637  * vtkSmartPointer<vtkDataSet> data = pcl::visualization::create2DCircle (circle_coeff, z);
1638  * \endcode
1639  */
1640  bool
1641  addCircle (const pcl::ModelCoefficients &coefficients,
1642  const std::string &id = "circle",
1643  int viewport = 0);
1644 
1645  /** \brief Add a cone from a set of given model coefficients
1646  * \param[in] coefficients the model coefficients (see \ref pcl::visualization::createCone)
1647  * \param[in] id the cone id/name (default: "cone")
1648  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1649  */
1650  bool
1651  addCone (const pcl::ModelCoefficients &coefficients,
1652  const std::string &id = "cone",
1653  int viewport = 0);
1654 
1655  /** \brief Add a cube from a set of given model coefficients
1656  * \param[in] coefficients the model coefficients (see \ref pcl::visualization::createCube)
1657  * \param[in] id the cube id/name (default: "cube")
1658  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1659  */
1660  bool
1661  addCube (const pcl::ModelCoefficients &coefficients,
1662  const std::string &id = "cube",
1663  int viewport = 0);
1664 
1665  /** \brief Add a cube from a set of given model coefficients
1666  * \param[in] translation a translation to apply to the cube from 0,0,0
1667  * \param[in] rotation a quaternion-based rotation to apply to the cube
1668  * \param[in] width the cube's width
1669  * \param[in] height the cube's height
1670  * \param[in] depth the cube's depth
1671  * \param[in] id the cube id/name (default: "cube")
1672  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1673  */
1674  bool
1675  addCube (const Eigen::Vector3f &translation, const Eigen::Quaternionf &rotation,
1676  double width, double height, double depth,
1677  const std::string &id = "cube",
1678  int viewport = 0);
1679 
1680  /** \brief Add a cube
1681  * \param[in] x_min the min X coordinate
1682  * \param[in] x_max the max X coordinate
1683  * \param[in] y_min the min Y coordinate
1684  * \param[in] y_max the max Y coordinate
1685  * \param[in] z_min the min Z coordinate
1686  * \param[in] z_max the max Z coordinate
1687  * \param[in] r how much red (0.0 -> 1.0)
1688  * \param[in] g how much green (0.0 -> 1.0)
1689  * \param[in] b how much blue (0.0 -> 1.0)
1690  * \param[in] id the cube id/name (default: "cube")
1691  * \param[in] viewport (optional) the id of the new viewport (default: 0)
1692  */
1693  bool
1694  addCube (float x_min, float x_max, float y_min, float y_max, float z_min, float z_max,
1695  double r = 1.0, double g = 1.0, double b = 1.0, const std::string &id = "cube", int viewport = 0);
1696 
1697  /** \brief Changes the visual representation for all actors to surface representation. */
1698  void
1699  setRepresentationToSurfaceForAllActors ();
1700 
1701  /** \brief Changes the visual representation for all actors to points representation. */
1702  void
1703  setRepresentationToPointsForAllActors ();
1704 
1705  /** \brief Changes the visual representation for all actors to wireframe representation. */
1706  void
1707  setRepresentationToWireframeForAllActors ();
1708 
1709  /** \brief Sets whether the 2D overlay text showing the framerate of the window is displayed or not.
1710  * \param[in] show_fps determines whether the fps text will be shown or not.
1711  */
1712  void
1713  setShowFPS (bool show_fps);
1714 
1715  /** Get the current rendering framerate.
1716  * \see setShowFPS */
1717  float
1718  getFPS () const;
1719 
1720  /** \brief Renders a virtual scene as seen from the camera viewpoint and returns the rendered point cloud.
1721  * ATT: This method will only render the scene if only on viewport exists. Otherwise, returns an empty
1722  * point cloud and exits immediately.
1723  * \param[in] xres is the size of the window (X) used to render the scene
1724  * \param[in] yres is the size of the window (Y) used to render the scene
1725  * \param[in] cloud is the rendered point cloud
1726  */
1727  void
1728  renderView (int xres, int yres, pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud);
1729 
1730  /** \brief The purpose of this method is to render a CAD model added to the visualizer from different viewpoints
1731  * in order to simulate partial views of model. The viewpoint locations are the vertices of a tessellated sphere
1732  * build from an icosaheadron. The tessellation parameter controls how many times the triangles of the original
1733  * icosahedron are divided to approximate the sphere and thus the number of partial view generated for a model,
1734  * with a tesselation_level of 0, 12 views are generated if use_vertices=true and 20 views if use_vertices=false
1735  *
1736  * \param[in] xres the size of the window (X) used to render the partial view of the object
1737  * \param[in] yres the size of the window (Y) used to render the partial view of the object
1738  * \param[in] cloud is a vector of pointcloud with XYZ information that represent the model as seen from the respective viewpoints.
1739  * \param[out] poses represent the transformation from object coordinates to camera coordinates for the respective viewpoint.
1740  * \param[out] enthropies are values between 0 and 1 representing which percentage of the model is seen from the respective viewpoint.
1741  * \param[in] tesselation_level represents the number of subdivisions applied to the triangles of original icosahedron.
1742  * \param[in] view_angle field of view of the virtual camera. Default: 45
1743  * \param[in] radius_sphere the tessellated sphere radius. Default: 1
1744  * \param[in] use_vertices if true, use the vertices of tessellated icosahedron (12,42,...) or if false, use the faces of tessellated
1745  * icosahedron (20,80,...). Default: true
1746  */
1747  void
1748  renderViewTesselatedSphere (
1749  int xres, int yres,
1751  std::vector<Eigen::Matrix4f,Eigen::aligned_allocator< Eigen::Matrix4f > > & poses, std::vector<float> & enthropies, int tesselation_level,
1752  float view_angle = 45, float radius_sphere = 1, bool use_vertices = true);
1753 
1754 
1755  /** \brief Initialize camera parameters with some default values. */
1756  void
1757  initCameraParameters ();
1758 
1759  /** \brief Search for camera parameters at the command line and set them internally.
1760  * \param[in] argc
1761  * \param[in] argv
1762  */
1763  bool
1764  getCameraParameters (int argc, char **argv);
1765 
1766  /** \brief Load camera parameters from a camera parameters file.
1767  * \param[in] file the name of the camera parameters file
1768  */
1769  bool
1770  loadCameraParameters (const std::string &file);
1771 
1772  /** \brief Checks whether the camera parameters were manually loaded.
1773  * \return True if valid "-cam" option is available in command line.
1774  * \sa cameraFileLoaded ()
1775  */
1776  bool
1777  cameraParamsSet () const;
1778 
1779  /** \brief Checks whether a camera file were automatically loaded.
1780  * \return True if a valid camera file is automatically loaded.
1781  * \note The camera file is saved by pressing "ctrl + s" during last run of the program
1782  * and restored automatically when the program runs this time.
1783  * \sa cameraParamsSet ()
1784  */
1785  bool
1786  cameraFileLoaded () const;
1787 
1788  /** \brief Get camera file for camera parameter saving/restoring.
1789  * \note This will be valid only when valid "-cam" option were available in command line
1790  * or a saved camera file were automatically loaded.
1791  * \sa cameraParamsSet (), cameraFileLoaded ()
1792  */
1793  std::string
1794  getCameraFile () const;
1795 
1796  /** \brief Update camera parameters and render. */
1797  void
1798  updateCamera ();
1799 
1800  /** \brief Reset camera parameters and render. */
1801  void
1802  resetCamera ();
1803 
1804  /** \brief Reset the camera direction from {0, 0, 0} to the center_{x, y, z} of a given dataset.
1805  * \param[in] id the point cloud object id (default: cloud)
1806  */
1807  void
1808  resetCameraViewpoint (const std::string &id = "cloud");
1809 
1810  /** \brief Set the camera pose given by position, viewpoint and up vector
1811  * \param[in] pos_x the x coordinate of the camera location
1812  * \param[in] pos_y the y coordinate of the camera location
1813  * \param[in] pos_z the z coordinate of the camera location
1814  * \param[in] view_x the x component of the view point of the camera
1815  * \param[in] view_y the y component of the view point of the camera
1816  * \param[in] view_z the z component of the view point of the camera
1817  * \param[in] up_x the x component of the view up direction of the camera
1818  * \param[in] up_y the y component of the view up direction of the camera
1819  * \param[in] up_z the y component of the view up direction of the camera
1820  * \param[in] viewport the viewport to modify camera of (0 modifies all cameras)
1821  */
1822  void
1823  setCameraPosition (double pos_x, double pos_y, double pos_z,
1824  double view_x, double view_y, double view_z,
1825  double up_x, double up_y, double up_z, int viewport = 0);
1826 
1827  /** \brief Set the camera location and viewup according to the given arguments
1828  * \param[in] pos_x the x coordinate of the camera location
1829  * \param[in] pos_y the y coordinate of the camera location
1830  * \param[in] pos_z the z coordinate of the camera location
1831  * \param[in] up_x the x component of the view up direction of the camera
1832  * \param[in] up_y the y component of the view up direction of the camera
1833  * \param[in] up_z the z component of the view up direction of the camera
1834  * \param[in] viewport the viewport to modify camera of (0 modifies all cameras)
1835  */
1836  void
1837  setCameraPosition (double pos_x, double pos_y, double pos_z,
1838  double up_x, double up_y, double up_z, int viewport = 0);
1839 
1840  /** \brief Set the camera parameters via an intrinsics and and extrinsics matrix
1841  * \note This assumes that the pixels are square and that the center of the image is at the center of the sensor.
1842  * \param[in] intrinsics the intrinsics that will be used to compute the VTK camera parameters
1843  * \param[in] extrinsics the extrinsics that will be used to compute the VTK camera parameters
1844  * \param[in] viewport the viewport to modify camera of (0 modifies all cameras)
1845  */
1846  void
1847  setCameraParameters (const Eigen::Matrix3f &intrinsics, const Eigen::Matrix4f &extrinsics, int viewport = 0);
1848 
1849  /** \brief Set the camera parameters by given a full camera data structure.
1850  * \param[in] camera camera structure containing all the camera parameters.
1851  * \param[in] viewport the viewport to modify camera of (0 modifies all cameras)
1852  */
1853  void
1854  setCameraParameters (const Camera &camera, int viewport = 0);
1855 
1856  /** \brief Set the camera clipping distances.
1857  * \param[in] near the near clipping distance (no objects closer than this to the camera will be drawn)
1858  * \param[in] far the far clipping distance (no objects further away than this to the camera will be drawn)
1859  * \param[in] viewport the viewport to modify camera of (0 modifies all cameras)
1860  */
1861  void
1862  setCameraClipDistances (double near, double far, int viewport = 0);
1863 
1864  /** \brief Set the camera vertical field of view.
1865  * \param[in] fovy vertical field of view in radians
1866  * \param[in] viewport the viewport to modify camera of (0 modifies all cameras)
1867  */
1868  void
1869  setCameraFieldOfView (double fovy, int viewport = 0);
1870 
1871  /** \brief Get the current camera parameters. */
1872  void
1873  getCameras (std::vector<Camera>& cameras);
1874 
1875 
1876  /** \brief Get the current viewing pose. */
1877  Eigen::Affine3f
1878  getViewerPose (int viewport = 0);
1879 
1880  /** \brief Save the current rendered image to disk, as a PNG screenshot.
1881  * \param[in] file the name of the PNG file
1882  */
1883  void
1884  saveScreenshot (const std::string &file);
1885 
1886  /** \brief Save the camera parameters to disk, as a .cam file.
1887  * \param[in] file the name of the .cam file
1888  */
1889  void
1890  saveCameraParameters (const std::string &file);
1891 
1892  /** \brief Get camera parameters of a given viewport (0 means default viewport). */
1893  void
1894  getCameraParameters (Camera &camera, int viewport = 0) const;
1895 
1896  /** \brief Return a pointer to the underlying VTK Render Window used. */
1899  {
1900  return (win_);
1901  }
1902 
1903  /** \brief Return a pointer to the underlying VTK Renderer Collection. */
1906  {
1907  return (rens_);
1908  }
1909 
1910  /** \brief Return a pointer to the CloudActorMap this visualizer uses. */
1913  {
1914  return (cloud_actor_map_);
1915  }
1916 
1917  /** \brief Return a pointer to the ShapeActorMap this visualizer uses. */
1920  {
1921  return (shape_actor_map_);
1922  }
1923 
1924  /** \brief Set the position in screen coordinates.
1925  * \param[in] x where to move the window to (X)
1926  * \param[in] y where to move the window to (Y)
1927  */
1928  void
1929  setPosition (int x, int y);
1930 
1931  /** \brief Set the window size in screen coordinates.
1932  * \param[in] xw window size in horizontal (pixels)
1933  * \param[in] yw window size in vertical (pixels)
1934  */
1935  void
1936  setSize (int xw, int yw);
1937 
1938  /** \brief Use Vertex Buffer Objects renderers.
1939  * This is an optimization for the obsolete OpenGL backend. Modern OpenGL2 backend (VTK ≥ 6.3) uses vertex
1940  * buffer objects by default, transparently for the user.
1941  * \param[in] use_vbos set to true to use VBOs
1942  */
1943  void
1944  setUseVbos (bool use_vbos);
1945 
1946  /** \brief Set the ID of a cloud or shape to be used for LUT display
1947  * \param[in] id The id of the cloud/shape look up table to be displayed
1948  * The look up table is displayed by pressing 'u' in the PCLVisualizer */
1949  void
1950  setLookUpTableID (const std::string id);
1951 
1952  /** \brief Create the internal Interactor object. */
1953  void
1954  createInteractor ();
1955 
1956  /** \brief Set up our unique PCL interactor style for a given vtkRenderWindowInteractor object
1957  * attached to a given vtkRenderWindow
1958  * \param[in,out] iren the vtkRenderWindowInteractor object to set up
1959  * \param[in,out] win a vtkRenderWindow object that the interactor is attached to
1960  */
1961  void
1962  setupInteractor (vtkRenderWindowInteractor *iren,
1963  vtkRenderWindow *win);
1964 
1965  /** \brief Set up PCLVisualizer with custom interactor style for a given vtkRenderWindowInteractor object
1966  * attached to a given vtkRenderWindow
1967  * \param[in,out] iren the vtkRenderWindowInteractor object to set up
1968  * \param[in,out] win a vtkRenderWindow object that the interactor is attached to
1969  * \param[in,out] style a vtkInteractorStyle object
1970  */
1971  void
1972  setupInteractor (vtkRenderWindowInteractor *iren,
1973  vtkRenderWindow *win,
1974  vtkInteractorStyle *style);
1975 
1976  /** \brief Get a pointer to the current interactor style used. */
1979  {
1980  return (style_);
1981  }
1982  protected:
1983  /** \brief The render window interactor. */
1985  private:
1986  /** \brief Internal function for renderer setup
1987  * \param[in] vtk renderer
1988  */
1989  void setupRenderer (vtkSmartPointer<vtkRenderer> ren);
1990 
1991  /** \brief Internal function for setting up FPS callback
1992  * \param[in] vtk renderer
1993  */
1994  void setupFPSCallback (const vtkSmartPointer<vtkRenderer>& ren);
1995 
1996  /** \brief Internal function for setting up render window
1997  * \param[in] name the window name
1998  */
1999  void setupRenderWindow (const std::string& name);
2000 
2001  /** \brief Internal function for setting up interactor style
2002  */
2003  void setupStyle ();
2004 
2005  /** \brief Internal function for setting the default render window size and position on screen
2006  */
2007  void setDefaultWindowSizeAndPos ();
2008 
2009  /** \brief Set up camera parameters.
2010  *
2011  * Parses command line arguments to find camera parameters (either explicit numbers or a path to a .cam file).
2012  * If not found, will generate a unique .cam file path (based on the rest of command line arguments) and try
2013  * to load that. If it is also not found, just set the defaults.
2014  */
2015  void setupCamera (int argc, char **argv);
2016 
2017  struct PCL_EXPORTS ExitMainLoopTimerCallback : public vtkCommand
2018  {
2019  static ExitMainLoopTimerCallback* New ()
2020  {
2021  return (new ExitMainLoopTimerCallback);
2022  }
2023  void
2024  Execute (vtkObject*, unsigned long event_id, void*) override;
2025 
2026  int right_timer_id;
2027  PCLVisualizer* pcl_visualizer;
2028  };
2029 
2030  struct PCL_EXPORTS ExitCallback : public vtkCommand
2031  {
2032  static ExitCallback* New ()
2033  {
2034  return (new ExitCallback);
2035  }
2036  void
2037  Execute (vtkObject*, unsigned long event_id, void*) override;
2038 
2039  PCLVisualizer* pcl_visualizer;
2040  };
2041 
2042  //////////////////////////////////////////////////////////////////////////////////////////////
2043  struct PCL_EXPORTS FPSCallback : public vtkCommand
2044  {
2045  static FPSCallback *New () { return (new FPSCallback); }
2046 
2047  FPSCallback () : actor (), pcl_visualizer (), decimated (), last_fps(0.0f) {}
2048  FPSCallback (const FPSCallback& src) : vtkCommand (src), actor (src.actor), pcl_visualizer (src.pcl_visualizer), decimated (src.decimated), last_fps (src.last_fps) {}
2049  FPSCallback& operator = (const FPSCallback& src) { actor = src.actor; pcl_visualizer = src.pcl_visualizer; decimated = src.decimated; last_fps = src.last_fps; return (*this); }
2050 
2051  void
2052  Execute (vtkObject*, unsigned long event_id, void*) override;
2053 
2054  vtkTextActor *actor;
2055  PCLVisualizer* pcl_visualizer;
2056  bool decimated;
2057  float last_fps;
2058  };
2059 
2060  /** \brief The FPSCallback object for the current visualizer. */
2061  vtkSmartPointer<FPSCallback> update_fps_;
2062 
2063  /** \brief Set to false if the interaction loop is running. */
2064  bool stopped_;
2065 
2066  /** \brief Global timer ID. Used in destructor only. */
2067  int timer_id_;
2068 
2069  /** \brief Callback object enabling us to leave the main loop, when a timer fires. */
2070  vtkSmartPointer<ExitMainLoopTimerCallback> exit_main_loop_timer_callback_;
2071  vtkSmartPointer<ExitCallback> exit_callback_;
2072 
2073  /** \brief The collection of renderers used. */
2075 
2076  /** \brief The render window. */
2078 
2079  /** \brief The render window interactor style. */
2081 
2082  /** \brief Internal list with actor pointers and name IDs for point clouds. */
2083  CloudActorMapPtr cloud_actor_map_;
2084 
2085  /** \brief Internal list with actor pointers and name IDs for shapes. */
2086  ShapeActorMapPtr shape_actor_map_;
2087 
2088  /** \brief Internal list with actor pointers and viewpoint for coordinates. */
2089  CoordinateActorMapPtr coordinate_actor_map_;
2090 
2091  /** \brief Internal pointer to widget which contains a set of axes */
2093 
2094  /** \brief Boolean that holds whether or not the camera parameters were manually initialized */
2095  bool camera_set_;
2096 
2097  /** \brief Boolean that holds whether or not a camera file were automatically loaded */
2098  bool camera_file_loaded_;
2099 
2100  /** \brief Boolean that holds whether or not to use the vtkVertexBufferObjectMapper*/
2101  bool use_vbos_;
2102 
2103  /** \brief Internal method. Removes a vtk actor from the screen.
2104  * \param[in] actor a pointer to the vtk actor object
2105  * \param[in] viewport the view port where the actor should be removed from (default: all)
2106  */
2107  bool
2108  removeActorFromRenderer (const vtkSmartPointer<vtkLODActor> &actor,
2109  int viewport = 0);
2110 
2111  /** \brief Internal method. Removes a vtk actor from the screen.
2112  * \param[in] actor a pointer to the vtk actor object
2113  * \param[in] viewport the view port where the actor should be removed from (default: all)
2114  */
2115  bool
2116  removeActorFromRenderer (const vtkSmartPointer<vtkActor> &actor,
2117  int viewport = 0);
2118 
2119  /** \brief Internal method. Adds a vtk actor to screen.
2120  * \param[in] actor a pointer to the vtk actor object
2121  * \param[in] viewport port where the actor should be added to (default: 0/all)
2122  *
2123  * \note If viewport is set to 0, the actor will be added to all existing
2124  * renders. To select a specific viewport use an integer between 1 and N.
2125  */
2126  void
2127  addActorToRenderer (const vtkSmartPointer<vtkProp> &actor,
2128  int viewport = 0);
2129 
2130  /** \brief Internal method. Adds a vtk actor to screen.
2131  * \param[in] actor a pointer to the vtk actor object
2132  * \param[in] viewport the view port where the actor should be added to (default: all)
2133  */
2134  bool
2135  removeActorFromRenderer (const vtkSmartPointer<vtkProp> &actor,
2136  int viewport = 0);
2137 
2138  /** \brief Internal method. Creates a vtk actor from a vtk polydata object.
2139  * \param[in] data the vtk polydata object to create an actor for
2140  * \param[out] actor the resultant vtk actor object
2141  * \param[in] use_scalars set scalar properties to the mapper if it exists in the data. Default: true.
2142  */
2143  void
2144  createActorFromVTKDataSet (const vtkSmartPointer<vtkDataSet> &data,
2146  bool use_scalars = true) const;
2147 
2148  /** \brief Internal method. Creates a vtk actor from a vtk polydata object.
2149  * \param[in] data the vtk polydata object to create an actor for
2150  * \param[out] actor the resultant vtk actor object
2151  * \param[in] use_scalars set scalar properties to the mapper if it exists in the data. Default: true.
2152  */
2153  void
2154  createActorFromVTKDataSet (const vtkSmartPointer<vtkDataSet> &data,
2156  bool use_scalars = true) const;
2157 
2158  /** \brief Converts a PCL templated PointCloud object to a vtk polydata object.
2159  * \param[in] cloud the input PCL PointCloud dataset
2160  * \param[out] polydata the resultant polydata containing the cloud
2161  * \param[out] initcells a list of cell indices used for the conversion. This can be set once and then passed
2162  * around to speed up the conversion.
2163  */
2164  template <typename PointT> void
2165  convertPointCloudToVTKPolyData (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
2166  vtkSmartPointer<vtkPolyData> &polydata,
2167  vtkSmartPointer<vtkIdTypeArray> &initcells);
2168 
2169  /** \brief Converts a PCL templated PointCloud object to a vtk polydata object.
2170  * \param[in] geometry_handler the geometry handler object used to extract the XYZ data
2171  * \param[out] polydata the resultant polydata containing the cloud
2172  * \param[out] initcells a list of cell indices used for the conversion. This can be set once and then passed
2173  * around to speed up the conversion.
2174  */
2175  template <typename PointT> void
2176  convertPointCloudToVTKPolyData (const PointCloudGeometryHandler<PointT> &geometry_handler,
2177  vtkSmartPointer<vtkPolyData> &polydata,
2178  vtkSmartPointer<vtkIdTypeArray> &initcells);
2179 
2180  /** \brief Converts a PCL object to a vtk polydata object.
2181  * \param[in] geometry_handler the geometry handler object used to extract the XYZ data
2182  * \param[out] polydata the resultant polydata containing the cloud
2183  * \param[out] initcells a list of cell indices used for the conversion. This can be set once and then passed
2184  * around to speed up the conversion.
2185  */
2186  void
2187  convertPointCloudToVTKPolyData (const GeometryHandlerConstPtr &geometry_handler,
2188  vtkSmartPointer<vtkPolyData> &polydata,
2189  vtkSmartPointer<vtkIdTypeArray> &initcells);
2190 
2191  /** \brief Updates a set of cells (vtkIdTypeArray) if the number of points in a cloud changes
2192  * \param[out] cells the vtkIdTypeArray object (set of cells) to update
2193  * \param[out] initcells a previously saved set of cells. If the number of points in the current cloud is
2194  * higher than the number of cells in \a cells, and initcells contains enough data, then a copy from it
2195  * will be made instead of regenerating the entire array.
2196  * \param[in] nr_points the number of points in the new cloud. This dictates how many cells we need to
2197  * generate
2198  */
2199  void
2200  updateCells (vtkSmartPointer<vtkIdTypeArray> &cells,
2202  vtkIdType nr_points);
2203 
2204  /** \brief Internal function which converts the information present in the geometric
2205  * and color handlers into VTK PolyData+Scalars, constructs a vtkActor object, and adds
2206  * all the required information to the internal cloud_actor_map_ object.
2207  * \param[in] geometry_handler the geometric handler that contains the XYZ data
2208  * \param[in] color_handler the color handler that contains the "RGB" (scalar) data
2209  * \param[in] id the point cloud object id
2210  * \param[in] viewport the view port where the Point Cloud should be added
2211  * \param[in] sensor_origin the origin of the cloud data in global coordinates (defaults to 0,0,0)
2212  * \param[in] sensor_orientation the orientation of the cloud data in global coordinates (defaults to 1,0,0,0)
2213  */
2214  template <typename PointT> bool
2215  fromHandlersToScreen (const PointCloudGeometryHandler<PointT> &geometry_handler,
2216  const PointCloudColorHandler<PointT> &color_handler,
2217  const std::string &id,
2218  int viewport,
2219  const Eigen::Vector4f& sensor_origin = Eigen::Vector4f (0, 0, 0, 0),
2220  const Eigen::Quaternion<float>& sensor_orientation = Eigen::Quaternion<float> (1, 0, 0 ,0));
2221 
2222  /** \brief Internal function which converts the information present in the geometric
2223  * and color handlers into VTK PolyData+Scalars, constructs a vtkActor object, and adds
2224  * all the required information to the internal cloud_actor_map_ object.
2225  * \param[in] geometry_handler the geometric handler that contains the XYZ data
2226  * \param[in] color_handler the color handler that contains the "RGB" (scalar) data
2227  * \param[in] id the point cloud object id
2228  * \param[in] viewport the view port where the Point Cloud should be added
2229  * \param[in] sensor_origin the origin of the cloud data in global coordinates (defaults to 0,0,0)
2230  * \param[in] sensor_orientation the orientation of the cloud data in global coordinates (defaults to 1,0,0,0)
2231  */
2232  template <typename PointT> bool
2233  fromHandlersToScreen (const PointCloudGeometryHandler<PointT> &geometry_handler,
2234  const ColorHandlerConstPtr &color_handler,
2235  const std::string &id,
2236  int viewport,
2237  const Eigen::Vector4f& sensor_origin = Eigen::Vector4f (0, 0, 0, 0),
2238  const Eigen::Quaternion<float>& sensor_orientation = Eigen::Quaternion<float> (1, 0, 0 ,0));
2239 
2240  /** \brief Internal function which converts the information present in the geometric
2241  * and color handlers into VTK PolyData+Scalars, constructs a vtkActor object, and adds
2242  * all the required information to the internal cloud_actor_map_ object.
2243  * \param[in] geometry_handler the geometric handler that contains the XYZ data
2244  * \param[in] color_handler the color handler that contains the "RGB" (scalar) data
2245  * \param[in] id the point cloud object id
2246  * \param[in] viewport the view port where the Point Cloud should be added
2247  * \param[in] sensor_origin the origin of the cloud data in global coordinates (defaults to 0,0,0)
2248  * \param[in] sensor_orientation the orientation of the cloud data in global coordinates (defaults to 1,0,0,0)
2249  */
2250  bool
2251  fromHandlersToScreen (const GeometryHandlerConstPtr &geometry_handler,
2252  const ColorHandlerConstPtr &color_handler,
2253  const std::string &id,
2254  int viewport,
2255  const Eigen::Vector4f& sensor_origin = Eigen::Vector4f (0, 0, 0, 0),
2256  const Eigen::Quaternion<float>& sensor_orientation = Eigen::Quaternion<float> (1, 0, 0 ,0));
2257 
2258  /** \brief Internal function which converts the information present in the geometric
2259  * and color handlers into VTK PolyData+Scalars, constructs a vtkActor object, and adds
2260  * all the required information to the internal cloud_actor_map_ object.
2261  * \param[in] geometry_handler the geometric handler that contains the XYZ data
2262  * \param[in] color_handler the color handler that contains the "RGB" (scalar) data
2263  * \param[in] id the point cloud object id
2264  * \param[in] viewport the view port where the Point Cloud should be added
2265  * \param[in] sensor_origin the origin of the cloud data in global coordinates (defaults to 0,0,0)
2266  * \param[in] sensor_orientation the orientation of the cloud data in global coordinates (defaults to 1,0,0,0)
2267  */
2268  template <typename PointT> bool
2269  fromHandlersToScreen (const GeometryHandlerConstPtr &geometry_handler,
2270  const PointCloudColorHandler<PointT> &color_handler,
2271  const std::string &id,
2272  int viewport,
2273  const Eigen::Vector4f& sensor_origin = Eigen::Vector4f (0, 0, 0, 0),
2274  const Eigen::Quaternion<float>& sensor_orientation = Eigen::Quaternion<float> (1, 0, 0 ,0));
2275 
2276  /** \brief Allocate a new polydata smartpointer. Internal
2277  * \param[out] polydata the resultant poly data
2278  */
2279  void
2280  allocVtkPolyData (vtkSmartPointer<vtkAppendPolyData> &polydata);
2281 
2282  /** \brief Allocate a new polydata smartpointer. Internal
2283  * \param[out] polydata the resultant poly data
2284  */
2285  void
2286  allocVtkPolyData (vtkSmartPointer<vtkPolyData> &polydata);
2287 
2288  /** \brief Allocate a new unstructured grid smartpointer. Internal
2289  * \param[out] polydata the resultant poly data
2290  */
2291  void
2293 
2294  /** \brief Transform the point cloud viewpoint to a transformation matrix
2295  * \param[in] origin the camera origin
2296  * \param[in] orientation the camera orientation
2297  * \param[out] transformation the camera transformation matrix
2298  */
2299  void
2300  getTransformationMatrix (const Eigen::Vector4f &origin,
2301  const Eigen::Quaternion<float> &orientation,
2302  Eigen::Matrix4f &transformation);
2303 
2304  /** \brief Fills a vtkTexture structure from pcl::TexMaterial.
2305  * \param[in] tex_mat texture material in PCL format
2306  * \param[out] vtk_tex texture material in VTK format
2307  * \return 0 on success and -1 else.
2308  * \note for now only image based textures are supported, image file must be in
2309  * tex_file attribute of \a tex_mat.
2310  */
2311  int
2312  textureFromTexMaterial (const pcl::TexMaterial& tex_mat,
2313  vtkTexture* vtk_tex) const;
2314 
2315  /** \brief Get camera file for camera parameter saving/restoring from command line.
2316  * Camera filename is calculated using sha1 value of all paths of input .pcd files
2317  * \return empty string if failed.
2318  */
2319  std::string
2320  getUniqueCameraFile (int argc, char **argv);
2321 
2322  //There's no reason these conversion functions shouldn't be public and static so others can use them.
2323  public:
2324  /** \brief Convert Eigen::Matrix4f to vtkMatrix4x4
2325  * \param[in] m the input Eigen matrix
2326  * \param[out] vtk_matrix the resultant VTK matrix
2327  */
2328  static void
2329  convertToVtkMatrix (const Eigen::Matrix4f &m,
2330  vtkSmartPointer<vtkMatrix4x4> &vtk_matrix);
2331 
2332  /** \brief Convert origin and orientation to vtkMatrix4x4
2333  * \param[in] origin the point cloud origin
2334  * \param[in] orientation the point cloud orientation
2335  * \param[out] vtk_matrix the resultant VTK 4x4 matrix
2336  */
2337  static void
2338  convertToVtkMatrix (const Eigen::Vector4f &origin,
2339  const Eigen::Quaternion<float> &orientation,
2340  vtkSmartPointer<vtkMatrix4x4> &vtk_matrix);
2341 
2342  /** \brief Convert vtkMatrix4x4 to an Eigen4f
2343  * \param[in] vtk_matrix the original VTK 4x4 matrix
2344  * \param[out] m the resultant Eigen 4x4 matrix
2345  */
2346  static void
2347  convertToEigenMatrix (const vtkSmartPointer<vtkMatrix4x4> &vtk_matrix,
2348  Eigen::Matrix4f &m);
2349 
2350  };
2351  }
2352 }
2353 
2354 #include <pcl/visualization/impl/pcl_visualizer.hpp>
shared_ptr< CoordinateActorMap > CoordinateActorMapPtr
Definition: actor_map.h:108
static PCLVisualizerInteractorStyle * New()
vtkSmartPointer< PCLVisualizerInteractorStyle > getInteractorStyle()
Get a pointer to the current interactor style used.
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:429
bool updatePointCloud(const pcl::PointCloud< pcl::PointXYZL >::ConstPtr &cloud, const std::string &id="cloud")
Updates the XYZL data for an existing cloud object id on screen.
bool addPointCloud(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &cloud, const std::string &id="cloud", int viewport=0)
Add a PointXYZRGB Point Cloud to screen.
bool updatePointCloud(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &cloud, const std::string &id="cloud")
Updates the XYZRGB data for an existing cloud object id on screen.
bool addPointCloud(const pcl::PointCloud< pcl::PointXYZL >::ConstPtr &cloud, const std::string &id="cloud", int viewport=0)
Add a PointXYZL Point Cloud to 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.
boost::signals2::connection registerMouseCallback(void(*callback)(const pcl::visualization::MouseEvent &, void *), void *cookie=nullptr)
Register a callback function for mouse events.
shared_ptr< const PointCloudColorHandler< PointCloud > > ConstPtr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
Camera class holds a set of camera parameters together with the window pos/size.
Definition: common.h:151
boost::signals2::connection registerKeyboardCallback(void(*callback)(const pcl::visualization::KeyboardEvent &, void *), void *cookie=nullptr)
Register a callback function for keyboard events.
vtkSmartPointer< vtkRendererCollection > getRendererCollection()
Return a pointer to the underlying VTK Renderer Collection.
RenderingProperties
Set of rendering properties.
Definition: common.h:100
shared_ptr< CloudActorMap > CloudActorMapPtr
Definition: actor_map.h:102
/brief Class representing 3D point picking events.
bool updatePointCloud(const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &cloud, const std::string &id="cloud")
Updates the XYZ data for an existing cloud object id on screen.
Base Handler class for PointCloud colors.
bool addPointCloud(const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &cloud, const std::string &id="cloud", int viewport=0)
Add a PointXYZ Point Cloud to screen.
vtkSmartPointer< vtkRenderWindowInteractor > interactor_
The render window interactor.
ColorHandler::ConstPtr ColorHandlerConstPtr
vtkIdType fillCells(std::vector< int > &lookup, const std::vector< pcl::Vertices > &vertices, vtkSmartPointer< vtkCellArray > cell_array, int max_size_of_polygon)
shared_ptr< PCLVisualizer > Ptr
bool updateCorrespondences(const typename pcl::PointCloud< PointT >::ConstPtr &source_points, const typename pcl::PointCloud< PointT >::ConstPtr &target_points, const pcl::Correspondences &correspondences, const std::string &id="correspondences", int viewport=0)
Update the specified correspondences to the display.
PCL Visualizer main class.
bool removePolygonMesh(const std::string &id="polygon", int viewport=0)
Removes a PolygonMesh from screen, based on a given ID.
PlanarPolygon represents a planar (2D) polygon, potentially in a 3D space.
std::vector< PointCloud< PointT >, Eigen::aligned_allocator< PointCloud< PointT > > > CloudVectorType
Definition: point_cloud.h:428
ShapeActorMapPtr getShapeActorMap()
Return a pointer to the ShapeActorMap this visualizer uses.
boost::signals2::connection registerKeyboardCallback(void(T::*callback)(const pcl::visualization::KeyboardEvent &, void *), T &instance, void *cookie=nullptr)
Register a callback function for keyboard events.
bool contains(const std::string &id) const
Check if the cloud, shape, or coordinate with the given id was already added to this visualizer...
bool addLine(const pcl::ModelCoefficients &coefficients, const char *id="line", int viewport=0)
Add a line from a set of given model coefficients.
shared_ptr< const PCLVisualizer > ConstPtr
PointCloud represents the base class in PCL for storing collections of 3D points. ...
Definition: distances.h:55
PCL_EXPORTS void allocVtkUnstructuredGrid(vtkSmartPointer< vtkUnstructuredGrid > &polydata)
Allocate a new unstructured grid smartpointer.
PCLVisualizerInteractorStyle defines an unique, custom VTK based interactory style for PCL Visualizer...
bool addCorrespondences(const typename pcl::PointCloud< PointT >::ConstPtr &source_points, const typename pcl::PointCloud< PointT >::ConstPtr &target_points, const pcl::Correspondences &correspondences, const std::string &id="correspondences", int viewport=0)
Add the specified correspondences to the display.
vtkSmartPointer< vtkRenderWindow > getRenderWindow()
Return a pointer to the underlying VTK Render Window used.
CloudActorMapPtr getCloudActorMap()
Return a pointer to the CloudActorMap this visualizer uses.
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:430
Base handler class for PointCloud geometry.
/brief Class representing 3D area picking events.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
GeometryHandler::ConstPtr GeometryHandlerConstPtr
boost::signals2::connection registerPointPickingCallback(void(T::*callback)(const pcl::visualization::PointPickingEvent &, void *), T &instance, void *cookie=nullptr)
Register a callback function for point picking events.
A point structure representing Euclidean xyz coordinates, and the RGB color.
/brief Class representing key hit/release events
shared_ptr< const PointCloudGeometryHandler< PointCloud > > ConstPtr
#define PCL_EXPORTS
Definition: pcl_macros.h:328
boost::signals2::connection registerAreaPickingCallback(void(T::*callback)(const pcl::visualization::AreaPickingEvent &, void *), T &instance, void *cookie=nullptr)
Register a callback function for area picking events.
shared_ptr< ShapeActorMap > ShapeActorMapPtr
Definition: actor_map.h:105
bool addPointCloud(const pcl::PointCloud< pcl::PointXYZRGBA >::ConstPtr &cloud, const std::string &id="cloud", int viewport=0)
Add a PointXYZRGBA Point Cloud to screen.
bool updatePointCloud(const pcl::PointCloud< pcl::PointXYZRGBA >::ConstPtr &cloud, const std::string &id="cloud")
Updates the XYZRGBA data for an existing cloud object id on screen.
GeometryHandler::Ptr GeometryHandlerPtr