ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkFastMarchingReachedTargetNodesStoppingCriterion.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 
25 namespace itk
26 {
36 template< typename TInput, typename TOutput >
38 public FastMarchingStoppingCriterionBase< TInput, TOutput >
39 {
40 public:
41  ITK_DISALLOW_COPY_AND_ASSIGN(FastMarchingReachedTargetNodesStoppingCriterion);
42 
44  using Superclass = FastMarchingStoppingCriterionBase< TInput, TOutput >;
47  using Traits = typename Superclass::Traits;
48 
50  itkNewMacro(Self);
51 
54  FastMarchingStoppingCriterionBase );
55 
56  using OutputPixelType = typename Superclass::OutputPixelType;
57  using NodeType = typename Superclass::NodeType;
58 
63 
66  void SetTargetCondition( const TargetConditionType& iCondition )
67  {
68  m_TargetCondition = iCondition;
69  m_Initialized = false;
70  this->Modified();
71  }
73 
74  itkGetConstReferenceMacro( TargetCondition, TargetConditionType );
75 
77  itkSetMacro( TargetOffset, OutputPixelType );
78  itkGetMacro( TargetOffset, OutputPixelType );
80 
82  void SetNumberOfTargetsToBeReached( const size_t& iN )
83  {
85  m_Initialized = false;
86  this->Modified();
87  }
88 
90  virtual void SetTargetNodes( const std::vector< NodeType >& iNodes )
91  {
92  m_TargetNodes = iNodes;
93  m_Initialized = false;
94  this->Modified();
95  }
96 
98  void SetCurrentNode( const NodeType& iNode ) override
99  {
100  if( !m_Initialized )
101  {
102  Initialize();
103  }
104 
105  if( !m_Satisfied )
106  {
107  // Only check for reached targets if the mode is not NoTargets and
108  // there is at least one TargetPoint.
109  if ( !m_TargetNodes.empty() )
110  {
111  typename std::vector< NodeType >::const_iterator
112  pointsIter = m_TargetNodes.begin();
113  typename std::vector< NodeType >::const_iterator
114  pointsEnd = m_TargetNodes.end();
115 
116  while( pointsIter != pointsEnd )
117  {
118  if ( *pointsIter == iNode )
119  {
120  this->m_ReachedTargetNodes.push_back( iNode );
121  m_Satisfied =
123  break;
124  }
125  ++pointsIter;
126  }
127  if( m_Satisfied )
128  {
129  m_StoppingValue = this->m_CurrentValue + m_TargetOffset;
130  }
131  }
132  else
133  {
134  m_Satisfied = false;
135  }
136  }
137  }
138 
140  bool IsSatisfied() const override
141  {
142  return m_Satisfied && ( this->m_CurrentValue >= m_StoppingValue );
143  }
144 
146  std::string GetDescription() const override
147  {
148  return "Target Nodes Reached with possible overshoot";
149  }
150 
151 protected:
152 
155  Superclass(),
159 
160  {
161  }
162 
165 
167  std::vector< NodeType > m_TargetNodes;
168  std::vector< NodeType > m_ReachedTargetNodes;
172  bool m_Satisfied{false};
173  bool m_Initialized{false};
174 
175  void Reset() override
176  {
177  this->Initialize();
178  }
179 
180  void Initialize()
181  {
183  {
185  }
187  {
189  }
191  {
192  itkExceptionMacro(
193  <<"Number of target nodes to be reached is null" );
194  }
196  {
197  itkExceptionMacro(
198  <<"Number of target nodes to be reached is above the provided number of target nodes" );
199  }
200  m_ReachedTargetNodes.clear();
201 
202  m_Satisfied = false;
203  m_Initialized = true;
204  }
205 };
206 }
207 #endif // itkFastMarchingThresholdStoppingCriterion_h
std::string GetDescription() const override
Get a short description of the stopping criterion.
Define numeric traits for std::vector.
void SetCurrentNode(const NodeType &iNode) override
Set the current node.
bool IsSatisfied() const override
returns if the stopping condition is satisfied or not.
void SetNumberOfTargetsToBeReached(const vcl_size_t &iN)
Set the number of target nodes to be reached.
virtual void SetTargetNodes(const std::vector< NodeType > &iNodes)
Set Target Nodes.