ITK  6.0.0
Insight Toolkit
itkLevelSetEquationTermContainer.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 <atomic>
26 #include <map>
27 #include <string>
28 #include <unordered_map>
29 
30 namespace itk
31 {
41 template <typename TInputImage, typename TLevelSetContainer>
42 class ITK_TEMPLATE_EXPORT LevelSetEquationTermContainer : public Object
43 {
44 public:
45  ITK_DISALLOW_COPY_AND_MOVE(LevelSetEquationTermContainer);
46 
50  using Superclass = Object;
51 
53  itkNewMacro(Self);
54 
56  itkOverrideGetNameOfClassMacro(LevelSetEquationTermContainer);
57 
58  using TermIdType = unsigned int;
59 
60  using InputImageType = TInputImage;
62 
63  using LevelSetContainerType = TLevelSetContainer;
65 
66  using LevelSetType = typename LevelSetContainerType::LevelSetType;
67  using LevelSetPointer = typename LevelSetContainerType::LevelSetPointer;
68 
69  using LevelSetIdentifierType = typename LevelSetContainerType::LevelSetIdentifierType;
70  using LevelSetOutputPixelType = typename LevelSetContainerType::OutputType;
71  using LevelSetOutputRealType = typename LevelSetContainerType::OutputRealType;
72  using LevelSetDataType = typename LevelSetContainerType::LevelSetDataType;
73  using LevelSetInputIndexType = typename LevelSetContainerType::InputIndexType;
74  using LevelSetGradientType = typename LevelSetContainerType::GradientType;
75  using LevelSetHessianType = typename LevelSetContainerType::HessianType;
76 
78  using TermPointer = typename TermType::Pointer;
79 
81  itkSetObjectMacro(Input, InputImageType);
82  itkGetModifiableObjectMacro(Input, InputImageType);
85  itkSetMacro(CurrentLevelSetId, LevelSetIdentifierType);
86  itkGetMacro(CurrentLevelSetId, LevelSetIdentifierType);
87 
88  itkSetObjectMacro(LevelSetContainer, LevelSetContainerType);
89  itkGetModifiableObjectMacro(LevelSetContainer, LevelSetContainerType);
90 
92  void
93  PushTerm(TermType * iTerm);
94 
96  void
97  AddTerm(const TermIdType & iId, TermType * iTerm);
98 
100  TermType *
101  GetTerm(const TermIdType & iId);
102 
104  TermType *
105  GetTerm(const std::string & iName);
106 
108  void
109  Initialize(const LevelSetInputIndexType & iP);
110 
112  void
113  UpdatePixel(const LevelSetInputIndexType & iP,
114  const LevelSetOutputRealType & oldValue,
115  const LevelSetOutputRealType & newValue);
116 
118  void
119  InitializeParameters();
120 
123  Evaluate(const LevelSetInputIndexType & iP);
124 
126  Evaluate(const LevelSetInputIndexType & iP, const LevelSetDataType & iData);
127 
129  void
130  Update();
131 
134  ComputeCFLContribution() const;
135 
136  void
137  ComputeRequiredData(const LevelSetInputIndexType & iP, LevelSetDataType & ioData);
138 
139 protected:
140  using MapTermContainerType = std::map<TermIdType, TermPointer>;
141  using MapTermContainerIteratorType = typename MapTermContainerType::iterator;
142  using MapTermContainerConstIteratorType = typename MapTermContainerType::const_iterator;
143 
144 public:
145  class Iterator;
146  friend class Iterator;
147 
149  {
150  public:
151  ConstIterator() = default;
153  : m_Iterator(it)
154  {}
155  ~ConstIterator() = default;
157  : m_Iterator(it.m_Iterator)
158  {}
159  ConstIterator &
161  {
162  return *this;
163  }
164  ConstIterator *
166  {
167  return this;
168  }
169  ConstIterator &
171  {
172  ++m_Iterator;
173  return *this;
174  }
177  {
178  ConstIterator tmp(*this);
179  ++(*this);
180  return tmp;
181  }
182  ConstIterator &
184  {
185  --m_Iterator;
186  return *this;
187  }
190  {
191  ConstIterator tmp(*this);
192  --(*this);
193  return tmp;
194  }
195  bool
196  operator==(const Iterator & it) const
197  {
198  return (m_Iterator == it.m_Iterator);
199  }
200 
201  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Iterator);
202 
203  bool
204  operator==(const ConstIterator & it) const
205  {
206  return (m_Iterator == it.m_Iterator);
207  }
208 
209  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstIterator);
210 
211  TermIdType
213  {
214  return m_Iterator->first;
215  }
216 
217  TermType *
218  GetTerm() const
219  {
220  return m_Iterator->second;
221  }
222 
223  private:
225  friend class Iterator;
226  };
227 
228  class Iterator
229  {
230  public:
231  Iterator() = default;
233  : m_Iterator(it)
234  {}
236  : m_Iterator(it.m_Iterator)
237  {}
238  ~Iterator() = default;
239 
240  Iterator &
242  {
243  return *this;
244  }
245  Iterator *
247  {
248  return this;
249  }
250 
251  Iterator &
253  {
254  ++m_Iterator;
255  return *this;
256  }
257  Iterator
259  {
260  Iterator tmp(*this);
261  ++(*this);
262  return tmp;
263  }
264  Iterator &
266  {
267  --m_Iterator;
268  return *this;
269  }
270  Iterator
272  {
273  Iterator tmp(*this);
274  --(*this);
275  return tmp;
276  }
277 
278  bool
279  operator==(const Iterator & it) const
280  {
281  return (m_Iterator == it.m_Iterator);
282  }
283 
284  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Iterator);
285 
286  bool
287  operator==(const ConstIterator & it) const
288  {
289  return (m_Iterator == it.m_Iterator);
290  }
291 
292  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstIterator);
293 
294  TermIdType
296  {
297  return m_Iterator->first;
298  }
299 
300  TermType *
301  GetTerm() const
302  {
303  return m_Iterator->second;
304  }
305 
306  private:
308  friend class ConstIterator;
309  };
310 
311  Iterator
312  Begin();
313  Iterator
314  End();
315 
317  Begin() const;
319  End() const;
320 
321 protected:
323 
324  ~LevelSetEquationTermContainer() override = default;
325 
326  LevelSetIdentifierType m_CurrentLevelSetId{};
327  LevelSetContainerPointer m_LevelSetContainer{};
328 
329  InputImagePointer m_Input{};
330 
331  using HashMapStringTermContainerType = std::unordered_map<std::string, TermPointer>;
332 
334 
336  RequiredDataType m_RequiredData{};
337 
338  MapTermContainerType m_Container{};
339 
340  using MapCFLContainerType = std::map<TermIdType, std::atomic<LevelSetOutputRealType>>;
341  using MapCFLContainerIterator = typename MapCFLContainerType::iterator;
342  using MapCFLContainerConstIterator = typename MapCFLContainerType::const_iterator;
343 
344  MapCFLContainerType m_TermContribution{};
345 };
346 
347 } // namespace itk
348 #ifndef ITK_MANUAL_INSTANTIATION
349 # include "itkLevelSetEquationTermContainer.hxx"
350 #endif
351 
352 #endif // itkLevelSetEquationTermContainer_h
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::LevelSetEquationTermContainer::MapCFLContainerType
std::map< TermIdType, std::atomic< LevelSetOutputRealType > > MapCFLContainerType
Definition: itkLevelSetEquationTermContainer.h:340
itk::LevelSetEquationTermBase::RequiredDataType
std::unordered_set< std::string > RequiredDataType
Definition: itkLevelSetEquationTermBase.h:140
itk::LevelSetEquationTermContainer::InputImagePointer
typename InputImageType::Pointer InputImagePointer
Definition: itkLevelSetEquationTermContainer.h:61
itk::LevelSetEquationTermContainer::Iterator::operator--
Iterator & operator--()
Definition: itkLevelSetEquationTermContainer.h:265
itk::LevelSetEquationTermContainer::ConstIterator::m_Iterator
MapTermContainerConstIteratorType m_Iterator
Definition: itkLevelSetEquationTermContainer.h:224
itk::LevelSetEquationTermContainer::ConstIterator::operator==
bool operator==(const Iterator &it) const
Definition: itkLevelSetEquationTermContainer.h:196
itk::LevelSetEquationTermContainer::LevelSetPointer
typename LevelSetContainerType::LevelSetPointer LevelSetPointer
Definition: itkLevelSetEquationTermContainer.h:67
itk::LevelSetEquationTermContainer::Iterator::operator==
bool operator==(const ConstIterator &it) const
Definition: itkLevelSetEquationTermContainer.h:287
itk::LevelSetEquationTermContainer::Iterator::operator++
Iterator & operator++()
Definition: itkLevelSetEquationTermContainer.h:252
itk::LevelSetEquationTermContainer::ConstIterator::ConstIterator
ConstIterator(const MapTermContainerConstIteratorType &it)
Definition: itkLevelSetEquationTermContainer.h:152
itk::LevelSetEquationTermContainer::ConstIterator::operator++
ConstIterator operator++(int)
Definition: itkLevelSetEquationTermContainer.h:176
itk::SmartPointer< Self >
itk::LevelSetEquationTermContainer::LevelSetDataType
typename LevelSetContainerType::LevelSetDataType LevelSetDataType
Definition: itkLevelSetEquationTermContainer.h:72
itk::LevelSetEquationTermContainer::Iterator::Iterator
Iterator(const ConstIterator &it)
Definition: itkLevelSetEquationTermContainer.h:235
itk::LevelSetEquationTermContainer::Iterator::operator->
Iterator * operator->()
Definition: itkLevelSetEquationTermContainer.h:246
itk::LevelSetEquationTermContainer::ConstIterator::operator*
ConstIterator & operator*()
Definition: itkLevelSetEquationTermContainer.h:160
itk::LevelSetEquationTermContainer::LevelSetInputIndexType
typename LevelSetContainerType::InputIndexType LevelSetInputIndexType
Definition: itkLevelSetEquationTermContainer.h:73
itk::LevelSetEquationTermContainer::LevelSetContainerPointer
typename LevelSetContainerType::Pointer LevelSetContainerPointer
Definition: itkLevelSetEquationTermContainer.h:64
itk::LevelSetEquationTermContainer::ConstIterator::operator--
ConstIterator operator--(int)
Definition: itkLevelSetEquationTermContainer.h:189
itk::LevelSetEquationTermContainer::ConstIterator::operator--
ConstIterator & operator--()
Definition: itkLevelSetEquationTermContainer.h:183
itk::LevelSetEquationTermContainer::TermIdType
unsigned int TermIdType
Definition: itkLevelSetEquationTermContainer.h:58
itk::LevelSetEquationTermContainer::ConstIterator::ConstIterator
ConstIterator(const Iterator &it)
Definition: itkLevelSetEquationTermContainer.h:156
itk::LevelSetEquationTermContainer::LevelSetHessianType
typename LevelSetContainerType::HessianType LevelSetHessianType
Definition: itkLevelSetEquationTermContainer.h:75
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::LevelSetEquationTermContainer::LevelSetOutputRealType
typename LevelSetContainerType::OutputRealType LevelSetOutputRealType
Definition: itkLevelSetEquationTermContainer.h:71
itk::LevelSetEquationTermContainer::ConstIterator::operator->
ConstIterator * operator->()
Definition: itkLevelSetEquationTermContainer.h:165
itk::LevelSetEquationTermContainer::Iterator::GetIdentifier
TermIdType GetIdentifier() const
Definition: itkLevelSetEquationTermContainer.h:295
itk::LevelSetEquationTermContainer::MapCFLContainerIterator
typename MapCFLContainerType::iterator MapCFLContainerIterator
Definition: itkLevelSetEquationTermContainer.h:341
itk::LevelSetEquationTermContainer::Iterator::operator*
Iterator & operator*()
Definition: itkLevelSetEquationTermContainer.h:241
itk::LevelSetEquationTermContainer::HashMapStringTermContainerType
std::unordered_map< std::string, TermPointer > HashMapStringTermContainerType
Definition: itkLevelSetEquationTermContainer.h:331
itk::LevelSetEquationTermContainer::ConstIterator::GetTerm
TermType * GetTerm() const
Definition: itkLevelSetEquationTermContainer.h:218
itk::LevelSetEquationTermContainer::ConstIterator::GetIdentifier
TermIdType GetIdentifier() const
Definition: itkLevelSetEquationTermContainer.h:212
itk::LevelSetEquationTermContainer::InputImageType
TInputImage InputImageType
Definition: itkLevelSetEquationTermContainer.h:60
itk::LevelSetEquationTermContainer::LevelSetGradientType
typename LevelSetContainerType::GradientType LevelSetGradientType
Definition: itkLevelSetEquationTermContainer.h:74
itk::LevelSetEquationTermContainer::Iterator
Definition: itkLevelSetEquationTermContainer.h:228
itk::LevelSetEquationTermContainer::LevelSetContainerType
TLevelSetContainer LevelSetContainerType
Definition: itkLevelSetEquationTermContainer.h:63
itk::LevelSetEquationTermContainer::Iterator::Iterator
Iterator(const MapTermContainerIteratorType &it)
Definition: itkLevelSetEquationTermContainer.h:232
itk::LevelSetEquationTermContainer::MapCFLContainerConstIterator
typename MapCFLContainerType::const_iterator MapCFLContainerConstIterator
Definition: itkLevelSetEquationTermContainer.h:342
itk::LevelSetEquationTermContainer::MapTermContainerConstIteratorType
typename MapTermContainerType::const_iterator MapTermContainerConstIteratorType
Definition: itkLevelSetEquationTermContainer.h:142
itk::LevelSetContainer
Container of Level-Sets.
Definition: itkLevelSetContainer.h:39
itk::LevelSetEquationTermContainer::LevelSetOutputPixelType
typename LevelSetContainerType::OutputType LevelSetOutputPixelType
Definition: itkLevelSetEquationTermContainer.h:70
itk::LevelSetEquationTermContainer::ConstIterator::operator==
bool operator==(const ConstIterator &it) const
Definition: itkLevelSetEquationTermContainer.h:204
itkObject.h
itk::LevelSetEquationTermBase
Abstract class to represents a term in the level-set evolution PDE.
Definition: itkLevelSetEquationTermBase.h:49
itk::LevelSetEquationTermContainer::Iterator::operator--
Iterator operator--(int)
Definition: itkLevelSetEquationTermContainer.h:271
itk::LevelSetEquationTermContainer::LevelSetIdentifierType
typename LevelSetContainerType::LevelSetIdentifierType LevelSetIdentifierType
Definition: itkLevelSetEquationTermContainer.h:69
itk::LevelSetEquationTermContainer::Iterator::GetTerm
TermType * GetTerm() const
Definition: itkLevelSetEquationTermContainer.h:301
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::LevelSetEquationTermContainer::ConstIterator
Definition: itkLevelSetEquationTermContainer.h:148
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::LevelSetEquationTermContainer::Iterator::operator++
Iterator operator++(int)
Definition: itkLevelSetEquationTermContainer.h:258
itk::LevelSetEquationTermContainer::TermPointer
typename TermType::Pointer TermPointer
Definition: itkLevelSetEquationTermContainer.h:78
itk::LevelSetEquationTermContainer::Iterator::m_Iterator
MapTermContainerIteratorType m_Iterator
Definition: itkLevelSetEquationTermContainer.h:307
itkLevelSetEquationTermBase.h
itk::LevelSetEquationTermContainer::RequiredDataType
typename TermType::RequiredDataType RequiredDataType
Definition: itkLevelSetEquationTermContainer.h:335
itk::LevelSetEquationTermContainer::MapTermContainerIteratorType
typename MapTermContainerType::iterator MapTermContainerIteratorType
Definition: itkLevelSetEquationTermContainer.h:141
itk::LevelSetEquationTermContainer::MapTermContainerType
std::map< TermIdType, TermPointer > MapTermContainerType
Definition: itkLevelSetEquationTermContainer.h:140
itk::LevelSetEquationTermContainer::Iterator::operator==
bool operator==(const Iterator &it) const
Definition: itkLevelSetEquationTermContainer.h:279
itk::LevelSetEquationTermContainer
Class for container holding the terms of a given level set update equation.
Definition: itkLevelSetEquationTermContainer.h:42
itk::LevelSetEquationTermContainer::LevelSetType
typename LevelSetContainerType::LevelSetType LevelSetType
Definition: itkLevelSetEquationTermContainer.h:66
itk::LevelSetEquationTermContainer::ConstIterator::operator++
ConstIterator & operator++()
Definition: itkLevelSetEquationTermContainer.h:170