ITK  5.1.0
Insight Toolkit
itkNthElementPixelAccessor.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 {
51 template <typename T, typename TContainer>
53 {
54 public:
57 
59  using ExternalType = T;
60 
63  using InternalType = TContainer;
64 
66  inline void
67  Set(InternalType & output, const ExternalType & input) const
68  {
70  }
71 
73  inline ExternalType
74  Get(const InternalType & input) const
75  {
76  return static_cast<ExternalType>(DefaultConvertPixelTraits<InternalType>::GetNthComponent(m_ElementNumber, input));
77  }
78 
80  unsigned int
82  {
83  return m_ElementNumber;
84  }
85 
87  void
88  SetElementNumber(unsigned int nth)
89  {
90  m_ElementNumber = nth;
91  }
92 
95  bool
96  operator!=(const Self & accessor) const
97  {
98  return (m_ElementNumber != accessor.m_ElementNumber);
99  }
100 
104  {
105  m_ElementNumber = accessor.m_ElementNumber;
106  return *this;
107  }
108 
111 
112 private:
113  // Identifier of the N-th element to be accessed
114  unsigned int m_ElementNumber;
115 };
116 
117 
118 template <typename TOutputPixelType, typename TPixelType>
119 class NthElementPixelAccessor<TOutputPixelType, itk::VariableLengthVector<TPixelType>>
120  : private DefaultVectorPixelAccessor<TPixelType>
121 {
122 public:
125 
126  using VectorLengthType = unsigned int;
127 
130  using ExternalType = TOutputPixelType;
131 
133  using InternalType = TPixelType;
134 
136 
137  inline void
138  Set(ActualPixelType & output, const ExternalType & input) const
139  {
140  output[m_ElementNumber] = input;
141  }
142 
143  inline void
144  Set(InternalType & output, const ExternalType & input, const unsigned long offset) const
145  {
146  // note: v is a reference to the internal buffer, this method of
147  // access relies on return value optimization to work
148  ActualPixelType v = Superclass::Get(output, offset);
149 
150  return Set(v, input);
151  }
152 
153  inline ExternalType
154  Get(const ActualPixelType & input) const
155  {
156  ExternalType output;
157 
158  output = static_cast<ExternalType>(input[m_ElementNumber]);
159  return output;
160  }
161 
162  inline ExternalType
163  Get(const InternalType & input, const SizeValueType offset) const
164  {
165  return Get(Superclass::Get(input, offset));
166  }
167 
168 
170  unsigned int
172  {
173  return m_ElementNumber;
174  }
175 
177  void
178  SetElementNumber(unsigned int nth)
179  {
180  m_ElementNumber = nth;
181  }
182 
184  void
186  {
187  Superclass::SetVectorLength(l);
188  }
189 
191  VectorLengthType
193  {
194  return Superclass::GetVectorLength();
195  }
196 
197  NthElementPixelAccessor(unsigned int length = 1) { Superclass::SetVectorLength(length); }
198 
201  bool
202  operator!=(const Self & accessor) const
203  {
204  return (m_ElementNumber != accessor.m_ElementNumber);
205  }
206 
210  {
211  m_ElementNumber = accessor.m_ElementNumber;
212  this->SetVectorLength(accessor.GetVectorLength());
213  return *this;
214  }
216 
217 protected:
219 
220 private:
222 };
223 
224 } // end namespace itk
225 
226 #endif
itk::NthElementPixelAccessor::ExternalType
T ExternalType
Definition: itkNthElementPixelAccessor.h:59
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::Get
ExternalType Get(const ActualPixelType &input) const
Definition: itkNthElementPixelAccessor.h:154
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::operator=
NthElementPixelAccessor & operator=(const NthElementPixelAccessor &accessor)
Definition: itkNthElementPixelAccessor.h:209
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::SetVectorLength
void SetVectorLength(VectorLengthType l)
Definition: itkNthElementPixelAccessor.h:185
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::VectorLengthType
unsigned int VectorLengthType
Definition: itkNthElementPixelAccessor.h:126
itkVariableLengthVector.h
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::Set
void Set(InternalType &output, const ExternalType &input, const unsigned long offset) const
Definition: itkNthElementPixelAccessor.h:144
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::operator!=
bool operator!=(const Self &accessor) const
Definition: itkNthElementPixelAccessor.h:202
itk::NthElementPixelAccessor::SetElementNumber
void SetElementNumber(unsigned int nth)
Definition: itkNthElementPixelAccessor.h:88
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::Get
ExternalType Get(const InternalType &input, const SizeValueType offset) const
Definition: itkNthElementPixelAccessor.h:163
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::Set
void Set(ActualPixelType &output, const ExternalType &input) const
Definition: itkNthElementPixelAccessor.h:138
itk::NthElementPixelAccessor::NthElementPixelAccessor
NthElementPixelAccessor()
Definition: itkNthElementPixelAccessor.h:110
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:74
itk::NthElementPixelAccessor::operator=
NthElementPixelAccessor & operator=(const NthElementPixelAccessor &accessor)
Definition: itkNthElementPixelAccessor.h:103
itk::NthElementPixelAccessor::Set
void Set(InternalType &output, const ExternalType &input) const
Definition: itkNthElementPixelAccessor.h:67
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::SetElementNumber
void SetElementNumber(unsigned int nth)
Definition: itkNthElementPixelAccessor.h:178
itkDefaultVectorPixelAccessor.h
itk::NthElementPixelAccessor
Give access to the N-th of a Container type.
Definition: itkNthElementPixelAccessor.h:52
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:171
itk::NthElementPixelAccessor::m_ElementNumber
unsigned int m_ElementNumber
Definition: itkNthElementPixelAccessor.h:114
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::ExternalType
TOutputPixelType ExternalType
Definition: itkNthElementPixelAccessor.h:130
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::NthElementPixelAccessor::InternalType
TContainer InternalType
Definition: itkNthElementPixelAccessor.h:63
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::GetVectorLength
VectorLengthType GetVectorLength() const
Definition: itkNthElementPixelAccessor.h:192
itk::NthElementPixelAccessor::GetElementNumber
unsigned int GetElementNumber() const
Definition: itkNthElementPixelAccessor.h:81
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::InternalType
TPixelType InternalType
Definition: itkNthElementPixelAccessor.h:133
itk::NthElementPixelAccessor::operator!=
bool operator!=(const Self &accessor) const
Definition: itkNthElementPixelAccessor.h:96
itk::NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector< TPixelType > >::NthElementPixelAccessor
NthElementPixelAccessor(unsigned int length=1)
Definition: itkNthElementPixelAccessor.h:197
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83