ITK  5.0.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:
46  ITK_DISALLOW_COPY_AND_ASSIGN(LevelSetEquationTermContainer);
47 
51  using Superclass = Object;
52 
54  itkNewMacro( Self );
55 
57  itkTypeMacro( LevelSetEquationTermContainer,
58  Object );
59 
60  using TermIdType = unsigned int;
61 
62  using InputImageType = TInputImage;
63  using InputImagePointer = typename InputImageType::Pointer;
64 
65  using LevelSetContainerType = TLevelSetContainer;
66  using LevelSetContainerPointer = typename LevelSetContainerType::Pointer;
67 
68  using LevelSetType = typename LevelSetContainerType::LevelSetType;
69  using LevelSetPointer = typename LevelSetContainerType::LevelSetPointer;
70 
71  using LevelSetIdentifierType = typename LevelSetContainerType::LevelSetIdentifierType;
72  using LevelSetOutputPixelType = typename LevelSetContainerType::OutputType;
73  using LevelSetOutputRealType = typename LevelSetContainerType::OutputRealType;
74  using LevelSetDataType = typename LevelSetContainerType::LevelSetDataType;
75  using LevelSetInputIndexType = typename LevelSetContainerType::InputIndexType;
76  using LevelSetGradientType = typename LevelSetContainerType::GradientType;
77  using LevelSetHessianType = typename LevelSetContainerType::HessianType;
78 
79  using TermType =
81  using TermPointer = typename TermType::Pointer;
82 
84  itkSetObjectMacro( Input, InputImageType );
85  itkGetModifiableObjectMacro(Input, InputImageType );
87 
88  itkSetMacro( CurrentLevelSetId, LevelSetIdentifierType );
89  itkGetMacro( CurrentLevelSetId, LevelSetIdentifierType );
90 
91  itkSetObjectMacro( LevelSetContainer, LevelSetContainerType );
92  itkGetModifiableObjectMacro(LevelSetContainer, LevelSetContainerType );
93 
95  void PushTerm( TermType* iTerm );
96 
98  void AddTerm( const TermIdType& iId, TermType* iTerm );
99 
101  TermType* GetTerm( const TermIdType& iId );
102 
104  TermType* GetTerm( const std::string& iName );
105 
107  void Initialize( const LevelSetInputIndexType& iP );
108 
110  void UpdatePixel( const LevelSetInputIndexType& iP,
111  const LevelSetOutputRealType & oldValue,
112  const LevelSetOutputRealType & newValue );
113 
115  void InitializeParameters();
116 
118  LevelSetOutputRealType Evaluate( const LevelSetInputIndexType& iP );
119 
121  const LevelSetDataType& iData );
122 
124  void Update();
125 
127  LevelSetOutputRealType ComputeCFLContribution() const;
128 
129  void ComputeRequiredData( const LevelSetInputIndexType& iP,
130  LevelSetDataType& ioData );
131 
132 protected:
133 
134  using MapTermContainerType = std::map< TermIdType, TermPointer >;
135  using MapTermContainerIteratorType = typename MapTermContainerType::iterator;
136  using MapTermContainerConstIteratorType = typename MapTermContainerType::const_iterator;
137 
138 public:
139  class Iterator;
140  friend class Iterator;
141 
143  {
144  public:
145  ConstIterator() = default;
146  ConstIterator( const MapTermContainerConstIteratorType& it ) : m_Iterator( it ) {}
147  ~ConstIterator() = default;
148  ConstIterator( const Iterator& it ) : m_Iterator( it.m_Iterator ) {}
149  ConstIterator & operator * () { return *this; }
150  ConstIterator * operator->() { return this; }
152  {
153  ++m_Iterator;
154  return *this;
155  }
157  {
158  ConstIterator tmp( *this );
159  ++(*this);
160  return tmp;
161  }
163  {
164  --m_Iterator;
165  return *this;
166  }
168  {
169  ConstIterator tmp( *this );
170  --(*this);
171  return tmp;
172  }
173  bool operator == (const Iterator& it) const
174  {
175  return (m_Iterator == it.m_Iterator);
176  }
177  bool operator != (const Iterator& it) const
178  {
179  return (m_Iterator != it.m_Iterator);
180  }
181  bool operator == (const ConstIterator& it) const
182  {
183  return (m_Iterator == it.m_Iterator);
184  }
185  bool operator != (const ConstIterator& it) const
186  {
187  return (m_Iterator != it.m_Iterator);
188  }
190  {
191  return m_Iterator->first;
192  }
193 
194  TermType * GetTerm() const
195  {
196  return m_Iterator->second;
197  }
198  private:
200  friend class Iterator;
201  };
202 
203  class Iterator
204  {
205  public:
206  Iterator() = default;
207  Iterator( const MapTermContainerIteratorType& it ) : m_Iterator( it ) {}
208  Iterator( const ConstIterator& it ) : m_Iterator( it.m_Iterator ) {}
209  ~Iterator() = default;
210 
211  Iterator & operator * () { return *this; }
212  Iterator * operator ->() { return this; }
213 
215  {
216  ++m_Iterator;
217  return *this;
218  }
220  {
221  Iterator tmp( *this );
222  ++(*this);
223  return tmp;
224  }
226  {
227  --m_Iterator;
228  return *this;
229  }
231  {
232  Iterator tmp( *this );
233  --(*this);
234  return tmp;
235  }
236 
237  bool operator==(const Iterator& it) const
238  {
239  return (m_Iterator==it.m_Iterator);
240  }
241  bool operator!=(const Iterator& it) const
242  {
243  return (m_Iterator!=it.m_Iterator);
244  }
245  bool operator==(const ConstIterator& it)const
246  {
247  return (m_Iterator == it.m_Iterator);
248  }
249  bool operator!=(const ConstIterator& it)const
250  {
251  return (m_Iterator != it.m_Iterator);
252  }
254  {
255  return m_Iterator->first;
256  }
257 
258  TermType * GetTerm() const
259  {
260  return m_Iterator->second;
261  }
262  private:
264  friend class ConstIterator;
265  };
266 
267  Iterator Begin();
268  Iterator End();
269 
270  ConstIterator Begin() const;
271  ConstIterator End() const;
272 
273 protected:
275 
276  ~LevelSetEquationTermContainer() override = default;
277 
280 
282 
283  using HashMapStringTermContainerType = itksys::hash_map< std::string, TermPointer >;
284 
286 
289 
291 
292  using MapCFLContainerType = std::map< TermIdType, LevelSetOutputRealType >;
293  using MapCFLContainerIterator = typename MapCFLContainerType::iterator;
294  using MapCFLContainerConstIterator = typename MapCFLContainerType::const_iterator;
295 
297 };
298 
299 }
300 #ifndef ITK_MANUAL_INSTANTIATION
301 #include "itkLevelSetEquationTermContainer.hxx"
302 #endif
303 
304 #endif // itkLevelSetEquationTermContainer_h
bool operator==(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:485
Light weight base class for most itk classes.
Class for container holding the terms of a given level set update equation.
ConstIterator(const MapTermContainerConstIteratorType &it)
typename LevelSetContainerType::InputIndexType LevelSetInputIndexType
CovariantVector< T, NVectorDimension > operator*(const T &scalar, const CovariantVector< T, NVectorDimension > &v)
typename MapCFLContainerType::iterator MapCFLContainerIterator
itksys::hash_map< std::string, TermPointer > HashMapStringTermContainerType
typename MapTermContainerType::iterator MapTermContainerIteratorType
std::map< TermIdType, LevelSetOutputRealType > MapCFLContainerType
typename LevelSetContainerType::LevelSetType LevelSetType
typename LevelSetContainerType::LevelSetDataType LevelSetDataType
itksys::hash_set< std::string > RequiredDataType
Abstract class to represents a term in the level-set evolution PDE.
typename LevelSetContainerType::Pointer LevelSetContainerPointer
bool operator!=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:492
typename LevelSetContainerType::GradientType LevelSetGradientType
typename LevelSetContainerType::OutputRealType LevelSetOutputRealType
typename MapTermContainerType::const_iterator MapTermContainerConstIteratorType
typename MapCFLContainerType::const_iterator MapCFLContainerConstIterator
Container of Level-Sets.
typename TermType::RequiredDataType RequiredDataType
typename InputImageType::Pointer InputImagePointer
typename LevelSetContainerType::HessianType LevelSetHessianType
std::map< TermIdType, TermPointer > MapTermContainerType
typename LevelSetContainerType::LevelSetIdentifierType LevelSetIdentifierType
Base class for most ITK classes.
Definition: itkObject.h:60
typename LevelSetContainerType::LevelSetPointer LevelSetPointer
typename LevelSetContainerType::OutputType LevelSetOutputPixelType