ITK  5.3.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 
26 namespace itk
27 {
33 {
34 public:
39  enum class TargetCondition : uint8_t
40  {
41  OneTarget = 1,
44  };
45 };
46 // Define how to print enumeration
47 extern ITKFastMarching_EXPORT std::ostream &
49 
59 template <typename TInput, typename TOutput>
61  : public FastMarchingStoppingCriterionBase<TInput, TOutput>
62 {
63 public:
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  itkTypeMacro(FastMarchingReachedTargetNodesStoppingCriterion, FastMarchingStoppingCriterionBase);
77 
78  using typename Superclass::OutputPixelType;
79  using typename Superclass::NodeType;
80 
82 #if !defined(ITK_LEGACY_REMOVE)
83 
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
109  SetNumberOfTargetsToBeReached(const size_t & iN)
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 
179 protected:
182  : Superclass()
183  , m_TargetOffset(NumericTraits<OutputPixelType>::ZeroValue())
184  , m_StoppingValue(NumericTraits<OutputPixelType>::ZeroValue())
185  {}
186 
189 
190  TargetConditionEnum m_TargetCondition{ TargetConditionEnum::AllTargets };
191  std::vector<NodeType> m_TargetNodes;
192  std::vector<NodeType> m_ReachedTargetNodes;
193  size_t m_NumberOfTargetsToBeReached{ 0 };
194  OutputPixelType m_TargetOffset;
195  OutputPixelType m_StoppingValue;
196  bool m_Satisfied{ false };
197  bool m_Initialized{ false };
198 
199  void
200  Reset() override
201  {
202  this->Initialize();
203  }
204 
205  void
207  {
208  if (m_TargetCondition == TargetConditionEnum::OneTarget)
209  {
210  m_NumberOfTargetsToBeReached = 1;
211  }
212  if (m_TargetCondition == TargetConditionEnum::AllTargets)
213  {
214  m_NumberOfTargetsToBeReached = m_TargetNodes.size();
215  }
216  if (m_NumberOfTargetsToBeReached < 1)
217  {
218  itkExceptionMacro(<< "Number of target nodes to be reached is null");
219  }
220  if (m_NumberOfTargetsToBeReached > m_TargetNodes.size())
221  {
222  itkExceptionMacro(
223  << "Number of target nodes to be reached is above the provided number of target nodes");
224  }
225  m_ReachedTargetNodes.clear();
226 
227  m_Satisfied = false;
228  m_Initialized = true;
229  }
230 };
231 } // namespace itk
232 #endif // itkFastMarchingThresholdStoppingCriterion_h
itk::FastMarchingReachedTargetNodesStoppingCriterion::IsSatisfied
bool IsSatisfied() const override
returns if the stopping condition is satisfied or not.
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:167
itkObjectFactory.h
itk::FastMarchingReachedTargetNodesStoppingCriterion::m_TargetOffset
OutputPixelType m_TargetOffset
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:194
itk::FastMarchingReachedTargetNodesStoppingCriterionEnums::TargetCondition::OneTarget
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:216
itk::FastMarchingReachedTargetNodesStoppingCriterionEnums::TargetCondition::SomeTargets
itk::SmartPointer< Self >
itk::FastMarchingReachedTargetNodesStoppingCriterion::FastMarchingReachedTargetNodesStoppingCriterion
FastMarchingReachedTargetNodesStoppingCriterion()
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:181
itk::FastMarchingReachedTargetNodesStoppingCriterion::Initialize
void Initialize()
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:206
itk::FastMarchingReachedTargetNodesStoppingCriterion::m_ReachedTargetNodes
std::vector< NodeType > m_ReachedTargetNodes
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:192
itk::FastMarchingReachedTargetNodesStoppingCriterion::Reset
void Reset() override
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:200
itk::FastMarchingReachedTargetNodesStoppingCriterion::SetCurrentNode
void SetCurrentNode(const NodeType &iNode) override
Set the current node.
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:127
TargetCondition
itk::FastMarchingReachedTargetNodesStoppingCriterion::Superclass
FastMarchingStoppingCriterionBase< TInput, TOutput > Superclass
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:67
itk::FastMarchingReachedTargetNodesStoppingCriterion::m_TargetNodes
std::vector< NodeType > m_TargetNodes
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:191
itk::FastMarchingReachedTargetNodesStoppingCriterionEnums::TargetCondition
TargetCondition
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:39
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::FastMarchingReachedTargetNodesStoppingCriterion::SetNumberOfTargetsToBeReached
void SetNumberOfTargetsToBeReached(const vcl_size_t &iN)
Set the number of target nodes to be reached.
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:109
itk::FastMarchingReachedTargetNodesStoppingCriterionEnums::TargetCondition::AllTargets
itk::FastMarchingReachedTargetNodesStoppingCriterion::GetDescription
std::string GetDescription() const override
Get a short description of the stopping criterion.
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:174
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::FastMarchingReachedTargetNodesStoppingCriterion
Stopping criterion for FastMarchingFilterBase.
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:60
itkFastMarchingStoppingCriterionBase.h
itk::FastMarchingReachedTargetNodesStoppingCriterionEnums
Contains all enum classes used by FastMarchingReachedTargetNodesStoppingCriterion class.
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:32
itk::FastMarchingReachedTargetNodesStoppingCriterion::SetTargetNodes
virtual void SetTargetNodes(const std::vector< NodeType > &iNodes)
Set Target Nodes.
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:118
itk::FastMarchingReachedTargetNodesStoppingCriterion::SetTargetCondition
void SetTargetCondition(const TargetConditionEnum &iCondition)
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:92
itk::FastMarchingReachedTargetNodesStoppingCriterion::m_StoppingValue
OutputPixelType m_StoppingValue
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:195