ITK  5.2.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  * http://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>
60 class FastMarchingReachedTargetNodesStoppingCriterion : public FastMarchingStoppingCriterionBase<TInput, TOutput>
61 {
62 public:
63  ITK_DISALLOW_COPY_AND_MOVE(FastMarchingReachedTargetNodesStoppingCriterion);
64 
66  using Superclass = FastMarchingStoppingCriterionBase<TInput, TOutput>;
69  using Traits = typename Superclass::Traits;
70 
72  itkNewMacro(Self);
73 
75  itkTypeMacro(FastMarchingReachedTargetNodesStoppingCriterion, FastMarchingStoppingCriterionBase);
76 
77  using OutputPixelType = typename Superclass::OutputPixelType;
78  using NodeType = typename Superclass::NodeType;
79 
81 #if !defined(ITK_LEGACY_REMOVE)
82 
83  static constexpr TargetConditionEnum OneTarget = TargetConditionEnum::OneTarget;
84  static constexpr TargetConditionEnum SomeTargets = TargetConditionEnum::SomeTargets;
85  static constexpr TargetConditionEnum AllTargets = TargetConditionEnum::AllTargets;
86 #endif
87 
90  void
92  {
93  m_TargetCondition = iCondition;
94  m_Initialized = false;
95  this->Modified();
96  }
98 
99  itkGetConstReferenceMacro(TargetCondition, TargetConditionEnum);
100 
102  itkSetMacro(TargetOffset, OutputPixelType);
103  itkGetMacro(TargetOffset, OutputPixelType);
105 
107  void
108  SetNumberOfTargetsToBeReached(const size_t & iN)
109  {
111  m_Initialized = false;
112  this->Modified();
113  }
114 
116  virtual void
117  SetTargetNodes(const std::vector<NodeType> & iNodes)
118  {
119  m_TargetNodes = iNodes;
120  m_Initialized = false;
121  this->Modified();
122  }
123 
125  void
126  SetCurrentNode(const NodeType & iNode) override
127  {
128  if (!m_Initialized)
129  {
130  Initialize();
131  }
132 
133  if (!m_Satisfied)
134  {
135  // Only check for reached targets if the mode is not NoTargets and
136  // there is at least one TargetPoint.
137  if (!m_TargetNodes.empty())
138  {
139  typename std::vector<NodeType>::const_iterator pointsIter = m_TargetNodes.begin();
140  typename std::vector<NodeType>::const_iterator pointsEnd = m_TargetNodes.end();
141 
142  while (pointsIter != pointsEnd)
143  {
144  if (*pointsIter == iNode)
145  {
146  this->m_ReachedTargetNodes.push_back(iNode);
148  break;
149  }
150  ++pointsIter;
151  }
152  if (m_Satisfied)
153  {
154  m_StoppingValue = this->m_CurrentValue + m_TargetOffset;
155  }
156  }
157  else
158  {
159  m_Satisfied = false;
160  }
161  }
162  }
163 
165  bool
166  IsSatisfied() const override
167  {
168  return m_Satisfied && (this->m_CurrentValue >= m_StoppingValue);
169  }
170 
172  std::string
173  GetDescription() const override
174  {
175  return "Target Nodes Reached with possible overshoot";
176  }
177 
178 protected:
181  : Superclass()
184  {}
185 
188 
190  std::vector<NodeType> m_TargetNodes;
191  std::vector<NodeType> m_ReachedTargetNodes;
195  bool m_Satisfied{ false };
196  bool m_Initialized{ false };
197 
198  void
199  Reset() override
200  {
201  this->Initialize();
202  }
203 
204  void
206  {
208  {
210  }
212  {
213  m_NumberOfTargetsToBeReached = m_TargetNodes.size();
214  }
216  {
217  itkExceptionMacro(<< "Number of target nodes to be reached is null");
218  }
220  {
221  itkExceptionMacro(
222  << "Number of target nodes to be reached is above the provided number of target nodes");
223  }
224  m_ReachedTargetNodes.clear();
225 
226  m_Satisfied = false;
227  m_Initialized = true;
228  }
229 };
230 } // namespace itk
231 #endif // itkFastMarchingThresholdStoppingCriterion_h
itk::FastMarchingReachedTargetNodesStoppingCriterion::IsSatisfied
bool IsSatisfied() const override
returns if the stopping condition is satisfied or not.
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:166
itk::uint8_t
::uint8_t uint8_t
Definition: itkIntTypes.h:29
itkObjectFactory.h
itk::FastMarchingReachedTargetNodesStoppingCriterion::m_Initialized
bool m_Initialized
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:196
itk::FastMarchingReachedTargetNodesStoppingCriterion::m_TargetOffset
OutputPixelType m_TargetOffset
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:193
itk::FastMarchingReachedTargetNodesStoppingCriterionEnums::TargetCondition::OneTarget
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:218
itk::FastMarchingReachedTargetNodesStoppingCriterionEnums::TargetCondition::SomeTargets
itk::SmartPointer< Self >
itk::FastMarchingReachedTargetNodesStoppingCriterion::~FastMarchingReachedTargetNodesStoppingCriterion
~FastMarchingReachedTargetNodesStoppingCriterion() override=default
itk::FastMarchingReachedTargetNodesStoppingCriterion::m_Satisfied
bool m_Satisfied
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:195
itk::FastMarchingReachedTargetNodesStoppingCriterion::FastMarchingReachedTargetNodesStoppingCriterion
FastMarchingReachedTargetNodesStoppingCriterion()
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:180
itk::FastMarchingReachedTargetNodesStoppingCriterion::Initialize
void Initialize()
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:205
itk::FastMarchingReachedTargetNodesStoppingCriterion::m_ReachedTargetNodes
std::vector< NodeType > m_ReachedTargetNodes
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:191
itk::FastMarchingReachedTargetNodesStoppingCriterion::Reset
void Reset() override
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:199
itk::FastMarchingReachedTargetNodesStoppingCriterion::SetCurrentNode
void SetCurrentNode(const NodeType &iNode) override
Set the current node.
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:126
itk::FastMarchingReachedTargetNodesStoppingCriterion::OutputPixelType
typename Superclass::OutputPixelType OutputPixelType
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:77
TargetCondition
itk::FastMarchingReachedTargetNodesStoppingCriterion::Superclass
FastMarchingStoppingCriterionBase< TInput, TOutput > Superclass
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:66
itk::FastMarchingReachedTargetNodesStoppingCriterion::m_TargetNodes
std::vector< NodeType > m_TargetNodes
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:190
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::m_TargetCondition
TargetConditionEnum m_TargetCondition
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:189
itk::FastMarchingReachedTargetNodesStoppingCriterion::SetNumberOfTargetsToBeReached
void SetNumberOfTargetsToBeReached(const vcl_size_t &iN)
Set the number of target nodes to be reached.
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:108
itk::FastMarchingReachedTargetNodesStoppingCriterionEnums::TargetCondition::AllTargets
itk::FastMarchingReachedTargetNodesStoppingCriterion::GetDescription
std::string GetDescription() const override
Get a short description of the stopping criterion.
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:173
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::TargetConditionEnum
FastMarchingReachedTargetNodesStoppingCriterionEnums::TargetCondition TargetConditionEnum
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:80
itk::FastMarchingReachedTargetNodesStoppingCriterion::SetTargetNodes
virtual void SetTargetNodes(const std::vector< NodeType > &iNodes)
Set Target Nodes.
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:117
itk::FastMarchingReachedTargetNodesStoppingCriterion::SetTargetCondition
void SetTargetCondition(const TargetConditionEnum &iCondition)
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:91
itk::FastMarchingReachedTargetNodesStoppingCriterion::Traits
typename Superclass::Traits Traits
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:69
itk::FastMarchingReachedTargetNodesStoppingCriterion::m_NumberOfTargetsToBeReached
vcl_size_t m_NumberOfTargetsToBeReached
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:192
itk::FastMarchingReachedTargetNodesStoppingCriterion::m_StoppingValue
OutputPixelType m_StoppingValue
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:194
itk::FastMarchingReachedTargetNodesStoppingCriterion::NodeType
typename Superclass::NodeType NodeType
Definition: itkFastMarchingReachedTargetNodesStoppingCriterion.h:78