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
00242 itkNewMacro(Self);
00243
00245 itkTypeMacro(SparseFieldLevelSetImageFilter, FiniteDifferenceImageFilter);
00246
00248 typedef TInputImage InputImageType;
00249 typedef TOutputImage OutputImageType;
00250 typedef typename OutputImageType::IndexType IndexType;
00251 itkStaticConstMacro(ImageDimension, unsigned int,
00252 TOutputImage::ImageDimension);
00253
00256 typedef typename OutputImageType::ValueType ValueType;
00257
00259 typedef SparseFieldLevelSetNode<IndexType> LayerNodeType;
00260
00262 typedef SparseFieldLayer<LayerNodeType> LayerType;
00263 typedef typename LayerType::Pointer LayerPointerType;
00264
00266 typedef std::vector<LayerPointerType> LayerListType;
00267
00269 typedef signed char StatusType;
00270
00273 typedef Image<StatusType, itkGetStaticConstMacro(ImageDimension)>
00274 StatusImageType;
00275
00278 typedef ObjectStore<LayerNodeType> LayerNodeStorageType;
00279
00281 typedef std::vector<ValueType> UpdateBufferType;
00282
00286 itkSetMacro(NumberOfLayers, unsigned int);
00287 itkGetMacro(NumberOfLayers, unsigned int);
00289
00291 itkSetMacro(IsoSurfaceValue, ValueType);
00292 itkGetMacro(IsoSurfaceValue, ValueType);
00294
00298
00299
00304 itkSetMacro(InterpolateSurfaceLocation, bool);
00305 itkGetMacro(InterpolateSurfaceLocation, bool);
00307
00309 void InterpolateSurfaceLocationOn()
00310 { this->SetInterpolateSurfaceLocation(true); }
00311 void InterpolateSurfaceLocationOff()
00312 { this->SetInterpolateSurfaceLocation(false); }
00314
00315 #ifdef ITK_USE_CONCEPT_CHECKING
00316
00317 itkConceptMacro(OutputEqualityComparableCheck,
00318 (Concept::EqualityComparable<typename TOutputImage::PixelType>));
00319 itkConceptMacro(DoubleConvertibleToOutputCheck,
00320 (Concept::Convertible<double, typename TOutputImage::PixelType>));
00321 itkConceptMacro(OutputOStreamWritableCheck,
00322 (Concept::OStreamWritable<typename TOutputImage::PixelType>));
00323
00325 #endif
00326
00327 protected:
00328 SparseFieldLevelSetImageFilter();
00329 ~SparseFieldLevelSetImageFilter();
00330 virtual void PrintSelf(std::ostream& os, Indent indent) const;
00331
00336 inline virtual ValueType CalculateUpdateValue(
00337 const IndexType &itkNotUsed(idx),
00338 const TimeStepType &dt,
00339 const ValueType &value,
00340 const ValueType &change)
00341 { return (value + dt * change); }
00342
00346 virtual void PostProcessOutput();
00347
00352 virtual void InitializeBackgroundPixels();
00353
00355 void Initialize();
00356
00361 void CopyInputToOutput();
00362
00364 void AllocateUpdateBuffer();
00365
00368 void ApplyUpdate(TimeStepType dt);
00369
00372 TimeStepType CalculateChange();
00373
00377 void ConstructLayer(StatusType from, StatusType to);
00378
00383 void ConstructActiveLayer();
00384
00386 void InitializeActiveLayerValues();
00387
00395 void PropagateLayerValues(StatusType from, StatusType to,
00396 StatusType promote, int InOrOut);
00397
00402 void PropagateAllLayerValues();
00403
00407 void UpdateActiveLayerValues(TimeStepType dt, LayerType *StatusUpList,
00408 LayerType *StatusDownList);
00409
00411 void ProcessStatusList(LayerType *InputList, LayerType *OutputList,
00412 StatusType ChangeToStatus, StatusType SearchForStatus);
00413
00415 void ProcessOutsideList(LayerType *OutsideList, StatusType ChangeToStatus);
00416
00417 itkGetConstMacro(ValueZero, ValueType);
00418 itkGetConstMacro(ValueOne, ValueType);
00419
00421 SparseFieldCityBlockNeighborList<NeighborhoodIterator<OutputImageType> >
00422 m_NeighborList;
00423
00426 static double m_ConstantGradientValue;
00427
00429 static ValueType m_ValueOne;
00430
00432 static ValueType m_ValueZero;
00433
00436 static StatusType m_StatusChanging;
00437
00440 static StatusType m_StatusActiveChangingUp;
00441
00444 static StatusType m_StatusActiveChangingDown;
00445
00448 static StatusType m_StatusBoundaryPixel;
00449
00452 static StatusType m_StatusNull;
00453
00457 typename OutputImageType::Pointer m_ShiftedImage;
00458
00463 LayerListType m_Layers;
00464
00468 unsigned int m_NumberOfLayers;
00469
00471 typename StatusImageType::Pointer m_StatusImage;
00472
00474 typename LayerNodeStorageType::Pointer m_LayerNodeStore;
00475
00477 ValueType m_IsoSurfaceValue;
00478
00481 UpdateBufferType m_UpdateBuffer;
00482
00486
00487
00492 bool m_InterpolateSurfaceLocation;
00493
00494 private:
00495 SparseFieldLevelSetImageFilter(const Self&);
00496 void operator=(const Self&);
00497
00500 bool m_BoundsCheckingActive;
00501
00502 };
00503
00504
00505 }
00506
00507 #ifndef ITK_MANUAL_INSTANTIATION
00508 #include "itkSparseFieldLevelSetImageFilter.txx"
00509 #endif
00510
00511 #endif
00512