]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageView.cxx
#3190 creaMaracasVisu FeatureNewNormal - ManualPaint2 Box
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / ThresholdImageView.cxx
index 426bf801a48364a716277e59605357682718de16..f20eefcf92e9d57318477c5711e7cd62ecd63d35 100644 (file)
@@ -1,18 +1,51 @@
+/*# ---------------------------------------------------------------------
+#
+# 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.
+# ------------------------------------------------------------------------ */
+
 
 /**
  *  \file 
  *  \brief Class bbtk::ThresholdImageView . 
  */
 
-
 #include "ThresholdImageView.h"
+#include <vtkImageReslice.h>
+#include <vtkLookupTable.h>
+#include <vtkImageData.h>
 
 
-
+  //=========================================================================
+  //=========================================================================
+  //=========================================================================
   //=========================================================================
        ThresholdImageView::ThresholdImageView( )
   {
-         _actorPresent                         = false;
+         _minValue                                     =       0;
+         _maxValue                                     =       1000;
+         _baseColorR                           =       1;
+         _baseColorG                           =       0;
+         _baseColorB                           =       0;
   }
 
   //=========================================================================
   //=========================================================================
 
 
-//----------------------------------------------------------------------------
-void ThresholdImageView::SetImage(vtkImageData* image)
-{
-       _image = image;
-}
 
 //----------------------------------------------------------------------------
-void ThresholdImageView::SetwxVtkBaseView(wxVtkBaseView *baseview)
+void ThresholdImageView::SetminMaxValue(int min, int max)
 {
-       _baseView = baseview;
+       _minValue = min;
+       _maxValue = max;
 }
 
-//----------------------------------------------------------------------------
-void ThresholdImageView::SetZ(int z)
-{
-       _Z = z;
-}
 
 //----------------------------------------------------------------------------
