9 #pragma warning(disable : 4996)
12 #include <pcl/common/time.h>
13 #include <pcl/visualization/common/float_image_utils.h>
14 #include <pcl/visualization/keyboard_event.h>
15 #include <pcl/visualization/mouse_event.h>
18 #include <vtkCallbackCommand.h>
19 #include <vtkCamera.h>
20 #include <vtkImageSlice.h>
21 #include <vtkImageSliceMapper.h>
22 #include <vtkImageViewer.h>
23 #include <vtkObjectFactory.h>
24 #include <vtkRenderer.h>
25 #include <vtkVersion.h>
43 algo_->SetInterpolationModeToCubic();
44 algo_->PreserveImageExtentOn();
45 algo_->FlipAboutOriginOn();
46 algo_->SetFilteredAxis(1);
59 win_->SetSize(640, 480);
61 win_->SetWindowName(window_title.c_str());
68 map->SetInputData(empty_image);
71 ren_->GetActiveCamera()->ParallelProjectionOn();
94 PCL_DEBUG(
"[pcl::visualization::ImageViewer] VTK version found: %d.%d\n",
95 VTK_MAJOR_VERSION, VTK_MINOR_VERSION);
100 interactor_->DestroyTimer(timer_id_);
107 const std::string& layer_id,
111 (
unsigned(getSize()[0]) !=
width ||
unsigned(getSize()[1]) !=
height))
116 LayerMap::iterator am_it = std::find_if(
118 if (am_it == layer_map_.end()) {
120 "[pcl::visualization::ImageViewer::addRGBImage] No layer with "
121 "ID='%s' found. Creating new one...\n",
123 am_it = createLayer(layer_id,
width,
height, opacity,
false);
126 void*
data =
const_cast<void*
>(
reinterpret_cast<const void*
>(rgb_data));
130 image->AllocateScalars(VTK_UNSIGNED_CHAR, 3);
133 algo_->SetInputData(
image);
135 slice_->GetMapper()->SetInputConnection(algo_->GetOutputPort());
137 ren_->GetActiveCamera()->SetParallelScale(0.5 * win_->GetSize()[1]);
142 const unsigned char* rgb_data,
145 const std::string& layer_id,
147 addRGBImage(rgb_data,
width,
height, layer_id, opacity);
153 const unsigned char* rgb_data,
156 const std::string& layer_id,
158 if (
unsigned(getSize()[0]) !=
width ||
unsigned(getSize()[1]) !=
height)
163 LayerMap::iterator am_it = std::find_if(
165 if (am_it == layer_map_.end()) {
167 "[pcl::visualization::ImageViewer::showMonoImage] No layer "
168 "with ID='%s' found. Creating new one...\n",
170 am_it = createLayer(layer_id,
width,
height, opacity,
false);
173 void*
data =
const_cast<void*
>(
reinterpret_cast<const void*
>(rgb_data));
177 image->AllocateScalars(VTK_UNSIGNED_CHAR, 1);
180 algo_->SetInputData(
image);
182 slice_->GetMapper()->SetInputConnection(algo_->GetOutputPort());
184 ren_->GetActiveCamera()->SetParallelScale(0.5 * win_->GetSize()[1]);
189 const unsigned char* rgb_data,
192 const std::string& layer_id,
194 addMonoImage(rgb_data,
width,
height, layer_id, opacity);
200 const pcl::PointCloud<pcl::Intensity>& cloud,
201 const std::string& layer_id,
203 if (data_size_ < cloud.width * cloud.height) {
204 data_size_ = cloud.width * cloud.height * 3;
205 data_.reset(
new unsigned char[data_size_]);
208 convertIntensityCloudToUChar(cloud, data_);
210 return (addMonoImage(data_.get(), cloud.width, cloud.height, layer_id,
216 const pcl::PointCloud<pcl::Intensity>& cloud,
217 const std::string& layer_id,
219 addMonoImage(cloud, layer_id, opacity);
225 const pcl::PointCloud<pcl::Intensity8u>& cloud,
226 const std::string& layer_id,
228 if (data_size_ < cloud.width * cloud.height) {
229 data_size_ = cloud.width * cloud.height * 3;
230 data_.reset(
new unsigned char[data_size_]);
233 convertIntensityCloud8uToUChar(cloud, data_);
235 return (addMonoImage(data_.get(), cloud.width, cloud.height, layer_id,
241 const pcl::PointCloud<pcl::Intensity8u>& cloud,
242 const std::string& layer_id,
244 addMonoImage(cloud, layer_id, opacity);
255 const std::string& layer_id,
257 unsigned char* rgb_image = FloatImageUtils::getVisualImage(
258 float_image,
width,
height, min_value, max_value, grayscale);
259 addRGBImage(rgb_image,
width,
height, layer_id, opacity);
260 image_data_.push_back(rgb_image);
265 const float* float_image,
271 const std::string& layer_id,
273 addFloatImage(float_image,
width,
height, min_value, max_value, grayscale,
282 const std::string& layer_id,
284 unsigned char* rgb_image =
285 FloatImageUtils::getVisualAngleImage(angle_image,
width,
height);
286 addRGBImage(rgb_image,
width,
height, layer_id, opacity);
287 image_data_.push_back(rgb_image);
292 const float* angle_image,
295 const std::string& layer_id,
297 addAngleImage(angle_image,
width,
height, layer_id, opacity);
303 const float* angle_image,
306 const std::string& layer_id,
308 unsigned char* rgb_image = FloatImageUtils::getVisualHalfAngleImage(
310 addRGBImage(rgb_image,
width,
height, layer_id, opacity);
311 image_data_.push_back(rgb_image);
316 const float* angle_image,
319 const std::string& layer_id,
321 addHalfAngleImage(angle_image,
width,
height, layer_id, opacity);
327 const unsigned short* short_image,
330 unsigned short min_value,
331 unsigned short max_value,
333 const std::string& layer_id,
335 unsigned char* rgb_image = FloatImageUtils::getVisualImage(
336 short_image,
width,
height, min_value, max_value, grayscale);
337 addRGBImage(rgb_image,
width,
height, layer_id, opacity);
338 image_data_.push_back(rgb_image);
343 const unsigned short* short_image,
346 unsigned short min_value,
347 unsigned short max_value,
349 const std::string& layer_id,
351 addShortImage(short_image,
width,
height, min_value, max_value, grayscale,
362 interactor_->Start();
372 if (time <= 0) time = 1;
374 DO_EVERY(1.0 / interactor_->GetDesiredUpdateRate(),
375 exit_main_loop_timer_callback_->right_timer_id =
376 interactor_->CreateRepeatingTimer(time);
377 interactor_->Start(); interactor_->DestroyTimer(
378 exit_main_loop_timer_callback_->right_timer_id););
379 for (
auto& i : image_data_)
delete[] i;
384 boost::signals2::connection
386 std::function<
void(
const pcl::visualization::MouseEvent&)>
callback) {
388 if (mouse_signal_.empty()) {
389 interactor_->GetInteractorStyle()->AddObserver(
390 vtkCommand::MouseMoveEvent, mouse_command_);
391 interactor_->GetInteractorStyle()->AddObserver(
392 vtkCommand::MiddleButtonPressEvent, mouse_command_);
393 interactor_->GetInteractorStyle()->AddObserver(
394 vtkCommand::MiddleButtonReleaseEvent, mouse_command_);
395 interactor_->GetInteractorStyle()->AddObserver(
396 vtkCommand::MouseWheelBackwardEvent, mouse_command_);
397 interactor_->GetInteractorStyle()->AddObserver(
398 vtkCommand::MouseWheelForwardEvent, mouse_command_);
399 interactor_->GetInteractorStyle()->AddObserver(
400 vtkCommand::LeftButtonPressEvent, mouse_command_);
401 interactor_->GetInteractorStyle()->AddObserver(
402 vtkCommand::LeftButtonReleaseEvent, mouse_command_);
403 interactor_->GetInteractorStyle()->AddObserver(
404 vtkCommand::RightButtonPressEvent, mouse_command_);
405 interactor_->GetInteractorStyle()->AddObserver(
406 vtkCommand::RightButtonReleaseEvent, mouse_command_);
408 return (mouse_signal_.connect(
callback));
412 boost::signals2::connection
414 std::function<
void(
const pcl::visualization::KeyboardEvent&)>
417 if (keyboard_signal_.empty()) {
418 interactor_->AddObserver(vtkCommand::KeyPressEvent, keyboard_command_);
419 interactor_->AddObserver(vtkCommand::KeyReleaseEvent,
423 return (keyboard_signal_.connect(
callback));
429 int x = this->interactor_->GetEventPosition()[0];
430 int y = this->interactor_->GetEventPosition()[1];
431 MouseEvent
event(MouseEvent::MouseMove, MouseEvent::NoButton,
x,
y,
432 interactor_->GetAltKey(), interactor_->GetControlKey(),
433 interactor_->GetShiftKey());
436 case vtkCommand::MouseMoveEvent:
437 event.setType(MouseEvent::MouseMove);
440 case vtkCommand::LeftButtonPressEvent:
441 event.setButton(MouseEvent::LeftButton);
442 if (interactor_->GetRepeatCount() == 0)
443 event.setType(MouseEvent::MouseButtonPress);
445 event.setType(MouseEvent::MouseDblClick);
448 case vtkCommand::LeftButtonReleaseEvent:
449 event.setButton(MouseEvent::LeftButton);
450 event.setType(MouseEvent::MouseButtonRelease);
453 case vtkCommand::RightButtonPressEvent:
454 event.setButton(MouseEvent::RightButton);
455 if (interactor_->GetRepeatCount() == 0)
456 event.setType(MouseEvent::MouseButtonPress);
458 event.setType(MouseEvent::MouseDblClick);
461 case vtkCommand::RightButtonReleaseEvent:
462 event.setButton(MouseEvent::RightButton);
463 event.setType(MouseEvent::MouseButtonRelease);
466 case vtkCommand::MiddleButtonPressEvent:
467 event.setButton(MouseEvent::MiddleButton);
468 if (interactor_->GetRepeatCount() == 0)
469 event.setType(MouseEvent::MouseButtonPress);
471 event.setType(MouseEvent::MouseDblClick);
474 case vtkCommand::MiddleButtonReleaseEvent:
475 event.setButton(MouseEvent::MiddleButton);
476 event.setType(MouseEvent::MouseButtonRelease);
479 case vtkCommand::MouseWheelBackwardEvent:
480 event.setButton(MouseEvent::VScroll);
481 event.setType(MouseEvent::MouseScrollDown);
482 if (interactor_->GetRepeatCount() != 0) repeat =
true;
485 case vtkCommand::MouseWheelForwardEvent:
486 event.setButton(MouseEvent::VScroll);
487 event.setType(MouseEvent::MouseScrollUp);
488 if (interactor_->GetRepeatCount() != 0) repeat =
true;
494 mouse_signal_(
event);
495 if (repeat) mouse_signal_(
event);
500 unsigned long event_id) {
501 KeyboardEvent
event(
bool(event_id == vtkCommand::KeyPressEvent),
502 interactor_->GetKeySym(), interactor_->GetKeyCode(),
503 interactor_->GetAltKey(), interactor_->GetControlKey(),
504 interactor_->GetShiftKey());
505 keyboard_signal_(
event);
527 pcl::visualization::ImageViewer::LayerMap::iterator
537 l.
actor->PickableOff();
538 l.
actor->DragableOff();
542 rect->setColors(0, 0, 0);
543 rect->setOpacity(opacity);
544 rect->set(0, 0,
static_cast<float>(
width),
static_cast<float>(
height));
545 l.
actor->GetScene()->AddItem(rect);
547 ren_->AddActor(l.
actor);
549 layer_map_.push_back(l);
551 return (layer_map_.end() - 1);
561 LayerMap::iterator am_it = std::find_if(
563 if (am_it != layer_map_.end()) {
565 "[pcl::visualization::ImageViewer::addLayer] Layer with "
566 "ID='%s' already exists!\n",
571 createLayer(layer_id,
width,
height, opacity,
false);
580 LayerMap::iterator am_it = std::find_if(
582 if (am_it == layer_map_.end()) {
584 "[pcl::visualization::ImageViewer::removeLayer] No layer with "
589 ren_->RemoveActor(am_it->actor);
590 layer_map_.erase(am_it);
600 const std::string& layer_id,
604 LayerMap::iterator am_it = std::find_if(
606 if (am_it == layer_map_.end()) {
608 "[pcl::visualization::ImageViewer::addCircle] No layer with "
609 "ID='%s' found. Creating new one...\n",
611 am_it = createLayer(layer_id, getSize()[0] - 1, getSize()[1] - 1,
617 circle->setColors(
static_cast<unsigned char>(255.0 * r),
618 static_cast<unsigned char>(255.0 * g),
619 static_cast<unsigned char>(255.0 * b));
620 circle->setOpacity(opacity);
621 circle->set(
static_cast<float>(
x),
static_cast<float>(
y),
622 static_cast<float>(radius));
623 am_it->actor->GetScene()->AddItem(circle);
632 const std::string& layer_id,
634 return (addCircle(
x,
y, radius, 0.0, 1.0, 0.0, layer_id, opacity));
646 const std::string& layer_id,
650 LayerMap::iterator am_it = std::find_if(
652 if (am_it == layer_map_.end()) {
654 "[pcl::visualization::ImageViewer::addFilledRectangle] No "
655 "layer with ID='%s' found. Creating new one...\n",
657 am_it = createLayer(layer_id, getSize()[0] - 1, getSize()[1] - 1,
663 rect->setColors(
static_cast<unsigned char>(255.0 * r),
664 static_cast<unsigned char>(255.0 * g),
665 static_cast<unsigned char>(255.0 * b));
666 rect->setOpacity(opacity);
667 rect->set(
static_cast<float>(x_min),
static_cast<float>(y_min),
668 static_cast<float>(x_max - x_min),
669 static_cast<float>(y_max - y_min));
670 am_it->actor->GetScene()->AddItem(rect);
681 const std::string& layer_id,
683 return (addFilledRectangle(x_min, x_max, y_min, y_max, 0.0, 1.0, 0.0,
695 const std::string& layer_id,
699 LayerMap::iterator am_it = std::find_if(
701 if (am_it == layer_map_.end()) {
703 "[pcl::visualization::ImageViewer::addRectangle] No layer with "
704 "ID='%s' found. Creating new one...\n",
706 am_it = createLayer(layer_id, getSize()[0] - 1, getSize()[1] - 1,
712 rect->setColors(
static_cast<unsigned char>(255.0 * r),
713 static_cast<unsigned char>(255.0 * g),
714 static_cast<unsigned char>(255.0 * b));
715 rect->setOpacity(opacity);
716 rect->set(
static_cast<float>(x_min),
static_cast<float>(y_min),
717 static_cast<float>(x_max),
static_cast<float>(y_max));
718 am_it->actor->GetScene()->AddItem(rect);
728 const std::string& layer_id,
730 return (addRectangle(x_min, x_max, y_min, y_max, 0.0, 1.0, 0.0, layer_id,
736 const pcl::PointXY& max_pt,
740 const std::string& layer_id,
744 LayerMap::iterator am_it = std::find_if(
746 if (am_it == layer_map_.end()) {
748 "[pcl::visualization::ImageViewer::addRectangle] No layer with "
749 "ID='%s' found. Creating new one...\n",
751 am_it = createLayer(layer_id, getSize()[0] - 1, getSize()[1] - 1,
757 rect->setColors(
static_cast<unsigned char>(255.0 * r),
758 static_cast<unsigned char>(255.0 * g),
759 static_cast<unsigned char>(255.0 * b));
760 rect->setOpacity(opacity);
761 rect->set(min_pt.x, min_pt.y, max_pt.x, max_pt.y);
762 am_it->actor->GetScene()->AddItem(rect);
769 const pcl::PointXY& max_pt,
770 const std::string& layer_id,
772 return (addRectangle(min_pt, max_pt, 0.0, 1.0, 0.0, layer_id, opacity));
783 const std::string& layer_id,
787 LayerMap::iterator am_it = std::find_if(
789 if (am_it == layer_map_.end()) {
791 "[pcl::visualization::ImageViewer::addLine] No layer with "
792 "ID='%s' found. Creating new one...\n",
794 am_it = createLayer(layer_id, getSize()[0] - 1, getSize()[1] - 1,
800 line->setColors(
static_cast<unsigned char>(255.0 * r),
801 static_cast<unsigned char>(255.0 * g),
802 static_cast<unsigned char>(255.0 * b));
803 line->setOpacity(opacity);
804 line->set(
static_cast<float>(x_min),
static_cast<float>(y_min),
805 static_cast<float>(x_max),
static_cast<float>(y_max));
806 am_it->actor->GetScene()->AddItem(line);
816 const std::string& layer_id,
818 return (addLine(x_min, y_min, x_max, y_max, 0.0, 1.0, 0.0, layer_id,
825 const std::string& text_string,
829 const std::string& layer_id,
833 LayerMap::iterator am_it = std::find_if(
835 if (am_it == layer_map_.end()) {
837 "[pcl::visualization::ImageViewer::addText] No layer with "
838 "ID='%s' found. Creating new one...\n",
840 am_it = createLayer(layer_id, getSize()[0] - 1, getSize()[1] - 1,
846 text->setColors(
static_cast<unsigned char>(255.0 * r),
847 static_cast<unsigned char>(255.0 * g),
848 static_cast<unsigned char>(255.0 * b));
849 text->setOpacity(opacity);
850 text->set(
static_cast<float>(
x),
static_cast<float>(
y), text_string);
851 am_it->actor->GetScene()->AddItem(text);
859 const std::string& text,
860 const std::string& layer_id,
862 return (addText(
x,
y, text, 0.0, 1.0, 0.0, layer_id, opacity));
871 const std::string& layer_id,
875 LayerMap::iterator am_it = std::find_if(
877 if (am_it == layer_map_.end()) {
879 "[pcl::visualization::ImageViewer::markPoint] No layer with "
880 "ID='%s' found. Creating new one...\n",
882 am_it = createLayer(layer_id, getSize()[0] - 1, getSize()[1] - 1,
888 point->setColors(fg_color[0], fg_color[1], fg_color[2]);
889 point->setOpacity(opacity);
893 disk->setColors(bg_color[0], bg_color[1], bg_color[2]);
894 disk->setOpacity(opacity);
896 point->set(
static_cast<float>(u),
static_cast<float>(v));
897 disk->set(
static_cast<float>(u),
static_cast<float>(v),
898 static_cast<float>(radius));
900 am_it->actor->GetScene()->AddItem(disk);
901 am_it->actor->GetScene()->AddItem(point);
909 const std::string& layer_id,
911 if (
uv.empty())
return;
913 std::vector<float> float_uv(
uv.size());
914 for (std::size_t i = 0; i <
uv.size(); ++i)
915 float_uv[i] =
static_cast<float>(
uv[i]);
916 return (markPoints(float_uv, fg_color, bg_color,
size, layer_id, opacity));
924 const std::string& layer_id,
926 if (
uv.empty())
return;
930 LayerMap::iterator am_it = std::find_if(
932 if (am_it == layer_map_.end()) {
934 "[pcl::visualization::ImageViewer::markPoint] No layer with "
935 "ID='%s' found. Creating new one...\n",
937 am_it = createLayer(layer_id, getSize()[0] - 1, getSize()[1] - 1,
943 markers->setOpacity(opacity);
945 markers->setSize(
size);
946 markers->setColors(bg_color[0], bg_color[1], bg_color[2]);
947 markers->setPointColors(fg_color[0], fg_color[1], fg_color[2]);
948 am_it->actor->GetScene()->AddItem(markers);
954 for (
auto& i : image_data_)
delete[] i;
960 const pcl::PointCloud<pcl::Intensity>& cloud,
961 boost::shared_array<unsigned char>
data) {
963 for (
const auto& point : cloud.points) {
964 data[j++] =
static_cast<unsigned char>(point.intensity * 255);
970 const pcl::PointCloud<pcl::Intensity8u>& cloud,
971 boost::shared_array<unsigned char>
data) {
973 for (
const auto& point : cloud.points)
974 data[j++] =
static_cast<unsigned char>(point.intensity);
984 FindPokedRenderer(Interactor->GetEventPosition()[0],
985 Interactor->GetEventPosition()[1]);
987 Superclass::OnChar();
992 vtkImageData*
image, vtkRenderer* ren) {
994 double origin[3], spacing[3];
997 image->GetSpacing(spacing);
998 image->GetExtent(extent);
1000 vtkCamera* camera = ren->GetActiveCamera();
1001 double xc =
origin[0] + 0.5 * (extent[0] + extent[1]) * spacing[0];
1002 double yc =
origin[1] + 0.5 * (extent[2] + extent[3]) * spacing[1];
1003 double yd = (extent[3] - extent[2] + 1) * spacing[1];
1004 double d = camera->GetDistance();
1005 camera->SetParallelScale(0.5 * yd);
1006 camera->SetFocalPoint(xc, yc, 0.0);
1007 camera->SetPosition(xc, yc, d);
1014 vtkCamera* camera = ren->GetActiveCamera();
1015 int* wh = ren->GetRenderWindow()->GetSize();
1016 double xc =
static_cast<double>(wh[0]) / 2.0,
1017 yc =
static_cast<double>(wh[1]) / 2.0,
1018 yd =
static_cast<double>(wh[1]), d = 3.346065;
1019 camera->SetParallelScale(0.5 * yd);
1020 camera->SetFocalPoint(xc, yc, 0.0);
1021 camera->SetPosition(xc, yc, d);
1026 int x = Interactor->GetEventPosition()[0];
1027 int y = Interactor->GetEventPosition()[1];
1029 FindPokedRenderer(
x,
y);
1030 if (!CurrentRenderer)
return;
1033 GrabFocus(this->EventCallbackCommand);
1035 if (!this->Interactor->GetShiftKey() &&
1036 !this->Interactor->GetControlKey()) {
1037 WindowLevelStartPosition[0] =
x;
1038 WindowLevelStartPosition[1] =
y;
1040 }
else if (Interactor->GetShiftKey())
1043 else if (Interactor->GetControlKey())
1047 Superclass::OnLeftButtonDown();
1052 win_->SetWindowName(
name.c_str());
1057 win_->SetPosition(
x,
y);
1065 win_->SetSize(xw, yw);
1070 namespace visualization {
std::shared_ptr< core::Tensor > image
std::function< void(std::shared_ptr< core::Tensor >)> callback
An image viewer interactor style, tailored for ImageViewer.
ImageViewerInteractorStyle()
void OnLeftButtonDown() override
void adjustCamera(vtkImageData *image, vtkRenderer *ren)
ImageViewer is a class for 2D image visualization.
vtkSmartPointer< vtkRenderWindow > win_
The render window.
void setWindowTitle(const std::string &name)
Set the window title name.
static void MouseCallback(vtkObject *, unsigned long eid, void *clientdata, void *calldata)
bool addRectangle(const pcl::PointXY &min_pt, const pcl::PointXY &max_pt, const std::string &layer_id="rectangles", double opacity=1.0)
Add a 2D box and color its edges with a given color.
vtkSmartPointer< vtkCallbackCommand > keyboard_command_
void resetStoppedFlag()
Set the stopped flag back to false.
virtual ~ImageViewer()
Destructor.
int * getSize()
Return the window size in pixels.
void showAngleImage(const float *data, unsigned width, unsigned height, const std::string &layer_id="angle_image", double opacity=1.0)
Show a 2D image on screen representing angle data.
boost::signals2::connection registerMouseCallback(void(*callback)(const pcl::visualization::MouseEvent &, void *), void *cookie=nullptr)
Register a callback std::function for mouse events.
void showRGBImage(const unsigned char *data, unsigned width, unsigned height, const std::string &layer_id="rgb_image", double opacity=1.0)
Show a 2D RGB image on screen.
void convertIntensityCloudToUChar(const pcl::PointCloud< pcl::Intensity > &cloud, boost::shared_array< unsigned char > data)
Convert the Intensity information in a PointCloud<Intensity> to an unsigned char array.
bool addFilledRectangle(unsigned int x_min, unsigned int x_max, unsigned int y_min, unsigned int y_max, const std::string &layer_id="boxes", double opacity=0.5)
Add a 2D box and fill it in with a given color.
void spinOnce(int time=1, bool force_redraw=true)
Spin once method. Calls the interactor and updates the screen once.
bool addLayer(const std::string &layer_id, int width, int height, double opacity=0.5)
Add a new 2D rendering layer to the viewer.
void removeLayer(const std::string &layer_id)
Remove a 2D layer given by its ID.
void addHalfAngleImage(const float *data, unsigned width, unsigned height, const std::string &layer_id="half_angle_image", double opacity=1.0)
Add a half angle 2D image layer, but do not render it (use spin/spinOnce to update).
boost::signals2::connection registerKeyboardCallback(void(*callback)(const pcl::visualization::KeyboardEvent &, void *), void *cookie=nullptr)
Register a callback function for keyboard events.
vtkSmartPointer< vtkImageSlice > slice_
Global prop. This is the actual "actor".
bool addText(unsigned int x, unsigned int y, const std::string &text, double r, double g, double b, const std::string &layer_id="line", double opacity=1.0)
Add a 2D text with a given color.
void addMonoImage(const unsigned char *data, unsigned width, unsigned height, 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).
void showFloatImage(const float *data, unsigned int width, unsigned int height, float min_value=std::numeric_limits< float >::min(), float max_value=std::numeric_limits< float >::max(), bool grayscale=false, const std::string &layer_id="float_image", double opacity=1.0)
Show a 2D image (float) on screen.
void spin()
Spin method. Calls the interactor and runs an internal loop.
void markPoints(const std::vector< int > &uv, Vector3ub fg_color, Vector3ub bg_color=red_color, double size=3.0, const std::string &layer_id="markers", double opacity=1.0)
Sets the pixel at coordinates(u,v) to color while setting the neighborhood to another.
void showHalfAngleImage(const float *data, unsigned width, unsigned height, const std::string &layer_id="half_angle_image", double opacity=1.0)
Show a 2D image on screen representing half angle data.
bool addLine(unsigned int x_min, unsigned int y_min, unsigned int x_max, unsigned int y_max, double r, double g, double b, const std::string &layer_id="line", double opacity=1.0)
Add a 2D line with a given color.
void showShortImage(const unsigned short *short_image, unsigned int width, unsigned int height, unsigned short min_value=std::numeric_limits< unsigned short >::min(), unsigned short max_value=std::numeric_limits< unsigned short >::max(), bool grayscale=false, const std::string &layer_id="short_image", double opacity=1.0)
Show a 2D image (unsigned short) on screen.
void emitMouseEvent(unsigned long event_id)
Fire up a mouse event with a specified event ID.
void addShortImage(const unsigned short *short_image, unsigned int width, unsigned int height, unsigned short min_value=std::numeric_limits< unsigned short >::min(), unsigned short max_value=std::numeric_limits< unsigned short >::max(), bool grayscale=false, const std::string &layer_id="short_image", double opacity=1.0)
Add a short 2D image layer, but do not render it (use spin/spinOnce to update).
vtkSmartPointer< vtkRenderer > ren_
The renderer.
vtkSmartPointer< ExitMainLoopTimerCallback > exit_main_loop_timer_callback_
Callback object enabling us to leave the main loop, when a timer fires.
void showMonoImage(const unsigned char *data, unsigned width, unsigned height, const std::string &layer_id="mono_image", double opacity=1.0)
Show a monochrome 2D image on screen.
void emitKeyboardEvent(unsigned long event_id)
Fire up a keyboard event with a specified event ID.
ImageViewer(const std::string &window_title="")
Constructor.
void setSize(int xw, int yw)
Set the window size in screen coordinates.
vtkSmartPointer< vtkRenderWindowInteractor > interactor_
void addFloatImage(const float *data, unsigned int width, unsigned int height, float min_value=std::numeric_limits< float >::min(), float max_value=std::numeric_limits< float >::max(), bool grayscale=false, const std::string &layer_id="float_image", double opacity=1.0)
Add a float 2D image layer, but do not render it (use spin/spinOnce to update).
static void KeyboardCallback(vtkObject *, unsigned long eid, void *clientdata, void *calldata)
void setPosition(int x, int y)
Set the position in screen coordinates.
void markPoint(std::size_t u, std::size_t v, Vector3ub fg_color, Vector3ub bg_color=red_color, double radius=3.0, const std::string &layer_id="points", double opacity=1.0)
Sets the pixel at coordinates(u,v) to color while setting the neighborhood to another.
vtkSmartPointer< ImageViewerInteractorStyle > interactor_style_
The interactor style.
void addAngleImage(const float *data, unsigned width, unsigned height, const std::string &layer_id="angle_image", double opacity=1.0)
Add an angle 2D image layer, but do not render it (use spin/spinOnce to update).
vtkSmartPointer< vtkCallbackCommand > mouse_command_
vtkSmartPointer< ExitCallback > exit_callback_
void render()
Trigger a render call.
void convertIntensityCloud8uToUChar(const pcl::PointCloud< pcl::Intensity8u > &cloud, boost::shared_array< unsigned char > data)
Convert the Intensity8u information in a PointCloud<Intensity8u> to an unsigned char array.
LayerMap::iterator createLayer(const std::string &layer_id, int width, int height, double opacity=0.5, bool fill_box=true)
Add a new 2D rendering layer to the viewer.
bool addCircle(unsigned int x, unsigned int y, double radius, const std::string &layer_id="circles", double opacity=1.0)
Add a circle shape from a point and a radius.
void addRGBImage(const unsigned char *data, unsigned width, unsigned height, const std::string &layer_id="rgb_image", double opacity=1.0, bool autoresize=true)
Add an RGB 2D image layer, but do not render it (use spin/spinOnce to update).
vtkSmartPointer< vtkImageFlip > algo_
Image reslice, used for flipping the image.
Eigen::Array< unsigned char, 3, 1 > Vector3ub
vtkStandardNewMacro(ImageViewerInteractorStyle)
Internal structure describing a layer.
vtkSmartPointer< vtkContextActor > actor
vtkRenderWindowInteractor * vtkRenderWindowInteractorFixNew()