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
23namespace itk
24{
25namespace Functor
26{
27template <typename TInput, typename TOutput>
29{
30public:
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
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
59private:
60 unsigned int m_Index;
61};
62} // namespace Functor
63
87template <typename TInputImage, typename TOutputImage>
90 TInputImage,
91 TOutputImage,
92 Functor::VectorIndexSelectionCast<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
93{
94public:
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
136protected:
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_UNEQUAL_OPERATOR_MEMBER_FUNCTION(VectorIndexSelectionCast)
bool operator==(const VectorIndexSelectionCast &other) const
Base class for all process objects that output image data.
const InputImageType * GetInput() const
Define additional traits for native types such as int or float.
virtual void Modified() const
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Implements pixel-wise generic operation on one image.
Extracts the selected index of the vector that is the input pixel type.
~VectorIndexSelectionCastImageFilter() override=default
#define itkConceptMacro(name, concept)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....