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 <vtkInteractorStyleImage.h>
57 class vtkContextActor;
63 namespace visualization
65 typedef Eigen::Array<unsigned char, 3, 1>
Vector3ub;
84 virtual void OnLeftButtonDown ();
90 adjustCamera (vtkImageData *image, vtkRenderer *ren);
93 adjustCamera (vtkRenderer *ren);
120 typedef boost::shared_ptr<ImageViewer>
Ptr;
125 ImageViewer (
const std::string& window_title =
"");
130 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION > 4)))
136 setInteractorStyle (vtkInteractorObserver *style)
138 interactor_->SetInteractorStyle (style);
149 showMonoImage (
const unsigned char* data,
unsigned width,
unsigned height,
150 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
160 addMonoImage (
const unsigned char* data,
unsigned width,
unsigned height,
161 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
170 const std::string &layer_id =
"mono_image",
double opacity = 1.0)
172 return (showMonoImage (*cloud, layer_id, opacity));
182 const std::string &layer_id =
"mono_image",
double opacity = 1.0)
184 return (addMonoImage (*cloud, layer_id, opacity));
194 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
203 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
212 const std::string &layer_id =
"mono_image",
double opacity = 1.0)
214 return (showMonoImage (*cloud, layer_id, opacity));
224 const std::string &layer_id =
"mono_image",
double opacity = 1.0)
226 return (addMonoImage (*cloud, layer_id, opacity));
236 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
245 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
255 showRGBImage (
const unsigned char* data,
unsigned width,
unsigned height,
256 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
266 addRGBImage (
const unsigned char* data,
unsigned width,
unsigned height,
267 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
274 template <
typename T>
inline void
276 const std::string &layer_id =
"rgb_image",
double opacity = 1.0)
278 return (showRGBImage<T> (*cloud, layer_id, opacity));
286 template <
typename T>
inline void
288 const std::string &layer_id =
"rgb_image",
double opacity = 1.0)
290 return (addRGBImage<T> (*cloud, layer_id, opacity));
298 template <
typename T>
void
300 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
307 template <
typename T>
void
309 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
322 showFloatImage (
const float* data,
unsigned int width,
unsigned int height,
323 float min_value = std::numeric_limits<float>::min (),
324 float max_value = std::numeric_limits<float>::max (),
bool grayscale =
false,
325 const std::string &layer_id =
"float_image",
double opacity = 1.0);
338 addFloatImage (
const float* data,
unsigned int width,
unsigned int height,
339 float min_value = std::numeric_limits<float>::min (),
340 float max_value = std::numeric_limits<float>::max (),
bool grayscale =
false,
341 const std::string &layer_id =
"float_image",
double opacity = 1.0);
354 showShortImage (
const unsigned short* short_image,
unsigned int width,
unsigned int height,
355 unsigned short min_value = std::numeric_limits<unsigned short>::min (),
356 unsigned short max_value = std::numeric_limits<unsigned short>::max (),
bool grayscale =
false,
357 const std::string &layer_id =
"short_image",
double opacity = 1.0);
370 addShortImage (
const unsigned short* short_image,
unsigned int width,
unsigned int height,
371 unsigned short min_value = std::numeric_limits<unsigned short>::min (),
372 unsigned short max_value = std::numeric_limits<unsigned short>::max (),
bool grayscale =
false,
373 const std::string &layer_id =
"short_image",
double opacity = 1.0);
383 showAngleImage (
const float* data,
unsigned width,
unsigned height,
384 const std::string &layer_id =
"angle_image",
double opacity = 1.0);
394 addAngleImage (
const float* data,
unsigned width,
unsigned height,
395 const std::string &layer_id =
"angle_image",
double opacity = 1.0);
405 showHalfAngleImage (
const float* data,
unsigned width,
unsigned height,
406 const std::string &layer_id =
"half_angle_image",
double opacity = 1.0);
416 addHalfAngleImage (
const float* data,
unsigned width,
unsigned height,
417 const std::string &layer_id =
"half_angle_image",
double opacity = 1.0);
430 const std::string &layer_id =
"points",
double opacity = 1.0);
436 setWindowTitle (
const std::string& name);
448 spinOnce (
int time = 1,
bool force_redraw =
true);
455 boost::signals2::connection
459 return (registerKeyboardCallback (boost::bind (callback, _1, cookie)));
468 template<
typename T> boost::signals2::connection
470 T& instance,
void* cookie = NULL)
472 return (registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
479 boost::signals2::connection
487 boost::signals2::connection
491 return (registerMouseCallback (boost::bind (callback, _1, cookie)));
500 template<
typename T> boost::signals2::connection
502 T& instance,
void* cookie = NULL)
504 return (registerMouseCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
511 boost::signals2::connection
519 setPosition (
int x,
int y);
526 setSize (
int xw,
int yw);
542 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
543 interactor_->stopLoop ();
545 interactor_->TerminateApp ();
557 addCircle (
unsigned int x,
unsigned int y,
double radius,
558 const std::string &layer_id =
"circles",
double opacity = 1.0);
571 addCircle (
unsigned int x,
unsigned int y,
double radius,
572 double r,
double g,
double b,
573 const std::string &layer_id =
"circles",
double opacity = 1.0);
583 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
596 double r,
double g,
double b,
597 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
608 addRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
609 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
623 addRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
624 double r,
double g,
double b,
625 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
634 template <
typename T>
bool
636 const T &min_pt,
const T &max_pt,
637 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
649 template <
typename T>
bool
651 const T &min_pt,
const T &max_pt,
652 double r,
double g,
double b,
653 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
664 template <
typename T>
bool
666 double r,
double g,
double b,
667 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
675 template <
typename T>
bool
677 const std::string &layer_id =
"image_mask",
double opacity = 1.0);
688 addFilledRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
689 const std::string &layer_id =
"boxes",
double opacity = 0.5);
703 addFilledRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
704 double r,
double g,
double b,
705 const std::string &layer_id =
"boxes",
double opacity = 0.5);
719 addLine (
unsigned int x_min,
unsigned int y_min,
unsigned int x_max,
unsigned int y_max,
720 double r,
double g,
double b,
721 const std::string &layer_id =
"line",
double opacity = 1.0);
732 addLine (
unsigned int x_min,
unsigned int y_min,
unsigned int x_max,
unsigned int y_max,
733 const std::string &layer_id =
"line",
double opacity = 1.0);
746 addText (
unsigned int x,
unsigned int y,
const std::string& text,
747 double r,
double g,
double b,
748 const std::string &layer_id =
"line",
double opacity = 1.0);
758 addText (
unsigned int x,
unsigned int y,
const std::string& text,
759 const std::string &layer_id =
"line",
double opacity = 1.0);
770 template <
typename T>
bool
772 double r,
double g,
double b,
773 const std::string &layer_id =
"image_mask",
double opacity = 0.5);
781 template <
typename T>
bool
783 const std::string &layer_id =
"image_mask",
double opacity = 0.5);
795 template <
typename T>
bool
797 double r,
double g,
double b,
798 const std::string &layer_id =
"planar_polygon",
double opacity = 1.0);
807 template <
typename T>
bool
809 const std::string &layer_id =
"planar_polygon",
double opacity = 1.0);
818 addLayer (
const std::string &layer_id,
int width,
int height,
double opacity = 0.5);
824 removeLayer (
const std::string &layer_id);
833 template <
typename Po
intT>
bool
838 const std::string &layer_id =
"correspondences");
853 boost::shared_array<unsigned char> data);
863 boost::shared_array<unsigned char> data);
871 template <
typename T>
void
873 boost::shared_array<unsigned char> &data);
883 emitMouseEvent (
unsigned long event_id);
889 emitKeyboardEvent (
unsigned long event_id);
893 MouseCallback (vtkObject*,
unsigned long eid,
void* clientdata,
void *calldata);
895 KeyboardCallback (vtkObject*,
unsigned long eid,
void* clientdata,
void *calldata);
907 Execute (vtkObject* vtkNotUsed (caller),
unsigned long event_id,
void* call_data)
909 if (event_id != vtkCommand::TimerEvent)
911 int timer_id = *
static_cast<int*
> (call_data);
912 if (timer_id != right_timer_id)
914 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
915 window->interactor_->stopLoop ();
917 window->interactor_->TerminateApp ();
932 Execute (vtkObject*,
unsigned long event_id,
void*)
934 if (event_id != vtkCommand::ExitEvent)
936 window->stopped_ =
true;
937 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
938 window->interactor_->stopLoop ();
940 window->interactor_->TerminateApp ();
950 Layer () : actor (), layer_name () {}
952 std::string layer_name;
955 typedef std::vector<Layer> LayerMap;
965 createLayer (
const std::string &layer_id,
int width,
int height,
double opacity = 0.5,
bool fill_box =
true);
967 boost::signals2::signal<void (const pcl::visualization::MouseEvent&)> mouse_signal_;
968 boost::signals2::signal<void (const pcl::visualization::KeyboardEvent&)> keyboard_signal_;
970 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
991 #if (((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 10)) || (VTK_MAJOR_VERSION > 5))
999 boost::shared_array<unsigned char> data_;
1014 LayerMap layer_map_;
1022 std::vector<unsigned char*> image_data_;
1024 struct LayerComparator
1026 LayerComparator (
const std::string &str) : str_ (str) {}
1027 const std::string &str_;
1030 operator () (
const Layer &layer)
1032 return (layer.layer_name == str_);
1037 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
1042 #include <pcl/visualization/impl/image_viewer.hpp>
virtual void OnMouseWheelForward()
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
virtual void OnMiddleButtonDown()
boost::signals2::connection registerKeyboardCallback(void(*callback)(const pcl::visualization::KeyboardEvent &, void *), void *cookie=NULL)
Register a callback function for keyboard events.
PlanarPolygon represents a planar (2D) polygon, potentially in a 3D space.
boost::signals2::connection registerKeyboardCallback(void(T::*callback)(const pcl::visualization::KeyboardEvent &, void *), T &instance, void *cookie=NULL)
Register a callback function for keyboard events.
ImageViewer is a class for 2D image visualization.
static const Vector3ub blue_color(0, 0, 255)
A 2D point structure representing Euclidean xy coordinates.
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
boost::signals2::connection registerMouseCallback(void(*callback)(const pcl::visualization::MouseEvent &, void *), void *cookie=NULL)
Register a callback boost::function for mouse events.
static const Vector3ub green_color(0, 255, 0)
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).
virtual void Execute(vtkObject *vtkNotUsed(caller), unsigned long event_id, void *call_data)
boost::signals2::connection registerMouseCallback(void(T::*callback)(const pcl::visualization::MouseEvent &, void *), T &instance, void *cookie=NULL)
Register a callback function for mouse events.
/brief Class representing key hit/release events
boost::shared_ptr< ImageViewer > Ptr
virtual void Execute(vtkObject *, unsigned long event_id, void *)
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 OnMouseWheelBackward()
bool wasStopped() const
Returns true when the user tried to close the window.
void resetStoppedFlag()
Set the stopped flag back to false.
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.
ExitMainLoopTimerCallback()
virtual void OnRightButtonDown()
An image viewer interactor style, tailored for ImageViewer.
static const Vector3ub red_color(255, 0, 0)
static ExitCallback * New()
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).
static ExitMainLoopTimerCallback * New()
PointCloud represents the base class in PCL for storing collections of 3D points. ...
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 close()
Stop the interaction and close the visualizaton window.
Eigen::Array< unsigned char, 3, 1 > Vector3ub
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.