ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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
86
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 }
122
123
124 unsigned int
125 GetIndex() const
126 {
127 return this->GetFunctor().GetIndex();
128 }
129
131
132protected:
135
136 void
138 {
139 const unsigned int index = this->GetIndex();
140 const TInputImage * image = this->GetInput();
141
142 const unsigned int numberOfRunTimeComponents = image->GetNumberOfComponentsPerPixel();
143
144 using PixelType = typename TInputImage::PixelType;
145
146 using PixelRealType = typename NumericTraits<PixelType>::RealType;
147
148 using PixelScalarRealType = typename NumericTraits<PixelType>::ScalarRealType;
149
150 const unsigned int numberOfCompileTimeComponents = sizeof(PixelRealType) / sizeof(PixelScalarRealType);
151
152 unsigned int numberOfComponents = numberOfRunTimeComponents;
153
154 if (numberOfCompileTimeComponents > numberOfRunTimeComponents)
155 {
156 numberOfComponents = numberOfCompileTimeComponents;
157 }
158
159 if (index >= numberOfComponents)
160 {
161 itkExceptionMacro("Selected index = " << index
162 << " is greater than the number of components = " << numberOfComponents);
163 }
164 }
165};
166} // end namespace itk
167
168#endif
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(VectorIndexSelectionCast)
bool operator==(const VectorIndexSelectionCast &other) const
const InputImageType * GetInput() const
virtual void Modified() const
Implements transparent reference counting.
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::VectorIndexSelectionCast< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
~VectorIndexSelectionCastImageFilter() override=default
#define itkConceptMacro(name, concept)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....