ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 00019 #ifndef __itkFastMarchingReachedTargetNodesStoppingCriterion_h 00020 #define __itkFastMarchingReachedTargetNodesStoppingCriterion_h 00021 00022 #include "itkFastMarchingStoppingCriterionBase.h" 00023 #include "itkObjectFactory.h" 00024 00025 namespace itk 00026 { 00035 template< class TInput, class TOutput > 00036 class FastMarchingReachedTargetNodesStoppingCriterion : 00037 public FastMarchingStoppingCriterionBase< TInput, TOutput > 00038 { 00039 public: 00040 typedef FastMarchingReachedTargetNodesStoppingCriterion Self; 00041 typedef FastMarchingStoppingCriterionBase< TInput, TOutput > Superclass; 00042 typedef SmartPointer< Self > Pointer; 00043 typedef SmartPointer< const Self > ConstPointer; 00044 typedef typename Superclass::Traits Traits; 00045 00047 itkNewMacro(Self); 00048 00050 itkTypeMacro(FastMarchingReachedTargetNodesStoppingCriterion, 00051 FastMarchingStoppingCriterionBase ); 00052 00053 typedef typename Superclass::OutputPixelType OutputPixelType; 00054 typedef typename Superclass::NodeType NodeType; 00055 00057 enum TargetConditionType { OneTarget = 1, 00058 SomeTargets, 00059 AllTargets }; 00060 00063 void SetTargetCondition( const TargetConditionType& iCondition ) 00064 { 00065 m_TargetCondition = iCondition; 00066 m_Initialized = false; 00067 this->Modified(); 00068 } 00070 00071 itkGetConstReferenceMacro( TargetCondition, TargetConditionType ); 00072 00074 itkSetMacro( TargetOffset, OutputPixelType ); 00075 itkGetMacro( TargetOffset, OutputPixelType ); 00077 00079 void SetNumberOfTargetsToBeReached( const size_t& iN ) 00080 { 00081 m_NumberOfTargetsToBeReached = iN; 00082 m_Initialized = false; 00083 this->Modified(); 00084 } 00085 00087 virtual void SetTargetNodes( const std::vector< NodeType >& iNodes ) 00088 { 00089 m_TargetNodes = iNodes; 00090 m_Initialized = false; 00091 this->Modified(); 00092 } 00093 00095 void SetCurrentNode( const NodeType& iNode ) 00096 { 00097 if( !m_Initialized ) 00098 { 00099 Initialize(); 00100 } 00101 00102 if( !m_Satisfied ) 00103 { 00104 // Only check for reached targets if the mode is not NoTargets and 00105 // there is at least one TargetPoint. 00106 if ( !m_TargetNodes.empty() ) 00107 { 00108 typename std::vector< NodeType >::const_iterator 00109 pointsIter = m_TargetNodes.begin(); 00110 typename std::vector< NodeType >::const_iterator 00111 pointsEnd = m_TargetNodes.end(); 00112 00113 while( pointsIter != pointsEnd ) 00114 { 00115 if ( *pointsIter == iNode ) 00116 { 00117 this->m_ReachedTargetNodes.push_back( iNode ); 00118 m_Satisfied = 00119 ( m_ReachedTargetNodes.size() == m_NumberOfTargetsToBeReached ); 00120 break; 00121 } 00122 ++pointsIter; 00123 } 00124 if( m_Satisfied ) 00125 { 00126 m_StoppingValue = this->m_CurrentValue + m_TargetOffset; 00127 } 00128 } 00129 else 00130 { 00131 m_Satisfied = false; 00132 } 00133 } 00134 } 00135 00137 bool IsSatisfied() const 00138 { 00139 return m_Satisfied && ( this->m_CurrentValue >= m_StoppingValue ); 00140 } 00141 00143 std::string GetDescription() const 00144 { 00145 return "Target Nodes Reached with possible overshoot"; 00146 } 00147 00148 protected: 00149 00151 FastMarchingReachedTargetNodesStoppingCriterion() : Superclass() 00152 { 00153 m_TargetCondition = AllTargets; 00154 m_TargetOffset = NumericTraits< OutputPixelType >::Zero; 00155 m_StoppingValue = NumericTraits< OutputPixelType >::Zero; 00156 m_Satisfied = false; 00157 m_Initialized = false; 00158 } 00159 00161 ~FastMarchingReachedTargetNodesStoppingCriterion() {} 00162 00163 TargetConditionType m_TargetCondition; 00164 std::vector< NodeType > m_TargetNodes; 00165 std::vector< NodeType > m_ReachedTargetNodes; 00166 size_t m_NumberOfTargetsToBeReached; 00167 OutputPixelType m_TargetOffset; 00168 OutputPixelType m_StoppingValue; 00169 bool m_Satisfied; 00170 bool m_Initialized; 00171 00172 void Reset() 00173 { 00174 this->Initialize(); 00175 } 00176 00177 void Initialize() 00178 { 00179 if( m_TargetCondition == OneTarget ) 00180 { 00181 m_NumberOfTargetsToBeReached = 1; 00182 } 00183 if( m_TargetCondition == AllTargets ) 00184 { 00185 m_NumberOfTargetsToBeReached = m_TargetNodes.size(); 00186 } 00187 if( m_NumberOfTargetsToBeReached < 1 ) 00188 { 00189 itkExceptionMacro( 00190 <<"Number of target nodes to be reached is null" ); 00191 } 00192 if( m_NumberOfTargetsToBeReached > m_TargetNodes.size() ) 00193 { 00194 itkExceptionMacro( 00195 <<"Number of target nodes to be reached is above the provided number of target nodes" ); 00196 } 00197 m_ReachedTargetNodes.clear(); 00198 00199 m_Satisfied = false; 00200 m_Initialized = true; 00201 } 00202 00203 private: 00204 FastMarchingReachedTargetNodesStoppingCriterion( const Self& ); 00205 void operator = ( const Self& ); 00206 }; 00207 } 00208 #endif // __itkFastMarchingThresholdStoppingCriterion_h 00209