]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx
#3162 creaMaracasVisu Bug New Normal - Threshold layer
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / LayerImageBase.cxx
index d7e3e7284cfb40319a7f7f6176bcbccf876ae29a..06a085a5634fbf8c4bb87aabbc3a31be2fa09484 100644 (file)
@@ -67,7 +67,7 @@ class ColorLayerObserver : public vtkCommand{
                                        _layerimagebase->SetX( vtkmprbasedata->GetX() );
                                        _layerimagebase->SetY( vtkmprbasedata->GetY() );
                                        _layerimagebase->SetZ( vtkmprbasedata->GetZ() );
-                       _layerimagebase->onThresholdChange();
+                               _layerimagebase->onThresholdChange();
                                } // if basedata
                                
                        } // if wxvtkbaseview
@@ -94,9 +94,10 @@ private:
 LayerImageBase::LayerImageBase()
 {
        _actorPresent                   =       false;
-       _X                                              =       0;
-       _Y                                              =       0;
-       _Z                                              =       0;
+       _X                                              =       -1;
+       _Y                                              =       -1;
+       _Z                                              =       -1;
+       _opacity                                =       1;
        _thresholdTable                 =       NULL;
        _thresholdMapper                =       NULL;
        _scalarbarActor                 =       NULL;
@@ -191,6 +192,7 @@ void LayerImageBase::SetImage(vtkImageData* image)
        spcBase[5]=0;
 
        _image = image;
+       _image->Update();
        _image->GetWholeExtent(ext);
        dimensionOriginalLayer[0] = ext[1]-ext[0]+1;
        dimensionOriginalLayer[1] = ext[3]-ext[2]+1;
@@ -211,12 +213,14 @@ void LayerImageBase::SetImage(vtkImageData* image)
                        SetDimensionBase(dimBase);
                        imagebase->GetSpacing(spcBase);
                        SetSpcBase(spcBase);
-                       SetX( dimBase[0]*spcBase[0]/2 );
-                       SetY( dimBase[1]*spcBase[1]/2 );
-                       SetZ( dimBase[2]*spcBase[2]/2 );
+
+                       if ((_X<0) || (_X>dimBase[0])) { SetX( dimBase[0]/2 ); } 
+                       if ((_Y<0) || (_Y>dimBase[1])) { SetY( dimBase[1]/2 ); } 
+                       if ((_Z<0) || (_Z>dimBase[2])) { SetZ( dimBase[2]/2 ); } 
+
+
                } // if imagebase
        } // if wxvtkbaseview
-       _image->Update();
        _image->GetScalarRange( _range );
        _thresholdTable = vtkLookupTable::New();
 
@@ -301,6 +305,12 @@ void LayerImageBase::GetDimensionBase(int *dim)
 }
 
 
+//------------------------------------------------------------------------------
+void LayerImageBase::SetColorBarPosition(std::vector<int> &colorbarposition)
+{
+   _colorBarPosition=colorbarposition;
+}
+
 //------------------------------------------------------------------------------
 void LayerImageBase::SetRangeForColorBar(std::vector<double> &range)
 {
@@ -389,24 +399,6 @@ void LayerImageBase::CleanXYZ(double &x, double &y, double &z)
                z = maxSize;
        }
        
-/*
-
-       if ( x > (ext[1]-ext[0]) )
-       {
-               z=ext[1]-ext[0];
-       }
-
-       if ( y > (ext[3]-ext[2]) )
-       {
-               z=ext[3]-ext[2];
-       }
-
-       if ( z > (ext[5]-ext[4]) )
-       {
-               z=ext[5]-ext[4];
-       }
-*/
-
 }
 
 //----------------------------------------------------------------------------
@@ -432,6 +424,7 @@ void LayerImageBase::onThreshold()
                        directionViewer =  wxvtk2dbasevie->GetDirection();
                } // ParallelProjection
 
+
                if (!GetActorPresent())
                {
                        if (_thresholdTable==NULL)
@@ -449,8 +442,16 @@ void LayerImageBase::onThreshold()
                        {
                                _thresholdActor = vtkImageActor::New( );
                                _scalarbarActor = vtkScalarBarActor::New();
-                               _thresholdActor->SetOpacity( 0.6 );
+                               if (_colorBarPosition.size()==2)
+                               { 
+                                       _scalarbarActor->SetDisplayPosition(_colorBarPosition[0],_colorBarPosition[1]);
+                               } else {
+                                       _scalarbarActor->SetDisplayPosition(0,0);
+                               }
+
+                               _thresholdActor->SetOpacity( 1 );
                                _thresholdActor->InterpolateOn(  );
+                               
                                if (directionViewer==0)
                                {
                                        _thresholdActor->SetPosition( 900-1,0,0 );
@@ -507,7 +508,8 @@ void LayerImageBase::onThreshold()
                _thresholdMapper->SetInput( img );
                _thresholdMapper->SetLookupTable( _thresholdTable );
                _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
-               
+               _thresholdActor->SetOpacity(_opacity);
+
                _scalarbarActor->SetLookupTable( _thresholdTable );
 //             _scalarbarActor->SetLookupTable( _thresholdMapper->GetLookupTable() );
                _scalarbarActor->SetTitle("Value");
@@ -553,8 +555,10 @@ void LayerImageBase::onThresholdChangeOpacity (int opacity)
 {
        if (_actorPresent)
        {
-               _thresholdActor->SetOpacity(opacity*0.1);
+               _thresholdActor->SetOpacity(opacity/100.0);
        }
+// EED 2017-12-17
+       _opacity = (double)opacity/100.0;
 }
 
 //----------------------------------------------------------------------------