]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/LayerImageBase.cxx
#3262 creaMaracasVisu Feature New Normal - Export LookupTable fron ColorLayerImageV...
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / LayerImageBase.cxx
index a86251cddaa68abde26eba60a6d3a7b2560c367e..5fd366cd9ce03bc4f4bf3c44684e1707702fd12b 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;
@@ -152,7 +153,14 @@ int LayerImageBase::GetZ()  // virtual
 vtkImageData* LayerImageBase::GetImage()
 {
 //     return _image;
-       return _imageChangeInformation->GetOutput();
+       vtkImageData *result;
+       if (_image==NULL)
+       {
+               result = NULL;
+       } else {
+               result = _imageChangeInformation->GetOutput();
+       }
+       return result;
 }
 
 //----------------------------------------------------------------------------
@@ -166,8 +174,25 @@ bool LayerImageBase::GetActorPresent()
 void LayerImageBase::SetImage(vtkImageData* image)
 {
        int     ext[6];
+       double  spcBase[3];
        int     dimensionOriginalLayer[3];
+       int     dimBase[6];
+
+       ext[0]=0;
+       ext[1]=0;
+       ext[2]=0;
+       ext[3]=0;
+       ext[4]=0;
+       ext[5]=0;
+       spcBase[0]=0;
+       spcBase[1]=0;
+       spcBase[2]=0;
+       spcBase[3]=0;
+       spcBase[4]=0;
+       spcBase[5]=0;
+
        _image = image;
+       _image->Update();
        _image->GetWholeExtent(ext);
        dimensionOriginalLayer[0] = ext[1]-ext[0]+1;
        dimensionOriginalLayer[1] = ext[3]-ext[2]+1;
@@ -181,21 +206,21 @@ void LayerImageBase::SetImage(vtkImageData* image)
                vtkImageData    *imagebase              =       GetwxVtkBaseView()->GetVtkBaseData()->GetImageData();
                if (imagebase!=NULL) 
                {       
-                       int dimBase[6];
                        imagebase->GetWholeExtent(ext);
                        dimBase[0]=ext[1]-ext[0]+1;                             
                        dimBase[1]=ext[3]-ext[2]+1;                             
                        dimBase[2]=ext[5]-ext[4]+1;                             
                        SetDimensionBase(dimBase);
-                       double  spcBase[3];
                        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();
 
@@ -280,6 +305,12 @@ void LayerImageBase::GetDimensionBase(int *dim)
 }
 
 
+//------------------------------------------------------------------------------
+void LayerImageBase::SetColorBarPosition(std::vector<int> &colorbarposition)
+{
+   _colorBarPosition=colorbarposition;
+}
+
 //------------------------------------------------------------------------------
 void LayerImageBase::SetRangeForColorBar(std::vector<double> &range)
 {
@@ -311,7 +342,6 @@ void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
                ColorLayerObserver *colorlayerobserver = ColorLayerObserver::New();
                _baseView->GetVtkBaseData()->AddObserver( 1, colorlayerobserver );
                colorlayerobserver->SetLayerImageBase(this);
-
        } // if _baseView
 }
 
@@ -340,61 +370,35 @@ vtkLookupTable* LayerImageBase::GetThresholdTable()
 //----------------------------------------------------------------------------
 void LayerImageBase::CleanXYZ(double &x, double &y, double &z)
 {
-
        if (x<0)
        {
                x=0;
        }
-
        if (y<0)
        {
                y=0;
        }
-
        if (z<0)
        {
                z=0;
        }
-
        double maxSize;
-
        maxSize=_dimOriginalLayer[0]*_newSpcLayer[0];
        if ( x > maxSize  )
        {
                x=maxSize;
        }
-
        maxSize=_dimOriginalLayer[1]*_newSpcLayer[1];
        if ( y > maxSize  )
        {
                y = maxSize;
        }
-
        maxSize=_dimOriginalLayer[2]*_newSpcLayer[2];
        if ( z > maxSize  )
        {
                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];
-       }
-*/
-
 }
 
 //----------------------------------------------------------------------------
@@ -402,26 +406,16 @@ void LayerImageBase::onThreshold()
 {
        if ((_image!=NULL) && (_baseView!=NULL))
        {
-double spc[3];
-GetImage()-> GetSpacing(spc);
-printf("EED  LayerImageBase::onThreshold  A img-spc %f  %f  %f\n", spc[0],spc[1],spc[2]);
                double x=GetX();
                double y=GetY();
                double z=GetZ();
 
-//             x = x*spc[0];
-//             y = y*spc[1];
-//             z = z*spc[2];
-
-               
                x = x*_spcBase[0];
                y = y*_spcBase[1];
                z = z*_spcBase[2];
 
-
                CleanXYZ(x,y,z);
 
-
                vtkCamera *camera = _baseView->GetRenderer()->GetActiveCamera();
                int directionViewer=0;
                if (camera->GetParallelProjection()==1)
@@ -448,8 +442,18 @@ printf("EED  LayerImageBase::onThreshold  A img-spc %f  %f  %f\n", spc[0],spc[1]
                        {
                                _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);
+                               }
+                               _scalarbarActor->SetHeight(0.4);        //default  0.8
+                               _scalarbarActor->SetWidth(0.08);    //default  0.17
+
+                               _thresholdActor->SetOpacity( 1 );
                                _thresholdActor->InterpolateOn(  );
+                               
                                if (directionViewer==0)
                                {
                                        _thresholdActor->SetPosition( 900-1,0,0 );
@@ -506,9 +510,10 @@ printf("EED  LayerImageBase::onThreshold  A img-spc %f  %f  %f\n", spc[0],spc[1]
                _thresholdMapper->SetInput( img );
                _thresholdMapper->SetLookupTable( _thresholdTable );
                _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
-               
-//             _scalarbarActor->SetLookupTable( _thresholdTable );
-               _scalarbarActor->SetLookupTable( _thresholdMapper->GetLookupTable() );
+               _thresholdActor->SetOpacity(_opacity);
+
+               _scalarbarActor->SetLookupTable( _thresholdTable );
+//             _scalarbarActor->SetLookupTable( _thresholdMapper->GetLookupTable() );
                _scalarbarActor->SetTitle("Value");
                _scalarbarActor->SetNumberOfLabels(4);
                int fontsize = _scalarbarActor->GetLabelTextProperty()->GetFontSize();
@@ -516,9 +521,6 @@ printf("EED  LayerImageBase::onThreshold  A img-spc %f  %f  %f\n", spc[0],spc[1]
 
 //             _scalarbarActor->SetTextPad(4);  ??
 
-GetImage()-> GetSpacing(spc);
-printf("EED  LayerImageBase::onThreshold  B img-spc %f  %f  %f\n", spc[0],spc[1],spc[2]);
-
 
                } // _image
 }
@@ -555,8 +557,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;
 }
 
 //----------------------------------------------------------------------------
@@ -594,6 +598,12 @@ void LayerImageBase::GetImageScalarRange()
        _range[1]=max;
 }
 
+vtkScalarsToColors* LayerImageBase::GetLookupTable()
+{
+       return _thresholdTable;
+}
+
+
 
 
 // EOF