ITK  4.9.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 
111 
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 
278  {
279  return m_Buffer ? m_Buffer->GetBufferPointer() : ITK_NULLPTR;
280  }
282  {
283  return m_Buffer ? m_Buffer->GetBufferPointer() : ITK_NULLPTR;
284  }
286 
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 
311 
314 
317  {
319  }
320 
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 
349 
352 };
353 } // end namespace itk
354 
355 #ifndef ITK_MANUAL_INSTANTIATION
356 #include "itkVectorImage.hxx"
357 #endif
358 
359 #endif
VectorImage Self
const InternalPixelType * GetBufferPointer() const
Superclass::OffsetValueType OffsetValueType
static const unsigned int ImageDimension
virtual void Initialize() override
virtual void SetNumberOfComponentsPerPixel(unsigned int n) override
ImportImageContainer< SizeValueType, InternalPixelType > PixelContainer
Index< VImageDimension > IndexType
Definition: itkImageBase.h:137
PixelContainer::Pointer PixelContainerPointer
virtual void Allocate(bool UseDefaultConstructor=false) override
PixelContainer * GetPixelContainer()
PixelType GetPixel(const IndexType &index)
Get a &quot;reference&quot; to a pixel. This result cannot be used as an lvalue because the pixel is converted ...
Superclass::IndexType IndexType
Superclass::SizeType SizeType
Templated n-dimensional vector image class.
itk::VectorImage< UPixelType, NUImageDimension > Type
ObjectType * GetPointer() const
SmartPointer< const Self > ConstPointer
AccessorType GetPixelAccessor(void)
Implements a weak reference to an object.
A structure which enable changing any image class&#39; pixel type to another.
Size< VImageDimension > SizeType
Definition: itkImageBase.h:146
Superclass::OffsetType OffsetType
Point< PointValueType, VImageDimension > PointType
Definition: itkImageBase.h:162
NeighborhoodAccessorFunctorType GetNeighborhoodAccessor()
Matrix< SpacePrecisionType, VImageDimension, VImageDimension > DirectionType
Definition: itkImageBase.h:167
Superclass::DirectionType DirectionType
Give access to partial aspects of a type.
This class provides a common API for pixel accessors for Image and VectorImage. (between the DefaultV...
Superclass::PointType PointType
Represents an array whose length can be defined at run-time.
Offset< VImageDimension > OffsetType
Definition: itkImageBase.h:142
InternalPixelType * GetBufferPointer()
DefaultVectorPixelAccessor< InternalPixelType > AccessorType
Vector< SpacingValueType, VImageDimension > SpacingType
Definition: itkImageBase.h:157
OffsetValueType FastComputeOffset(const IndexType &ind) const
Definition: itkImageBase.h:731
Superclass::SpacingType SpacingType
VariableLengthVector< TPixel > PixelType
InternalPixelType IOPixelType
OffsetType::OffsetValueType OffsetValueType
Definition: itkImageBase.h:143
VectorImageNeighborhoodAccessorFunctor< Self > NeighborhoodAccessorFunctorType
unsigned int VectorLengthType
WeakPointer< const Self > ConstWeakPointer
Base class for templated image classes.
Definition: itkImageBase.h:112
const AccessorType GetPixelAccessor(void) const
void PrintSelf(std::ostream &os, Indent indent) const override
void SetPixel(const IndexType &index, const PixelType &value)
Set a pixel value.
Superclass::RegionType RegionType
VectorLengthType m_VectorLength
const PixelType GetPixel(const IndexType &index) const
Get a pixel (read only version).
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual unsigned int GetNumberOfComponentsPerPixel() const override
PixelContainerPointer m_Buffer
void FillBuffer(const PixelType &value)
ImageRegion< VImageDimension > RegionType
Definition: itkImageBase.h:150
const PixelType operator[](const IndexType &index) const
Access a pixel.
Superclass::IndexValueType IndexValueType
DefaultVectorPixelAccessorFunctor< Self > AccessorFunctorType
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 ...
PixelContainer::ConstPointer PixelContainerConstPointer
SmartPointer< Self > Pointer
const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
void SetPixelContainer(PixelContainer *container)
virtual void Graft(const DataObject *data) override
const PixelContainer * GetPixelContainer() const
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:138
ImageBase< VImageDimension > Superclass
Defines an itk::Image front-end to a standard C-array.