38 #ifndef PCL_PCL_VISUALIZER_H_
39 #define PCL_PCL_VISUALIZER_H_
42 #include <pcl/correspondence.h>
43 #include <pcl/ModelCoefficients.h>
44 #include <pcl/PolygonMesh.h>
46 #include <pcl/console/print.h>
47 #include <pcl/visualization/common/actor_map.h>
48 #include <pcl/visualization/common/common.h>
49 #include <pcl/visualization/point_cloud_geometry_handlers.h>
50 #include <pcl/visualization/point_cloud_color_handlers.h>
51 #include <pcl/visualization/point_picking_event.h>
52 #include <pcl/visualization/area_picking_event.h>
53 #include <pcl/visualization/interactor_style.h>
58 class vtkRenderWindow;
59 class vtkOrientationMarkerWidget;
60 class vtkAppendPolyData;
61 class vtkRenderWindow;
62 class vtkRenderWindowInteractor;
64 class vtkInteractorStyle;
69 class vtkUnstructuredGrid;
74 template <
typename T>
class PlanarPolygon;
76 namespace visualization
88 typedef boost::shared_ptr<PCLVisualizer>
Ptr;
89 typedef boost::shared_ptr<const PCLVisualizer>
ConstPtr;
103 PCLVisualizer (
const std::string &name =
"",
const bool create_interactor =
true);
112 PCLVisualizer (
int &argc,
char **argv,
const std::string &name =
"",
124 setFullScreen (
bool mode);
130 setWindowName (
const std::string &name);
138 setWindowBorders (
bool mode);
144 boost::signals2::connection
152 inline boost::signals2::connection
155 return (registerKeyboardCallback (boost::bind (callback, _1, cookie)));
164 template<
typename T>
inline boost::signals2::connection
167 return (registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
174 boost::signals2::connection
182 inline boost::signals2::connection
185 return (registerMouseCallback (boost::bind (callback, _1, cookie)));
194 template<
typename T>
inline boost::signals2::connection
197 return (registerMouseCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
204 boost::signals2::connection
212 boost::signals2::connection
221 template<
typename T>
inline boost::signals2::connection
224 return (registerPointPickingCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
231 boost::signals2::connection
239 boost::signals2::connection
248 template<
typename T>
inline boost::signals2::connection
251 return (registerAreaPickingCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
264 spinOnce (
int time = 1,
bool force_redraw =
false);
270 addOrientationMarkerWidgetAxes (vtkRenderWindowInteractor* interactor);
274 removeOrientationMarkerWidgetAxes ();
281 addCoordinateSystem (
double scale = 1.0,
int viewport = 0);
291 addCoordinateSystem (
double scale,
float x,
float y,
float z,
int viewport = 0);
325 addCoordinateSystem (
double scale,
const Eigen::Affine3f& t,
int viewport = 0);
331 removeCoordinateSystem (
int viewport = 0);
340 removePointCloud (
const std::string &
id =
"cloud",
int viewport = 0);
347 removePolygonMesh (
const std::string &
id =
"polygon",
int viewport = 0)
350 return (removePointCloud (
id, viewport));
359 removeShape (
const std::string &
id =
"cloud",
int viewport = 0);
366 removeText3D (
const std::string &
id =
"cloud",
int viewport = 0);
372 removeAllPointClouds (
int viewport = 0);
378 removeAllShapes (
int viewport = 0);
387 setBackgroundColor (
const double &r,
const double &g,
const double &b,
int viewport = 0);
397 addText (
const std::string &text,
399 const std::string &
id =
"",
int viewport = 0);
412 addText (
const std::string &text,
int xpos,
int ypos,
double r,
double g,
double b,
413 const std::string &
id =
"",
int viewport = 0);
427 addText (
const std::string &text,
int xpos,
int ypos,
int fontsize,
double r,
double g,
double b,
428 const std::string &
id =
"",
int viewport = 0);
438 updateText (
const std::string &text,
440 const std::string &
id =
"");
452 updateText (
const std::string &text,
453 int xpos,
int ypos,
double r,
double g,
double b,
454 const std::string &
id =
"");
467 updateText (
const std::string &text,
468 int xpos,
int ypos,
int fontsize,
double r,
double g,
double b,
469 const std::string &
id =
"");
481 updateShapePose (
const std::string &
id,
const Eigen::Affine3f& pose);
493 updatePointCloudPose (
const std::string &
id,
const Eigen::Affine3f& pose);
505 template <
typename Po
intT>
bool
506 addText3D (
const std::string &text,
508 double textScale = 1.0,
509 double r = 1.0,
double g = 1.0,
double b = 1.0,
510 const std::string &
id =
"",
int viewport = 0);
519 template <
typename Po
intNT>
bool
521 int level = 100,
float scale = 0.02f,
522 const std::string &
id =
"cloud",
int viewport = 0);
532 template <
typename Po
intT,
typename Po
intNT>
bool
535 int level = 100,
float scale = 0.02f,
536 const std::string &
id =
"cloud",
int viewport = 0);
548 addPointCloudPrincipalCurvatures (
552 int level = 100,
float scale = 1.0f,
553 const std::string &
id =
"cloud",
int viewport = 0);
563 template <
typename Po
intT,
typename GradientT>
bool
566 int level = 100,
double scale = 1e-6,
567 const std::string &
id =
"cloud",
int viewport = 0);
574 template <
typename Po
intT>
bool
576 const std::string &
id =
"cloud",
int viewport = 0);
583 template <
typename Po
intT>
bool
585 const std::string &
id =
"cloud");
593 template <
typename Po
intT>
bool
596 const std::string &
id =
"cloud");
604 template <
typename Po
intT>
bool
607 const std::string &
id =
"cloud");
615 template <
typename Po
intT>
bool
618 const std::string &
id =
"cloud",
int viewport = 0);
632 template <
typename Po
intT>
bool
634 const GeometryHandlerConstPtr &geometry_handler,
635 const std::string &
id =
"cloud",
int viewport = 0);
643 template <
typename Po
intT>
bool
646 const std::string &
id =
"cloud",
int viewport = 0);
660 template <
typename Po
intT>
bool
662 const ColorHandlerConstPtr &color_handler,
663 const std::string &
id =
"cloud",
int viewport = 0);
678 template <
typename Po
intT>
bool
680 const GeometryHandlerConstPtr &geometry_handler,
681 const ColorHandlerConstPtr &color_handler,
682 const std::string &
id =
"cloud",
int viewport = 0);
701 const GeometryHandlerConstPtr &geometry_handler,
702 const ColorHandlerConstPtr &color_handler,
703 const Eigen::Vector4f& sensor_origin,
704 const Eigen::Quaternion<float>& sensor_orientation,
705 const std::string &
id =
"cloud",
int viewport = 0);
723 const GeometryHandlerConstPtr &geometry_handler,
724 const Eigen::Vector4f& sensor_origin,
725 const Eigen::Quaternion<float>& sensor_orientation,
726 const std::string &
id =
"cloud",
int viewport = 0);
744 const ColorHandlerConstPtr &color_handler,
745 const Eigen::Vector4f& sensor_origin,
746 const Eigen::Quaternion<float>& sensor_orientation,
747 const std::string &
id =
"cloud",
int viewport = 0);
756 template <
typename Po
intT>
bool
760 const std::string &
id =
"cloud",
int viewport = 0);
769 const std::string &
id =
"cloud",
int viewport = 0)
771 return (addPointCloud<pcl::PointXYZ> (cloud,
id, viewport));
782 const std::string &
id =
"cloud",
int viewport = 0)
785 return (addPointCloud<pcl::PointXYZRGB> (cloud, color_handler,
id, viewport));
795 const std::string &
id =
"cloud",
int viewport = 0)
798 return (addPointCloud<pcl::PointXYZRGBA> (cloud, color_handler,
id, viewport));
808 const std::string &
id =
"cloud")
810 return (updatePointCloud<pcl::PointXYZ> (cloud,
id));
820 const std::string &
id =
"cloud")
823 return (updatePointCloud<pcl::PointXYZRGB> (cloud, color_handler,
id));
833 const std::string &
id =
"cloud")
836 return (updatePointCloud<pcl::PointXYZRGBA> (cloud, color_handler,
id));
846 const std::string &
id =
"polygon",
855 template <
typename Po
intT>
bool
857 const std::vector<pcl::Vertices> &vertices,
858 const std::string &
id =
"polygon",
867 template <
typename Po
intT>
bool
869 const std::vector<pcl::Vertices> &vertices,
870 const std::string &
id =
"polygon");
879 const std::string &
id =
"polygon");
888 const std::string &
id =
"polyline",
898 template <
typename Po
intT>
bool
901 const std::vector<int> & correspondences,
902 const std::string &
id =
"correspondences",
913 template <
typename Po
intT>
bool
918 const std::string &
id =
"correspondences",
928 template <
typename Po
intT>
bool
932 const std::string &
id =
"correspondences",
936 return (addCorrespondences<PointT> (source_points, target_points,
937 correspondences, 1,
id, viewport));
947 template <
typename Po
intT>
bool
948 updateCorrespondences (
953 const std::string &
id =
"correspondences");
960 removeCorrespondences (
const std::string &
id =
"correspondences",
int viewport = 0);
966 getColorHandlerIndex (
const std::string &
id);
972 getGeometryHandlerIndex (
const std::string &
id);
979 updateColorHandlerIndex (
const std::string &
id,
int index);
990 setPointCloudRenderingProperties (
int property,
double val1,
double val2,
double val3,
991 const std::string &
id =
"cloud",
int viewport = 0);
1000 setPointCloudRenderingProperties (
int property,
double value,
1001 const std::string &
id =
"cloud",
int viewport = 0);
1009 getPointCloudRenderingProperties (
int property,
double &value,
1010 const std::string &
id =
"cloud");
1017 setPointCloudSelected (
const bool selected,
const std::string &
id =
"cloud" );
1026 setShapeRenderingProperties (
int property,
double value,
1027 const std::string &
id,
int viewport = 0);
1038 setShapeRenderingProperties (
int property,
double val1,
double val2,
double val3,
1039 const std::string &
id,
int viewport = 0);
1043 wasStopped ()
const;
1047 resetStoppedFlag ();
1065 createViewPort (
double xmin,
double ymin,
double xmax,
double ymax,
int &viewport);
1071 createViewPortCamera (
const int viewport);
1082 template <
typename Po
intT>
bool
1084 double r,
double g,
double b,
1085 const std::string &
id =
"polygon",
int viewport = 0);
1093 template <
typename Po
intT>
bool
1095 const std::string &
id =
"polygon",
1106 template <
typename Po
intT>
bool
1108 double r,
double g,
double b,
1109 const std::string &
id =
"polygon",
1118 template <
typename P1,
typename P2>
bool
1119 addLine (
const P1 &pt1,
const P2 &pt2,
const std::string &
id =
"line",
1131 template <
typename P1,
typename P2>
bool
1132 addLine (
const P1 &pt1,
const P2 &pt2,
double r,
double g,
double b,
1133 const std::string &
id =
"line",
int viewport = 0);
1144 template <
typename P1,
typename P2>
bool
1145 addArrow (
const P1 &pt1,
const P2 &pt2,
double r,
double g,
double b,
1146 const std::string &
id =
"arrow",
int viewport = 0);
1158 template <
typename P1,
typename P2>
bool
1159 addArrow (
const P1 &pt1,
const P2 &pt2,
double r,
double g,
double b,
bool display_length,
1160 const std::string &
id =
"arrow",
int viewport = 0);
1174 template <
typename P1,
typename P2>
bool
1175 addArrow (
const P1 &pt1,
const P2 &pt2,
1176 double r_line,
double g_line,
double b_line,
1177 double r_text,
double g_text,
double b_text,
1178 const std::string &
id =
"arrow",
int viewport = 0);
1187 template <
typename Po
intT>
bool
1188 addSphere (
const PointT ¢er,
double radius,
const std::string &
id =
"sphere",
1200 template <
typename Po
intT>
bool
1201 addSphere (
const PointT ¢er,
double radius,
double r,
double g,
double b,
1202 const std::string &
id =
"sphere",
int viewport = 0);
1212 template <
typename Po
intT>
bool
1213 updateSphere (
const PointT ¢er,
double radius,
double r,
double g,
double b,
1214 const std::string &
id =
"sphere");
1223 const std::string &
id =
"PolyData",
1235 const std::string &
id =
"PolyData",
1244 addModelFromPLYFile (
const std::string &filename,
1245 const std::string &
id =
"PLYModel",
1255 addModelFromPLYFile (
const std::string &filename,
1257 const std::string &
id =
"PLYModel",
1288 const std::string &
id =
"cylinder",
1315 const std::string &
id =
"sphere",
1343 const std::string &
id =
"line",
1368 const std::string &
id =
"plane",
1373 const std::string &
id =
"plane",
1396 const std::string &
id =
"circle",
1406 const std::string &
id =
"cone",
1416 const std::string &
id =
"cube",
1429 addCube (
const Eigen::Vector3f &translation,
const Eigen::Quaternionf &rotation,
1430 double width,
double height,
double depth,
1431 const std::string &
id =
"cube",
1448 addCube (
float x_min,
float x_max,
float y_min,
float y_max,
float z_min,
float z_max,
1449 double r = 1.0,
double g = 1.0,
double b = 1.0,
const std::string &
id =
"cube",
int viewport = 0);
1453 setRepresentationToSurfaceForAllActors ();
1457 setRepresentationToPointsForAllActors ();
1461 setRepresentationToWireframeForAllActors ();
1467 setShowFPS (
bool show_fps);
1497 renderViewTesselatedSphere (
1500 std::vector<Eigen::Matrix4f,Eigen::aligned_allocator< Eigen::Matrix4f > > & poses, std::vector<float> & enthropies,
int tesselation_level,
1501 float view_angle = 45,
float radius_sphere = 1,
bool use_vertices =
true);
1506 initCameraParameters ();
1513 getCameraParameters (
int argc,
char **argv);
1517 cameraParamsSet ()
const;
1531 resetCameraViewpoint (
const std::string &
id =
"cloud");
1546 setCameraPosition (
double pos_x,
double pos_y,
double pos_z,
1547 double view_x,
double view_y,
double view_z,
1548 double up_x,
double up_y,
double up_z,
int viewport = 0);
1560 setCameraPosition (
double pos_x,
double pos_y,
double pos_z,
1561 double up_x,
double up_y,
double up_z,
int viewport = 0);
1570 setCameraParameters (
const Eigen::Matrix3f &intrinsics,
const Eigen::Matrix4f &extrinsics,
int viewport = 0);
1577 setCameraParameters (
const Camera &camera,
int viewport = 0);
1584 setCameraClipDistances (
double near,
double far,
int viewport = 0);
1591 setCameraFieldOfView (
double fovy,
int viewport = 0);
1595 getCameras (std::vector<Camera>& cameras);
1600 getViewerPose (
int viewport = 0);
1606 saveScreenshot (
const std::string &file);
1617 getRendererCollection ()
1626 return (cloud_actor_map_);
1635 setPosition (
int x,
int y);
1642 setSize (
int xw,
int yw);
1648 setUseVbos (
bool use_vbos);
1652 createInteractor ();
1660 setupInteractor (vtkRenderWindowInteractor *iren,
1661 vtkRenderWindow *win);
1670 setupInteractor (vtkRenderWindowInteractor *iren,
1671 vtkRenderWindow *win,
1672 vtkInteractorStyle *style);
1676 getInteractorStyle ()
1682 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
1688 struct ExitMainLoopTimerCallback :
public vtkCommand
1690 static ExitMainLoopTimerCallback* New ()
1692 return (
new ExitMainLoopTimerCallback);
1695 Execute (vtkObject*,
unsigned long event_id,
void*);
1701 struct ExitCallback :
public vtkCommand
1703 static ExitCallback* New ()
1705 return (
new ExitCallback);
1708 Execute (vtkObject*,
unsigned long event_id,
void*);
1710 PCLVisualizer* pcl_visualizer;
1714 struct FPSCallback :
public vtkCommand
1716 static FPSCallback *New () {
return (
new FPSCallback); }
1718 FPSCallback () : actor (), pcl_visualizer (), decimated () {}
1719 FPSCallback (
const FPSCallback& src) : vtkCommand (), actor (src.actor), pcl_visualizer (src.pcl_visualizer), decimated (src.decimated) {}
1720 FPSCallback& operator = (
const FPSCallback& src) { actor = src.actor; pcl_visualizer = src.pcl_visualizer; decimated = src.decimated;
return (*
this); }
1723 Execute (vtkObject*,
unsigned long event_id,
void*);
1725 vtkTextActor *actor;
1726 PCLVisualizer* pcl_visualizer;
1733 #if !((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
1814 bool use_scalars =
true);
1824 bool use_scalars =
true);
1832 template <
typename Po
intT>
void
1843 template <
typename Po
intT>
void
1844 convertPointCloudToVTKPolyData (
const PointCloudGeometryHandler<PointT> &geometry_handler,
1855 convertPointCloudToVTKPolyData (
const GeometryHandlerConstPtr &geometry_handler,
1870 vtkIdType nr_points);
1882 template <
typename Po
intT>
bool
1883 fromHandlersToScreen (
const PointCloudGeometryHandler<PointT> &geometry_handler,
1884 const PointCloudColorHandler<PointT> &color_handler,
1885 const std::string &
id,
1887 const Eigen::Vector4f& sensor_origin = Eigen::Vector4f (0, 0, 0, 0),
1888 const Eigen::Quaternion<float>& sensor_orientation = Eigen::Quaternion<float> (1, 0, 0 ,0));
1900 template <
typename Po
intT>
bool
1901 fromHandlersToScreen (
const PointCloudGeometryHandler<PointT> &geometry_handler,
1902 const ColorHandlerConstPtr &color_handler,
1903 const std::string &
id,
1905 const Eigen::Vector4f& sensor_origin = Eigen::Vector4f (0, 0, 0, 0),
1906 const Eigen::Quaternion<float>& sensor_orientation = Eigen::Quaternion<float> (1, 0, 0 ,0));
1919 fromHandlersToScreen (
const GeometryHandlerConstPtr &geometry_handler,
1920 const ColorHandlerConstPtr &color_handler,
1921 const std::string &
id,
1923 const Eigen::Vector4f& sensor_origin = Eigen::Vector4f (0, 0, 0, 0),
1924 const Eigen::Quaternion<float>& sensor_orientation = Eigen::Quaternion<float> (1, 0, 0 ,0));
1936 template <
typename Po
intT>
bool
1937 fromHandlersToScreen (
const GeometryHandlerConstPtr &geometry_handler,
1938 const PointCloudColorHandler<PointT> &color_handler,
1939 const std::string &
id,
1941 const Eigen::Vector4f& sensor_origin = Eigen::Vector4f (0, 0, 0, 0),
1942 const Eigen::Quaternion<float>& sensor_orientation = Eigen::Quaternion<float> (1, 0, 0 ,0));
1968 getTransformationMatrix (
const Eigen::Vector4f &origin,
1969 const Eigen::Quaternion<float> &orientation,
1970 Eigen::Matrix4f &transformation);
1979 convertToVtkMatrix (
const Eigen::Matrix4f &m,
1988 convertToVtkMatrix (
const Eigen::Vector4f &origin,
1989 const Eigen::Quaternion<float> &orientation,
1998 Eigen::Matrix4f &m);
2004 #include <pcl/visualization/impl/pcl_visualizer.hpp>