ITK  5.2.0
Insight Toolkit
itkVectorConnectedComponentImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 "itkMath.h"
32 #include "itkNumericTraits.h"
34 
35 namespace itk
36 {
37 namespace Functor
38 {
50 template <typename TInput>
52 {
53 public:
55 
56  ~SimilarVectorsFunctor() = default;
57 
58  void
59  SetDistanceThreshold(const typename TInput::ValueType & thresh)
60  {
61  m_Threshold = thresh;
62  }
63  typename TInput::ValueType
65  {
66  return (m_Threshold);
67  }
68 
69  bool
71  {
72  return false;
73  }
74 
75  bool
76  operator==(const SimilarVectorsFunctor & other) const
77  {
78  return !(*this != other);
79  }
80 
81  bool
82  operator()(const TInput & a, const TInput & b) const
83  {
84  using RealValueType = typename NumericTraits<typename TInput::ValueType>::RealType;
85  RealValueType dotProduct = NumericTraits<RealValueType>::ZeroValue();
86  for (unsigned int i = 0; i < NumericTraits<TInput>::GetLength(a); ++i)
87  {
88  dotProduct += a[i] * b[i];
89  }
90  return (static_cast<typename TInput::ValueType>(1.0 - itk::Math::abs(dotProduct)) <= m_Threshold);
91  }
92 
93 protected:
94  typename TInput::ValueType m_Threshold;
95 };
96 } // end namespace Functor
97 
108 template <typename TInputImage, typename TOutputImage, typename TMaskImage = TInputImage>
110  : public ConnectedComponentFunctorImageFilter<TInputImage,
111  TOutputImage,
112  Functor::SimilarVectorsFunctor<typename TInputImage::ValueType>,
113  TMaskImage>
114 {
115 public:
116  ITK_DISALLOW_COPY_AND_ASSIGN(VectorConnectedComponentImageFilter);
117 
120  using Superclass =
122  TOutputImage,
124  TMaskImage>;
127 
129  itkNewMacro(Self);
130 
133 
134  using InputValueType = typename TInputImage::PixelType::ValueType;
135 
136  virtual void
138  {
139  this->GetFunctor().SetDistanceThreshold(thresh);
140  }
141 
142  virtual InputValueType
144  {
145  return (this->GetFunctor().GetDistanceThreshold());
146  }
147 
148 #ifdef ITK_USE_CONCEPT_CHECKING
149  // Begin concept checking
150  itkConceptMacro(InputValueHasNumericTraitsCheck, (Concept::HasNumericTraits<InputValueType>));
151  itkConceptMacro(InputValyeTypeIsFloatingCheck, (Concept::IsFloatingPoint<InputValueType>));
152  // End concept checking
153 #endif
154 
155 protected:
157  ~VectorConnectedComponentImageFilter() override = default;
158 };
159 } // end namespace itk
160 
161 #endif
itk::VectorConnectedComponentImageFilter::SetDistanceThreshold
virtual void SetDistanceThreshold(const InputValueType &thresh)
Definition: itkVectorConnectedComponentImageFilter.h:137
itk::VectorConnectedComponentImageFilter::GetDistanceThreshold
virtual InputValueType GetDistanceThreshold()
Definition: itkVectorConnectedComponentImageFilter.h:143
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:712
itk::ConnectedComponentFunctorImageFilter
A generic connected components filter that labels the objects in an arbitrary image.
Definition: itkConnectedComponentFunctorImageFilter.h:54
itk::VectorConnectedComponentImageFilter::~VectorConnectedComponentImageFilter
~VectorConnectedComponentImageFilter() override=default
itk::Functor::SimilarVectorsFunctor::~SimilarVectorsFunctor
~SimilarVectorsFunctor()=default
itk::VectorConnectedComponentImageFilter::VectorConnectedComponentImageFilter
VectorConnectedComponentImageFilter()=default
itk::Functor::SimilarVectorsFunctor::operator!=
bool operator!=(const SimilarVectorsFunctor &) const
Definition: itkVectorConnectedComponentImageFilter.h:70
itk::SmartPointer< Self >
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::Functor::SimilarVectorsFunctor::operator==
bool operator==(const SimilarVectorsFunctor &other) const
Definition: itkVectorConnectedComponentImageFilter.h:76
itk::Functor::SimilarVectorsFunctor
A connected components filter that labels the objects in a vector image. Two vectors are pointing sim...
Definition: itkVectorConnectedComponentImageFilter.h:51
itk::Concept::IsFloatingPoint
Definition: itkConceptChecking.h:945
itk::VectorConnectedComponentImageFilter
A connected components filter that labels the objects in a vector image. Two vectors are pointing sim...
Definition: itkVectorConnectedComponentImageFilter.h:109
itk::ConnectedComponentFunctorImageFilter< TInputImage, TOutputImage, Functor::SimilarVectorsFunctor< TInputImage::ValueType >, TMaskImage >::GetFunctor
FunctorType & GetFunctor()
Definition: itkConnectedComponentFunctorImageFilter.h:117
itk::Functor::SimilarVectorsFunctor::GetDistanceThreshold
TInput::ValueType GetDistanceThreshold()
Definition: itkVectorConnectedComponentImageFilter.h:64
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::NumericTraits::ZeroValue
static T ZeroValue()
Definition: itkNumericTraits.h:148
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:64
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itkConnectedComponentFunctorImageFilter.h
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itkNumericTraits.h
itk::Functor::SimilarVectorsFunctor::SimilarVectorsFunctor
SimilarVectorsFunctor()
Definition: itkVectorConnectedComponentImageFilter.h:54
itk::Functor::SimilarVectorsFunctor::m_Threshold
TInput::ValueType m_Threshold
Definition: itkVectorConnectedComponentImageFilter.h:94
itk::Functor::SimilarVectorsFunctor::SetDistanceThreshold
void SetDistanceThreshold(const typename TInput::ValueType &thresh)
Definition: itkVectorConnectedComponentImageFilter.h:59
itk::VectorConnectedComponentImageFilter::InputValueType
typename TInputImage::PixelType::ValueType InputValueType
Definition: itkVectorConnectedComponentImageFilter.h:134
itkMath.h
itk::Functor::SimilarVectorsFunctor::operator()
bool operator()(const TInput &a, const TInput &b) const
Definition: itkVectorConnectedComponentImageFilter.h:82