Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkSeedsImage.h"
00019
00020 #include "mitkOperation.h"
00021 #include "mitkOperationActor.h"
00022 #include "mitkDrawOperation.h"
00023 #include "mitkImageAccessByItk.h"
00024 #include "mitkInteractionConst.h"
00025 #include "mitkRenderingManager.h"
00026
00027 #include <itkNeighborhoodIterator.h>
00028 #include <itkLineConstIterator.h>
00029
00030
00031 mitk::SeedsImage::SeedsImage()
00032 {
00033 m_GaussianFunction3D = GaussianFunction3DType::New();
00034 m_GaussianFunction2D = GaussianFunction2DType::New();
00035 }
00036
00037 mitk::SeedsImage::~SeedsImage()
00038 {
00039 }
00040
00041 void mitk::SeedsImage::Initialize()
00042 {
00043 Superclass::Initialize();
00044 m_Radius = 1;
00045 }
00046
00047
00048 void mitk::SeedsImage::ExecuteOperation(mitk::Operation* operation)
00049 {
00050
00051 m_Spacing = this->GetGeometry()->GetSpacing();
00052 for(unsigned int i=0; i<this->GetDimension(); i++)
00053 orig_size[i] = this->GetDimension(i);
00054
00055 mitk::DrawOperation * seedsOp =
00056 dynamic_cast< mitk::DrawOperation * >( operation );
00057
00058 if ( seedsOp != NULL )
00059 {
00060 m_DrawState = seedsOp->GetDrawState();
00061
00062 if (m_Radius != seedsOp->GetRadius())
00063 {
00064 m_Radius = seedsOp->GetRadius();
00065 }
00066
00067 switch (operation->GetOperationType())
00068 {
00069 case mitk::OpADD:
00070 {
00071 m_Point = seedsOp->GetPoint();
00072 m_LastPoint = m_Point;
00073 AccessByItk(this, AddSeedPoint);
00074 break;
00075 }
00076 case mitk::OpMOVE:
00077 {
00078 m_Point = seedsOp->GetPoint();
00079 AccessByItk(this, AddSeedPoint);
00080 AccessByItk(this, PointInterpolation);
00081 m_LastPoint = m_Point;
00082 break;
00083 }
00084 case mitk::OpUNDOADD:
00085 {
00086 m_Point = seedsOp->GetPoint();
00087 m_LastPoint = m_Point;
00088 m_DrawState = 0;
00089
00090
00091
00092 m_Radius = m_Radius+4;
00093 AccessByItk(this, AddSeedPoint);
00094 break;
00095 }
00096 case mitk::OpUNDOMOVE:
00097 {
00098 m_Point = seedsOp->GetPoint();
00099 m_DrawState = 0;
00100
00101
00102
00103 m_Radius = m_Radius+4;
00104 AccessByItk(this, AddSeedPoint);
00105 AccessByItk(this, PointInterpolation);
00106 m_LastPoint = m_Point;
00107 break;
00108 }
00109 }
00110
00111
00112 mitk::RenderingManager::GetInstance()->RequestUpdateAll();
00113
00114
00115 this->Modified();
00116 }
00117 }
00118
00119
00120 template < typename SeedsImageType >
00121 void mitk::SeedsImage::AddSeedPoint(SeedsImageType* itkImage)
00122 {
00123 typedef itk::NeighborhoodIterator< SeedsImageType >
00124 NeighborhoodIteratorType;
00125 typedef typename NeighborhoodIteratorType::IndexType IndexType;
00126
00127 NeighborhoodIteratorType& nit = this->GetNit< SeedsImageType >( itkImage );
00128
00129 const unsigned int dimension =
00130 ::itk::GetImageDimension<SeedsImageType>::ImageDimension;
00131
00132 mitk::Point3D index;
00133 this->GetGeometry()->WorldToIndex( m_Point, index );
00134
00135 IndexType itkIndex;
00136 unsigned int d;
00137 for ( d = 0; d < dimension; ++d )
00138 {
00139 itkIndex[d] = (int)(index[d] + 0.5);
00140 }
00141 nit.SetLocation( itkIndex );
00142
00143
00144 unsigned int i;
00145 for ( i = 0; i < nit.Size(); ++i )
00146 {
00147 if ( nit[i] != 0 )
00148 {
00149 try
00150 {
00151 nit.SetPixel( i, m_DrawState );
00152 }
00153 catch( itk::RangeError & )
00154 {
00155 }
00156 }
00157 }
00158 }
00159
00160
00161 template < typename SeedsImageType >
00162 void mitk::SeedsImage::PointInterpolation(SeedsImageType* itkImage)
00163 {
00164 typedef itk::NeighborhoodIterator< SeedsImageType >
00165 NeighborhoodIteratorType;
00166 typedef typename NeighborhoodIteratorType::IndexType IndexType;
00167
00168
00169 NeighborhoodIteratorType& nit = this->GetNit< SeedsImageType >( itkImage );
00170
00171 const unsigned int dimension =
00172 ::itk::GetImageDimension<SeedsImageType>::ImageDimension;
00173
00174 mitk::Point3D indexBegin, indexEnd;
00175 this->GetGeometry()->WorldToIndex( m_Point, indexBegin );
00176 this->GetGeometry()->WorldToIndex( m_LastPoint, indexEnd );
00177
00178 IndexType itkIndexBegin, itkIndexEnd;
00179 unsigned int d;
00180 for ( d = 0; d < dimension; ++d )
00181 {
00182 itkIndexBegin[d] = (int)(indexBegin[d] + 0.5);
00183 itkIndexEnd[d] = (int)(indexEnd[d] + 0.5);
00184 }
00185
00186
00187 typedef itk::LineConstIterator< SeedsImageType > LineIteratorType;
00188 LineIteratorType lit( itkImage, itkIndexBegin, itkIndexEnd );
00189
00190
00191
00192 bool warningDisplay = itk::Object::GetGlobalWarningDisplay();
00193 itk::Object::GlobalWarningDisplayOff();
00194 for ( lit.GoToBegin(); !lit.IsAtEnd(); ++lit )
00195 {
00196 nit.SetLocation( lit.GetIndex() );
00197
00198 unsigned int i;
00199 for ( i = 0; i < nit.Size(); ++i )
00200 {
00201 if ( nit[i] != 0 )
00202 {
00203 try
00204 {
00205 nit.SetPixel( i, m_DrawState );
00206 }
00207 catch( itk::RangeError & )
00208 {
00209 }
00210 }
00211 }
00212 }
00213 itk::Object::SetGlobalWarningDisplay( warningDisplay );
00214 }
00215
00216 void mitk::SeedsImage::ClearBuffer()
00217 {
00218 AccessByItk(this, ClearBuffer);
00219 }
00220
00221 template < typename SeedsImageType >
00222 void mitk::SeedsImage::ClearBuffer(SeedsImageType* itkImage)
00223 {
00224 itkImage->FillBuffer(0);
00225 }
00226
00227 template < typename SeedsImageType >
00228 itk::NeighborhoodIterator< SeedsImageType >&
00229 mitk::SeedsImage::GetNit( SeedsImageType* image )
00230 {
00231 typedef itk::NeighborhoodIterator< SeedsImageType >
00232 NeighborhoodIteratorType;
00233 typedef typename NeighborhoodIteratorType::OffsetType OffsetType;
00234 typedef typename NeighborhoodIteratorType::SizeType SizeType;
00235 typedef itk::GaussianSpatialFunction< int, SeedsImageType::ImageDimension >
00236 GaussianFunctionType;
00237
00238 static SeedsImageType* iteratedImage = 0;
00239 static NeighborhoodIteratorType nit;
00240 static typename GaussianFunctionType::Pointer gaussianFunction
00241 = GaussianFunctionType::New();
00242
00243 if ( iteratedImage != image )
00244 {
00245 SizeType radius;
00246 radius.Fill( m_Radius);
00247 nit.Initialize( radius, image, image->GetBufferedRegion() );
00248 iteratedImage = image;
00249 }
00250
00251 nit.SetRadius( m_Radius );
00252
00253 unsigned int i;
00254 for ( i = 0; i < nit.GetCenterNeighborhoodIndex()*2+1; ++i )
00255 {
00256 OffsetType offset = nit.GetOffset( i );
00257
00258 typename GaussianFunctionType::InputType point;
00259 double dist = 0;
00260 unsigned int d;
00261 for ( d = 0; d < SeedsImageType::ImageDimension; ++d )
00262 {
00263 point[d] = offset[d];
00264 dist += offset[d] * offset[d];
00265 }
00266 }
00267
00268 return nit;
00269 }
00270