ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkLevelSetContainerBase.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 __itkLevelSetContainerBase_h
00020 #define __itkLevelSetContainerBase_h
00021 
00022 #include <map>
00023 #include "itkObject.h"
00024 #include "itkObjectFactory.h"
00025 #include "itkHeavisideStepFunctionBase.h"
00026 #include "itkLevelSetDomainMapImageFilter.h"
00027 
00028 
00029 namespace itk
00030 {
00041 template< class TIdentifier, class TLevelSet >
00042 class LevelSetContainerBase : public Object
00043 {
00044 public:
00045   typedef LevelSetContainerBase      Self;
00046   typedef SmartPointer< Self >       Pointer;
00047   typedef SmartPointer< const Self > ConstPointer;
00048   typedef Object                     Superclass;
00049 
00051   itkTypeMacro ( LevelSetContainerBase, Object );
00052 
00054   typedef TLevelSet                               LevelSetType;
00055   typedef typename LevelSetType::Pointer          LevelSetPointer;
00056   typedef typename LevelSetType::InputType        InputIndexType;
00057   typedef typename LevelSetType::OutputType       OutputType;
00058   typedef typename LevelSetType::OutputRealType   OutputRealType;
00059   typedef typename LevelSetType::GradientType     GradientType;
00060   typedef typename LevelSetType::HessianType      HessianType;
00061   typedef typename LevelSetType::LevelSetDataType LevelSetDataType;
00062 
00064   typedef TIdentifier LevelSetIdentifierType;
00065 
00066   typedef std::map< LevelSetIdentifierType, LevelSetPointer > LevelSetContainerType;
00067   typedef typename LevelSetContainerType::const_iterator      LevelSetContainerConstIteratorType;
00068   typedef typename LevelSetContainerType::iterator            LevelSetContainerIteratorType;
00069 
00070   typedef HeavisideStepFunctionBase< OutputRealType, OutputRealType > HeavisideType;
00071   typedef typename HeavisideType::ConstPointer                        HeavisideConstPointer;
00072 
00073   itkStaticConstMacro ( Dimension, unsigned int, LevelSetType::Dimension );
00074 
00075   typedef std::list< LevelSetIdentifierType >           IdListType;
00076   typedef typename IdListType::iterator                 IdListIterator;
00077   typedef typename IdListType::const_iterator           IdListConstIterator;
00078   typedef Image< IdListType, Dimension >                IdListImageType;
00079   typedef Image< short, Dimension >                     CacheImageType;
00080 
00081   typedef LevelSetDomainMapImageFilter< IdListImageType, CacheImageType > DomainMapImageFilterType;
00082 
00083   typedef std::pair< LevelSetIdentifierType, LevelSetPointer > LevelSetPairType;
00084 
00085   typedef typename DomainMapImageFilterType::Pointer          DomainMapImageFilterPointer;
00086   typedef typename DomainMapImageFilterType::LevelSetDomain   LevelSetDomainType;
00087 
00088   typedef std::map< LevelSetIdentifierType, LevelSetDomainType >   DomainContainerType;
00089   typedef typename DomainContainerType::iterator                   DomainIteratorType;
00090 
00092   class Iterator;
00093   friend class Iterator;
00094 
00098   class ConstIterator
00099   {
00100   public:
00101     ConstIterator( ) {}
00102     ConstIterator( const LevelSetContainerConstIteratorType& it ) : m_Iterator( it ) {}
00103     ~ConstIterator() {}
00104     ConstIterator( const Iterator& it ) : m_Iterator( it.m_Iterator ) {}
00105 
00106     ConstIterator & operator * () { return *this; }
00107     ConstIterator * operator->()  { return this; }
00108     ConstIterator & operator++()
00109     {
00110       ++m_Iterator;
00111       return *this;
00112     }
00113     ConstIterator operator++(int)
00114     {
00115       ConstIterator tmp( *this );
00116       ++(*this);
00117       return tmp;
00118     }
00119     ConstIterator & operator--()
00120     {
00121       --m_Iterator;
00122       return *this;
00123     }
00124     ConstIterator operator--(int)
00125     {
00126       ConstIterator tmp( *this );
00127       --(*this);
00128       return tmp;
00129     }
00130     bool operator==(const Iterator& it) const
00131     {
00132       return ( m_Iterator == it.m_Iterator );
00133     }
00134     bool operator!=(const Iterator& it) const
00135     {
00136       return (m_Iterator != it.m_Iterator );
00137     }
00138     bool operator==(const ConstIterator& it) const
00139     {
00140       return ( m_Iterator == it.m_Iterator );
00141     }
00142     bool operator!=(const ConstIterator& it) const
00143     {
00144       return (m_Iterator != it.m_Iterator );
00145     }
00146 
00147     LevelSetIdentifierType GetIdentifier() const
00148     {
00149       return m_Iterator->first;
00150     }
00151 
00152     LevelSetType* GetLevelSet() const
00153     {
00154       return m_Iterator->second;
00155     }
00156 
00157   private:
00158     LevelSetContainerConstIteratorType m_Iterator;
00159     friend class Iterator;
00160     };
00161 
00164   class Iterator
00165     {
00166   public:
00167     Iterator( ) {}
00168     Iterator( const LevelSetContainerIteratorType& it ) : m_Iterator( it ) {}
00169     Iterator( const ConstIterator& it ) : m_Iterator( it.m_Iterator ) {}
00170     ~Iterator() {}
00171 
00172     Iterator & operator * () { return *this; }
00173     Iterator * operator->()  { return this; }
00174     Iterator & operator++()
00175     {
00176       ++m_Iterator;
00177       return *this;
00178     }
00179     Iterator operator++(int)
00180     {
00181       Iterator tmp( *this );
00182       ++(*this);
00183       return tmp;
00184     }
00185     Iterator & operator--()
00186     {
00187       --m_Iterator;
00188       return *this;
00189     }
00190     Iterator operator--(int)
00191     {
00192       Iterator tmp( *this );
00193       --(*this);
00194       return tmp;
00195     }
00196     bool operator==(const Iterator& it) const
00197     {
00198       return ( m_Iterator == it.m_Iterator );
00199     }
00200     bool operator!=(const Iterator& it) const
00201     {
00202       return (m_Iterator != it.m_Iterator );
00203     }
00204     bool operator==(const ConstIterator& it) const
00205     {
00206       return ( m_Iterator == it.m_Iterator );
00207     }
00208     bool operator!=(const ConstIterator& it) const
00209     {
00210       return (m_Iterator != it.m_Iterator );
00211     }
00212 
00213     LevelSetIdentifierType GetIdentifier() const
00214     {
00215       return m_Iterator->first;
00216     }
00217 
00218     LevelSetType* GetLevelSet() const
00219     {
00220       return m_Iterator->second;
00221     }
00222 
00223   private:
00224     LevelSetContainerIteratorType m_Iterator;
00225     friend class ConstIterator;
00226   };
00227 
00228   Iterator Begin();
00229   Iterator End();
00230 
00231   ConstIterator Begin() const;
00232   ConstIterator End() const;
00233 
00235   LevelSetIdentifierType Size() const;
00236 
00241   LevelSetPointer GetLevelSet( const LevelSetIdentifierType& iId ) const;
00242 
00252   bool AddLevelSet( const LevelSetIdentifierType& iId,
00253                     LevelSetType * iLevelSet,
00254                     const bool iForce = true );
00255 
00261   bool RemoveLevelSet( const LevelSetIdentifierType& iId );
00262 
00264   itkSetObjectMacro( Heaviside, HeavisideType );
00265   itkGetConstObjectMacro( Heaviside, HeavisideType );
00267 
00269   itkSetObjectMacro( DomainMapFilter, DomainMapImageFilterType );
00270   itkGetObjectMacro( DomainMapFilter, DomainMapImageFilterType );
00272 
00274   bool HasDomainMap() const;
00275 
00276 protected:
00278   LevelSetContainerBase();
00279 
00281   ~LevelSetContainerBase();
00282 
00283   const LevelSetContainerType& GetContainer() const;
00284   void SetContainer( const LevelSetContainerType& iContainer );
00285 
00286 private:
00287   LevelSetContainerBase( const Self & ); // purposely not implemented
00288   void operator = ( const Self & ); // purposely not implemented
00289 
00290   HeavisideConstPointer         m_Heaviside;
00291   DomainMapImageFilterPointer   m_DomainMapFilter;
00292   LevelSetContainerType         m_Container;
00293 };
00294 }
00295 
00296 #ifndef ITK_MANUAL_INSTANTIATION
00297 #include "itkLevelSetContainerBase.hxx"
00298 #endif
00299 
00300 #endif // __itkLevelSetContainerBase_h
00301