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 unsigned long 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  ExternalType output;
160 
161  output = static_cast<ExternalType>(input[m_ElementNumber]);
162  return output;
163  }
164 
165  inline ExternalType
166  Get(const InternalType & input, const SizeValueType offset) const
167  {
168  return Get(Superclass::Get(input, offset));
169  }
170 
171 
173  unsigned int
175  {
176  return m_ElementNumber;
177  }
178 
180  void
181  SetElementNumber(unsigned int nth)
182  {
183  m_ElementNumber = nth;
184  }
185 
187  void
189  {
190  Superclass::SetVectorLength(l);
191  }
192 
194  VectorLengthType
196  {
197  return Superclass::GetVectorLength();
198  }
199 
200  NthElementPixelAccessor(unsigned int length = 1) { Superclass::SetVectorLength(length); }
201 
204  bool
205  operator==(const Self & accessor) const
206  {
207  return m_ElementNumber == accessor.m_ElementNumber;
208  }
209 
211 
215  {
216  m_ElementNumber = accessor.m_ElementNumber;
217  this->SetVectorLength(accessor.GetVectorLength());
218  return *this;
219  }
222 protected:
224 
225 private:
227 };
228 
229 } // end namespace itk
230 
231 #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:214
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::SetVectorLength
void SetVectorLength(VectorLengthType l)
Definition: itkNthElementPixelAccessor.h:188
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::VectorLengthType
unsigned int VectorLengthType
Definition: itkNthElementPixelAccessor.h:129
itkVariableLengthVector.h
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::Set
void Set(InternalType &output, const ExternalType &input, const unsigned long offset) const
Definition: itkNthElementPixelAccessor.h:147
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:166
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:181
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:174
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:205
itk::NthElementPixelAccessor::InternalType
TContainer InternalType
Definition: itkNthElementPixelAccessor.h:64
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::GetVectorLength
VectorLengthType GetVectorLength() const
Definition: itkNthElementPixelAccessor.h:195
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:200
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86