ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkVectorImageToImageAdaptor.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 __itkVectorImageToImageAdaptor_h
19 #define __itkVectorImageToImageAdaptor_h
20 
21 #include "itkImageAdaptor.h"
22 #include "itkVectorImage.h"
23 
24 namespace itk
25 {
26 namespace Accessor
27 {
46 template< class TType >
48  : private DefaultVectorPixelAccessor< TType >
49 {
50 public:
51 
52  typedef unsigned int VectorLengthType;
53 
56  typedef TType ExternalType;
57 
59  typedef TType InternalType;
60 
62 
63  inline void Set(ActualPixelType output, const ExternalType & input) const
64  {
65  output[m_ComponentIdx] = input;
66  }
67 
68  inline void Set(InternalType &output, const ExternalType & input,
69  const unsigned long offset) const
70  {
71  return Set( Superclass::Get( output, offset ), input );
72  }
73 
74  inline ExternalType Get(const ActualPixelType & input) const
75  {
76  ExternalType output;
77 
78  output = input[m_ComponentIdx];
79  return output;
80  }
81 
82  inline ExternalType Get(const InternalType &input, const SizeValueType offset) const
83  {
84  return Get( Superclass::Get(input, offset) );
85  }
86 
87  void SetExtractComponentIdx(VectorLengthType idx)
88  {
89  m_ComponentIdx = idx;
90  }
91 
92  VectorLengthType GetExtractComponentIdx() const
93  {
94  return m_ComponentIdx;
95  }
96 
98  void SetVectorLength(VectorLengthType l)
99  {
100  Superclass::SetVectorLength( l );
101  }
102 
104  VectorLengthType GetVectorLength() const { return Superclass::GetVectorLength(); }
105 
106  VectorImageToImagePixelAccessor( unsigned int length = 1)
107  :m_ComponentIdx(0)
108  {
109  Superclass::SetVectorLength( length );
110  }
111 
112 protected:
114 
115 private:
117 };
118 } // end namespace Accessor
119 
142 template< class TPixelType, unsigned int Dimension >
143 class ITK_EXPORT VectorImageToImageAdaptor:public
144  ImageAdaptor< VectorImage< TPixelType, Dimension >,
145  Accessor::VectorImageToImagePixelAccessor< TPixelType > >
146 {
147 public:
151  typedef ImageAdaptor< VectorImageType,
153 
156 
158  itkNewMacro(Self);
159 
162 
165  typedef typename Superclass::PixelContainer PixelContainer;
166  typedef typename Superclass::PixelContainerPointer PixelContainerPointer;
167  typedef typename Superclass::PixelContainerConstPointer PixelContainerConstPointer;
168  typedef typename Superclass::IOPixelType IOPixelType;
169 
172 
173  // Set/GetMethods to set the component to be extracted.
174  void SetExtractComponentIndex(VectorLengthType componentIdx)
175  {
176  this->GetPixelAccessor().SetExtractComponentIdx(componentIdx);
177  }
178 
179  // Set/GetMethods to set the component to be extracted.
180  VectorLengthType GetExtractComponentIndex() const
181  {
182  return this->GetPixelAccessor().GetExtractComponentIdx();
183  }
184 
185 protected:
188 
189 private:
190  VectorImageToImageAdaptor(const Self &); //purposely not implemented
191  void operator=(const Self &); //purposely not implemented
192 };
193 } // end namespace itk
194 
195 #endif
196