X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FmaracasVisuLib%2Fsrc%2Finterface%2FwxWindows%2Fwidgets%2FThresholdImageView%2FThresholdImageView.cxx;h=7907cdf98c0f505f8399713ebfc4b9c4f937250d;hb=d725af03e25b41e03b212c26068be2c04dacd270;hp=693b7d8510c8f1d2bc5f6c251e70a951ce550e39;hpb=42ef0b76d65a1b4cdde710db14ada2eed990a63b;p=creaMaracasVisu.git diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageView.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageView.cxx index 693b7d8..7907cdf 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageView.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageView.cxx @@ -4,23 +4,20 @@ * \brief Class bbtk::ThresholdImageView . */ - #include "ThresholdImageView.h" +#include +#include +#include - + //========================================================================= + //========================================================================= + //========================================================================= //========================================================================= ThresholdImageView::ThresholdImageView( ) { - _actorPresent = false; - _Z = 0; _minValue = 0; _maxValue = 1000; - _image = NULL; - _imageReslicer = NULL; - _thresholdTable = NULL; - _thresholdMapper = NULL; - _thresholdActor = NULL; _baseColorR = 1; _baseColorG = 0; _baseColorB = 0; @@ -33,30 +30,6 @@ //========================================================================= -//---------------------------------------------------------------------------- -void ThresholdImageView::SetImage(vtkImageData* image) -{ - printf("ThresholdImageView::SetImage %p\n", image); - _image = image; -} - -//---------------------------------------------------------------------------- -void ThresholdImageView::SetwxVtkBaseView(wxVtkBaseView *baseview) -{ - _baseView = baseview; -} - -//---------------------------------------------------------------------------- -wxVtkBaseView *ThresholdImageView::GetwxVtkBaseView() -{ - return _baseView; -} - -//---------------------------------------------------------------------------- -void ThresholdImageView::SetZ(int z) -{ - _Z = z; -} //---------------------------------------------------------------------------- void ThresholdImageView::SetminMaxValue(int min, int max) @@ -65,192 +38,55 @@ void ThresholdImageView::SetminMaxValue(int min, int max) _maxValue = max; } + //---------------------------------------------------------------------------- -void ThresholdImageView::onThreshold() +void ThresholdImageView::ConfigLookupTable() // virtual { - 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]); - int minVal = floor (_minValue); int maxVal = floor (_maxValue); - - - if (!_actorPresent) + + 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) - { - //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( ); - } - - //Assign a fake color for the upper image, and set the white as transparent - int i; - for(i = minTot; i <= maxTot; i++) - { - if( i >= minVal && i <= maxVal ) - { - _thresholdTable->SetTableValue(i,_baseColorR,_baseColorG,_baseColorB, 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->Build( ); - - if (_thresholdMapper==NULL) + if( i >= minVal && i <= maxVal ) { - _thresholdMapper = vtkImageMapToColors::New( ); + thresholdTable->SetTableValue(i,_baseColorR,_baseColorG,_baseColorB, 1); } - - _thresholdMapper->SetLookupTable( _thresholdTable ); - _thresholdMapper->SetInput( img ); - - if (_thresholdActor==NULL) + else if( i >= minTot && i < minVal ) { - _thresholdActor = vtkImageActor::New( ); - _thresholdActor->SetOpacity( 0.6 ); - _thresholdActor->InterpolateOn( ); - _thresholdActor->SetPosition( 0,0, 900-1 ); + thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent } - - _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++) - { - if( i >= minVal && i <= maxVal ) - { - _thresholdTable->SetTableValue(i,_baseColorR,_baseColorG,_baseColorB, 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->Build( ); - _thresholdMapper->SetLookupTable( _thresholdTable ); - _thresholdMapper->SetInput( img ); - _thresholdActor->SetInput( _thresholdMapper->GetOutput() ); - } -} - - -//---------------------------------------------------------------------------- -void ThresholdImageView::onThresholdChange() -{ - if (_actorPresent) - { - onThreshold(); - } -} - -//---------------------------------------------------------------------------- -void ThresholdImageView::onThresholdInterpolation(bool interpolate) -{ - if (_thresholdActor!=NULL) - { - if (interpolate) + else if( i > maxVal && i < maxTot ) { - _thresholdActor->InterpolateOn( ); + thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent } - else { - _thresholdActor->InterpolateOff( ); + thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent } - -//EED _theViewPanel->RefreshInterface(); - } -} - -//---------------------------------------------------------------------------- -void ThresholdImageView::onThresholdChangeOpacity (int opacity) -{ - if (_actorPresent) - { - _thresholdActor->SetOpacity(opacity*0.1); - } - -//EED _theViewPanel->RefreshInterface(); -} + } // for + thresholdTable->Build( ); -//---------------------------------------------------------------------------- -void ThresholdImageView::onThresholdRemove() -{ - if (_actorPresent) - { - wxVtkBaseView * baseView = _baseView; - baseView->GetRenderer()->RemoveActor( _thresholdActor ); - _actorPresent = false; - } - -//EED _theViewPanel->RefreshInterface(); }