ITK  5.0.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 "itkMath.h"
32 #include "itkNumericTraits.h"
34 
35 namespace itk
36 {
37 namespace Functor
38 {
49 template< typename TInput >
51 {
52 public:
54  { m_Threshold = itk::NumericTraits< typename TInput::ValueType >::ZeroValue(); }
55 
56  ~SimilarVectorsFunctor() = default;
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  using RealValueType = typename NumericTraits<typename TInput::ValueType>::RealType;
75  RealValueType dotProduct = NumericTraits<RealValueType>::ZeroValue();
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 - itk::Math::abs(dotProduct) ) <= m_Threshold );
81  }
82 
83 protected:
84  typename TInput::ValueType m_Threshold;
85 };
86 } // end namespace Functor
87 
97 template< typename TInputImage, typename TOutputImage, typename TMaskImage = TInputImage >
99  public ConnectedComponentFunctorImageFilter< TInputImage, TOutputImage,
100  Functor::SimilarVectorsFunctor< typename TInputImage::ValueType >,
101  TMaskImage >
102 {
103 public:
104  ITK_DISALLOW_COPY_AND_ASSIGN(VectorConnectedComponentImageFilter);
105 
108  using Superclass = ConnectedComponentFunctorImageFilter< TInputImage, TOutputImage,
110  TMaskImage >;
113 
115  itkNewMacro(Self);
116 
119 
120  using InputValueType = typename TInputImage::PixelType::ValueType;
121 
122  virtual void SetDistanceThreshold(const InputValueType & thresh)
123  { this->GetFunctor().SetDistanceThreshold(thresh); }
124 
126  { return ( this->GetFunctor().GetDistanceThreshold() ); }
127 
128 #ifdef ITK_USE_CONCEPT_CHECKING
129  // Begin concept checking
130  itkConceptMacro( InputValueHasNumericTraitsCheck,
132  itkConceptMacro( InputValyeTypeIsFloatingCheck,
134  // End concept checking
135 #endif
136 
137 protected:
139  ~VectorConnectedComponentImageFilter() override = default;
140 };
141 } // end namespace itk
142 
143 #endif
bool operator==(const SimilarVectorsFunctor &other) const
Define numeric traits for std::vector.
A connected components filter that labels the objects in a vector image. Two vectors are pointing sim...
typename TInputImage::PixelType::ValueType InputValueType
A connected components filter that labels the objects in a vector image. Two vectors are pointing sim...
A generic connected components filter that labels the objects in an artibitrary image.
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
~VectorConnectedComponentImageFilter() override=default
Base class for all process objects that output image data.
virtual void SetDistanceThreshold(const InputValueType &thresh)
bool operator()(const TInput &a, const TInput &b) const
void SetDistanceThreshold(const typename TInput::ValueType &thresh)
bool operator!=(const SimilarVectorsFunctor &) const
#define itkConceptMacro(name, concept)