]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtk2DBaseView.cxx
#3418 creaMaracasVisu Feature New Normal - ManualPaint_model with openmp
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxVtk2DBaseView.cxx
index fe3b8513deaa5cf49f02c1d594f587ddf77d00b8..5337c807149d005d81571e3b5aa476a66779726a 100644 (file)
@@ -1,8 +1,34 @@
+/*# ---------------------------------------------------------------------
+#
+# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+#                        pour la Sant�)
+# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+# Previous Authors : Laurent Guigues, Jean-Pierre Roux
+# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+#
+#  This software is governed by the CeCILL-B license under French law and
+#  abiding by the rules of distribution of free software. You can  use,
+#  modify and/ or redistribute the software under the terms of the CeCILL-B
+#  license as circulated by CEA, CNRS and INRIA at the following URL
+#  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+#  or in the file LICENSE.txt.
+#
+#  As a counterpart to the access to the source code and  rights to copy,
+#  modify and redistribute granted by the license, users are provided only
+#  with a limited warranty  and the software's author,  the holder of the
+#  economic rights,  and the successive licensors  have only  limited
+#  liability.
+#
+#  The fact that you are presently reading this means that you have had
+#  knowledge of the CeCILL-B license and that you accept its terms.
+# ------------------------------------------------------------------------ */
+
 #include "wxVtk2DBaseView.h"
 
 #include "vtkInfoTextImage.h"
 #include "vtkInteractorStyleBaseView2D.h"
 #include "vtkInfoTextImageInteractor.h"
+#include "vtkImageActor.h"
 
 
 wxVtk2DBaseView::wxVtk2DBaseView(wxWindow *parent)
@@ -20,7 +46,6 @@ wxVtk2DBaseView::~wxVtk2DBaseView()
        {
           delete _vtkIinfoTextImage;
        }
