ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkLevelSetEquationContainerBase.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 __itkLevelSetEquationContainerBase_h
00020 #define __itkLevelSetEquationContainerBase_h
00021 
00022 #include "itkObject.h"
00023 #include "itkObjectFactory.h"
00024 
00025 namespace itk
00026 {
00057 template< class TTermContainer >
00058 class LevelSetEquationContainerBase : public Object
00059 {
00060 public:
00061   typedef LevelSetEquationContainerBase Self;
00062   typedef SmartPointer< Self >          Pointer;
00063   typedef SmartPointer< const Self >    ConstPointer;
00064   typedef Object                        Superclass;
00066 
00068   itkNewMacro( Self );
00069 
00071   itkTypeMacro( LevelSetEquationContainerBase, Object );
00072 
00073   typedef TTermContainer                            TermContainerType;
00074   typedef typename TermContainerType::Pointer       TermContainerPointer;
00075 
00076   typedef typename TermContainerType::InputImageType    InputImageType;
00077   typedef typename TermContainerType::InputImagePointer InputImagePointer;
00078 
00079   typedef typename TermContainerType::LevelSetOutputRealType  LevelSetOutputRealType;
00080   typedef typename TermContainerType::LevelSetInputIndexType  LevelSetInputIndexType;
00081 
00082   typedef typename TermContainerType::LevelSetIdentifierType    LevelSetIdentifierType;
00083   typedef typename TermContainerType::LevelSetContainerType     LevelSetContainerType;
00084   typedef typename TermContainerType::LevelSetContainerPointer  LevelSetContainerPointer;
00085 
00087   void AddEquation( const LevelSetIdentifierType& iId, TermContainerType * iEquation );
00088 
00090   TermContainerType * GetEquation( const LevelSetIdentifierType& iId ) const;
00091 
00093   void UpdateInternalEquationTerms();
00094 
00096   void UpdatePixel( const LevelSetInputIndexType & iP,
00097                     const LevelSetOutputRealType & oldValue,
00098                     const LevelSetOutputRealType & newValue );
00099 
00101   void InitializeParameters();
00102 
00105   LevelSetOutputRealType ComputeCFLContribution() const;
00106 
00108   itkSetObjectMacro( Input, InputImageType );
00109   itkGetConstObjectMacro( Input, InputImageType );
00111 
00112   itkSetObjectMacro( LevelSetContainer, LevelSetContainerType );
00113   itkGetObjectMacro( LevelSetContainer, LevelSetContainerType );
00114 
00115 protected:
00116   typedef std::map< LevelSetIdentifierType, TermContainerPointer >  MapContainerType;
00117   typedef typename MapContainerType::iterator                       MapContainerIterator;
00118   typedef typename MapContainerType::const_iterator                 MapContainerConstIterator;
00119 
00120 public:
00121   class Iterator;
00122   friend class Iterator;
00123 
00124   class ConstIterator
00125   {
00126   public:
00127     ConstIterator() {}
00128     ConstIterator( const MapContainerConstIterator& it ) : m_Iterator( it ) {}
00129     ~ConstIterator() {}
00130     ConstIterator( const Iterator& it ) : m_Iterator( it.m_Iterator ) {}
00131     ConstIterator & operator * () { return *this; }
00132     ConstIterator * operator->() { return this; }
00133     ConstIterator & operator++()
00134       {
00135       ++m_Iterator;
00136       return *this;
00137       }
00138     ConstIterator operator++(int)
00139       {
00140       ConstIterator tmp( *this );
00141       ++(*this);
00142       return tmp;
00143       }
00144     ConstIterator & operator--()
00145       {
00146       --m_Iterator;
00147       return *this;
00148       }
00149     ConstIterator operator--(int)
00150       {
00151       ConstIterator tmp( *this );
00152       --(*this);
00153       return tmp;
00154       }
00155     bool operator == (const Iterator& it) const
00156       {
00157       return (m_Iterator == it.m_Iterator);
00158       }
00159     bool operator != (const Iterator& it) const
00160       {
00161       return (m_Iterator != it.m_Iterator);
00162       }
00163     bool operator == (const ConstIterator& it) const
00164       {
00165       return (m_Iterator == it.m_Iterator);
00166       }
00167     bool operator != (const ConstIterator& it) const
00168       {
00169       return (m_Iterator != it.m_Iterator);
00170       }
00171     LevelSetIdentifierType GetIdentifier() const
00172       {
00173       return m_Iterator->first;
00174       }
00175 
00176     TermContainerType * GetEquation() const
00177       {
00178       return m_Iterator->second;
00179       }
00180   private:
00181     MapContainerConstIterator m_Iterator;
00182     friend class Iterator;
00183   };
00184 
00185   class Iterator
00186   {
00187   public:
00188     Iterator() {}
00189     Iterator( const MapContainerIterator& it ) : m_Iterator( it ) {}
00190     Iterator( const ConstIterator& it ) : m_Iterator( it.m_Iterator ) {}
00191     ~Iterator() {}
00192 
00193     Iterator & operator * () { return *this; }
00194     Iterator * operator ->() { return this; }
00195 
00196     Iterator & operator++()
00197       {
00198       ++m_Iterator;
00199       return *this;
00200       }
00201     Iterator operator++(int)
00202       {
00203       Iterator tmp( *this );
00204       ++(*this);
00205       return tmp;
00206       }
00207     Iterator & operator--()
00208       {
00209       --m_Iterator;
00210       return *this;
00211       }
00212     Iterator operator--(int)
00213       {
00214       Iterator tmp( *this );
00215       --(*this);
00216       return tmp;
00217       }
00218 
00219     bool operator==(const Iterator& it) const
00220       {
00221       return (m_Iterator==it.m_Iterator);
00222       }
00223     bool operator!=(const Iterator& it) const
00224       {
00225       return (m_Iterator!=it.m_Iterator);
00226       }
00227     bool operator==(const ConstIterator& it)const
00228       {
00229       return (m_Iterator == it.m_Iterator);
00230       }
00231     bool operator!=(const ConstIterator& it)const
00232       {
00233       return (m_Iterator != it.m_Iterator);
00234       }
00235     LevelSetIdentifierType GetIdentifier() const
00236       {
00237       return m_Iterator->first;
00238       }
00239 
00240     TermContainerType * GetEquation() const
00241       {
00242       return m_Iterator->second;
00243       }
00244   private:
00245     MapContainerIterator m_Iterator;
00246     friend class ConstIterator;
00247   };
00248 
00249   Iterator Begin();
00250   Iterator End();
00251 
00252   ConstIterator Begin() const;
00253   ConstIterator End() const;
00254 
00255 protected:
00256 
00257   LevelSetEquationContainerBase();
00258   virtual ~LevelSetEquationContainerBase();
00259 
00260   LevelSetContainerPointer  m_LevelSetContainer;
00261   MapContainerType          m_Container;
00262   InputImagePointer         m_Input;
00263 
00264 
00265 private:
00266   LevelSetEquationContainerBase( const Self& ); // purposely not implemented
00267   void operator = ( const Self& ); // purposely not implemented
00268 
00269 };
00270 }
00271 
00272 #ifndef ITK_MANUAL_INSTANTIATION
00273 #include "itkLevelSetEquationContainerBase.hxx"
00274 #endif
00275 
00276 #endif // __itkLevelSetEquationContainerBase_h
00277