ITK  4.13.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:
45  typedef typename Superclass::Traits Traits;
46 
48  itkNewMacro(Self);
49 
53 
55  typedef typename Superclass::NodeType NodeType;
56 
61 
64  void SetTargetCondition( const TargetConditionType& iCondition )
65  {
66  m_TargetCondition = iCondition;
67  m_Initialized = false;
68  this->Modified();
69  }
71 
72  itkGetConstReferenceMacro( TargetCondition, TargetConditionType );
73 
75  itkSetMacro( TargetOffset, OutputPixelType );
76  itkGetMacro( TargetOffset, OutputPixelType );
78 
80  void SetNumberOfTargetsToBeReached( const size_t& iN )
81  {
83  m_Initialized = false;
84  this->Modified();
85  }
86 
88  virtual void SetTargetNodes( const std::vector< NodeType >& iNodes )
89  {
90  m_TargetNodes = iNodes;
91  m_Initialized = false;
92  this->Modified();
93  }
94 
96  void SetCurrentNode( const NodeType& iNode ) ITK_OVERRIDE
97  {
98  if( !m_Initialized )
99  {
100  Initialize();
101  }
102 
103  if( !m_Satisfied )
104  {
105  // Only check for reached targets if the mode is not NoTargets and
106  // there is at least one TargetPoint.
107  if ( !m_TargetNodes.empty() )
108  {
109  typename std::vector< NodeType >::const_iterator
110  pointsIter = m_TargetNodes.begin();
111  typename std::vector< NodeType >::const_iterator
112  pointsEnd = m_TargetNodes.end();
113 
114  while( pointsIter != pointsEnd )
115  {
116  if ( *pointsIter == iNode )
117  {
118  this->m_ReachedTargetNodes.push_back( iNode );
119  m_Satisfied =
121  break;
122  }
123  ++pointsIter;
124  }
125  if( m_Satisfied )
126  {
128  }
129  }
130  else
131  {
132  m_Satisfied = false;
133  }
134  }
135  }
136 
138  bool IsSatisfied() const ITK_OVERRIDE
139  {
140  return m_Satisfied && ( this->m_CurrentValue >= m_StoppingValue );
141  }
142 
144  std::string GetDescription() const ITK_OVERRIDE
145  {
146  return "Target Nodes Reached with possible overshoot";
147  }
148 
149 protected:
150 
153  Superclass(),
158  m_Satisfied(false),
159  m_Initialized(false)
160  {
161  }
162 
165 
167  std::vector< NodeType > m_TargetNodes;
168  std::vector< NodeType > m_ReachedTargetNodes;
174 
175  void Reset() ITK_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 private:
207  ITK_DISALLOW_COPY_AND_ASSIGN(FastMarchingReachedTargetNodesStoppingCriterion);
208 };
209 }
210 #endif // itkFastMarchingThresholdStoppingCriterion_h
Light weight base class for most itk classes.
std::string GetDescription() const override
Get a short description of the stopping criterion.
void SetCurrentNode(const NodeType &iNode) override
Set the current node.
bool IsSatisfied() const override
returns if the stopping condition is satisfied or not.
virtual void Modified() const
Abstract Stopping Criterion dedicated for Fast Marching Methods.
Define additional traits for native types such as int or float.
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.