#include "LayerImageBase.h"
+#include "wxMPRBaseData.h"
#include "wxVtk2DBaseView.h"
-#include "wxVTKRenderWindowInteractor.h"
+#include "creawxVTKRenderWindowInteractor.h"
+#include "vtkTextProperty.h"
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
-ColorLayerImageBasevtkInteractor::ColorLayerImageBasevtkInteractor(LayerImageBase* layerImageBase)
-{
- _state=false;
- _stateKey=false;
- _layerImageBase=layerImageBase;
-
-}
+// Callback for the interaction
+class ColorLayerObserver : public vtkCommand{
+ public:
+ virtual char const *GetClassName() const { return "ColorLayerObserver";}
-//---------------------------------------------------------------------------------------------
-ColorLayerImageBasevtkInteractor::~ColorLayerImageBasevtkInteractor()
-{
-}
+ static ColorLayerObserver *New() { return new ColorLayerObserver; }
-//---------------------------------------------------------------------------------------------
-bool ColorLayerImageBasevtkInteractor::OnChar()
-{
- return true;
-}
-
-
-//---------------------------------------------------------------------------------------------
-bool ColorLayerImageBasevtkInteractor::OnMouseMove() // vitual
-{
- printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove start \n");
+ ColorLayerObserver()
+ {
+ _layerimagebase = NULL;
+ }
- vtkRenderWindowInteractor *interactor = _vtkInteractorStyleBaseView->GetInteractor();
+ virtual void Execute(vtkObject *wdg, unsigned long event, void* calldata)
+ {
+ if (_layerimagebase!= NULL)
+ {
- // For example in ManualPaint Action
- // This is not working, because the order of insertion events mecanism (_vtkInteractorStyleBaseView)
- // Layer first Paint after.
- // the only way to make it works is to take the axes an paint. this force a first SetParent_refresh_waiting()
-// if ( this->_vtkInteractorStyleBaseView->GetParent_refresh_waiting() == true )
+ wxVtkBaseView *wxvtkbaseview = _layerimagebase->GetwxVtkBaseView();
+ if (wxvtkbaseview!=NULL)
+ {
- if ( interactor->GetControlKey()==1 ) // EED This if for ManaulPaint Interaction compatibility
- {
- printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove need Refresh \n" );
- _layerImageBase->onThreshold();
- _layerImageBase->GetvtkImageReslice()->Modified();
- }
- else {
- printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove NOT need Refresh \n" );
- }
+ vtkMPRBaseData *vtkmprbasedata = (vtkMPRBaseData*)wxvtkbaseview->GetVtkBaseData();
+ if (vtkmprbasedata!=NULL)
+ {
+ _layerimagebase->SetX( vtkmprbasedata->GetX() );
+ _layerimagebase->SetY( vtkmprbasedata->GetY() );
+ _layerimagebase->SetZ( vtkmprbasedata->GetZ() );
+ _layerimagebase->onThresholdChange();
+ } // if basedata
+
+ } // if wxvtkbaseview
+ } //if layerimagebase
+ }
-
- if (_state==true)
+ void SetLayerImageBase(LayerImageBase* layerimagebase)
{
- wxVtk2DBaseView *wxvtk2Dbaseview = (wxVtk2DBaseView*) _vtkInteractorStyleBaseView->GetWxVtk2DBaseView();
- wxVTKRenderWindowInteractor *wxVTKiren = wxvtk2Dbaseview->GetWxVTKRenderWindowInteractor();
- int px, py;
- wxVTKiren->GetEventPosition(px, py);
-
-// int typeView = 1;
- double X = (double) px;
- double Y = (double) py;
- double Z = wxvtk2Dbaseview->GetActualSlice();
-// wxvtk2Dbaseview->TransFromCoordScreenToWorld(X, Y, Z,true, typeView);
- wxvtk2Dbaseview->TransFromCoordScreenToWorld(X, Y, Z, true);
-
-// _manualPaintControler->PaintImage((int) X, (int) Y, (int) Z);
-
- _layerImageBase->SetX( (int)X );
- _layerImageBase->SetY( (int)Y );
- _layerImageBase->SetZ( (int)Z );
- _layerImageBase->onThreshold();
-// _layerImageBase->Refresh();
-
- this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
-
- if (_vtkInteractorStyleBaseView->GetRefresh_waiting()==true)
- {
- _layerImageBase->GetvtkImageReslice()->Modified();
- }
- printf("EED ColorLayerImageBasevtkInteractor::YESSSSSS \n");
+ _layerimagebase = layerimagebase;
}
- return true;
-}
-//---------------------------------------------------------------------------------------------
-bool ColorLayerImageBasevtkInteractor::OnRightButtonDown() // virtual
-{
- printf("EED ColorLayerImageBasevtkInteractor::OnRightButtonDown \n");
- _state=true;
- return true;
-}
+private:
+ LayerImageBase* _layerimagebase;
+};
-//---------------------------------------------------------------------------------------------
-bool ColorLayerImageBasevtkInteractor::OnRightButtonUp() // virtual
-{
- printf("EED ColorLayerImageBasevtkInteractor::OnRightButtonUp \n");
- _state=false;
- return true;
-}
//---------------------------------------------------------------------------------------------
LayerImageBase::LayerImageBase()
{
_actorPresent = false;
- _X = 0;
- _Y = 0;
- _Z = 0;
+ _X = -1;
+ _Y = -1;
+ _Z = -1;
_thresholdTable = NULL;
_thresholdMapper = NULL;
+ _scalarbarActor = NULL;
_thresholdActor = NULL;
- _image = NULL;
- _baseView = NULL;
+ _image = NULL;
+ _baseView = NULL;
_imageReslicer = vtkImageReslice::New();
-
+ _imageChangeInformation = vtkImageChangeInformation::New();
}
//----------------------------------------------------------------------------
- LayerImageBase::~LayerImageBase()
- {
- }
+LayerImageBase::~LayerImageBase()
+{
+}
//----------------------------------------------------------------------------
void LayerImageBase::SetX(int x)
//----------------------------------------------------------------------------
vtkImageData* LayerImageBase::GetImage()
{
- return _image;
+// return _image;
+ vtkImageData *result;
+ if (_image==NULL)
+ {
+ result = NULL;
+ } else {
+ result = _imageChangeInformation->GetOutput();
+ }
+ return result;
}
//----------------------------------------------------------------------------
}
-
//----------------------------------------------------------------------------
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;
+
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
+ _image->Update();
+ _image->GetWholeExtent(ext);
+#else
+ _image->GetExtent(ext);
+#endif
+
+ dimensionOriginalLayer[0] = ext[1]-ext[0]+1;
+ dimensionOriginalLayer[1] = ext[3]-ext[2]+1;
+ dimensionOriginalLayer[2] = ext[5]-ext[4]+1;
+ SetDimensionOriginalLayer(dimensionOriginalLayer);
+ double spcOriginalLayer[3];
+ _image->GetSpacing(spcOriginalLayer);
+ SetSpcOriginalLayer(spcOriginalLayer);
+ if (GetwxVtkBaseView()!=NULL)
+ {
+ vtkImageData *imagebase = GetwxVtkBaseView()->GetVtkBaseData()->GetImageData();
+ if (imagebase!=NULL)
+ {
+
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
+ imagebase->GetWholeExtent(ext);
+#else
+ imagebase->GetExtent(ext);
+#endif
+
+ dimBase[0]=ext[1]-ext[0]+1;
+ dimBase[1]=ext[3]-ext[2]+1;
+ dimBase[2]=ext[5]-ext[4]+1;
+ SetDimensionBase(dimBase);
+ imagebase->GetSpacing(spcBase);
+ SetSpcBase(spcBase);
+
+ 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->GetScalarRange( _range );
+ _thresholdTable = vtkLookupTable::New();
+
+
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
+ _imageChangeInformation->SetInput(_image);
+#else
+ _imageChangeInformation->SetInputData(_image);
+ _imageChangeInformation->Update();
+#endif
+
+}
+
+//------------------------------------------------------------------------------
+void LayerImageBase::SetSpcOriginalLayer(double spc[3])
+{
+ _spcOriginalLayer[0] = spc[0];
+ _spcOriginalLayer[1] = spc[1];
+ _spcOriginalLayer[2] = spc[2];
+}
+
+//------------------------------------------------------------------------------
+void LayerImageBase::SetNewSpacingLayer(double spc[3])
+{
+ _newSpcLayer[0] = spc[0];
+ _newSpcLayer[1] = spc[1];
+ _newSpcLayer[2] = spc[2];
+ _imageChangeInformation->SetOutputSpacing( _newSpcLayer );
+
+}
+
+
+//------------------------------------------------------------------------------
+void LayerImageBase::SetSpcBase(double spc[3])
+{
+ _spcBase[0] = spc[0];
+ _spcBase[1] = spc[1];
+ _spcBase[2] = spc[2];
+}
+
+//------------------------------------------------------------------------------
+void LayerImageBase::SetDimensionOriginalLayer(int dim[3])
+{
+ _dimOriginalLayer[0] = dim[0];
+ _dimOriginalLayer[1] = dim[1];
+ _dimOriginalLayer[2] = dim[2];
+}
+
+//------------------------------------------------------------------------------
+void LayerImageBase::SetDimensionBase(int dim[3])
+{
+ _dimBase[0] = dim[0];
+ _dimBase[1] = dim[1];
+ _dimBase[2] = dim[2];
+}
+
+
+
+//------------------------------------------------------------------------------
+void LayerImageBase::GetSpcOriginalLayer(double *spc)
+{
+ spc[0] = _spcOriginalLayer[0];
+ spc[1] = _spcOriginalLayer[1];
+ spc[2] = _spcOriginalLayer[2];
}
+//------------------------------------------------------------------------------
+void LayerImageBase::GetSpcBase(double *spc)
+{
+ spc[0] = _spcBase[0];
+ spc[1] = _spcBase[1];
+ spc[2] = _spcBase[2];
+}
+
+//------------------------------------------------------------------------------
+void LayerImageBase::GetDimensionOriginalLayer(int *dim)
+{
+ dim[0] = _dimOriginalLayer[0];
+ dim[1] = _dimOriginalLayer[1];
+ dim[2] = _dimOriginalLayer[2];
+}
+
+//------------------------------------------------------------------------------
+void LayerImageBase::GetDimensionBase(int *dim)
+{
+ dim[0] = _dimBase[0];
+ dim[1] = _dimBase[1];
+ dim[2] = _dimBase[2];
+}
+
+
+//------------------------------------------------------------------------------
+void LayerImageBase::SetColorBarPosition(std::vector<int> &colorbarposition)
+{
+ _colorBarPosition=colorbarposition;
+}
+
+//------------------------------------------------------------------------------
+void LayerImageBase::SetRangeForColorBar(std::vector<double> &range)
+{
+ _rangeForColorBar=range;
+}
+
+
+//------------------------------------------------------------------------------
+void LayerImageBase::GetRangeForColorBar(double &minRange, double &maxRange)
+{
+ if (_rangeForColorBar.size()==2)
+ {
+ minRange = _rangeForColorBar[0];
+ maxRange = _rangeForColorBar[1];
+ } else {
+ minRange = _range[0];
+ maxRange = _range[1];
+ }
+}
+
+
+
//----------------------------------------------------------------------------
void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
{
- printf("EED LayerImageBase::SetwxVtkBaseView start baseview:%p \n", baseview);
if (_baseView==NULL)
- {
- _baseView = baseview;
- vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
- isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
+ {
+ _baseView = baseview;
+ ColorLayerObserver *colorlayerobserver = ColorLayerObserver::New();
+ _baseView->GetVtkBaseData()->AddObserver( 1, colorlayerobserver );
+ colorlayerobserver->SetLayerImageBase(this);
} // if _baseView
- printf("EED LayerImageBase::SetwxVtkBaseView end \n");
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void LayerImageBase::Refresh()
{
- printf("EED LayerImageBase::Refresh\n");
if (_baseView!=NULL)
{
_baseView->Refresh();
//----------------------------------------------------------------------------
void LayerImageBase::CleanXYZ(double &x, double &y, double &z)
{
- int ext[6];
- _image->GetWholeExtent(ext);
-
if (x<0)
{
x=0;
}
-
if (y<0)
{
y=0;
}
-
if (z<0)
{
z=0;
}
-
- if ( x > (ext[1]-ext[0]) )
+ double maxSize;
+ maxSize=_dimOriginalLayer[0]*_newSpcLayer[0];
+ if ( x > maxSize )
{
- z=ext[1]-ext[0];
+ x=maxSize;
}
-
- if ( y > (ext[3]-ext[2]) )
+ maxSize=_dimOriginalLayer[1]*_newSpcLayer[1];
+ if ( y > maxSize )
{
- z=ext[3]-ext[2];
+ y = maxSize;
}
-
- if ( z > (ext[5]-ext[4]) )
+ maxSize=_dimOriginalLayer[2]*_newSpcLayer[2];
+ if ( z > maxSize )
{
- z=ext[5]-ext[4];
+ z = maxSize;
}
-
-
+
}
//----------------------------------------------------------------------------
void LayerImageBase::onThreshold()
{
-
- printf("EED LayerImageBase::onThreshold start \n");
-
if ((_image!=NULL) && (_baseView!=NULL))
{
- double spc[3];
- GetImage()-> GetSpacing(spc);
double x=GetX();
double y=GetY();
double z=GetZ();
- CleanXYZ(x,y,z);
- x = x*spc[0];
- y = y*spc[1];
- z = z*spc[2];
-
+ x = x*_spcBase[0];
+ y = y*_spcBase[1];
+ z = z*_spcBase[2];
- printf("EED LayerImageBase::onThreshold z = %d spcZ%f\n" , z, spc[2]);
-
+ CleanXYZ(x,y,z);
vtkCamera *camera = _baseView->GetRenderer()->GetActiveCamera();
int directionViewer=0;
directionViewer = wxvtk2dbasevie->GetDirection();
} // ParallelProjection
-printf("EED LayerImageBase::onThreshold projection = %d\n" , camera->GetParallelProjection() );
-printf("EED LayerImageBase::onThreshold direction = %d\n" , directionViewer );
-
if (!GetActorPresent())
{
if (_thresholdActor==NULL)
{
_thresholdActor = vtkImageActor::New( );
- _thresholdActor->SetOpacity( 0.6 );
+ _scalarbarActor = vtkScalarBarActor::New();
+ 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 );
}
} // _thresholdActor
_baseView->GetRenderer()->AddActor( _thresholdActor );
+ _baseView->GetRenderer()->AddActor2D( _scalarbarActor );
_actorPresent = true;
} // !GetActorPresent()
ConfigLookupTable(); // virtual method
+
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
_imageReslicer->SetInput( GetImage() );
+#else
+ _imageReslicer->SetInputData( GetImage() );
+#endif
+
_imageReslicer->SetInformationInput( GetImage() );
if (directionViewer==0)
_imageReslicer->SetResliceAxesOrigin(0,0,z);
}
-
_imageReslicer->SetOutputDimensionality(2);
// _imageReslicer->SetInterpolationModeToLinear();
_imageReslicer->SetInterpolationModeToNearestNeighbor();
-
+ _imageReslicer->Modified();
+
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
+ // ..
+#else
+ _imageReslicer->Update();
+#endif
vtkImageData *img = _imageReslicer->GetOutput();
// img->Update();
// img->UpdateInformation();
+// _thresholdTable->Update();
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
_thresholdMapper->SetInput( img );
+#else
+ _thresholdMapper->SetInputData( img );
+#endif
+
_thresholdMapper->SetLookupTable( _thresholdTable );
- _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
- printf("EED LayerImageBase::onThreshold working \n");
-
+
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
+ _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
+#else
+ _thresholdMapper->Update();
+ _thresholdActor->SetInputData( _thresholdMapper->GetOutput() );
+#endif
+ _scalarbarActor->SetLookupTable( _thresholdTable );
+// _scalarbarActor->SetLookupTable( _thresholdMapper->GetLookupTable() );
+ _scalarbarActor->SetTitle("Value");
+ _scalarbarActor->SetNumberOfLabels(4);
+ int fontsize = _scalarbarActor->GetLabelTextProperty()->GetFontSize();
+ _scalarbarActor->GetLabelTextProperty()->SetFontSize(fontsize/2);
+// _scalarbarActor->SetTextPad(4); ??
} // _image
- printf("EED LayerImageBase::onThreshold end \n");
}
{
if (_actorPresent)
{
- _thresholdActor->SetOpacity(opacity*0.1);
+ _thresholdActor->SetOpacity(opacity/100.0);
}
}
{
wxVtkBaseView * baseView = _baseView;
baseView->GetRenderer()->RemoveActor( _thresholdActor );
+ baseView->GetRenderer()->RemoveActor( _scalarbarActor );
+
_actorPresent = false;
- }
+ } // if _actorPresent
}
//----------------------------------------------------------------------------
return _thresholdTable;
}
+//----------------------------------------------------------------------------
vtkImageReslice *LayerImageBase::GetvtkImageReslice()
{
return _imageReslicer;
}
-
+//----------------------------------------------------------------------------
+void LayerImageBase::GetImageScalarRange()
+{
+ double min,max;
+ GetRangeForColorBar(min,max);
+// _image->GetScalarRange(_range);
+ _range[0]=min;
+ _range[1]=max;
+}
// EOF