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 __itkVectorConnectedComponentImageFilter_h 00029 #define __itkVectorConnectedComponentImageFilter_h 00030 00031 #include "vnl/vnl_math.h" 00032 #include "itkNumericTraits.h" 00033 #include "itkConnectedComponentFunctorImageFilter.h" 00034 00035 namespace itk 00036 { 00037 namespace Functor 00038 { 00049 template< class TInput > 00050 class SimilarVectorsFunctor 00051 { 00052 public: 00053 SimilarVectorsFunctor() 00054 { m_Threshold = itk::NumericTraits< typename TInput::ValueType >::Zero; } 00055 00056 ~SimilarVectorsFunctor() {} 00057 00058 void SetDistanceThreshold(const typename TInput::ValueType & thresh) 00059 { m_Threshold = thresh; } 00060 typename TInput::ValueType GetDistanceThreshold() { return ( m_Threshold ); } 00061 00062 bool operator!=(const SimilarVectorsFunctor &) const 00063 { 00064 return false; 00065 } 00066 00067 bool operator==(const SimilarVectorsFunctor & other) const 00068 { 00069 return !( *this != other ); 00070 } 00071 00072 bool operator()(const TInput & a, const TInput & b) const 00073 { 00074 typedef typename NumericTraits<typename TInput::ValueType>::RealType RealValueType; 00075 RealValueType dotProduct = NumericTraits<RealValueType>::Zero; 00076 for ( unsigned int i = 0; i < NumericTraits<TInput>::GetLength(a); ++i) 00077 { 00078 dotProduct += a[i]*b[i]; 00079 } 00080 return ( static_cast<typename TInput::ValueType>( 1.0 - vnl_math_abs(dotProduct) ) <= m_Threshold ); 00081 } 00082 00083 protected: 00084 typename TInput::ValueType m_Threshold; 00085 }; 00086 } // end namespace Functor 00087 00097 template< class TInputImage, class TOutputImage, class TMaskImage = TInputImage > 00098 class ITK_EXPORT VectorConnectedComponentImageFilter: 00099 public ConnectedComponentFunctorImageFilter< TInputImage, TOutputImage, 00100 Functor::SimilarVectorsFunctor< typename TInputImage::ValueType >, 00101 TMaskImage > 00102 { 00103 public: 00105 typedef VectorConnectedComponentImageFilter Self; 00106 typedef ConnectedComponentFunctorImageFilter< TInputImage, TOutputImage, 00107 Functor::SimilarVectorsFunctor< typename TInputImage::ValueType >, 00108 TMaskImage > Superclass; 00109 typedef SmartPointer< Self > Pointer; 00110 typedef SmartPointer< const Self > ConstPointer; 00111 00113 itkNewMacro(Self); 00114 00116 itkTypeMacro(VectorConnectedComponentImageFilter, ConnectedComponentFunctorImageFilter); 00117 00118 typedef typename TInputImage::PixelType::ValueType InputValueType; 00119 00120 virtual void SetDistanceThreshold(const InputValueType & thresh) 00121 { this->GetFunctor().SetDistanceThreshold(thresh); } 00122 00123 virtual InputValueType GetDistanceThreshold() 00124 { return ( this->GetFunctor().GetDistanceThreshold() ); } 00125 00126 #ifdef ITK_USE_CONCEPT_CHECKING 00127 00128 itkConceptMacro( InputValueHasNumericTraitsCheck, 00129 ( Concept::HasNumericTraits< InputValueType > ) ); 00130 itkConceptMacro( InputValyeTypeIsFloatingCheck, 00131 ( Concept::IsFloatingPoint< InputValueType > ) ); 00132 00134 #endif 00135 protected: 00136 VectorConnectedComponentImageFilter() {} 00137 virtual ~VectorConnectedComponentImageFilter() {} 00138 private: 00139 VectorConnectedComponentImageFilter(const Self &); //purposely not implemented 00140 void operator=(const Self &); //purposely not implemented 00141 }; 00142 } // end namespace itk 00144 00145 #endif 00146