-void ThresholdImageView::SetminMax(int min, int max)
+void ThresholdImageView::ConfigLookupTable()  // virtual
 {
-       _min = min;
-       _max = max;
-}
-
-//----------------------------------------------------------------------------
-void ThresholdImageView::onThreshold()
-{
-       int     z = _Z;
        double range[2];
        
-       vtkImageData *img = _image;
-       img->GetScalarRange(range);
+       GetImage()->GetScalarRange(range);
+       if (range[1]==0)
+       {
+               range[1]=255;
+       }
        
        int minTot = floor (range[0]);
        int maxTot = ceil (range[1]);
        
-//EED  _pannew->onThresholdInstantChange(minMax);
-       
-       int minVal = floor (_min);
-       int maxVal = floor (_max);
-       
-       if (!_actorPresent)
+       int minVal = floor (_minValue);
+       int maxVal = floor (_maxValue);
+
+       vtkLookupTable* thresholdTable = GetThresholdTable();
+       thresholdTable->SetNumberOfTableValues(maxTot+1);
+       thresholdTable->SetTableRange(range); 
+       thresholdTable->SetAlphaRange(0, 1);
+       thresholdTable->SetValueRange(0, 1);
+       thresholdTable->SetSaturationRange(0, 0); 
+       thresholdTable->SetRampToLinear( );
+
+       //Assign a fake color for the upper image, and set the white as transparent
+       int i;
+       for(i = minTot; i <= maxTot; i++)
        {
-               if (_imageReslicer==NULL)
-               {
-                       _imageReslicer = vtkImageReslice::New();
-                       _imageReslicer->SetInput( img );
-                       _imageReslicer->SetInformationInput(img);
-                       _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
-                       _imageReslicer->SetOutputDimensionality(2);
-                       _imageReslicer->SetInterpolationModeToLinear();
-               }
-               
-               _imageReslicer->SetResliceAxesOrigin(0,0,z);
-               
-               img = _imageReslicer->GetOutput();
-               img->Update();
-               img->UpdateInformation();
-               
-               wxVtkBaseView *baseView = _baseView;
-               
-               if (_thresholdTable==NULL)
+               if( i >= minVal && i <= maxVal )
                {
-                       //Lookup Table
-                       _thresholdTable = vtkLookupTable::New();
-                       _thresholdTable->SetNumberOfTableValues(maxTot+1);
-                       _thresholdTable->SetTableRange(range); 
-                       _thresholdTable->SetAlphaRange(0, 1);
-                       _thresholdTable->SetValueRange(0, 1);
-                       _thresholdTable->SetSaturationRange(0, 0); 
-                       _thresholdTable->SetRampToLinear( );
+                       thresholdTable->SetTableValue(i,_baseColorR,_baseColorG,_baseColorB, 1);
                }
-               
-               //Assign a fake color for the upper image, and set the white as transparent
-               int i;
-               for(i = minTot; i <= maxTot; i++)
+               else if( i >= minTot && i < minVal )
                {
-                       if( i >= minVal && i <= maxVal )
-                       {
-                               _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
-                       }
-                       else if( i >= minTot && i < minVal )
-                       {
-                               _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
-                       }
-                       else if( i > maxVal && i < maxTot )
-                       {
-                               _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
-                       }
-                       else
-                       {
-                               _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
-                       }
+                       thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
                }
-               _thresholdTable->Build( );
-               
-               if (_thresholdMapper==NULL)
-               {
-                       _thresholdMapper = vtkImageMapToColors::New( );
-               }
-               
-               _thresholdMapper->SetLookupTable( _thresholdTable );
-               _thresholdMapper->SetInput( img );
-               
-               if (_thresholdActor==NULL)
-               {
-                       _thresholdActor = vtkImageActor::New( );
-                       _thresholdActor->SetOpacity( 0.6 );
-                       _thresholdActor->InterpolateOn(  );
-                       _thresholdActor->SetPosition( 0,0, 900-1 );
-               }
-               
-               _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
-               
-               baseView->GetRenderer()->AddActor( _thresholdActor );
-               _actorPresent = true;
-       }
-       
-       else
-       {
-               _imageReslicer->SetResliceAxesOrigin(0,0,z);
-               img = _imageReslicer->GetOutput();
-               img->Update();
-               img->UpdateInformation();
-               
-               //Assign a fake color for the upper image, and set the white as transparent
-               int i;
-               for(i = minTot; i <= maxTot; i++)
+               else if( i > maxVal && i < maxTot )
                {
-                       if( i >= minVal && i <= maxVal )
-                       {
-                               _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
-                       }
-                       else if( i >= minTot && i < minVal )
-                       {
-                               _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
-                       }
-                       else if( i > maxVal && i < maxTot )
-                       {
-                               _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
-                       }
-                       else
-                       {
-                               _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
-                       }
+                       thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
                }
-               
-               _thresholdTable->Build( );
-               _thresholdMapper->SetLookupTable( _thresholdTable );
-               _thresholdMapper->SetInput( img );
-               _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
-       }
-       /*
-        vtkImageViewer2* viewer = vtkImageViewer2::New();       
-        viewer->SetInput( upperImageActor->GetInput() ); 
-        viewer->SetColorLevel((range[1]-range[0])/2);
-        viewer->SetColorWindow(range[1]);
-        viewer->GetRenderer()->AddActor( upperImageActor );
-        viewer->Render();
-        */
-//EED  _theViewPanel->RefreshInterface();
-}
-
-
-//----------------------------------------------------------------------------
-void ThresholdImageView::onThresholdChange()
-{
-       if (_actorPresent)
-       {
-               onThreshold();
-       }
-}
-
-//----------------------------------------------------------------------------
-void ThresholdImageView::onThresholdInterpolation(bool interpolate)
-{
-       if (_thresholdActor!=NULL)
-       {
-               if (interpolate)
-               {
-                       _thresholdActor->InterpolateOn( );
-               }
-               
                else
                {
-                       _thresholdActor->InterpolateOff( );
+                       thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
                }
-               
-//EED          _theViewPanel->RefreshInterface();
-       }
-}
+       } // for
+       thresholdTable->Build( );
 
-//----------------------------------------------------------------------------
-void ThresholdImageView::onThresholdChangeOpacity (int opacity)
-{
-       if (_actorPresent)
-       {
-               _thresholdActor->SetOpacity(opacity*0.1);
-       }
-       
-//EED  _theViewPanel->RefreshInterface();
 }
 
+
 //----------------------------------------------------------------------------
-void ThresholdImageView::onThresholdRemove()
+void ThresholdImageView::SetBaseColor(double r, double g, double b)
 {
-       if (_actorPresent)
-       {
-               wxVtkBaseView * baseView = _baseView;
-               baseView->GetRenderer()->RemoveActor( _thresholdActor );
-               _actorPresent = false;
-       }
-       
-//EED  _theViewPanel->RefreshInterface();
+       _baseColorR = r;
+       _baseColorG = g;
+       _baseColorB = b;
 }
 
 
-
-
 // EOF