#include "LayerImageBase.h"
+#include "wxMPRBaseData.h"
+#include "wxVtk2DBaseView.h"
+#include "wxVTKRenderWindowInteractor.h"
+#include "vtkTextProperty.h"
+
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
-ColorLayerImageBasevtkInteractor::ColorLayerImageBasevtkInteractor(LayerImageBase* layerImageBase)
-{
- _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; }
+ ColorLayerObserver()
+ {
+ _layerimagebase = NULL;
+ }
-//---------------------------------------------------------------------------------------------
-bool ColorLayerImageBasevtkInteractor::OnMouseMove()
-{
- printf("EED ColorLayerImageBasevtkInteractor::OnMouseMove \n");
- if (_vtkInteractorStyleBaseView->GetRefresh_waiting()==true)
- {
- _layerImageBase->GetvtkImageReslice()->Modified();
- }
+ virtual void Execute(vtkObject *wdg, unsigned long event, void* calldata)
+ {
+ if (_layerimagebase!= NULL)
+ {
+
+ wxVtkBaseView *wxvtkbaseview = _layerimagebase->GetwxVtkBaseView();
+ if (wxvtkbaseview!=NULL)
+ {
+
+ 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
+ }
+
+ void SetLayerImageBase(LayerImageBase* layerimagebase)
+ {
+ _layerimagebase = layerimagebase;
+ }
+
+private:
+ LayerImageBase* _layerimagebase;
+};
- return true;
-}
//---------------------------------------------------------------------------------------------
LayerImageBase::LayerImageBase()
{
- _actorPresent = false;
- _Z = 0;
- _thresholdTable = NULL;
- _thresholdMapper = NULL;
- _thresholdActor = NULL;
+ _actorPresent = false;
+ _X = 0;
+ _Y = 0;
+ _Z = 0;
+ _thresholdTable = NULL;
+ _thresholdMapper = NULL;
+ _scalarbarActor = NULL;
+ _thresholdActor = NULL;
_image = NULL;
- _baseView = NULL;
- _imageReslicer = vtkImageReslice::New();
+ _baseView = NULL;
+ _imageReslicer = vtkImageReslice::New();
+}
+//----------------------------------------------------------------------------
+LayerImageBase::~LayerImageBase()
+{
}
//----------------------------------------------------------------------------
- LayerImageBase::~LayerImageBase()
- {
- }
+void LayerImageBase::SetX(int x)
+{
+ _X = x;
+}
+
+//----------------------------------------------------------------------------
+void LayerImageBase::SetY(int y)
+{
+ _Y = y;
+}
//----------------------------------------------------------------------------
void LayerImageBase::SetZ(int z)
_Z = z;
}
+//----------------------------------------------------------------------------
+int LayerImageBase::GetX() // virtual
+{
+ return _X;
+}
+
+//----------------------------------------------------------------------------
+int LayerImageBase::GetY() // virtual
+{
+ return _Y;
+}
//----------------------------------------------------------------------------
int LayerImageBase::GetZ() // virtual
{
return _Z;
}
+
//----------------------------------------------------------------------------
vtkImageData* LayerImageBase::GetImage()
{
//----------------------------------------------------------------------------
void LayerImageBase::SetImage(vtkImageData* image)
{
+ double spc[3];
+ int ext[6];
_image = image;
+ _image->GetSpacing(spc);
+ _image->GetWholeExtent(ext);
+ int sx=ext[1]-ext[0]+1;
+ int sy=ext[3]-ext[2]+1;
+ int sz=ext[5]-ext[4]+1;
+ int ssx=(sx/2)*spc[0];
+ int ssy=(sy/2)*spc[1];
+ int ssz=(sz/2)*spc[2];
+ SetX( ssx );
+ SetY( ssy );
+ SetZ( ssz );
+ _image->Update();
+ _image->GetScalarRange( _range );
+ _thresholdTable = vtkLookupTable::New();
}
-//----------------------------------------------------------------------------
-void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
+void LayerImageBase::SetRangeForColorBar(std::vector<double> &range)
+{
+ _rangeForColorBar=range;
+}
+
+void LayerImageBase::GetRangeForColorBar(double &minRange, double &maxRange)
{
- printf("EED LayerImageBase::SetwxVtkBaseView start baseview:%p \n", baseview);
+ if (_rangeForColorBar.size()==2)
+ {
+ minRange = _rangeForColorBar[0];
+ maxRange = _rangeForColorBar[1];
+ } else {
+ minRange = _range[0];
+ maxRange = _range[1];
+ }
+}
+
- _baseView = baseview;
- vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)(_baseView->GetInteractorStyleBaseView());
- isbv->AddInteractorStyleMaracas( new ColorLayerImageBasevtkInteractor(this) );
-
- printf("EED LayerImageBase::SetwxVtkBaseView end \n");
+//----------------------------------------------------------------------------
+void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
+{
+ if (_baseView==NULL)
+ {
+ _baseView = baseview;
+ ColorLayerObserver *colorlayerobserver = ColorLayerObserver::New();
+ _baseView->GetVtkBaseData()->AddObserver( 1, colorlayerobserver );
+ colorlayerobserver->SetLayerImageBase(this);
+
+ } // if _baseView
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void LayerImageBase::Refresh()
{
- printf("EED LayerImageBase::Refresh\n");
if (_baseView!=NULL)
{
_baseView->Refresh();
}
//----------------------------------------------------------------------------
-int LayerImageBase::CleanZ(int z)
+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]) )
+ {
+ 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];
}
- return z;
+
}
//----------------------------------------------------------------------------
void LayerImageBase::onThreshold()
{
-
- printf("EED LayerImageBase::onThreshold start \n");
-
if ((_image!=NULL) && (_baseView!=NULL))
{
- int z=CleanZ( GetZ() );
+ 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];
+
+ vtkCamera *camera = _baseView->GetRenderer()->GetActiveCamera();
+ int directionViewer=0;
+ if (camera->GetParallelProjection()==1)
+ {
+ wxVtk2DBaseView *wxvtk2dbasevie = (wxVtk2DBaseView *)_baseView;
+ directionViewer = wxvtk2dbasevie->GetDirection();
+ } // ParallelProjection
+
if (!GetActorPresent())
{
if (_thresholdActor==NULL)
{
_thresholdActor = vtkImageActor::New( );
+ _scalarbarActor = vtkScalarBarActor::New();
_thresholdActor->SetOpacity( 0.6 );
_thresholdActor->InterpolateOn( );
- _thresholdActor->SetPosition( 0,0, -900-1 );
+ if (directionViewer==0)
+ {
+ _thresholdActor->SetPosition( 900-1,0,0 );
+ _thresholdActor->RotateY( -90 );
+ }
+ if (directionViewer==1)
+ {
+ _thresholdActor->SetPosition( 0,-900-1, 0 );
+ _thresholdActor->RotateX( 90 );
+ }
+ if (directionViewer==2)
+ {
+ _thresholdActor->SetPosition( 0,0, -900-1 );
+ }
} // _thresholdActor
_baseView->GetRenderer()->AddActor( _thresholdActor );
+ _baseView->GetRenderer()->AddActor2D( _scalarbarActor );
_actorPresent = true;
} // !GetActorPresent()
ConfigLookupTable(); // virtual method
_imageReslicer->SetInput( GetImage() );
_imageReslicer->SetInformationInput( GetImage() );
- _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
+
+ if (directionViewer==0)
+ {
+ _imageReslicer->SetResliceAxesDirectionCosines( 0,0,1, 0,1,0, -1,0,0 );
+ _imageReslicer->SetResliceAxesOrigin(x,0,0);
+ }
+
+ if (directionViewer==1)
+ {
+ _imageReslicer->SetResliceAxesDirectionCosines( 1,0,0 ,0,0,1, 0,-1,0 );
+ _imageReslicer->SetResliceAxesOrigin(0,y,0);
+ }
+
+ if (directionViewer==2)
+ {
+ _imageReslicer->SetResliceAxesDirectionCosines( 1,0,0, 0,1,0 ,0,0,1 );
+ _imageReslicer->SetResliceAxesOrigin(0,0,z);
+ }
+
+
_imageReslicer->SetOutputDimensionality(2);
// _imageReslicer->SetInterpolationModeToLinear();
_imageReslicer->SetInterpolationModeToNearestNeighbor();
- _imageReslicer->SetResliceAxesOrigin(0,0,z);
vtkImageData *img = _imageReslicer->GetOutput();
// img->Update();
// img->UpdateInformation();
+// _thresholdTable->Update();
_thresholdMapper->SetInput( img );
_thresholdMapper->SetLookupTable( _thresholdTable );
_thresholdActor->SetInput( _thresholdMapper->GetOutput() );
-
- printf("EED LayerImageBase::onThreshold working \n");
-
+// _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");
}
{
wxVtkBaseView * baseView = _baseView;
baseView->GetRenderer()->RemoveActor( _thresholdActor );
+ baseView->GetRenderer()->RemoveActor( _scalarbarActor );
+
_actorPresent = false;
}
}
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