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 * 00020 * Portions of this file are subject to the VTK Toolkit Version 3 copyright. 00021 * 00022 * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00023 * 00024 * For complete copyright, license and disclaimer of warranty information 00025 * please refer to the NOTICE file at the top of the ITK source tree. 00026 * 00027 *=========================================================================*/ 00028 #ifndef __itkScalarConnectedComponentImageFilter_h 00029 #define __itkScalarConnectedComponentImageFilter_h 00030 00031 #include "vnl/vnl_math.h" 00032 #include "itkNumericTraits.h" 00033 #include "itkConnectedComponentFunctorImageFilter.h" 00034 00035 namespace itk 00036 { 00050 namespace Functor 00051 { 00052 template< class TInput > 00053 class SimilarPixelsFunctor 00054 { 00055 public: 00056 SimilarPixelsFunctor() 00057 { 00058 m_Threshold = NumericTraits< TInput >::Zero; 00059 } 00060 00061 ~SimilarPixelsFunctor() 00062 {} 00063 00064 bool operator!=(const SimilarPixelsFunctor & other) const 00065 { 00066 if ( m_Threshold != other.m_Threshold ) 00067 { 00068 return true; 00069 } 00070 return false; 00071 } 00072 00073 bool operator==(const SimilarPixelsFunctor & other) const 00074 { 00075 return !( *this != other ); 00076 } 00077 00078 void SetDistanceThreshold(const TInput & thresh) 00079 { 00080 m_Threshold = thresh; 00081 } 00082 00083 TInput GetDistanceThreshold() 00084 { 00085 return ( m_Threshold ); 00086 } 00087 00088 bool operator()(const TInput & a, const TInput & b) const 00089 { 00090 typedef typename NumericTraits< TInput >::RealType InputRealType; 00091 TInput absDifference = static_cast< TInput >( vnl_math_abs( 00092 static_cast< InputRealType >( a ) 00093 - static_cast< InputRealType >( b ) ) ); 00094 if ( absDifference <= m_Threshold ) 00095 { 00096 return true; 00097 } 00098 else 00099 { 00100 return false; 00101 } 00102 } 00103 00104 protected: 00105 TInput m_Threshold; 00106 }; 00107 } // end namespace Functor 00108 00109 template< class TInputImage, class TOutputImage, class TMaskImage = TInputImage > 00110 class ITK_EXPORT ScalarConnectedComponentImageFilter: 00111 public ConnectedComponentFunctorImageFilter< TInputImage, TOutputImage, 00112 Functor::SimilarPixelsFunctor< typename TInputImage::ValueType >, 00113 TMaskImage > 00114 { 00115 public: 00117 typedef ScalarConnectedComponentImageFilter Self; 00118 typedef ConnectedComponentFunctorImageFilter< 00119 TInputImage, TOutputImage, 00120 Functor::SimilarPixelsFunctor< typename TInputImage::ValueType >, 00121 TMaskImage > Superclass; 00122 00123 typedef SmartPointer< Self > Pointer; 00124 typedef SmartPointer< const Self > ConstPointer; 00125 00127 itkNewMacro(Self); 00128 00130 itkTypeMacro(ScalarConnectedComponentImageFilter, ConnectedComponentFunctorImageFilter); 00131 00132 typedef typename TInputImage::PixelType InputPixelType; 00133 00134 virtual void SetDistanceThreshold(const InputPixelType & thresh) 00135 { this->GetFunctor().SetDistanceThreshold(thresh); } 00136 00137 virtual InputPixelType GetDistanceThreshold() 00138 { return ( this->GetFunctor().GetDistanceThreshold() ); } 00139 00140 #ifdef ITK_USE_CONCEPT_CHECKING 00141 00142 itkConceptMacro( InputEqualityComparableCheck, 00143 ( Concept::EqualityComparable< InputPixelType > ) ); 00144 itkConceptMacro( OutputEqualityComparableCheck, 00145 ( Concept::EqualityComparable< typename TOutputImage::PixelType > ) ); 00146 itkConceptMacro( MaskEqualityComparableCheck, 00147 ( Concept::EqualityComparable< typename TMaskImage::PixelType > ) ); 00148 itkConceptMacro( OutputIncrementDecrementOperatorsCheck, 00149 ( Concept::IncrementDecrementOperators< typename TOutputImage::PixelType > ) ); 00150 00152 #endif 00153 protected: 00154 ScalarConnectedComponentImageFilter() {} 00155 virtual ~ScalarConnectedComponentImageFilter() {} 00156 private: 00157 ScalarConnectedComponentImageFilter(const Self &); //purposely not implemented 00158 void operator=(const Self &); //purposely not implemented 00159 }; 00160 } // end namespace itk 00162 00163 #endif 00164