]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx
v1.0.3 BUG 1404
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / LayerImageBase.cxx
index a4946f0ccbc07659f62e56a62ad2cda49801cb6c..6f0d5e14b8d1747d126d032830d3f891dc7ec51b 100644 (file)
@@ -1,11 +1,46 @@
 
 /**
- *  \file 
- *  \brief Class bbtk::ThresholdImageView . 
+ *  \file
+ *  \brief Class bbtk::ThresholdImageView .
  */
 
 #include "LayerImageBase.h"
 
+
+//---------------------------------------------------------------------------------------------
+//---------------------------------------------------------------------------------------------
+//---------------------------------------------------------------------------------------------
+
+ColorLayerImageBasevtkInteractor::ColorLayerImageBasevtkInteractor(LayerImageBase* layerImageBase)
+{
+    _layerImageBase=layerImageBase;
+}
+
+//---------------------------------------------------------------------------------------------
+ColorLayerImageBasevtkInteractor::~ColorLayerImageBasevtkInteractor()
+{
+}
+
+
+//---------------------------------------------------------------------------------------------
+bool ColorLayerImageBasevtkInteractor::OnMouseMove()
+{
+       printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove \n");
+    if  (_vtkInteractorStyleBaseView->GetRefresh_waiting()==true)
+    {
+        _layerImageBase->GetvtkImageReslice()->Modified();
+    }
+
+    return true;
+}
+
+
+//---------------------------------------------------------------------------------------------
+//---------------------------------------------------------------------------------------------
+//---------------------------------------------------------------------------------------------
+
+
+
 LayerImageBase::LayerImageBase()
 {
        _actorPresent                   =       false;
@@ -14,6 +49,7 @@ LayerImageBase::LayerImageBase()
        _thresholdMapper                =       NULL;
        _thresholdActor                 =       NULL;
        _image                                  =       NULL;
+       _baseView               =   NULL;
        _imageReslicer                  =       vtkImageReslice::New();
 
 }
@@ -30,7 +66,7 @@ void LayerImageBase::SetZ(int z)
 }
 
 //----------------------------------------------------------------------------
-int LayerImageBase::GetZ()
+int LayerImageBase::GetZ()  // virtual
 {
        return _Z;
 }
@@ -58,7 +94,14 @@ void LayerImageBase::SetImage(vtkImageData* image)
 //----------------------------------------------------------------------------
 void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
 {
+       printf("EED LayerImageBase::SetwxVtkBaseView start baseview:%p \n", baseview);
+
        _baseView = baseview;
+
+    vtkInteractorStyleBaseView *isbv    = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
+    isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
+       
+       printf("EED LayerImageBase::SetwxVtkBaseView end \n");
 }
 
 //----------------------------------------------------------------------------
@@ -67,6 +110,15 @@ wxVtkBaseView *LayerImageBase::GetwxVtkBaseView()
        return _baseView;
 }
 
+//----------------------------------------------------------------------------
+void LayerImageBase::Refresh()
+{
+    printf("EED LayerImageBase::Refresh\n");
+    if (_baseView!=NULL)
+    {
+        _baseView->Refresh();
+    }
+}
 
 
 //----------------------------------------------------------------------------
@@ -75,54 +127,81 @@ vtkLookupTable* LayerImageBase::GetThresholdTable()
        return _thresholdTable;
 }
 
