38 #ifndef PCL_VISUALIZATION_IMAGE_VISUALIZER_H__
39 #define PCL_VISUALIZATION_IMAGE_VISUALIZER_H__
41 #include <boost/shared_array.hpp>
44 #include <boost/signals2.hpp>
52 namespace visualization
54 typedef Eigen::Array<unsigned char, 3, 1>
Vector3ub;
55 static const Vector3ub green_color (0, 255, 0);
56 static const Vector3ub red_color (255, 0, 0);
57 static const Vector3ub blue_color (0, 0, 255);
99 showMonoImage (
const unsigned char* data,
unsigned width,
unsigned height,
100 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
110 addMonoImage (
const unsigned char* data,
unsigned width,
unsigned height,
111 const std::string &layer_id =
"mono_image",
double opacity = 1.0);
121 showRGBImage (
const unsigned char* data,
unsigned width,
unsigned height,
122 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
132 addRGBImage (
const unsigned char* data,
unsigned width,
unsigned height,
133 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
140 template <
typename T>
inline void
142 const std::string &layer_id =
"rgb_image",
double opacity = 1.0)
144 return (showRGBImage<T> (*cloud, layer_id, opacity));
152 template <
typename T>
inline void
154 const std::string &layer_id =
"rgb_image",
double opacity = 1.0)
156 return (addRGBImage<T> (*cloud, layer_id, opacity));
164 template <
typename T>
void
166 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
173 template <
typename T>
void
175 const std::string &layer_id =
"rgb_image",
double opacity = 1.0);
188 showFloatImage (
const float* data,
unsigned int width,
unsigned int height,
189 float min_value = std::numeric_limits<float>::min (),
190 float max_value = std::numeric_limits<float>::max (),
bool grayscale =
false,
191 const std::string &layer_id =
"float_image",
double opacity = 1.0);
204 addFloatImage (
const float* data,
unsigned int width,
unsigned int height,
205 float min_value = std::numeric_limits<float>::min (),
206 float max_value = std::numeric_limits<float>::max (),
bool grayscale =
false,
207 const std::string &layer_id =
"float_image",
double opacity = 1.0);
220 showShortImage (
const unsigned short* short_image,
unsigned int width,
unsigned int height,
221 unsigned short min_value = std::numeric_limits<unsigned short>::min (),
222 unsigned short max_value = std::numeric_limits<unsigned short>::max (),
bool grayscale =
false,
223 const std::string &layer_id =
"short_image",
double opacity = 1.0);
236 addShortImage (
const unsigned short* short_image,
unsigned int width,
unsigned int height,
237 unsigned short min_value = std::numeric_limits<unsigned short>::min (),
238 unsigned short max_value = std::numeric_limits<unsigned short>::max (),
bool grayscale =
false,
239 const std::string &layer_id =
"short_image",
double opacity = 1.0);
249 showAngleImage (
const float* data,
unsigned width,
unsigned height,
250 const std::string &layer_id =
"angle_image",
double opacity = 1.0);
260 addAngleImage (
const float* data,
unsigned width,
unsigned height,
261 const std::string &layer_id =
"angle_image",
double opacity = 1.0);
271 showHalfAngleImage (
const float* data,
unsigned width,
unsigned height,
272 const std::string &layer_id =
"half_angle_image",
double opacity = 1.0);
282 addHalfAngleImage (
const float* data,
unsigned width,
unsigned height,
283 const std::string &layer_id =
"half_angle_image",
double opacity = 1.0);
295 markPoint (
size_t u,
size_t v,
Vector3ub fg_color,
Vector3ub bg_color = red_color,
double radius = 3.0,
296 const std::string &layer_id =
"points",
double opacity = 1.0);
302 setWindowTitle (
const std::string& name)
304 image_viewer_->GetRenderWindow ()->SetWindowName (name.c_str ());
317 spinOnce (
int time = 1,
bool force_redraw =
true);
324 boost::signals2::connection
328 return (registerKeyboardCallback (boost::bind (callback, _1, cookie)));
337 template<
typename T> boost::signals2::connection
339 T& instance,
void* cookie = NULL)
341 return (registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
348 boost::signals2::connection
356 boost::signals2::connection
360 return (registerMouseCallback (boost::bind (callback, _1, cookie)));
369 template<
typename T> boost::signals2::connection
371 T& instance,
void* cookie = NULL)
373 return (registerMouseCallback (boost::bind (callback, boost::ref (instance), _1, cookie)));
380 boost::signals2::connection
388 setPosition (
int x,
int y)
390 image_viewer_->SetPosition (x, y);
398 setSize (
int xw,
int yw)
400 image_viewer_->SetSize (xw, yw);
405 wasStopped ()
const {
if (image_viewer_)
return (stopped_);
else return (
true); }
415 addCircle (
unsigned int x,
unsigned int y,
double radius,
416 const std::string &layer_id =
"circles",
double opacity = 1.0);
429 addCircle (
unsigned int x,
unsigned int y,
double radius,
430 double r,
double g,
double b,
431 const std::string &layer_id =
"circles",
double opacity = 1.0);
441 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
454 double r,
double g,
double b,
455 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
466 addRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
467 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
481 addRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
482 double r,
double g,
double b,
483 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
492 template <
typename T>
bool
494 const T &min_pt,
const T &max_pt,
495 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
507 template <
typename T>
bool
509 const T &min_pt,
const T &max_pt,
510 double r,
double g,
double b,
511 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
522 template <
typename T>
bool
524 double r,
double g,
double b,
525 const std::string &layer_id =
"rectangles",
double opacity = 1.0);
533 template <
typename T>
bool
535 const std::string &layer_id =
"image_mask",
double opacity = 1.0);
546 addFilledRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
547 const std::string &layer_id =
"boxes",
double opacity = 0.5);
561 addFilledRectangle (
unsigned int x_min,
unsigned int x_max,
unsigned int y_min,
unsigned int y_max,
562 double r,
double g,
double b,
563 const std::string &layer_id =
"boxes",
double opacity = 0.5);
577 addLine (
unsigned int x_min,
unsigned int y_min,
unsigned int x_max,
unsigned int y_max,
578 double r,
double g,
double b,
579 const std::string &layer_id =
"line",
double opacity = 1.0);
590 addLine (
unsigned int x_min,
unsigned int y_min,
unsigned int x_max,
unsigned int y_max,
591 const std::string &layer_id =
"line",
double opacity = 1.0);
603 template <
typename T>
bool
605 double r,
double g,
double b,
606 const std::string &layer_id =
"image_mask",
double opacity = 0.5);
614 template <
typename T>
bool
616 const std::string &layer_id =
"image_mask",
double opacity = 0.5);
628 template <
typename T>
bool
630 double r,
double g,
double b,
631 const std::string &layer_id =
"planar_polygon",
double opacity = 1.0);
640 template <
typename T>
bool
642 const std::string &layer_id =
"planar_polygon",
double opacity = 1.0);
651 addLayer (
const std::string &layer_id,
int width,
int height,
double opacity = 0.5);
657 removeLayer (
const std::string &layer_id);
661 resetStoppedFlag () {
if (image_viewer_) stopped_ =
false; }
667 emitMouseEvent (
unsigned long event_id);
673 emitKeyboardEvent (
unsigned long event_id);
677 MouseCallback (vtkObject*,
unsigned long eid,
void* clientdata,
void *calldata);
679 KeyboardCallback (vtkObject*,
unsigned long eid,
void* clientdata,
void *calldata);
682 struct ExitMainLoopTimerCallback :
public vtkCommand
684 ExitMainLoopTimerCallback () : right_timer_id (), window () {}
686 static ExitMainLoopTimerCallback* New ()
688 return (
new ExitMainLoopTimerCallback);
691 Execute (vtkObject* vtkNotUsed (caller),
unsigned long event_id,
void* call_data)
693 if (event_id != vtkCommand::TimerEvent)
695 int timer_id = *
static_cast<int*
> (call_data);
696 if (timer_id != right_timer_id)
698 window->interactor_->TerminateApp ();
703 struct ExitCallback :
public vtkCommand
705 ExitCallback () : window () {}
707 static ExitCallback* New ()
709 return (
new ExitCallback);
712 Execute (vtkObject*,
unsigned long event_id,
void*)
714 if (event_id != vtkCommand::ExitEvent)
716 window->stopped_ =
true;
717 window->interactor_->TerminateApp ();
727 Layer () : canvas (), layer_name (), opacity () {}
728 vtkSmartPointer<PCLImageCanvasSource2D> canvas;
729 std::string layer_name;
733 typedef std::vector<Layer> LayerMap;
743 createLayer (
const std::string &layer_id,
int width,
int height,
double opacity = 0.5,
bool fill_box =
true);
745 boost::signals2::signal<void (const pcl::visualization::MouseEvent&)> mouse_signal_;
746 boost::signals2::signal<void (const pcl::visualization::KeyboardEvent&)> keyboard_signal_;
748 vtkSmartPointer<vtkRenderWindowInteractor> interactor_;
749 vtkSmartPointer<vtkCallbackCommand> mouse_command_;
750 vtkSmartPointer<vtkCallbackCommand> keyboard_command_;
753 vtkSmartPointer<ExitMainLoopTimerCallback> exit_main_loop_timer_callback_;
754 vtkSmartPointer<ExitCallback> exit_callback_;
757 vtkSmartPointer<vtkImageViewer> image_viewer_;
760 boost::shared_array<unsigned char> data_;
772 vtkSmartPointer<vtkImageBlend> blend_;
777 struct LayerComparator
779 LayerComparator (
const std::string &str) : str_ (str) {}
780 const std::string &str_;
783 operator () (
const Layer &layer)
785 return (layer.layer_name == str_);
790 EIGEN_MAKE_ALIGNED_OPERATOR_NEW