ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkFastMarchingImageFilterBase.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 
00019 #ifndef __itkFastMarchingImageFilterBase_h
00020 #define __itkFastMarchingImageFilterBase_h
00021 
00022 #include "itkFastMarchingBase.h"
00023 #include "itkImageRegionConstIteratorWithIndex.h"
00024 #include "itkNeighborhoodIterator.h"
00025 #include "itkArray.h"
00026 
00027 namespace itk
00028 {
00070 template< class TInput, class TOutput >
00071 class FastMarchingImageFilterBase :
00072     public FastMarchingBase< TInput, TOutput >
00073   {
00074 public:
00075   typedef FastMarchingImageFilterBase          Self;
00076   typedef FastMarchingBase< TInput, TOutput >  Superclass;
00077   typedef SmartPointer< Self >                 Pointer;
00078   typedef SmartPointer< const Self >           ConstPointer;
00079   typedef typename Superclass::Traits          Traits;
00081 
00083   itkNewMacro(Self);
00084 
00086   itkTypeMacro(FastMarchingImageFilterBase, FastMarchingBase);
00087 
00088 
00089   typedef typename Superclass::InputDomainType     InputImageType;
00090   typedef typename Superclass::InputDomainPointer  InputImagePointer;
00091   typedef typename Superclass::InputPixelType      InputPixelType;
00092 
00093   typedef typename Superclass::OutputDomainType     OutputImageType;
00094   typedef typename Superclass::OutputDomainPointer  OutputImagePointer;
00095   typedef typename Superclass::OutputPixelType      OutputPixelType;
00096   typedef typename OutputImageType::SpacingType     OutputSpacingType;
00097   typedef typename OutputImageType::SizeType        OutputSizeType;
00098   typedef typename OutputImageType::RegionType      OutputRegionType;
00099   typedef typename OutputImageType::PointType       OutputPointType;
00100   typedef typename OutputImageType::DirectionType   OutputDirectionType;
00101 
00102   typedef typename Traits::NodeType                 NodeType;
00103   typedef typename Traits::NodePairType             NodePairType;
00104   typedef typename Traits::NodePairContainerType    NodePairContainerType;
00105   typedef typename Traits::NodePairContainerPointer NodePairContainerPointer;
00106   typedef typename Traits::NodePairContainerConstIterator
00107     NodePairContainerConstIterator;
00108 
00109   /*
00110   typedef typename Superclass::ElementIdentifier ElementIdentifier;
00111 
00112   typedef typename Superclass::PriorityQueueElementType PriorityQueueElementType;
00113 
00114   typedef typename Superclass::PriorityQueueType PriorityQueueType;
00115   typedef typename Superclass::PriorityQueuePointer PriorityQueuePointer;
00116   */
00117 
00118   typedef typename Superclass::LabelType LabelType;
00119 
00120   itkStaticConstMacro( ImageDimension, unsigned int, Traits::ImageDimension );
00121 
00122   typedef Image< unsigned char, ImageDimension >  LabelImageType;
00123   typedef typename LabelImageType::Pointer        LabelImagePointer;
00124 
00125   typedef Image< unsigned int, ImageDimension >
00126     ConnectedComponentImageType;
00127   typedef typename ConnectedComponentImageType::Pointer ConnectedComponentImagePointer;
00128 
00129   typedef NeighborhoodIterator<LabelImageType> NeighborhoodIteratorType;
00130   typedef typename NeighborhoodIteratorType::RadiusType NeighborhoodRadiusType;
00131 
00132   itkGetObjectMacro( LabelImage, LabelImageType );
00133 
00134 
00142   virtual void SetOutputSize(const OutputSizeType & size)
00143   { m_OutputRegion = size; }
00144   virtual OutputSizeType GetOutputSize() const
00145   { return m_OutputRegion.GetSize(); }
00146   itkSetMacro(OutputRegion, OutputRegionType);
00147   itkGetConstReferenceMacro(OutputRegion, OutputRegionType);
00148   itkSetMacro(OutputSpacing, OutputSpacingType);
00149   itkGetConstReferenceMacro(OutputSpacing, OutputSpacingType);
00150   itkSetMacro(OutputDirection, OutputDirectionType);
00151   itkGetConstReferenceMacro(OutputDirection, OutputDirectionType);
00152   itkSetMacro(OutputOrigin, OutputPointType);
00153   itkGetConstReferenceMacro(OutputOrigin, OutputPointType);
00154   itkSetMacro(OverrideOutputInformation, bool);
00155   itkGetConstReferenceMacro(OverrideOutputInformation, bool);
00156   itkBooleanMacro(OverrideOutputInformation);
00158 
00159 protected:
00160 
00162   FastMarchingImageFilterBase();
00163 
00165   virtual ~FastMarchingImageFilterBase();
00166 
00167   class InternalNodeStructure;
00168 
00169   OutputRegionType  m_BufferedRegion;
00170   NodeType          m_StartIndex;
00171   NodeType          m_LastIndex;
00172 
00173   OutputRegionType    m_OutputRegion;
00174   OutputPointType     m_OutputOrigin;
00175   OutputSpacingType   m_OutputSpacing;
00176   OutputDirectionType m_OutputDirection;
00177   bool                m_OverrideOutputInformation;
00178 
00180   virtual void GenerateOutputInformation();
00181 
00182   virtual void EnlargeOutputRequestedRegion(DataObject *output);
00183 
00184   LabelImagePointer               m_LabelImage;
00185   ConnectedComponentImagePointer  m_ConnectedComponentImage;
00186 
00187   IdentifierType GetTotalNumberOfNodes() const;
00188 
00189   void SetOutputValue( OutputImageType* oDomain,
00190                        const NodeType& iNode,
00191                        const OutputPixelType& iValue );
00192 
00194   const OutputPixelType GetOutputValue( OutputImageType* oImage,
00195                                   const NodeType& iNode ) const;
00196 
00198   unsigned char
00199   GetLabelValueForGivenNode( const NodeType& iNode ) const;
00200 
00202   void SetLabelValueForGivenNode( const NodeType& iNode,
00203                                  const LabelType& iLabel );
00204 
00206   virtual void UpdateNeighbors( OutputImageType* oImage,
00207                                 const NodeType& iNode );
00208 
00210   virtual void UpdateValue( OutputImageType* oImage,
00211                             const NodeType& iValue );
00212 
00214   bool CheckTopology( OutputImageType* oImage,
00215                       const NodeType& iNode );
00216   void InitializeOutput( OutputImageType* oImage );
00218 
00220   void GetInternalNodesUsed( OutputImageType* oImage,
00221                             const NodeType& iNode,
00222                             std::vector< InternalNodeStructure >& ioNodesUsed );
00223 
00225   double Solve( OutputImageType* oImage,
00226                const NodeType& iNode,
00227                std::vector< InternalNodeStructure >& ioNeighbors ) const;
00228 
00229   // --------------------------------------------------------------------------
00230   // --------------------------------------------------------------------------
00231 
00236   // Functions/data for the 2-D case
00237   void InitializeIndices2D();
00238   bool IsChangeWellComposed2D( const NodeType& ) const;
00239   bool IsCriticalC1Configuration2D( const std::vector<bool>& ) const;
00240   bool IsCriticalC2Configuration2D( const std::vector<bool>& ) const;
00241   bool IsCriticalC3Configuration2D( const std::vector<bool>& ) const;
00242   bool IsCriticalC4Configuration2D( const std::vector<bool>& ) const;
00243 
00244   Array<unsigned char>  m_RotationIndices[4];
00245   Array<unsigned char>  m_ReflectionIndices[2];
00246 
00247   // Functions/data for the 3-D case
00248   void InitializeIndices3D();
00249   bool IsCriticalC1Configuration3D( const std::vector<bool>& ) const;
00250   unsigned int IsCriticalC2Configuration3D( const std::vector<bool>& ) const;
00251   bool IsChangeWellComposed3D( const NodeType& ) const;
00252 
00253   Array<unsigned char>                        m_C1Indices[12];
00254   Array<unsigned char>                        m_C2Indices[8];
00255 
00256   // Functions for both 2D/3D cases
00257   bool DoesVoxelChangeViolateWellComposedness( const NodeType& ) const;
00258   bool DoesVoxelChangeViolateStrictTopology( const NodeType& ) const;
00259 
00260 private:
00261 
00262   FastMarchingImageFilterBase( const Self& );
00263   void operator = ( const Self& );
00264   };
00265 }
00266 
00267 #include "itkFastMarchingImageFilterBase.hxx"
00268 #endif // __itkFastMarchingImageFilterBase_h
00269