]> Creatis software - clitk.git/blobdiff - vv/vvSlicerManagerCommand.cxx
- add end of pick event
[clitk.git] / vv / vvSlicerManagerCommand.cxx
index e109b6d85c7b1c78bb6d72e8575357aed152643c..0415c9e8934fe6b98fe6848b37e8ef01445c2776 100644 (file)
@@ -1,44 +1,35 @@
 /*=========================================================================
+  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
 
-Program:   vv
-Module:    $RCSfile: vvSlicerManagerCommand.cxx,v $
-Language:  C++
-Date:      $Date: 2010/01/06 13:31:57 $
-Version:   $Revision: 1.1 $
-Author :   Pierre Seroul (pierre.seroul@gmail.com)
+  Authors belong to: 
+  - University of LYON              http://www.universite-lyon.fr/
+  - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
+  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
 
-Copyright (C) 2008
-Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
-CREATIS-LRMN http://www.creatis.insa-lyon.fr
+  This software is distributed WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the copyright notices for more information.
 
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 3 of the License.
+  It is distributed under dual licence
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-=========================================================================*/
+  - 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"
 
-#include "vtkTextProperty.h"
-#include "vtkRenderer.h"
-#include "vtkImageActor.h"
-#include "vtkRenderWindowInteractor.h"
-#include "vtkPropPicker.h"
-#include "vtkCamera.h"
-#include "vtkImageMapToWindowLevelColors.h"
-#include "vtkLookupTable.h"
-#include "vtkMath.h"
-#include "vtkAbstractPropPicker.h"
-#include "vtkAssemblyPath.h"
-#include "vtkCornerAnnotation.h"
+#include <vtkTextProperty.h>
+#include <vtkRenderer.h>
+#include <vtkImageActor.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkPropPicker.h>
+#include <vtkCamera.h>
+#include <vtkImageMapToWindowLevelColors.h>
+#include <vtkLookupTable.h>
+#include <vtkMath.h>
+#include <vtkAbstractPropPicker.h>
+#include <vtkAssemblyPath.h>
+#include <vtkCornerAnnotation.h>
 #include <vtkRenderWindow.h>
 
 #include "vvSlicer.h"
@@ -46,28 +37,34 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <cmath>
 
-vvSlicerManagerCallback::vvSlicerManagerCallback()
+//------------------------------------------------------------------------------
+vvSlicerManagerCommand::vvSlicerManagerCommand()
 {
     mStartSlicer = -1;
+    mSlicerNumber=-1;
 }
+//------------------------------------------------------------------------------
 
+
+//------------------------------------------------------------------------------
 //return the num of the current slicer if visible (-1 else)
-int vvSlicerManagerCallback::FindSlicerNumber(vtkRenderWindow* renwin)
+int vvSlicerManagerCommand::FindSlicerNumber(vtkRenderWindow* renwin)
 {
-    for (int i = 0; i < SM->NumberOfSlicers(); i++)
-    {
-        if (SM->GetSlicer(i)->GetRenderWindow() == renwin
-                && SM->GetSlicer(i)->GetRenderer()->GetDraw())
-        {
-            return i;
-        }
-    }
-    return -1;
+    int rvalue;
+    if (renwin != SM->GetSlicer(mSlicerNumber)->GetRenderWindow() ||
+            !SM->GetSlicer(mSlicerNumber)->GetRenderer()->GetDraw())
+        rvalue = -1;
+    else rvalue = mSlicerNumber;
+    //std::cerr << this << ":" << mSlicerNumber << ": " << rvalue << endl;
+    return rvalue;
 }
+//------------------------------------------------------------------------------
 
