00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __itkMultiphaseSparseFiniteDifferenceImageFilter_h
00019 #define __itkMultiphaseSparseFiniteDifferenceImageFilter_h
00020
00021 #include "itkMultiphaseFiniteDifferenceImageFilter.h"
00022 #include "itkMultiThreader.h"
00023 #include "itkSparseFieldLayer.h"
00024 #include "itkObjectStore.h"
00025 #include "itkNeighborhoodIterator.h"
00026 #include "itkZeroCrossingImageFilter.h"
00027 #include "itkImageRegionIterator.h"
00028 #include "itkImageRegionConstIterator.h"
00029 #include "itkShiftScaleImageFilter.h"
00030 #include "itkNeighborhoodAlgorithm.h"
00031 #include "itkSparseFieldLevelSetImageFilter.h"
00032
00033 #include <vector>
00034
00035 namespace itk {
00179 template < class TInputImage, class TOutputImage, class TFunction,
00180 typename TIdCell = unsigned int >
00181 class ITK_EXPORT MultiphaseSparseFiniteDifferenceImageFilter :
00182 public MultiphaseFiniteDifferenceImageFilter< TInputImage, TOutputImage, TFunction, TIdCell >
00183 {
00184 public:
00185
00187 typedef MultiphaseSparseFiniteDifferenceImageFilter Self;
00188 typedef MultiphaseFiniteDifferenceImageFilter<
00189 TInputImage, TOutputImage, TFunction, TIdCell > Superclass;
00190 typedef SmartPointer<Self> Pointer;
00191 typedef SmartPointer<const Self> ConstPointer;
00192
00194 itkNewMacro(Self);
00195
00197 itkTypeMacro( MultiphaseSparseFiniteDifferenceImageFilter, MultiphaseFiniteDifferenceImageFilter );
00198
00200 typedef typename Superclass::TimeStepType TimeStepType;
00201
00203 typedef typename Superclass::InputImageType InputImageType;
00204 typedef typename Superclass::InputSizeType InputSizeType;
00205 typedef typename Superclass::InputImagePointer InputImagePointer;
00206 typedef typename Superclass::InputRegionType InputRegionType;
00207 typedef typename Superclass::InputSpacingType InputSpacingType;
00208 typedef typename Superclass::InputPointType InputPointType;
00209
00210 typedef typename Superclass::OutputImageType OutputImageType;
00211 typedef typename Superclass::OutputImagePointer OutputImagePointer;
00212 typedef typename Superclass::OutputRegionType OutputRegionType;
00213 typedef typename Superclass::OutputSizeType OutputSizeType;
00214 typedef typename Superclass::OutputSizeValueType SizeValueType;
00215 typedef typename OutputImageType::ValueType ValueType;
00216 typedef typename Superclass::OutputIndexType OutputIndexType;
00217 typedef typename Superclass::OutputIndexValueType OutputIndexValueType;
00218 typedef typename Superclass::OutputPixelType OutputPixelType;
00219
00220 typedef typename Superclass::IdCellType IdCellType;
00221
00222
00223 itkStaticConstMacro( ImageDimension, unsigned int, TOutputImage::ImageDimension );
00224
00225 typedef typename Superclass::FiniteDifferenceFunctionType
00226 FiniteDifferenceFunctionType;
00227 typedef typename Superclass::FiniteDifferenceFunctionPointer
00228 FiniteDifferenceFunctionPointer;
00229 typedef typename FiniteDifferenceFunctionType::FloatOffsetType
00230 FiniteDifferenceFunctionFloatOffsetType;
00231
00233 typedef SparseFieldLevelSetNode< OutputIndexType > LayerNodeType;
00234
00236 typedef SparseFieldLayer< LayerNodeType > LayerType;
00237 typedef typename LayerType::Pointer LayerPointerType;
00238 typedef typename LayerType::Iterator LayerIterator;
00239 typedef typename LayerType::ConstIterator LayerConstIterator;
00240
00242 typedef std::vector< LayerPointerType > LayerListType;
00243 typedef typename LayerListType::iterator LayerListIterator;
00244 typedef typename LayerListType::const_iterator LayerListConstIterator;
00245
00246
00248 typedef signed char StatusType;
00249
00252 typedef Image< StatusType, itkGetStaticConstMacro(ImageDimension) >
00253 StatusImageType;
00254 typedef typename StatusImageType::Pointer StatusImagePointer;
00255
00256 typedef ZeroCrossingImageFilter<OutputImageType, OutputImageType>
00257 ZeroCrossingFilterType;
00258 typedef typename ZeroCrossingFilterType::Pointer
00259 ZeroCrossingFilterPointer;
00260
00263 typedef ObjectStore< LayerNodeType > LayerNodeStorageType;
00264 typedef typename LayerNodeStorageType::Pointer LayerNodeStoragePointer;
00265
00267 typedef std::vector< ValueType > UpdateBufferType;
00268 typedef typename UpdateBufferType::const_iterator UpdateBufferConstIterator;
00269
00273 itkSetMacro( NumberOfLayers, unsigned int );
00274 itkGetConstMacro( NumberOfLayers, unsigned int );
00276
00278 itkSetMacro( IsoSurfaceValue, ValueType );
00279 itkGetConstMacro( IsoSurfaceValue, ValueType );
00281
00286 itkSetMacro(InterpolateSurfaceLocation, bool);
00287 itkGetConstMacro(InterpolateSurfaceLocation, bool);
00289
00291 void InterpolateSurfaceLocationOn()
00292 { this->SetInterpolateSurfaceLocation( true ); }
00293 void InterpolateSurfaceLocationOff()
00294 { this->SetInterpolateSurfaceLocation( false ); }
00296
00297 void SetFunctionCount( const IdCellType& n )
00298 {
00299 this->Superclass::SetFunctionCount( n );
00300
00301 m_SparseData.resize( this->m_FunctionCount, 0 );
00302
00303 for( IdCellType i = 0; i < this->m_FunctionCount; i++ )
00304 {
00305 m_SparseData[i] = new SparseDataStruct( i );
00306 }
00307 }
00308
00309
00310 #ifdef ITK_USE_CONCEPT_CHECKING
00311
00312 itkConceptMacro(OutputEqualityComparableCheck,
00313 (Concept::EqualityComparable<typename TOutputImage::PixelType>));
00314 itkConceptMacro(DoubleConvertibleToOutputCheck,
00315 (Concept::Convertible<double, typename TOutputImage::PixelType>));
00316 itkConceptMacro(OutputOStreamWritableCheck,
00317 (Concept::OStreamWritable<typename TOutputImage::PixelType>));
00318
00320 #endif
00321
00322 protected:
00323 MultiphaseSparseFiniteDifferenceImageFilter();
00324 ~MultiphaseSparseFiniteDifferenceImageFilter()
00325 {
00326 while( !m_SparseData.empty() )
00327 {
00328 if( m_SparseData.back() )
00329 {
00330 delete m_SparseData.back();
00331 }
00332 m_SparseData.pop_back();
00333 }
00334 }
00335
00336 virtual void PrintSelf(std::ostream& os, Indent indent) const;
00337
00338
00339 struct SparseDataStruct
00340 {
00341 SparseDataStruct( const IdCellType& index )
00342 {
00343 m_LayerNodeStore = LayerNodeStorageType::New();
00344 m_LayerNodeStore->SetGrowthStrategyToExponential();
00345 m_Index = index;
00346 }
00347
00349 SparseFieldCityBlockNeighborList< NeighborhoodIterator<OutputImageType> >
00350 m_NeighborList;
00351
00356 LayerListType m_Layers;
00357
00359 StatusImagePointer m_StatusImage;
00360
00361 OutputImagePointer m_ShiftedImage;
00362
00364 LayerNodeStoragePointer m_LayerNodeStore;
00365
00368 UpdateBufferType m_UpdateBuffer;
00369
00370 IdCellType m_Index;
00371 };
00372
00377 inline virtual ValueType CalculateUpdateValue(
00378 const OutputIndexType &itkNotUsed(idx),
00379 const TimeStepType &dt,
00380 const ValueType &value,
00381 const ValueType &change)
00382 {
00383 return (value + dt * change);
00384 }
00385
00389 virtual void PostProcessOutput();
00390
00395 virtual void InitializeBackgroundPixels();
00396
00398 void Initialize();
00399
00404 void CopyInputToOutput();
00405
00407 void AllocateUpdateBuffer();
00408
00411 void ApplyUpdate(TimeStepType dt);
00412
00415 TimeStepType CalculateChange();
00416
00420 void ConstructLayer(SparseDataStruct *sparsePtr, StatusType from, StatusType
00421 to);
00422
00427 void ConstructActiveLayer();
00428
00430 void InitializeActiveLayerValues();
00431
00439 void PropagateLayerValues(SparseDataStruct *sparsePtr, StatusType from,
00440 StatusType to, StatusType promote, int InOrOut);
00441
00446 void PropagateAllLayerValues();
00447
00448 void PropagateFunctionLayerValues( unsigned int functionIndex );
00449
00453 void UpdateActiveLayerValues( TimeStepType dt, LayerType *StatusUpList,
00454 LayerType *StatusDownList );
00455
00457 void ProcessStatusList( LayerType *InputList, LayerType *OutputList,
00458 StatusType ChangeToStatus, StatusType SearchForStatus);
00459
00461 void ProcessOutsideList(LayerType *OutsideList, StatusType ChangeToStatus);
00462
00463 void InitializeIteration();
00464
00465 virtual void UpdatePixel(unsigned int itkNotUsed(functionIndex), unsigned int itkNotUsed(idx),
00466 NeighborhoodIterator<OutputImageType> & itkNotUsed(iterator), ValueType & itkNotUsed(newValue),
00467 bool & itkNotUsed(status) ){};
00468
00469 itkGetConstMacro( ValueZero, ValueType );
00470 itkGetConstMacro( ValueOne, ValueType );
00471
00474 static double m_ConstantGradientValue;
00475
00477 static const ValueType m_ValueOne;
00478
00480 static const ValueType m_ValueZero;
00481
00484 static const StatusType m_StatusChanging;
00485
00488 static const StatusType m_StatusActiveChangingUp;
00489
00492 static const StatusType m_StatusActiveChangingDown;
00493
00496 static const StatusType m_StatusBoundaryPixel;
00497
00500 static const StatusType m_StatusNull;
00501
00502 std::vector< SparseDataStruct* > m_SparseData;
00503
00507 unsigned int m_NumberOfLayers;
00508
00510 ValueType m_IsoSurfaceValue;
00511
00516 bool m_InterpolateSurfaceLocation;
00517
00518 private:
00519 MultiphaseSparseFiniteDifferenceImageFilter(const Self&);
00520 void operator=(const Self&);
00521
00522 unsigned int m_CurrentFunctionIndex;
00523
00526 bool m_BoundsCheckingActive;
00527 };
00528
00529
00530 }
00531
00532 #ifndef ITK_MANUAL_INSTANTIATION
00533 #include "itkMultiphaseSparseFiniteDifferenceImageFilter.txx"
00534 #endif
00535
00536 #endif
00537