39 #ifndef PCL_VISUALIZATION_IMAGE_VISUALIZER_H__
40 #define PCL_VISUALIZATION_IMAGE_VISUALIZER_H__
42 #include <pcl/pcl_macros.h>
43 #include <pcl/point_types.h>
44 #include <pcl/console/print.h>
45 #include <pcl/visualization/interactor.h>
46 #include <pcl/visualization/interactor_style.h>
47 #include <pcl/visualization/vtk/pcl_image_canvas_source_2d.h>
48 #include <pcl/visualization/vtk/pcl_context_item.h>
49 #include <pcl/geometry/planar_polygon.h>
50 #include <pcl/correspondence.h>
52 #include <boost/shared_array.hpp>
54 #include <vtkVersion.h>
55 #include <vtkInteractorStyleImage.h>
58 class vtkContextActor;
64 namespace visualization
66 typedef Eigen::Array<unsigned char, 3, 1>
Vector3ub;
68 static const Vector3ub
red_color (255, 0, 0);
85 virtual void OnLeftButtonDown ();
91 adjustCamera (vtkImageData *image, vtkRenderer *ren);
94 adjustCamera (vtkRenderer *ren);
121 typedef boost::shared_ptr<ImageViewer>
Ptr;
126 ImageViewer (
const std::string& window_title =
"");
131 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION > 4)))
137 setInteractorStyle (vtkInteractorObserver *style)
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);
267 addRGBImage (
const unsigned char* data,
unsigned width,
unsigned height,
268 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
275 template <
typename T>
inline void
277 const std::string &layer_id =
"rgb_image",
double opacity = 1.0)
279 return (showRGBImage<T> (*cloud, layer_id, opacity));
287 template <
typename T>
inline void
289 const std::string &layer_id =
"rgb_image",
double opacity = 1.0)
291 return (addRGBImage<T> (*cloud, layer_id, opacity));
299 template <
typename T>
void
301 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
308 template <
typename T>
void
310 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
323 showFloatImage (
const float* data,
unsigned int width,
unsigned int height,
324 float min_value = std::numeric_limits<float>::min (),
325 float max_value = std::numeric_limits<float>::max (),
bool grayscale =
false,
326 const std::string &layer_id =
"float_image",
double opacity = 1.0);
339 addFloatImage (
const float* data,
unsigned int width,
unsigned int height,
340 float min_value = std::numeric_limits<float>::min (),
341 float max_value = std::numeric_limits<float>::max (),
bool grayscale =
false,
342 const std::string &layer_id =
"float_image",
double opacity = 1.0);
355 showShortImage (
const unsigned short* short_image,
unsigned int width,
unsigned int height,
356 unsigned short min_value = std::numeric_limits<unsigned short>::min (),
357 unsigned short max_value = std::numeric_limits<unsigned short>::max (),
bool grayscale =
false,
358 const std::string &layer_id =
"short_image",
double opacity = 1.0);
371 addShortImage (
const unsigned short* short_image,
unsigned int width,
unsigned int height,
372 unsigned short min_value = std::numeric_limits<unsigned short>::min (),
373 unsigned short max_value = std::numeric_limits<unsigned short>::max (),
bool grayscale =
false,
374 const std::string &layer_id =
"short_image",
double opacity = 1.0);
384 showAngleImage (
const float* data,
unsigned width,
unsigned height,
385 const std::string &layer_id =
"angle_image",
double opacity = 1.0);
395 addAngleImage (
const float* data,
unsigned width,
unsigned height,
396 const std::string &layer_id =
"angle_image",
double opacity = 1.0);
406 showHalfAngleImage (
const float* data,
unsigned width,
unsigned height,
407 const std::string &layer_id =
"half_angle_image",
double opacity = 1.0);
417 addHalfAngleImage (
const float* data,
unsigned width,
unsigned height,
418 const std::string &layer_id =
"half_angle_image",
double opacity = 1.0);
430 markPoint (
size_t u,
size_t v, Vector3ub fg_color, Vector3ub bg_color =
red_color,
double radius = 3.0,
431 const std::string &layer_id =
"points",
double opacity = 1.0);
442 markPoints (
const std::vector<int>& uv, Vector3ub fg_color, Vector3ub bg_color =
red_color,
double size = 3.0,
443 const std::string &layer_id =
"markers",
double opacity = 1.0);
454 markPoints (
const std::vector<float>& uv, Vector3ub fg_color, Vector3ub bg_color =
red_color,
double size = 3.0,
455 const std::string &layer_id =
"markers",
double opacity = 1.0);
461 setWindowTitle (
const std::string& name);
473 spinOnce (
int time = 1,
bool force_redraw =
true);
480 boost::signals2::connection
484 return (registerKeyboardCallback (boost::bind (callback, _1, cookie)));
493 template<
typename T> boost::signals2::connection
495 T& instance,
void* cookie = NULL)
497 return (registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
504 boost::signals2::connection
512 boost::signals2::connection
516 return (registerMouseCallback (boost::bind (callback, _1, cookie)));
525 template<
typename T> boost::signals2::connection
527 T& instance,
void* cookie = NULL)
529 return (registerMouseCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
536 boost::signals2::connection
544 setPosition (
int x,
int y);
551 setSize (
int xw,
int yw);
567 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
568 interactor_->stopLoop ();
570 interactor_->TerminateApp ();
582 addCircle (
unsigned int x,
unsigned int y,
double radius,
583 const std::string &layer_id =
"circles",
double opacity = 1.0);
596 addCircle (
unsigned int x,
unsigned int y,
double radius,
597 double r,
double g,
double b,
598 const std::string &layer_id =
"circles",
double opacity = 1.0);
608 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
621 double r,
double g,
double b,
622 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
633 addRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
634 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
648 addRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
649 double r,
double g,
double b,
650 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
659 template <
typename T>
bool
661 const T &min_pt,
const T &max_pt,
662 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
674 template <
typename T>
bool
676 const T &min_pt,
const T &max_pt,
677 double r,
double g,
double b,
678 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
689 template <
typename T>
bool
691 double r,
double g,
double b,
692 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
700 template <
typename T>
bool
702 const std::string &layer_id =
"image_mask",
double opacity = 1.0);
713 addFilledRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
714 const std::string &layer_id =
"boxes",
double opacity = 0.5);
728 addFilledRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
729 double r,
double g,
double b,
730 const std::string &layer_id =
"boxes",
double opacity = 0.5);
744 addLine (
unsigned int x_min,
unsigned int y_min,
unsigned int x_max,
unsigned int y_max,
745 double r,
double g,
double b,
746 const std::string &layer_id =
"line",
double opacity = 1.0);
757 addLine (
unsigned int x_min,
unsigned int y_min,
unsigned int x_max,
unsigned int y_max,
758 const std::string &layer_id =
"line",
double opacity = 1.0);
771 addText (
unsigned int x,
unsigned int y,
const std::string& text,
772 double r,
double g,
double b,
773 const std::string &layer_id =
"line",
double opacity = 1.0);
783 addText (
unsigned int x,
unsigned int y,
const std::string& text,
784 const std::string &layer_id =
"line",
double opacity = 1.0);
795 template <
typename T>
bool
797 double r,
double g,
double b,
798 const std::string &layer_id =
"image_mask",
double opacity = 0.5);
806 template <
typename T>
bool
808 const std::string &layer_id =
"image_mask",
double opacity = 0.5);
820 template <
typename T>
bool
822 double r,
double g,
double b,
823 const std::string &layer_id =
"planar_polygon",
double opacity = 1.0);
832 template <
typename T>
bool
834 const std::string &layer_id =
"planar_polygon",
double opacity = 1.0);
843 addLayer (
const std::string &layer_id,
int width,
int height,
double opacity = 0.5);
849 removeLayer (
const std::string &layer_id);
858 template <
typename Po
intT>
bool
863 const std::string &layer_id =
"correspondences");
878 boost::shared_array<unsigned char> data);
888 boost::shared_array<unsigned char> data);
896 template <
typename T>
void
898 boost::shared_array<unsigned char> &data);
908 emitMouseEvent (
unsigned long event_id);
914 emitKeyboardEvent (
unsigned long event_id);
918 MouseCallback (vtkObject*,
unsigned long eid,
void* clientdata,
void *calldata);
920 KeyboardCallback (vtkObject*,
unsigned long eid,
void* clientdata,
void *calldata);
932 Execute (vtkObject* vtkNotUsed (caller),
unsigned long event_id,
void* call_data)
934 if (event_id != vtkCommand::TimerEvent)
936 int timer_id = *
static_cast<int*
> (call_data);
937 if (timer_id != right_timer_id)
939 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
940 window->interactor_->stopLoop ();
942 window->interactor_->TerminateApp ();
957 Execute (vtkObject*,
unsigned long event_id,
void*)
959 if (event_id != vtkCommand::ExitEvent)
961 window->stopped_ =
true;
962 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
963 window->interactor_->stopLoop ();
965 window->interactor_->TerminateApp ();
975 Layer () : actor (), layer_name () {}
977 std::string layer_name;
980 typedef std::vector<Layer> LayerMap;
990 createLayer (
const std::string &layer_id,
int width,
int height,
double opacity = 0.5,
bool fill_box =
true);
992 boost::signals2::signal<void (const pcl::visualization::MouseEvent&)> mouse_signal_;
993 boost::signals2::signal<void (const pcl::visualization::KeyboardEvent&)> keyboard_signal_;
995 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
1016 #if !((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 10))
1024 boost::shared_array<unsigned char> data_;
1039 LayerMap layer_map_;
1047 std::vector<unsigned char*> image_data_;
1049 struct LayerComparator
1051 LayerComparator (
const std::string &str) : str_ (str) {}
1052 const std::string &str_;
1055 operator () (
const Layer &layer)
1057 return (layer.layer_name == str_);
1062 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
1067 #include <pcl/visualization/impl/image_viewer.hpp>
void resetStoppedFlag()
Set the stopped flag back to false.
void close()
Stop the interaction and close the visualizaton window.
boost::shared_ptr< ImageViewer > Ptr
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).
virtual void Execute(vtkObject *vtkNotUsed(caller), unsigned long event_id, void *call_data)
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.
This file defines compatibility wrappers for low level I/O functions.
ImageViewer is a class for 2D image visualization.
virtual void Execute(vtkObject *, unsigned long event_id, void *)
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 registerMouseCallback(void(T::*callback)(const pcl::visualization::MouseEvent &, void *), T &instance, void *cookie=NULL)
Register a callback function for mouse events.
bool wasStopped() const
Returns true when the user tried to close the window.
A 2D point structure representing Euclidean xy coordinates.
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
An image viewer interactor style, tailored for ImageViewer.
virtual void OnMouseWheelBackward()
boost::signals2::connection registerMouseCallback(void(*callback)(const pcl::visualization::MouseEvent &, void *), void *cookie=NULL)
Register a callback boost::function for mouse events.
boost::signals2::connection registerKeyboardCallback(void(*callback)(const pcl::visualization::KeyboardEvent &, void *), void *cookie=NULL)
Register a callback function for keyboard events.
static const Vector3ub blue_color(0, 0, 255)
virtual void OnMouseWheelForward()
PlanarPolygon represents a planar (2D) polygon, potentially in a 3D space.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
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. ...
Eigen::Array< unsigned char, 3, 1 > Vector3ub
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).
boost::signals2::connection registerKeyboardCallback(void(T::*callback)(const pcl::visualization::KeyboardEvent &, void *), T &instance, void *cookie=NULL)
Register a callback function for keyboard 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()
static ExitCallback * New()
virtual void OnRightButtonDown()
/brief Class representing key hit/release events
static const Vector3ub red_color(255, 0, 0)
ExitMainLoopTimerCallback()
virtual void OnMiddleButtonDown()
static const Vector3ub green_color(0, 255, 0)