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 );
00077
00078 const RadiusType &GetRadius() const
00079 { return m_Radius; }
00080
00081 const unsigned int &GetArrayIndex(unsigned int i) const
00082 { return m_ArrayIndex[i]; }
00083
00084 const OffsetType &GetNeighborhoodOffset(unsigned int i) const
00085 { return m_NeighborhoodOffset[i]; }
00086
00087 const unsigned int &GetSize() const
00088 { return m_Size; }
00089
00090 int GetStride(unsigned int i)
00091 { return m_StrideTable[i]; }
00092
00093 SparseFieldCityBlockNeighborList();
00094 ~SparseFieldCityBlockNeighborList() {}
00095
00096 void Print(std::ostream &os) const;
00097
00098 private:
00099 unsigned int m_Size;
00100 RadiusType m_Radius;
00101 std::vector<unsigned int> m_ArrayIndex;
00102 std::vector<OffsetType> m_NeighborhoodOffset;
00103
00106 unsigned m_StrideTable[Dimension];
00107 };
00108
00109
00225 template <class TInputImage, class TOutputImage>
00226 class ITK_EXPORT SparseFieldLevelSetImageFilter :
00227 public FiniteDifferenceImageFilter<TInputImage, TOutputImage>
00228 {
00229 public:
00231 typedef SparseFieldLevelSetImageFilter Self;
00232 typedef FiniteDifferenceImageFilter<TInputImage, TOutputImage> Superclass;
00233 typedef SmartPointer<Self> Pointer;
00234 typedef SmartPointer<const Self> ConstPointer;
00235
00237 typedef typename Superclass::TimeStepType TimeStepType;
00238
00240 itkNewMacro(Self);
00241
00243 itkTypeMacro(SparseFieldLevelSetImageFilter, FiniteDifferenceImageFilter);
00244
00246 typedef TInputImage InputImageType;
00247 typedef TOutputImage OutputImageType;
00248 typedef typename OutputImageType::IndexType IndexType;
00249 itkStaticConstMacro(ImageDimension, unsigned int,
00250 TOutputImage::ImageDimension);
00251
00254 typedef typename OutputImageType::ValueType ValueType;
00255
00257 typedef SparseFieldLevelSetNode<IndexType> LayerNodeType;
00258
00260 typedef SparseFieldLayer<LayerNodeType> LayerType;
00261 typedef typename LayerType::Pointer LayerPointerType;
00262
00264 typedef std::vector<LayerPointerType> LayerListType;
00265
00267 typedef char StatusType;
00268
00271 typedef Image<StatusType, itkGetStaticConstMacro(ImageDimension)>
00272 StatusImageType;
00273
00276 typedef ObjectStore<LayerNodeType> LayerNodeStorageType;
00277
00279 typedef std::vector<ValueType> UpdateBufferType;
00280
00284 itkSetMacro(NumberOfLayers, unsigned int);
00285 itkGetMacro(NumberOfLayers, unsigned int);
00286
00288 itkSetMacro(IsoSurfaceValue, ValueType);
00289 itkGetMacro(IsoSurfaceValue, ValueType);
00290
00294 itkGetMacro(RMSChange, ValueType);
00295
00300 itkSetMacro(InterpolateSurfaceLocation, bool);
00301 itkGetMacro(InterpolateSurfaceLocation, bool);
00302
00304 void InterpolateSurfaceLocationOn()
00305 { this->SetInterpolateSurfaceLocation(true); }
00306 void InterpolateSurfaceLocationOff()
00307 { this->SetInterpolateSurfaceLocation(false); }
00308
00309 protected:
00310 SparseFieldLevelSetImageFilter();
00311 ~SparseFieldLevelSetImageFilter();
00312 virtual void PrintSelf(std::ostream& os, Indent indent) const;
00313
00318 inline virtual ValueType CalculateUpdateValue(
00319 const IndexType &itkNotUsed(idx),
00320 const TimeStepType &dt,
00321 const ValueType &value,
00322 const ValueType &change)
00323 { return (value + dt * change); }
00324
00328 virtual void PostProcessOutput();
00329
00334 virtual void InitializeBackgroundPixels();
00335
00337 void Initialize();
00338
00343 void CopyInputToOutput();
00344
00346 void AllocateUpdateBuffer();
00347
00350 void ApplyUpdate(TimeStepType dt);
00351
00354 TimeStepType CalculateChange();
00355
00359 void ConstructLayer(StatusType from, StatusType to);
00360
00365 void ConstructActiveLayer();
00366
00368 void InitializeActiveLayerValues();
00369
00377 void PropagateLayerValues(StatusType from, StatusType to,
00378 StatusType promote, int InOrOut);
00379
00384 void PropagateAllLayerValues();
00385
00389 void UpdateActiveLayerValues(TimeStepType dt, LayerType *StatusUpList,
00390 LayerType *StatusDownList);
00392 void ProcessStatusList(LayerType *InputList, LayerType *OutputList,
00393 StatusType ChangeToStatus, StatusType SearchForStatus);
00394
00396 void ProcessOutsideList(LayerType *OutsideList, StatusType ChangeToStatus);
00397
00399 SparseFieldCityBlockNeighborList<NeighborhoodIterator<OutputImageType> >
00400 m_NeighborList;
00401
00404 static double m_ConstantGradientValue;
00405
00407 static ValueType m_ValueOne;
00408
00410 static ValueType m_ValueZero;
00411
00414 static StatusType m_StatusChanging;
00415
00418 static StatusType m_StatusActiveChangingUp;
00419
00422 static StatusType m_StatusActiveChangingDown;
00423
00426 static StatusType m_StatusNull;
00427
00431 typename OutputImageType::Pointer m_ShiftedImage;
00432
00437 LayerListType m_Layers;
00438
00442 unsigned int m_NumberOfLayers;
00443
00445 typename StatusImageType::Pointer m_StatusImage;
00446
00448 typename LayerNodeStorageType::Pointer m_LayerNodeStore;
00449
00451 ValueType m_IsoSurfaceValue;
00452
00455 UpdateBufferType m_UpdateBuffer;
00456
00460 ValueType m_RMSChange;
00461
00466 bool m_InterpolateSurfaceLocation;
00467
00468 private:
00469 SparseFieldLevelSetImageFilter(const Self&);
00470 void operator=(const Self&);
00471 };
00472
00473
00474 }
00475
00476 #ifndef ITK_MANUAL_INSTANTIATION
00477 #include "itkSparseFieldLevelSetImageFilter.txx"
00478 #endif
00479
00480 #endif