44#include <pcl/console/print.h>
45#include <pcl/visualization/interactor_style.h>
46#include <pcl/visualization/vtk/pcl_image_canvas_source_2d.h>
47#include <pcl/visualization/vtk/pcl_context_item.h>
48#include <pcl/geometry/planar_polygon.h>
49#include <pcl/correspondence.h>
51#include <boost/shared_array.hpp>
53#include <vtkVersion.h>
54#include <vtkInteractorStyleImage.h>
55#include <vtkRenderWindowInteractor.h>
64 namespace visualization
66 using Vector3ub = Eigen::Array<unsigned char, 3, 1>;
139 interactor_->SetInteractorStyle (
style);
161 addMonoImage (
const unsigned char* data,
unsigned width,
unsigned height,
256 showRGBImage (
const unsigned char* data,
unsigned width,
unsigned height,
268 addRGBImage (
const unsigned char* data,
unsigned width,
unsigned height,
277 template <
typename T>
inline void
289 template <
typename T>
inline void
301 template <
typename T>
void
310 template <
typename T>
void
326 float min_value = std::numeric_limits<float>::min (),
342 float min_value = std::numeric_limits<float>::min (),
358 unsigned short min_value = std::numeric_limits<unsigned short>::min (),
359 unsigned short max_value = std::numeric_limits<unsigned short>::max (),
bool grayscale =
false,
374 unsigned short min_value = std::numeric_limits<unsigned short>::min (),
375 unsigned short max_value = std::numeric_limits<unsigned short>::max (),
bool grayscale =
false,
409 const std::string &
layer_id =
"half_angle_image",
double opacity = 1.0);
420 const std::string &
layer_id =
"half_angle_image",
double opacity = 1.0);
482 boost::signals2::connection
495 template<
typename T> boost::signals2::connection
506 boost::signals2::connection
514 boost::signals2::connection
527 template<
typename T> boost::signals2::connection
538 boost::signals2::connection
569 interactor_->TerminateApp ();
580 addCircle (
unsigned int x,
unsigned int y,
double radius,
594 addCircle (
unsigned int x,
unsigned int y,
double radius,
595 double r,
double g,
double b,
619 double r,
double g,
double b,
647 double r,
double g,
double b,
657 template <
typename T>
bool
672 template <
typename T>
bool
675 double r,
double g,
double b,
687 template <
typename T>
bool
689 double r,
double g,
double b,
698 template <
typename T>
bool
727 double r,
double g,
double b,
743 double r,
double g,
double b,
769 addText (
unsigned int x,
unsigned int y,
const std::string& text,
770 double r,
double g,
double b,
781 addText (
unsigned int x,
unsigned int y,
const std::string& text,
793 template <
typename T>
bool
795 double r,
double g,
double b,
804 template <
typename T>
bool
818 template <
typename T>
bool
820 double r,
double g,
double b,
830 template <
typename T>
bool
856 template <
typename Po
intT>
bool
861 const std::string &
layer_id =
"correspondences");
876 boost::shared_array<unsigned char> data);
886 boost::shared_array<unsigned char> data);
894 template <
typename T>
void
896 boost::shared_array<unsigned char> &data);
932 if (
event_id != vtkCommand::TimerEvent)
937 window->interactor_->TerminateApp ();
953 if (
event_id != vtkCommand::ExitEvent)
955 window->stopped_ =
true;
956 window->interactor_->TerminateApp ();
967 std::string layer_name;
970 using LayerMap = std::vector<Layer>;
1009 boost::shared_array<unsigned char> data_;
1012 std::size_t data_size_;
1024 LayerMap layer_map_;
1032 std::vector<unsigned char*> image_data_;
1034 struct LayerComparator
1036 LayerComparator (
const std::string &
str) : str_ (
str) {}
1037 const std::string &str_;
1040 operator () (
const Layer &layer)
1042 return (layer.layer_name == str_);
1052#include <pcl/visualization/impl/image_viewer.hpp>
Iterator class for point clouds with or without given indices.
shared_ptr< const PointCloud< PointT > > ConstPtr
ImageViewer is a class for 2D image visualization.
void markPoints(const std::vector< float > &uv, Vector3ub fg_color, Vector3ub bg_color=red_color, double size=3.0, const std::string &layer_id="markers", double opacity=1.0)
Sets the pixel at coordinates(u,v) to color while setting the neighborhood to another (float coordina...
bool addRectangle(unsigned int x_min, unsigned int x_max, unsigned int y_min, unsigned int y_max, const std::string &layer_id="rectangles", double opacity=1.0)
Add a 2D box and color its edges with a given color.
void setWindowTitle(const std::string &name)
Set the window title name.
bool addRectangle(const pcl::PointXY &min_pt, const pcl::PointXY &max_pt, const std::string &layer_id="rectangles", double opacity=1.0)
Add a 2D box and color its edges with a given color.
void resetStoppedFlag()
Set the stopped flag back to false.
bool addLine(unsigned int x_min, unsigned int y_min, unsigned int x_max, unsigned int y_max, const std::string &layer_id="line", double opacity=1.0)
Add a 2D line with a given color.
boost::signals2::connection registerKeyboardCallback(void(T::*callback)(const pcl::visualization::KeyboardEvent &, void *), T &instance, void *cookie=nullptr)
Register a callback function for keyboard events.
int * getSize()
Return the window size in pixels.
void showAngleImage(const float *data, unsigned width, unsigned height, const std::string &layer_id="angle_image", double opacity=1.0)
Show a 2D image on screen representing angle data.
shared_ptr< const ImageViewer > ConstPtr
boost::signals2::connection registerMouseCallback(void(*callback)(const pcl::visualization::MouseEvent &, void *), void *cookie=nullptr)
Register a callback std::function for mouse events.
void showRGBImage(const unsigned char *data, unsigned width, unsigned height, const std::string &layer_id="rgb_image", double opacity=1.0)
Show a 2D RGB image on screen.
void convertIntensityCloudToUChar(const pcl::PointCloud< pcl::Intensity > &cloud, boost::shared_array< unsigned char > data)
Convert the Intensity information in a PointCloud<Intensity> to an unsigned char array.
void addMonoImage(const pcl::PointCloud< pcl::Intensity8u >::ConstPtr &cloud, const std::string &layer_id="mono_image", double opacity=1.0)
Add a monochrome 2D image layer, but do not render it (use spin/spinOnce to update).
void showRGBImage(const typename pcl::PointCloud< T >::ConstPtr &cloud, const std::string &layer_id="rgb_image", double opacity=1.0)
Show a 2D image on screen, obtained from the RGB channel of a point cloud.
bool addFilledRectangle(unsigned int x_min, unsigned int x_max, unsigned int y_min, unsigned int y_max, const std::string &layer_id="boxes", double opacity=0.5)
Add a 2D box and fill it in with a given color.
void spinOnce(int time=1, bool force_redraw=true)
Spin once method.
static void MouseCallback(vtkObject *, unsigned long eid, void *clientdata, void *calldata)
void addMonoImage(const pcl::PointCloud< pcl::Intensity > &cloud, const std::string &layer_id="mono_image", double opacity=1.0)
Add a monochrome 2D image layer, but do not render it (use spin/spinOnce to update).
bool addRectangle(const pcl::PointXY &min_pt, const pcl::PointXY &max_pt, double r, double g, double b, const std::string &layer_id="rectangles", double opacity=1.0)
Add a 2D box and color its edges with a given color.
bool addRectangle(unsigned int x_min, unsigned int x_max, unsigned int y_min, unsigned int y_max, double r, double g, double b, const std::string &layer_id="rectangles", double opacity=1.0)
Add a 2D box and color its edges with a given color.
bool addLayer(const std::string &layer_id, int width, int height, double opacity=0.5)
Add a new 2D rendering layer to the viewer.
void removeLayer(const std::string &layer_id)
Remove a 2D layer given by its ID.
void addHalfAngleImage(const float *data, unsigned width, unsigned height, const std::string &layer_id="half_angle_image", double opacity=1.0)
Add a half angle 2D image layer, but do not render it (use spin/spinOnce to update).
boost::signals2::connection registerKeyboardCallback(void(*callback)(const pcl::visualization::KeyboardEvent &, void *), void *cookie=nullptr)
Register a callback function for keyboard events.
bool addText(unsigned int x, unsigned int y, const std::string &text, double r, double g, double b, const std::string &layer_id="line", double opacity=1.0)
Add a 2D text with a given color.
void addMonoImage(const unsigned char *data, unsigned width, unsigned height, const std::string &layer_id="mono_image", double opacity=1.0)
Add a monochrome 2D image layer, but do not render it (use spin/spinOnce to update).
void showFloatImage(const float *data, unsigned int width, unsigned int height, float min_value=std::numeric_limits< float >::min(), float max_value=std::numeric_limits< float >::max(), bool grayscale=false, const std::string &layer_id="float_image", double opacity=1.0)
Show a 2D image (float) on screen.
void showMonoImage(const pcl::PointCloud< pcl::Intensity8u >::ConstPtr &cloud, const std::string &layer_id="mono_image", double opacity=1.0)
Show a monochrome 2D image on screen.
void markPoints(const std::vector< int > &uv, Vector3ub fg_color, Vector3ub bg_color=red_color, double size=3.0, const std::string &layer_id="markers", double opacity=1.0)
Sets the pixel at coordinates(u,v) to color while setting the neighborhood to another.
void showHalfAngleImage(const float *data, unsigned width, unsigned height, const std::string &layer_id="half_angle_image", double opacity=1.0)
Show a 2D image on screen representing half angle data.
bool addLine(unsigned int x_min, unsigned int y_min, unsigned int x_max, unsigned int y_max, double r, double g, double b, const std::string &layer_id="line", double opacity=1.0)
Add a 2D line with a given color.
void addMonoImage(const pcl::PointCloud< pcl::Intensity8u > &cloud, const std::string &layer_id="mono_image", double opacity=1.0)
Add a monochrome 2D image layer, but do not render it (use spin/spinOnce to update).
void showShortImage(const unsigned short *short_image, unsigned int width, unsigned int height, unsigned short min_value=std::numeric_limits< unsigned short >::min(), unsigned short max_value=std::numeric_limits< unsigned short >::max(), bool grayscale=false, const std::string &layer_id="short_image", double opacity=1.0)
Show a 2D image (unsigned short) on screen.
boost::signals2::connection registerMouseCallback(void(T::*callback)(const pcl::visualization::MouseEvent &, void *), T &instance, void *cookie=nullptr)
Register a callback function for mouse events.
void emitMouseEvent(unsigned long event_id)
Fire up a mouse event with a specified event ID.
void addShortImage(const unsigned short *short_image, unsigned int width, unsigned int height, unsigned short min_value=std::numeric_limits< unsigned short >::min(), unsigned short max_value=std::numeric_limits< unsigned short >::max(), bool grayscale=false, const std::string &layer_id="short_image", double opacity=1.0)
Add a short 2D image layer, but do not render it (use spin/spinOnce to update).
static void KeyboardCallback(vtkObject *, unsigned long eid, void *clientdata, void *calldata)
virtual ~ImageViewer()
Destructor.
void showMonoImage(const pcl::PointCloud< pcl::Intensity8u > &cloud, const std::string &layer_id="mono_image", double opacity=1.0)
Show a monochrome 2D image on screen.
void showMonoImage(const unsigned char *data, unsigned width, unsigned height, const std::string &layer_id="mono_image", double opacity=1.0)
Show a monochrome 2D image on screen.
void emitKeyboardEvent(unsigned long event_id)
Fire up a keyboard event with a specified event ID.
ImageViewer(const std::string &window_title="")
Constructor.
void close()
Stop the interaction and close the visualizaton window.
void setSize(int xw, int yw)
Set the window size in screen coordinates.
bool addText(unsigned int x, unsigned int y, const std::string &text, const std::string &layer_id="line", double opacity=1.0)
Add a 2D text with a given color.
void addRGBImage(const typename pcl::PointCloud< T >::ConstPtr &cloud, const std::string &layer_id="rgb_image", double opacity=1.0)
Add an RGB 2D image layer, but do not render it (use spin/spinOnce to update).
boost::signals2::connection registerMouseCallback(std::function< void(const pcl::visualization::MouseEvent &)> cb)
Register a callback function for mouse events.
void addFloatImage(const float *data, unsigned int width, unsigned int height, float min_value=std::numeric_limits< float >::min(), float max_value=std::numeric_limits< float >::max(), bool grayscale=false, const std::string &layer_id="float_image", double opacity=1.0)
Add a float 2D image layer, but do not render it (use spin/spinOnce to update).
void showMonoImage(const pcl::PointCloud< pcl::Intensity > &cloud, const std::string &layer_id="mono_image", double opacity=1.0)
Show a monochrome 2D image on screen.
void setPosition(int x, int y)
Set the position in screen coordinates.
void markPoint(std::size_t u, std::size_t v, Vector3ub fg_color, Vector3ub bg_color=red_color, double radius=3.0, const std::string &layer_id="points", double opacity=1.0)
Sets the pixel at coordinates(u,v) to color while setting the neighborhood to another.
void addMonoImage(const pcl::PointCloud< pcl::Intensity >::ConstPtr &cloud, const std::string &layer_id="mono_image", double opacity=1.0)
Add a monochrome 2D image layer, but do not render it (use spin/spinOnce to update).
void addAngleImage(const float *data, unsigned width, unsigned height, const std::string &layer_id="angle_image", double opacity=1.0)
Add an angle 2D image layer, but do not render it (use spin/spinOnce to update).
boost::signals2::connection registerKeyboardCallback(std::function< void(const pcl::visualization::KeyboardEvent &)> cb)
Register a callback std::function for keyboard events.
bool addFilledRectangle(unsigned int x_min, unsigned int x_max, unsigned int y_min, unsigned int y_max, double r, double g, double b, const std::string &layer_id="boxes", double opacity=0.5)
Add a 2D box and fill it in with a given color.
void render()
Trigger a render call.
void convertIntensityCloud8uToUChar(const pcl::PointCloud< pcl::Intensity8u > &cloud, boost::shared_array< unsigned char > data)
Convert the Intensity8u information in a PointCloud<Intensity8u> to an unsigned char array.
bool addCircle(unsigned int x, unsigned int y, double radius, const std::string &layer_id="circles", double opacity=1.0)
Add a circle shape from a point and a radius.
void addRGBImage(const unsigned char *data, unsigned width, unsigned height, const std::string &layer_id="rgb_image", double opacity=1.0, bool autoresize=true)
Add an RGB 2D image layer, but do not render it (use spin/spinOnce to update).
bool wasStopped() const
Returns true when the user tried to close the window.
bool addCircle(unsigned int x, unsigned int y, double radius, double r, double g, double b, const std::string &layer_id="circles", double opacity=1.0)
Add a circle shape from a point and a radius.
void showMonoImage(const pcl::PointCloud< pcl::Intensity >::ConstPtr &cloud, const std::string &layer_id="mono_image", double opacity=1.0)
Show a monochrome 2D image on screen.
void setInteractorStyle(vtkInteractorObserver *style)
Set up the interactor style.
An image viewer interactor style, tailored for ImageViewer.
void adjustCamera(vtkRenderer *ren)
void OnMouseWheelForward() override
void OnMiddleButtonDown() override
ImageViewerInteractorStyle()
void OnLeftButtonDown() override
static ImageViewerInteractorStyle * New()
void OnRightButtonDown() override
void adjustCamera(vtkImageData *image, vtkRenderer *ren)
void OnMouseWheelBackward() override
/brief Class representing key hit/release events
Defines all the PCL implemented PointT point type structures.
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Defines functions, macros and traits for allocating and using memory.
static const Vector3ub red_color(255, 0, 0)
Eigen::Array< unsigned char, 3, 1 > Vector3ub
static const Vector3ub blue_color(0, 0, 255)
static const Vector3ub green_color(0, 255, 0)
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
Defines all the PCL and non-PCL macros used.
A 2D point structure representing Euclidean xy coordinates.
void Execute(vtkObject *, unsigned long event_id, void *) override
static ExitCallback * New()
static ExitMainLoopTimerCallback * New()
ExitMainLoopTimerCallback()
void Execute(vtkObject *vtkNotUsed(caller), unsigned long event_id, void *call_data) override