ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkScalarConnectedComponentImageFilter.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 __itkScalarConnectedComponentImageFilter_h
29 #define __itkScalarConnectedComponentImageFilter_h
30 
31 #include "vnl/vnl_math.h"
32 #include "itkNumericTraits.h"
34 
35 namespace itk
36 {
50 namespace Functor
51 {
52 template< typename TInput >
54 {
55 public:
57  {
59  }
60 
62  {}
63 
64  bool operator!=(const SimilarPixelsFunctor & other) const
65  {
66  if ( m_Threshold != other.m_Threshold )
67  {
68  return true;
69  }
70  return false;
71  }
72 
73  bool operator==(const SimilarPixelsFunctor & other) const
74  {
75  return !( *this != other );
76  }
77 
78  void SetDistanceThreshold(const TInput & thresh)
79  {
80  m_Threshold = thresh;
81  }
82 
84  {
85  return ( m_Threshold );
86  }
87 
88  bool operator()(const TInput & a, const TInput & b) const
89  {
90  typedef typename NumericTraits< TInput >::RealType InputRealType;
91  TInput absDifference = static_cast< TInput >( vnl_math_abs(
92  static_cast< InputRealType >( a )
93  - static_cast< InputRealType >( b ) ) );
94  if ( absDifference <= m_Threshold )
95  {
96  return true;
97  }
98  else
99  {
100  return false;
101  }
102  }
103 
104 protected:
105  TInput m_Threshold;
106 };
107 } // end namespace Functor
108 
109 template< typename TInputImage, typename TOutputImage, typename TMaskImage = TInputImage >
111  public ConnectedComponentFunctorImageFilter< TInputImage, TOutputImage,
112  Functor::SimilarPixelsFunctor< typename TInputImage::ValueType >,
113  TMaskImage >
114 {
115 public:
119  TInputImage, TOutputImage,
121  TMaskImage > Superclass;
122 
125 
127  itkNewMacro(Self);
128 
131 
132  typedef typename TInputImage::PixelType InputPixelType;
133 
134  virtual void SetDistanceThreshold(const InputPixelType & thresh)
135  { this->GetFunctor().SetDistanceThreshold(thresh); }
136 
138  { return ( this->GetFunctor().GetDistanceThreshold() ); }
139 
140 #ifdef ITK_USE_CONCEPT_CHECKING
141  // Begin concept checking
142  itkConceptMacro( InputEqualityComparableCheck,
144  itkConceptMacro( OutputEqualityComparableCheck,
146  itkConceptMacro( MaskEqualityComparableCheck,
148  itkConceptMacro( OutputIncrementDecrementOperatorsCheck,
150  // End concept checking
151 #endif
152 
153 protected:
156 
157 private:
158  ScalarConnectedComponentImageFilter(const Self &); //purposely not implemented
159  void operator=(const Self &); //purposely not implemented
160 };
161 } // end namespace itk
162 
163 #endif
A connected components filter that labels the objects in an arbitrary image. Two pixels are similar i...
bool operator!=(const SimilarPixelsFunctor &other) const
A generic connected components filter that labels the objects in an artibitrary image.
Base class for all process objects that output image data.
bool operator()(const TInput &a, const TInput &b) const
ConnectedComponentFunctorImageFilter< TInputImage, TOutputImage, Functor::SimilarPixelsFunctor< typename TInputImage::ValueType >, TMaskImage > Superclass
bool operator==(const SimilarPixelsFunctor &other) const
virtual void SetDistanceThreshold(const InputPixelType &thresh)
Define additional traits for native types such as int or float.
#define itkConceptMacro(name, concept)