Point Cloud Library (PCL)
1.11.0
|
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>
58 class vtkContextActor;
64 namespace visualization
66 using Vector3ub = Eigen::Array<unsigned char, 3, 1>;
121 using Ptr = shared_ptr<ImageViewer>;
139 interactor_->SetInteractorStyle (style);
151 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
161 addMonoImage (
const unsigned char* data,
unsigned width,
unsigned height,
162 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
171 const std::string &layer_id =
"mono_image",
double opacity = 1.0)
173 return (showMonoImage (*cloud, layer_id, opacity));
183 const std::string &layer_id =
"mono_image",
double opacity = 1.0)
185 return (addMonoImage (*cloud, layer_id, opacity));
195 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
204 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
213 const std::string &layer_id =
"mono_image",
double opacity = 1.0)
215 return (showMonoImage (*cloud, layer_id, opacity));
225 const std::string &layer_id =
"mono_image",
double opacity = 1.0)
227 return (addMonoImage (*cloud, layer_id, opacity));
237 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
246 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
256 showRGBImage (
const unsigned char* data,
unsigned width,
unsigned height,
257 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
268 addRGBImage (
const unsigned char* data,
unsigned width,
unsigned height,
269 const std::string &layer_id =
"rgb_image",
double opacity = 1.0,
270 bool autoresize =
true);
277 template <
typename T>
inline void
279 const std::string &layer_id =
"rgb_image",
double opacity = 1.0)
281 return (showRGBImage<T> (*cloud, layer_id, opacity));
289 template <
typename T>
inline void
291 const std::string &layer_id =
"rgb_image",
double opacity = 1.0)
293 return (addRGBImage<T> (*cloud, layer_id, opacity));
301 template <
typename T>
void
303 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
310 template <
typename T>
void
312 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
326 float min_value = std::numeric_limits<float>::min (),
327 float max_value = std::numeric_limits<float>::max (),
bool grayscale =
false,
328 const std::string &layer_id =
"float_image",
double opacity = 1.0);
342 float min_value = std::numeric_limits<float>::min (),
343 float max_value = std::numeric_limits<float>::max (),
bool grayscale =
false,
344 const std::string &layer_id =
"float_image",
double opacity = 1.0);
357 showShortImage (
const unsigned short* short_image,
unsigned int width,
unsigned int height,
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,
360 const std::string &layer_id =
"short_image",
double opacity = 1.0);
373 addShortImage (
const unsigned short* short_image,
unsigned int width,
unsigned int height,
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,
376 const std::string &layer_id =
"short_image",
double opacity = 1.0);
387 const std::string &layer_id =
"angle_image",
double opacity = 1.0);
398 const std::string &layer_id =
"angle_image",
double opacity = 1.0);
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);
433 const std::string &layer_id =
"points",
double opacity = 1.0);
445 const std::string &layer_id =
"markers",
double opacity = 1.0);
457 const std::string &layer_id =
"markers",
double opacity = 1.0);
482 boost::signals2::connection
484 void* cookie =
nullptr)
495 template<
typename T> boost::signals2::connection
497 T& instance,
void* cookie =
nullptr)
506 boost::signals2::connection
514 boost::signals2::connection
516 void* cookie =
nullptr)
527 template<
typename T> boost::signals2::connection
529 T& instance,
void* cookie =
nullptr)
538 boost::signals2::connection
569 interactor_->TerminateApp ();
580 addCircle (
unsigned int x,
unsigned int y,
double radius,
581 const std::string &layer_id =
"circles",
double opacity = 1.0);
594 addCircle (
unsigned int x,
unsigned int y,
double radius,
595 double r,
double g,
double b,
596 const std::string &layer_id =
"circles",
double opacity = 1.0);
606 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
619 double r,
double g,
double b,
620 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
631 addRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
632 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
646 addRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
647 double r,
double g,
double b,
648 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
657 template <
typename T>
bool
659 const T &min_pt,
const T &max_pt,
660 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
672 template <
typename T>
bool
674 const T &min_pt,
const T &max_pt,
675 double r,
double g,
double b,
676 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
687 template <
typename T>
bool
689 double r,
double g,
double b,
690 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
698 template <
typename T>
bool
700 const std::string &layer_id =
"image_mask",
double opacity = 1.0);
712 const std::string &layer_id =
"boxes",
double opacity = 0.5);
727 double r,
double g,
double b,
728 const std::string &layer_id =
"boxes",
double opacity = 0.5);
742 addLine (
unsigned int x_min,
unsigned int y_min,
unsigned int x_max,
unsigned int y_max,
743 double r,
double g,
double b,
744 const std::string &layer_id =
"line",
double opacity = 1.0);
755 addLine (
unsigned int x_min,
unsigned int y_min,
unsigned int x_max,
unsigned int y_max,
756 const std::string &layer_id =
"line",
double opacity = 1.0);
769 addText (
unsigned int x,
unsigned int y,
const std::string& text,
770 double r,
double g,
double b,
771 const std::string &layer_id =
"line",
double opacity = 1.0);
781 addText (
unsigned int x,
unsigned int y,
const std::string& text,
782 const std::string &layer_id =
"line",
double opacity = 1.0);
793 template <
typename T>
bool
795 double r,
double g,
double b,
796 const std::string &layer_id =
"image_mask",
double opacity = 0.5);
804 template <
typename T>
bool
806 const std::string &layer_id =
"image_mask",
double opacity = 0.5);
818 template <
typename T>
bool
820 double r,
double g,
double b,
821 const std::string &layer_id =
"planar_polygon",
double opacity = 1.0);
830 template <
typename T>
bool
832 const std::string &layer_id =
"planar_polygon",
double opacity = 1.0);
841 addLayer (
const std::string &layer_id,
int width,
int height,
double opacity = 0.5);
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);
916 MouseCallback (vtkObject*,
unsigned long eid,
void* clientdata,
void *calldata);
930 Execute (vtkObject* vtkNotUsed (caller),
unsigned long event_id,
void* call_data)
override
932 if (event_id != vtkCommand::TimerEvent)
934 int timer_id = *
static_cast<int*
> (call_data);
935 if (timer_id != right_timer_id)
937 window->interactor_->TerminateApp ();
951 Execute (vtkObject*,
unsigned long event_id,
void*)
override
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>;
980 createLayer (
const std::string &layer_id,
int width,
int height,
double opacity = 0.5,
bool fill_box =
true);
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>
void Execute(vtkObject *vtkNotUsed(caller), unsigned long event_id, void *call_data) override
static ImageViewerInteractorStyle * New()
Defines all the PCL and non-PCL macros used.
void setSize(int xw, int yw)
Set the window size in screen coordinates.
void emitKeyboardEvent(unsigned long event_id)
Fire up a keyboard event with a specified event ID.
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 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.
ExitMainLoopTimerCallback()
static ExitCallback * New()
boost::signals2::connection registerMouseCallback(std::function< void(const pcl::visualization::MouseEvent &)> cb)
Register a callback function for mouse events.
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 emitMouseEvent(unsigned long event_id)
Fire up a mouse event with a specified event ID.
void OnMouseWheelForward() override
int * getSize()
Return the window size in pixels.
void adjustCamera(vtkRenderer *ren)
void setInteractorStyle(vtkInteractorObserver *style)
Set up the interactor style.
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.
void removeLayer(const std::string &layer_id)
Remove a 2D layer given by its ID.
void setWindowTitle(const std::string &name)
Set the window title name.
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.
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 close()
Stop the interaction and close the visualizaton window.
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 OnRightButtonDown() override
void OnMouseWheelBackward() override
Eigen::Array< unsigned char, 3, 1 > Vector3ub
shared_ptr< const ImageViewer > ConstPtr
PointCloud represents the base class in PCL for storing collections of 3D points.
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).
ImageViewer(const std::string &window_title="")
Constructor.
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).
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.
static const Vector3ub blue_color(0, 0, 255)
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 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 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).
static void KeyboardCallback(vtkObject *, unsigned long eid, void *clientdata, void *calldata)
An image viewer interactor style, tailored for ImageViewer.
static void MouseCallback(vtkObject *, unsigned long eid, void *clientdata, void *calldata)
void spinOnce(int time=1, bool force_redraw=true)
Spin once method.
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.
shared_ptr< ImageViewer > Ptr
ImageViewer is a class for 2D image visualization.
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 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.
bool wasStopped() const
Returns true when the user tried to close the window.
virtual ~ImageViewer()
Destructor.
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 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 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).
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
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 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...
static const Vector3ub red_color(255, 0, 0)
A 2D point structure representing Euclidean xy coordinates.
void adjustCamera(vtkImageData *image, vtkRenderer *ren)
void resetStoppedFlag()
Set the stopped flag back to false.
void Execute(vtkObject *, unsigned long event_id, void *) override
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 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).
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 OnMiddleButtonDown() override
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 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.
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 setPosition(int x, int y)
Set the position in screen coordinates.
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).
static const Vector3ub green_color(0, 255, 0)
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.
boost::signals2::connection registerKeyboardCallback(std::function< void(const pcl::visualization::KeyboardEvent &)> cb)
Register a callback std::function for keyboard events.
shared_ptr< const PointCloud< PointT > > ConstPtr
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.
ImageViewerInteractorStyle()
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).
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.
PlanarPolygon represents a planar (2D) polygon, potentially in a 3D space.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
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.
boost::signals2::connection registerKeyboardCallback(void(T::*callback)(const pcl::visualization::KeyboardEvent &, void *), T &instance, void *cookie=nullptr)
Register a callback function for keyboard events.
boost::signals2::connection registerKeyboardCallback(void(*callback)(const pcl::visualization::KeyboardEvent &, void *), void *cookie=nullptr)
Register a callback function for keyboard events.
static ExitMainLoopTimerCallback * New()
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 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).
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 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.
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.
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.
Defines functions, macros and traits for allocating and using memory.
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.
void OnLeftButtonDown() override
/brief Class representing key hit/release events
boost::signals2::connection registerMouseCallback(void(T::*callback)(const pcl::visualization::MouseEvent &, void *), T &instance, void *cookie=nullptr)
Register a callback function for mouse events.