ITK  6.0.0
Insight Toolkit
itkFastMarchingReachedTargetNodesStoppingCriterion.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 itkFastMarchingReachedTargetNodesStoppingCriterion_h
20#define itkFastMarchingReachedTargetNodesStoppingCriterion_h
21
23#include "itkObjectFactory.h"
24#include "ITKFastMarchingExport.h"
25
26namespace itk
27{
33{
34public:
39 enum class TargetCondition : uint8_t
40 {
41 OneTarget = 1,
42 SomeTargets,
43 AllTargets
44 };
45};
46// Define how to print enumeration
47extern ITKFastMarching_EXPORT std::ostream &
49
59template <typename TInput, typename TOutput>
61 : public FastMarchingStoppingCriterionBase<TInput, TOutput>
62{
63public:
64 ITK_DISALLOW_COPY_AND_MOVE(FastMarchingReachedTargetNodesStoppingCriterion);
65
67 using Superclass = FastMarchingStoppingCriterionBase<TInput, TOutput>;
70 using typename Superclass::Traits;
71
73 itkNewMacro(Self);
74
76 itkOverrideGetNameOfClassMacro(FastMarchingReachedTargetNodesStoppingCriterion);
77
78 using typename Superclass::OutputPixelType;
79 using typename Superclass::NodeType;
80
82#if !defined(ITK_LEGACY_REMOVE)
84 static constexpr TargetConditionEnum OneTarget = TargetConditionEnum::OneTarget;
85 static constexpr TargetConditionEnum SomeTargets = TargetConditionEnum::SomeTargets;
86 static constexpr TargetConditionEnum AllTargets = TargetConditionEnum::AllTargets;
87#endif
88
91 void
93 {
94 m_TargetCondition = iCondition;
95 m_Initialized = false;
96 this->Modified();
97 }
100 itkGetConstReferenceMacro(TargetCondition, TargetConditionEnum);
101
103 itkSetMacro(TargetOffset, OutputPixelType);
104 itkGetMacro(TargetOffset, OutputPixelType);
108 void
110 {
111 m_NumberOfTargetsToBeReached = iN;
112 m_Initialized = false;
113 this->Modified();
114 }
115
117 virtual void
118 SetTargetNodes(const std::vector<NodeType> & iNodes)
119 {
120 m_TargetNodes = iNodes;
121 m_Initialized = false;
122 this->Modified();
123 }
124
126 void
127 SetCurrentNode(const NodeType & iNode) override
128 {
129 if (!m_Initialized)
130 {
131 Initialize();
132 }
133
134 if (!m_Satisfied)
135 {
136 // Only check for reached targets if the mode is not NoTargets and
137 // there is at least one TargetPoint.
138 if (!m_TargetNodes.empty())
139 {
140 typename std::vector<NodeType>::const_iterator pointsIter = m_TargetNodes.begin();
141 typename std::vector<NodeType>::const_iterator pointsEnd = m_TargetNodes.end();
142
143 while (pointsIter != pointsEnd)
144 {
145 if (*pointsIter == iNode)
146 {
147 this->m_ReachedTargetNodes.push_back(iNode);
148 m_Satisfied = (m_ReachedTargetNodes.size() == m_NumberOfTargetsToBeReached);
149 break;
150 }
151 ++pointsIter;
152 }
153 if (m_Satisfied)
154 {
155 m_StoppingValue = this->m_CurrentValue + m_TargetOffset;
156 }
157 }
158 else
159 {
160 m_Satisfied = false;
161 }
162 }
163 }
164
166 bool
167 IsSatisfied() const override
168 {
169 return m_Satisfied && (this->m_CurrentValue >= m_StoppingValue);
170 }
171
173 std::string
174 GetDescription() const override
175 {
176 return "Target Nodes Reached with possible overshoot";
177 }
178
179protected:
182 : Superclass()
183 , m_TargetOffset(OutputPixelType{})
184 , m_StoppingValue(OutputPixelType{})
185 {}
190
191 TargetConditionEnum m_TargetCondition{ TargetConditionEnum::AllTargets };
192 std::vector<NodeType> m_TargetNodes{};
193 std::vector<NodeType> m_ReachedTargetNodes{};
194 size_t m_NumberOfTargetsToBeReached{ 0 };
195 OutputPixelType m_TargetOffset{};
196 OutputPixelType m_StoppingValue{};
197 bool m_Satisfied{ false };
198 bool m_Initialized{ false };
199
200 void
201 Reset() override
202 {
203 this->Initialize();
204 }
205
206 void
208 {
209 if (m_TargetCondition == TargetConditionEnum::OneTarget)
210 {
211 m_NumberOfTargetsToBeReached = 1;
212 }
213 if (m_TargetCondition == TargetConditionEnum::AllTargets)
214 {
215 m_NumberOfTargetsToBeReached = m_TargetNodes.size();
216 }
217 if (m_NumberOfTargetsToBeReached < 1)
218 {
219 itkExceptionMacro("Number of target nodes to be reached is null");
220 }
221 if (m_NumberOfTargetsToBeReached > m_TargetNodes.size())
222 {
223 itkExceptionMacro(
224 << "Number of target nodes to be reached is above the provided number of target nodes");
225 }
226 m_ReachedTargetNodes.clear();
227
228 m_Satisfied = false;
229 m_Initialized = true;
230 }
231};
232} // namespace itk
233#endif // itkFastMarchingThresholdStoppingCriterion_h
Contains all enum classes used by FastMarchingReachedTargetNodesStoppingCriterion class.
void SetNumberOfTargetsToBeReached(const vcl_size_t &iN)
Set the number of target nodes to be reached.
bool IsSatisfied() const override
returns if the stopping condition is satisfied or not.
virtual void SetTargetNodes(const std::vector< NodeType > &iNodes)
Set Target Nodes.
void SetCurrentNode(const NodeType &iNode) override
Set the current node.
std::string GetDescription() const override
Get a short description of the stopping criterion.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:216