00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkSparseFieldLevelSetImageFilter_h_
00018 #define __itkSparseFieldLevelSetImageFilter_h_
00019
00020 #include "itkFiniteDifferenceImageFilter.h"
00021 #include "itkMultiThreader.h"
00022 #include "itkSparseFieldLayer.h"
00023 #include "itkObjectStore.h"
00024 #include <vector>
00025 #include "itkNeighborhoodIterator.h"
00026
00027 namespace itk {
00028
00033 template <class TValueType>
00034 class SparseFieldLevelSetNode
00035 {
00036 public:
00037 TValueType m_Value;
00038 SparseFieldLevelSetNode *Next;
00039 SparseFieldLevelSetNode *Previous;
00040 };
00041
00068 template <class TNeighborhoodType>
00069 class SparseFieldCityBlockNeighborList
00070 {
00071 public:
00072 typedef TNeighborhoodType NeighborhoodType;
00073 typedef typename NeighborhoodType::OffsetType OffsetType;
00074 typedef typename NeighborhoodType::RadiusType RadiusType;
00075 itkStaticConstMacro(Dimension, unsigned int,
00076 NeighborhoodType::Dimension );
00078
00079 const RadiusType &GetRadius() const
00080 { return m_Radius; }
00081
00082 const unsigned int &GetArrayIndex(unsigned int i) const
00083 { return m_ArrayIndex[i]; }
00084
00085 const OffsetType &GetNeighborhoodOffset(unsigned int i) const
00086 { return m_NeighborhoodOffset[i]; }
00087
00088 const unsigned int &GetSize() const
00089 { return m_Size; }
00090
00091 int GetStride(unsigned int i)
00092 { return m_StrideTable[i]; }
00093
00094 SparseFieldCityBlockNeighborList();
00095 ~SparseFieldCityBlockNeighborList() {}
00096
00097 void Print(std::ostream &os) const;
00098
00099 private:
00100 unsigned int m_Size;
00101 RadiusType m_Radius;
00102 std::vector<unsigned int> m_ArrayIndex;
00103 std::vector<OffsetType> m_NeighborhoodOffset;
00104
00107 unsigned m_StrideTable[Dimension];
00108 };
00109
00110
00226 template <class TInputImage, class TOutputImage>
00227 class ITK_EXPORT SparseFieldLevelSetImageFilter :
00228 public FiniteDifferenceImageFilter<TInputImage, TOutputImage>
00229 {
00230 public:
00231
00233 typedef SparseFieldLevelSetImageFilter Self;
00234 typedef FiniteDifferenceImageFilter<TInputImage, TOutputImage> Superclass;
00235 typedef SmartPointer<Self> Pointer;
00236 typedef SmartPointer<const Self> ConstPointer;
00237
00239 typedef typename Superclass::TimeStepType TimeStepType;
00240 typedef typename Superclass::RadiusType RadiusType;
00241 typedef typename Superclass::NeighborhoodScalesType NeighborhoodScalesType;
00242
00244 itkNewMacro(Self);
00245
00247 itkTypeMacro(SparseFieldLevelSetImageFilter, FiniteDifferenceImageFilter);
00248
00250 typedef TInputImage InputImageType;
00251 typedef TOutputImage OutputImageType;
00252 typedef typename OutputImageType::IndexType IndexType;
00253 itkStaticConstMacro(ImageDimension, unsigned int,
00254 TOutputImage::ImageDimension);
00255
00258 typedef typename OutputImageType::ValueType ValueType;
00259
00261 typedef SparseFieldLevelSetNode<IndexType> LayerNodeType;
00262
00264 typedef SparseFieldLayer<LayerNodeType> LayerType;
00265 typedef typename LayerType::Pointer LayerPointerType;
00266
00268 typedef std::vector<LayerPointerType> LayerListType;
00269
00271 typedef signed char StatusType;
00272
00275 typedef Image<StatusType, itkGetStaticConstMacro(ImageDimension)>
00276 StatusImageType;
00277
00280 typedef ObjectStore<LayerNodeType> LayerNodeStorageType;
00281
00283 typedef std::vector<ValueType> UpdateBufferType;
00284
00288 itkSetMacro(NumberOfLayers, unsigned int);
00289 itkGetMacro(NumberOfLayers, unsigned int);
00291
00293 itkSetMacro(IsoSurfaceValue, ValueType);
00294 itkGetMacro(IsoSurfaceValue, ValueType);
00296
00300
00301
00306 itkSetMacro(InterpolateSurfaceLocation, bool);
00307 itkGetMacro(InterpolateSurfaceLocation, bool);
00309
00311 void InterpolateSurfaceLocationOn()
00312 { this->SetInterpolateSurfaceLocation(true); }
00313 void InterpolateSurfaceLocationOff()
00314 { this->SetInterpolateSurfaceLocation(false); }
00316
00317 #ifdef ITK_USE_CONCEPT_CHECKING
00318
00319 itkConceptMacro(OutputEqualityComparableCheck,
00320 (Concept::EqualityComparable<typename TOutputImage::PixelType>));
00321 itkConceptMacro(DoubleConvertibleToOutputCheck,
00322 (Concept::Convertible<double, typename TOutputImage::PixelType>));
00323 itkConceptMacro(OutputOStreamWritableCheck,
00324 (Concept::OStreamWritable<typename TOutputImage::PixelType>));
00325
00327 #endif
00328
00329 protected:
00330 SparseFieldLevelSetImageFilter();
00331 ~SparseFieldLevelSetImageFilter();
00332 virtual void PrintSelf(std::ostream& os, Indent indent) const;
00333
00338 inline virtual ValueType CalculateUpdateValue(
00339 const IndexType &itkNotUsed(idx),
00340 const TimeStepType &dt,
00341 const ValueType &value,
00342 const ValueType &change)
00343 { return (value + dt * change); }
00344
00348 virtual void PostProcessOutput();
00349
00354 virtual void InitializeBackgroundPixels();
00355
00357 void Initialize();
00358
00363 void CopyInputToOutput();
00364
00366 void AllocateUpdateBuffer();
00367
00370 void ApplyUpdate(TimeStepType dt);
00371
00374 TimeStepType CalculateChange();
00375
00379 void ConstructLayer(StatusType from, StatusType to);
00380
00385 void ConstructActiveLayer();
00386
00388 void InitializeActiveLayerValues();
00389
00397 void PropagateLayerValues(StatusType from, StatusType to,
00398 StatusType promote, int InOrOut);
00399
00404 void PropagateAllLayerValues();
00405
00409 void UpdateActiveLayerValues(TimeStepType dt, LayerType *StatusUpList,
00410 LayerType *StatusDownList);
00411
00413 void ProcessStatusList(LayerType *InputList, LayerType *OutputList,
00414 StatusType ChangeToStatus, StatusType SearchForStatus);
00415
00417 void ProcessOutsideList(LayerType *OutsideList, StatusType ChangeToStatus);
00418
00419 itkGetConstMacro(ValueZero, ValueType);
00420 itkGetConstMacro(ValueOne, ValueType);
00421
00423 SparseFieldCityBlockNeighborList<NeighborhoodIterator<OutputImageType> >
00424 m_NeighborList;
00425
00428 double m_ConstantGradientValue;
00429
00431 static ValueType m_ValueOne;
00432
00434 static ValueType m_ValueZero;
00435
00438 static StatusType m_StatusChanging;
00439
00442 static StatusType m_StatusActiveChangingUp;
00443
00446 static StatusType m_StatusActiveChangingDown;
00447
00450 static StatusType m_StatusBoundaryPixel;
00451
00454 static StatusType m_StatusNull;
00455
00459 typename OutputImageType::Pointer m_ShiftedImage;
00460
00465 LayerListType m_Layers;
00466
00470 unsigned int m_NumberOfLayers;
00471
00473 typename StatusImageType::Pointer m_StatusImage;
00474
00476 typename LayerNodeStorageType::Pointer m_LayerNodeStore;
00477
00479 ValueType m_IsoSurfaceValue;
00480
00483 UpdateBufferType m_UpdateBuffer;
00484
00488
00489
00494 bool m_InterpolateSurfaceLocation;
00495
00496 private:
00497 SparseFieldLevelSetImageFilter(const Self&);
00498 void operator=(const Self&);
00499
00502 bool m_BoundsCheckingActive;
00503
00504 };
00505
00506
00507 }
00508
00509 #ifndef ITK_MANUAL_INSTANTIATION
00510 #include "itkSparseFieldLevelSetImageFilter.txx"
00511 #endif
00512
00513 #endif
00514