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 #ifndef __itkMultiphaseFiniteDifferenceImageFilter_h
00019 #define __itkMultiphaseFiniteDifferenceImageFilter_h
00020
00021 #include "itkArray.h"
00022 #include "itkInPlaceImageFilter.h"
00023 #include "itkFiniteDifferenceFunction.h"
00024 #include <vnl/vnl_vector.h>
00025 #include "itkImageRegionIterator.h"
00026
00027 #include "itkVector.h"
00028 #include "itkListSample.h"
00029 #include "itkKdTree.h"
00030 #include "itkKdTreeGenerator.h"
00031
00032 namespace itk {
00033
00161 template < class TInputImage,
00162 class TFeatureImage,
00163 class TOutputImage,
00164 class TFiniteDifferenceFunction = FiniteDifferenceFunction<TOutputImage>,
00165 typename TIdCell = unsigned int >
00166 class ITK_EXPORT MultiphaseFiniteDifferenceImageFilter
00167 : public InPlaceImageFilter< TFeatureImage, TOutputImage >
00168 {
00169 public:
00170
00172 typedef MultiphaseFiniteDifferenceImageFilter Self;
00173 typedef InPlaceImageFilter<TFeatureImage, TOutputImage> Superclass;
00174 typedef SmartPointer<Self> Pointer;
00175 typedef SmartPointer<const Self> ConstPointer;
00176
00178 itkTypeMacro( MultiphaseFiniteDifferenceImageFilter, InPlaceImageFilter );
00179
00181 itkStaticConstMacro(ImageDimension, unsigned int, TOutputImage::ImageDimension);
00182
00184 typedef TInputImage InputImageType;
00185 typedef typename InputImageType::Pointer InputImagePointer;
00186 typedef typename InputImageType::PointType InputPointType;
00187 typedef typename InputPointType::CoordRepType InputCoordRepType;
00188 typedef typename InputImageType::IndexType InputIndexType;
00189 typedef typename InputIndexType::IndexValueType InputIndexValueType;
00190 typedef typename InputImageType::SizeType InputSizeType;
00191 typedef typename InputSizeType::SizeValueType InputSizeValueType;
00192 typedef typename InputImageType::RegionType InputRegionType;
00193 typedef typename InputImageType::PixelType InputPixelType;
00194 typedef typename InputImageType::SpacingType InputSpacingType;
00195
00196 typedef TFeatureImage FeatureImageType;
00197 typedef typename FeatureImageType::Pointer FeatureImagePointer;
00198 typedef typename FeatureImageType::RegionType FeatureRegionType;
00199 typedef typename FeatureImageType::SizeType FeatureSizeType;
00200 typedef typename FeatureImageType::SpacingType FeatureSpacingType;
00201 typedef typename FeatureImageType::PointType FeaturePointType;
00202 typedef typename FeatureImageType::PixelType FeaturePixelType;
00203
00204 typedef TOutputImage OutputImageType;
00205 typedef typename OutputImageType::Pointer OutputImagePointer;
00206 typedef typename OutputImageType::PixelType OutputPixelType;
00207 typedef typename OutputImageType::RegionType OutputRegionType;
00208 typedef typename OutputImageType::SizeType OutputSizeType;
00209 typedef typename OutputImageType::SizeValueType OutputSizeValueType;
00210 typedef typename OutputImageType::IndexType OutputIndexType;
00211 typedef typename OutputImageType::IndexValueType OutputIndexValueType;
00212
00213 typedef TIdCell IdCellType;
00214 typedef std::vector< IdCellType > VectorIdCellType;
00215
00219 typedef TFiniteDifferenceFunction FiniteDifferenceFunctionType;
00220 typedef typename FiniteDifferenceFunctionType::Pointer FiniteDifferenceFunctionPointer;
00221 typedef typename FiniteDifferenceFunctionType::TimeStepType TimeStepType;
00222 typedef typename std::vector< TimeStepType > TimeStepVectorType;
00223 typedef typename FiniteDifferenceFunctionType::RadiusType RadiusType;
00224
00225 typedef Vector< float, itkGetStaticConstMacro(ImageDimension) >
00226 CentroidVectorType;
00227 typedef Statistics::ListSample< CentroidVectorType > SampleType;
00228 typedef Statistics::KdTreeGenerator< SampleType > KdTreeGeneratorType;
00229 typedef typename KdTreeGeneratorType::Pointer KdTreeGeneratorPointer;
00230 typedef typename KdTreeGeneratorType::KdTreeType KdTreeType;
00231 typedef typename KdTreeType::Pointer KdTreePointer;
00232
00237 virtual const FiniteDifferenceFunctionPointer GetDifferenceFunction(
00238 const IdCellType& functionIndex ) const
00239 {
00240 if( functionIndex < m_FunctionCount )
00241 {
00242 return ( this->m_DifferenceFunctions[functionIndex] );
00243 }
00244 else
00245 {
00246 return 0;
00247 }
00248 }
00250
00255 virtual void SetDifferenceFunction( const IdCellType& functionIndex,
00256 FiniteDifferenceFunctionPointer function)
00257 {
00258 if( functionIndex < m_FunctionCount )
00259 {
00260 this->m_DifferenceFunctions[functionIndex] = function;
00261 }
00262 }
00264
00266 itkSetMacro(NumberOfIterations, unsigned int);
00267 itkGetConstReferenceMacro(NumberOfIterations, unsigned int);
00269
00272 itkSetMacro(UseImageSpacing,bool);
00273 itkBooleanMacro(UseImageSpacing);
00274 itkGetConstReferenceMacro(UseImageSpacing, bool);
00276
00279 itkSetMacro(MaximumRMSError, double);
00280 itkGetConstReferenceMacro(MaximumRMSError, double);
00282
00285 itkSetMacro(RMSChange, double);
00286 itkGetConstReferenceMacro(RMSChange, double);
00288
00290 itkSetMacro( InitializedState, bool );
00291 itkGetConstReferenceMacro( InitializedState, bool );
00292 itkBooleanMacro( InitializedState );
00294
00297 itkSetMacro( ManualReinitialization, bool );
00298 itkGetConstReferenceMacro( ManualReinitialization, bool );
00299 itkBooleanMacro( ManualReinitialization );
00301
00303 itkSetMacro( ElapsedIterations, unsigned int );
00304
00306 itkGetConstReferenceMacro( ElapsedIterations, unsigned int );
00307
00308 void SetLevelSet( const IdCellType & i, const InputImageType *levelSet )
00309 {
00310 m_LevelSet[i] = InputImageType::New();
00311 m_LevelSet[i]->SetRequestedRegion( levelSet->GetRequestedRegion() );
00312 m_LevelSet[i]->SetBufferedRegion( levelSet->GetBufferedRegion() );
00313 m_LevelSet[i]->SetLargestPossibleRegion( levelSet->GetLargestPossibleRegion() );
00314 m_LevelSet[i]->Allocate();
00315 m_LevelSet[i]->CopyInformation( levelSet );
00316
00317 ImageRegionConstIterator< InputImageType > in ( levelSet, levelSet->GetBufferedRegion());
00318 ImageRegionIterator< InputImageType > cp ( m_LevelSet[i], levelSet->GetBufferedRegion() );
00319
00320 in.GoToBegin();
00321 cp.GoToBegin();
00322
00323 while( !in.IsAtEnd() )
00324 {
00325 cp.Set( in.Get() );
00326 ++in;
00327 ++cp;
00328 }
00329 }
00330
00331 InputImagePointer GetLevelSet( const IdCellType& i )
00332 {
00333 if( i >= m_FunctionCount )
00334 {
00335 itkExceptionMacro("Request for level set #" << i
00336 << " but there are only " << m_FunctionCount );
00337 }
00338 else
00339 {
00340 return m_LevelSet[i];
00341 }
00342 }
00343
00344 void SetLookup ( VectorIdCellType lookup )
00345 {
00346 this->m_Lookup = lookup;
00347 }
00348
00349 void SetKdTree( KdTreeType * kdtree )
00350 {
00351 this->m_KdTree = kdtree;
00352 }
00353
00354 void SetFunctionCount( const IdCellType& n )
00355 {
00356 m_FunctionCount = n;
00357
00358 m_DifferenceFunctions.resize( m_FunctionCount, 0 );
00359
00360 RadiusType radius;
00361 radius.Fill( 1 );
00362
00363 for( unsigned int i = 0; i < this->m_FunctionCount; i++ )
00364 {
00365 this->m_DifferenceFunctions[i] = FiniteDifferenceFunctionType::New();
00366 this->m_DifferenceFunctions[i]->Initialize(radius);
00367 }
00368
00369
00370 m_LevelSet.resize( m_FunctionCount, 0 );
00371
00372
00373 this->m_Lookup.resize( m_FunctionCount );
00374
00375 IdCellType k = 1;
00376
00377 typedef typename std::vector< IdCellType >::iterator VectorIteratorType;
00378
00379 VectorIteratorType it = this->m_Lookup.begin();
00380
00381 while( it != this->m_Lookup.end() )
00382 {
00383 *it = k;
00384 ++it;
00385 ++k;
00386 }
00387 }
00388
00389 protected:
00390 MultiphaseFiniteDifferenceImageFilter()
00391 {
00392 this->m_KdTree = 0;
00393 this->m_ElapsedIterations = 0;
00394 this->m_MaximumRMSError = vnl_math::eps;
00395 this->m_RMSChange = NumericTraits<double>::max();
00396 this->m_UseImageSpacing = true;
00397 this->m_ManualReinitialization = false;
00398 this->m_InitializedState = false;
00399 this->m_NumberOfIterations = NumericTraits<unsigned int>::max();
00400 this->m_FunctionCount = 0;
00401 this->InPlaceOff();
00402 }
00403
00404 ~MultiphaseFiniteDifferenceImageFilter(){}
00405
00406 IdCellType m_FunctionCount;
00407 std::vector< InputImagePointer > m_LevelSet;
00408 VectorIdCellType m_Lookup;
00409 KdTreePointer m_KdTree;
00410
00411 unsigned int m_ElapsedIterations;
00412 double m_MaximumRMSError;
00413 double m_RMSChange;
00414 unsigned int m_NumberOfIterations;
00415
00417 std::vector< FiniteDifferenceFunctionPointer > m_DifferenceFunctions;
00418
00421 bool m_UseImageSpacing;
00422
00423 void PrintSelf(std::ostream& os, Indent indent) const;
00424
00426 virtual void AllocateUpdateBuffer() = 0;
00427
00431 virtual void ApplyUpdate(TimeStepType dt) = 0;
00432
00438 virtual TimeStepType CalculateChange() = 0;
00439
00443 virtual void CopyInputToOutput() = 0;
00444
00448 virtual void GenerateData();
00449
00461 virtual void GenerateInputRequestedRegion();
00462
00465 virtual bool Halt();
00466
00476 virtual bool ThreadedHalt(void *itkNotUsed(threadInfo))
00477 {
00478 return this->Halt();
00479 }
00480
00486 virtual void Initialize() { };
00487
00494 virtual void InitializeIteration()
00495 {
00496 for( IdCellType i = 0; i < this->m_FunctionCount; i++ )
00497 {
00498 this->m_DifferenceFunctions[i]->InitializeIteration();
00499 }
00500 }
00502
00516 inline TimeStepType ResolveTimeStep(const TimeStepVectorType& timeStepList,
00517 const std::vector< bool >& valid );
00518
00521 virtual void PostProcessOutput() {}
00522
00523
00524 private:
00525 MultiphaseFiniteDifferenceImageFilter(const Self&);
00526
00527 void operator=(const Self&);
00528
00531 bool m_ManualReinitialization;
00532
00534 bool m_InitializedState;
00535 };
00536
00537 }
00538
00539 #ifndef ITK_MANUAL_INSTANTIATION
00540 #include "itkMultiphaseFiniteDifferenceImageFilter.txx"
00541 #endif
00542
00543 #endif
00544