ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkLevelSetEquationTermContainer.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #ifndef itkLevelSetEquationTermContainer_h
20 #define itkLevelSetEquationTermContainer_h
21 
23 #include "itkObject.h"
24 
25 #include "itksys/hash_map.hxx"
26 
27 #include <map>
28 #include <string>
29 
30 namespace itk
31 {
41 template< typename TInputImage,
42  typename TLevelSetContainer >
43 class ITK_TEMPLATE_EXPORT LevelSetEquationTermContainer : public Object
44 {
45 public:
49  typedef Object Superclass;
50 
52  itkNewMacro( Self );
53 
55  itkTypeMacro( LevelSetEquationTermContainer,
56  Object );
57 
58  typedef unsigned int TermIdType;
59 
60  typedef TInputImage InputImageType;
61  typedef typename InputImageType::Pointer InputImagePointer;
62 
63  typedef TLevelSetContainer LevelSetContainerType;
64  typedef typename LevelSetContainerType::Pointer LevelSetContainerPointer;
65 
66  typedef typename LevelSetContainerType::LevelSetType LevelSetType;
67  typedef typename LevelSetContainerType::LevelSetPointer LevelSetPointer;
68 
69  typedef typename LevelSetContainerType::LevelSetIdentifierType
71  typedef typename LevelSetContainerType::OutputType LevelSetOutputPixelType;
72  typedef typename LevelSetContainerType::OutputRealType LevelSetOutputRealType;
73  typedef typename LevelSetContainerType::LevelSetDataType LevelSetDataType;
74  typedef typename LevelSetContainerType::InputIndexType LevelSetInputIndexType;
75  typedef typename LevelSetContainerType::GradientType LevelSetGradientType;
76  typedef typename LevelSetContainerType::HessianType LevelSetHessianType;
77 
80  typedef typename TermType::Pointer TermPointer;
81 
83  itkSetObjectMacro( Input, InputImageType );
84  itkGetModifiableObjectMacro(Input, InputImageType );
86 
87  itkSetMacro( CurrentLevelSetId, LevelSetIdentifierType );
88  itkGetMacro( CurrentLevelSetId, LevelSetIdentifierType );
89 
90  itkSetObjectMacro( LevelSetContainer, LevelSetContainerType );
91  itkGetModifiableObjectMacro(LevelSetContainer, LevelSetContainerType );
92 
94  void PushTerm( TermType* iTerm );
95 
97  void AddTerm( const TermIdType& iId, TermType* iTerm );
98 
100  TermType* GetTerm( const TermIdType& iId );
101 
103  TermType* GetTerm( const std::string& iName );
104 
106  void Initialize( const LevelSetInputIndexType& iP );
107 
109  void UpdatePixel( const LevelSetInputIndexType& iP,
110  const LevelSetOutputRealType & oldValue,
111  const LevelSetOutputRealType & newValue );
112 
114  void InitializeParameters();
115 
117  LevelSetOutputRealType Evaluate( const LevelSetInputIndexType& iP );
118 
120  const LevelSetDataType& iData );
121 
123  void Update();
124 
126  LevelSetOutputRealType ComputeCFLContribution() const;
127 
128  void ComputeRequiredData( const LevelSetInputIndexType& iP,
129  LevelSetDataType& ioData );
130 
131 protected:
132 
133  typedef std::map< TermIdType, TermPointer > MapTermContainerType;
134  typedef typename MapTermContainerType::iterator MapTermContainerIteratorType;
135  typedef typename MapTermContainerType::const_iterator MapTermContainerConstIteratorType;
136 
137 public:
138  class Iterator;
139  friend class Iterator;
140 
142  {
143  public:
145  ConstIterator( const MapTermContainerConstIteratorType& it ) : m_Iterator( it ) {}
147  ConstIterator( const Iterator& it ) : m_Iterator( it.m_Iterator ) {}
148  ConstIterator & operator * () { return *this; }
149  ConstIterator * operator->() { return this; }
151  {
152  ++m_Iterator;
153  return *this;
154  }
156  {
157  ConstIterator tmp( *this );
158  ++(*this);
159  return tmp;
160  }
162  {
163  --m_Iterator;
164  return *this;
165  }
167  {
168  ConstIterator tmp( *this );
169  --(*this);
170  return tmp;
171  }
172  bool operator == (const Iterator& it) const
173  {
174  return (m_Iterator == it.m_Iterator);
175  }
176  bool operator != (const Iterator& it) const
177  {
178  return (m_Iterator != it.m_Iterator);
179  }
180  bool operator == (const ConstIterator& it) const
181  {
182  return (m_Iterator == it.m_Iterator);
183  }
184  bool operator != (const ConstIterator& it) const
185  {
186  return (m_Iterator != it.m_Iterator);
187  }
189  {
190  return m_Iterator->first;
191  }
192 
193  TermType * GetTerm() const
194  {
195  return m_Iterator->second;
196  }
197  private:
199  friend class Iterator;
200  };
201 
202  class Iterator
203  {
204  public:
205  Iterator() {}
206  Iterator( const MapTermContainerIteratorType& it ) : m_Iterator( it ) {}
207  Iterator( const ConstIterator& it ) : m_Iterator( it.m_Iterator ) {}
209 
210  Iterator & operator * () { return *this; }
211  Iterator * operator ->() { return this; }
212 
214  {
215  ++m_Iterator;
216  return *this;
217  }
219  {
220  Iterator tmp( *this );
221  ++(*this);
222  return tmp;
223  }
225  {
226  --m_Iterator;
227  return *this;
228  }
230  {
231  Iterator tmp( *this );
232  --(*this);
233  return tmp;
234  }
235 
236  bool operator==(const Iterator& it) const
237  {
238  return (m_Iterator==it.m_Iterator);
239  }
240  bool operator!=(const Iterator& it) const
241  {
242  return (m_Iterator!=it.m_Iterator);
243  }
244  bool operator==(const ConstIterator& it)const
245  {
246  return (m_Iterator == it.m_Iterator);
247  }
248  bool operator!=(const ConstIterator& it)const
249  {
250  return (m_Iterator != it.m_Iterator);
251  }
253  {
254  return m_Iterator->first;
255  }
256 
257  TermType * GetTerm() const
258  {
259  return m_Iterator->second;
260  }
261  private:
263  friend class ConstIterator;
264  };
265 
266  Iterator Begin();
267  Iterator End();
268 
269  ConstIterator Begin() const;
270  ConstIterator End() const;
271 
272 protected:
274 
275  virtual ~LevelSetEquationTermContainer() ITK_OVERRIDE;
276 
277  LevelSetIdentifierType m_CurrentLevelSetId;
278  LevelSetContainerPointer m_LevelSetContainer;
279 
281 
282  typedef itksys::hash_map< std::string, TermPointer > HashMapStringTermContainerType;
283 
284  HashMapStringTermContainerType m_NameContainer;
285 
287  RequiredDataType m_RequiredData;
288 
289  MapTermContainerType m_Container;
290 
292  typedef typename MapCFLContainerType::iterator MapCFLContainerIterator;
293  typedef typename MapCFLContainerType::const_iterator MapCFLContainerConstIterator;
294 
295  MapCFLContainerType m_TermContribution;
296 
297 private:
299  void operator = ( const Self& );
300 };
301 
302 }
303 #ifndef ITK_MANUAL_INSTANTIATION
304 #include "itkLevelSetEquationTermContainer.hxx"
305 #endif
306 
307 #endif // itkLevelSetEquationTermContainer_h
bool operator!=(const ImageRegionCopier< D1, D2 > &c1, const ImageRegionCopier< D1, D2 > &c2)
Light weight base class for most itk classes.
Class for container holding the terms of a given level set update equation.
std::map< TermIdType, LevelSetOutputRealType > MapCFLContainerType
std::map< TermIdType, TermPointer > MapTermContainerType
LevelSetEquationTermBase< InputImageType, LevelSetContainerType > TermType
ConstIterator(const MapTermContainerConstIteratorType &it)
LevelSetContainerType::OutputType LevelSetOutputPixelType
CovariantVector< T, NVectorDimension > operator*(const T &scalar, const CovariantVector< T, NVectorDimension > &v)
LevelSetContainerType::LevelSetType LevelSetType
LevelSetContainerType::LevelSetPointer LevelSetPointer
Abstract class to represents a term in the level-set evolution PDE.
MapTermContainerType::const_iterator MapTermContainerConstIteratorType
MapTermContainerType::iterator MapTermContainerIteratorType
itksys::hash_map< std::string, TermPointer > HashMapStringTermContainerType
MapCFLContainerType::iterator MapCFLContainerIterator
LevelSetContainerType::HessianType LevelSetHessianType
LevelSetContainerType::Pointer LevelSetContainerPointer
LevelSetContainerType::LevelSetIdentifierType LevelSetIdentifierType
LevelSetContainerType::LevelSetDataType LevelSetDataType
Container of Level-Sets.
LevelSetContainerType::InputIndexType LevelSetInputIndexType
LevelSetContainerType::GradientType LevelSetGradientType
LevelSetContainerType::OutputRealType LevelSetOutputRealType
Base class for most ITK classes.
Definition: itkObject.h:59
bool ITKIOXML_EXPORT operator==(itk::FancyString &s, const std::string &)
MapCFLContainerType::const_iterator MapCFLContainerConstIterator