ITK  6.0.0
Insight Toolkit
itkVectorIndexSelectionCastImageFilter.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 #ifndef itkVectorIndexSelectionCastImageFilter_h
19 #define itkVectorIndexSelectionCastImageFilter_h
20 
22 
23 namespace itk
24 {
25 namespace Functor
26 {
27 template <typename TInput, typename TOutput>
29 {
30 public:
32  ~VectorIndexSelectionCast() = default;
33 
34  unsigned int
35  GetIndex() const
36  {
37  return m_Index;
38  }
39  void
40  SetIndex(unsigned int i)
41  {
42  m_Index = i;
43  }
44 
45  bool
46  operator==(const VectorIndexSelectionCast & other) const
47  {
48  return m_Index == other.m_Index;
49  }
50 
52 
53  inline TOutput
54  operator()(const TInput & A) const
55  {
56  return static_cast<TOutput>(A[m_Index]);
57  }
58 
59 private:
60  unsigned int m_Index;
61 };
62 } // namespace Functor
63 
87 template <typename TInputImage, typename TOutputImage>
89  : public UnaryFunctorImageFilter<
90  TInputImage,
91  TOutputImage,
92  Functor::VectorIndexSelectionCast<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
93 {
94 public:
95  ITK_DISALLOW_COPY_AND_MOVE(VectorIndexSelectionCastImageFilter);
96 
100  TInputImage,
101  TOutputImage,
105 
107  itkNewMacro(Self);
108 
110  itkOverrideGetNameOfClassMacro(VectorIndexSelectionCastImageFilter);
111 
113  void
114  SetIndex(unsigned int i)
115  {
116  if (i != this->GetFunctor().GetIndex())
117  {
118  this->GetFunctor().SetIndex(i);
119  this->Modified();
120  }
121  }
124  unsigned int
125  GetIndex() const
126  {
127  return this->GetFunctor().GetIndex();
128  }
129 
130 #ifdef ITK_USE_CONCEPT_CHECKING
131  // Begin concept checking
133  // End concept checking
134 #endif
135 
136 protected:
138  ~VectorIndexSelectionCastImageFilter() override = default;
139 
140  void
142  {
143  const unsigned int index = this->GetIndex();
144  const TInputImage * image = this->GetInput();
145 
146  const unsigned int numberOfRunTimeComponents = image->GetNumberOfComponentsPerPixel();
147 
148  using PixelType = typename TInputImage::PixelType;
149 
150  using PixelRealType = typename NumericTraits<PixelType>::RealType;
151 
152  using PixelScalarRealType = typename NumericTraits<PixelType>::ScalarRealType;
153 
154  const unsigned int numberOfCompileTimeComponents = sizeof(PixelRealType) / sizeof(PixelScalarRealType);
155 
156  unsigned int numberOfComponents = numberOfRunTimeComponents;
157 
158  if (numberOfCompileTimeComponents > numberOfRunTimeComponents)
159  {
160  numberOfComponents = numberOfCompileTimeComponents;
161  }
162 
163  if (index >= numberOfComponents)
164  {
165  itkExceptionMacro("Selected index = " << index
166  << " is greater than the number of components = " << numberOfComponents);
167  }
168  }
169 };
170 } // end namespace itk
171 
172 #endif
itk::VectorIndexSelectionCastImageFilter::SetIndex
void SetIndex(unsigned int i)
Definition: itkVectorIndexSelectionCastImageFilter.h:114
itkUnaryFunctorImageFilter.h
itk::VectorIndexSelectionCastImageFilter::GetIndex
unsigned int GetIndex() const
Definition: itkVectorIndexSelectionCastImageFilter.h:125
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:716
itk::UnaryFunctorImageFilter
Implements pixel-wise generic operation on one image.
Definition: itkUnaryFunctorImageFilter.h:50
itk::Functor::VectorIndexSelectionCast::ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(VectorIndexSelectionCast)
itk::VectorIndexSelectionCastImageFilter::VectorIndexSelectionCastImageFilter
VectorIndexSelectionCastImageFilter()=default
itk::SmartPointer< Self >
itk::VectorIndexSelectionCastImageFilter
Extracts the selected index of the vector that is the input pixel type.
Definition: itkVectorIndexSelectionCastImageFilter.h:88
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::Functor::VectorIndexSelectionCast::SetIndex
void SetIndex(unsigned int i)
Definition: itkVectorIndexSelectionCastImageFilter.h:40
itk::VectorIndexSelectionCastImageFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData() override
Definition: itkVectorIndexSelectionCastImageFilter.h:141
itk::Functor::VectorIndexSelectionCast::operator()
TOutput operator()(const TInput &A) const
Definition: itkVectorIndexSelectionCastImageFilter.h:54
itk::Functor::VectorIndexSelectionCast::VectorIndexSelectionCast
VectorIndexSelectionCast()
Definition: itkVectorIndexSelectionCastImageFilter.h:31
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:60
itk::ImageToImageFilter::GetInput
const InputImageType * GetInput() const
itk::Functor::VectorIndexSelectionCast::operator==
bool operator==(const VectorIndexSelectionCast &other) const
Definition: itkVectorIndexSelectionCastImageFilter.h:46
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
itk::Functor::VectorIndexSelectionCast::GetIndex
unsigned int GetIndex() const
Definition: itkVectorIndexSelectionCastImageFilter.h:35
itk::Functor::VectorIndexSelectionCast::m_Index
unsigned int m_Index
Definition: itkVectorIndexSelectionCastImageFilter.h:60
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itk::Functor::VectorIndexSelectionCast
Definition: itkVectorIndexSelectionCastImageFilter.h:28
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::VectorIndexSelectionCast< TInputImage::PixelType, TOutputImage::PixelType > >::GetFunctor
FunctorType & GetFunctor()
Definition: itkUnaryFunctorImageFilter.h:85
itk::VectorIndexSelectionCastImageFilter::~VectorIndexSelectionCastImageFilter
~VectorIndexSelectionCastImageFilter() override=default
itk::Object::Modified
virtual void Modified() const
itk::Functor::VectorIndexSelectionCast::~VectorIndexSelectionCast
~VectorIndexSelectionCast()=default