ITK  5.2.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  * http://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 
105  {
106  m_ElementNumber = accessor.m_ElementNumber;
107  return *this;
108  }
109 
112 
113 private:
114  // Identifier of the N-th element to be accessed
115  unsigned int m_ElementNumber;
116 };
117 
118 
119 template <typename TOutputPixelType, typename TPixelType>
120 class NthElementPixelAccessor<TOutputPixelType, itk::VariableLengthVector<TPixelType>>
121  : private DefaultVectorPixelAccessor<TPixelType>
122 {
123 public:
126 
127  using VectorLengthType = unsigned int;
128 
131  using ExternalType = TOutputPixelType;
132 
134  using InternalType = TPixelType;
135 
137 
138  inline void
139  Set(ActualPixelType & output, const ExternalType & input) const
140  {
141  output[m_ElementNumber] = input;
142  }
143 
144  inline void
145  Set(InternalType & output, const ExternalType & input, const unsigned long offset) const
146  {
147  // note: v is a reference to the internal buffer, this method of
148  // access relies on return value optimization to work
149  ActualPixelType v = Superclass::Get(output, offset);
150 
151  return Set(v, input);
152  }
153 
154  inline ExternalType
155  Get(const ActualPixelType & input) const
156  {
157  ExternalType output;
158 
159  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 
211  {
212  m_ElementNumber = accessor.m_ElementNumber;
213  this->SetVectorLength(accessor.GetVectorLength());
214  return *this;
215  }
217 
218 protected:
220 
221 private:
223 };
224 
225 } // end namespace itk
226 
227 #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:155
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::operator=
NthElementPixelAccessor & operator=(const NthElementPixelAccessor &accessor)
Definition: itkNthElementPixelAccessor.h:210
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:127
itkVariableLengthVector.h
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::Set
void Set(InternalType &output, const ExternalType &input, const unsigned long offset) const
Definition: itkNthElementPixelAccessor.h:145
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::operator!=
bool operator!=(const Self &accessor) const
Definition: itkNthElementPixelAccessor.h:203
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:139
itk::NthElementPixelAccessor::NthElementPixelAccessor
NthElementPixelAccessor()
Definition: itkNthElementPixelAccessor.h:111
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:104
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::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:115
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::ExternalType
TOutputPixelType ExternalType
Definition: itkNthElementPixelAccessor.h:131
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
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::GetElementNumber
unsigned int GetElementNumber() const
Definition: itkNthElementPixelAccessor.h:82
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::InternalType
TPixelType InternalType
Definition: itkNthElementPixelAccessor.h:134
itk::NthElementPixelAccessor::operator!=
bool operator!=(const Self &accessor) const
Definition: itkNthElementPixelAccessor.h:97
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::NthElementPixelAccessor
NthElementPixelAccessor(unsigned int length=1)
Definition: itkNthElementPixelAccessor.h:198
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83