43 #include <pcl/console/print.h>
44 #include <pcl/visualization/interactor_style.h>
45 #include <pcl/visualization/vtk/pcl_image_canvas_source_2d.h>
46 #include <pcl/visualization/vtk/pcl_context_item.h>
47 #include <pcl/geometry/planar_polygon.h>
48 #include <pcl/correspondence.h>
50 #include <boost/shared_array.hpp>
52 #include <vtkVersion.h>
53 #include <vtkInteractorStyleImage.h>
54 #include <vtkRenderWindowInteractor.h>
57 class vtkContextActor;
63 namespace visualization
65 using Vector3ub = Eigen::Array<unsigned char, 3, 1>;
84 void OnLeftButtonDown ()
override;
90 adjustCamera (vtkImageData *image, vtkRenderer *ren);
93 adjustCamera (vtkRenderer *ren);
126 ImageViewer (
const std::string& window_title =
"");
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);
267 addRGBImage (
const unsigned char* data,
unsigned width,
unsigned height,
268 const std::string &layer_id =
"rgb_image",
double opacity = 1.0,
269 bool autoresize =
true);
276 template <
typename T>
inline void
278 const std::string &layer_id =
"rgb_image",
double opacity = 1.0)
280 return (showRGBImage<T> (*cloud, layer_id, opacity));
288 template <
typename T>
inline void
290 const std::string &layer_id =
"rgb_image",
double opacity = 1.0)
292 return (addRGBImage<T> (*cloud, layer_id, opacity));
300 template <
typename T>
void
302 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
309 template <
typename T>
void
311 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
324 showFloatImage (
const float* data,
unsigned int width,
unsigned int height,
325 float min_value = std::numeric_limits<float>::min (),
326 float max_value = std::numeric_limits<float>::max (),
bool grayscale =
false,
327 const std::string &layer_id =
"float_image",
double opacity = 1.0);
340 addFloatImage (
const float* data,
unsigned int width,
unsigned int height,
341 float min_value = std::numeric_limits<float>::min (),
342 float max_value = std::numeric_limits<float>::max (),
bool grayscale =
false,
343 const std::string &layer_id =
"float_image",
double opacity = 1.0);
356 showShortImage (
const unsigned short* short_image,
unsigned int width,
unsigned int height,
357 unsigned short min_value = std::numeric_limits<unsigned short>::min (),
358 unsigned short max_value = std::numeric_limits<unsigned short>::max (),
bool grayscale =
false,
359 const std::string &layer_id =
"short_image",
double opacity = 1.0);
372 addShortImage (
const unsigned short* short_image,
unsigned int width,
unsigned int height,
373 unsigned short min_value = std::numeric_limits<unsigned short>::min (),
374 unsigned short max_value = std::numeric_limits<unsigned short>::max (),
bool grayscale =
false,
375 const std::string &layer_id =
"short_image",
double opacity = 1.0);
385 showAngleImage (
const float* data,
unsigned width,
unsigned height,
386 const std::string &layer_id =
"angle_image",
double opacity = 1.0);
396 addAngleImage (
const float* data,
unsigned width,
unsigned height,
397 const std::string &layer_id =
"angle_image",
double opacity = 1.0);
407 showHalfAngleImage (
const float* data,
unsigned width,
unsigned height,
408 const std::string &layer_id =
"half_angle_image",
double opacity = 1.0);
418 addHalfAngleImage (
const float* data,
unsigned width,
unsigned height,
419 const std::string &layer_id =
"half_angle_image",
double opacity = 1.0);
432 const std::string &layer_id =
"points",
double opacity = 1.0);
444 const std::string &layer_id =
"markers",
double opacity = 1.0);
456 const std::string &layer_id =
"markers",
double opacity = 1.0);
462 setWindowTitle (
const std::string& name);
474 spinOnce (
int time = 1,
bool force_redraw =
true);
481 boost::signals2::connection
483 void* cookie =
nullptr)
494 template<
typename T> boost::signals2::connection
496 T& instance,
void* cookie =
nullptr)
505 boost::signals2::connection
513 boost::signals2::connection
515 void* cookie =
nullptr)
526 template<
typename T> boost::signals2::connection
528 T& instance,
void* cookie =
nullptr)
537 boost::signals2::connection
545 setPosition (
int x,
int y);
552 setSize (
int xw,
int yw);
568 interactor_->TerminateApp ();
579 addCircle (
unsigned int x,
unsigned int y,
double radius,
580 const std::string &layer_id =
"circles",
double opacity = 1.0);
593 addCircle (
unsigned int x,
unsigned int y,
double radius,
594 double r,
double g,
double b,
595 const std::string &layer_id =
"circles",
double opacity = 1.0);
605 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
618 double r,
double g,
double b,
619 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
630 addRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
631 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
645 addRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
646 double r,
double g,
double b,
647 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
656 template <
typename T>
bool
658 const T &min_pt,
const T &max_pt,
659 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
671 template <
typename T>
bool
673 const T &min_pt,
const T &max_pt,
674 double r,
double g,
double b,
675 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
686 template <
typename T>
bool
688 double r,
double g,
double b,
689 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
697 template <
typename T>
bool
699 const std::string &layer_id =
"image_mask",
double opacity = 1.0);
710 addFilledRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
711 const std::string &layer_id =
"boxes",
double opacity = 0.5);
725 addFilledRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
726 double r,
double g,
double b,
727 const std::string &layer_id =
"boxes",
double opacity = 0.5);
741 addLine (
unsigned int x_min,
unsigned int y_min,
unsigned int x_max,
unsigned int y_max,
742 double r,
double g,
double b,
743 const std::string &layer_id =
"line",
double opacity = 1.0);
754 addLine (
unsigned int x_min,
unsigned int y_min,
unsigned int x_max,
unsigned int y_max,
755 const std::string &layer_id =
"line",
double opacity = 1.0);
768 addText (
unsigned int x,
unsigned int y,
const std::string& text,
769 double r,
double g,
double b,
770 const std::string &layer_id =
"line",
double opacity = 1.0);
780 addText (
unsigned int x,
unsigned int y,
const std::string& text,
781 const std::string &layer_id =
"line",
double opacity = 1.0);
792 template <
typename T>
bool
794 double r,
double g,
double b,
795 const std::string &layer_id =
"image_mask",
double opacity = 0.5);
803 template <
typename T>
bool
805 const std::string &layer_id =
"image_mask",
double opacity = 0.5);
817 template <
typename T>
bool
819 double r,
double g,
double b,
820 const std::string &layer_id =
"planar_polygon",
double opacity = 1.0);
829 template <
typename T>
bool
831 const std::string &layer_id =
"planar_polygon",
double opacity = 1.0);
840 addLayer (
const std::string &layer_id,
int width,
int height,
double opacity = 0.5);
846 removeLayer (
const std::string &layer_id);
855 template <
typename Po
intT>
bool
860 const std::string &layer_id =
"correspondences");
875 boost::shared_array<unsigned char> data);
885 boost::shared_array<unsigned char> data);
893 template <
typename T>
void
895 boost::shared_array<unsigned char> &data);
905 emitMouseEvent (
unsigned long event_id);
911 emitKeyboardEvent (
unsigned long event_id);
915 MouseCallback (vtkObject*,
unsigned long eid,
void* clientdata,
void *calldata);
917 KeyboardCallback (vtkObject*,
unsigned long eid,
void* clientdata,
void *calldata);
929 Execute (vtkObject* vtkNotUsed (caller),
unsigned long event_id,
void* call_data)
override
931 if (event_id != vtkCommand::TimerEvent)
933 int timer_id = *
static_cast<int*
> (call_data);
934 if (timer_id != right_timer_id)
936 window->interactor_->TerminateApp ();
950 Execute (vtkObject*,
unsigned long event_id,
void*)
override
952 if (event_id != vtkCommand::ExitEvent)
954 window->stopped_ =
true;
955 window->interactor_->TerminateApp ();
966 std::string layer_name;
969 using LayerMap = std::vector<Layer>;
979 createLayer (
const std::string &layer_id,
int width,
int height,
double opacity = 0.5,
bool fill_box =
true);
1008 boost::shared_array<unsigned char> data_;
1011 std::size_t data_size_;
1023 LayerMap layer_map_;
1031 std::vector<unsigned char*> image_data_;
1033 struct LayerComparator
1035 LayerComparator (
const std::string &str) : str_ (str) {}
1036 const std::string &str_;
1039 operator () (
const Layer &layer)
1041 return (layer.layer_name == str_);
1051 #include <pcl/visualization/impl/image_viewer.hpp>