-void vvSlicerManagerCallback::Execute(vtkObject *caller,
-                                       unsigned long event,
-                                       void *vtkNotUsed(callData))
+
+//------------------------------------------------------------------------------
+void vvSlicerManagerCommand::Execute(vtkObject *caller,
+                                     unsigned long event,
+                                     void *vtkNotUsed(callData))
 {
     //KeyPress event
     vvInteractorStyleNavigator *isi =
@@ -80,7 +77,7 @@ void vvSlicerManagerCallback::Execute(vtkObject *caller,
 
         int VisibleInWindow = this->FindSlicerNumber(isi->GetInteractor()->GetRenderWindow());
         vtkRenderer* renderer=NULL;
-        if (VisibleInWindow>-1) 
+        if (VisibleInWindow>-1)
             renderer=this->SM->GetSlicer(VisibleInWindow)->GetRenderer();
         newLandmark = false;
 
@@ -100,9 +97,23 @@ void vvSlicerManagerCallback::Execute(vtkObject *caller,
             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")
                 {
@@ -174,19 +185,18 @@ void vvSlicerManagerCallback::Execute(vtkObject *caller,
                 }
                 if (KeyPress == "minus")
                 {
-                    std::cout << "KeyPress : - " << std::endl;
                     this->SM->SetColorWindow(-this->SM->GetColorWindow());
                     this->SM->SetColorMap(-1);
                     this->SM->UpdateWindowLevel();
                     return;
                 }
-                if (KeyPress == "u")
+                if (KeyPress == "c")
                 {
                     this->SM->ToggleContourSuperposition();
                     this->SM->Render();
                     return;
                 }
-                if (KeyPress == "i")
+                if (KeyPress == "l")
                 {
                     this->SM->ToggleInterpolation();
                     this->SM->Render();
@@ -198,13 +208,13 @@ void vvSlicerManagerCallback::Execute(vtkObject *caller,
                     this->SM->Render();
                     return;
                 }
-                if (KeyPress == "l")
+                if (KeyPress == "u")
                 {
                     this->SM->Reload();
                     this->SM->Render();
                     return;
                 }
-                if (KeyPress == "r" or KeyPress=="R")
+                if (KeyPress == "r" || KeyPress=="R")
                 {
                     this->SM->GetSlicer(VisibleInWindow)->ResetCamera();
                     this->SM->GetSlicer(VisibleInWindow)->Render();
@@ -252,21 +262,21 @@ void vvSlicerManagerCallback::Execute(vtkObject *caller,
                 if (KeyPress == "Right")
                     this->SM->SetNextTSlice(VisibleInWindow);
 
-                if (KeyPress == "F1")
+                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 == "F2")
+                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 == "F3")
+                if (KeyPress == "F4")
                 {
                     this->SM->GetSlicer(VisibleInWindow)->GetAnnotation()->SetText(2,"Axial\n<slice>");
                     this->SM->GetSlicer(VisibleInWindow)->SetSliceOrientation(2);
@@ -284,6 +294,15 @@ void vvSlicerManagerCallback::Execute(vtkObject *caller,
                 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;
@@ -341,29 +360,29 @@ void vvSlicerManagerCallback::Execute(vtkObject *caller,
             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;
+                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());
@@ -385,7 +404,7 @@ void vvSlicerManagerCallback::Execute(vtkObject *caller,
                 this->SM->GetSlicer(VisibleInWindow)->Render();
             }
             //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)->GetTSlice());
             //this->SM->GetSlicer(VisibleInWindow)->Render();
         }
 
@@ -401,9 +420,9 @@ void vvSlicerManagerCallback::Execute(vtkObject *caller,
 
             // Compute normalized delta
             double dx = static_cast<double>(isi->GetWindowLevelCurrentPosition()[0] -
-                         isi->GetWindowLevelStartPosition()[0]) / size[0];
+                                            isi->GetWindowLevelStartPosition()[0]) / size[0];
             double dy = static_cast<double>(isi->GetWindowLevelStartPosition()[1] -
-                         isi->GetWindowLevelCurrentPosition()[1]) / size[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
@@ -417,12 +436,15 @@ void vvSlicerManagerCallback::Execute(vtkObject *caller,
         }
     }
 }
+//------------------------------------------------------------------------------
+
 
-void vvSlicerManagerCallback::Dolly(double factor, vtkRenderWindowInteractor *interactor)
+//------------------------------------------------------------------------------
+void vvSlicerManagerCommand::Dolly(double factor, vtkRenderWindowInteractor *interactor)
 {
     int VisibleInWindow = this->FindSlicerNumber(interactor->GetRenderWindow());
     vtkRenderer* renderer;
-    if (VisibleInWindow>-1) 
+    if (VisibleInWindow>-1)
         renderer=this->SM->GetSlicer(VisibleInWindow)->GetRenderer();
     else
     {
@@ -445,9 +467,9 @@ void vvSlicerManagerCallback::Dolly(double factor, vtkRenderWindowInteractor *in
     oldPos[2] = focalDepth;
 
     distance[0] = 1/factor*
-                  (interactor->GetEventPosition()[0]-renderer->GetCenter()[0]);
+        (interactor->GetEventPosition()[0]-renderer->GetCenter()[0]);
     distance[1] = 1/factor*
-                  (interactor->GetEventPosition()[1]-renderer->GetCenter()[1]);
+        (interactor->GetEventPosition()[1]-renderer->GetCenter()[1]);
 
     newPos[0] = interactor->GetEventPosition()[0] - distance[0];
     newPos[1] = interactor->GetEventPosition()[1] - distance[1];
@@ -495,15 +517,18 @@ void vvSlicerManagerCallback::Dolly(double factor, vtkRenderWindowInteractor *in
     renderer->ResetCameraClippingRange();
     //interactor->Render();
 }
+//------------------------------------------------------------------------------
+
 
-void vvSlicerManagerCallback::FlyToPosition(vtkRenderWindowInteractor *interactor,vvSlicer* slicer)
+//------------------------------------------------------------------------------
+void vvSlicerManagerCommand::FlyToPosition(vtkRenderWindowInteractor *interactor,vvSlicer* slicer)
 {
     double flyFrom[3], flyTo[3];
     double d[3], focalPt[3], position[3], positionFrom[3];
     int i, j;
     int VisibleInWindow = this->FindSlicerNumber(interactor->GetRenderWindow());
     vtkRenderer* renderer=NULL;
-    if (VisibleInWindow>-1) 
+    if (VisibleInWindow>-1)
         renderer=this->SM->GetSlicer(VisibleInWindow)->GetRenderer();
     else
         return;
@@ -564,3 +589,4 @@ void vvSlicerManagerCallback::FlyToPosition(vtkRenderWindowInteractor *interacto
         }
     }
 }
+//------------------------------------------------------------------------------