ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkScalarConnectedComponentImageFilter.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 itkScalarConnectedComponentImageFilter_h
29#define itkScalarConnectedComponentImageFilter_h
30
31#include "itkMath.h"
32#include "itkNumericTraits.h"
34
35namespace itk
36{
50
51namespace Functor
52{
53template <typename TInput>
55{
56public:
58 : m_Threshold(TInput{})
59 {}
60
62
63 bool
64 operator==(const SimilarPixelsFunctor & other) const
65 {
66 return m_Threshold == other.m_Threshold;
67 }
68
70
71 void
72 SetDistanceThreshold(const TInput & thresh)
73 {
74 m_Threshold = thresh;
75 }
76
77 TInput
79 {
80 return (m_Threshold);
81 }
82
83 bool
84 operator()(const TInput & a, const TInput & b) const
85 {
86 using InputRealType = typename NumericTraits<TInput>::RealType;
87 auto absDifference =
88 static_cast<TInput>(itk::Math::abs(static_cast<InputRealType>(a) - static_cast<InputRealType>(b)));
89 if (absDifference <= m_Threshold)
90 {
91 return true;
92 }
93
94 return false;
95 }
96
97protected:
99};
100} // end namespace Functor
101
102template <typename TInputImage, typename TOutputImage, typename TMaskImage = TInputImage>
104 : public ConnectedComponentFunctorImageFilter<TInputImage,
105 TOutputImage,
106 Functor::SimilarPixelsFunctor<typename TInputImage::ValueType>,
107 TMaskImage>
108{
109public:
110 ITK_DISALLOW_COPY_AND_MOVE(ScalarConnectedComponentImageFilter);
111
116 TOutputImage,
118 TMaskImage>;
119
122
124 itkNewMacro(Self);
125
127 itkOverrideGetNameOfClassMacro(ScalarConnectedComponentImageFilter);
128
129 using InputPixelType = typename TInputImage::PixelType;
130
131 virtual void
133 {
134 this->GetFunctor().SetDistanceThreshold(thresh);
135 }
136
137 virtual InputPixelType
139 {
140 return (this->GetFunctor().GetDistanceThreshold());
141 }
142
143 itkConceptMacro(InputEqualityComparableCheck, (Concept::EqualityComparable<InputPixelType>));
146 itkConceptMacro(OutputIncrementDecrementOperatorsCheck,
148
149protected:
152};
153} // end namespace itk
154
155#endif
bool operator==(const SimilarPixelsFunctor &other) const
bool operator()(const TInput &a, const TInput &b) const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(SimilarPixelsFunctor)
virtual void SetDistanceThreshold(const InputPixelType &thresh)
~ScalarConnectedComponentImageFilter() override=default
ConnectedComponentFunctorImageFilter< TInputImage, TOutputImage, Functor::SimilarPixelsFunctor< typename TInputImage::ValueType >, TMaskImage > Superclass
Implements transparent reference counting.
#define itkConceptMacro(name, concept)
bool abs(bool x)
Definition itkMath.h:833
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....