ITK  6.0.0
Insight Toolkit
itkNthElementPixelAccessor.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 itkNthElementPixelAccessor_h
19 #define itkNthElementPixelAccessor_h
20 
21 #include "itkMacro.h"
25 
26 namespace itk
27 {
52 template <typename T, typename TContainer>
54 {
55 public:
58 
60  using ExternalType = T;
61 
64  using InternalType = TContainer;
65 
67  inline void
68  Set(InternalType & output, const ExternalType & input) const
69  {
71  }
72 
74  inline ExternalType
75  Get(const InternalType & input) const
76  {
77  return static_cast<ExternalType>(DefaultConvertPixelTraits<InternalType>::GetNthComponent(m_ElementNumber, input));
78  }
79 
81  unsigned int
83  {
84  return m_ElementNumber;
85  }
86 
88  void
89  SetElementNumber(unsigned int nth)
90  {
91  m_ElementNumber = nth;
92  }
93 
96  bool
97  operator==(const Self & accessor) const
98  {
99  return m_ElementNumber == accessor.m_ElementNumber;
100  }
101 
103 
107  {
108  m_ElementNumber = accessor.m_ElementNumber;
109  return *this;
110  }
111 
114 
115 private:
116  // Identifier of the N-th element to be accessed
117  unsigned int m_ElementNumber;
118 };
119 
120 
121 template <typename TOutputPixelType, typename TPixelType>
122 class NthElementPixelAccessor<TOutputPixelType, itk::VariableLengthVector<TPixelType>>
123  : private DefaultVectorPixelAccessor<TPixelType>
124 {
125 public:
128 
129  using VectorLengthType = unsigned int;
130 
133  using ExternalType = TOutputPixelType;
134 
136  using InternalType = TPixelType;
137 
139 
140  inline void
141  Set(ActualPixelType & output, const ExternalType & input) const
142  {
143  output[m_ElementNumber] = input;
144  }
145 
146  inline void
147  Set(InternalType & output, const ExternalType & input, const SizeValueType offset) const
148  {
149  // note: v is a reference to the internal buffer, this method of
150  // access relies on return value optimization to work
151  ActualPixelType v = Superclass::Get(output, offset);
152 
153  return Set(v, input);
154  }
155 
156  inline ExternalType
157  Get(const ActualPixelType & input) const
158  {
159  const auto output = static_cast<ExternalType>(input[m_ElementNumber]);
160  return output;
161  }
162 
163  inline ExternalType
164  Get(const InternalType & input, const SizeValueType offset) const
165  {
166  return Get(Superclass::Get(input, offset));
167  }
168 
169 
171  unsigned int
173  {
174  return m_ElementNumber;
175  }
176 
178  void
179  SetElementNumber(unsigned int nth)
180  {
181  m_ElementNumber = nth;
182  }
183 
185  void
187  {
188  Superclass::SetVectorLength(l);
189  }
190 
192  VectorLengthType
194  {
195  return Superclass::GetVectorLength();
196  }
197 
198  NthElementPixelAccessor(unsigned int length = 1) { Superclass::SetVectorLength(length); }
199 
202  bool
203  operator==(const Self & accessor) const
204  {
205  return m_ElementNumber == accessor.m_ElementNumber;
206  }
207 
209 
213  {
214  m_ElementNumber = accessor.m_ElementNumber;
215  this->SetVectorLength(accessor.GetVectorLength());
216  return *this;
217  }
220 protected:
222 
223 private:
225 };
226 
227 } // end namespace itk
228 
229 #endif
itk::NthElementPixelAccessor::ExternalType
T ExternalType
Definition: itkNthElementPixelAccessor.h:60
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::Get
ExternalType Get(const ActualPixelType &input) const
Definition: itkNthElementPixelAccessor.h:157
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::operator=
NthElementPixelAccessor & operator=(const NthElementPixelAccessor &accessor)
Definition: itkNthElementPixelAccessor.h:212
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::SetVectorLength
void SetVectorLength(VectorLengthType l)
Definition: itkNthElementPixelAccessor.h:186
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::VectorLengthType
unsigned int VectorLengthType
Definition: itkNthElementPixelAccessor.h:129
itkVariableLengthVector.h
itk::NthElementPixelAccessor::SetElementNumber
void SetElementNumber(unsigned int nth)
Definition: itkNthElementPixelAccessor.h:89
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::Get
ExternalType Get(const InternalType &input, const SizeValueType offset) const
Definition: itkNthElementPixelAccessor.h:164
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::Set
void Set(ActualPixelType &output, const ExternalType &input) const
Definition: itkNthElementPixelAccessor.h:141
itk::NthElementPixelAccessor::NthElementPixelAccessor
NthElementPixelAccessor()
Definition: itkNthElementPixelAccessor.h:113
itkDefaultConvertPixelTraits.h
itk::DefaultVectorPixelAccessor
Give access to partial aspects of a type.
Definition: itkDefaultVectorPixelAccessor.h:50
itkMacro.h
itk::DefaultConvertPixelTraits
Traits class used to by ConvertPixels to convert blocks of pixels.
Definition: itkDefaultConvertPixelTraits.h:41
itk::DefaultConvertPixelTraits::SetNthComponent
static void SetNthComponent(int c, PixelType &pixel, const ComponentType &v)
Definition: itkDefaultConvertPixelTraits.h:69
itk::NthElementPixelAccessor::Get
ExternalType Get(const InternalType &input) const
Definition: itkNthElementPixelAccessor.h:75
itk::NthElementPixelAccessor::operator=
NthElementPixelAccessor & operator=(const NthElementPixelAccessor &accessor)
Definition: itkNthElementPixelAccessor.h:106
itk::NthElementPixelAccessor::Set
void Set(InternalType &output, const ExternalType &input) const
Definition: itkNthElementPixelAccessor.h:68
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::SetElementNumber
void SetElementNumber(unsigned int nth)
Definition: itkNthElementPixelAccessor.h:179
itkDefaultVectorPixelAccessor.h
itk::NthElementPixelAccessor
Give access to the N-th of a Container type.
Definition: itkNthElementPixelAccessor.h:53
itk::NthElementPixelAccessor::ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self)
itk::VariableLengthVector
Represents an array whose length can be defined at run-time.
Definition: itkConstantBoundaryCondition.h:28
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::GetElementNumber
unsigned int GetElementNumber() const
Definition: itkNthElementPixelAccessor.h:172
itk::NthElementPixelAccessor::m_ElementNumber
unsigned int m_ElementNumber
Definition: itkNthElementPixelAccessor.h:117
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::ExternalType
TOutputPixelType ExternalType
Definition: itkNthElementPixelAccessor.h:133
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::operator==
bool operator==(const Self &accessor) const
Definition: itkNthElementPixelAccessor.h:203
itk::NthElementPixelAccessor::InternalType
TContainer InternalType
Definition: itkNthElementPixelAccessor.h:64
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::GetVectorLength
VectorLengthType GetVectorLength() const
Definition: itkNthElementPixelAccessor.h:193
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::Set
void Set(InternalType &output, const ExternalType &input, const SizeValueType offset) const
Definition: itkNthElementPixelAccessor.h:147
itk::NthElementPixelAccessor::operator==
bool operator==(const Self &accessor) const
Definition: itkNthElementPixelAccessor.h:97
itk::NthElementPixelAccessor::GetElementNumber
unsigned int GetElementNumber() const
Definition: itkNthElementPixelAccessor.h:82
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::InternalType
TPixelType InternalType
Definition: itkNthElementPixelAccessor.h:136
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::NthElementPixelAccessor
NthElementPixelAccessor(unsigned int length=1)
Definition: itkNthElementPixelAccessor.h:198
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86