ITK  4.6.0
Insight Segmentation and Registration 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  typedef T ExternalType;
60 
63  typedef TContainer InternalType;
64 
66  inline void Set(InternalType & output, const ExternalType & input) const
68 
70  inline ExternalType Get(const InternalType & input) const
72 
74  unsigned int GetElementNumber(void) const
75  { return m_ElementNumber; }
76 
78  void SetElementNumber(unsigned int nth)
79  { m_ElementNumber = nth; }
80 
83  bool operator!=(const Self & accessor) const
84  {
85  return ( m_ElementNumber != accessor.m_ElementNumber );
86  }
87 
90  {
92  return *this;
93  }
94 
97  {
98  m_ElementNumber = 0;
99  }
100 
101 private:
102  // Identifier of the N-th element to be accessed
103  unsigned int m_ElementNumber;
104 };
105 
106 
107 template< typename TOutputPixelType, typename TPixelType >
108 class NthElementPixelAccessor< TOutputPixelType, itk::VariableLengthVector<TPixelType> >
109  : private DefaultVectorPixelAccessor< TPixelType >
110 {
111 public:
114 
115  typedef unsigned int VectorLengthType;
116 
119  typedef TOutputPixelType ExternalType;
120 
122  typedef TPixelType InternalType;
123 
125 
126  inline void Set(ActualPixelType &output, const ExternalType & input) const
127  {
128  output[m_ElementNumber] = input;
129  }
130 
131  inline void Set(InternalType &output, const ExternalType & input,
132  const unsigned long offset) const
133  {
134  // note: v is a reference to the internal buffer, this method of
135  // access relies on return value optimization to work
136  ActualPixelType v = Superclass::Get( output, offset );
137 
138  return Set( v, input );
139  }
140 
141  inline ExternalType Get(const ActualPixelType & input) const
142  {
143  ExternalType output;
144 
145  output = static_cast< ExternalType >( input[m_ElementNumber] );
146  return output;
147  }
148 
149  inline ExternalType Get(const InternalType &input, const SizeValueType offset) const
150  {
151  return Get( Superclass::Get(input, offset) );
152  }
153 
154 
156  unsigned int GetElementNumber(void) const
157  { return m_ElementNumber; }
158 
160  void SetElementNumber(unsigned int nth)
161  { m_ElementNumber = nth; }
162 
165  {
166  Superclass::SetVectorLength( l );
167  }
168 
170  VectorLengthType GetVectorLength() const { return Superclass::GetVectorLength(); }
171 
172  NthElementPixelAccessor( unsigned int length = 1)
173  :m_ElementNumber(0)
174  {
175  Superclass::SetVectorLength( length );
176  }
177 
180  bool operator!=(const Self & accessor) const
181  {
182  return ( m_ElementNumber != accessor.m_ElementNumber );
183  }
184 
187  {
188  m_ElementNumber = accessor.m_ElementNumber;
189  this->SetVectorLength( accessor.GetVectorLength() );
190  return *this;
191  }
193 
194 protected:
196 
197 private:
199 };
200 
201 } // end namespace itk
202 
203 #endif
void Set(InternalType &output, const ExternalType &input) const
unsigned int GetElementNumber(void) const
static void SetNthComponent(int c, PixelType &pixel, const ComponentType &v)
NthElementPixelAccessor & operator=(const NthElementPixelAccessor &accessor)
bool operator!=(const Self &accessor) const
NthElementPixelAccessor & operator=(const NthElementPixelAccessor &accessor)
unsigned long SizeValueType
Definition: itkIntTypes.h:143
static ComponentType GetNthComponent(int c, const PixelType &pixel)
Give access to partial aspects of a type.
Represents an array whose length can be defined at run-time.
ExternalType Get(const InternalType &input) const
void Set(InternalType &output, const ExternalType &input, const unsigned long offset) const
Give access to the N-th of a Container type.
ExternalType Get(const InternalType &input, const SizeValueType offset) const