]> Creatis software - clitk.git/blobdiff - vv/vvSlicerManagerCommand.cxx
Debug RTStruct conversion with empty struc
[clitk.git] / vv / vvSlicerManagerCommand.cxx
index 4122a75fd6f6d5686f988b0b91eeba73d96c7852..9e978324b038d586b63d61420267858ed71d7f1c 100644 (file)
@@ -3,7 +3,7 @@
 
   Authors belong to:
   - University of LYON              http://www.universite-lyon.fr/
-  - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
 
   This software is distributed WITHOUT ANY WARRANTY; without even
@@ -14,7 +14,7 @@
 
   - BSD        See included LICENSE.txt file
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-======================================================================-====*/
+===========================================================================**/
 #include "vvSlicerManagerCommand.h"
 #include "vvSlicerManager.h"
 
@@ -38,7 +38,6 @@
 #include "vtkTransform.h"
 
 #include <cmath>
-
 //------------------------------------------------------------------------------
 vvSlicerManagerCommand::vvSlicerManagerCommand()
 {
@@ -74,7 +73,7 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller,
   if (isi) {
     double x = isi->GetInteractor()->GetEventPosition()[0];
     double y = isi->GetInteractor()->GetEventPosition()[1];
-    double z;
+    double z(4000);
 
     int VisibleInWindow = this->FindSlicerNumber(isi->GetInteractor()->GetRenderWindow());
     vtkRenderer* renderer=NULL;
@@ -85,9 +84,10 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller,
 
 
     if (event == vtkCommand::StartPickEvent && VisibleInWindow == -1) {
-      for (int i = 0; i < this->SM->NumberOfSlicers(); i++) {
-        if (this->SM->GetSlicer(i)->GetCursorVisibility()) {
+      for (int i = 0; i < this->SM->GetNumberOfSlicers(); i++) {
+        if (this->SM->GetSlicer(i)->GetCursorVisibility() && !this->SM->IsLinked()) {
           this->SM->GetSlicer(i)->SetCursorVisibility(0);
+          this->SM->GetSlicer(i)->SetCornerAnnotationVisibility(0);
           this->SM->GetSlicer(i)->Render();
         }
       }
@@ -95,6 +95,7 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller,
     if ( VisibleInWindow > -1 ) {
       if (event == vtkCommand::KeyPressEvent) {
         std::string KeyPress = isi->GetInteractor()->GetKeySym();
+        bool bCtrlKey = isi->GetInteractor()->GetControlKey();
         if (KeyPress == "Tab") {
           if(isi->GetInteractor()->GetShiftKey())
             this->SM->PrevImage(VisibleInWindow);
@@ -107,62 +108,62 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller,
           return;
         }
         if (KeyPress == "w") {
-          this->SM->SetLocalColorWindowing(VisibleInWindow);
+          this->SM->SetLocalColorWindowing(VisibleInWindow, bCtrlKey);
           return;
         }
-        if (KeyPress == "0") {
-          this->SM->SetPreset(0);
+        if (KeyPress == "0" || KeyPress == "KP_0") {
+          this->SM->SetPreset(WL_AUTO);
           this->SM->UpdateWindowLevel();
           return;
         }
-        if (KeyPress == "1") {
-          this->SM->SetPreset(1);
+        if (KeyPress == "1" || KeyPress == "KP_1") {
+          this->SM->SetPreset(WL_HOUNSFIELD);
           this->SM->UpdateWindowLevel();
           return;
         }
-        if (KeyPress == "2") {
-          this->SM->SetPreset(2);
+        if (KeyPress == "2" || KeyPress == "KP_2") {
+          this->SM->SetPreset(WL_SOFTTISSUE);
           this->SM->UpdateWindowLevel();
 
           return;
         }
-        if (KeyPress == "3") {
-          this->SM->SetPreset(3);
+        if (KeyPress == "3" || KeyPress == "KP_3") {
+          this->SM->SetPreset(WL_LUNGS);
           this->SM->UpdateWindowLevel();
           return;
         }
-        if (KeyPress == "4") {
-          this->SM->SetPreset(4);
+        if (KeyPress == "4" || KeyPress == "KP_4") {
+          this->SM->SetPreset(WL_BONES);
           this->SM->UpdateWindowLevel();
           return;
         }
-        if (KeyPress == "5") {
-          this->SM->SetPreset(5);
+        if (KeyPress == "5" || KeyPress == "KP_5") {
+          this->SM->SetPreset(WL_HEAD);
           this->SM->UpdateWindowLevel();
           return;
         }
-        if (KeyPress == "6") {
+        if (KeyPress == "6" || KeyPress == "KP_6") {
           this->SM->SetColorMap(0);
           this->SM->UpdateWindowLevel();
           return;
         }
-        if (KeyPress == "7") {
+        if (KeyPress == "7" || KeyPress == "KP_7") {
           this->SM->SetColorMap(1);
           this->SM->UpdateWindowLevel();
           return;
         }
-        if (KeyPress == "8") {
+        if (KeyPress == "8" || KeyPress == "KP_8") {
           this->SM->SetColorMap(2);
           this->SM->UpdateWindowLevel();
           return;
         }
-        if (KeyPress == "9") {
+        if (KeyPress == "9" || KeyPress == "KP_9") {
           this->SM->SetColorMap(3);
           this->SM->UpdateWindowLevel();
           return;
         }
         if (KeyPress == "equal") { //keycodes are in vtkWin32RenderWindowInteractor
-          this->SM->SetPreset(7);
+          this->SM->SetPreset(WL_VENTILATION);
           //this->SM->SetColorMap(1);
           this->SM->UpdateWindowLevel();
           return;
@@ -184,12 +185,12 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller,
           return;
         }
         if (KeyPress == "h") {
-          this->SM->SetCursorVisibility(0);
+          this->SM->SetCursorAndCornerAnnotationVisibility(0);
           this->SM->Render();
           return;
         }
         if (KeyPress == "x") {
-          for(int i=0; i<SM->NumberOfSlicers(); i++) {
+          for(int i=0; i<SM->GetNumberOfSlicers(); i++) {
             SM->RemoveActor("overlay",0);
             SM->SetColorMap(0);
             SM->Render();
@@ -208,9 +209,13 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller,
           return;
         }
         if (KeyPress == "g") {
-          double* cursorPos = this->SM->GetSlicer(VisibleInWindow)->GetCursorPosition();
-          this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(
-            cursorPos[0],cursorPos[1],cursorPos[2],cursorPos[3]);
+          if(bCtrlKey)
+            this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(0,0,0,0);
+          else {
+            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;
@@ -226,18 +231,12 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller,
           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;
@@ -249,34 +248,34 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller,
 
         if (KeyPress == "F2") {
           this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetText(2,"Sagital\n<slice>");
-          this->SM->GetSlicer(VisibleInWindow)->SetSliceOrientation(0);
+          //this->SM->GetSlicer(VisibleInWindow)->SetSliceOrientation(0);
+          this->SM->SetSliceOrientation(VisibleInWindow, 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->GetSlicer(VisibleInWindow)->SetSliceOrientation(1);
+          this->SM->SetSliceOrientation(VisibleInWindow, 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->GetSlicer(VisibleInWindow)->SetSliceOrientation(2);
+          this->SM->SetSliceOrientation(VisibleInWindow, 2);
           this->SM->UpdateSliceRange(VisibleInWindow);
-          this->SM->UpdateInfoOnCursorPosition(VisibleInWindow);
         }
 
+        this->SM->EmitKeyPressed(KeyPress);
       }
 
       //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());
+            -VTK_DOUBLE_MAX,this->SM->GetSlicer(VisibleInWindow)->GetMaxCurrentTSlice());
         this->SM->GetSlicer(VisibleInWindow)->Render();
         return;
       }
 
-      //DD(event);
       // Mouse release HERE
       if (event == vtkCommand::EndPickEvent) {
         //           DD(VisibleInWindow);
@@ -301,27 +300,27 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller,
       }
 
       if (event == vtkCommand::EndInteractionEvent) {
+        this->SM->Picked();
         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);
+      this->SM->GetSlicer(VisibleInWindow)->SetCornerAnnotationVisibility(1);
 
       if (event == vtkCommand::MouseWheelForwardEvent && !isi->GetInteractor()->GetControlKey()) {
+        this->SM->Picked();
         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->Picked();
         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());
@@ -362,15 +361,37 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller,
         zWorld = z;
         break;
       }
-      this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(xWorld,yWorld,zWorld,
-          this->SM->GetSlicer(VisibleInWindow)->GetTSlice());
+
+      // <<<<<<< HEAD
+      //       this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(xWorld,yWorld,zWorld,
+      //                           this->SM->GetSlicer(VisibleInWindow)->GetTSlice());
+      //       // We propagate the mouse position
+      //       this->SM->EmitMousePositionUpdated(VisibleInWindow);      
+      // =======
+      double p[3]; p[0] = xWorld; p[1] = yWorld; p[2] = zWorld;
+      double pt[3];
+      this->SM->GetSlicer(VisibleInWindow)->GetSlicingTransform()->TransformPoint(p, pt);
+
+      this->SM->GetSlicer(VisibleInWindow)->SetCurrentPosition(pt[0],pt[1],pt[2],
+          this->SM->GetSlicer(VisibleInWindow)->GetMaxCurrentTSlice());
+
+      // We propagate the mouse position
+      this->SM->EmitMousePositionUpdated(VisibleInWindow);
+
+      //>>>>>>> 921642d767beba2442dacc8fdb40dc36396e1b7d
+
       if (newLandmark) {
-        this->SM->AddLandmark(xWorld,yWorld,zWorld,
+        double pLand[3]; pLand[0] = xWorld; pLand[1] = yWorld; pLand[2] = zWorld;
+        double ptLand[3];
+        this->SM->GetSlicer(VisibleInWindow)->GetConcatenatedTransform()->TransformPoint(pLand, ptLand);
+        this->SM->AddNewLandmark(ptLand[0],ptLand[1],ptLand[2],
                               this->SM->GetSlicer(VisibleInWindow)->GetTSlice());
-        this->SM->GetSlicer(VisibleInWindow)->UpdateLandmarks();
+        this->SM->GetSlicer(VisibleInWindow)->RemoveLandmarks();
+        //this->SM->GetSlicer(VisibleInWindow)->DisplayLandmarks();
         this->SM->Render();
       }
       if (event == vtkCommand::PickEvent || event == vtkCommand::StartPickEvent) {
+        this->SM->Picked();
         this->SM->UpdateViews(1,VisibleInWindow);
         this->SM->UpdateLinked(VisibleInWindow);
         this->SM->UpdateInfoOnCursorPosition(VisibleInWindow);
@@ -383,7 +404,7 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller,
     }
 
     if (event == vtkCommand::WindowLevelEvent && mStartSlicer > -1) {
-      this->SM->GetSlicer(mStartSlicer)->GetAnnotation()->SetVisibility(1);
+      this->SM->GetSlicer(mStartSlicer)->SetCornerAnnotationVisibility(1);
       // Adjust the window level here
       int *size = isi->GetInteractor()->GetRenderWindow()->GetSize();
       double window = this->InitialWindow;
@@ -402,9 +423,9 @@ void vvSlicerManagerCommand::Execute(vtkObject *caller,
 
       this->SM->SetColorWindow(window*dx);
       this->SM->SetColorLevel(level-dy);
-      this->SM->SetPreset(6);
-      this->SM->UpdateWindowLevel();
+      this->SM->SetPreset(WL_USER);
       this->SM->Render();
+      this->SM->UpdateWindowLevel();
       return;
     }
   }