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>;
85 void OnLeftButtonDown ()
override;
91 adjustCamera (vtkImageData *image, vtkRenderer *ren);
94 adjustCamera (vtkRenderer *ren);
121 using Ptr = shared_ptr<ImageViewer>;
127 ImageViewer (
const std::string& window_title =
"");
139 interactor_->SetInteractorStyle (style);
150 showMonoImage (
const unsigned char* data,
unsigned width,
unsigned height,
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);
325 showFloatImage (
const float* data,
unsigned int width,
unsigned int height,
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);
341 addFloatImage (
const float* data,
unsigned int width,
unsigned int height,
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);
386 showAngleImage (
const float* data,
unsigned width,
unsigned height,
387 const std::string &layer_id =
"angle_image",
double opacity = 1.0);
397 addAngleImage (
const float* data,
unsigned width,
unsigned height,
398 const std::string &layer_id =
"angle_image",
double opacity = 1.0);
408 showHalfAngleImage (
const float* data,
unsigned width,
unsigned height,
409 const std::string &layer_id =
"half_angle_image",
double opacity = 1.0);
419 addHalfAngleImage (
const float* data,
unsigned width,
unsigned height,
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);
463 setWindowTitle (
const std::string& name);
475 spinOnce (
int time = 1,
bool force_redraw =
true);
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
546 setPosition (
int x,
int y);
553 setSize (
int xw,
int yw);
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);
711 addFilledRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
712 const std::string &layer_id =
"boxes",
double opacity = 0.5);
726 addFilledRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
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);
847 removeLayer (
const std::string &layer_id);
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);
906 emitMouseEvent (
unsigned long event_id);
912 emitKeyboardEvent (
unsigned long event_id);
916 MouseCallback (vtkObject*,
unsigned long eid,
void* clientdata,
void *calldata);
918 KeyboardCallback (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);
982 boost::signals2::signal<void (const pcl::visualization::MouseEvent&)> mouse_signal_;
983 boost::signals2::signal<void (const pcl::visualization::KeyboardEvent&)> keyboard_signal_;
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 resetStoppedFlag()
Set the stopped flag back to false.
boost::signals2::connection registerKeyboardCallback(void(*callback)(const pcl::visualization::KeyboardEvent &, void *), void *cookie=nullptr)
Register a callback function for keyboard events.
Defines functions, macros and traits for allocating and using memory.
void close()
Stop the interaction and close the visualizaton window.
boost::signals2::connection registerMouseCallback(void(*callback)(const pcl::visualization::MouseEvent &, void *), void *cookie=nullptr)
Register a callback std::function for mouse events.
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).
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.
ImageViewer is a class for 2D image visualization.
bool wasStopped() const
Returns true when the user tried to close the window.
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.
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
void Execute(vtkObject *, unsigned long event_id, void *) override
A 2D point structure representing Euclidean xy coordinates.
An image viewer interactor style, tailored for ImageViewer.
shared_ptr< ImageViewer > Ptr
Defines all the PCL implemented PointT point type structures.
static const Vector3ub blue_color(0, 0, 255)
void OnMiddleButtonDown() override
PlanarPolygon represents a planar (2D) polygon, potentially in a 3D space.
void OnMouseWheelForward() override
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.
PointCloud represents the base class in PCL for storing collections of 3D points. ...
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).
shared_ptr< const PointCloud< PointT > > ConstPtr
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 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 ExitMainLoopTimerCallback * New()
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
static ExitCallback * New()
/brief Class representing key hit/release events
void Execute(vtkObject *vtkNotUsed(caller), unsigned long event_id, void *call_data) override
static const Vector3ub red_color(255, 0, 0)
boost::signals2::connection registerKeyboardCallback(void(T::*callback)(const pcl::visualization::KeyboardEvent &, void *), T &instance, void *cookie=nullptr)
Register a callback function for keyboard events.
void OnRightButtonDown() override
ExitMainLoopTimerCallback()
void OnMouseWheelBackward() override
Defines all the PCL and non-PCL macros used.
shared_ptr< const ImageViewer > ConstPtr
static const Vector3ub green_color(0, 255, 0)
Eigen::Array< unsigned char, 3, 1 > Vector3ub