]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / LayerImageBase.cxx
index a4946f0ccbc07659f62e56a62ad2cda49801cb6c..c079604b5debfe8a5eecf4536ee736a64003267f 100644 (file)
@@ -30,7 +30,7 @@ void LayerImageBase::SetZ(int z)
 }
 
 //----------------------------------------------------------------------------
-int LayerImageBase::GetZ()
+int LayerImageBase::GetZ()  // virtual
 {
        return _Z;
 }
@@ -75,54 +75,73 @@ 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)
-               {
-                       _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->SetResliceAxesOrigin(0,0,z);
-
-       vtkImageData *img = _imageReslicer->GetOutput();
-       img->Update();
-       img->UpdateInformation();
-
-       _thresholdMapper->SetInput( img );
-       _thresholdMapper->SetLookupTable( _thresholdTable );
-       _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
+
+       if (_image!=NULL)
+       {
+               int z=CleanZ( GetZ() );
+
+               if (!GetActorPresent())
+               {                               
+                       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->SetResliceAxesOrigin(0,0,z);
+
+               vtkImageData *img = _imageReslicer->GetOutput();
+               img->Update();
+               img->UpdateInformation();
+
+               _thresholdMapper->SetInput( img );
+               _thresholdMapper->SetLookupTable( _thresholdTable );
+               _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
+               } // _image
 }