+//----------------------------------------------------------------------------
+int LayerImageBase::CleanZ(int z)
+{
+       int ext[6];
+       _image->GetWholeExtent(ext);
 
+       if (z<0)
+       {
+               z=0;
+       }
+
+       if ( z > (ext[5]-ext[4]) )
+       {
+               z=ext[5]-ext[4];
+       }
+
+       return z;
+}
 
 //----------------------------------------------------------------------------
 void LayerImageBase::onThreshold()
 {
-       int     z = GetZ();
        
-       if (!GetActorPresent())
-       {                               
-               if (_thresholdTable==NULL)
-               {
-                       //Lookup Table
-                       _thresholdTable = vtkLookupTable::New();
-               } // _thresholdTable
-               
-               if (_thresholdMapper==NULL)
-               {
-                       _thresholdMapper = vtkImageMapToColors::New( );
-               }
-               
-               if (_thresholdActor==NULL)
+       printf("EED LayerImageBase::onThreshold start \n");
+       
+       if ((_image!=NULL) && (_baseView!=NULL))
+       {
+               int z=CleanZ( GetZ() );
+
+               if (!GetActorPresent())
                {
-                       _thresholdActor = vtkImageActor::New( );
-                       _thresholdActor->SetOpacity( 0.6 );
-                       _thresholdActor->InterpolateOn(  );
-                       _thresholdActor->SetPosition( 0,0, 900-1 );
-               } // _thresholdActor
+                       if (_thresholdTable==NULL)
+                       {
+                               //Lookup Table
+                               _thresholdTable = vtkLookupTable::New();
+                       } // _thresholdTable
+
+                       if (_thresholdMapper==NULL)
+                       {
+                               _thresholdMapper = vtkImageMapToColors::New( );
+                       }
+
+                       if (_thresholdActor==NULL)
+                       {
+                               _thresholdActor = vtkImageActor::New( );
+                               _thresholdActor->SetOpacity( 0.6 );
+                               _thresholdActor->InterpolateOn(  );
+                               _thresholdActor->SetPosition( 0,0, -900-1 );
+                       } // _thresholdActor
+                       _baseView->GetRenderer()->AddActor( _thresholdActor );
+                       _actorPresent = true;
+               }  // !GetActorPresent()
+
+               ConfigLookupTable();  // virtual method
+               _imageReslicer->SetInput( GetImage() );
+               _imageReslicer->SetInformationInput( GetImage() );
+               _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
+               _imageReslicer->SetOutputDimensionality(2);
+//             _imageReslicer->SetInterpolationModeToLinear();
+               _imageReslicer->SetInterpolationModeToNearestNeighbor();
+               _imageReslicer->SetResliceAxesOrigin(0,0,z);
+
+               vtkImageData *img = _imageReslicer->GetOutput();
+//             img->Update();
+//             img->UpdateInformation();
+
+               _thresholdMapper->SetInput( img );
+               _thresholdMapper->SetLookupTable( _thresholdTable );
+               _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
+
+               printf("EED LayerImageBase::onThreshold working \n");
                
                
-               _baseView->GetRenderer()->AddActor( _thresholdActor );
-               _actorPresent = true;           
-       }  // !GetActorPresent()
-
-       ConfigLookupTable();  // virtual method
-       _imageReslicer->SetInput( GetImage() );
-       _imageReslicer->SetInformationInput( GetImage() );                      
-       _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
-       _imageReslicer->SetOutputDimensionality(2);
-       _imageReslicer->SetInterpolationModeToLinear();
-       _imageReslicer->SetResliceAxesOrigin(0,0,z);
-
-       vtkImageData *img = _imageReslicer->GetOutput();
-       img->Update();
-       img->UpdateInformation();
-
-       _thresholdMapper->SetInput( img );
-       _thresholdMapper->SetLookupTable( _thresholdTable );
-       _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
+               } // _image
+       printf("EED LayerImageBase::onThreshold end");
 }
 
 
@@ -148,7 +227,7 @@ void LayerImageBase::onThresholdInterpolation(bool interpolate)
                else
                {
                        _thresholdActor->InterpolateOff( );
-               }               
+               }
        }
 }
 
@@ -169,9 +248,19 @@ void LayerImageBase::onThresholdRemove()
                wxVtkBaseView * baseView = _baseView;
                baseView->GetRenderer()->RemoveActor( _thresholdActor );
                _actorPresent = false;
-       }       
+       }
 }
 
+//----------------------------------------------------------------------------
+vtkLookupTable *LayerImageBase::GetvtkLookupTable()
+{
+    return _thresholdTable;
+}
+
+vtkImageReslice *LayerImageBase::GetvtkImageReslice()
+{
+    return _imageReslicer;
+}