39 #ifndef PCL_PCL_VISUALIZER_H_
40 #define PCL_PCL_VISUALIZER_H_
52 #include <boost/algorithm/string/split.hpp>
53 #include <boost/algorithm/string/classification.hpp>
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))
74 #include <vtkRenderWindowInteractor.h>
79 namespace visualization
100 PCLVisualizer (
const std::string &name =
"",
const bool create_interactor =
true);
108 PCLVisualizer (
int &argc,
char **argv,
const std::string &name =
"",
120 setFullScreen (
bool mode)
123 win_->SetFullScreen (mode);
132 setWindowBorders (
bool mode)
135 win_->SetBorders (mode);
142 boost::signals2::connection
150 inline boost::signals2::connection
153 return (registerKeyboardCallback (boost::bind (callback, _1, cookie)));
162 template<
typename T>
inline boost::signals2::connection
165 return (registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
172 boost::signals2::connection
180 inline boost::signals2::connection
183 return (registerMouseCallback (boost::bind (callback, _1, cookie)));
192 template<
typename T>
inline boost::signals2::connection
195 return (registerMouseCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
202 boost::signals2::connection
210 inline boost::signals2::connection
213 return (registerPointPickingCallback (boost::bind (callback, _1, cookie)));
222 template<
typename T>
inline boost::signals2::connection
225 return (registerPointPickingCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
238 spinOnce (
int time = 1,
bool force_redraw =
false);
245 addCoordinateSystem (
double scale = 1.0,
int viewport = 0);
255 addCoordinateSystem (
double scale,
float x,
float y,
float z,
int viewport = 0);
289 addCoordinateSystem (
double scale,
const Eigen::Affine3f& t,
int viewport = 0);
295 removeCoordinateSystem (
int viewport = 0);
304 removePointCloud (
const std::string &
id =
"cloud",
int viewport = 0);
311 removePolygonMesh (
const std::string &
id =
"polygon",
int viewport = 0)
314 return (removePointCloud (
id, viewport));
323 removeShape (
const std::string &
id =
"cloud",
int viewport = 0);
330 removeText3D (
const std::string &
id =
"cloud",
int viewport = 0);
336 removeAllPointClouds (
int viewport = 0);
342 removeAllShapes (
int viewport = 0);
351 setBackgroundColor (
const double &r,
const double &g,
const double &b,
int viewport = 0);
361 addText (
const std::string &text,
363 const std::string &
id =
"",
int viewport = 0);
376 addText (
const std::string &text,
int xpos,
int ypos,
double r,
double g,
double b,
377 const std::string &
id =
"",
int viewport = 0);
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);
402 updateText (
const std::string &text,
404 const std::string &
id =
"");
416 updateText (
const std::string &text,
417 int xpos,
int ypos,
double r,
double g,
double b,
418 const std::string &
id =
"");
431 updateText (
const std::string &text,
432 int xpos,
int ypos,
int fontsize,
double r,
double g,
double b,
433 const std::string &
id =
"");
445 updateShapePose (
const std::string &
id,
const Eigen::Affine3f& pose);
457 template <
typename Po
intT>
bool
458 addText3D (
const std::string &text,
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);
471 template <
typename Po
intNT>
bool
473 int level = 100,
double scale = 0.02,
474 const std::string &
id =
"cloud",
int viewport = 0);
484 template <
typename Po
intT,
typename Po
intNT>
bool
487 int level = 100,
double scale = 0.02,
488 const std::string &
id =
"cloud",
int viewport = 0);
500 addPointCloudPrincipalCurvatures (
504 int level = 100,
double scale = 1.0,
505 const std::string &
id =
"cloud",
int viewport = 0);
512 template <
typename Po
intT>
bool
514 const std::string &
id =
"cloud",
int viewport = 0);
521 template <
typename Po
intT>
bool
523 const std::string &
id =
"cloud");
531 template <
typename Po
intT>
bool
534 const std::string &
id =
"cloud");
542 template <
typename Po
intT>
bool
545 const std::string &
id =
"cloud");
558 template <
typename Po
intT>
bool
561 const std::string &
id =
"cloud",
int viewport = 0);
575 template <
typename Po
intT>
bool
577 const GeometryHandlerConstPtr &geometry_handler,
578 const std::string &
id =
"cloud",
int viewport = 0);
586 template <
typename Po
intT>
bool
589 const std::string &
id =
"cloud",
int viewport = 0);
603 template <
typename Po
intT>
bool
605 const ColorHandlerConstPtr &color_handler,
606 const std::string &
id =
"cloud",
int viewport = 0);
621 template <
typename Po
intT>
bool
623 const GeometryHandlerConstPtr &geometry_handler,
624 const ColorHandlerConstPtr &color_handler,
625 const std::string &
id =
"cloud",
int viewport = 0);
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);
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);
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);
699 template <
typename Po
intT>
bool
703 const std::string &
id =
"cloud",
int viewport = 0);
712 const std::string &
id =
"cloud",
int viewport = 0)
714 return (addPointCloud<pcl::PointXYZ> (cloud,
id, viewport));
725 const std::string &
id =
"cloud",
int viewport = 0)
728 return (addPointCloud<pcl::PointXYZRGB> (cloud, color_handler,
id, viewport));
738 const std::string &
id =
"cloud",
int viewport = 0)
741 return (addPointCloud<pcl::PointXYZRGBA> (cloud, color_handler,
id, viewport));
751 const std::string &
id =
"cloud")
753 return (updatePointCloud<pcl::PointXYZ> (cloud,
id));
763 const std::string &
id =
"cloud")
766 return (updatePointCloud<pcl::PointXYZRGB> (cloud, color_handler,
id));
776 const std::string &
id =
"cloud")
779 return (updatePointCloud<pcl::PointXYZRGBA> (cloud, color_handler,
id));
789 const std::string &
id =
"polygon",
798 template <
typename Po
intT>
bool
800 const std::vector<pcl::Vertices> &vertices,
801 const std::string &
id =
"polygon",
810 template <
typename Po
intT>
bool
812 const std::vector<pcl::Vertices> &vertices,
813 const std::string &
id =
"polygon");
822 const std::string &
id =
"polyline",
832 template <
typename Po
intT>
bool
835 const std::vector<int> & correspondences,
836 const std::string &
id =
"correspondences",
846 template <
typename Po
intT>
bool
850 const std::string &
id =
"correspondences",
858 removeCorrespondences (
const std::string &
id =
"correspondences",
int viewport = 0)
860 removeShape (
id, viewport);
867 getColorHandlerIndex (
const std::string &
id)
869 CloudActorMap::iterator am_it = style_->getCloudActorMap ()->find (
id);
870 if (am_it == cloud_actor_map_->end ())
873 return (am_it->second.color_handler_index_);
880 getGeometryHandlerIndex (
const std::string &
id)
882 CloudActorMap::iterator am_it = style_->getCloudActorMap ()->find (
id);
883 if (am_it != cloud_actor_map_->end ())
886 return (am_it->second.geometry_handler_index_);
894 updateColorHandlerIndex (
const std::string &
id,
int index);
905 setPointCloudRenderingProperties (
int property,
double val1,
double val2,
double val3,
906 const std::string &
id =
"cloud",
int viewport = 0);
915 setPointCloudRenderingProperties (
int property,
double value,
916 const std::string &
id =
"cloud",
int viewport = 0);
924 getPointCloudRenderingProperties (
int property,
double &value,
925 const std::string &
id =
"cloud");
934 setShapeRenderingProperties (
int property,
double value,
935 const std::string &
id,
int viewport = 0);
946 setShapeRenderingProperties (
int property,
double val1,
double val2,
double val3,
947 const std::string &
id,
int viewport = 0);
949 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
952 wasStopped ()
const {
if (interactor_ != NULL)
return (interactor_->stopped);
else return true; }
956 resetStoppedFlag () {
if (interactor_ != NULL) interactor_->stopped =
false; }
960 wasStopped ()
const {
if (interactor_ != NULL)
return (stopped_);
else return (
true); }
971 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
972 interactor_->stopped =
true;
974 interactor_->stopLoop ();
978 interactor_->TerminateApp ();
994 createViewPort (
double xmin,
double ymin,
double xmax,
double ymax,
int &viewport);
1005 template <
typename Po
intT>
bool
1007 double r,
double g,
double b,
1008 const std::string &
id =
"polygon",
int viewport = 0);
1016 template <
typename Po
intT>
bool
1018 const std::string &
id =
"polygon",
1027 template <
typename P1,
typename P2>
bool
1028 addLine (
const P1 &pt1,
const P2 &pt2,
const std::string &
id =
"line",
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);
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);
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);
1077 template <
typename Po
intT>
bool
1078 addSphere (
const PointT ¢er,
double radius,
const std::string &
id =
"sphere",
1090 template <
typename Po
intT>
bool
1091 addSphere (
const PointT ¢er,
double radius,
double r,
double g,
double b,
1092 const std::string &
id =
"sphere",
int viewport = 0);
1102 template <
typename Po
intT>
bool
1103 updateSphere (
const PointT ¢er,
double radius,
double r,
double g,
double b,
1104 const std::string &
id =
"sphere");
1112 addModelFromPolyData (vtkSmartPointer<vtkPolyData> polydata,
1113 const std::string &
id =
"PolyData",
1123 addModelFromPolyData (vtkSmartPointer<vtkPolyData> polydata,
1124 vtkSmartPointer<vtkTransform> transform,
1125 const std::string &
id =
"PolyData",
1134 addModelFromPLYFile (
const std::string &filename,
1135 const std::string &
id =
"PLYModel",
1145 addModelFromPLYFile (
const std::string &filename,
1146 vtkSmartPointer<vtkTransform> transform,
1147 const std::string &
id =
"PLYModel",
1178 const std::string &
id =
"cylinder",
1205 const std::string &
id =
"sphere",
1233 const std::string &
id =
"line",
1258 const std::string &
id =
"plane",
1282 const std::string &
id =
"circle",
1292 const std::string &
id =
"cone",
1302 const std::string &
id =
"cube",
1315 addCube (
const Eigen::Vector3f &translation,
const Eigen::Quaternionf &rotation,
1316 double width,
double height,
double depth,
1317 const std::string &
id =
"cube",
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",
1343 setRepresentationToSurfaceForAllActors ();
1347 setRepresentationToPointsForAllActors ();
1351 setRepresentationToWireframeForAllActors ();
1381 renderViewTesselatedSphere (
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);
1392 initCameraParameters ();
1399 getCameraParameters (
int argc,
char **argv);
1403 cameraParamsSet ()
const;
1417 resetCameraViewpoint (
const std::string &
id =
"cloud");
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);
1446 setCameraPosition (
double posX,
double posY,
double posZ,
1447 double viewX,
double viewY,
double viewZ,
int viewport = 0);
1451 getCameras (std::vector<Camera>& cameras);
1461 saveScreenshot (
const std::string &file);
1464 vtkSmartPointer<vtkRenderWindow>
1472 createInteractor ();
1480 setupInteractor (vtkRenderWindowInteractor *iren,
1481 vtkRenderWindow *win);
1484 inline vtkSmartPointer<PCLVisualizerInteractorStyle>
1485 getInteractorStyle ()
1491 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
1492 vtkSmartPointer<PCLVisualizerInteractor> interactor_;
1494 vtkSmartPointer<vtkRenderWindowInteractor> interactor_;
1497 struct ExitMainLoopTimerCallback :
public vtkCommand
1499 static ExitMainLoopTimerCallback* New()
1501 return new ExitMainLoopTimerCallback;
1503 virtual void Execute(vtkObject* vtkNotUsed(caller),
unsigned long event_id,
void* call_data)
1505 if (event_id != vtkCommand::TimerEvent)
1507 int timer_id = *(
int*)call_data;
1509 if (timer_id != right_timer_id)
1512 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
1513 pcl_visualizer->interactor_->stopLoop ();
1515 pcl_visualizer->interactor_->TerminateApp ();
1519 PCLVisualizer* pcl_visualizer;
1521 struct ExitCallback :
public vtkCommand
1523 static ExitCallback* New ()
1525 return new ExitCallback;
1527 virtual void Execute (vtkObject* caller,
unsigned long event_id,
void* call_data)
1529 if (event_id != vtkCommand::ExitEvent)
1531 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
1532 pcl_visualizer->interactor_->stopped =
true;
1534 pcl_visualizer->interactor_->stopLoop ();
1536 pcl_visualizer->stopped_ =
true;
1538 pcl_visualizer->interactor_->TerminateApp ();
1541 PCLVisualizer* pcl_visualizer;
1544 #if !((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
1552 vtkSmartPointer<ExitMainLoopTimerCallback> exit_main_loop_timer_callback_;
1553 vtkSmartPointer<ExitCallback> exit_callback_;
1556 vtkSmartPointer<vtkRendererCollection> rens_;
1559 vtkSmartPointer<vtkRenderWindow> win_;
1562 vtkSmartPointer<PCLVisualizerInteractorStyle> style_;
1581 removeActorFromRenderer (
const vtkSmartPointer<vtkLODActor> &actor,
1589 addActorToRenderer (
const vtkSmartPointer<vtkProp> &actor,
1597 removeActorFromRenderer (
const vtkSmartPointer<vtkProp> &actor,
1606 createActorFromVTKDataSet (
const vtkSmartPointer<vtkDataSet> &data,
1607 vtkSmartPointer<vtkLODActor> &actor,
1608 bool use_scalars =
true);
1616 template <
typename Po
intT>
void
1618 vtkSmartPointer<vtkPolyData> &polydata,
1619 vtkSmartPointer<vtkIdTypeArray> &initcells);
1627 template <
typename Po
intT>
void
1628 convertPointCloudToVTKPolyData (
const PointCloudGeometryHandler<PointT> &geometry_handler,
1629 vtkSmartPointer<vtkPolyData> &polydata,
1630 vtkSmartPointer<vtkIdTypeArray> &initcells);
1639 convertPointCloudToVTKPolyData (
const GeometryHandlerConstPtr &geometry_handler,
1640 vtkSmartPointer<vtkPolyData> &polydata,
1641 vtkSmartPointer<vtkIdTypeArray> &initcells);
1652 updateCells (vtkSmartPointer<vtkIdTypeArray> &cells,
1653 vtkSmartPointer<vtkIdTypeArray> &initcells,
1654 vtkIdType nr_points);
1666 template <
typename Po
intT>
bool
1667 fromHandlersToScreen (
const PointCloudGeometryHandler<PointT> &geometry_handler,
1668 const PointCloudColorHandler<PointT> &color_handler,
1669 const std::string &
id,
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));
1684 template <
typename Po
intT>
bool
1685 fromHandlersToScreen (
const PointCloudGeometryHandler<PointT> &geometry_handler,
1686 const ColorHandlerConstPtr &color_handler,
1687 const std::string &
id,
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));
1703 fromHandlersToScreen (
const GeometryHandlerConstPtr &geometry_handler,
1704 const ColorHandlerConstPtr &color_handler,
1705 const std::string &
id,
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));
1720 template <
typename Po
intT>
bool
1721 fromHandlersToScreen (
const GeometryHandlerConstPtr &geometry_handler,
1722 const PointCloudColorHandler<PointT> &color_handler,
1723 const std::string &
id,
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));
1732 allocVtkPolyData (vtkSmartPointer<vtkAppendPolyData> &polydata);
1738 allocVtkPolyData (vtkSmartPointer<vtkPolyData> &polydata);
1752 getTransformationMatrix (
const Eigen::Vector4f &origin,
1753 const Eigen::Quaternion<float> &orientation,
1754 Eigen::Matrix4f &transformation);
1761 convertToVtkMatrix (
const Eigen::Matrix4f &m,
1762 vtkSmartPointer<vtkMatrix4x4> &vtk_matrix);
1770 convertToVtkMatrix (
const Eigen::Vector4f &origin,
1771 const Eigen::Quaternion<float> &orientation,
1772 vtkSmartPointer<vtkMatrix4x4> &vtk_matrix);