ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkVectorConnectedComponentImageFilter.h
Go to the documentation of this file.
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     typename TInput::ValueType dotProduct = vnl_math_abs(a * b);
00075     return ( 1.0 - dotProduct <= m_Threshold );
00076   }
00077 
00078 protected:
00079   typename TInput::ValueType m_Threshold;
00080 };
00081 } // end namespace Functor
00082 
00092 template< class TInputImage, class TOutputImage, class TMaskImage = TInputImage >
00093 class ITK_EXPORT VectorConnectedComponentImageFilter:
00094   public ConnectedComponentFunctorImageFilter< TInputImage, TOutputImage,
00095                                                Functor::SimilarVectorsFunctor< typename TInputImage::ValueType >,
00096                                                TMaskImage >
00097 {
00098 public:
00100   typedef VectorConnectedComponentImageFilter Self;
00101   typedef ConnectedComponentFunctorImageFilter< TInputImage, TOutputImage,
00102                                                 Functor::SimilarVectorsFunctor< typename TInputImage::ValueType >,
00103                                                 TMaskImage >                      Superclass;
00104   typedef SmartPointer< Self >       Pointer;
00105   typedef SmartPointer< const Self > ConstPointer;
00106 
00108   itkNewMacro(Self);
00109 
00111   itkTypeMacro(VectorConnectedComponentImageFilter, ConnectedComponentFunctorImageFilter);
00112 
00113   typedef typename TInputImage::PixelType::ValueType InputValueType;
00114 
00115   virtual void SetDistanceThreshold(const InputValueType & thresh)
00116   { this->GetFunctor().SetDistanceThreshold(thresh); }
00117 
00118   virtual InputValueType GetDistanceThreshold()
00119   { return ( this->GetFunctor().GetDistanceThreshold() ); }
00120 
00121 #ifdef ITK_USE_CONCEPT_CHECKING
00122 
00123   itkConceptMacro( InputHasNumericTraitsCheck,
00124                    ( Concept::HasNumericTraits< InputValueType > ) );
00125 
00127 #endif
00128 protected:
00129   VectorConnectedComponentImageFilter() {}
00130   virtual ~VectorConnectedComponentImageFilter() {}
00131 private:
00132   VectorConnectedComponentImageFilter(const Self &); //purposely not implemented
00133   void operator=(const Self &);                      //purposely not implemented
00134 };
00135 } // end namespace itk
00137 
00138 #endif
00139