ITK  6.0.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  * https://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:
54  SimilarVectorsFunctor() = default;
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 true;
73  }
74 
76 
77  bool
78  operator()(const TInput & a, const TInput & b) const
79  {
80  using RealValueType = typename NumericTraits<typename TInput::ValueType>::RealType;
81  RealValueType dotProduct{};
82  for (unsigned int i = 0; i < NumericTraits<TInput>::GetLength(a); ++i)
83  {
84  dotProduct += a[i] * b[i];
85  }
86  return (static_cast<typename TInput::ValueType>(1.0 - itk::Math::abs(dotProduct)) <= m_Threshold);
87  }
88 
89 protected:
90  typename TInput::ValueType m_Threshold{};
91 };
92 } // end namespace Functor
93 
104 template <typename TInputImage, typename TOutputImage, typename TMaskImage = TInputImage>
106  : public ConnectedComponentFunctorImageFilter<TInputImage,
107  TOutputImage,
108  Functor::SimilarVectorsFunctor<typename TInputImage::ValueType>,
109  TMaskImage>
110 {
111 public:
112  ITK_DISALLOW_COPY_AND_MOVE(VectorConnectedComponentImageFilter);
113 
116  using Superclass =
118  TOutputImage,
120  TMaskImage>;
123 
125  itkNewMacro(Self);
126 
128  itkOverrideGetNameOfClassMacro(VectorConnectedComponentImageFilter);
129 
130  using InputValueType = typename TInputImage::PixelType::ValueType;
131 
132  virtual void
134  {
135  this->GetFunctor().SetDistanceThreshold(thresh);
136  }
137 
138  virtual InputValueType
140  {
141  return (this->GetFunctor().GetDistanceThreshold());
142  }
143 
144 #ifdef ITK_USE_CONCEPT_CHECKING
145  // Begin concept checking
146  itkConceptMacro(InputValueHasNumericTraitsCheck, (Concept::HasNumericTraits<InputValueType>));
147  itkConceptMacro(InputValyeTypeIsFloatingCheck, (Concept::IsFloatingPoint<InputValueType>));
148  // End concept checking
149 #endif
150 
151 protected:
153  ~VectorConnectedComponentImageFilter() override = default;
154 };
155 } // end namespace itk
156 
157 #endif
itk::Functor::SimilarVectorsFunctor::operator==
bool operator==(const SimilarVectorsFunctor &) const
Definition: itkVectorConnectedComponentImageFilter.h:70
itk::VectorConnectedComponentImageFilter::SetDistanceThreshold
virtual void SetDistanceThreshold(const InputValueType &thresh)
Definition: itkVectorConnectedComponentImageFilter.h:133
itk::VectorConnectedComponentImageFilter::GetDistanceThreshold
virtual InputValueType GetDistanceThreshold()
Definition: itkVectorConnectedComponentImageFilter.h:139
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:716
itk::Functor::SimilarVectorsFunctor::SimilarVectorsFunctor
SimilarVectorsFunctor()=default
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::SmartPointer< Self >
itk::Functor::SimilarVectorsFunctor::ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(SimilarVectorsFunctor)
itk::Math::abs
bool abs(bool x)
Definition: itkMath.h:840
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
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:948
itk::VectorConnectedComponentImageFilter
A connected components filter that labels the objects in a vector image. Two vectors are pointing sim...
Definition: itkVectorConnectedComponentImageFilter.h:105
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:60
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itkConnectedComponentFunctorImageFilter.h
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itkNumericTraits.h
itk::Functor::SimilarVectorsFunctor::m_Threshold
TInput::ValueType m_Threshold
Definition: itkVectorConnectedComponentImageFilter.h:90
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:130
itkMath.h
itk::Functor::SimilarVectorsFunctor::operator()
bool operator()(const TInput &a, const TInput &b) const
Definition: itkVectorConnectedComponentImageFilter.h:78