ITK  4.10.0
Insight Segmentation and Registration Toolkit
itkVectorImage.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 itkVectorImage_h
19 #define itkVectorImage_h
20 
21 #include "itkImageRegion.h"
26 #include "itkWeakPointer.h"
27 
28 namespace itk
29 {
80 template< typename TPixel, unsigned int VImageDimension = 3 >
81 class VectorImage:
82  public ImageBase< VImageDimension >
83 {
84 public:
86  typedef VectorImage Self;
91 
93  itkNewMacro(Self);
94 
96  itkTypeMacro(VectorImage, ImageBase);
97 
103 
107  typedef TPixel InternalPixelType;
108 
110  typedef PixelType ValueType;
111 
112  typedef InternalPixelType IOPixelType;
113 
117 
121 
126 
131  itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
132 
136 
139 
141  typedef typename Superclass::SizeType SizeType;
142 
145 
148 
152 
156 
160 
164 
167 
168  typedef unsigned int VectorLengthType;
169 
185  template <typename UPixelType, unsigned int NUImageDimension = VImageDimension>
186  struct Rebind
187  {
189  };
190 
192  template <typename UElementType, unsigned int NUImageDimension>
193  struct Rebind< VariableLengthVector< UElementType >, NUImageDimension>
194  {
196  };
198 
201  virtual void Allocate(bool UseDefaultConstructor = false) ITK_OVERRIDE;
202 
205  virtual void Initialize() ITK_OVERRIDE;
206 
209  void FillBuffer(const PixelType & value);
210 
216  void SetPixel(const IndexType & index, const PixelType & value)
217  {
218  OffsetValueType offset = m_VectorLength * this->FastComputeOffset(index);
219 
220  for ( VectorLengthType i = 0; i < m_VectorLength; i++ )
221  {
222  ( *m_Buffer )[offset + i] = value[i];
223  }
224  }
225 
231  const PixelType GetPixel(const IndexType & index) const
232  {
233  OffsetValueType offset = m_VectorLength * this->FastComputeOffset(index);
234 
235  // Do not create a local for this method, to use return value
236  // optimization.
237  return PixelType(&( ( *m_Buffer )[offset] ), m_VectorLength);
238  }
239 
249  PixelType GetPixel(const IndexType & index)
250  {
251  OffsetValueType offset = m_VectorLength * this->FastComputeOffset(index);
252 
253  // Correctness of this method relies of return value optimization, do
254  // not create a local for the value.
255  return PixelType(&( ( *m_Buffer )[offset] ), m_VectorLength);
256  }
257 
267  PixelType operator[](const IndexType & index) { return this->GetPixel(index); }
268 
273  const PixelType operator[](const IndexType & index) const { return this->GetPixel(index); }
274 
277  InternalPixelType * GetBufferPointer()
278  {
279  return m_Buffer ? m_Buffer->GetBufferPointer() : ITK_NULLPTR;
280  }
281  const InternalPixelType * GetBufferPointer() const
282  {
283  return m_Buffer ? m_Buffer->GetBufferPointer() : ITK_NULLPTR;
284  }
286 
288  PixelContainer * GetPixelContainer() { return m_Buffer.GetPointer(); }
289 
291  const PixelContainer * GetPixelContainer() const { return m_Buffer.GetPointer(); }
292 
295  void SetPixelContainer(PixelContainer *container);
296 
307  virtual void Graft(const DataObject *data) ITK_OVERRIDE;
308 
310  AccessorType GetPixelAccessor(void) { return AccessorType(m_VectorLength); }
311 
313  const AccessorType GetPixelAccessor(void) const { return AccessorType(m_VectorLength); }
314 
316  NeighborhoodAccessorFunctorType GetNeighborhoodAccessor()
317  {
319  }
320 
322  const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
323  {
325  }
326 
328  itkSetMacro(VectorLength, VectorLengthType);
329  itkGetConstReferenceMacro(VectorLength, VectorLengthType);
331 
333  virtual unsigned int GetNumberOfComponentsPerPixel() const ITK_OVERRIDE;
334 
335  virtual void SetNumberOfComponentsPerPixel(unsigned int n) ITK_OVERRIDE;
336 
337 protected:
338  VectorImage();
339  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
340 
341  virtual ~VectorImage() {}
342 
343 private:
344  VectorImage(const Self &) ITK_DELETE_FUNCTION;
345  void operator=(const Self &) ITK_DELETE_FUNCTION;
346 
348  VectorLengthType m_VectorLength;
349 
351  PixelContainerPointer m_Buffer;
352 };
353 } // end namespace itk
354 
355 #ifndef ITK_MANUAL_INSTANTIATION
356 #include "itkVectorImage.hxx"
357 #endif
358 
359 #endif
InternalPixelType IOPixelType
VectorLengthType m_VectorLength
Index< VImageDimension > IndexType
Definition: itkImageBase.h:140
Superclass::PointType PointType
Superclass::SizeType SizeType
const PixelContainer * GetPixelContainer() const
const PixelType GetPixel(const IndexType &index) const
Get a pixel (read only version).
PixelContainer::Pointer PixelContainerPointer
Superclass::OffsetValueType OffsetValueType
AccessorType GetPixelAccessor(void)
VectorImage Self
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes...
Definition: itkArray.h:30
WeakPointer< const Self > ConstWeakPointer
NeighborhoodAccessorFunctorType GetNeighborhoodAccessor()
Templated n-dimensional vector image class.
PixelContainer::ConstPointer PixelContainerConstPointer
ObjectType * GetPointer() const
Implements a weak reference to an object.
A structure which enable changing any image class&#39; pixel type to another.
SmartPointer< const Self > ConstPointer
void PrintSelf(std::ostream &os, Indent indent) const override
virtual void Initialize() override
virtual void Allocate(bool UseDefaultConstructor=false) override
Size< VImageDimension > SizeType
Definition: itkImageBase.h:149
itk::VectorImage< UPixelType, NUImageDimension > Type
Point< PointValueType, VImageDimension > PointType
Definition: itkImageBase.h:165
virtual void SetNumberOfComponentsPerPixel(unsigned int n) override
Matrix< SpacePrecisionType, VImageDimension, VImageDimension > DirectionType
Definition: itkImageBase.h:170
Give access to partial aspects of a type.
This class provides a common API for pixel accessors for Image and VectorImage. (between the DefaultV...
void operator=(const Self &) ITK_DELETE_FUNCTION
Represents an array whose length can be defined at run-time.
void SetPixel(const IndexType &index, const PixelType &value)
Set a pixel value.
DefaultVectorPixelAccessor< InternalPixelType > AccessorType
VariableLengthVector< TPixel > PixelType
Offset< VImageDimension > OffsetType
Definition: itkImageBase.h:145
ImportImageContainer< SizeValueType, InternalPixelType > PixelContainer
Vector< SpacingValueType, VImageDimension > SpacingType
Definition: itkImageBase.h:160
const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
OffsetValueType FastComputeOffset(const IndexType &ind) const
Definition: itkImageBase.h:734
static const unsigned int ImageDimension
PixelContainerPointer m_Buffer
const InternalPixelType * GetBufferPointer() const
SmartPointer< Self > Pointer
InternalPixelType * GetBufferPointer()
Superclass::IndexValueType IndexValueType
void SetPixelContainer(PixelContainer *container)
Superclass::DirectionType DirectionType
const AccessorType GetPixelAccessor(void) const
void FillBuffer(const PixelType &value)
OffsetType::OffsetValueType OffsetValueType
Definition: itkImageBase.h:146
virtual ~VectorImage()
Superclass::IndexType IndexType
Base class for templated image classes.
Definition: itkImageBase.h:115
const PixelType operator[](const IndexType &index) const
Access a pixel.
DefaultVectorPixelAccessorFunctor< Self > AccessorFunctorType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
ImageBase< VImageDimension > Superclass
Superclass::SpacingType SpacingType
PixelContainer * GetPixelContainer()
Superclass::OffsetType OffsetType
ImageRegion< VImageDimension > RegionType
Definition: itkImageBase.h:153
virtual unsigned int GetNumberOfComponentsPerPixel() const override
unsigned int VectorLengthType
Superclass::RegionType RegionType
Base class for all data objects in ITK.
Provides accessor interfaces to Access pixels and is meant to be used on pointers to pixels held by t...
IndexType::IndexValueType IndexValueType
Definition: itkImageBase.h:141
virtual void Graft(const DataObject *data) override
VectorImageNeighborhoodAccessorFunctor< Self > NeighborhoodAccessorFunctorType
PixelType operator[](const IndexType &index)
Access a pixel. This result cannot be used as an lvalue because the pixel is converted on the fly to ...
PixelType GetPixel(const IndexType &index)
Get a "reference" to a pixel. This result cannot be used as an lvalue because the pixel is converted ...
Defines an itk::Image front-end to a standard C-array.