ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkSparseFieldLevelSetImageFilter.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkSparseFieldLevelSetImageFilter_h
00019 #define __itkSparseFieldLevelSetImageFilter_h
00020 
00021 #include "itkFiniteDifferenceImageFilter.h"
00022 #include "itkMultiThreader.h"
00023 #include "itkSparseFieldLayer.h"
00024 #include "itkObjectStore.h"
00025 #include <vector>
00026 #include "itkNeighborhoodIterator.h"
00027 
00028 namespace itk
00029 {
00035 template< class TValueType >
00036 class SparseFieldLevelSetNode
00037 {
00038 public:
00039   TValueType               m_Value;
00040   SparseFieldLevelSetNode *Next;
00041   SparseFieldLevelSetNode *Previous;
00042 };
00043 
00072 template< class TNeighborhoodType >
00073 class SparseFieldCityBlockNeighborList
00074 {
00075 public:
00076   typedef TNeighborhoodType                     NeighborhoodType;
00077   typedef typename NeighborhoodType::OffsetType OffsetType;
00078   typedef typename NeighborhoodType::RadiusType RadiusType;
00079   itkStaticConstMacro(Dimension, unsigned int,
00080                       NeighborhoodType::Dimension);
00082 
00083   const RadiusType & GetRadius() const
00084   { return m_Radius; }
00085 
00086   const unsigned int & GetArrayIndex(unsigned int i) const
00087   { return m_ArrayIndex[i]; }
00088 
00089   const OffsetType & GetNeighborhoodOffset(unsigned int i) const
00090   { return m_NeighborhoodOffset[i]; }
00091 
00092   const unsigned int & GetSize() const
00093   { return m_Size; }
00094 
00095   int GetStride(unsigned int i)
00096   { return m_StrideTable[i]; }
00097 
00098   SparseFieldCityBlockNeighborList();
00099   ~SparseFieldCityBlockNeighborList() {}
00100 
00101   void Print(std::ostream & os) const;
00102 
00103 private:
00104   unsigned int                m_Size;
00105   RadiusType                  m_Radius;
00106   std::vector< unsigned int > m_ArrayIndex;
00107   std::vector< OffsetType >   m_NeighborhoodOffset;
00108 
00111   unsigned m_StrideTable[Dimension];
00112 };
00113 
00229 template< class TInputImage, class TOutputImage >
00230 class ITK_EXPORT SparseFieldLevelSetImageFilter:
00231   public FiniteDifferenceImageFilter< TInputImage, TOutputImage >
00232 {
00233 public:
00234 
00236   typedef SparseFieldLevelSetImageFilter                           Self;
00237   typedef FiniteDifferenceImageFilter< TInputImage, TOutputImage > Superclass;
00238   typedef SmartPointer< Self >                                     Pointer;
00239   typedef SmartPointer< const Self >                               ConstPointer;
00240 
00242   typedef typename Superclass::TimeStepType           TimeStepType;
00243   typedef typename Superclass::RadiusType             RadiusType;
00244   typedef typename Superclass::NeighborhoodScalesType NeighborhoodScalesType;
00245 
00247   itkNewMacro(Self);
00248 
00250   itkTypeMacro(SparseFieldLevelSetImageFilter, FiniteDifferenceImageFilter);
00251 
00253   typedef TInputImage                         InputImageType;
00254   typedef TOutputImage                        OutputImageType;
00255   typedef typename OutputImageType::IndexType IndexType;
00256   itkStaticConstMacro(ImageDimension, unsigned int,
00257                       TOutputImage::ImageDimension);
00258 
00261   typedef typename OutputImageType::ValueType ValueType;
00262 
00264   typedef SparseFieldLevelSetNode< IndexType > LayerNodeType;
00265 
00267   typedef SparseFieldLayer< LayerNodeType > LayerType;
00268   typedef typename LayerType::Pointer       LayerPointerType;
00269 
00271   typedef std::vector< LayerPointerType > LayerListType;
00272 
00274   typedef signed char StatusType;
00275 
00278   typedef Image< StatusType, itkGetStaticConstMacro(ImageDimension) >
00279   StatusImageType;
00280 
00283   typedef ObjectStore< LayerNodeType > LayerNodeStorageType;
00284 
00286   typedef std::vector< ValueType > UpdateBufferType;
00287 
00291   itkSetMacro(NumberOfLayers, unsigned int);
00292   itkGetConstMacro(NumberOfLayers, unsigned int);
00294 
00296   itkSetMacro(IsoSurfaceValue, ValueType);
00297   itkGetConstMacro(IsoSurfaceValue, ValueType);
00299 
00303   //  itkGetConstMacro(RMSChange, ValueType);
00304 
00310   itkSetMacro(InterpolateSurfaceLocation, bool);
00311   itkGetConstMacro(InterpolateSurfaceLocation, bool);
00313 
00315   void InterpolateSurfaceLocationOn()
00316   { this->SetInterpolateSurfaceLocation(true); }
00317   void InterpolateSurfaceLocationOff()
00318   { this->SetInterpolateSurfaceLocation(false); }
00320 
00321 #ifdef ITK_USE_CONCEPT_CHECKING
00322 
00323   itkConceptMacro( OutputEqualityComparableCheck,
00324                    ( Concept::EqualityComparable< typename TOutputImage::PixelType > ) );
00325   itkConceptMacro( DoubleConvertibleToOutputCheck,
00326                    ( Concept::Convertible< double, typename TOutputImage::PixelType > ) );
00327   itkConceptMacro( OutputOStreamWritableCheck,
00328                    ( Concept::OStreamWritable< typename TOutputImage::PixelType > ) );
00329 
00331 #endif
00332 protected:
00333   SparseFieldLevelSetImageFilter();
00334   ~SparseFieldLevelSetImageFilter();
00335   virtual void PrintSelf(std::ostream & os, Indent indent) const;
00337 
00342   inline virtual ValueType CalculateUpdateValue(
00343     const IndexType & itkNotUsed(idx),
00344     const TimeStepType & dt,
00345     const ValueType & value,
00346     const ValueType & change)
00347   { return ( value + dt * change ); }
00348 
00352   virtual void PostProcessOutput();
00353 
00358   virtual void InitializeBackgroundPixels();
00359 
00361   void Initialize();
00362 
00367   void CopyInputToOutput();
00368 
00370   void AllocateUpdateBuffer();
00371 
00374   void ApplyUpdate(const TimeStepType& dt);
00375 
00378   TimeStepType CalculateChange();
00379 
00383   void ConstructLayer(StatusType from, StatusType to);
00384 
00389   void ConstructActiveLayer();
00390 
00392   void InitializeActiveLayerValues();
00393 
00401   void PropagateLayerValues(StatusType from, StatusType to,
00402                             StatusType promote, int InOrOut);
00403 
00408   void PropagateAllLayerValues();
00409 
00413   void UpdateActiveLayerValues(TimeStepType dt, LayerType *StatusUpList,
00414                                LayerType *StatusDownList);
00415 
00417   void ProcessStatusList(LayerType *InputList, LayerType *OutputList,
00418                          StatusType ChangeToStatus, StatusType SearchForStatus);
00419 
00421   void ProcessOutsideList(LayerType *OutsideList, StatusType ChangeToStatus);
00422 
00423   itkGetConstMacro(ValueZero, ValueType);
00424   itkGetConstMacro(ValueOne, ValueType);
00425 
00427   SparseFieldCityBlockNeighborList< NeighborhoodIterator< OutputImageType > >
00428   m_NeighborList;
00429 
00432   double m_ConstantGradientValue;
00433 
00435   static ValueType m_ValueOne;
00436 
00438   static ValueType m_ValueZero;
00439 
00442   static StatusType m_StatusChanging;
00443 
00446   static StatusType m_StatusActiveChangingUp;
00447 
00450   static StatusType m_StatusActiveChangingDown;
00451 
00454   static StatusType m_StatusBoundaryPixel;
00455 
00458   static StatusType m_StatusNull;
00459 
00463   typename OutputImageType::Pointer m_ShiftedImage;
00464 
00469   LayerListType m_Layers;
00470 
00475   unsigned int m_NumberOfLayers;
00476 
00478   typename StatusImageType::Pointer m_StatusImage;
00479 
00481   typename LayerNodeStorageType::Pointer m_LayerNodeStore;
00482 
00484   ValueType m_IsoSurfaceValue;
00485 
00488   UpdateBufferType m_UpdateBuffer;
00489 
00493   //  ValueType m_RMSChange;
00494 
00499   bool m_InterpolateSurfaceLocation;
00500 private:
00501   SparseFieldLevelSetImageFilter(const Self &); //purposely not implemented
00502   void operator=(const Self &);                 //purposely not implemented
00504 
00507   bool m_BoundsCheckingActive;
00508 };
00509 } // end namespace itk
00510 
00511 #ifndef ITK_MANUAL_INSTANTIATION
00512 #include "itkSparseFieldLevelSetImageFilter.hxx"
00513 #endif
00514 
00515 #endif
00516