ITK  5.2.0
Insight Toolkit
itkImageAdaptor.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 itkImageAdaptor_h
19 #define itkImageAdaptor_h
20 
21 #include "itkImage.h"
22 
23 namespace itk
24 {
25 
26 template <typename TPixelType, unsigned int VImageDimension>
27 class VectorImage;
28 
55 template <typename TImage, typename TAccessor>
56 class ITK_TEMPLATE_EXPORT ImageAdaptor : public ImageBase<TImage::ImageDimension>
57 {
58 public:
59  ITK_DISALLOW_COPY_AND_MOVE(ImageAdaptor);
60 
65  static constexpr unsigned int ImageDimension = TImage::ImageDimension;
66 
68  using Self = ImageAdaptor;
73 
75  itkTypeMacro(ImageAdaptor, ImageBase);
76 
78  using InternalImageType = TImage;
79 
81  itkNewMacro(Self);
82 
85  using PixelType = typename TAccessor::ExternalType;
86 
89  using InternalPixelType = typename TAccessor::InternalType;
90 
92 
95  using AccessorType = TAccessor;
96 
99  using AccessorFunctorType = typename InternalImageType::AccessorFunctorType::template Rebind<Self>::Type;
100 
104 
106  using SizeType = typename Superclass::SizeType;
108 
110  using OffsetType = typename Superclass::OffsetType;
112 
116 
119  using SpacingType = typename Superclass::SpacingType;
120 
124 
129 
130 
137  template <typename UPixelType, unsigned int UImageDimension = TImage::ImageDimension>
138  struct Rebind
139  {
141  };
142 
143  template <typename UPixelType, unsigned int NUImageDimension = TImage::ImageDimension>
145 
146 
153  void
154  SetLargestPossibleRegion(const RegionType & region) override;
155 
159  void
160  SetBufferedRegion(const RegionType & region) override;
161 
165  void
166  SetRequestedRegion(const RegionType & region) override;
167 
172  void
173  SetRequestedRegion(const DataObject * data) override;
174 
181  const RegionType &
182  GetRequestedRegion() const override;
183 
192  const RegionType &
193  GetLargestPossibleRegion() const override;
194 
200  const RegionType &
201  GetBufferedRegion() const override;
202 
204  void
205  Allocate(bool initialize = false) override;
206 
209  void
210  Initialize() override;
211 
213  void
214  SetPixel(const IndexType & index, const PixelType & value)
215  {
216  m_PixelAccessor.Set(m_Image->GetPixel(index), value);
217  }
218 
220  PixelType
221  GetPixel(const IndexType & index) const
222  {
223  return m_PixelAccessor.Get(m_Image->GetPixel(index));
224  }
225 
227  PixelType operator[](const IndexType & index) const { return m_PixelAccessor.Get(m_Image->GetPixel(index)); }
228 
230  const OffsetValueType *
231  GetOffsetTable() const;
232 
234  IndexType
235  ComputeIndex(OffsetValueType offset) const;
236 
239  using PixelContainer = typename TImage::PixelContainer;
240  using PixelContainerPointer = typename TImage::PixelContainerPointer;
241  using PixelContainerConstPointer = typename TImage::PixelContainerConstPointer;
242 
246  {
247  return m_Image->GetPixelContainer();
248  }
249 
250  const PixelContainer *
252  {
253  return m_Image->GetPixelContainer();
254  }
255 
258  void
259  SetPixelContainer(PixelContainer * container);
260 
271  virtual void
272  Graft(const Self * imgData);
273 
276 
280  GetBufferPointer();
281 
282  const InternalPixelType *
283  GetBufferPointer() const;
284 
286  void
287  SetSpacing(const SpacingType & spacing) override;
288 
289  void
290  SetSpacing(const double * spacing /*[ImageDimension]*/) override;
291 
292  void
293  SetSpacing(const float * spacing /*[ImageDimension]*/) override;
294 
298  const SpacingType &
299  GetSpacing() const override;
300 
304  const PointType &
305  GetOrigin() const override;
306 
308  void
309  SetOrigin(const PointType origin) override;
310 
311  void
312  SetOrigin(const double * origin /*[ImageDimension]*/) override;
313 
314  void
315  SetOrigin(const float * origin /*[ImageDimension]*/) override;
316 
318  void
319  SetDirection(const DirectionType & direction) override;
320 
324  const DirectionType &
325  GetDirection() const override;
326 
328  virtual void
329  SetImage(TImage *);
330 
332  void
333  Modified() const override;
334 
337  GetMTime() const override;
338 
340  AccessorType &
342  {
343  return m_PixelAccessor;
344  }
345 
347  const AccessorType &
349  {
350  return m_PixelAccessor;
351  }
352 
354  void
355  SetPixelAccessor(const AccessorType & accessor)
356  {
357  m_PixelAccessor = accessor;
358  }
359 
361  void
362  Update() override;
363 
364  void
365  CopyInformation(const DataObject * data) override;
366 
369  void
370  UpdateOutputInformation() override;
371 
372  void
373  SetRequestedRegionToLargestPossibleRegion() override;
374 
375  void
376  PropagateRequestedRegion() override;
377 
378  void
379  UpdateOutputData() override;
380 
381  bool
382  VerifyRequestedRegion() override;
383 
388  template <typename TCoordRep>
389  bool
392  {
393  return m_Image->TransformPhysicalPointToContinuousIndex(point, index);
394  }
395 
400  template <typename TCoordRep>
401  bool
403  {
404  return m_Image->TransformPhysicalPointToIndex(point, index);
405  }
406 
411  template <typename TCoordRep>
412  void
415  {
416  m_Image->TransformContinuousIndexToPhysicalPoint(index, point);
417  }
418 
424  template <typename TCoordRep>
425  void
427  {
428  m_Image->TransformIndexToPhysicalPoint(index, point);
429  }
430 
431  template <typename TCoordRep>
432  void
434  FixedArray<TCoordRep, Self::ImageDimension> & outputGradient) const
435  {
436  m_Image->TransformLocalVectorToPhysicalVector(inputGradient, outputGradient);
437  }
438 
439  template <typename TVector>
440  TVector
441  TransformLocalVectorToPhysicalVector(const TVector & inputGradient) const
442  {
443  TVector outputGradient;
444  TransformLocalVectorToPhysicalVector(inputGradient, outputGradient);
445  return outputGradient;
446  }
447 
448  template <typename TCoordRep>
449  void
451  FixedArray<TCoordRep, Self::ImageDimension> & outputGradient) const
452  {
453  m_Image->TransformPhysicalVectorToLocalVector(inputGradient, outputGradient);
454  }
455 
456  template <typename TVector>
457  TVector
458  TransformPhysicalVectorToLocalVector(const TVector & inputGradient) const
459  {
460  TVector outputGradient;
461  TransformPhysicalVectorToLocalVector(inputGradient, outputGradient);
462  return outputGradient;
463  }
464 
465 protected:
466  ImageAdaptor();
467  ~ImageAdaptor() override = default;
468  void
469  PrintSelf(std::ostream & os, Indent indent) const override;
470  void
471  Graft(const DataObject * data) override;
472  using Superclass::Graft;
473 
474 private:
475  // a specialized method to update PixelAccessors for VectorImages,
476  // to have the correct vector length of the image.
477  template <typename TPixelType>
478  void
479  UpdateAccessor(typename ::itk::VectorImage<TPixelType, ImageDimension> * itkNotUsed(dummy))
480  {
481  this->m_PixelAccessor.SetVectorLength(this->m_Image->GetNumberOfComponentsPerPixel());
482  }
483 
484  // The other image types don't expect an accessor which needs any updates
485  template <typename T>
486  void
487  UpdateAccessor(T * itkNotUsed(dummy))
488  {}
489 
490  // Adapted image, most of the calls to ImageAdaptor
491  // will be delegated to this image
492  typename TImage::Pointer m_Image;
493 
494  // Data accessor object,
495  // it converts the presentation of a pixel
497 };
498 } // end namespace itk
499 
500 #ifndef ITK_MANUAL_INSTANTIATION
501 # include "itkImageAdaptor.hxx"
502 #endif
503 
504 #endif
itk::ImageAdaptor::GetPixel
PixelType GetPixel(const IndexType &index) const
Definition: itkImageAdaptor.h:221
itk::ImageBase< TImage::ImageDimension >::OffsetValueType
typename OffsetType::OffsetValueType OffsetValueType
Definition: itkImageBase.h:138
itk::ImageAdaptor< TImage, Accessor::AddPixelAccessor< TImage::PixelType > >::PixelContainerConstPointer
typename TImage::PixelContainerConstPointer PixelContainerConstPointer
Definition: itkImageAdaptor.h:241
itk::Index< VImageDimension >
itk::ImageAdaptor< TImage, Accessor::AddPixelAccessor< TImage::PixelType > >::InternalImageType
TImage InternalImageType
Definition: itkImageAdaptor.h:78
itk::GTest::TypedefsAndConstructors::Dimension2::DirectionType
ImageBaseType::DirectionType DirectionType
Definition: itkGTestTypedefsAndConstructors.h:52
itk::ModifiedTimeType
SizeValueType ModifiedTimeType
Definition: itkIntTypes.h:102
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:69
itk::ImageAdaptor< TImage, Accessor::AddPixelAccessor< TImage::PixelType > >::PixelContainer
typename TImage::PixelContainer PixelContainer
Definition: itkImageAdaptor.h:239
itk::ImageBase
Base class for templated image classes.
Definition: itkImageBase.h:105
itk::ImageAdaptor::m_PixelAccessor
AccessorType m_PixelAccessor
Definition: itkImageAdaptor.h:496
itk::ImageAdaptor::m_Image
TImage::Pointer m_Image
Definition: itkImageAdaptor.h:492
itk::ImageRegion
An image region represents a structured region of data.
Definition: itkImageRegion.h:69
itk::ImageAdaptor::TransformLocalVectorToPhysicalVector
TVector TransformLocalVectorToPhysicalVector(const TVector &inputGradient) const
Definition: itkImageAdaptor.h:441
itk::ImageBase< TImage::ImageDimension >::SizeValueType
typename SizeType::SizeValueType SizeValueType
Definition: itkImageBase.h:142
itk::ImageAdaptor< TImage, Accessor::AddPixelAccessor< TImage::PixelType > >::InternalPixelType
typename Accessor::AddPixelAccessor< TImage::PixelType > ::InternalType InternalPixelType
Definition: itkImageAdaptor.h:89
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::Vector< SpacingValueType, VImageDimension >
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::ImageAdaptor::TransformPhysicalPointToIndex
bool TransformPhysicalPointToIndex(const Point< TCoordRep, Self::ImageDimension > &point, IndexType &index) const
Definition: itkImageAdaptor.h:402
itkImage.h
itk::ImageAdaptor::UpdateAccessor
void UpdateAccessor(T *)
Definition: itkImageAdaptor.h:487
itk::ImageAdaptor::TransformLocalVectorToPhysicalVector
void TransformLocalVectorToPhysicalVector(const FixedArray< TCoordRep, Self::ImageDimension > &inputGradient, FixedArray< TCoordRep, Self::ImageDimension > &outputGradient) const
Definition: itkImageAdaptor.h:433
itk::ImageAdaptor< TImage, Accessor::AddPixelAccessor< TImage::PixelType > >::InternalPixelPointerType
InternalPixelType * InternalPixelPointerType
Definition: itkImageAdaptor.h:275
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ImageAdaptor::GetPixelContainer
const PixelContainer * GetPixelContainer() const
Definition: itkImageAdaptor.h:251
itk::ImageBase< TImage::ImageDimension >::IndexValueType
typename IndexType::IndexValueType IndexValueType
Definition: itkImageBase.h:133
itk::ImageAdaptor::operator[]
PixelType operator[](const IndexType &index) const
Definition: itkImageAdaptor.h:227
itk::ImageAdaptor
Give access to partial aspects of voxels from an Image.
Definition: itkImageAdaptor.h:56
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageAdaptor::Rebind
Definition: itkImageAdaptor.h:138
itk::ImageAdaptor::TransformPhysicalVectorToLocalVector
TVector TransformPhysicalVectorToLocalVector(const TVector &inputGradient) const
Definition: itkImageAdaptor.h:458
itk::ImageAdaptor::TransformPhysicalPointToContinuousIndex
bool TransformPhysicalPointToContinuousIndex(const Point< TCoordRep, Self::ImageDimension > &point, ContinuousIndex< TCoordRep, Self::ImageDimension > &index) const
Get the continuous index from a physical point.
Definition: itkImageAdaptor.h:390
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ImageAdaptor< TImage, Accessor::AddPixelAccessor< TImage::PixelType > >::AccessorFunctorType
typename InternalImageType::AccessorFunctorType::template Rebind< Self >::Type AccessorFunctorType
Definition: itkImageAdaptor.h:99
itk::ImageAdaptor::SetPixelAccessor
void SetPixelAccessor(const AccessorType &accessor)
Definition: itkImageAdaptor.h:355
itk::ImageAdaptor::TransformIndexToPhysicalPoint
void TransformIndexToPhysicalPoint(const IndexType &index, Point< TCoordRep, Self::ImageDimension > &point) const
Definition: itkImageAdaptor.h:426
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:52
itk::Matrix< SpacePrecisionType, VImageDimension, VImageDimension >
itk::ImageAdaptor< TImage, Accessor::AddPixelAccessor< TImage::PixelType > >::PixelContainerPointer
typename TImage::PixelContainerPointer PixelContainerPointer
Definition: itkImageAdaptor.h:240
itk::ImageAdaptor< TImage, Accessor::AddPixelAccessor< TImage::PixelType > >::PixelType
typename Accessor::AddPixelAccessor< TImage::PixelType > ::ExternalType PixelType
Definition: itkImageAdaptor.h:85
itk::Offset
Represent a n-dimensional offset between two n-dimensional indexes of n-dimensional image.
Definition: itkOffset.h:67
itk::ImageAdaptor::TransformPhysicalVectorToLocalVector
void TransformPhysicalVectorToLocalVector(const FixedArray< TCoordRep, Self::ImageDimension > &inputGradient, FixedArray< TCoordRep, Self::ImageDimension > &outputGradient) const
Definition: itkImageAdaptor.h:450
itk::ImageAdaptor::UpdateAccessor
void UpdateAccessor(typename ::itk::VectorImage< TPixelType, ImageDimension > *)
Definition: itkImageAdaptor.h:479
itk::WeakPointer
Implements a weak reference to an object.
Definition: itkWeakPointer.h:44
itk::ImageAdaptor::TransformContinuousIndexToPhysicalPoint
void TransformContinuousIndexToPhysicalPoint(const ContinuousIndex< TCoordRep, Self::ImageDimension > &index, Point< TCoordRep, Self::ImageDimension > &point) const
Definition: itkImageAdaptor.h:413
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ContinuousIndex< TCoordRep, Self::ImageDimension >
itk::OffsetValueType
signed long OffsetValueType
Definition: itkIntTypes.h:94
itk::IndexValueType
signed long IndexValueType
Definition: itkIntTypes.h:90
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::ImageAdaptor::SetPixel
void SetPixel(const IndexType &index, const PixelType &value)
Definition: itkImageAdaptor.h:214
itk::Point< PointValueType, VImageDimension >
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86
itk::Accessor::AddPixelAccessor< TImage::PixelType >
itk::ImageAdaptor::GetPixelAccessor
AccessorType & GetPixelAccessor()
Definition: itkImageAdaptor.h:341
itk::ImageAdaptor::GetPixelAccessor
const AccessorType & GetPixelAccessor() const
Definition: itkImageAdaptor.h:348
itk::ImageAdaptor::GetPixelContainer
PixelContainerPointer GetPixelContainer()
Definition: itkImageAdaptor.h:245
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::ImageAdaptor< TImage, Accessor::AddPixelAccessor< TImage::PixelType > >::IOPixelType
PixelType IOPixelType
Definition: itkImageAdaptor.h:91
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293