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
30namespace itk
31{
41template <typename TInputImage, typename TLevelSetContainer>
42class ITK_TEMPLATE_EXPORT LevelSetEquationTermContainer : public Object
43{
44public:
45 ITK_DISALLOW_COPY_AND_MOVE(LevelSetEquationTermContainer);
46
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
79
81 itkSetObjectMacro(Input, InputImageType);
82 itkGetModifiableObjectMacro(Input, InputImageType);
85 itkSetMacro(CurrentLevelSetId, LevelSetIdentifierType);
86 itkGetMacro(CurrentLevelSetId, LevelSetIdentifierType);
87
89 itkGetModifiableObjectMacro(LevelSetContainer, LevelSetContainerType);
90
92 void
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
110
112 void
114 const LevelSetOutputRealType & oldValue,
115 const LevelSetOutputRealType & newValue);
116
118 void
120
124
127
129 void
131
135
136 void
138
139protected:
140 using MapTermContainerType = std::map<TermIdType, TermPointer>;
141 using MapTermContainerIteratorType = typename MapTermContainerType::iterator;
142 using MapTermContainerConstIteratorType = typename MapTermContainerType::const_iterator;
143
144public:
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 {}
161 {
162 return *this;
163 }
166 {
167 return this;
168 }
171 {
172 ++m_Iterator;
173 return *this;
174 }
177 {
178 ConstIterator tmp(*this);
179 ++(*this);
180 return tmp;
181 }
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
202
203 bool
204 operator==(const ConstIterator & it) const
205 {
206 return (m_Iterator == it.m_Iterator);
207 }
208
210
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
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 }
259 {
260 Iterator tmp(*this);
261 ++(*this);
262 return tmp;
263 }
264 Iterator &
266 {
267 --m_Iterator;
268 return *this;
269 }
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
285
286 bool
287 operator==(const ConstIterator & it) const
288 {
289 return (m_Iterator == it.m_Iterator);
290 }
291
293
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
315
317 Begin() const;
319 End() const;
320
321protected:
323
324 ~LevelSetEquationTermContainer() override = default;
325
326 LevelSetIdentifierType m_CurrentLevelSetId{};
327 LevelSetContainerPointer m_LevelSetContainer{};
328
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
Container of Level-Sets.
Abstract class to represents a term in the level-set evolution PDE.
std::unordered_set< std::string > RequiredDataType
ConstIterator(const MapTermContainerConstIteratorType &it)
Class for container holding the terms of a given level set update equation.
std::unordered_map< std::string, TermPointer > HashMapStringTermContainerType
typename InputImageType::Pointer InputImagePointer
TermType * GetTerm(const TermIdType &iId)
typename LevelSetContainerType::LevelSetIdentifierType LevelSetIdentifierType
void ComputeRequiredData(const LevelSetInputIndexType &iP, LevelSetDataType &ioData)
TermType * GetTerm(const std::string &iName)
typename LevelSetContainerType::OutputRealType LevelSetOutputRealType
typename LevelSetContainerType::OutputType LevelSetOutputPixelType
typename LevelSetContainerType::LevelSetPointer LevelSetPointer
typename MapTermContainerType::const_iterator MapTermContainerConstIteratorType
typename TermType::RequiredDataType RequiredDataType
LevelSetOutputRealType ComputeCFLContribution() const
typename LevelSetContainerType::LevelSetType LevelSetType
typename LevelSetContainerType::GradientType LevelSetGradientType
typename MapCFLContainerType::iterator MapCFLContainerIterator
LevelSetOutputRealType Evaluate(const LevelSetInputIndexType &iP)
LevelSetOutputRealType Evaluate(const LevelSetInputIndexType &iP, const LevelSetDataType &iData)
typename MapTermContainerType::iterator MapTermContainerIteratorType
void AddTerm(const TermIdType &iId, TermType *iTerm)
std::map< TermIdType, TermPointer > MapTermContainerType
typename LevelSetContainerType::HessianType LevelSetHessianType
void UpdatePixel(const LevelSetInputIndexType &iP, const LevelSetOutputRealType &oldValue, const LevelSetOutputRealType &newValue)
void PushTerm(TermType *iTerm)
std::map< TermIdType, std::atomic< LevelSetOutputRealType > > MapCFLContainerType
typename LevelSetContainerType::Pointer LevelSetContainerPointer
~LevelSetEquationTermContainer() override=default
typename MapCFLContainerType::const_iterator MapCFLContainerConstIterator
typename LevelSetContainerType::LevelSetDataType LevelSetDataType
typename LevelSetContainerType::InputIndexType LevelSetInputIndexType
void Initialize(const LevelSetInputIndexType &iP)
Light weight base class for most itk classes.
Base class for most ITK classes.
Definition: itkObject.h:62
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....