ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkSparseFieldFourthOrderLevelSetImageFilter.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 __itkSparseFieldFourthOrderLevelSetImageFilter_h
00019 #define __itkSparseFieldFourthOrderLevelSetImageFilter_h
00020 
00021 #include "itkNormalVectorDiffusionFunction.h"
00022 #include "itkImplicitManifoldNormalVectorFilter.h"
00023 #include "itkLevelSetFunctionWithRefitTerm.h"
00024 #include "itkSparseFieldLevelSetImageFilter.h"
00025 #include <math.h>
00026 
00027 namespace itk
00028 {
00037 template< class TImageType >
00038 class NormalBandNode
00039 {
00040 public:
00041 
00043   typedef TImageType LevelSetImageType;
00044 
00046   typedef typename LevelSetImageType::PixelType NodeValueType;
00047 
00049   typedef typename LevelSetImageType::IndexType IndexType;
00050 
00052   typedef Vector< NodeValueType,
00053                   ::itk::GetImageDimension< TImageType >::ImageDimension >
00054   NodeDataType;
00055 
00057   NodeDataType m_Data;
00058 
00060   NodeDataType m_InputData;
00061 
00063   NodeDataType m_Update;
00064 
00067   NodeDataType
00068     m_ManifoldNormal[::itk::GetImageDimension < TImageType > ::ImageDimension];
00069 
00071   NodeDataType m_Flux[::itk::GetImageDimension < TImageType > ::ImageDimension];
00072 
00075   NodeValueType m_Curvature;
00076 
00079   bool m_CurvatureFlag;
00080 
00082   IndexType m_Index;
00083 
00085   NormalBandNode *Next;
00086   NormalBandNode *Previous;
00087 };
00088 
00156 template< class TInputImage, class TOutputImage >
00157 class ITK_EXPORT SparseFieldFourthOrderLevelSetImageFilter:
00158   public SparseFieldLevelSetImageFilter< TInputImage, TOutputImage >
00159 {
00160 public:
00161 
00163   typedef SparseFieldFourthOrderLevelSetImageFilter                   Self;
00164   typedef SparseFieldLevelSetImageFilter< TInputImage, TOutputImage > Superclass;
00165   typedef SmartPointer< Self >                                        Pointer;
00166   typedef SmartPointer< const Self >                                  ConstPointer;
00167 
00169   itkTypeMacro(SparseFieldFourthOrderLevelSetImageFilter,
00170                SparseFieldLevelSetImageFilter);
00171 
00173   itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
00174 
00176   typedef typename Superclass::OutputImageType        OutputImageType;
00177   typedef typename Superclass::ValueType              ValueType;
00178   typedef typename Superclass::IndexType              IndexType;
00179   typedef typename Superclass::LayerType              LayerType;
00180   typedef typename Superclass::RadiusType             RadiusType;
00181   typedef typename Superclass::NeighborhoodScalesType NeighborhoodScalesType;
00182 
00185   typedef NormalBandNode< OutputImageType > NodeType;
00186 
00188   typedef SparseImage< NodeType,
00189                        itkGetStaticConstMacro(ImageDimension) > SparseImageType;
00190 
00192   typedef typename NodeType::NodeDataType NormalVectorType;
00193 
00195   typedef NeighborhoodIterator< SparseImageType > SparseImageIteratorType;
00196 
00198   typedef ImplicitManifoldNormalVectorFilter< OutputImageType, SparseImageType >
00199   NormalVectorFilterType;
00200 
00202   typedef NormalVectorDiffusionFunction< SparseImageType >
00203   NormalVectorFunctionType;
00204 
00206   //typedef typename NormalVectorFunctionType::RadiusType RadiusType;
00207 
00209   typedef LevelSetFunctionWithRefitTerm< OutputImageType,
00210                                          SparseImageType > LevelSetFunctionType;
00211 
00212   itkGetConstReferenceMacro(MaxRefitIteration, unsigned int);
00213   itkSetMacro(MaxRefitIteration, unsigned int);
00214   itkGetConstReferenceMacro(MaxNormalIteration, unsigned int);
00215   itkSetMacro(MaxNormalIteration, unsigned int);
00216   itkGetConstReferenceMacro(CurvatureBandWidth, ValueType);
00217   itkSetMacro(CurvatureBandWidth, ValueType);
00218   itkGetConstReferenceMacro(RMSChangeNormalProcessTrigger, ValueType);
00219   itkSetMacro(RMSChangeNormalProcessTrigger, ValueType);
00220   itkGetConstReferenceMacro(NormalProcessType, int);
00221   itkSetMacro(NormalProcessType, int);
00222   itkGetConstReferenceMacro(NormalProcessConductance, ValueType);
00223   itkSetMacro(NormalProcessConductance, ValueType);
00224   itkSetMacro(NormalProcessUnsharpFlag, bool);
00225   itkGetConstReferenceMacro(NormalProcessUnsharpFlag, bool);
00226   itkSetMacro(NormalProcessUnsharpWeight, ValueType);
00227   itkGetConstReferenceMacro(NormalProcessUnsharpWeight, ValueType);
00228 
00231   void SetLevelSetFunction(LevelSetFunctionType *lsf);
00232 
00236   unsigned int GetMinimumNumberOfLayers() const
00237   {
00238     return (int)vcl_ceil( m_CurvatureBandWidth
00239                           + itkGetStaticConstMacro(ImageDimension) );
00240   }
00241 
00244   virtual void SetNumberOfLayers(const unsigned int n)
00245   {
00246     unsigned int nm = vnl_math_max (this->GetMinimumNumberOfLayers (), n);
00247 
00248     if ( nm != this->GetNumberOfLayers() )
00249       {
00250       Superclass::SetNumberOfLayers (nm);
00251       this->Modified();
00252       }
00253   }
00254 
00257   virtual void InitializeIteration()
00258   {
00259     Superclass::InitializeIteration();
00260     ValueType rmschange = this->GetRMSChange();
00262 
00263     if ( ( this->GetElapsedIterations() == 0 )
00264          || ( m_RefitIteration == m_MaxRefitIteration )
00265          || ( rmschange <= m_RMSChangeNormalProcessTrigger )
00266          || ( this->ActiveLayerCheckBand() ) )
00267       {
00268       if ( ( this->GetElapsedIterations() != 0 )
00269            && ( rmschange <= m_RMSChangeNormalProcessTrigger )
00270            && ( m_RefitIteration <= 1 ) )
00271         {
00272         m_ConvergenceFlag = true;
00273         }
00274 
00275       m_RefitIteration = 0;
00276       ProcessNormals();
00277       }
00278 
00279     m_RefitIteration++;
00280   }
00281 
00282 #ifdef ITK_USE_CONCEPT_CHECKING
00283 
00284   itkConceptMacro( OutputHasNumericTraitsCheck,
00285                    ( Concept::HasNumericTraits< ValueType > ) );
00286 
00288 #endif
00289 protected:
00290   SparseFieldFourthOrderLevelSetImageFilter();
00291   ~SparseFieldFourthOrderLevelSetImageFilter() {}
00292   virtual void PrintSelf(std::ostream & os, Indent indent) const;
00294 
00297   ValueType ComputeCurvatureFromSparseImageNeighborhood
00298     (SparseImageIteratorType & neighborhood) const;
00299 
00303   void ComputeCurvatureTarget(const OutputImageType *distanceImage,
00304                               SparseImageType *sparseImage) const;
00305 
00307   void ProcessNormals();
00308 
00313   bool ActiveLayerCheckBand() const;
00314 
00315 private:
00318   unsigned int m_RefitIteration;
00319 
00323   unsigned int m_MaxRefitIteration;
00324 
00327   unsigned int m_MaxNormalIteration;
00328 
00332   ValueType m_RMSChangeNormalProcessTrigger;
00333 
00336   bool m_ConvergenceFlag;
00337 
00340   LevelSetFunctionType *m_LevelSetFunction;
00341 
00346   ValueType m_CurvatureBandWidth;
00347 
00350   int m_NormalProcessType;
00351 
00354   ValueType m_NormalProcessConductance;
00355 
00358   bool m_NormalProcessUnsharpFlag;
00359 
00362   ValueType m_NormalProcessUnsharpWeight;
00363 
00365   static const SizeValueType  m_NumVertex;
00366   static const ValueType      m_DimConst;
00367 
00368   SparseFieldFourthOrderLevelSetImageFilter(const Self &);
00369   //purposely not implemented
00370   void operator=(const Self &); //purposely not implemented
00371 };
00372 } // end namespace itk
00373 
00374 #ifndef ITK_MANUAL_INSTANTIATION
00375 #include "itkSparseFieldFourthOrderLevelSetImageFilter.hxx"
00376 #endif
00377 
00378 #endif
00379