+ if ( VisibleInWindow > -1 ) {
+ if (event == vtkCommand::KeyPressEvent) {
+ std::string KeyPress = isi->GetInteractor()->GetKeySym();
+ if (KeyPress == "Tab") {
+ if(isi->GetInteractor()->GetShiftKey())
+ this->SM->PrevImage(VisibleInWindow);
+ else
+ this->SM->NextImage(VisibleInWindow);
+ return;
+ }
+ if (KeyPress == "f" || KeyPress == "F") {
+ FlyToPosition(isi->GetInteractor(),this->SM->GetSlicer(VisibleInWindow));
+ return;
+ }
+ if (KeyPress == "w") {
+ this->SM->SetLocalColorWindowing(VisibleInWindow);
+ return;
+ }
+ if (KeyPress == "0") {
+ this->SM->SetPreset(0);
+ this->SM->UpdateWindowLevel();
+ return;
+ }
+ if (KeyPress == "1") {
+ this->SM->SetPreset(1);
+ this->SM->UpdateWindowLevel();
+ return;
+ }
+ if (KeyPress == "2") {
+ this->SM->SetPreset(2);
+ this->SM->UpdateWindowLevel();
+
+ return;
+ }
+ if (KeyPress == "3") {
+ this->SM->SetPreset(3);
+ this->SM->UpdateWindowLevel();
+ return;
+ }
+ if (KeyPress == "4") {
+ this->SM->SetPreset(4);
+ this->SM->UpdateWindowLevel();
+ return;
+ }
+ if (KeyPress == "5") {
+ this->SM->SetPreset(5);
+ this->SM->UpdateWindowLevel();
+ return;
+ }
+ if (KeyPress == "6") {
+ this->SM->SetColorMap(0);
+ this->SM->UpdateWindowLevel();
+ return;
+ }
+ if (KeyPress == "7") {
+ this->SM->SetColorMap(1);
+ this->SM->UpdateWindowLevel();
+ return;
+ }
+ if (KeyPress == "8") {
+ this->SM->SetColorMap(2);
+ this->SM->UpdateWindowLevel();
+ return;
+ }
+ if (KeyPress == "9") {
+ this->SM->SetColorMap(3);
+ this->SM->UpdateWindowLevel();
+ return;
+ }
+ if (KeyPress == "equal") { //keycodes are in vtkWin32RenderWindowInteractor
+ this->SM->SetPreset(7);
+ //this->SM->SetColorMap(1);
+ this->SM->UpdateWindowLevel();
+ return;
+ }
+ if (KeyPress == "minus") {
+ this->SM->SetColorWindow(-this->SM->GetColorWindow());
+ this->SM->SetColorMap(-1);
+ this->SM->UpdateWindowLevel();
+ return;
+ }
+ if (KeyPress == "c") {
+ this->SM->ToggleContourSuperposition();
+ this->SM->Render();
+ return;
+ }
+ if (KeyPress == "l") {
+ this->SM->ToggleInterpolation();
+ this->SM->Render();
+ return;
+ }
+ if (KeyPress == "h") {
+ this->SM->SetCursorVisibility(0);
+ this->SM->Render();
+ return;
+ }
+ if (KeyPress == "x") {
+ for(int i=0; i<SM->NumberOfSlicers(); i++) {
+ SM->RemoveActor("overlay",0);
+ SM->SetColorMap(0);
+ SM->Render();
+ }
+ return;
+ }
+ if (KeyPress == "u") {
+ this->SM->Reload();
+ this->SM->Render();
+ return;
+ }
+ if (KeyPress == "r" || KeyPress=="R") {
+ this->SM->GetSlicer(VisibleInWindow)->ResetCamera();
+ this->SM->GetSlicer(VisibleInWindow)->Render();
+ return;
+ }
+ if (KeyPress == "g") {
+ double* cursorPos = this->SM->GetSlicer(VisibleInWindow)->GetCursorPosition();
+ this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(
+ cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]);
+ this->SM->UpdateViews(1,VisibleInWindow);
+ this->SM->UpdateLinked(VisibleInWindow);
+ return;
+ }
+ if (KeyPress == "F5") {
+ this->SM->GetSlicer(VisibleInWindow)->FlipHorizontalView();
+ this->SM->GetSlicer(VisibleInWindow)->Render();
+ return;
+ }
+ if (KeyPress == "F6") {
+ this->SM->GetSlicer(VisibleInWindow)->FlipVerticalView();
+ this->SM->GetSlicer(VisibleInWindow)->Render();
+ return;
+ }
+ if (KeyPress == "Up") {
+ // DD("------------ up");
+ this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()+1);
+ //DD("------------ after set slice");
+ this->SM->UpdateInfoOnCursorPosition(VisibleInWindow);
+ //DD("------------ after UpdateInfoOnCursorPosition");
+ this->SM->UpdateSlice(VisibleInWindow);
+ //DD("------------ after updateslice");
+ }
+ if (KeyPress == "Down") {
+ this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()-1);
+ this->SM->UpdateSlice(VisibleInWindow);
+ this->SM->UpdateInfoOnCursorPosition(VisibleInWindow);
+ }
+ if (KeyPress == "space") {
+ newLandmark = true;
+ }
+ if (KeyPress == "Left")
+ this->SM->SetPreviousTSlice(VisibleInWindow);
+ if (KeyPress == "Right")
+ this->SM->SetNextTSlice(VisibleInWindow);
+
+ if (KeyPress == "F2") {
+ this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetText(2,"Sagital\n<slice>");
+ this->SM->GetSlicer(VisibleInWindow)->SetSliceOrientation(0);
+ this->SM->UpdateSliceRange(VisibleInWindow);
+ this->SM->UpdateInfoOnCursorPosition(VisibleInWindow);
+ }
+ if (KeyPress == "F3") {
+ this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetText(2,"Coronal\n<slice>");
+ this->SM->GetSlicer(VisibleInWindow)->SetSliceOrientation(1);
+ this->SM->UpdateSliceRange(VisibleInWindow);
+ this->SM->UpdateInfoOnCursorPosition(VisibleInWindow);
+ }
+ if (KeyPress == "F4") {
+ this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetText(2,"Axial\n<slice>");
+ this->SM->GetSlicer(VisibleInWindow)->SetSliceOrientation(2);
+ this->SM->UpdateSliceRange(VisibleInWindow);
+ this->SM->UpdateInfoOnCursorPosition(VisibleInWindow);
+ }
+
+ }
+
+ //All type of mouse events
+ if (event == vtkCommand::LeaveEvent) {
+ this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX,
+ -VTK_DOUBLE_MAX,this->SM->GetSlicer(VisibleInWindow)->GetTSlice());
+ this->SM->GetSlicer(VisibleInWindow)->Render();
+ return;
+ }
+
+ //DD(event);
+ // Mouse release HERE
+ if (event == vtkCommand::EndPickEvent) {
+ // DD(VisibleInWindow);
+ if (VisibleInWindow > -1)
+ this->SM->LeftButtonReleaseEvent(VisibleInWindow);
+ return; // no return !!!! ???
+ }
+
+ if (event == vtkCommand::StartWindowLevelEvent) {
+ mStartSlicer = -1;
+ this->InitialWindow = this->SM->GetColorWindow();
+ this->InitialLevel = this->SM->GetColorLevel();
+
+ if (VisibleInWindow > -1) {
+ mStartSlicer = VisibleInWindow;
+ }
+ return;
+ }
+
+ if (event == vtkCommand::EndWindowLevelEvent) {
+ mStartSlicer = -1;
+ }
+
+ if (event == vtkCommand::EndInteractionEvent) {
+ this->SM->UpdateLinkedNavigation(this->SM->GetSlicer(VisibleInWindow),true);
+ return;
+ }
+ }
+ if (VisibleInWindow > -1) {
+ this->SM->Activated();
+ //if(!this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->GetVisibility())
+ this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetVisibility(1);
+
+ if (event == vtkCommand::MouseWheelForwardEvent && !isi->GetInteractor()->GetControlKey()) {
+ this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()+1);
+ this->SM->UpdateSlice(VisibleInWindow);
+ this->SM->UpdateInfoOnCursorPosition(VisibleInWindow);
+ } else if (event == vtkCommand::MouseWheelForwardEvent && isi->GetInteractor()->GetControlKey()) {
+ double factor = 2;
+ this->Dolly(pow((double)1.1, factor),isi->GetInteractor());
+ Execute(caller, vtkCommand::EndInteractionEvent, NULL);
+ } else if (event == vtkCommand::MouseWheelBackwardEvent && !isi->GetInteractor()->GetControlKey()) {
+ this->SM->GetSlicer(VisibleInWindow)->SetSlice(this->SM->GetSlicer(VisibleInWindow)->GetSlice()-1);
+ this->SM->UpdateSlice(VisibleInWindow);
+ this->SM->UpdateInfoOnCursorPosition(VisibleInWindow);
+ } else if (event == vtkCommand::MouseWheelBackwardEvent && isi->GetInteractor()->GetControlKey()) {
+ double factor = -2;
+ this->Dolly(pow((double)1.1, factor),isi->GetInteractor());
+ Execute(caller, vtkCommand::EndInteractionEvent, NULL);
+ }
+ double xWorld=0;
+ double yWorld=0;
+ double zWorld=0;
+
+ //Move into World Coordinate
+ renderer->DisplayToNormalizedDisplay(x,y);
+ renderer->NormalizedDisplayToViewport(x,y);
+ renderer->ViewportToNormalizedViewport(x,y);
+ renderer->NormalizedViewportToView(x,y,z);
+ renderer->ViewToWorld(x,y,z);
+ switch (this->SM->GetSlicer(VisibleInWindow)->GetSliceOrientation()) {
+ case vtkImageViewer2::SLICE_ORIENTATION_XY:
+ xWorld = x;
+ yWorld = y;
+ zWorld = this->SM->GetSlicer(VisibleInWindow)->GetSlice()*
+ this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetSpacing()[2] +
+ this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetOrigin()[2];
+ break;
+
+ case vtkImageViewer2::SLICE_ORIENTATION_XZ:
+ xWorld = x;
+ yWorld = this->SM->GetSlicer(VisibleInWindow)->GetSlice()*
+ this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetSpacing()[1] +
+ this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetOrigin()[1];
+ zWorld = z;
+ break;
+
+ case vtkImageViewer2::SLICE_ORIENTATION_YZ:
+ xWorld = this->SM->GetSlicer(VisibleInWindow)->GetSlice()*
+ this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetSpacing()[0] +
+ this->SM->GetSlicer(VisibleInWindow)->GetInput()->GetOrigin()[0];
+ yWorld = y;
+ zWorld = z;
+ break;
+ }
+ this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(xWorld,yWorld,zWorld,
+ this->SM->GetSlicer(VisibleInWindow)->GetTSlice());
+ if (newLandmark) {
+ this->SM->AddLandmark(xWorld,yWorld,zWorld,
+ this->SM->GetSlicer(VisibleInWindow)->GetTSlice());
+ this->SM->GetSlicer(VisibleInWindow)->UpdateLandmarks();
+ this->SM->Render();
+ }
+ if (event == vtkCommand::PickEvent || event == vtkCommand::StartPickEvent) {
+ this->SM->UpdateViews(1,VisibleInWindow);
+ this->SM->UpdateLinked(VisibleInWindow);
+ this->SM->UpdateInfoOnCursorPosition(VisibleInWindow);
+ } else {
+ this->SM->GetSlicer(VisibleInWindow)->Render();
+ }
+ //this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(-VTK_DOUBLE_MAX,-VTK_DOUBLE_MAX,
+ //-VTK_DOUBLE_MAX,this->SM->GetSlicer(VisibleInWindow)->GetTSlice());
+ //this->SM->GetSlicer(VisibleInWindow)->Render();
+ }
+
+ if (event == vtkCommand::WindowLevelEvent && mStartSlicer > -1) {
+ this->SM->GetSlicer(mStartSlicer)->GetAnnotation()->SetVisibility(1);
+ // Adjust the window level here
+ int *size = isi->GetInteractor()->GetRenderWindow()->GetSize();
+ double window = this->InitialWindow;
+ double level = this->InitialLevel;
+ double range[2];
+ this->SM->GetImage()->GetScalarRange(range);
+
+ // Compute normalized delta
+ double dx = static_cast<double>(isi->GetWindowLevelCurrentPosition()[0] -
+ isi->GetWindowLevelStartPosition()[0]) / size[0];
+ double dy = static_cast<double>(isi->GetWindowLevelStartPosition()[1] -
+ isi->GetWindowLevelCurrentPosition()[1]) / size[1];
+ //Window is exponential in nature, use exponential to avoid falling into negative numbers
+ dx = std::exp(1.0 * (dx*fabs(dx) + dx)) ; //Quadratic behavior for more reactive interface
+ dy = 0.15 * (dy*fabs(dy) + dy) * (range[1]-range[0]);//Quadratic behavior for more reactive interface
+
+ this->SM->SetColorWindow(window*dx);
+ this->SM->SetColorLevel(level-dy);
+ this->SM->SetPreset(6);
+ this->SM->UpdateWindowLevel();
+ this->SM->Render();
+ return;
+ }
+ }