Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pcl_visualizer.h
Go to the documentation of this file.
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  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id: pcl_visualizer.h 6220 2012-07-06 22:34:56Z rusu $
37  *
38  */
39 #ifndef PCL_PCL_VISUALIZER_H_
40 #define PCL_PCL_VISUALIZER_H_
41 
42 // PCL includes
43 #include <pcl/point_types.h>
44 #include <pcl/correspondence.h>
45 #include <pcl/point_cloud.h>
46 #include <pcl/PolygonMesh.h>
47 //
48 #include <pcl/console/print.h>
52 #include <boost/algorithm/string/split.hpp>
53 #include <boost/algorithm/string/classification.hpp>
54 // VTK includes
55 #include <vtkAxes.h>
56 #include <vtkFloatArray.h>
57 #include <vtkAppendPolyData.h>
58 #include <vtkPointData.h>
59 #include <vtkPolyData.h>
60 #include <vtkUnstructuredGrid.h>
61 #include <vtkTubeFilter.h>
62 #include <vtkPolyDataMapper.h>
63 #include <vtkDataSetMapper.h>
64 #include <vtkCellArray.h>
65 #include <vtkCommand.h>
66 #include <vtkPLYReader.h>
67 #include <vtkTransformFilter.h>
68 #include <vtkPolyLine.h>
69 #include <vtkVectorText.h>
70 #include <vtkFollower.h>
71 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
73 #else
74 #include <vtkRenderWindowInteractor.h>
75 #endif
76 
77 namespace pcl
78 {
79  namespace visualization
80  {
86  {
87  public:
91 
95 
100  PCLVisualizer (const std::string &name = "", const bool create_interactor = true);
108  PCLVisualizer (int &argc, char **argv, const std::string &name = "",
109  PCLVisualizerInteractorStyle* style = PCLVisualizerInteractorStyle::New (), const bool create_interactor = true);
110 
112  virtual ~PCLVisualizer ();
113 
119  inline void
120  setFullScreen (bool mode)
121  {
122  if (win_)
123  win_->SetFullScreen (mode);
124  }
125 
131  inline void
132  setWindowBorders (bool mode)
133  {
134  if (win_)
135  win_->SetBorders (mode);
136  }
137 
142  boost::signals2::connection
143  registerKeyboardCallback (boost::function<void (const pcl::visualization::KeyboardEvent&)> cb);
144 
150  inline boost::signals2::connection
151  registerKeyboardCallback (void (*callback) (const pcl::visualization::KeyboardEvent&, void*), void* cookie = NULL)
152  {
153  return (registerKeyboardCallback (boost::bind (callback, _1, cookie)));
154  }
155 
162  template<typename T> inline boost::signals2::connection
163  registerKeyboardCallback (void (T::*callback) (const pcl::visualization::KeyboardEvent&, void*), T& instance, void* cookie = NULL)
164  {
165  return (registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
166  }
167 
172  boost::signals2::connection
173  registerMouseCallback (boost::function<void (const pcl::visualization::MouseEvent&)> cb);
174 
180  inline boost::signals2::connection
181  registerMouseCallback (void (*callback) (const pcl::visualization::MouseEvent&, void*), void* cookie = NULL)
182  {
183  return (registerMouseCallback (boost::bind (callback, _1, cookie)));
184  }
185 
192  template<typename T> inline boost::signals2::connection
193  registerMouseCallback (void (T::*callback) (const pcl::visualization::MouseEvent&, void*), T& instance, void* cookie = NULL)
194  {
195  return (registerMouseCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
196  }
197 
202  boost::signals2::connection
203  registerPointPickingCallback (boost::function<void (const pcl::visualization::PointPickingEvent&)> cb);
204 
210  inline boost::signals2::connection
211  registerPointPickingCallback (void (*callback) (const pcl::visualization::PointPickingEvent&, void*), void* cookie = NULL)
212  {
213  return (registerPointPickingCallback (boost::bind (callback, _1, cookie)));
214  }
215 
222  template<typename T> inline boost::signals2::connection
223  registerPointPickingCallback (void (T::*callback) (const pcl::visualization::PointPickingEvent&, void*), T& instance, void* cookie = NULL)
224  {
225  return (registerPointPickingCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
226  }
227 
229  void
230  spin ();
231 
237  void
238  spinOnce (int time = 1, bool force_redraw = false);
239 
244  void
245  addCoordinateSystem (double scale = 1.0, int viewport = 0);
246 
254  void
255  addCoordinateSystem (double scale, float x, float y, float z, int viewport = 0);
256 
288  void
289  addCoordinateSystem (double scale, const Eigen::Affine3f& t, int viewport = 0);
290 
294  bool
295  removeCoordinateSystem (int viewport = 0);
296 
303  bool
304  removePointCloud (const std::string &id = "cloud", int viewport = 0);
305 
310  inline bool
311  removePolygonMesh (const std::string &id = "polygon", int viewport = 0)
312  {
313  // Polygon Meshes are represented internally as point clouds with special cell array structures since 1.4
314  return (removePointCloud (id, viewport));
315  }
316 
322  bool
323  removeShape (const std::string &id = "cloud", int viewport = 0);
324 
329  bool
330  removeText3D (const std::string &id = "cloud", int viewport = 0);
331 
335  bool
336  removeAllPointClouds (int viewport = 0);
337 
341  bool
342  removeAllShapes (int viewport = 0);
343 
350  void
351  setBackgroundColor (const double &r, const double &g, const double &b, int viewport = 0);
352 
360  bool
361  addText (const std::string &text,
362  int xpos, int ypos,
363  const std::string &id = "", int viewport = 0);
364 
375  bool
376  addText (const std::string &text, int xpos, int ypos, double r, double g, double b,
377  const std::string &id = "", int viewport = 0);
378 
390  bool
391  addText (const std::string &text, int xpos, int ypos, int fontsize, double r, double g, double b,
392  const std::string &id = "", int viewport = 0);
393 
394 
401  bool
402  updateText (const std::string &text,
403  int xpos, int ypos,
404  const std::string &id = "");
405 
415  bool
416  updateText (const std::string &text,
417  int xpos, int ypos, double r, double g, double b,
418  const std::string &id = "");
419 
430  bool
431  updateText (const std::string &text,
432  int xpos, int ypos, int fontsize, double r, double g, double b,
433  const std::string &id = "");
434 
444  bool
445  updateShapePose (const std::string &id, const Eigen::Affine3f& pose);
446 
457  template <typename PointT> bool
458  addText3D (const std::string &text,
459  const PointT &position,
460  double textScale = 1.0,
461  double r = 1.0, double g = 1.0, double b = 1.0,
462  const std::string &id = "", int viewport = 0);
463 
471  template <typename PointNT> bool
472  addPointCloudNormals (const typename pcl::PointCloud<PointNT>::ConstPtr &cloud,
473  int level = 100, double scale = 0.02,
474  const std::string &id = "cloud", int viewport = 0);
475 
484  template <typename PointT, typename PointNT> bool
485  addPointCloudNormals (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
486  const typename pcl::PointCloud<PointNT>::ConstPtr &normals,
487  int level = 100, double scale = 0.02,
488  const std::string &id = "cloud", int viewport = 0);
489 
499  bool
500  addPointCloudPrincipalCurvatures (
504  int level = 100, double scale = 1.0,
505  const std::string &id = "cloud", int viewport = 0);
506 
512  template <typename PointT> bool
513  addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
514  const std::string &id = "cloud", int viewport = 0);
515 
521  template <typename PointT> bool
522  updatePointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
523  const std::string &id = "cloud");
524 
531  template <typename PointT> bool
532  updatePointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
533  const PointCloudGeometryHandler<PointT> &geometry_handler,
534  const std::string &id = "cloud");
535 
542  template <typename PointT> bool
543  updatePointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
544  const PointCloudColorHandler<PointT> &color_handler,
545  const std::string &id = "cloud");
546 
547 // bool
548 // updatePointCloud (const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &cloud,
549 // const PointCloudColorHandlerRGBField<pcl::PointXYZRGB> &color_handler,
550 // const std::string &id = "cloud");
551 
558  template <typename PointT> bool
559  addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
560  const PointCloudGeometryHandler<PointT> &geometry_handler,
561  const std::string &id = "cloud", int viewport = 0);
562 
575  template <typename PointT> bool
576  addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
577  const GeometryHandlerConstPtr &geometry_handler,
578  const std::string &id = "cloud", int viewport = 0);
579 
586  template <typename PointT> bool
587  addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
588  const PointCloudColorHandler<PointT> &color_handler,
589  const std::string &id = "cloud", int viewport = 0);
590 
603  template <typename PointT> bool
604  addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
605  const ColorHandlerConstPtr &color_handler,
606  const std::string &id = "cloud", int viewport = 0);
607 
621  template <typename PointT> bool
622  addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
623  const GeometryHandlerConstPtr &geometry_handler,
624  const ColorHandlerConstPtr &color_handler,
625  const std::string &id = "cloud", int viewport = 0);
626 
642  bool
643  addPointCloud (const sensor_msgs::PointCloud2::ConstPtr &cloud,
644  const GeometryHandlerConstPtr &geometry_handler,
645  const ColorHandlerConstPtr &color_handler,
646  const Eigen::Vector4f& sensor_origin,
647  const Eigen::Quaternion<float>& sensor_orientation,
648  const std::string &id = "cloud", int viewport = 0);
649 
664  bool
665  addPointCloud (const sensor_msgs::PointCloud2::ConstPtr &cloud,
666  const GeometryHandlerConstPtr &geometry_handler,
667  const Eigen::Vector4f& sensor_origin,
668  const Eigen::Quaternion<float>& sensor_orientation,
669  const std::string &id = "cloud", int viewport = 0);
670 
685  bool
686  addPointCloud (const sensor_msgs::PointCloud2::ConstPtr &cloud,
687  const ColorHandlerConstPtr &color_handler,
688  const Eigen::Vector4f& sensor_origin,
689  const Eigen::Quaternion<float>& sensor_orientation,
690  const std::string &id = "cloud", int viewport = 0);
691 
699  template <typename PointT> bool
700  addPointCloud (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
701  const PointCloudColorHandler<PointT> &color_handler,
702  const PointCloudGeometryHandler<PointT> &geometry_handler,
703  const std::string &id = "cloud", int viewport = 0);
704 
710  inline bool
711  addPointCloud (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud,
712  const std::string &id = "cloud", int viewport = 0)
713  {
714  return (addPointCloud<pcl::PointXYZ> (cloud, id, viewport));
715  }
716 
717 
723  inline bool
724  addPointCloud (const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &cloud,
725  const std::string &id = "cloud", int viewport = 0)
726  {
728  return (addPointCloud<pcl::PointXYZRGB> (cloud, color_handler, id, viewport));
729  }
730 
736  inline bool
737  addPointCloud (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloud,
738  const std::string &id = "cloud", int viewport = 0)
739  {
741  return (addPointCloud<pcl::PointXYZRGBA> (cloud, color_handler, id, viewport));
742  }
743 
749  inline bool
750  updatePointCloud (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud,
751  const std::string &id = "cloud")
752  {
753  return (updatePointCloud<pcl::PointXYZ> (cloud, id));
754  }
755 
761  inline bool
762  updatePointCloud (const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr &cloud,
763  const std::string &id = "cloud")
764  {
766  return (updatePointCloud<pcl::PointXYZRGB> (cloud, color_handler, id));
767  }
768 
774  inline bool
775  updatePointCloud (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloud,
776  const std::string &id = "cloud")
777  {
779  return (updatePointCloud<pcl::PointXYZRGBA> (cloud, color_handler, id));
780  }
781 
787  bool
788  addPolygonMesh (const pcl::PolygonMesh &polymesh,
789  const std::string &id = "polygon",
790  int viewport = 0);
791 
798  template <typename PointT> bool
799  addPolygonMesh (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
800  const std::vector<pcl::Vertices> &vertices,
801  const std::string &id = "polygon",
802  int viewport = 0);
803 
810  template <typename PointT> bool
811  updatePolygonMesh (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
812  const std::vector<pcl::Vertices> &vertices,
813  const std::string &id = "polygon");
814 
820  bool
821  addPolylineFromPolygonMesh (const pcl::PolygonMesh &polymesh,
822  const std::string &id = "polyline",
823  int viewport = 0);
824 
832  template <typename PointT> bool
833  addCorrespondences (const typename pcl::PointCloud<PointT>::ConstPtr &source_points,
834  const typename pcl::PointCloud<PointT>::ConstPtr &target_points,
835  const std::vector<int> & correspondences,
836  const std::string &id = "correspondences",
837  int viewport = 0);
838 
846  template <typename PointT> bool
847  addCorrespondences (const typename pcl::PointCloud<PointT>::ConstPtr &source_points,
848  const typename pcl::PointCloud<PointT>::ConstPtr &target_points,
849  const pcl::Correspondences &correspondences,
850  const std::string &id = "correspondences",
851  int viewport = 0);
852 
857  inline void
858  removeCorrespondences (const std::string &id = "correspondences", int viewport = 0)
859  {
860  removeShape (id, viewport);
861  }
862 
866  inline int
867  getColorHandlerIndex (const std::string &id)
868  {
869  CloudActorMap::iterator am_it = style_->getCloudActorMap ()->find (id);
870  if (am_it == cloud_actor_map_->end ())
871  return (-1);
872 
873  return (am_it->second.color_handler_index_);
874  }
875 
879  inline int
880  getGeometryHandlerIndex (const std::string &id)
881  {
882  CloudActorMap::iterator am_it = style_->getCloudActorMap ()->find (id);
883  if (am_it != cloud_actor_map_->end ())
884  return (-1);
885 
886  return (am_it->second.geometry_handler_index_);
887  }
888 
893  bool
894  updateColorHandlerIndex (const std::string &id, int index);
895 
904  bool
905  setPointCloudRenderingProperties (int property, double val1, double val2, double val3,
906  const std::string &id = "cloud", int viewport = 0);
907 
914  bool
915  setPointCloudRenderingProperties (int property, double value,
916  const std::string &id = "cloud", int viewport = 0);
917 
923  bool
924  getPointCloudRenderingProperties (int property, double &value,
925  const std::string &id = "cloud");
926 
933  bool
934  setShapeRenderingProperties (int property, double value,
935  const std::string &id, int viewport = 0);
936 
945  bool
946  setShapeRenderingProperties (int property, double val1, double val2, double val3,
947  const std::string &id, int viewport = 0);
948 
949 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
950 
951  bool
952  wasStopped () const { if (interactor_ != NULL) return (interactor_->stopped); else return true; }
953 
955  void
956  resetStoppedFlag () { if (interactor_ != NULL) interactor_->stopped = false; }
957 #else
958 
959  bool
960  wasStopped () const { if (interactor_ != NULL) return (stopped_); else return (true); }
961 
963  void
964  resetStoppedFlag () { if (interactor_ != NULL) stopped_ = false; }
965 #endif
966 
968  void
969  close ()
970  {
971 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
972  interactor_->stopped = true;
973  // This tends to close the window...
974  interactor_->stopLoop ();
975 #else
976  stopped_ = true;
977  // This tends to close the window...
978  interactor_->TerminateApp ();
979 #endif
980  }
981 
993  void
994  createViewPort (double xmin, double ymin, double xmax, double ymax, int &viewport);
995 
1005  template <typename PointT> bool
1006  addPolygon (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
1007  double r, double g, double b,
1008  const std::string &id = "polygon", int viewport = 0);
1009 
1016  template <typename PointT> bool
1017  addPolygon (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
1018  const std::string &id = "polygon",
1019  int viewport = 0);
1020 
1027  template <typename P1, typename P2> bool
1028  addLine (const P1 &pt1, const P2 &pt2, const std::string &id = "line",
1029  int viewport = 0);
1030 
1040  template <typename P1, typename P2> bool
1041  addLine (const P1 &pt1, const P2 &pt2, double r, double g, double b,
1042  const std::string &id = "line", int viewport = 0);
1043 
1053  template <typename P1, typename P2> bool
1054  addArrow (const P1 &pt1, const P2 &pt2, double r, double g, double b,
1055  const std::string &id = "arrow", int viewport = 0);
1056 
1067  template <typename P1, typename P2> bool
1068  addArrow (const P1 &pt1, const P2 &pt2, double r, double g, double b, bool display_length,
1069  const std::string &id = "arrow", int viewport = 0);
1070 
1077  template <typename PointT> bool
1078  addSphere (const PointT &center, double radius, const std::string &id = "sphere",
1079  int viewport = 0);
1080 
1090  template <typename PointT> bool
1091  addSphere (const PointT &center, double radius, double r, double g, double b,
1092  const std::string &id = "sphere", int viewport = 0);
1093 
1102  template <typename PointT> bool
1103  updateSphere (const PointT &center, double radius, double r, double g, double b,
1104  const std::string &id = "sphere");
1105 
1111  bool
1112  addModelFromPolyData (vtkSmartPointer<vtkPolyData> polydata,
1113  const std::string & id = "PolyData",
1114  int viewport = 0);
1115 
1122  bool
1123  addModelFromPolyData (vtkSmartPointer<vtkPolyData> polydata,
1124  vtkSmartPointer<vtkTransform> transform,
1125  const std::string &id = "PolyData",
1126  int viewport = 0);
1127 
1133  bool
1134  addModelFromPLYFile (const std::string &filename,
1135  const std::string &id = "PLYModel",
1136  int viewport = 0);
1137 
1144  bool
1145  addModelFromPLYFile (const std::string &filename,
1146  vtkSmartPointer<vtkTransform> transform,
1147  const std::string &id = "PLYModel",
1148  int viewport = 0);
1149 
1176  bool
1177  addCylinder (const pcl::ModelCoefficients &coefficients,
1178  const std::string &id = "cylinder",
1179  int viewport = 0);
1180 
1203  bool
1204  addSphere (const pcl::ModelCoefficients &coefficients,
1205  const std::string &id = "sphere",
1206  int viewport = 0);
1207 
1231  bool
1232  addLine (const pcl::ModelCoefficients &coefficients,
1233  const std::string &id = "line",
1234  int viewport = 0);
1235 
1256  bool
1257  addPlane (const pcl::ModelCoefficients &coefficients,
1258  const std::string &id = "plane",
1259  int viewport = 0);
1260 
1280  bool
1281  addCircle (const pcl::ModelCoefficients &coefficients,
1282  const std::string &id = "circle",
1283  int viewport = 0);
1284 
1290  bool
1291  addCone (const pcl::ModelCoefficients &coefficients,
1292  const std::string &id = "cone",
1293  int viewport = 0);
1294 
1300  bool
1301  addCube (const pcl::ModelCoefficients &coefficients,
1302  const std::string &id = "cube",
1303  int viewport = 0);
1304 
1314  bool
1315  addCube (const Eigen::Vector3f &translation, const Eigen::Quaternionf &rotation,
1316  double width, double height, double depth,
1317  const std::string &id = "cube",
1318  int viewport = 0);
1319 
1333  bool
1334  addCube (double x_min, double x_max,
1335  double y_min, double y_max,
1336  double z_min, double z_max,
1337  double r = 1.0, double g = 1.0, double b = 1.0,
1338  const std::string &id = "cube",
1339  int viewport = 0);
1340 
1342  void
1343  setRepresentationToSurfaceForAllActors ();
1344 
1346  void
1347  setRepresentationToPointsForAllActors ();
1348 
1350  void
1351  setRepresentationToWireframeForAllActors ();
1352 
1360  void
1361  renderView (int xres, int yres, pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud);
1362 
1380  void
1381  renderViewTesselatedSphere (
1382  int xres, int yres,
1383  std::vector<pcl::PointCloud<pcl::PointXYZ>,Eigen::aligned_allocator< pcl::PointCloud<pcl::PointXYZ> > > & cloud,
1384  std::vector<Eigen::Matrix4f,Eigen::aligned_allocator< Eigen::Matrix4f > > & poses, std::vector<float> & enthropies, int tesselation_level,
1385  float view_angle = 45, float radius_sphere = 1, bool use_vertices = true);
1386 
1389 
1391  void
1392  initCameraParameters ();
1393 
1398  bool
1399  getCameraParameters (int argc, char **argv);
1400 
1402  bool
1403  cameraParamsSet () const;
1404 
1406  void
1407  updateCamera ();
1408 
1410  void
1411  resetCamera ();
1412 
1416  void
1417  resetCameraViewpoint (const std::string &id = "cloud");
1418 
1431  void
1432  setCameraPose (double posX, double posY, double posZ,
1433  double viewX, double viewY, double viewZ,
1434  double upX, double upY, double upZ, int viewport = 0);
1435 
1445  void
1446  setCameraPosition (double posX,double posY, double posZ,
1447  double viewX, double viewY, double viewZ, int viewport = 0);
1448 
1450  void
1451  getCameras (std::vector<Camera>& cameras);
1452 
1454  Eigen::Affine3f
1455  getViewerPose ();
1456 
1460  void
1461  saveScreenshot (const std::string &file);
1462 
1464  vtkSmartPointer<vtkRenderWindow>
1465  getRenderWindow ()
1466  {
1467  return (win_);
1468  }
1469 
1471  void
1472  createInteractor ();
1473 
1479  void
1480  setupInteractor (vtkRenderWindowInteractor *iren,
1481  vtkRenderWindow *win);
1482 
1484  inline vtkSmartPointer<PCLVisualizerInteractorStyle>
1485  getInteractorStyle ()
1486  {
1487  return (style_);
1488  }
1489  protected:
1491 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
1492  vtkSmartPointer<PCLVisualizerInteractor> interactor_;
1493 #else
1494  vtkSmartPointer<vtkRenderWindowInteractor> interactor_;
1495 #endif
1496  private:
1497  struct ExitMainLoopTimerCallback : public vtkCommand
1498  {
1499  static ExitMainLoopTimerCallback* New()
1500  {
1501  return new ExitMainLoopTimerCallback;
1502  }
1503  virtual void Execute(vtkObject* vtkNotUsed(caller), unsigned long event_id, void* call_data)
1504  {
1505  if (event_id != vtkCommand::TimerEvent)
1506  return;
1507  int timer_id = *(int*)call_data;
1508  //PCL_WARN ("[pcl::visualization::PCLVisualizer::ExitMainLoopTimerCallback] Timer %d called.\n", timer_id);
1509  if (timer_id != right_timer_id)
1510  return;
1511  // Stop vtk loop and send notification to app to wake it up
1512 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
1513  pcl_visualizer->interactor_->stopLoop ();
1514 #else
1515  pcl_visualizer->interactor_->TerminateApp ();
1516 #endif
1517  }
1518  int right_timer_id;
1519  PCLVisualizer* pcl_visualizer;
1520  };
1521  struct ExitCallback : public vtkCommand
1522  {
1523  static ExitCallback* New ()
1524  {
1525  return new ExitCallback;
1526  }
1527  virtual void Execute (vtkObject* caller, unsigned long event_id, void* call_data)
1528  {
1529  if (event_id != vtkCommand::ExitEvent)
1530  return;
1531 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
1532  pcl_visualizer->interactor_->stopped = true;
1533  // This tends to close the window...
1534  pcl_visualizer->interactor_->stopLoop ();
1535 #else
1536  pcl_visualizer->stopped_ = true;
1537  // This tends to close the window...
1538  pcl_visualizer->interactor_->TerminateApp ();
1539 #endif
1540  }
1541  PCLVisualizer* pcl_visualizer;
1542  };
1543 
1544 #if !((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
1545 
1546  bool stopped_;
1547 
1549  int timer_id_;
1550 #endif
1551 
1552  vtkSmartPointer<ExitMainLoopTimerCallback> exit_main_loop_timer_callback_;
1553  vtkSmartPointer<ExitCallback> exit_callback_;
1554 
1556  vtkSmartPointer<vtkRendererCollection> rens_;
1557 
1559  vtkSmartPointer<vtkRenderWindow> win_;
1560 
1562  vtkSmartPointer<PCLVisualizerInteractorStyle> style_;
1563 
1565  CloudActorMapPtr cloud_actor_map_;
1566 
1568  ShapeActorMapPtr shape_actor_map_;
1569 
1571  CoordinateActorMap coordinate_actor_map_;
1572 
1574  bool camera_set_;
1575 
1580  bool
1581  removeActorFromRenderer (const vtkSmartPointer<vtkLODActor> &actor,
1582  int viewport = 0);
1583 
1588  void
1589  addActorToRenderer (const vtkSmartPointer<vtkProp> &actor,
1590  int viewport = 0);
1591 
1596  bool
1597  removeActorFromRenderer (const vtkSmartPointer<vtkProp> &actor,
1598  int viewport = 0);
1599 
1605  void
1606  createActorFromVTKDataSet (const vtkSmartPointer<vtkDataSet> &data,
1607  vtkSmartPointer<vtkLODActor> &actor,
1608  bool use_scalars = true);
1609 
1616  template <typename PointT> void
1617  convertPointCloudToVTKPolyData (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
1618  vtkSmartPointer<vtkPolyData> &polydata,
1619  vtkSmartPointer<vtkIdTypeArray> &initcells);
1620 
1627  template <typename PointT> void
1628  convertPointCloudToVTKPolyData (const PointCloudGeometryHandler<PointT> &geometry_handler,
1629  vtkSmartPointer<vtkPolyData> &polydata,
1630  vtkSmartPointer<vtkIdTypeArray> &initcells);
1631 
1638  void
1639  convertPointCloudToVTKPolyData (const GeometryHandlerConstPtr &geometry_handler,
1640  vtkSmartPointer<vtkPolyData> &polydata,
1641  vtkSmartPointer<vtkIdTypeArray> &initcells);
1642 
1651  void
1652  updateCells (vtkSmartPointer<vtkIdTypeArray> &cells,
1653  vtkSmartPointer<vtkIdTypeArray> &initcells,
1654  vtkIdType nr_points);
1655 
1666  template <typename PointT> bool
1667  fromHandlersToScreen (const PointCloudGeometryHandler<PointT> &geometry_handler,
1668  const PointCloudColorHandler<PointT> &color_handler,
1669  const std::string &id,
1670  int viewport,
1671  const Eigen::Vector4f& sensor_origin = Eigen::Vector4f (0, 0, 0, 0),
1672  const Eigen::Quaternion<float>& sensor_orientation = Eigen::Quaternion<float> (1, 0, 0 ,0));
1673 
1684  template <typename PointT> bool
1685  fromHandlersToScreen (const PointCloudGeometryHandler<PointT> &geometry_handler,
1686  const ColorHandlerConstPtr &color_handler,
1687  const std::string &id,
1688  int viewport,
1689  const Eigen::Vector4f& sensor_origin = Eigen::Vector4f (0, 0, 0, 0),
1690  const Eigen::Quaternion<float>& sensor_orientation = Eigen::Quaternion<float> (1, 0, 0 ,0));
1691 
1702  bool
1703  fromHandlersToScreen (const GeometryHandlerConstPtr &geometry_handler,
1704  const ColorHandlerConstPtr &color_handler,
1705  const std::string &id,
1706  int viewport,
1707  const Eigen::Vector4f& sensor_origin = Eigen::Vector4f (0, 0, 0, 0),
1708  const Eigen::Quaternion<float>& sensor_orientation = Eigen::Quaternion<float> (1, 0, 0 ,0));
1709 
1720  template <typename PointT> bool
1721  fromHandlersToScreen (const GeometryHandlerConstPtr &geometry_handler,
1722  const PointCloudColorHandler<PointT> &color_handler,
1723  const std::string &id,
1724  int viewport,
1725  const Eigen::Vector4f& sensor_origin = Eigen::Vector4f (0, 0, 0, 0),
1726  const Eigen::Quaternion<float>& sensor_orientation = Eigen::Quaternion<float> (1, 0, 0 ,0));
1727 
1731  void
1732  allocVtkPolyData (vtkSmartPointer<vtkAppendPolyData> &polydata);
1733 
1737  void
1738  allocVtkPolyData (vtkSmartPointer<vtkPolyData> &polydata);
1739 
1743  void
1744  allocVtkUnstructuredGrid (vtkSmartPointer<vtkUnstructuredGrid> &polydata);
1745 
1751  void
1752  getTransformationMatrix (const Eigen::Vector4f &origin,
1753  const Eigen::Quaternion<float> &orientation,
1754  Eigen::Matrix4f &transformation);
1755 
1760  void
1761  convertToVtkMatrix (const Eigen::Matrix4f &m,
1762  vtkSmartPointer<vtkMatrix4x4> &vtk_matrix);
1763 
1769  void
1770  convertToVtkMatrix (const Eigen::Vector4f &origin,
1771  const Eigen::Quaternion<float> &orientation,
1772  vtkSmartPointer<vtkMatrix4x4> &vtk_matrix);
1773 
1774  };
1775  }
1776 }
1777 
1779 
1780 #endif
1781