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 & operator*() { return *this; }
160  ConstIterator * operator->() { return this; }
161  ConstIterator &
163  {
164  ++m_Iterator;
165  return *this;
166  }
169  {
170  ConstIterator tmp(*this);
171  ++(*this);
172  return tmp;
173  }
174  ConstIterator &
176  {
177  --m_Iterator;
178  return *this;
179  }
182  {
183  ConstIterator tmp(*this);
184  --(*this);
185  return tmp;
186  }
187  bool
188  operator==(const Iterator & it) const
189  {
190  return (m_Iterator == it.m_Iterator);
191  }
192 
193  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Iterator);
194 
195  bool
196  operator==(const ConstIterator & it) const
197  {
198  return (m_Iterator == it.m_Iterator);
199  }
200 
201  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstIterator);
202 
203  TermIdType
205  {
206  return m_Iterator->first;
207  }
208 
209  TermType *
210  GetTerm() const
211  {
212  return m_Iterator->second;
213  }
214 
215  private:
217  friend class Iterator;
218  };
219 
220  class Iterator
221  {
222  public:
223  Iterator() = default;
225  : m_Iterator(it)
226  {}
228  : m_Iterator(it.m_Iterator)
229  {}
230  ~Iterator() = default;
231 
232  Iterator & operator*() { return *this; }
233  Iterator * operator->() { return this; }
234 
235  Iterator &
237  {
238  ++m_Iterator;
239  return *this;
240  }
241  Iterator
243  {
244  Iterator tmp(*this);
245  ++(*this);
246  return tmp;
247  }
248  Iterator &
250  {
251  --m_Iterator;
252  return *this;
253  }
254  Iterator
256  {
257  Iterator tmp(*this);
258  --(*this);
259  return tmp;
260  }
261 
262  bool
263  operator==(const Iterator & it) const
264  {
265  return (m_Iterator == it.m_Iterator);
266  }
267 
268  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Iterator);
269 
270  bool
271  operator==(const ConstIterator & it) const
272  {
273  return (m_Iterator == it.m_Iterator);
274  }
275 
276  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstIterator);
277 
278  TermIdType
280  {
281  return m_Iterator->first;
282  }
283 
284  TermType *
285  GetTerm() const
286  {
287  return m_Iterator->second;
288  }
289 
290  private:
292  friend class ConstIterator;
293  };
294 
295  Iterator
296  Begin();
297  Iterator
298  End();
299 
301  Begin() const;
303  End() const;
304 
305 protected:
307 
308  ~LevelSetEquationTermContainer() override = default;
309 
310  LevelSetIdentifierType m_CurrentLevelSetId{};
311  LevelSetContainerPointer m_LevelSetContainer{};
312 
313  InputImagePointer m_Input{};
314 
315  using HashMapStringTermContainerType = std::unordered_map<std::string, TermPointer>;
316 
318 
320  RequiredDataType m_RequiredData{};
321 
322  MapTermContainerType m_Container{};
323 
324  using MapCFLContainerType = std::map<TermIdType, std::atomic<LevelSetOutputRealType>>;
325  using MapCFLContainerIterator = typename MapCFLContainerType::iterator;
326  using MapCFLContainerConstIterator = typename MapCFLContainerType::const_iterator;
327 
328  MapCFLContainerType m_TermContribution{};
329 };
330 
331 } // namespace itk
332 #ifndef ITK_MANUAL_INSTANTIATION
333 # include "itkLevelSetEquationTermContainer.hxx"
334 #endif
335 
336 #endif // itkLevelSetEquationTermContainer_h
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::LevelSetEquationTermContainer::MapCFLContainerType
std::map< TermIdType, std::atomic< LevelSetOutputRealType > > MapCFLContainerType
Definition: itkLevelSetEquationTermContainer.h:324
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:249
itk::LevelSetEquationTermContainer::ConstIterator::m_Iterator
MapTermContainerConstIteratorType m_Iterator
Definition: itkLevelSetEquationTermContainer.h:216
itk::LevelSetEquationTermContainer::ConstIterator::operator==
bool operator==(const Iterator &it) const
Definition: itkLevelSetEquationTermContainer.h:188
itk::LevelSetEquationTermContainer::LevelSetPointer
typename LevelSetContainerType::LevelSetPointer LevelSetPointer
Definition: itkLevelSetEquationTermContainer.h:67
itk::LevelSetEquationTermContainer::Iterator::operator==
bool operator==(const ConstIterator &it) const
Definition: itkLevelSetEquationTermContainer.h:271
itk::LevelSetEquationTermContainer::Iterator::operator++
Iterator & operator++()
Definition: itkLevelSetEquationTermContainer.h:236
itk::LevelSetEquationTermContainer::ConstIterator::ConstIterator
ConstIterator(const MapTermContainerConstIteratorType &it)
Definition: itkLevelSetEquationTermContainer.h:152
itk::LevelSetEquationTermContainer::ConstIterator::operator++
ConstIterator operator++(int)
Definition: itkLevelSetEquationTermContainer.h:168
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:227
itk::LevelSetEquationTermContainer::Iterator::operator->
Iterator * operator->()
Definition: itkLevelSetEquationTermContainer.h:233
itk::LevelSetEquationTermContainer::ConstIterator::operator*
ConstIterator & operator*()
Definition: itkLevelSetEquationTermContainer.h:159
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:181
itk::LevelSetEquationTermContainer::ConstIterator::operator--
ConstIterator & operator--()
Definition: itkLevelSetEquationTermContainer.h:175
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:160
itk::LevelSetEquationTermContainer::Iterator::GetIdentifier
TermIdType GetIdentifier() const
Definition: itkLevelSetEquationTermContainer.h:279
itk::LevelSetEquationTermContainer::MapCFLContainerIterator
typename MapCFLContainerType::iterator MapCFLContainerIterator
Definition: itkLevelSetEquationTermContainer.h:325
itk::LevelSetEquationTermContainer::Iterator::operator*
Iterator & operator*()
Definition: itkLevelSetEquationTermContainer.h:232
itk::LevelSetEquationTermContainer::HashMapStringTermContainerType
std::unordered_map< std::string, TermPointer > HashMapStringTermContainerType
Definition: itkLevelSetEquationTermContainer.h:315
itk::LevelSetEquationTermContainer::ConstIterator::GetTerm
TermType * GetTerm() const
Definition: itkLevelSetEquationTermContainer.h:210
itk::LevelSetEquationTermContainer::ConstIterator::GetIdentifier
TermIdType GetIdentifier() const
Definition: itkLevelSetEquationTermContainer.h:204
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:220
itk::LevelSetEquationTermContainer::LevelSetContainerType
TLevelSetContainer LevelSetContainerType
Definition: itkLevelSetEquationTermContainer.h:63
itk::LevelSetEquationTermContainer::Iterator::Iterator
Iterator(const MapTermContainerIteratorType &it)
Definition: itkLevelSetEquationTermContainer.h:224
itk::LevelSetEquationTermContainer::MapCFLContainerConstIterator
typename MapCFLContainerType::const_iterator MapCFLContainerConstIterator
Definition: itkLevelSetEquationTermContainer.h:326
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:196
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:255
itk::LevelSetEquationTermContainer::LevelSetIdentifierType
typename LevelSetContainerType::LevelSetIdentifierType LevelSetIdentifierType
Definition: itkLevelSetEquationTermContainer.h:69
itk::LevelSetEquationTermContainer::Iterator::GetTerm
TermType * GetTerm() const
Definition: itkLevelSetEquationTermContainer.h:285
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
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:242
itk::LevelSetEquationTermContainer::TermPointer
typename TermType::Pointer TermPointer
Definition: itkLevelSetEquationTermContainer.h:78
itk::LevelSetEquationTermContainer::Iterator::m_Iterator
MapTermContainerIteratorType m_Iterator
Definition: itkLevelSetEquationTermContainer.h:291
itkLevelSetEquationTermBase.h
itk::LevelSetEquationTermContainer::RequiredDataType
typename TermType::RequiredDataType RequiredDataType
Definition: itkLevelSetEquationTermContainer.h:319
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:263
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:162