ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkVectorConnectedComponentImageFilter.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  *
20  * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  * For complete copyright, license and disclaimer of warranty information
25  * please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef __itkVectorConnectedComponentImageFilter_h
29 #define __itkVectorConnectedComponentImageFilter_h
30 
31 #include "vnl/vnl_math.h"
32 #include "itkNumericTraits.h"
34 
35 namespace itk
36 {
37 namespace Functor
38 {
49 template< class TInput >
51 {
52 public:
55 
57 
58  void SetDistanceThreshold(const typename TInput::ValueType & thresh)
59  { m_Threshold = thresh; }
60  typename TInput::ValueType GetDistanceThreshold() { return ( m_Threshold ); }
61 
62  bool operator!=(const SimilarVectorsFunctor &) const
63  {
64  return false;
65  }
66 
67  bool operator==(const SimilarVectorsFunctor & other) const
68  {
69  return !( *this != other );
70  }
71 
72  bool operator()(const TInput & a, const TInput & b) const
73  {
74  typedef typename NumericTraits<typename TInput::ValueType>::RealType RealValueType;
75  RealValueType dotProduct = NumericTraits<RealValueType>::Zero;
76  for ( unsigned int i = 0; i < NumericTraits<TInput>::GetLength(a); ++i)
77  {
78  dotProduct += a[i]*b[i];
79  }
80  return ( static_cast<typename TInput::ValueType>( 1.0 - vnl_math_abs(dotProduct) ) <= m_Threshold );
81  }
82 
83 protected:
84  typename TInput::ValueType m_Threshold;
85 };
86 } // end namespace Functor
87 
97 template< class TInputImage, class TOutputImage, class TMaskImage = TInputImage >
99  public ConnectedComponentFunctorImageFilter< TInputImage, TOutputImage,
100  Functor::SimilarVectorsFunctor< typename TInputImage::ValueType >,
101  TMaskImage >
102 {
103 public:
106  typedef ConnectedComponentFunctorImageFilter< TInputImage, TOutputImage,
108  TMaskImage > Superclass;
111 
113  itkNewMacro(Self);
114 
117 
118  typedef typename TInputImage::PixelType::ValueType InputValueType;
119 
120  virtual void SetDistanceThreshold(const InputValueType & thresh)
121  { this->GetFunctor().SetDistanceThreshold(thresh); }
122 
123  virtual InputValueType GetDistanceThreshold()
124  { return ( this->GetFunctor().GetDistanceThreshold() ); }
125 
126 #ifdef ITK_USE_CONCEPT_CHECKING
127 
128  itkConceptMacro( InputValueHasNumericTraitsCheck,
130  itkConceptMacro( InputValyeTypeIsFloatingCheck,
132 
134 #endif
135 protected:
138 private:
139  VectorConnectedComponentImageFilter(const Self &); //purposely not implemented
140  void operator=(const Self &); //purposely not implemented
141 };
142 } // end namespace itk
144 
145 #endif
146