LayerImageBase.cxx
Go to the documentation of this file.00001
00007 #include "LayerImageBase.h"
00008
00009 LayerImageBase::LayerImageBase()
00010 {
00011 _actorPresent = false;
00012 _Z = 0;
00013 _thresholdTable = NULL;
00014 _thresholdMapper = NULL;
00015 _thresholdActor = NULL;
00016 _image = NULL;
00017 _baseView = NULL;
00018 _imageReslicer = vtkImageReslice::New();
00019
00020 }
00021
00022
00023 LayerImageBase::~LayerImageBase()
00024 {
00025 }
00026
00027
00028 void LayerImageBase::SetZ(int z)
00029 {
00030 _Z = z;
00031 }
00032
00033
00034 int LayerImageBase::GetZ()
00035 {
00036 return _Z;
00037 }
00038
00039
00040 vtkImageData* LayerImageBase::GetImage()
00041 {
00042 return _image;
00043 }
00044
00045
00046 bool LayerImageBase::GetActorPresent()
00047 {
00048 return _actorPresent;
00049 }
00050
00051
00052
00053
00054 void LayerImageBase::SetImage(vtkImageData* image)
00055 {
00056 _image = image;
00057 }
00058
00059
00060 void LayerImageBase::SetwxVtkBaseView(wxVtkBaseView *baseview)
00061 {
00062 _baseView = baseview;
00063 }
00064
00065
00066 wxVtkBaseView *LayerImageBase::GetwxVtkBaseView()
00067 {
00068 return _baseView;
00069 }
00070
00071
00072 void LayerImageBase::Refresh()
00073 {
00074 if (_baseView!=NULL)
00075 {
00076 _baseView->Refresh();
00077 }
00078 }
00079
00080
00081
00082 vtkLookupTable* LayerImageBase::GetThresholdTable()
00083 {
00084 return _thresholdTable;
00085 }
00086
00087
00088 int LayerImageBase::CleanZ(int z)
00089 {
00090 int ext[6];
00091 _image->GetWholeExtent(ext);
00092
00093 if (z<0)
00094 {
00095 z=0;
00096 }
00097
00098 if ( z > (ext[5]-ext[4]) )
00099 {
00100 z=ext[5]-ext[4];
00101 }
00102
00103 return z;
00104 }
00105
00106
00107 void LayerImageBase::onThreshold()
00108 {
00109
00110 if ((_image!=NULL) && (_baseView!=NULL))
00111 {
00112 int z=CleanZ( GetZ() );
00113
00114 if (!GetActorPresent())
00115 {
00116 if (_thresholdTable==NULL)
00117 {
00118
00119 _thresholdTable = vtkLookupTable::New();
00120 }
00121
00122 if (_thresholdMapper==NULL)
00123 {
00124 _thresholdMapper = vtkImageMapToColors::New( );
00125 }
00126
00127 if (_thresholdActor==NULL)
00128 {
00129 _thresholdActor = vtkImageActor::New( );
00130 _thresholdActor->SetOpacity( 0.6 );
00131 _thresholdActor->InterpolateOn( );
00132 _thresholdActor->SetPosition( 0,0, 900-1 );
00133 }
00134 _baseView->GetRenderer()->AddActor( _thresholdActor );
00135 _actorPresent = true;
00136 }
00137
00138 ConfigLookupTable();
00139 _imageReslicer->SetInput( GetImage() );
00140 _imageReslicer->SetInformationInput( GetImage() );
00141 _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
00142 _imageReslicer->SetOutputDimensionality(2);
00143 _imageReslicer->SetInterpolationModeToLinear();
00144 _imageReslicer->SetResliceAxesOrigin(0,0,z);
00145
00146 vtkImageData *img = _imageReslicer->GetOutput();
00147 img->Update();
00148 img->UpdateInformation();
00149
00150 _thresholdMapper->SetInput( img );
00151 _thresholdMapper->SetLookupTable( _thresholdTable );
00152 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
00153 }
00154 }
00155
00156
00157
00158
00159 void LayerImageBase::onThresholdChange()
00160 {
00161 if (_actorPresent)
00162 {
00163 onThreshold();
00164 }
00165 }
00166
00167
00168 void LayerImageBase::onThresholdInterpolation(bool interpolate)
00169 {
00170 if (_thresholdActor!=NULL)
00171 {
00172 if (interpolate)
00173 {
00174 _thresholdActor->InterpolateOn( );
00175 }
00176 else
00177 {
00178 _thresholdActor->InterpolateOff( );
00179 }
00180 }
00181 }
00182
00183
00184 void LayerImageBase::onThresholdChangeOpacity (int opacity)
00185 {
00186 if (_actorPresent)
00187 {
00188 _thresholdActor->SetOpacity(opacity*0.1);
00189 }
00190 }
00191
00192
00193 void LayerImageBase::onThresholdRemove()
00194 {
00195 if (_actorPresent)
00196 {
00197 wxVtkBaseView * baseView = _baseView;
00198 baseView->GetRenderer()->RemoveActor( _thresholdActor );
00199 _actorPresent = false;
00200 }
00201 }
00202
00203
00204
00205
00206
00207