ITK  4.3.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 {
35  template< class TInput, class TOutput >
37  public FastMarchingStoppingCriterionBase< TInput, TOutput >
38  {
39  public:
44  typedef typename Superclass::Traits Traits;
45 
47  itkNewMacro(Self);
48 
52 
54  typedef typename Superclass::NodeType NodeType;
55 
60 
63  void SetTargetCondition( const TargetConditionType& iCondition )
64  {
65  m_TargetCondition = iCondition;
66  m_Initialized = false;
67  this->Modified();
68  }
70 
71  itkGetConstReferenceMacro( TargetCondition, TargetConditionType );
72 
74  itkSetMacro( TargetOffset, OutputPixelType );
75  itkGetMacro( TargetOffset, OutputPixelType );
77 
79  void SetNumberOfTargetsToBeReached( const size_t& iN )
80  {
82  m_Initialized = false;
83  this->Modified();
84  }
85 
87  virtual void SetTargetNodes( const std::vector< NodeType >& iNodes )
88  {
89  m_TargetNodes = iNodes;
90  m_Initialized = false;
91  this->Modified();
92  }
93 
95  void SetCurrentNode( const NodeType& iNode )
96  {
97  if( !m_Initialized )
98  {
99  Initialize();
100  }
101 
102  if( !m_Satisfied )
103  {
104  // Only check for reached targets if the mode is not NoTargets and
105  // there is at least one TargetPoint.
106  if ( !m_TargetNodes.empty() )
107  {
108  typename std::vector< NodeType >::const_iterator
109  pointsIter = m_TargetNodes.begin();
110  typename std::vector< NodeType >::const_iterator
111  pointsEnd = m_TargetNodes.end();
112 
113  while( pointsIter != pointsEnd )
114  {
115  if ( *pointsIter == iNode )
116  {
117  this->m_ReachedTargetNodes.push_back( iNode );
118  m_Satisfied =
120  break;
121  }
122  ++pointsIter;
123  }
124  if( m_Satisfied )
125  {
127  }
128  }
129  else
130  {
131  m_Satisfied = false;
132  }
133  }
134  }
135 
137  bool IsSatisfied() const
138  {
139  return m_Satisfied && ( this->m_CurrentValue >= m_StoppingValue );
140  }
141 
143  std::string GetDescription() const
144  {
145  return "Target Nodes Reached with possible overshoot";
146  }
147 
148  protected:
149 
152  {
156  m_Satisfied = false;
157  m_Initialized = false;
158  }
159 
162 
164  std::vector< NodeType > m_TargetNodes;
165  std::vector< NodeType > m_ReachedTargetNodes;
171 
172  void Reset()
173  {
174  this->Initialize();
175  }
176 
177  void Initialize()
178  {
180  {
182  }
184  {
186  }
188  {
189  itkExceptionMacro(
190  <<"Number of target nodes to be reached is null" );
191  }
193  {
194  itkExceptionMacro(
195  <<"Number of target nodes to be reached is above the provided number of target nodes" );
196  }
197  m_ReachedTargetNodes.clear();
198 
199  m_Satisfied = false;
200  m_Initialized = true;
201  }
202 
203  private:
205  void operator = ( const Self& );
206  };
207 }
208 #endif // __itkFastMarchingThresholdStoppingCriterion_h
209