ITK  4.2.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 {
43 template< class TType >
45  : private DefaultVectorPixelAccessor< TType >
46 {
47 public:
48 
49  typedef unsigned int VectorLengthType;
50 
53  typedef TType ExternalType;
54 
56  typedef TType InternalType;
57 
59 
60  inline void Set(ActualPixelType output, const ExternalType & input) const
61  {
62  output[m_ComponentIdx] = input;
63  }
64 
65  inline void Set(InternalType &output, const ExternalType & input,
66  const unsigned long offset) const
67  {
68  return Set( Superclass::Get( output, offset ), input );
69  }
70 
71  inline ExternalType Get(const ActualPixelType & input) const
72  {
73  ExternalType output;
74 
75  output = input[m_ComponentIdx];
76  return output;
77  }
78 
79  inline ExternalType Get(const InternalType &input, const SizeValueType offset) const
80  {
81  return Get( Superclass::Get(input, offset) );
82  }
83 
84  void SetExtractComponentIdx(VectorLengthType idx)
85  {
86  m_ComponentIdx = idx;
87  }
88 
89  VectorLengthType GetExtractComponentIdx() const
90  {
91  return m_ComponentIdx;
92  }
93 
95  void SetVectorLength(VectorLengthType l)
96  {
97  Superclass::SetVectorLength( l );
98  }
99 
101  VectorLengthType GetVectorLength() const { return Superclass::GetVectorLength(); }
102 
103  VectorImageToImagePixelAccessor( unsigned int length = 1)
104  :m_ComponentIdx(0)
105  {
106  Superclass::SetVectorLength( length );
107  }
108 
109 protected:
111 
112 private:
114 };
115 } // end namespace Accessor
116 
139 template< class TPixelType, unsigned int Dimension >
140 class ITK_EXPORT VectorImageToImageAdaptor:public
141  ImageAdaptor< VectorImage< TPixelType, Dimension >,
142  Accessor::VectorImageToImagePixelAccessor< TPixelType > >
143 {
144 public:
148  typedef ImageAdaptor< VectorImageType,
150 
153 
155  itkNewMacro(Self);
156 
159 
162  typedef typename Superclass::PixelContainer PixelContainer;
163  typedef typename Superclass::PixelContainerPointer PixelContainerPointer;
164  typedef typename Superclass::PixelContainerConstPointer PixelContainerConstPointer;
165  typedef typename Superclass::IOPixelType IOPixelType;
166 
169 
170  // Set/GetMethods to set the component to be extracted.
171  void SetExtractComponentIndex(VectorLengthType componentIdx)
172  {
173  this->GetPixelAccessor().SetExtractComponentIdx(componentIdx);
174  }
175 
176  // Set/GetMethods to set the component to be extracted.
177  VectorLengthType GetExtractComponentIndex() const
178  {
179  return this->GetPixelAccessor().GetExtractComponentIdx();
180  }
181 
182 protected:
185 private:
186  VectorImageToImageAdaptor(const Self &); //purposely not implemented
187  void operator=(const Self &); //purposely not implemented
188 };
189 } // end namespace itk
190 
191 #endif
192