ITK  4.5.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 )
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
139  {
140  return m_Satisfied && ( this->m_CurrentValue >= m_StoppingValue );
141  }
142 
144  std::string GetDescription() const
145  {
146  return "Target Nodes Reached with possible overshoot";
147  }
148 
149 protected:
150 
153  {
157  m_Satisfied = false;
158  m_Initialized = false;
159  }
160 
163 
165  std::vector< NodeType > m_TargetNodes;
166  std::vector< NodeType > m_ReachedTargetNodes;
172 
173  void Reset()
174  {
175  this->Initialize();
176  }
177 
178  void Initialize()
179  {
181  {
183  }
185  {
187  }
189  {
190  itkExceptionMacro(
191  <<"Number of target nodes to be reached is null" );
192  }
194  {
195  itkExceptionMacro(
196  <<"Number of target nodes to be reached is above the provided number of target nodes" );
197  }
198  m_ReachedTargetNodes.clear();
199 
200  m_Satisfied = false;
201  m_Initialized = true;
202  }
203 
204 private:
206  void operator = ( const Self& );
207 };
208 }
209 #endif // __itkFastMarchingThresholdStoppingCriterion_h
std::string GetDescription() const
Get a short description of the stopping criterion.
Light weight base class for most itk classes.
bool IsSatisfied() const
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.