LVRPickingInteractor.cpp
Go to the documentation of this file.
1 
34 #include "LVRPickingInteractor.hpp"
35 
36 #include <vtkObjectFactory.h>
37 #include <vtkTextProperty.h>
38 #include <vtkRenderWindowInteractor.h>
39 #include <vtkAbstractPicker.h>
40 #include <vtkRenderWindow.h>
41 #include <vtkRendererCollection.h>
42 #include <vtkPointPicker.h>
43 #include <vtkCamera.h>
44 #include <vtkCallbackCommand.h>
45 #include <vtkSphereSource.h>
46 #include <vtkPolyData.h>
47 #include <vtkSmartPointer.h>
48 #include <vtkPolyDataMapper.h>
49 #include <vtkProperty.h>
50 #include <vtkActor.h>
51 #include <vtkActorCollection.h>
52 #include <vtkCubeSource.h>
53 #include <vtkPlanes.h>
54 #include <vtkAreaPicker.h>
55 #include <vtkVertexGlyphFilter.h>
56 #include <vtkVersion.h>
57 #include <vtkPointData.h>
58 #include <vtkIdTypeArray.h>
59 #include <vtkDataSetSurfaceFilter.h>
60 #include <vtkPolyLine.h>
61 #include <vtkObjectFactory.h>
62 #include <vtkPointSource.h>
63 #include <vtkExtractGeometry.h>
64 #include <vtkDataSetMapper.h>
65 #include <vtkUnstructuredGrid.h>
66 #include <vtkIdFilter.h>
67 #include <set>
68 
69 namespace lvr2
70 {
71 
72 vtkStandardNewMacro(LVRPickingInteractor);
73 
75 //LVRPickingInteractor::LVRPickingInteractor(vtkSmartPointer<vtkRenderer> renderer) :
76  m_motionFactor(50), m_rotationFactor(20), m_interactorMode(TRACKBALL)
77 {
78  m_modified = false;
81 
82  m_viewUp[0] = 0.0;
83  m_viewUp[1] = 1.0;
84  m_viewUp[2] = 0.0;
85 
86  m_pickMode = None;
88  m_correspondenceMode = false;
89  vtkSmartPointer<vtkTextProperty> p = vtkSmartPointer<vtkTextProperty>::New();
90  p->SetColor(1.0, 1.0, 0.0);
91  p->SetBold(1);
92  p->SetShadow(0);
93 
94  m_textActor = vtkSmartPointer<vtkTextActor>::New();
95  m_textActor->SetDisplayPosition(100, 10);
96  m_textActor->SetTextProperty(p);
97  m_textActor->SetInput("Pick a point...");
98  m_textActor->VisibilityOff();
99 
100 }
101 
102 
103 void LVRPickingInteractor::setRenderer(vtkSmartPointer<vtkRenderer> renderer)
104 {
105 
106  m_renderer = renderer;
107  m_renderer->AddActor(m_textActor);
108  // Create a sphere actor to represent the current focal point
109  vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
110  sphereSource->SetCenter(0.0, 0.0, 0.0);
111 
112  double b[6];
113  m_renderer->ComputeVisiblePropBounds(b);
114  // Set radius to one percent of the largest scene dimension
115  double s = std::max(fabs(b[0] - b[1]), std::max(fabs(b[2] - b[3]), fabs(b[4] - b[5]))) * 0.1;
116  cout << s << endl;
117  sphereSource->SetRadius(s);
118 
119  vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
120  mapper->SetInputConnection(sphereSource->GetOutputPort());
121 
122  // m_selectionPoints = vtkSmartPointer<vtkPoints>::New();
123  m_sphereActor = vtkSmartPointer<vtkActor>::New();
124  m_sphereActor->SetMapper(mapper);
125  m_renderer->AddActor(m_sphereActor);
126 
127  double focalPoint[3];
128  m_renderer->GetActiveCamera()->GetFocalPoint(focalPoint);
129  m_sphereActor->SetPosition(focalPoint[0], focalPoint[1], focalPoint[2]);
130 
131  this->UseTimersOn();
132 
133 }
135 {
136  vtkRenderWindowInteractor *rwi = this->Interactor;
137  if(state == Qt::Checked)
138  {
139  rwi->GetRenderWindow()->StereoRenderOn();
140  }
141  else
142  {
143  rwi->GetRenderWindow()->StereoRenderOff();
144  }
145  rwi->Render();
146 }
147 
149 {
150  if(state == Qt::Checked)
151  {
152  m_sphereActor->SetVisibility(true);
153  }
154  else
155  {
156  m_sphereActor->SetVisibility(false);
157  }
158  vtkRenderWindowInteractor *rwi = this->Interactor;
159  rwi->Render();
160 }
161 
163 {
164  double focalPoint[3];
165  m_renderer->GetActiveCamera()->GetFocalPoint(focalPoint);
166  m_sphereActor->SetPosition(focalPoint[0], focalPoint[1], focalPoint[2]);
167 }
168 
169 void LVRPickingInteractor::setPoints(vtkSmartPointer<vtkPolyData> points)
170 {
171  if (points)
172  {
173  /*
174  std::cout <<"point_set" << std::endl;
175  auto vertexFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New();
176 auto a = points->GetPointData()->GetAbstractArray("OriginalIds");
177  if(a == nullptr)
178  {
179  std::cout << "array not found"<< std::endl;
180  std::cout << a->GetNumberOfComponents() << std::endl;
181  }
182  else
183  {
184  std::cout << "array found"<< std::endl;
185  std::cout << a->GetNumberOfComponents() << std::endl;
186  }
187  vertexFilter->SetInputData(points);
188 
189  vertexFilter->Update();
190  m_points = {};
191  std::cout <<"point_set" << std::endl;
192  m_points->DeepCopy(vertexFilter->GetOutput());*/
193  m_points = points;
194  m_selectedPoints = std::vector<bool>(m_points->GetNumberOfPoints(), false);
195  m_pointLabels = std::vector<uint16_t>(m_points->GetNumberOfPoints(), 0);
196  }
197 }
198 
200 {
201  m_motionFactor = factor;
202 }
203 
205 {
206  m_rotationFactor = factor;
207 }
208 
210 {
212 }
213 
215 {
217 }
218 
220 {
222 }
223 
225 {
226  // TODO Auto-generated destructor stub
227 }
228 
229 
231 {
232  switch(m_interactorMode)
233  {
234  case TRACKBALL:
235  dollyTrackball();
236  break;
237  case TERRAIN:
238  dollyTerrain();
239  break;
240  case SHOOTER:
241  dollyShooter();
242  break;
243  default:
244  dollyTrackball();
245  }
246 }
247 
248 void LVRPickingInteractor::Dolly(double speed)
249 {
250  switch(m_interactorMode)
251  {
252  case TRACKBALL:
253  dollyTrackball(speed);
254  break;
255  case TERRAIN:
256  dollyTerrain(speed);
257  break;
258  case SHOOTER:
259  dollyShooter(speed);
260  break;
261  default:
262  dollyTrackball();
263 
264  }
265 }
266 
268 {
269  switch(m_interactorMode)
270  {
271  case TRACKBALL:
272  panTrackball();
273  break;
274  case TERRAIN:
275  panTerrain();
276  break;
277  case SHOOTER:
278  panShooter();
279  break;
280  default:
281  panTrackball();
282 
283  }
284 }
285 
287 {
288  switch(m_interactorMode)
289  {
290  case TRACKBALL:
291  spinTrackball();
292  break;
293  case TERRAIN:
294  spinTerrain();
295  break;
296  case SHOOTER:
297  spinShooter();
298  break;
299  default:
300  spinTrackball();
301  }
302 }
303 
305 {
306  switch(m_interactorMode)
307  {
308  case TRACKBALL:
309  rotateTrackball();
310  break;
311  case TERRAIN:
312  rotateTerrain();
313  break;
314  case SHOOTER:
315  rotateShooter();
316  break;
317  default:
318  rotateTrackball();
319  }
320 }
321 
323 {
324  switch(m_interactorMode)
325  {
326  case TRACKBALL:
327  zoomTrackball();
328  break;
329  case TERRAIN:
330  zoomTerrain();
331  break;
332  case SHOOTER:
333  zoomShooter();
334  break;
335  default:
336  zoomTrackball();
337  }
338 }
339 
340 
342 {
343  if (m_pickMode == PickLabel)
344  {
346  return;
347  }
348  switch(m_interactorMode)
349  {
350  case TRACKBALL:
352  break;
353  case TERRAIN:
355  break;
356  case SHOOTER:
358  break;
359  default:
361  }
362  handlePicking();
363 }
364 
365 
367 {
368  if (m_pickMode == PickLabel)
369  {
370  calculateSelection(true);
371  return;
372  }
373  switch(m_interactorMode)
374  {
375  case TRACKBALL:
377  break;
378  case TERRAIN:
380  break;
381  case SHOOTER:
383  break;
384  default:
386  }
387 }
388 
390 {
391  if(m_pickMode == PickLabel)
392  {
394  return;
395  }
396  switch(m_interactorMode)
397  {
398  case TRACKBALL:
400  break;
401  case TERRAIN:
403  break;
404  case SHOOTER:
405  //onMouseMoveShooter();
406  break;
407  default:
409  }
410 }
411 
413 {
414  switch(m_interactorMode)
415  {
416  case TRACKBALL:
418  break;
419  case TERRAIN:
421  break;
422  case SHOOTER:
424  break;
425  default:
427  }
428 }
429 
431 {
432  switch(m_interactorMode)
433  {
434  case TRACKBALL:
436  break;
437  case TERRAIN:
439  break;
440  case SHOOTER:
442  break;
443  default:
445  }
446 }
447 
449 {
450  if (m_pickMode == PickLabel)
451  {
452  calculateSelection(false);
453  return;
454  }
455  switch(m_interactorMode)
456  {
457  case TRACKBALL:
459  break;
460  case TERRAIN:
462  break;
463  case SHOOTER:
465  break;
466  default:
468  }
469 }
470 
472 {
473  if (m_pickMode == PickLabel)
474  {
476  return;
477  }
478  switch(m_interactorMode)
479  {
480  case TRACKBALL:
482  break;
483  case TERRAIN:
485  break;
486  case SHOOTER:
488  break;
489  default:
491  }
492 }
493 
495 {
496  switch(m_interactorMode)
497  {
498  case TRACKBALL:
500  break;
501  case TERRAIN:
503  break;
504  case SHOOTER:
506  break;
507 
508  default:
510  }
511 }
512 
514 {
515  switch(m_interactorMode)
516  {
517  case TRACKBALL:
519  break;
520  case TERRAIN:
522  break;
523  case SHOOTER:
525  break;
526  default:
528  }
529 }
530 
532 {
533 
534 }
535 
537 {
538  vtkRenderWindowInteractor *rwi = this->Interactor;
539  vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
540 
541 
542  double position[3];
543  double direction[3];
544  double viewUp[3];
545  double cross[3];
546  double focalPoint[3];
547 
548  camera->GetPosition(position);
549  camera->GetDirectionOfProjection(direction);
550  camera->GetFocalPoint(focalPoint);
551  camera->GetViewUp(viewUp[0], viewUp[1], viewUp[2]);
552 
553  vtkMath::Cross(direction, viewUp, cross);
554 
555  // Move position
556  camera->SetPosition(
557  position[0] + 3 * factor * cross[0],
558  position[1] + 3 * factor * cross[1],
559  position[2] + 3 * factor * cross[2]);
560 
561  // Move position
562  camera->SetFocalPoint(
563  focalPoint[0] + 3 * factor * cross[0],
564  focalPoint[1] + 3 * factor * cross[1],
565  focalPoint[2] + 3 * factor * cross[2]);
566 
567  camera->OrthogonalizeViewUp();
568 
569  if (this->AutoAdjustCameraClippingRange)
570  {
571  this->CurrentRenderer->ResetCameraClippingRange();
572  }
573 
574 
575  rwi->Render();
576 }
577 
579 {
580  vtkRenderWindowInteractor *rwi = this->Interactor;
581  vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
582  camera->SetViewUp(m_viewUp[0], m_viewUp[1], m_viewUp[2]);
583  rwi->Render();
584 }
585 
587 {
588  vtkRenderWindowInteractor *rwi = this->Interactor;
589  if(this->CurrentRenderer!=nullptr)
590  {
591  this->CurrentRenderer->ResetCamera();
592  }
593  else
594  {
595  vtkWarningMacro(<<"no current renderer on the interactor style.");
596  }
597  rwi->Render();
598 }
599 
601 {
602 
603  vtkRenderWindowInteractor *rwi = this->Interactor;
604  vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
605 
606  double position[3];
607  double direction[3];
608 
609  camera->GetPosition(position);
610  camera->GetDirectionOfProjection(direction);
611 
612  camera->SetFocalPoint(
613  position[0] + 3 * fabs(factor) * direction[0],
614  position[1] + 3 * fabs(factor) * direction[1],
615  position[2] + 3 * fabs(factor) * direction[2]);
616 
617 
618 
619  // Compute desired position
620  camera->SetPosition(
621  position[0] - factor * direction[0],
622  position[1] - factor * direction[1],
623  position[2] - factor * direction[2]);
624 
625  camera->OrthogonalizeViewUp();
626 
627  if (this->AutoAdjustCameraClippingRange)
628  {
629  this->CurrentRenderer->ResetCameraClippingRange();
630  }
631 
632  rwi->Render();
633 }
634 
636 {
637 
638  vtkRenderWindowInteractor *rwi = this->Interactor;
639  vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
640 
641  // Compute offset from screen center
642  int mx = rwi->GetSize()[0] / 2;
643  int my = rwi->GetSize()[1] / 2;
644  int dx = rwi->GetEventPosition()[0] - m_startCameraMovePosition[0];
645  int dy = rwi->GetEventPosition()[1] - m_startCameraMovePosition[1];
646 
647 
648  float yawAngle = (1.0 * dx / mx) * m_rotationFactor;
649  float pitchAngle = (1.0 * dy / my) * m_rotationFactor;
650 
651  camera->Yaw(-yawAngle);
652  camera->Pitch(pitchAngle);
653  camera->OrthogonalizeViewUp();
654  camera->ViewingRaysModified();
655 
656  if (this->AutoAdjustCameraClippingRange)
657  {
658  this->CurrentRenderer->ResetCameraClippingRange();
659  }
660 
661  rwi->Render();
662 }
663 
665 {
666  vtkRenderWindowInteractor *rwi = this->Interactor;
667  vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
668 
669  int my = rwi->GetSize()[1] / 2;
670  int dy = rwi->GetEventPosition()[1] - m_startCameraMovePosition[1];
671 
672  double step = -(1.0 * dy / my) * m_motionFactor;
673  double position[3];
674  double focal[3];
675  double direction[3];
676 
677  camera->GetPosition(position);
678  camera->GetFocalPoint(focal);
679  camera->GetViewUp(direction);
680 
681 // cout << "STEP: " << step << endl;
682 // cout << "POSITION: " << position[0] << " " << position[1] << " " << position[2] << endl;
683 // cout << "DIRECTION: " << direction[0] << " " << direction[1] << " " << direction[2] << endl;
684 
685  camera->SetPosition(
686  position[0] + step * direction[0],
687  position[1] + step * direction[1],
688  position[2] + step * direction[2]);
689 
690  // Move position
691  camera->SetFocalPoint(
692  focal[0] + step * direction[0],
693  focal[1] + step * direction[1],
694  focal[2] + step * direction[2]);
695 
696 
697  camera->ViewingRaysModified();
698 
699  if (this->AutoAdjustCameraClippingRange)
700  {
701  this->CurrentRenderer->ResetCameraClippingRange();
702  }
703 
704  rwi->Render();
705 
706 }
707 
708 
710 {
711 
712 }
713 
715 {
716 
717 }
718 
720 {
721 
722 }
723 
725 {
726 
727 }
728 
730 {
731  this->m_shooterMode = LOOK;
732  this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
733  this->Interactor->GetEventPosition()[1]);
734  if (this->CurrentRenderer == nullptr)
735  {
736  return;
737  }
738 
739  GrabFocus(this->EventCallbackCommand, nullptr);
740  this->StartTimer();
741 
742  // Save klicked position to determine rotation speed
743  vtkRenderWindowInteractor *rwi = this->Interactor;
744  m_startCameraMovePosition[0] = rwi->GetEventPosition()[0];
745  m_startCameraMovePosition[1] = rwi->GetEventPosition()[1];
746 }
747 
749 {
750  switch (this->State)
751  {
752  case VTKIS_TIMER:
753  this->EndTimer();
754  if ( this->Interactor )
755  {
756  this->ReleaseFocus();
757  }
758  break;
759  }
760 }
761 
763 {
765  {
766  if(m_shooterMode == LOOK)
767  {
769  }
770  if(m_shooterMode == HOVER)
771  {
772  hoverShooter();
773  }
774  }
775 }
776 
777 
778 
780 {
781  switch (this->State)
782  {
783  case VTKIS_TIMER:
784  this->EndTimer();
785  if ( this->Interactor )
786  {
787  this->ReleaseFocus();
788  }
789  break;
790  }
791 }
792 
794 {
795  this->m_shooterMode = HOVER;
796  this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
797  this->Interactor->GetEventPosition()[1]);
798  if (this->CurrentRenderer == nullptr)
799  {
800  return;
801  }
802 
803  GrabFocus(this->EventCallbackCommand, nullptr);
804  this->StartTimer();
805 
806  // Save klicked position to determine rotation speed
807  vtkRenderWindowInteractor *rwi = this->Interactor;
808  m_startCameraMovePosition[0] = rwi->GetEventPosition()[0];
809  m_startCameraMovePosition[1] = rwi->GetEventPosition()[1];
810 }
811 
813 {
814 
815 }
816 
818 {
819 
820 }
821 
823 {
824 
825 }
826 
828 {
829 
830 }
831 
833 {
834  if (this->CurrentRenderer == nullptr)
835  {
836  return;
837  }
838 
839  vtkRenderWindowInteractor *rwi = this->Interactor;
840  vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
841  double *center = this->CurrentRenderer->GetCenter();
842 
843  int dy = rwi->GetEventPosition()[1] - rwi->GetLastEventPosition()[1];
844  double dyf = m_motionFactor * dy / center[1];
845  double zoomFactor = pow(1.1, dyf);
846 
847  if (camera->GetParallelProjection())
848  {
849  camera->SetParallelScale(camera->GetParallelScale() / zoomFactor);
850  }
851  else
852  {
853  camera->Dolly( zoomFactor );
854  if (this->AutoAdjustCameraClippingRange)
855  {
856  this->CurrentRenderer->ResetCameraClippingRange();
857  }
858  }
859 
860  if (rwi->GetLightFollowCamera())
861  {
862  this->CurrentRenderer->UpdateLightsGeometryToFollowCamera();
863  }
864 
865  rwi->Render();
866 }
867 
869 {
870 
871 }
872 
874 {
875  if (this->CurrentRenderer == nullptr)
876  {
877  return;
878  }
879 
880  vtkRenderWindowInteractor *rwi = this->Interactor;
881 
882  // Get the vector of motion
883 
884  double fp[3], focalPoint[3], pos[3], v[3], p1[4], p2[4];
885 
886  vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
887  camera->GetPosition( pos );
888  camera->GetFocalPoint( fp );
889 
890  this->ComputeWorldToDisplay(fp[0], fp[1], fp[2],
891  focalPoint);
892 
893  this->ComputeDisplayToWorld(rwi->GetEventPosition()[0],
894  rwi->GetEventPosition()[1],
895  focalPoint[2],
896  p1);
897 
898  this->ComputeDisplayToWorld(rwi->GetLastEventPosition()[0],
899  rwi->GetLastEventPosition()[1],
900  focalPoint[2],
901  p2);
902 
903  for (int i=0; i<3; i++)
904  {
905  v[i] = p2[i] - p1[i];
906  pos[i] += v[i];
907  fp[i] += v[i];
908  }
909 
910  camera->SetPosition( pos );
911  camera->SetFocalPoint( fp );
912 
913  if (rwi->GetLightFollowCamera())
914  {
915  this->CurrentRenderer->UpdateLightsGeometryToFollowCamera();
916  }
917 
918  rwi->Render();
919 }
920 
922 {
923 
924 }
925 
927 {
928 
929 }
930 
932 {
933  if (this->CurrentRenderer == nullptr)
934  {
935  return;
936  }
937 
938  vtkRenderWindowInteractor *rwi = this->Interactor;
939 
940  int dx = - ( rwi->GetEventPosition()[0] - rwi->GetLastEventPosition()[0] );
941  int dy = - ( rwi->GetEventPosition()[1] - rwi->GetLastEventPosition()[1] );
942 
943  int *size = this->CurrentRenderer->GetRenderWindow()->GetSize();
944 
945  double a = dx / static_cast<double>( size[0]) * 180.0;
946  double e = dy / static_cast<double>( size[1]) * 180.0;
947 
948  if (rwi->GetShiftKey())
949  {
950  if(abs( dx ) >= abs( dy ))
951  {
952  e = 0.0;
953  }
954  else
955  {
956  a = 0.0;
957  }
958  }
959 
960  // Move the camera.
961  // Make sure that we don't hit the north pole singularity.
962 
963  vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
964  camera->Azimuth( a );
965 
966  double dop[3], vup[3];
967 
968  camera->GetDirectionOfProjection( dop );
969  vtkMath::Normalize( dop );
970  camera->GetViewUp( vup );
971  vtkMath::Normalize( vup );
972 
973  double angle = vtkMath::DegreesFromRadians( acos(vtkMath::Dot( dop, vup) ) );
974  if ( ( angle + e ) > 179.0 ||
975  ( angle + e ) < 1.0 )
976  {
977  e = 0.0;
978  }
979 
980  camera->Elevation( e );
981 
982  if ( this->AutoAdjustCameraClippingRange )
983  {
984  this->CurrentRenderer->ResetCameraClippingRange();
985  }
986 
987  rwi->Render();
988 }
989 
991 {
992  this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
993  this->Interactor->GetEventPosition()[1]);
994  if (this->CurrentRenderer == nullptr)
995  {
996  return;
997  }
998 
999  this->GrabFocus(this->EventCallbackCommand);
1000  this->StartRotate();
1001 }
1002 
1004 {
1005  switch (this->State)
1006  {
1007  case VTKIS_ROTATE:
1008  this->EndRotate();
1009  if ( this->Interactor )
1010  {
1011  this->ReleaseFocus();
1012  }
1013  break;
1014  }
1015 }
1016 
1018 {
1019  int x = this->Interactor->GetEventPosition()[0];
1020  int y = this->Interactor->GetEventPosition()[1];
1021 
1022  switch (this->State)
1023  {
1024  case VTKIS_ROTATE:
1025  this->FindPokedRenderer(x, y);
1026  this->Rotate();
1027  this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
1028  break;
1029 
1030  case VTKIS_PAN:
1031  this->FindPokedRenderer(x, y);
1032  this->Pan();
1033  this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
1034  break;
1035 
1036  case VTKIS_DOLLY:
1037  this->FindPokedRenderer(x, y);
1038  this->Dolly();
1039  this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
1040  break;
1041  }
1042 }
1043 
1045 {
1046  switch (this->State)
1047  {
1048  case VTKIS_PAN:
1049  this->EndPan();
1050  if ( this->Interactor )
1051  {
1052  this->ReleaseFocus();
1053  }
1054  break;
1055  }
1056 }
1057 
1059 {
1060  this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
1061  this->Interactor->GetEventPosition()[1]);
1062  if (this->CurrentRenderer == nullptr)
1063  {
1064  return;
1065  }
1066 
1067  this->GrabFocus(this->EventCallbackCommand);
1068  this->StartPan();
1069 }
1070 
1072 {
1073  switch (this->State)
1074  {
1075  case VTKIS_DOLLY:
1076  this->EndDolly();
1077  if ( this->Interactor )
1078  {
1079  this->ReleaseFocus();
1080  }
1081  break;
1082  }
1083 }
1084 
1086 {
1087  this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
1088  this->Interactor->GetEventPosition()[1]);
1089  if (this->CurrentRenderer == nullptr)
1090  {
1091  return;
1092  }
1093 
1094  this->GrabFocus(this->EventCallbackCommand);
1095  this->StartDolly();
1096 }
1097 
1099 {
1100 
1101 }
1102 
1104 {
1105 
1106 }
1107 
1109 {
1110  if (this->CurrentRenderer == nullptr)
1111  {
1112  return;
1113  }
1114 
1115  vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
1116  if (camera->GetParallelProjection())
1117  {
1118  camera->SetParallelScale(camera->GetParallelScale() / factor);
1119  }
1120  else
1121  {
1122  double position[3];
1123  double direction[3];
1124 
1125  camera->GetPosition(position);
1126  camera->GetDirectionOfProjection(direction);
1127 
1128  // Compute desired position
1129  camera->SetPosition(
1130  position[0] - factor * direction[0],
1131  position[1] - factor * direction[1],
1132  position[2] - factor * direction[2]);
1133 
1134  if (this->AutoAdjustCameraClippingRange)
1135  {
1136  this->CurrentRenderer->ResetCameraClippingRange();
1137  }
1138  }
1139 
1140  if (this->Interactor->GetLightFollowCamera())
1141  {
1142  this->CurrentRenderer->UpdateLightsGeometryToFollowCamera();
1143  }
1144 
1145  this->Interactor->Render();
1146 }
1147 
1149 {
1150  if (this->CurrentRenderer == nullptr)
1151  {
1152  return;
1153  }
1154 
1155  vtkRenderWindowInteractor *rwi = this->Interactor;
1156  double *center = this->CurrentRenderer->GetCenter();
1157  int dy = rwi->GetEventPosition()[1] - rwi->GetLastEventPosition()[1];
1158  double dyf = 1 * dy / center[1];
1159 
1160  if (this->CurrentRenderer == nullptr)
1161  {
1162  return;
1163  }
1164 
1165  vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
1166  if (camera->GetParallelProjection())
1167  {
1168  camera->SetParallelScale(camera->GetParallelScale() / dyf);
1169  }
1170  else
1171  {
1172  camera->Dolly(dyf);
1173  if (this->AutoAdjustCameraClippingRange)
1174  {
1175  this->CurrentRenderer->ResetCameraClippingRange();
1176  }
1177  }
1178 
1179  if (this->Interactor->GetLightFollowCamera())
1180  {
1181  this->CurrentRenderer->UpdateLightsGeometryToFollowCamera();
1182  }
1183 
1184  this->Interactor->Render();
1185 }
1186 
1188 {
1189  if (this->CurrentRenderer == nullptr)
1190  {
1191  return;
1192  }
1193 
1194  vtkRenderWindowInteractor *rwi = this->Interactor;
1195 
1196  double viewFocus[4], focalDepth, viewPoint[3];
1197  double newPickPoint[4], oldPickPoint[4], motionVector[3];
1198 
1199  // Calculate the focal depth since we'll be using it a lot
1200 
1201  vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
1202  camera->GetFocalPoint(viewFocus);
1203  this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1], viewFocus[2],
1204  viewFocus);
1205  focalDepth = viewFocus[2];
1206 
1207  this->ComputeDisplayToWorld(rwi->GetEventPosition()[0],
1208  rwi->GetEventPosition()[1],
1209  focalDepth,
1210  newPickPoint);
1211 
1212  // Has to recalc old mouse point since the viewport has moved,
1213  // so can't move it outside the loop
1214 
1215  this->ComputeDisplayToWorld(rwi->GetLastEventPosition()[0],
1216  rwi->GetLastEventPosition()[1],
1217  focalDepth,
1218  oldPickPoint);
1219 
1220  // Camera motion is reversed
1221 
1222  motionVector[0] = oldPickPoint[0] - newPickPoint[0];
1223  motionVector[1] = oldPickPoint[1] - newPickPoint[1];
1224  motionVector[2] = oldPickPoint[2] - newPickPoint[2];
1225 
1226  camera->GetFocalPoint(viewFocus);
1227  camera->GetPosition(viewPoint);
1228  camera->SetFocalPoint(motionVector[0] + viewFocus[0],
1229  motionVector[1] + viewFocus[1],
1230  motionVector[2] + viewFocus[2]);
1231 
1232  camera->SetPosition(motionVector[0] + viewPoint[0],
1233  motionVector[1] + viewPoint[1],
1234  motionVector[2] + viewPoint[2]);
1235 
1236  if (rwi->GetLightFollowCamera())
1237  {
1238  this->CurrentRenderer->UpdateLightsGeometryToFollowCamera();
1239  }
1240 
1241  rwi->Render();
1242 }
1243 
1245 {
1246  if ( this->CurrentRenderer == nullptr )
1247  {
1248  return;
1249  }
1250 
1251  vtkRenderWindowInteractor *rwi = this->Interactor;
1252 
1253  double *center = this->CurrentRenderer->GetCenter();
1254 
1255  double newAngle =
1256  vtkMath::DegreesFromRadians( atan2( rwi->GetEventPosition()[1] - center[1],
1257  rwi->GetEventPosition()[0] - center[0] ) );
1258 
1259  double oldAngle =
1260  vtkMath::DegreesFromRadians( atan2( rwi->GetLastEventPosition()[1] - center[1],
1261  rwi->GetLastEventPosition()[0] - center[0] ) );
1262 
1263  vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
1264  camera->Roll( newAngle - oldAngle );
1265  camera->OrthogonalizeViewUp();
1266 
1267  rwi->Render();
1268 }
1269 
1271 {
1272  this->Zoom();
1273 }
1274 
1276 {
1277  if (this->CurrentRenderer == nullptr)
1278  {
1279  return;
1280  }
1281 
1282  vtkRenderWindowInteractor *rwi = this->Interactor;
1283 
1284  int dx = rwi->GetEventPosition()[0] - rwi->GetLastEventPosition()[0];
1285  int dy = rwi->GetEventPosition()[1] - rwi->GetLastEventPosition()[1];
1286 
1287  int *size = this->CurrentRenderer->GetRenderWindow()->GetSize();
1288 
1289  double delta_elevation = -m_rotationFactor / size[1];
1290  double delta_azimuth = -m_rotationFactor / size[0];
1291 
1292  double rxf = dx * delta_azimuth * m_motionFactor;
1293  double ryf = dy * delta_elevation * m_motionFactor;
1294 
1295  vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
1296  camera->Azimuth(rxf);
1297  camera->Elevation(ryf);
1298  camera->OrthogonalizeViewUp();
1299 
1300  if (this->AutoAdjustCameraClippingRange)
1301  {
1302  this->CurrentRenderer->ResetCameraClippingRange();
1303  }
1304 
1305  if (rwi->GetLightFollowCamera())
1306  {
1307  this->CurrentRenderer->UpdateLightsGeometryToFollowCamera();
1308  }
1309 
1310  rwi->Render();
1311 }
1312 
1314 {
1315  vtkRenderWindowInteractor *rwi = this->Interactor;
1316  m_correspondenceMode = true;
1317  m_textActor->SetInput("Pick first correspondence point...");
1318  m_textActor->VisibilityOn();
1319  rwi->Render();
1321 }
1322 
1324 {
1325  vtkRenderWindowInteractor *rwi = this->Interactor;
1326  m_correspondenceMode = false;
1327  m_pickMode = None;
1328  m_textActor->VisibilityOff();
1329  rwi->Render();
1330 }
1331 
1333 {
1334  vtkRenderWindowInteractor *rwi = this->Interactor;
1335  m_textActor->SetInput("Press \"l\" to select Points");
1336  m_textActor->VisibilityOn();
1337  rwi->Render();
1338 
1339  m_labelingMode = true;
1341  //m_pickMode = PickLabel;
1342 
1343 }
1345 {
1346  vtkRenderWindowInteractor *rwi = this->Interactor;
1347  m_labelingMode = false;
1348  m_pickMode = None;
1349  m_textActor->VisibilityOff();
1350  rwi->Render();
1351 }
1353 {
1354  vtkPointPicker* picker = (vtkPointPicker*)this->Interactor->GetPicker();
1355 
1356  if(m_pickMode == None)
1357  {
1358  this->m_numberOfClicks++;
1359  //std::cout << "m_numberOfClicks = " << this->m_numberOfClicks << std::endl;
1360  int pickPosition[2];
1361  this->GetInteractor()->GetEventPosition(pickPosition);
1362 
1363  int xdist = pickPosition[0] - this->m_previousPosition[0];
1364  int ydist = pickPosition[1] - this->m_previousPosition[1];
1365 
1366  this->m_previousPosition[0] = pickPosition[0];
1367  this->m_previousPosition[1] = pickPosition[1];
1368 
1369  int moveDistance = (int)sqrt((double)(xdist*xdist + ydist*ydist));
1370 
1371  // Reset numClicks - If mouse moved further than resetPixelDistance
1372  if(moveDistance > 5)
1373  {
1374  this->m_numberOfClicks = 1;
1375  }
1376 
1377  if(this->m_numberOfClicks == 2)
1378  {
1379  this->m_numberOfClicks = 0;
1380  double* picked = new double[3];
1381  picker->Pick(pickPosition[0],
1382  pickPosition[1],
1383  0, // always zero.
1384  this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
1385  vtkActor* actor = picker->GetActor();
1386  int point = picker->GetPointId();
1387  Q_EMIT(pointSelected(actor, point));
1388  }
1389  }
1390  else if(m_pickMode == PickFocal)
1391  {
1392  int* pickPos = this->Interactor->GetEventPosition();
1393  double* picked = new double[3];
1394  int res = picker->Pick(this->Interactor->GetEventPosition()[0],
1395  this->Interactor->GetEventPosition()[1],
1396  0, // always zero.
1397  this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
1398 
1399  if(res)
1400  {
1401  picker->GetPickPosition(picked);
1402 
1403  vtkCamera* cam = m_renderer->GetActiveCamera();
1404  cam->SetFocalPoint(picked[0], picked[1], picked[2]);
1405  updateFocalPoint();
1406 
1407  m_textActor->VisibilityOff();
1408  }
1409  m_pickMode = None;
1410  }
1411  else if(m_pickMode == PickLabel)
1412  {
1413 
1414 
1415  }
1416  else
1417  {
1418  int* pickPos = this->Interactor->GetEventPosition();
1419  double* picked = new double[3];
1420  picker->Pick(this->Interactor->GetEventPosition()[0],
1421  this->Interactor->GetEventPosition()[1],
1422  0, // always zero.
1423  this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
1424  picker->GetPickPosition(picked);
1425 
1426  if(m_pickMode == PickFirst)
1427  {
1428  Q_EMIT(firstPointPicked(picked));
1429  }
1430  else if(m_pickMode == PickSecond)
1431  {
1432  Q_EMIT(secondPointPicked(picked));
1433  }
1434  }
1435 }
1437 {
1438  // Code taken from vtkInteractorStyleTrackballCamera
1439  this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
1440  this->Interactor->GetEventPosition()[1]);
1441  if (this->CurrentRenderer == nullptr)
1442  {
1443  return;
1444  }
1445  if(m_labelingMode)
1446  {
1447  // vtkInteractorStyleRubberBandPick::OnLeftButtonDown();
1448  //return;
1449  }
1450 
1451  GrabFocus(this->EventCallbackCommand, nullptr);
1452  if (this->Interactor->GetShiftKey())
1453  {
1454  if (this->Interactor->GetControlKey())
1455  {
1456  this->StartDolly();
1457  }
1458  else
1459  {
1460  this->StartPan();
1461  }
1462  }
1463  else
1464  {
1465  if (this->Interactor->GetControlKey())
1466  {
1467  this->StartSpin();
1468  }
1469  else
1470  {
1471  this->StartRotate();
1472  }
1473  }
1474 }
1475 
1477 {
1478  switch (this->State)
1479  {
1480  case VTKIS_DOLLY:
1481  this->EndDolly();
1482  break;
1483 
1484  case VTKIS_PAN:
1485  this->EndPan();
1486  break;
1487 
1488  case VTKIS_SPIN:
1489  this->EndSpin();
1490  break;
1491 
1492  case VTKIS_ROTATE:
1493  this->EndRotate();
1494  break;
1495  }
1496 
1497  if ( this->Interactor )
1498  {
1499  this->ReleaseFocus();
1500  }
1501 }
1502 
1504 {
1505  int x = this->Interactor->GetEventPosition()[0];
1506  int y = this->Interactor->GetEventPosition()[1];
1507 
1508  switch (this->State)
1509  {
1510  case VTKIS_ROTATE:
1511  this->FindPokedRenderer(x, y);
1512  this->Rotate();
1513  this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
1514  break;
1515 
1516  case VTKIS_PAN:
1517  this->FindPokedRenderer(x, y);
1518  this->Pan();
1519  this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
1520  break;
1521 
1522  case VTKIS_DOLLY:
1523  this->FindPokedRenderer(x, y);
1524  this->Dolly();
1525  this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
1526  break;
1527 
1528  case VTKIS_SPIN:
1529  this->FindPokedRenderer(x, y);
1530  this->Spin();
1531  this->InvokeEvent(vtkCommand::InteractionEvent, nullptr);
1532  break;
1533  }
1534 }
1535 
1537 {
1538  switch (this->State)
1539  {
1540  case VTKIS_PAN:
1541  this->EndPan();
1542  if ( this->Interactor )
1543  {
1544  this->ReleaseFocus();
1545  }
1546  break;
1547  }
1548 }
1549 
1551 {
1552  this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
1553  this->Interactor->GetEventPosition()[1]);
1554  if (this->CurrentRenderer == nullptr)
1555  {
1556  return;
1557  }
1558 
1559  this->GrabFocus(this->EventCallbackCommand);
1560  this->StartDolly();
1561  double factor = m_motionFactor * this->MouseWheelMotionFactor;
1562  this->Dolly(-pow(1.1, factor));
1563  this->EndDolly();
1564  this->ReleaseFocus();
1565 }
1566 
1568 {
1569  this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
1570  this->Interactor->GetEventPosition()[1]);
1571  if (this->CurrentRenderer == nullptr)
1572  {
1573  return;
1574  }
1575 
1576  this->GrabFocus(this->EventCallbackCommand);
1577  this->StartDolly();
1578  double factor = m_motionFactor * this->MouseWheelMotionFactor;
1579  this->Dolly(pow(1.1, factor));
1580  this->EndDolly();
1581  this->ReleaseFocus();
1582 }
1583 
1585 {
1586  this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
1587  this->Interactor->GetEventPosition()[1]);
1588  if (this->CurrentRenderer == nullptr)
1589  {
1590  return;
1591  }
1592 
1593  this->GrabFocus(this->EventCallbackCommand);
1594  this->StartPan();
1595 }
1596 
1598 {
1599  switch (this->State)
1600  {
1601  case VTKIS_DOLLY:
1602  this->EndDolly();
1603 
1604  if ( this->Interactor )
1605  {
1606  this->ReleaseFocus();
1607  }
1608  break;
1609  }
1610 }
1611 
1613 {
1614  this->FindPokedRenderer(this->Interactor->GetEventPosition()[0],
1615  this->Interactor->GetEventPosition()[1]);
1616  if (this->CurrentRenderer == nullptr)
1617  {
1618  return;
1619  }
1620 
1621  this->GrabFocus(this->EventCallbackCommand);
1622  this->StartDolly();
1623 }
1624 
1625 
1627 {
1628 
1629 }
1630 
1632 {
1633  vtkRenderWindowInteractor *rwi = this->Interactor;
1634  std::string key = rwi->GetKeySym();
1635 
1636  if(key == "Escape" && m_labelingMode)
1637  {
1638  discardChanges();
1639  }
1640  if(key == "Return" && m_labelingMode)
1641  {
1644  {
1645  calculateSelection(true);
1646  }
1648  }
1649  if(key == "x" && m_correspondenceMode)
1650  {
1651  m_textActor->SetInput("Pick first correspondence point...");
1652  m_textActor->VisibilityOn();
1653  rwi->Render();
1655  }
1656 
1657  if(key == "y" && m_correspondenceMode)
1658  {
1659  m_textActor->SetInput("Pick second correspondence point...");
1660  m_textActor->VisibilityOn();
1661  rwi->Render();
1663  }
1664  if(m_labelingMode && key == "l")
1665  {
1667  }
1668 
1669  if(key == "f")
1670  {
1671  pickFocalPoint();
1672  }
1673 
1674  if(key == "q")
1675  {
1676  m_textActor->VisibilityOff();
1677  m_pickMode = None;
1678  rwi->Render();
1679  }
1680 
1681 
1682 }
1683 
1685 {
1686  if(m_pickMode == PickLabel)
1687  {
1688 
1690  return;
1691  }
1692  if(m_interactorMode == SHOOTER)
1693  {
1694  vtkRenderWindowInteractor *rwi = this->Interactor;
1695  vtkCamera* cam = this->CurrentRenderer->GetActiveCamera();
1696  switch (rwi->GetKeyCode())
1697  {
1698  case 'w':
1699  case 'W':
1700  dollyShooter(-this->m_motionFactor);
1701  break;
1702  case 'a':
1703  case 'A':
1704  strafeShooter(-this->m_motionFactor);
1705  break;
1706  case 's':
1707  case 'S':
1709  break;
1710  case 'd':
1711  case 'D':
1713  cout << "D" << endl;
1714  break;
1715  case 'u':
1716  case 'U':
1718  break;
1719  case '1':
1720  m_viewUp[0] = 1.0;
1721  m_viewUp[1] = 0.0;
1722  m_viewUp[2] = 0.0;
1724  break;
1725  case '2':
1726  m_viewUp[0] = 0.0;
1727  m_viewUp[1] = 1.0;
1728  m_viewUp[2] = 0.0;
1730  break;
1731  case '3':
1732  m_viewUp[0] = 0.0;
1733  m_viewUp[1] = 0.0;
1734  m_viewUp[2] = 1.0;
1736  break;
1737  case 'R':
1738  case 'r':
1739  resetCamera();
1740  break;
1741  }
1742  }
1743 
1744  else
1745  {
1746  vtkInteractorStyle::OnChar();
1747  }
1748 }
1749 
1751 {
1752  vtkRenderWindowInteractor *rwi = this->Interactor;
1753  m_textActor->SetInput("Pick new camera focal point...");
1754  m_textActor->VisibilityOn();
1755  rwi->Render();
1757 }
1758 
1760 {
1761 
1762 }
1763 
1764 bool LVRPickingInteractor::isInside(std::vector<vtkVector2i>* polygon, int& pX, int& pY)
1765 {
1766  int n = polygon->size();
1767  if (n < 3) return false;
1768 
1769  int i, j, c = 0;
1770  for(i = 0, j = n -1; i < n ; j = i++)
1771  {
1772  auto& vert = polygon->at(j);
1773  auto& vert_next = polygon->at(i);
1774 
1775  if (((vert_next.GetY() > pY) != (vert.GetY() > pY)) &&
1776  (pX < (vert.GetX() - vert_next.GetX()) * (pY - vert_next.GetY()) / (vert.GetY() - vert_next.GetY()) + vert_next.GetX()))
1777  {
1778  c = !c;
1779  }
1780  }
1781  return c;
1782 }
1783 
1784 
1786 {
1787 
1788  // Forward events
1790 
1791  if (!m_points)
1792  {
1793  return;
1794  }
1795 
1796  if (m_labelActors.find(m_selectedLabel) != m_labelActors.end())
1797  {
1798  this->CurrentRenderer->RemoveActor(m_labelActors[m_selectedLabel]);
1799  }
1800 
1801  this->CurrentRenderer->RemoveActor(m_selectedActor);
1802  m_selectedActor = vtkSmartPointer<vtkActor>::New();
1803  m_selectedMapper = vtkSmartPointer<vtkDataSetMapper>::New();
1804  m_selectedActor->SetMapper(m_selectedMapper);
1805 
1806  vtkPlanes* frustum = static_cast<vtkAreaPicker*>(this->GetInteractor()->GetPicker())->GetFrustum();
1807 
1808  vtkSmartPointer<vtkExtractGeometry> extractGeometry =
1809  vtkSmartPointer<vtkExtractGeometry>::New();
1810  extractGeometry->SetImplicitFunction(frustum);
1811 #if VTK_MAJOR_VERSION <= 5
1812  extractGeometry->SetInput(m_points);
1813 #else
1814  extractGeometry->SetInputData(m_points);
1815 #endif
1816  extractGeometry->Update();
1817 
1818  vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
1819  vtkSmartPointer<vtkVertexGlyphFilter>::New();
1820  glyphFilter->SetInputConnection(extractGeometry->GetOutputPort());
1821  glyphFilter->Update();
1822 
1823  vtkPolyData* selected = glyphFilter->GetOutput();
1824 
1825  vtkIdTypeArray* ids = vtkIdTypeArray::SafeDownCast(selected->GetPointData()->GetArray("OriginalIds"));
1826  m_selectedIds = vtkIdTypeArray::SafeDownCast(selected->GetPointData()->GetArray("OriginalIds"));
1827 
1828  //TODO Check if smart Pointer realy necassary
1829  vtkSmartPointer<vtkCoordinate> coordinate = vtkSmartPointer<vtkCoordinate>::New();
1830  coordinate->SetCoordinateSystemToWorld();
1831 
1832  std::vector<vtkVector2i> polygonPoints = this->GetPolygonPoints();
1833  std::vector<int> selectedPolyPoints;
1834  selectedPolyPoints.resize(ids->GetNumberOfTuples());
1835 
1836  for (vtkIdType i = 0; i < ids->GetNumberOfTuples(); i++)
1837  {
1838  auto selectedPoint = m_points->GetPoint(ids->GetValue(i));
1839  coordinate->SetValue(selectedPoint[0], selectedPoint[1], selectedPoint[2]);
1840  int* displayCoord;
1841  displayCoord = coordinate->GetComputedViewportValue(this->CurrentRenderer);
1842  if (isInside(&polygonPoints, displayCoord[0], displayCoord[1]))
1843  {
1844  selectedPolyPoints.push_back(ids->GetValue(i));
1845  }
1846  }
1847 
1848 #if VTK_MAJOR_VERSION <= 5
1849  m_selectedMapper->SetInput(selected);
1850 #else
1851  m_selectedMapper->SetInputData(selected);
1852 #endif
1853  m_selectedMapper->ScalarVisibilityOff();
1854 
1855  for(auto selectedPolyPoint : selectedPolyPoints)
1856  {
1857  m_selectedPoints[selectedPolyPoint] = select;
1858  }
1859 
1860  auto vertexFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New();
1861  auto selectedVtkPoints = vtkSmartPointer<vtkPoints>::New();
1862 
1863  double point[3];
1864  for (int i = 0; i < m_selectedPoints.size(); i++)
1865  {
1866  if (m_selectedPoints[i])
1867  {
1868  m_points->vtkDataSet::GetPoint(i, point);
1869  selectedVtkPoints->InsertNextPoint(point);
1870  }
1871  }
1872  if (selectedPolyPoints.size() > 0)
1873  {
1874  m_modified = true;
1875  }
1876 
1877  auto selectedVtkPoly = vtkSmartPointer<vtkPolyData>::New();
1878  selectedVtkPoly->SetPoints(selectedVtkPoints);
1879 
1880 
1881  vertexFilter->SetInputData(selectedVtkPoly);
1882  vertexFilter->Update();
1883 
1884  auto polyData = vtkSmartPointer<vtkPolyData>::New();
1885  polyData->ShallowCopy(vertexFilter->GetOutput());
1886 
1887 #if VTK_MAJOR_VERSION <= 5
1888  m_selectedMapper->SetInput(polyData);
1889 #else
1890  m_selectedMapper->SetInputData(polyData);
1891 #endif
1892  m_selectedMapper->ScalarVisibilityOff();
1893 
1894 
1895  int r, g, b;
1896  if(!m_labelColors.empty())
1897  {
1898  m_labelColors[m_selectedLabel].getRgb(&r, &g, &b);
1899  m_selectedActor->GetProperty()->SetColor(r/255.0, g/255.0, b/255.0); //(R,G,B)
1900  }
1901  //SelectedActor->GetProperty()->SetPointSize(3);
1902 
1903  m_renderer->AddActor(m_selectedActor);
1904  this->GetInteractor()->GetRenderWindow()->Render();
1905  this->HighlightProp(NULL);
1906 
1907 }
1908 
1909 void LVRPickingInteractor::newLabel(QTreeWidgetItem* item)
1910 {
1911  m_labelColors[item->data(3,0).toInt()] = item->data(3,1).value<QColor>();
1912  if(m_labelColors.size() == 1)
1913  {
1914  //first Label set as the choosen label
1915  m_selectedLabel = item->data(3,0).toInt();
1916  }
1917  if(m_labelActors.find(item->data(3,0).toInt()) != m_labelActors.end())
1918  {
1919  //Instance known just change color
1920  int r,g,b;
1921  m_labelColors[item->data(3,0).toInt()].getRgb(&r, &g, &b);
1922  m_labelActors[item->data(3,0).toInt()]->GetProperty()->SetColor(r/255.0, g/255.0, b/255.0); //(R,G,B)
1923  this->GetInteractor()->GetRenderWindow()->Render();
1924  this->HighlightProp(NULL);
1925  }
1926  /*
1927  if (item->data(3,0).toInt() == 0)
1928  {
1929  //Add Actor for all Unlabeled Points
1930  auto unlabeledMapper = vtkSmartPointer<vtkDataSetMapper>::New();
1931  auto unlabeledActor = vtkSmartPointer<vtkActor>::New();
1932  unlabeledActor->SetMapper(unlabeledMapper);
1933 
1934  //Crete copy of points
1935  double point[3];
1936  auto selectedVtkPoints = vtkSmartPointer<vtkPoints>::New();
1937  for (int i = 0; i < m_selectedPoints.size(); i++)
1938  {
1939  m_points->vtkDataSet::GetPoint(i, point);
1940  selectedVtkPoints->InsertNextPoint(point);
1941  }
1942 
1943  auto selectedVtkPoly = vtkSmartPointer<vtkPolyData>::New();
1944  selectedVtkPoly->SetPoints(selectedVtkPoints);
1945  auto vertexFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New();
1946  vertexFilter->SetInputData(selectedVtkPoly);
1947  vertexFilter->Update();
1948 
1949  auto polyData = vtkSmartPointer<vtkPolyData>::New();
1950  polyData->ShallowCopy(vertexFilter->GetOutput());
1951 
1952 
1953 #if VTK_MAJOR_VERSION <= 5
1954  unlabeledMapper->SetInput(polyData);
1955 #else
1956  unlabeledMapper->SetInputData(polyData);
1957 #endif
1958  unlabeledMapper->ScalarVisibilityOff();
1959 
1960  unlabeledActor->GetProperty()->SetColor(1,0.0,0.0); //(R,G,B)
1961 
1962  if(m_labelActors.find(0) != m_labelActors.end())
1963  {
1964  this->CurrentRenderer->RemoveActor(m_labelActors[0]);
1965  std::cout << "remove actor bedore" << std::endl;
1966  }
1967  m_labelActors[0] = unlabeledActor;
1968 
1969  m_renderer->AddActor(unlabeledActor);
1970  }*/
1971 }
1972 
1974 {
1975  int count = 0;
1976  std::set<uint16_t> modifiedActors;
1977  for (int i = 0; i < m_selectedPoints.size(); i++)
1978  {
1979  //Set Current selection as new selection for the selected label
1980  if(m_selectedPoints[i])
1981  {
1982  if(m_pointLabels[i] != m_selectedLabel)
1983  {
1984  //Only update if necessary
1985  modifiedActors.insert(m_pointLabels[i]);
1987  }
1988  count++;
1989  }
1990  else
1991  {
1992  //Check if Points were labeled before by this label
1993  if (m_pointLabels[i] == m_selectedLabel)
1994  {
1995  //Set to unlabeled
1996  m_pointLabels[i] = 0;
1997  modifiedActors.insert(0);
1998  }
1999  }
2000  }
2001 
2002  if(m_labelActors.find(m_selectedLabel) != m_labelActors.end())
2003  {
2004  this->CurrentRenderer->RemoveActor(m_labelActors[m_selectedLabel]);
2005  }
2006  if (modifiedActors.size() > 0)
2007  {
2008  m_modified = false;
2009  }
2010  Q_EMIT(pointsLabeled(m_selectedLabel, count));
2011 
2012  for (auto modifiedActorLabel : modifiedActors)
2013  {
2014  //redraw Actor
2015  updateActor(modifiedActorLabel);
2016  }
2017 
2018  //Save Current Actor
2020 
2021  //create new Selection Actor
2022  m_selectedActor = vtkSmartPointer<vtkActor>::New();
2023 }
2024 
2026 {
2027  //Undo Changes
2028  m_renderer->RemoveActor(m_selectedActor);
2029  if(m_labelActors.find(m_selectedLabel) != m_labelActors.end())
2030  {
2031  for (int i = 0; i < m_pointLabels.size(); i++)
2032  {
2034 
2035  }
2037  this->GetInteractor()->GetRenderWindow()->Render();
2038  this->HighlightProp(NULL);
2039 
2040  } else
2041  {
2042  //Label has no selected points just reset selected and delete actor
2043  std::fill(m_selectedPoints.begin(), m_selectedPoints.end(), 0);
2044  m_selectedActor = vtkSmartPointer<vtkActor>::New();
2045  }
2046  m_modified = false;
2047 }
2049 {
2050  if(m_selectedLabel == newLabel)
2051  {
2052  return;
2053  }
2054  if (m_modified)
2055  {
2056  QMessageBox acceptDialog;
2057  acceptDialog.setText("The Label has been modified. Do you want to save your changes?");
2058  acceptDialog.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
2059  acceptDialog.setDefaultButton(QMessageBox::Save);
2060  int returnValue = acceptDialog.exec();
2061  switch(returnValue)
2062  {
2063  case QMessageBox::Save:
2065  break;
2066  case QMessageBox::Discard:
2067  discardChanges();
2068  break;
2069  }
2070 
2071  }
2072  m_modified = false;
2074  //TODO ask if Changes should be safed
2075 
2076 
2077  for (int i = 0; i < m_pointLabels.size(); i++)
2078  {
2080 
2081  }
2082 }
2083 
2085 {
2086  Q_EMIT(responseLabels(m_pointLabels));
2087 }
2089 {
2090  if(m_labelActors.find(id) == m_labelActors.end())
2091  {
2092  //TODO Add new empty actor and set visibility so the choice is kept
2093  return;
2094  }
2095 
2096  m_labelActors[id]->SetVisibility(visibility);
2097  vtkRenderWindowInteractor *rwi = this->Interactor;
2098  rwi->Render();
2099 }
2100 
2102 {
2103  if (lassoToolSelected)
2104  {
2106  }else
2107  {
2109  }
2110 }
2111 
2112 void LVRPickingInteractor::setLabel(int labelId, std::vector<int> pointIds)
2113 {
2114 
2115  for (int pointId : pointIds)
2116  {
2117  m_pointLabels[pointId] = labelId;
2118  //TODO Check if other Actor was changed
2119  }
2120  //UpdateActor
2121  updateActor(labelId);
2122 }
2123 
2125 {
2126  auto updateMapper = vtkSmartPointer<vtkDataSetMapper>::New();
2127  auto updatedActor = vtkSmartPointer<vtkActor>::New();
2128  updatedActor->SetMapper(updateMapper);
2129 
2130  //Crete copy of points
2131  double point[3];
2132  auto selectedVtkPoints = vtkSmartPointer<vtkPoints>::New();
2133  int count = 0;
2134  for (int i = 0; i < m_pointLabels.size(); i++)
2135  {
2136  if (labelId == m_pointLabels[i])
2137  {
2138  count++;
2139  m_points->vtkDataSet::GetPoint(i, point);
2140  selectedVtkPoints->InsertNextPoint(point);
2141  }
2142  }
2143  Q_EMIT(pointsLabeled(labelId, count));
2144 
2145  auto updatedVtkPoly = vtkSmartPointer<vtkPolyData>::New();
2146  updatedVtkPoly->SetPoints(selectedVtkPoints);
2147  auto vertexFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New();
2148  vertexFilter->SetInputData(updatedVtkPoly);
2149  vertexFilter->Update();
2150 
2151  auto polyData = vtkSmartPointer<vtkPolyData>::New();
2152  polyData->ShallowCopy(vertexFilter->GetOutput());
2153 
2154 
2155 #if VTK_MAJOR_VERSION <= 5
2156  updatedMapper->SetInput(polyData);
2157 #else
2158  updateMapper->SetInputData(polyData);
2159 #endif
2160  updateMapper->ScalarVisibilityOff();
2161 
2162  int r, g, b;
2163  m_labelColors[labelId].getRgb(&r, &g, &b);
2164  updatedActor->GetProperty()->SetColor(r/255.0, g/255.0, b/255.0); //(R,G,B)
2165 
2166  //Get Visiibility and Discard old Actor after that
2167  bool visibility = true;
2168  if (m_labelActors.find(labelId) != m_labelActors.end())
2169  {
2170  visibility = m_labelActors[labelId]->GetVisibility();
2171  m_renderer->RemoveActor(m_labelActors[labelId]);
2172  }
2173  updatedActor->SetVisibility(visibility);
2174  m_labelActors[labelId] = updatedActor;
2175  m_renderer->AddActor(updatedActor);
2176 
2177  this->GetInteractor()->GetRenderWindow()->Render();
2178  this->HighlightProp(NULL);
2179 }
2180 
2182 {
2183 
2184  //Check if no Labels were created
2185  if( m_labelColors.empty())
2186  {
2187  QMessageBox noLabelDialog;
2188  noLabelDialog.setText("No Label Instance was created! Create an instance beofre labeling Points.");
2189  noLabelDialog.setStandardButtons(QMessageBox::Ok);
2190  noLabelDialog.setIcon(QMessageBox::Warning);
2191  int returnValue = noLabelDialog.exec();
2192  return;
2193 
2194  }
2195  Q_EMIT(labelingStarted(true));
2197 
2198 }
2199 
2200 std::vector<uint16_t>& LVRPickingInteractor::getLabeles()
2201 {
2202  return m_pointLabels;
2203 }
2204 vtkSmartPointer<vtkPolyData> LVRPickingInteractor::getPoints()
2205 {
2206  return m_points;
2207 }
2209 {
2210  if (m_labelActors.find(id) == m_labelActors.end())
2211  {
2212  //id unknown nothing to da
2213  return;
2214  }
2215 
2216  //Remove Actor
2217  m_renderer->RemoveActor(m_labelActors[id]);
2218  m_labelActors.erase(id);
2219 
2220  //update labeledpoints to unlabeled
2221  for(auto & pointlabel : m_pointLabels)
2222  {
2223  if (pointlabel == id)
2224  {
2225  //Set all points with this label to Unlabeled
2226  pointlabel = 0;
2227  }
2228  }
2229  updateActor(0);
2230 
2231 }
2232 
2233 } /* namespace lvr2 */
void pointSelected(vtkActor *, int)
vtkSmartPointer< vtkActor > m_selectedActor
bool isInside(std::vector< vtkVector2i > *polygon, int &pX, int &pY)
std::vector< uint16_t > & getLabeles()
vtkSmartPointer< vtkDataSetMapper > m_selectedMapper
void setPoints(vtkSmartPointer< vtkPolyData > points)
void responseLabels(std::vector< uint16_t >)
vtkSmartPointer< vtkActor > m_sphereActor
void secondPointPicked(double *)
vtkSmartPointer< vtkRenderer > m_renderer
std::map< uint16_t, vtkSmartPointer< vtkActor > > m_labelActors
vtkSmartPointer< vtkIdTypeArray > m_selectedIds
std::vector< bool > m_selectedPoints
void setLabel(int, std::vector< int >)
void pointsLabeled(uint16_t, int)
void newLabel(QTreeWidgetItem *)
void setRenderer(vtkSmartPointer< vtkRenderer > renderer)
SharedPointer p
T abs(T x)
Definition: nanoflann.hpp:237
std::vector< uint16_t > m_pointLabels
vtkSmartPointer< vtkTextActor > m_textActor
Text actor to display info if in picking mode.
PickMode m_pickMode
Indicates picking mode.
void firstPointPicked(double *)
std::map< uint16_t, QColor > m_labelColors
virtual void OnLeftButtonDown()
Overloaded mouse event handling.
virtual void OnKeyPress()
Overloaded keyboard press event handling.
vtkSmartPointer< vtkPolyData > m_points
vtkStandardNewMacro(LVRPickingInteractor)
vtkSmartPointer< vtkPolyData > getPoints()
virtual void OnKeyRelease()
Overloaded keyboard release event handling.
void setRotationFactor(double factor)
#define NULL
Definition: mydefs.hpp:141
__kf_hdevice__ float3 cross(const float3 &v1, const float3 &v2)
Definition: temp_utils.hpp:102
std::vector< vtkVector2i > GetPolygonPoints()


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:08