-
        if (_imageViewer2XYZ!=NULL)
        {
           delete _imageViewer2XYZ;
@@ -35,19 +60,17 @@ void wxVtk2DBaseView::TransformCoordinate_spacing_ViewToModel(double &X,double &
 //     GetVtkBaseData()->GetImageData()->GetSpacing(spc);
 //JCP 04/08/10 W/O Image this->_imageViewer2XYZ->GetVtkImageViewer2()->GetInput()->GetSpacing(spc);
        vtkImageData* image = this->_imageViewer2XYZ->GetVtkImageViewer2()->GetInput();
-       if(image){
+       if(image)
+       {
                image->GetSpacing(spc);
        }else{
                spc[0] = 1;
                spc[1] = 1;
                spc[2] = 1;
        }
-
-
        X = X / spc[0];
        Y = Y / spc[1];
        Z = Z / spc[2];
-
 }
 
 //-------------------------------------------------------------------
@@ -69,7 +92,6 @@ void wxVtk2DBaseView::TransformCoordinate_spacing_ModelToView(double &X,double &
        X=X*spc[0];
        Y=Y*spc[1];
        Z=Z*spc[2];
-
 }
 
 //-------------------------------------------------------------------
@@ -79,19 +101,23 @@ void wxVtk2DBaseView::ResetView()
        double spx = 0,spy = 0,spz = 0;
        int x1 = 1,x2 = 1,y1 = 1,y2 = 1,z1 = 1,z2 = 1;
        wxVtkBaseView::Configure();
-
-       wxVTKRenderWindowInteractor *iren = GetWxVTKRenderWindowInteractor();
+       crea::wxVTKRenderWindowInteractor *iren = GetWxVTKRenderWindowInteractor();
        vtkImageData *imageData = GetVtkBaseData()->GetImageData();
-       if(imageData){
+       if(imageData)
+       {
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
                imageData->UpdateInformation();
                imageData->SetUpdateExtent( imageData->GetWholeExtent());
                imageData->Update();
                _imageViewer2XYZ->GetVtkImageViewer2()->SetInput(imageData );
+#else
+               _imageViewer2XYZ->GetVtkImageViewer2()->SetInputData(imageData );
+#endif
                imageData->GetSpacing (spx,spy,spz);
                imageData->GetExtent (x1,x2,y1,y2,z1,z2);
        }
-
-
+printf("//EED wxVtk2DBaseView::ResetView %d %d    %d %d     %d %d \n",x1,x2,y1,y2,z1,z2);
        _imageViewer2XYZ -> SetExtentDimension(x1,x2,y1,y2,z1,z2);
        _imageViewer2XYZ -> GetVtkImageViewer2()->SetupInteractor ( iren );
 
@@ -115,6 +141,11 @@ void wxVtk2DBaseView::ResetView()
        vtkInteractorScrollZ *_vtkInteractorScrollZ = new vtkInteractorScrollZ();
        style2D->SetInteractorScrollZ(_vtkInteractorScrollZ);
 
+       vtkInteractorZoomCamera *_vtkInteractorZoomCamera = new vtkInteractorZoomCamera();
+       style2D->SetInteractorZoomCamera(_vtkInteractorZoomCamera);
+
+
+
        SetInteractorStyleImage( style2D );
 
        // RaC
@@ -122,17 +153,28 @@ void wxVtk2DBaseView::ResetView()
 
 }
 
-
-
 //-------------------------------------------------------------------
 void wxVtk2DBaseView::SetImageToVtkViewer(vtkImageData *imageData)
 {
+       int ext[6];
        if (_imageViewer2XYZ!=NULL)
        {
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
+               imageData->Update();
+               imageData->GetWholeExtent(ext);
+               _imageViewer2XYZ->SetExtentDimension( ext[0],ext[1],ext[2],ext[3],ext[4],ext[5] );
                _imageViewer2XYZ->GetVtkImageViewer2()->SetInput( imageData );
+#else
+               imageData->GetExtent(ext);
+               _imageViewer2XYZ->SetExtentDimension( ext[0],ext[1],ext[2],ext[3],ext[4],ext[5] );
+               _imageViewer2XYZ->GetVtkImageViewer2()->SetInputData( imageData );
+#endif
        } // if _imageViewer2XYZ
-}
 
+       GetRenderer()->GetActiveCamera()->SetClippingRange(0.01, 1000000);
+
+}
 
 //-------------------------------------------------------------------
 void wxVtk2DBaseView::Configure(bool okimage)
@@ -145,7 +187,7 @@ void wxVtk2DBaseView::Configure(bool okimage)
        if (_imageViewer2XYZ==NULL)
        {
                _imageViewer2XYZ = new vtkImageViewer2_XYZ();
-               wxVTKRenderWindowInteractor *iren = GetWxVTKRenderWindowInteractor();
+               crea::wxVTKRenderWindowInteractor *iren = GetWxVTKRenderWindowInteractor();
                _imageViewer2XYZ -> GetVtkImageViewer2()->SetupInteractor ( iren );
 
                //////////////
@@ -163,19 +205,28 @@ void wxVtk2DBaseView::Configure(bool okimage)
                vtkInteractorScrollZ *_vtkInteractorScrollZ = new vtkInteractorScrollZ();
                style2D->SetInteractorScrollZ(_vtkInteractorScrollZ);
 
+               vtkInteractorZoomCamera *_vtkInteractorZoomCamera = new vtkInteractorZoomCamera();
+               style2D->SetInteractorZoomCamera(_vtkInteractorZoomCamera);
+
                SetInteractorStyleImage( style2D );
 
                // RaC
                //////////////
        }
 
-
        vtkImageData *imageData = GetVtkBaseData()->GetMarImageData()->GetImageData();
        if (imageData!=NULL)
        {
+
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
                imageData->UpdateInformation();
                imageData->SetUpdateExtent( imageData->GetWholeExtent());
                imageData->Update();
+#else
+               //...
+#endif
+
                if (okimage==true){
                        imageData->GetSpacing (spx,spy,spz);
                        imageData->GetExtent (x1,x2,y1,y2,z1,z2);
@@ -206,11 +257,9 @@ void wxVtk2DBaseView::Configure(bool okimage)
 //_collookup->SetTableValue(255 , 0 , 1 , 0 , 1 );
 //_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel ()->SetLookupTable(_collookup );
 
-
 // EED 17 Oct 2007
 //                     SetInteractorStyleImage( vtkInteractorStyleBaseView2D::New() );
 
-
                        vtkImageViewer2 *IV2            =       _imageViewer2XYZ->GetVtkImageViewer2();
                        vtkCamera               *camera         =       IV2->GetRenderer()->GetActiveCamera();
 
@@ -218,7 +267,7 @@ void wxVtk2DBaseView::Configure(bool okimage)
 //EED 21 mars 2012     FLIP problem  ..PLOP..
                        
                        // XY
-                       camera->SetViewUp               ( spx*0                 , -spy*1                        , spz*0         );
+                       camera->SetViewUp               ( spx*0                 , -spy*1                , spz*0         );
                        camera->SetPosition             ( spx*(x1+x2)/2 , spy*(y1+y2)/2 , -spz*10000    );
                        camera->SetFocalPoint   ( spx*(x1+x2)/2 , spy*(y1+y2)/2 , spz*0         );
 /*
@@ -230,7 +279,10 @@ void wxVtk2DBaseView::Configure(bool okimage)
                        
                        camera->SetClippingRange( 0.01                  , 1000000 );
                        camera->ComputeViewPlaneNormal();
-                       camera->SetParallelScale( spx*(x2-x1)/3.0 );
+               
+                       double cameraparallelScale=spx*(x2-x1)/3.0;     
+                       camera->SetParallelScale( cameraparallelScale );
+                       GetVtkBaseData()->SetCameraParallelScale( cameraparallelScale );
 
                        // text information over the graphic window
                        if(_vtkIinfoTextImage == NULL){
@@ -249,29 +301,15 @@ void wxVtk2DBaseView::Configure(bool okimage)
 
 //-------------------------------------------------------------------
 
-int    wxVtk2DBaseView::GetActualSlice()  // virtual
+int wxVtk2DBaseView::GetActualSlice()  // virtual
 {
-   return (int)(_vtkbasedata->GetZ());
+   return (int)(GetVtkBaseData()->GetZ());
 }
 
 //-------------------------------------------------------------------
 void wxVtk2DBaseView::SetActualSlice(int slice)  // Virtual
 {
-   _vtkbasedata->SetZ(slice);
-}
-
-//-------------------------------------------------------------------
-
-vtkBaseData *wxVtk2DBaseView::GetVtkBaseData()
-{
-   return _vtkbasedata;
-}
-
-//-------------------------------------------------------------------
-
-void wxVtk2DBaseView::SetVtkBaseData(vtkBaseData *vtkbasedata)
-{
-   _vtkbasedata=vtkbasedata;
+   GetVtkBaseData()->SetZ(slice);
 }
 
 //-------------------------------------------------------------------
@@ -280,26 +318,30 @@ void wxVtk2DBaseView::UpdateColorWindowLevel()
        //EED 24oct2010
        //EED 02nov2012
        
-//     vtkImageViewer2 *vtkimageviewer2        = _imageViewer2XYZ->GetVtkImageViewer2();               
-       
-       
        vtkImageMapToWindowLevelColors* imagemaptowindowlevel = _imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel();
-       imagemaptowindowlevel->SetWindow( _vtkbasedata->GetColorWindow() );
-       imagemaptowindowlevel->SetLevel( _vtkbasedata->GetColorLevel() );
-       
-// EED Borrame
-//     vtkimageviewer2->SetColorWindow( _vtkbasedata->GetColorWindow() );
-//     vtkimageviewer2->SetColorLevel(  _vtkbasedata->GetColorLevel() );
+       imagemaptowindowlevel->SetWindow( GetVtkBaseData()->GetColorWindow() );
+       imagemaptowindowlevel->SetLevel( GetVtkBaseData()->GetColorLevel() );
        _imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->Modified();
 }
 
+//-------------------------------------------------------------------
+void wxVtk2DBaseView::UpdateCameraParallelScale()
+{
+       vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
+       camera->SetParallelScale( GetVtkBaseData()->GetCameraParallelScale() );
+}
+
 //-------------------------------------------------------------------
 void wxVtk2DBaseView::Refresh()
 {
        int z = (int)(GetVtkBaseData()->GetZ());
        _imageViewer2XYZ->SetZSlice( z );
+//EED 2016/02/19
+       vtkImageActor *imageactor = _imageViewer2XYZ->GetVtkImageViewer2()->GetImageActor();
+       imageactor->SetInterpolate( GetVtkBaseData()->GetInterpolate() );
        //EED 01nov2012
        UpdateColorWindowLevel();       
+       UpdateCameraParallelScale();    
        wxVtkBaseView::Refresh();
 }
 
@@ -307,12 +349,10 @@ void wxVtk2DBaseView::Refresh()
 void wxVtk2DBaseView::SetInteractorStyleImage(vtkInteractorStyleBaseView *interactorstylebaseview)
 {
        SetInteractorStyleBaseView(interactorstylebaseview);
-
-       wxVTKRenderWindowInteractor *iren = GetWxVTKRenderWindowInteractor();
+       crea::wxVTKRenderWindowInteractor *iren = GetWxVTKRenderWindowInteractor();
        interactorstylebaseview->SetInteractor ( iren );
        iren->SetInteractorStyle(interactorstylebaseview);
        interactorstylebaseview->SetwxVtkBaseView(this);
-
        vtkMaracasImageViewer2Callback * cbk = vtkMaracasImageViewer2Callback::New();
        cbk->IV = _imageViewer2XYZ->GetVtkImageViewer2();
        interactorstylebaseview->AddObserver( vtkCommand::WindowLevelEvent, cbk );
@@ -361,7 +401,7 @@ void wxVtk2DBaseView::setColorTransferFunction(vtkColorTransferFunction* colorta
 void wxVtk2DBaseView::SetColorWindow(double level)
 {
 //     _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow(level);
-       _vtkbasedata->SetColorWindow(level);    
+       GetVtkBaseData()->SetColorWindow(level);        
        this->Refresh();
 }
 
@@ -369,7 +409,14 @@ void wxVtk2DBaseView::SetColorWindow(double level)
 void wxVtk2DBaseView::SetColorLevel(double level)
 {
 //     _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel(level);
-       _vtkbasedata->SetColorLevel(level);
+       GetVtkBaseData()->SetColorLevel(level);
+       this->Refresh();
+}
+
+//-------------------------------------------------------------------
+void wxVtk2DBaseView::SetInterpolate(bool iterpolate)
+{
+       GetVtkBaseData()->SetInterpolate( iterpolate );
        this->Refresh();
 }