ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkLevelSetEquationTermContainerBase.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 __itkLevelSetEquationTermContainerBase_h
00020 #define __itkLevelSetEquationTermContainerBase_h
00021 
00022 #include "itkLevelSetEquationTermBase.h"
00023 #include "itkObject.h"
00024 
00025 #include "itksys/hash_map.hxx"
00026 
00027 #include <map>
00028 #include <string>
00029 
00030 namespace itk
00031 {
00041 template< class TInputImage,
00042           class TLevelSetContainer >
00043 class LevelSetEquationTermContainerBase : public Object
00044 {
00045 public:
00046   typedef LevelSetEquationTermContainerBase Self;
00047   typedef SmartPointer< Self >              Pointer;
00048   typedef SmartPointer< const Self >        ConstPointer;
00049   typedef Object                            Superclass;
00050 
00052   itkNewMacro( Self );
00053 
00055   itkTypeMacro( LevelSetEquationTermContainerBase,
00056                 Object );
00057 
00058   typedef unsigned int                      TermIdType;
00059 
00060   typedef TInputImage                       InputImageType;
00061   typedef typename InputImageType::Pointer  InputImagePointer;
00062 
00063   typedef TLevelSetContainer                                LevelSetContainerType;
00064   typedef typename LevelSetContainerType::Pointer           LevelSetContainerPointer;
00065 
00066   typedef typename LevelSetContainerType::LevelSetType      LevelSetType;
00067   typedef typename LevelSetContainerType::LevelSetPointer   LevelSetPointer;
00068 
00069   typedef typename LevelSetContainerType::LevelSetIdentifierType
00070                                                             LevelSetIdentifierType;
00071   typedef typename LevelSetContainerType::OutputType        LevelSetOutputPixelType;
00072   typedef typename LevelSetContainerType::OutputRealType    LevelSetOutputRealType;
00073   typedef typename LevelSetContainerType::LevelSetDataType  LevelSetDataType;
00074   typedef typename LevelSetContainerType::InputIndexType    LevelSetInputIndexType;
00075   typedef typename LevelSetContainerType::GradientType      LevelSetGradientType;
00076   typedef typename LevelSetContainerType::HessianType       LevelSetHessianType;
00077 
00078   typedef LevelSetEquationTermBase< InputImageType, LevelSetContainerType >
00079                                                                        TermType;
00080   typedef typename TermType::Pointer                                   TermPointer;
00081 
00083   itkSetObjectMacro( Input, InputImageType );
00084   itkGetObjectMacro( Input, InputImageType );
00086 
00087   itkSetMacro( CurrentLevelSetId, LevelSetIdentifierType );
00088   itkGetMacro( CurrentLevelSetId, LevelSetIdentifierType );
00089 
00090   itkSetObjectMacro( LevelSetContainer, LevelSetContainerType );
00091   itkGetObjectMacro( LevelSetContainer, LevelSetContainerType );
00092 
00094   void PushTerm( TermType* iTerm );
00095 
00097   void AddTerm( const TermIdType& iId, TermType* iTerm );
00098 
00100   TermType* GetTerm( const TermIdType& iId );
00101 
00103   TermType* GetTerm( const std::string& iName );
00104 
00106   void Initialize( const LevelSetInputIndexType& iP );
00107 
00109   void UpdatePixel( const LevelSetInputIndexType& iP,
00110                     const LevelSetOutputRealType & oldValue,
00111                     const LevelSetOutputRealType & newValue );
00112 
00114   void InitializeParameters();
00115 
00117   LevelSetOutputRealType Evaluate( const LevelSetInputIndexType& iP );
00118 
00119   LevelSetOutputRealType Evaluate( const LevelSetInputIndexType& iP,
00120                                    const LevelSetDataType& iData );
00121 
00123   void Update();
00124 
00126   LevelSetOutputRealType ComputeCFLContribution() const;
00127 
00128   void ComputeRequiredData( const LevelSetInputIndexType& iP,
00129                             LevelSetDataType& ioData );
00130 
00131 protected:
00132 
00133   typedef std::map< TermIdType, TermPointer >           MapTermContainerType;
00134   typedef typename MapTermContainerType::iterator       MapTermContainerIteratorType;
00135   typedef typename MapTermContainerType::const_iterator MapTermContainerConstIteratorType;
00136 
00137 public:
00138   class Iterator;
00139   friend class Iterator;
00140 
00141   class ConstIterator
00142   {
00143   public:
00144     ConstIterator() {}
00145     ConstIterator( const MapTermContainerConstIteratorType& it ) : m_Iterator( it ) {}
00146     ~ConstIterator() {}
00147     ConstIterator( const Iterator& it ) : m_Iterator( it.m_Iterator ) {}
00148     ConstIterator & operator * () { return *this; }
00149     ConstIterator * operator->() { return this; }
00150     ConstIterator & operator++()
00151       {
00152       ++m_Iterator;
00153       return *this;
00154       }
00155     ConstIterator operator++(int)
00156       {
00157       ConstIterator tmp( *this );
00158       ++(*this);
00159       return tmp;
00160       }
00161     ConstIterator & operator--()
00162       {
00163       --m_Iterator;
00164       return *this;
00165       }
00166     ConstIterator operator--(int)
00167       {
00168       ConstIterator tmp( *this );
00169       --(*this);
00170       return tmp;
00171       }
00172     bool operator == (const Iterator& it) const
00173       {
00174       return (m_Iterator == it.m_Iterator);
00175       }
00176     bool operator != (const Iterator& it) const
00177       {
00178       return (m_Iterator != it.m_Iterator);
00179       }
00180     bool operator == (const ConstIterator& it) const
00181       {
00182       return (m_Iterator == it.m_Iterator);
00183       }
00184     bool operator != (const ConstIterator& it) const
00185       {
00186       return (m_Iterator != it.m_Iterator);
00187       }
00188     TermIdType GetIdentifier() const
00189       {
00190       return m_Iterator->first;
00191       }
00192 
00193     TermType * GetTerm() const
00194       {
00195       return m_Iterator->second;
00196       }
00197   private:
00198     MapTermContainerConstIteratorType m_Iterator;
00199     friend class Iterator;
00200   };
00201 
00202   class Iterator
00203   {
00204   public:
00205     Iterator() {}
00206     Iterator( const MapTermContainerIteratorType& it ) : m_Iterator( it ) {}
00207     Iterator( const ConstIterator& it ) : m_Iterator( it.m_Iterator ) {}
00208     ~Iterator() {}
00209 
00210     Iterator & operator * () { return *this; }
00211     Iterator * operator ->() { return this; }
00212 
00213     Iterator & operator++()
00214       {
00215       ++m_Iterator;
00216       return *this;
00217       }
00218     Iterator operator++(int)
00219       {
00220        Iterator tmp( *this );
00221       ++(*this);
00222       return tmp;
00223       }
00224     Iterator & operator--()
00225       {
00226       --m_Iterator;
00227       return *this;
00228       }
00229     Iterator operator--(int)
00230       {
00231       Iterator tmp( *this );
00232       --(*this);
00233       return tmp;
00234       }
00235 
00236     bool operator==(const Iterator& it) const
00237       {
00238       return (m_Iterator==it.m_Iterator);
00239       }
00240     bool operator!=(const Iterator& it) const
00241       {
00242       return (m_Iterator!=it.m_Iterator);
00243       }
00244     bool operator==(const ConstIterator& it)const
00245       {
00246       return (m_Iterator == it.m_Iterator);
00247       }
00248     bool operator!=(const ConstIterator& it)const
00249       {
00250       return (m_Iterator != it.m_Iterator);
00251       }
00252     TermIdType GetIdentifier() const
00253       {
00254       return m_Iterator->first;
00255       }
00256 
00257     TermType * GetTerm() const
00258       {
00259       return m_Iterator->second;
00260       }
00261   private:
00262     MapTermContainerIteratorType m_Iterator;
00263     friend class ConstIterator;
00264   };
00265 
00266    Iterator Begin();
00267    Iterator End();
00268 
00269   ConstIterator Begin() const;
00270   ConstIterator End() const;
00271 
00272 protected:
00273   LevelSetEquationTermContainerBase();
00274 
00275   virtual ~LevelSetEquationTermContainerBase();
00276 
00277   LevelSetIdentifierType    m_CurrentLevelSetId;
00278   LevelSetContainerPointer  m_LevelSetContainer;
00279 
00280   InputImagePointer         m_Input;
00281 
00282   typedef itksys::hash_map< std::string, TermPointer > HashMapStringTermContainerType;
00283 
00284   HashMapStringTermContainerType m_NameContainer;
00285 
00286   typedef typename TermType::RequiredDataType RequiredDataType;
00287   RequiredDataType  m_RequiredData;
00288 
00289   MapTermContainerType  m_Container;
00290 
00291   typedef std::map< TermIdType, LevelSetOutputRealType >  MapCFLContainerType;
00292   typedef typename MapCFLContainerType::iterator          MapCFLContainerIterator;
00293   typedef typename MapCFLContainerType::const_iterator    MapCFLContainerConstIterator;
00294 
00295   MapCFLContainerType   m_TermContribution;
00296 
00297 private:
00298   LevelSetEquationTermContainerBase( const Self& );
00299   void operator = ( const Self& );
00300 };
00301 
00302 }
00303 #ifndef ITK_MANUAL_INSTANTIATION
00304 #include "itkLevelSetEquationTermContainerBase.hxx"
00305 #endif
00306 
00307 #endif // __itkLevelSetEquationTermContainerBase_h
00308