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 {}
159 ConstIterator & operator*() { return *this; }
160 ConstIterator * operator->() { return this; }
163 {
164 ++m_Iterator;
165 return *this;
166 }
169 {
170 ConstIterator tmp(*this);
171 ++(*this);
172 return tmp;
173 }
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
194
195 bool
196 operator==(const ConstIterator & it) const
197 {
198 return (m_Iterator == it.m_Iterator);
199 }
200
202
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
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 }
243 {
244 Iterator tmp(*this);
245 ++(*this);
246 return tmp;
247 }
248 Iterator &
250 {
251 --m_Iterator;
252 return *this;
253 }
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
269
270 bool
271 operator==(const ConstIterator & it) const
272 {
273 return (m_Iterator == it.m_Iterator);
274 }
275
277
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
299
301 Begin() const;
303 End() const;
304
305protected:
307
308 ~LevelSetEquationTermContainer() override = default;
309
310 LevelSetIdentifierType m_CurrentLevelSetId{};
311 LevelSetContainerPointer m_LevelSetContainer{};
312
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
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....