ITK  4.13.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 ITK_TEMPLATE_EXPORT 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 
138  typedef typename Superclass::OffsetType OffsetType;
139 
141  typedef typename Superclass::SizeType SizeType;
142 
145 
148 
151  typedef typename Superclass::RegionType RegionType;
152 
155  typedef typename Superclass::SpacingType SpacingType;
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 
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 Self *data);
308 
310  AccessorType GetPixelAccessor(void) { return AccessorType(m_VectorLength); }
311 
313  const AccessorType GetPixelAccessor(void) const { return AccessorType(m_VectorLength); }
314 
317  {
318  return NeighborhoodAccessorFunctorType(m_VectorLength);
319  }
320 
323  {
324  return NeighborhoodAccessorFunctorType(m_VectorLength);
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() ITK_OVERRIDE {}
342  virtual void Graft(const DataObject *data) ITK_OVERRIDE;
343  using Superclass::Graft;
344 private:
345  ITK_DISALLOW_COPY_AND_ASSIGN(VectorImage);
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
ImportImageContainer< SizeValueType, InternalPixelType > PixelContainer
PixelContainer::Pointer PixelContainerPointer
signed long OffsetValueType
Definition: itkIntTypes.h:154
signed long IndexValueType
Definition: itkIntTypes.h:150
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
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.
Superclass::OffsetType OffsetType
NeighborhoodAccessorFunctorType GetNeighborhoodAccessor()
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.
InternalPixelType * GetBufferPointer()
DefaultVectorPixelAccessor< InternalPixelType > AccessorType
Superclass::SpacingType SpacingType
VariableLengthVector< TPixel > PixelType
InternalPixelType IOPixelType
OffsetType::OffsetValueType OffsetValueType
Definition: itkImageBase.h:145
class ITK_TEMPLATE_EXPORT ImageBase
VectorImageNeighborhoodAccessorFunctor< Self > NeighborhoodAccessorFunctorType
unsigned int VectorLengthType
WeakPointer< const Self > ConstWeakPointer
Base class for templated image classes.
Definition: itkImageBase.h:114
const AccessorType GetPixelAccessor(void) const
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
PixelContainerPointer m_Buffer
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
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...
ImageBase< VImageDimension > Superclass
Defines an itk::Image front-end to a standard C-array.