9 #pragma warning(disable : 4996)
21 #include <pcl/visualization/common/io.h>
22 #include <vtkAbstractPicker.h>
23 #include <vtkAbstractPropPicker.h>
24 #include <vtkActorCollection.h>
25 #include <vtkAreaPicker.h>
26 #include <vtkAssemblyPath.h>
27 #include <vtkCamera.h>
28 #include <vtkCellArray.h>
29 #include <vtkCollection.h>
30 #include <vtkCollectionIterator.h>
31 #include <vtkLODActor.h>
32 #include <vtkLegendScaleActor.h>
34 #include <vtkLightCollection.h>
35 #include <vtkObjectFactory.h>
36 #include <vtkPNGWriter.h>
37 #include <vtkPointData.h>
38 #include <vtkPointPicker.h>
39 #include <vtkPolyData.h>
40 #include <vtkPolyDataMapper.h>
41 #include <vtkProperty.h>
42 #include <vtkRenderWindow.h>
43 #include <vtkRenderWindowInteractor.h>
44 #include <vtkRenderer.h>
45 #include <vtkRendererCollection.h>
46 #include <vtkScalarBarActor.h>
47 #include <vtkTextProperty.h>
48 #include <vtkVersion.h>
49 #include <vtkWindowToImageFilter.h>
53 #if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
54 #include <pcl/visualization/vtk/vtkVertexBufferObjectMapper.h>
60 #define VTKISRBP_ORIENT 0
61 #define VTKISRBP_SELECT 1
65 :
pcl::visualization::PCLVisualizerInteractorStyle(),
66 CameraManipulators(vtkCollection::New()),
67 CurrentManipulator(nullptr),
92 FindPokedRenderer(Interactor->GetEventPosition()[0],
93 Interactor->GetEventPosition()[1]);
96 double factor = 10.0 * 0.2 * .5;
97 Dolly(pow(1.1, factor));
103 FindPokedRenderer(Interactor->GetEventPosition()[0],
104 Interactor->GetEventPosition()[1]);
107 double factor = 10.0 * -0.2 * .5;
108 Dolly(pow(1.1, factor));
116 point_picker_ =
static_cast<vtkPointPicker*
>(Interactor->GetPicker());
120 Interactor->SetPicker(area_picker);
123 Interactor->SetPicker(point_picker_);
131 FindPokedRenderer(Interactor->GetEventPosition()[0],
132 Interactor->GetEventPosition()[1]);
133 if (Interactor->GetKeyCode() >=
'0' && Interactor->GetKeyCode() <=
'9')
135 std::string key(Interactor->GetKeySym());
136 if (key.find(
"XF86ZoomIn") != std::string::npos)
138 else if (key.find(
"XF86ZoomOut") != std::string::npos)
143 case pcl::visualization::INTERACTOR_KB_MOD_ALT: {
144 keymod = Interactor->GetAltKey();
147 case pcl::visualization::InteractorKeyboardModifier::
148 INTERACTOR_KB_MOD_CTRL: {
149 keymod = Interactor->GetControlKey();
152 case pcl::visualization::InteractorKeyboardModifier::
153 INTERACTOR_KB_MOD_SHIFT: {
154 keymod = Interactor->GetShiftKey();
159 switch (Interactor->GetKeyCode()) {
196 if (!keymod) vtkInteractorStyleRubberBandPick::OnChar();
200 vtkInteractorStyleRubberBandPick::OnChar();
210 "[vtkCustomInteractorStyle] No renderer collection given! Use "
211 "SetRendererCollection () before continuing.");
219 ->GetNextItemAsObject())) {
220 manipulator->
OnKeyDown(this->Interactor);
223 FindPokedRenderer(Interactor->GetEventPosition()[0],
224 Interactor->GetEventPosition()[1]);
226 if (wif_->GetInput() ==
NULL) {
227 wif_->SetInput(Interactor->GetRenderWindow());
229 snapshot_writer_->Modified();
233 if (win_height_ == -1 || win_width_ == -1) {
234 int* win_size = Interactor->GetRenderWindow()->GetSize();
235 win_height_ = win_size[0];
236 win_width_ = win_size[1];
240 bool shift = Interactor->GetShiftKey();
241 bool ctrl = Interactor->GetControlKey();
242 bool alt = Interactor->GetAltKey();
246 case pcl::visualization::INTERACTOR_KB_MOD_ALT: {
250 case pcl::visualization::INTERACTOR_KB_MOD_CTRL: {
254 case pcl::visualization::INTERACTOR_KB_MOD_SHIFT: {
263 if ((Interactor->GetKeySym()[0] ==
'S' ||
264 Interactor->GetKeySym()[0] ==
's') &&
265 ctrl && !alt && !shift) {
266 if (camera_file_.empty()) {
267 getCameraParameters(camera_);
268 camera_saved_ =
true;
270 "Camera parameters saved, you can press CTRL + R to "
273 if (saveCameraParameters(camera_file_)) {
275 "Save camera parameters to %s, you can press CTRL + R "
277 camera_file_.c_str());
280 "[vtkCustomInteractorStyle] Can't save camera "
281 "parameters to file: %s.",
282 camera_file_.c_str());
288 if ((Interactor->GetKeySym()[0] ==
'R' ||
289 Interactor->GetKeySym()[0] ==
'r') &&
290 ctrl && !alt && !shift) {
291 if (camera_file_.empty()) {
293 setCameraParameters(camera_);
296 CVLog::Print(
"No camera parameters saved for restoring.");
300 if (loadCameraParameters(camera_file_)) {
302 camera_file_.c_str());
305 "Can't restore camera parameters from file: %s.",
306 camera_file_.c_str());
309 CVLog::Print(
"No camera parameters saved in %s for restoring.",
310 camera_file_.c_str());
316 if (Interactor->GetKeySym() && Interactor->GetKeySym()[0] >=
'0' &&
317 Interactor->GetKeySym()[0] <=
'9') {
318 pcl::visualization::CloudActorMap::iterator it;
319 int index = Interactor->GetKeySym()[0] -
'0' - 1;
320 if (index == -1) index = 9;
323 if (ctrl) index += 10;
327 for (it = cloud_actors_->begin(); it != cloud_actors_->end();
329 pcl::visualization::CloudActor* act = &(*it).second;
330 if (index >=
static_cast<int>(act->geometry_handlers.size()))
334 act->geometry_handler_index_ = index;
337 pcl::visualization::PointCloudGeometryHandler<
338 pcl::PCLPointCloud2>::ConstPtr geometry_handler =
339 act->geometry_handlers[index];
343 geometry_handler->getGeometry(
points);
348 for (vtkIdType i = 0;
349 i < static_cast<vtkIdType>(
points->GetNumberOfPoints());
351 vertices->InsertNextCell(
static_cast<vtkIdType
>(1), &i);
357 data->SetVerts(vertices);
359 #if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
361 vtkVertexBufferObjectMapper* mapper =
362 static_cast<vtkVertexBufferObjectMapper*
>(
363 act->actor->GetMapper());
364 mapper->SetInput(
data);
366 act->actor->SetMapper(mapper);
370 vtkPolyDataMapper* mapper =
static_cast<vtkPolyDataMapper*
>(
371 act->actor->GetMapper());
372 #if VTK_MAJOR_VERSION < 6
373 mapper->SetInput(
data);
375 mapper->SetInputData(
data);
378 act->actor->SetMapper(mapper);
380 act->actor->Modified();
383 for (it = cloud_actors_->begin(); it != cloud_actors_->end();
385 pcl::visualization::CloudActor* act = &(*it).second;
387 if (index >=
static_cast<int>(act->color_handlers.size()))
391 act->color_handler_index_ = index;
394 pcl::visualization::PointCloudColorHandler<
395 pcl::PCLPointCloud2>::ConstPtr color_handler =
396 act->color_handlers[index];
399 color_handler->getColor();
402 scalars->GetRange(minmax);
404 vtkPolyData*
data =
static_cast<vtkPolyData*
>(
405 act->actor->GetMapper()->GetInput());
406 data->GetPointData()->SetScalars(scalars);
408 #if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
410 vtkVertexBufferObjectMapper* mapper =
411 static_cast<vtkVertexBufferObjectMapper*
>(
412 act->actor->GetMapper());
413 mapper->SetScalarRange(minmax);
414 mapper->SetScalarModeToUsePointData();
415 mapper->SetInput(
data);
417 act->actor->SetMapper(mapper);
421 vtkPolyDataMapper* mapper =
static_cast<vtkPolyDataMapper*
>(
422 act->actor->GetMapper());
423 mapper->SetScalarRange(minmax);
424 mapper->SetScalarModeToUsePointData();
425 #if VTK_MAJOR_VERSION < 6
426 mapper->SetInput(
data);
428 mapper->SetInputData(
data);
431 act->actor->SetMapper(mapper);
433 act->actor->Modified();
437 Interactor->Render();
441 std::string key(Interactor->GetKeySym());
442 if (key.find(
"XF86ZoomIn") != std::string::npos)
444 else if (key.find(
"XF86ZoomOut") != std::string::npos)
447 switch (Interactor->GetKeyCode()) {
453 " CTRL + SHIFT + p, P : switch to a point-based "
455 " CTRL + SHIFT + w, W : switch to a "
457 "representation (where available)"
458 " CTRL + SHIFT + s, S : switch to a "
460 "representation (where available)"
462 " CTRL + ALT + j, J : take a .PNG snapshot of "
465 " CTRL + ALT + c, C : display current "
468 " f, F : fly to point mode"
470 " e, E : exit the interactor"
471 " q, Q : stop and call VTK's TerminateApp"
473 " CTRL + SHIFT + +/- : increment/decrement "
475 " CTRL + ALT + +/-: zoom in/out "
477 " CTRL + ALT + g, G : display scale grid "
479 " CTRL + ALT + u, U : display lookup table "
482 " CTRL + ALT + o, O : switch between "
483 "perspective/parallel "
484 "projection (default = perspective)"
485 " r, R [+ ALT] : reset camera [to viewpoint = {0, 0, 0} "
486 "-> center_{x, y, z}]"
487 " CTRL + s, S : save camera parameters"
488 " CTRL + r, R : restore camera parameters"
490 " CTRL + ALT + s, S : turn stereo mode on/off"
491 " CTRL + ALT + f, F : switch between maximized window "
495 " l, L : list all available geometric "
496 "and color handlers for the current actor map"
497 " ALT + 0..9 [+ CTRL] : switch between different "
498 "geometric handlers (where available)"
499 " 0..9 [+ CTRL] : switch between different color "
500 "handlers (where available)"
502 " SHIFT + left click : select a point (start with "
503 "-use_point_picking)"
505 " a, A : toggle rubber band selection mode for "
506 "left mouse button");
515 for (pcl::visualization::CloudActorMap::iterator it =
516 cloud_actors_->begin();
517 it != cloud_actors_->end(); ++it) {
518 std::list<std::string> geometry_handlers_list,
520 pcl::visualization::CloudActor* act = &(*it).second;
521 for (
size_t i = 0; i < act->geometry_handlers.size(); ++i)
522 geometry_handlers_list.push_back(
523 act->geometry_handlers[i]->getFieldName());
524 for (
size_t i = 0; i < act->color_handlers.size(); ++i)
525 color_handlers_list.push_back(
526 act->color_handlers[i]->getFieldName());
528 if (!geometry_handlers_list.empty()) {
531 "List of available geometry handlers for actor ");
533 for (std::list<std::string>::iterator git =
534 geometry_handlers_list.begin();
535 git != geometry_handlers_list.end(); ++git)
538 if (!color_handlers_list.empty()) {
540 CVLog::Print(
"List of available color handlers for actor ");
542 for (std::list<std::string>::iterator cit =
543 color_handlers_list.begin();
544 cit != color_handlers_list.end(); ++cit)
557 CurrentRenderer->GetActors();
558 vtkCollectionSimpleIterator ait;
559 for (ac->InitTraversal(ait);
560 vtkActor* actor = ac->GetNextActor(ait);) {
561 for (actor->InitPathTraversal();
562 vtkAssemblyPath*
path = actor->GetNextPath();) {
564 reinterpret_cast<vtkActor*
>(
565 path->GetLastNode()->GetViewProp());
566 apart->GetProperty()->SetRepresentationToPoints();
578 CurrentRenderer->GetActors();
579 vtkCollectionSimpleIterator ait;
580 for (ac->InitTraversal(ait);
581 vtkActor* actor = ac->GetNextActor(ait);) {
582 for (actor->InitPathTraversal();
583 vtkAssemblyPath*
path = actor->GetNextPath();) {
585 reinterpret_cast<vtkActor*
>(
586 path->GetLastNode()->GetViewProp());
587 apart->GetProperty()->SetRepresentationToWireframe();
588 apart->GetProperty()->SetLighting(
false);
599 char cam_fn[80], snapshot_fn[80];
600 unsigned t =
static_cast<unsigned>(time(0));
601 sprintf(snapshot_fn,
"screenshot-%d.png", t);
602 saveScreenshot(snapshot_fn);
604 sprintf(cam_fn,
"screenshot-%d.cam", t);
605 saveCameraParameters(cam_fn);
608 "Screenshot (%s) and camera information (%s) "
611 snapshot_fn, cam_fn);
623 double clip[2], focal[3], pos[3], view[3];
624 cam->GetClippingRange(clip);
625 cam->GetFocalPoint(focal);
626 cam->GetPosition(pos);
627 cam->GetViewUp(view);
628 int* win_pos = Interactor->GetRenderWindow()->GetPosition();
629 int* win_size = Interactor->GetRenderWindow()->GetSize();
630 std::cerr <<
"Clipping plane [near,far] " << clip[0] <<
", "
632 <<
"Focal point [x,y,z] " << focal[0] <<
", "
633 << focal[1] <<
", " << focal[2] <<
endl
634 <<
"Position [x,y,z] " << pos[0] <<
", " << pos[1]
635 <<
", " << pos[2] <<
endl
636 <<
"View up [x,y,z] " << view[0] <<
", " << view[1]
637 <<
", " << view[2] <<
endl
638 <<
"Camera view angle [degrees] "
639 << cam->GetViewAngle() <<
endl
640 <<
"Window size [x,y] " << win_size[0] <<
", "
641 << win_size[1] <<
endl
642 <<
"Window position [x,y] " << win_pos[0] <<
", "
643 << win_pos[1] <<
endl;
661 }
else if (shift && ctrl) {
663 CurrentRenderer->GetActors();
664 vtkCollectionSimpleIterator ait;
665 for (ac->InitTraversal(ait);
666 vtkActor* actor = ac->GetNextActor(ait);) {
667 for (actor->InitPathTraversal();
668 vtkAssemblyPath*
path = actor->GetNextPath();) {
670 reinterpret_cast<vtkActor*
>(
671 path->GetLastNode()->GetViewProp());
672 float psize = apart->GetProperty()->GetPointSize();
674 apart->GetProperty()->SetPointSize(psize + 1.0f);
688 }
else if (shift && ctrl) {
690 CurrentRenderer->GetActors();
691 vtkCollectionSimpleIterator ait;
692 for (ac->InitTraversal(ait);
693 vtkActor* actor = ac->GetNextActor(ait);) {
694 for (actor->InitPathTraversal();
695 vtkAssemblyPath*
path = actor->GetNextPath();) {
697 static_cast<vtkActor*
>(
698 path->GetLastNode()->GetViewProp());
699 float psize = apart->GetProperty()->GetPointSize();
701 apart->GetProperty()->SetPointSize(psize - 1.0f);
714 int* temp = Interactor->GetRenderWindow()->GetScreenSize();
716 scr_size[0] = temp[0];
717 scr_size[1] = temp[1];
720 temp = Interactor->GetRenderWindow()->GetSize();
722 win_size[0] = temp[0];
723 win_size[1] = temp[1];
725 if (win_size[0] == max_win_height_ &&
726 win_size[1] == max_win_width_) {
728 Interactor->GetRenderWindow()->SetSize(win_height_,
731 Interactor->GetRenderWindow()->SetPosition(win_pos_x_,
733 Interactor->GetRenderWindow()->Render();
734 Interactor->Render();
737 Interactor->GetRenderWindow()->GetPosition();
739 win_pos_x_ = win_pos[0];
740 win_pos_y_ = win_pos[1];
742 win_height_ = win_size[0];
743 win_width_ = win_size[1];
745 Interactor->GetRenderWindow()->SetSize(scr_size[0],
747 Interactor->GetRenderWindow()->Render();
748 Interactor->Render();
750 Interactor->GetRenderWindow()->GetSize();
752 max_win_height_ = win_size[0];
753 max_win_width_ = win_size[1];
757 AnimState = VTKIS_ANIM_ON;
759 Interactor->GetPicker()->Pick(Interactor->GetEventPosition()[0],
760 Interactor->GetEventPosition()[1],
761 0.0, CurrentRenderer);
762 vtkAbstractPropPicker* picker;
763 if ((picker = vtkAbstractPropPicker::SafeDownCast(
764 Interactor->GetPicker())))
765 path = picker->GetPath();
767 Interactor->FlyTo(CurrentRenderer,
768 picker->GetPickPosition());
769 AnimState = VTKIS_ANIM_OFF;
778 Interactor->GetRenderWindow()->GetStereoRender();
779 if (!stereo_render) {
780 if (stereo_anaglyph_mask_default_) {
781 Interactor->GetRenderWindow()->SetAnaglyphColorMask(4,
783 stereo_anaglyph_mask_default_ =
false;
785 Interactor->GetRenderWindow()->SetAnaglyphColorMask(2,
787 stereo_anaglyph_mask_default_ =
true;
790 Interactor->GetRenderWindow()->SetStereoRender(!stereo_render);
791 Interactor->GetRenderWindow()->Render();
792 Interactor->Render();
793 }
else if (shift && ctrl) {
794 vtkInteractorStyleRubberBandPick::OnKeyDown();
796 CurrentRenderer->GetActors();
797 vtkCollectionSimpleIterator ait;
798 for (ac->InitTraversal(ait);
799 vtkActor* actor = ac->GetNextActor(ait);) {
800 for (actor->InitPathTraversal();
801 vtkAssemblyPath*
path = actor->GetNextPath();) {
803 reinterpret_cast<vtkActor*
>(
804 path->GetLastNode()->GetViewProp());
805 apart->GetProperty()->SetRepresentationToSurface();
806 apart->GetProperty()->SetLighting(
true);
817 if (!grid_enabled_) {
818 grid_actor_->TopAxisVisibilityOn();
819 CurrentRenderer->AddViewProp(grid_actor_);
820 grid_enabled_ =
true;
822 CurrentRenderer->RemoveViewProp(grid_actor_);
823 grid_enabled_ =
false;
833 CurrentRenderer->GetActiveCamera();
834 int flag = cam->GetParallelProjection();
835 cam->SetParallelProjection(!flag);
837 CurrentRenderer->SetActiveCamera(cam);
838 CurrentRenderer->Render();
855 FindPokedRenderer(Interactor->GetEventPosition()[0],
856 Interactor->GetEventPosition()[1]);
857 if (CurrentRenderer != 0)
858 CurrentRenderer->ResetCamera();
860 PCL_WARN(
"no current renderer on the interactor style.");
862 CurrentRenderer->Render();
868 static pcl::visualization::CloudActorMap::iterator it =
869 cloud_actors_->begin();
872 bool found_transformation =
false;
873 for (
unsigned idx = 0; idx < cloud_actors_->size(); ++idx, ++it) {
874 if (it == cloud_actors_->end()) it = cloud_actors_->begin();
876 const pcl::visualization::CloudActor& actor = it->second;
877 if (actor.viewpoint_transformation_.GetPointer()) {
878 found_transformation =
true;
885 if (found_transformation) {
886 const pcl::visualization::CloudActor& actor = it->second;
888 actor.viewpoint_transformation_->GetElement(0, 3),
889 actor.viewpoint_transformation_->GetElement(1, 3),
890 actor.viewpoint_transformation_->GetElement(2, 3));
893 actor.viewpoint_transformation_->GetElement(0, 3) -
894 actor.viewpoint_transformation_->GetElement(0,
896 actor.viewpoint_transformation_->GetElement(1, 3) -
897 actor.viewpoint_transformation_->GetElement(1,
899 actor.viewpoint_transformation_->GetElement(2, 3) -
900 actor.viewpoint_transformation_->GetElement(2,
904 actor.viewpoint_transformation_->GetElement(0, 1),
905 actor.viewpoint_transformation_->GetElement(1, 1),
906 actor.viewpoint_transformation_->GetElement(2, 1));
908 cam->SetPosition(0, 0, 0);
909 cam->SetFocalPoint(0, 0, 1);
910 cam->SetViewUp(0, -1, 0);
914 if (it != cloud_actors_->end())
917 it = cloud_actors_->begin();
919 CurrentRenderer->SetActiveCamera(cam);
920 CurrentRenderer->ResetCameraClippingRange();
921 CurrentRenderer->Render();
932 static_cast<vtkPointPicker*
>(Interactor->GetPicker());
936 Interactor->SetPicker(area_picker);
939 Interactor->SetPicker(point_picker_);
946 Interactor->ExitCallback();
950 vtkInteractorStyleRubberBandPick::OnKeyDown();
955 pcl::visualization::KeyboardEvent
event(
956 true, Interactor->GetKeySym(), Interactor->GetKeyCode(),
957 Interactor->GetAltKey(), Interactor->GetControlKey(),
958 Interactor->GetShiftKey());
959 keyboard_signal_(
event);
962 Interactor->Render();
967 pcl::visualization::KeyboardEvent
event(
968 false, Interactor->GetKeySym(), Interactor->GetKeyCode(),
969 Interactor->GetAltKey(), Interactor->GetControlKey(),
970 Interactor->GetShiftKey());
971 keyboard_signal_(
event);
977 ->GetNextItemAsObject())) {
978 manipulator->
OnKeyUp(this->Interactor);
981 vtkInteractorStyleRubberBandPick::OnKeyUp();
986 int x = this->Interactor->GetEventPosition()[0];
987 int y = this->Interactor->GetEventPosition()[1];
988 pcl::visualization::MouseEvent
event(
989 pcl::visualization::MouseEvent::MouseMove,
990 pcl::visualization::MouseEvent::NoButton,
x,
y,
991 Interactor->GetAltKey(), Interactor->GetControlKey(),
992 Interactor->GetShiftKey(),
993 vtkInteractorStyleRubberBandPick::CurrentMode);
994 mouse_signal_(
event);
1002 this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
1003 this->Interactor->GetEventPosition()[1]);
1008 this->Interactor->GetEventPosition()[0],
1009 this->Interactor->GetEventPosition()[1],
1010 this->CurrentRenderer, this->Interactor);
1011 this->InvokeEvent(vtkCommand::InteractionEvent);
1014 vtkInteractorStyleRubberBandPick::OnMouseMove();
1020 int x = this->Interactor->GetEventPosition()[0];
1021 int y = this->Interactor->GetEventPosition()[1];
1023 if (Interactor->GetRepeatCount() == 0) {
1024 pcl::visualization::MouseEvent
event(
1025 pcl::visualization::MouseEvent::MouseButtonPress,
1026 pcl::visualization::MouseEvent::LeftButton,
x,
y,
1027 Interactor->GetAltKey(), Interactor->GetControlKey(),
1028 Interactor->GetShiftKey(),
1029 vtkInteractorStyleRubberBandPick::CurrentMode);
1030 mouse_signal_(
event);
1032 pcl::visualization::MouseEvent
event(
1033 pcl::visualization::MouseEvent::MouseDblClick,
1034 pcl::visualization::MouseEvent::LeftButton,
x,
y,
1035 Interactor->GetAltKey(), Interactor->GetControlKey(),
1036 Interactor->GetShiftKey(),
1037 vtkInteractorStyleRubberBandPick::CurrentMode);
1038 mouse_signal_(
event);
1041 this->Interactor->GetControlKey());
1042 vtkInteractorStyleRubberBandPick::OnLeftButtonDown();
1047 int x = this->Interactor->GetEventPosition()[0];
1048 int y = this->Interactor->GetEventPosition()[1];
1049 pcl::visualization::MouseEvent
event(
1050 pcl::visualization::MouseEvent::MouseButtonRelease,
1051 pcl::visualization::MouseEvent::LeftButton,
x,
y,
1052 Interactor->GetAltKey(), Interactor->GetControlKey(),
1053 Interactor->GetShiftKey(),
1054 vtkInteractorStyleRubberBandPick::CurrentMode);
1055 mouse_signal_(
event);
1057 vtkInteractorStyleRubberBandPick::OnLeftButtonUp();
1062 int x = this->Interactor->GetEventPosition()[0];
1063 int y = this->Interactor->GetEventPosition()[1];
1064 if (Interactor->GetRepeatCount() == 0) {
1065 pcl::visualization::MouseEvent
event(
1066 pcl::visualization::MouseEvent::MouseButtonPress,
1067 pcl::visualization::MouseEvent::MiddleButton,
x,
y,
1068 Interactor->GetAltKey(), Interactor->GetControlKey(),
1069 Interactor->GetShiftKey(),
1070 vtkInteractorStyleRubberBandPick::CurrentMode);
1071 mouse_signal_(
event);
1073 pcl::visualization::MouseEvent
event(
1074 pcl::visualization::MouseEvent::MouseDblClick,
1075 pcl::visualization::MouseEvent::MiddleButton,
x,
y,
1076 Interactor->GetAltKey(), Interactor->GetControlKey(),
1077 Interactor->GetShiftKey(),
1078 vtkInteractorStyleRubberBandPick::CurrentMode);
1079 mouse_signal_(
event);
1082 this->Interactor->GetControlKey());
1083 vtkInteractorStyleRubberBandPick::OnMiddleButtonDown();
1088 int x = this->Interactor->GetEventPosition()[0];
1089 int y = this->Interactor->GetEventPosition()[1];
1090 pcl::visualization::MouseEvent
event(
1091 pcl::visualization::MouseEvent::MouseButtonRelease,
1092 pcl::visualization::MouseEvent::MiddleButton,
x,
y,
1093 Interactor->GetAltKey(), Interactor->GetControlKey(),
1094 Interactor->GetShiftKey(),
1095 vtkInteractorStyleRubberBandPick::CurrentMode);
1096 mouse_signal_(
event);
1098 vtkInteractorStyleRubberBandPick::OnMiddleButtonUp();
1103 int x = this->Interactor->GetEventPosition()[0];
1104 int y = this->Interactor->GetEventPosition()[1];
1105 if (Interactor->GetRepeatCount() == 0) {
1106 pcl::visualization::MouseEvent
event(
1107 pcl::visualization::MouseEvent::MouseButtonPress,
1108 pcl::visualization::MouseEvent::RightButton,
x,
y,
1109 Interactor->GetAltKey(), Interactor->GetControlKey(),
1110 Interactor->GetShiftKey(),
1111 vtkInteractorStyleRubberBandPick::CurrentMode);
1112 mouse_signal_(
event);
1114 pcl::visualization::MouseEvent
event(
1115 pcl::visualization::MouseEvent::MouseDblClick,
1116 pcl::visualization::MouseEvent::RightButton,
x,
y,
1117 Interactor->GetAltKey(), Interactor->GetControlKey(),
1118 Interactor->GetShiftKey(),
1119 vtkInteractorStyleRubberBandPick::CurrentMode);
1120 mouse_signal_(
event);
1124 this->Interactor->GetControlKey());
1125 vtkInteractorStyleRubberBandPick::OnRightButtonDown();
1130 int x = this->Interactor->GetEventPosition()[0];
1131 int y = this->Interactor->GetEventPosition()[1];
1132 pcl::visualization::MouseEvent
event(
1133 pcl::visualization::MouseEvent::MouseButtonRelease,
1134 pcl::visualization::MouseEvent::RightButton,
x,
y,
1135 Interactor->GetAltKey(), Interactor->GetControlKey(),
1136 Interactor->GetShiftKey(),
1137 vtkInteractorStyleRubberBandPick::CurrentMode);
1138 mouse_signal_(
event);
1140 vtkInteractorStyleRubberBandPick::OnRightButtonUp();
1145 int x = this->Interactor->GetEventPosition()[0];
1146 int y = this->Interactor->GetEventPosition()[1];
1147 pcl::visualization::MouseEvent
event(
1148 pcl::visualization::MouseEvent::MouseScrollUp,
1149 pcl::visualization::MouseEvent::VScroll,
x,
y,
1150 Interactor->GetAltKey(), Interactor->GetControlKey(),
1151 Interactor->GetShiftKey(),
1152 vtkInteractorStyleRubberBandPick::CurrentMode);
1153 mouse_signal_(
event);
1154 if (Interactor->GetRepeatCount()) mouse_signal_(
event);
1156 if (Interactor->GetAltKey()) {
1159 double opening_angle = cam->GetViewAngle();
1160 if (opening_angle > 15.0) opening_angle -= 1.0;
1162 cam->SetViewAngle(opening_angle);
1164 CurrentRenderer->SetActiveCamera(cam);
1165 CurrentRenderer->ResetCameraClippingRange();
1166 CurrentRenderer->Modified();
1167 CurrentRenderer->Render();
1169 Interactor->Render();
1171 vtkInteractorStyleRubberBandPick::OnMouseWheelForward();
1176 int x = this->Interactor->GetEventPosition()[0];
1177 int y = this->Interactor->GetEventPosition()[1];
1178 pcl::visualization::MouseEvent
event(
1179 pcl::visualization::MouseEvent::MouseScrollDown,
1180 pcl::visualization::MouseEvent::VScroll,
x,
y,
1181 Interactor->GetAltKey(), Interactor->GetControlKey(),
1182 Interactor->GetShiftKey(),
1183 vtkInteractorStyleRubberBandPick::CurrentMode);
1184 mouse_signal_(
event);
1185 if (Interactor->GetRepeatCount()) mouse_signal_(
event);
1187 if (Interactor->GetAltKey()) {
1190 double opening_angle = cam->GetViewAngle();
1191 if (opening_angle < 170.0) opening_angle += 1.0;
1193 cam->SetViewAngle(opening_angle);
1195 CurrentRenderer->SetActiveCamera(cam);
1196 CurrentRenderer->ResetCameraClippingRange();
1197 CurrentRenderer->Modified();
1198 CurrentRenderer->Render();
1200 Interactor->Render();
1202 vtkInteractorStyleRubberBandPick::OnMouseWheelBackward();
1207 if (!this->CurrentRenderer) {
1213 vtkLightCollection* lights = this->CurrentRenderer->GetLights();
1214 vtkCamera* camera = this->CurrentRenderer->GetActiveCamera();
1216 lights->InitTraversal();
1217 light = lights->GetNextItem();
1221 light->SetPosition(camera->GetPosition());
1222 light->SetFocalPoint(camera->GetFocalPoint());
1235 this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
1236 this->Interactor->GetEventPosition()[1]);
1237 if (this->CurrentRenderer ==
NULL) {
1245 this->InvokeEvent(vtkCommand::StartInteractionEvent);
1250 this->Interactor->GetEventPosition()[0],
1251 this->Interactor->GetEventPosition()[1], this->CurrentRenderer,
1263 this->Interactor->GetEventPosition()[0],
1264 this->Interactor->GetEventPosition()[1], this->CurrentRenderer,
1267 this->InvokeEvent(vtkCommand::EndInteractionEvent);
1281 ->GetNextItemAsObject())) {
1282 if (manipulator->GetButton() == button &&
1283 manipulator->GetShift() == shift &&
1284 manipulator->GetControl() == control) {
1292 if (this->Interactor->GetControlKey()) {
1294 fact, this->Interactor->GetEventPosition(),
1295 this->CurrentRenderer);
1297 this->vtkInteractorStyleRubberBandPick::Dolly(fact);
1304 vtkRenderer* renderer) {
1305 vtkCamera* cam = renderer->GetActiveCamera();
1306 if (cam->GetParallelProjection()) {
1307 int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
1309 int* aSize = renderer->GetRenderWindow()->GetSize();
1317 cam->SetParallelScale(cam->GetParallelScale() / fact);
1321 double viewFocus[4], originalViewFocus[3], cameraPos[3],
1323 double newFocalPoint[4], norm[3];
1326 cam->GetPosition(cameraPos);
1327 cam->GetFocalPoint(viewFocus);
1328 cam->GetFocalPoint(originalViewFocus);
1329 cam->GetViewPlaneNormal(norm);
1331 vtkCustomInteractorStyle::ComputeWorldToDisplay(
1332 renderer, viewFocus[0], viewFocus[1], viewFocus[2], viewFocus);
1334 vtkCustomInteractorStyle::ComputeDisplayToWorld(
1336 viewFocus[2], newFocalPoint);
1338 cam->SetFocalPoint(newFocalPoint);
1344 cam->GetPosition(newCameraPos);
1347 newPoint[0] = originalViewFocus[0] + newCameraPos[0] - cameraPos[0];
1348 newPoint[1] = originalViewFocus[1] + newCameraPos[1] - cameraPos[1];
1349 newPoint[2] = originalViewFocus[2] + newCameraPos[2] - cameraPos[2];
1351 cam->SetFocalPoint(newPoint);
1357 vtkRenderer* renderer,
int toX,
int toY,
int fromX,
int fromY) {
1358 vtkCamera* cam = renderer->GetActiveCamera();
1359 double viewFocus[4], focalDepth, viewPoint[3];
1360 double newPickPoint[4], oldPickPoint[4], motionVector[3];
1361 cam->GetFocalPoint(viewFocus);
1363 vtkCustomInteractorStyle::ComputeWorldToDisplay(
1364 renderer, viewFocus[0], viewFocus[1], viewFocus[2], viewFocus);
1365 focalDepth = viewFocus[2];
1367 vtkCustomInteractorStyle::ComputeDisplayToWorld(
1368 renderer,
double(toX),
double(toY), focalDepth, newPickPoint);
1369 vtkCustomInteractorStyle::ComputeDisplayToWorld(
1370 renderer,
double(fromX),
double(fromY), focalDepth, oldPickPoint);
1373 motionVector[0] = oldPickPoint[0] - newPickPoint[0];
1374 motionVector[1] = oldPickPoint[1] - newPickPoint[1];
1375 motionVector[2] = oldPickPoint[2] - newPickPoint[2];
1377 cam->GetFocalPoint(viewFocus);
1378 cam->GetPosition(viewPoint);
1379 cam->SetFocalPoint(motionVector[0] + viewFocus[0],
1380 motionVector[1] + viewFocus[1],
1381 motionVector[2] + viewFocus[2]);
1383 cam->SetPosition(motionVector[0] + viewPoint[0],
1384 motionVector[1] + viewPoint[1],
1385 motionVector[2] + viewPoint[2]);
1391 pcl::visualization::CloudActorMap::iterator am_it;
1392 pcl::visualization::ShapeActorMap::iterator sm_it;
1393 bool actor_found =
false;
1395 if (!lut_enabled_ && !add_lut)
return;
1401 if (am_it == cloud_actors_->end()) {
1403 if (sm_it == shape_actors_->end()) {
1405 "[updateLookUpTableDisplay] Could not find any "
1410 CurrentRenderer->RemoveActor(lut_actor_);
1411 lut_enabled_ =
false;
1420 !actor->GetMapper()->GetInput()->GetPointData()->GetScalars()) {
1422 "[updateLookUpTableDisplay] id <%s> does not hold "
1424 "color information!",
1427 CurrentRenderer->RemoveActor(lut_actor_);
1428 lut_enabled_ =
false;
1433 lut_actor_->SetLookupTable(actor->GetMapper()->GetLookupTable());
1434 lut_actor_->Modified();
1438 pcl::visualization::CloudActor* act = &(*am_it).second;
1439 if (!act->actor->GetMapper()->GetLookupTable() &&
1440 !act->actor->GetMapper()
1445 "[updateLookUpTableDisplay] id <%s> does not hold "
1447 "color information!",
1450 CurrentRenderer->RemoveActor(lut_actor_);
1451 lut_enabled_ =
false;
1456 vtkScalarsToColors* lut = act->actor->GetMapper()->GetLookupTable();
1457 lut_actor_->SetLookupTable(lut);
1458 lut_actor_->Modified();
1465 for (am_it = cloud_actors_->begin(); am_it != cloud_actors_->end();
1467 pcl::visualization::CloudActor* act = &(*am_it).second;
1468 if (!act->actor->GetMapper()->GetLookupTable())
continue;
1470 if (!act->actor->GetMapper()
1476 vtkScalarsToColors* lut = act->actor->GetMapper()->GetLookupTable();
1477 lut_actor_->SetLookupTable(lut);
1478 lut_actor_->Modified();
1484 for (sm_it = shape_actors_->begin(); sm_it != shape_actors_->end();
1488 if (!actor)
continue;
1490 if (!actor->GetMapper()
1495 lut_actor_->SetLookupTable(
1496 actor->GetMapper()->GetLookupTable());
1497 lut_actor_->Modified();
1504 if ((!actor_found && lut_enabled_) ||
1505 (lut_enabled_ && add_lut))
1507 CurrentRenderer->RemoveActor(lut_actor_);
1508 lut_enabled_ =
false;
1509 }
else if (!lut_enabled_ && add_lut && actor_found)
1511 CurrentRenderer->AddActor(lut_actor_);
1512 lut_actor_->SetVisibility(
true);
1513 lut_enabled_ =
true;
1514 }
else if (lut_enabled_)
1516 CurrentRenderer->RemoveActor(lut_actor_);
1517 CurrentRenderer->AddActor(lut_actor_);
1521 CurrentRenderer->Render();
1527 this->vtkInteractorStyleRubberBandPick::PrintSelf(os, indent);
static bool Print(const char *format,...)
Prints out a formatted message in console.
static bool Error(const char *format,...)
Display an error dialog with formatted message.
vtkCustomInteractorStyle defines an unique, custom VTK based interactory style for PCL Visualizer app...
virtual ~vtkCustomInteractorStyle() override
Empty destructor.
virtual void OnMouseMove() override
virtual void OnChar() override
Interactor style internal method. Gets called whenever a key is pressed.
virtual void OnLeftButtonUp() override
void zoomOut()
Interactor style internal method. Zoom out.
virtual void OnLeftButtonDown() override
virtual void OnKeyUp() override
virtual void OnMiddleButtonUp() override
void Dolly(double factor) override
void zoomIn()
Interactor style internal method. Zoom in.
std::string lut_actor_id_
ID used to fetch/display the look up table on the visualizer It should be set by PCLVisualizer setLoo...
virtual void OnMouseWheelForward() override
virtual void OnRightButtonUp() override
void AddManipulator(vtkCameraManipulator *m)
void OnButtonDown(int button, int shift, int control)
vtkCollection * CameraManipulators
static void DollyToPosition(double fact, int *position, vtkRenderer *renderer)
virtual void OnMouseWheelBackward() override
static void TranslateCamera(vtkRenderer *renderer, int toX, int toY, int fromX, int fromY)
void PrintSelf(ostream &os, vtkIndent indent) override
void RemoveAllManipulators()
virtual void OnRightButtonDown() override
void OnButtonUp(int button)
double CenterOfRotation[3]
virtual vtkCameraManipulator * FindManipulator(int button, int shift, int control)
virtual void OnMiddleButtonDown() override
virtual void OnKeyDown() override
void updateLookUpTableDisplay(bool add_lut=false)
Add/remove the look up table displayed when 'u' is pressed, can also be used to update the current LU...
vtkCameraManipulator * CurrentManipulator
vtkCustomInteractorStyle()
Empty constructor.
virtual void OnButtonUp(int x, int y, vtkRenderer *ren, vtkRenderWindowInteractor *iren)
virtual void OnMouseMove(int x, int y, vtkRenderer *ren, vtkRenderWindowInteractor *iren)
virtual void OnButtonDown(int x, int y, vtkRenderer *ren, vtkRenderWindowInteractor *iren)
virtual void StartInteraction()
virtual void OnKeyDown(vtkRenderWindowInteractor *iren)
virtual void EndInteraction()
virtual void OnKeyUp(vtkRenderWindowInteractor *iren)
QTextStream & endl(QTextStream &stream)
vtkStandardNewMacro(vtkCustomInteractorStyle)
static const std::string path
bool FileExists(const std::string &filename)
constexpr Rgbaf light(0.66f, 0.66f, 0.66f, 1.00f)