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 =
"");
138 showMonoImage (
const unsigned char* data,
unsigned width,
unsigned height,
139 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
149 addMonoImage (
const unsigned char* data,
unsigned width,
unsigned height,
150 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
159 const std::string &layer_id =
"mono_image",
double opacity = 1.0)
161 return (showMonoImage (*cloud, layer_id, opacity));
171 const std::string &layer_id =
"mono_image",
double opacity = 1.0)
173 return (addMonoImage (*cloud, layer_id, opacity));
183 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
192 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
201 const std::string &layer_id =
"mono_image",
double opacity = 1.0)
203 return (showMonoImage (*cloud, layer_id, opacity));
213 const std::string &layer_id =
"mono_image",
double opacity = 1.0)
215 return (addMonoImage (*cloud, layer_id, opacity));
225 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
234 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
244 showRGBImage (
const unsigned char* data,
unsigned width,
unsigned height,
245 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
255 addRGBImage (
const unsigned char* data,
unsigned width,
unsigned height,
256 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
263 template <
typename T>
inline void
265 const std::string &layer_id =
"rgb_image",
double opacity = 1.0)
267 return (showRGBImage<T> (*cloud, layer_id, opacity));
275 template <
typename T>
inline void
277 const std::string &layer_id =
"rgb_image",
double opacity = 1.0)
279 return (addRGBImage<T> (*cloud, layer_id, opacity));
287 template <
typename T>
void
289 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
296 template <
typename T>
void
298 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
311 showFloatImage (
const float* data,
unsigned int width,
unsigned int height,
312 float min_value = std::numeric_limits<float>::min (),
313 float max_value = std::numeric_limits<float>::max (),
bool grayscale =
false,
314 const std::string &layer_id =
"float_image",
double opacity = 1.0);
327 addFloatImage (
const float* data,
unsigned int width,
unsigned int height,
328 float min_value = std::numeric_limits<float>::min (),
329 float max_value = std::numeric_limits<float>::max (),
bool grayscale =
false,
330 const std::string &layer_id =
"float_image",
double opacity = 1.0);
343 showShortImage (
const unsigned short* short_image,
unsigned int width,
unsigned int height,
344 unsigned short min_value = std::numeric_limits<unsigned short>::min (),
345 unsigned short max_value = std::numeric_limits<unsigned short>::max (),
bool grayscale =
false,
346 const std::string &layer_id =
"short_image",
double opacity = 1.0);
359 addShortImage (
const unsigned short* short_image,
unsigned int width,
unsigned int height,
360 unsigned short min_value = std::numeric_limits<unsigned short>::min (),
361 unsigned short max_value = std::numeric_limits<unsigned short>::max (),
bool grayscale =
false,
362 const std::string &layer_id =
"short_image",
double opacity = 1.0);
372 showAngleImage (
const float* data,
unsigned width,
unsigned height,
373 const std::string &layer_id =
"angle_image",
double opacity = 1.0);
383 addAngleImage (
const float* data,
unsigned width,
unsigned height,
384 const std::string &layer_id =
"angle_image",
double opacity = 1.0);
394 showHalfAngleImage (
const float* data,
unsigned width,
unsigned height,
395 const std::string &layer_id =
"half_angle_image",
double opacity = 1.0);
405 addHalfAngleImage (
const float* data,
unsigned width,
unsigned height,
406 const std::string &layer_id =
"half_angle_image",
double opacity = 1.0);
419 const std::string &layer_id =
"points",
double opacity = 1.0);
425 setWindowTitle (
const std::string& name);
437 spinOnce (
int time = 1,
bool force_redraw =
true);
444 boost::signals2::connection
448 return (registerKeyboardCallback (boost::bind (callback, _1, cookie)));
457 template<
typename T> boost::signals2::connection
459 T& instance,
void* cookie = NULL)
461 return (registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
468 boost::signals2::connection
476 boost::signals2::connection
480 return (registerMouseCallback (boost::bind (callback, _1, cookie)));
489 template<
typename T> boost::signals2::connection
491 T& instance,
void* cookie = NULL)
493 return (registerMouseCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
500 boost::signals2::connection
508 setPosition (
int x,
int y);
515 setSize (
int xw,
int yw);
531 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
532 interactor_->stopLoop ();
534 interactor_->TerminateApp ();
546 addCircle (
unsigned int x,
unsigned int y,
double radius,
547 const std::string &layer_id =
"circles",
double opacity = 1.0);
560 addCircle (
unsigned int x,
unsigned int y,
double radius,
561 double r,
double g,
double b,
562 const std::string &layer_id =
"circles",
double opacity = 1.0);
572 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
585 double r,
double g,
double b,
586 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
597 addRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
598 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
612 addRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
613 double r,
double g,
double b,
614 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
623 template <
typename T>
bool
625 const T &min_pt,
const T &max_pt,
626 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
638 template <
typename T>
bool
640 const T &min_pt,
const T &max_pt,
641 double r,
double g,
double b,
642 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
653 template <
typename T>
bool
655 double r,
double g,
double b,
656 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
664 template <
typename T>
bool
666 const std::string &layer_id =
"image_mask",
double opacity = 1.0);
677 addFilledRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
678 const std::string &layer_id =
"boxes",
double opacity = 0.5);
692 addFilledRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
693 double r,
double g,
double b,
694 const std::string &layer_id =
"boxes",
double opacity = 0.5);
708 addLine (
unsigned int x_min,
unsigned int y_min,
unsigned int x_max,
unsigned int y_max,
709 double r,
double g,
double b,
710 const std::string &layer_id =
"line",
double opacity = 1.0);
721 addLine (
unsigned int x_min,
unsigned int y_min,
unsigned int x_max,
unsigned int y_max,
722 const std::string &layer_id =
"line",
double opacity = 1.0);
734 template <
typename T>
bool
736 double r,
double g,
double b,
737 const std::string &layer_id =
"image_mask",
double opacity = 0.5);
745 template <
typename T>
bool
747 const std::string &layer_id =
"image_mask",
double opacity = 0.5);
759 template <
typename T>
bool
761 double r,
double g,
double b,
762 const std::string &layer_id =
"planar_polygon",
double opacity = 1.0);
771 template <
typename T>
bool
773 const std::string &layer_id =
"planar_polygon",
double opacity = 1.0);
782 addLayer (
const std::string &layer_id,
int width,
int height,
double opacity = 0.5);
788 removeLayer (
const std::string &layer_id);
797 template <
typename Po
intT>
bool
802 const std::string &layer_id =
"correspondences");
817 boost::shared_array<unsigned char> data);
827 boost::shared_array<unsigned char> data);
835 template <
typename T>
void
837 boost::shared_array<unsigned char> &data);
847 emitMouseEvent (
unsigned long event_id);
853 emitKeyboardEvent (
unsigned long event_id);
857 MouseCallback (vtkObject*,
unsigned long eid,
void* clientdata,
void *calldata);
859 KeyboardCallback (vtkObject*,
unsigned long eid,
void* clientdata,
void *calldata);
871 Execute (vtkObject* vtkNotUsed (caller),
unsigned long event_id,
void* call_data)
873 if (event_id != vtkCommand::TimerEvent)
875 int timer_id = *
static_cast<int*
> (call_data);
876 if (timer_id != right_timer_id)
878 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
879 window->interactor_->stopLoop ();
881 window->interactor_->TerminateApp ();
896 Execute (vtkObject*,
unsigned long event_id,
void*)
898 if (event_id != vtkCommand::ExitEvent)
900 window->stopped_ =
true;
901 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
902 window->interactor_->stopLoop ();
904 window->interactor_->TerminateApp ();
914 Layer () : actor (), layer_name () {}
916 std::string layer_name;
919 typedef std::vector<Layer> LayerMap;
929 createLayer (
const std::string &layer_id,
int width,
int height,
double opacity = 0.5,
bool fill_box =
true);
931 boost::signals2::signal<void (const pcl::visualization::MouseEvent&)> mouse_signal_;
932 boost::signals2::signal<void (const pcl::visualization::KeyboardEvent&)> keyboard_signal_;
934 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
955 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 10))
963 boost::shared_array<unsigned char> data_;
986 std::vector<unsigned char*> image_data_;
988 struct LayerComparator
990 LayerComparator (
const std::string &str) : str_ (str) {}
991 const std::string &str_;
994 operator () (
const Layer &layer)
996 return (layer.layer_name == str_);
1001 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
1006 #include <pcl/visualization/impl/image_viewer.hpp>