Medical Imaging Interaction Toolkit  2024.06.99-60d9b802
Medical Imaging Interaction Toolkit
mitkImagePixelAccessor.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkImagePixelAccessor_h
14 #define mitkImagePixelAccessor_h
15 
16 #include "mitkImage.h"
17 #include "mitkImageDataItem.h"
18 
19 #include <typeinfo>
20 
21 namespace mitk
22 {
29  template <class TPixel, unsigned int VDimension = 3>
31  {
32  public:
33  typedef itk::Index<VDimension> IndexType;
36 
38  int GetDimension(int i) const { return m_ImageDataItem->GetDimension(i); }
39 
40  private:
41  friend class Image;
42 
43  protected:
49  {
50  if (iDI == nullptr)
51  {
52  m_ImageDataItem = iP->GetChannelData();
53  }
54  CheckData(iP.GetPointer());
55  }
56 
58  virtual ~ImagePixelAccessor() {}
59 
60  void CheckData( const Image *image )
61  {
62  // Check if Dimensions are correct
63  if ( m_ImageDataItem == nullptr )
64  {
65  if ( image->GetDimension() != VDimension )
66  {
67  mitkThrow() << "Invalid ImageAccessor: The Dimensions of ImageAccessor and Image are not equal."
68  << " They have to be equal if an entire image is requested."
69  << " image->GetDimension(): " << image->GetDimension() << " , VDimension: " << VDimension;
70  }
71  }
72  else
73  {
74  if ( m_ImageDataItem->GetDimension() != VDimension )
75  {
76  mitkThrow() << "Invalid ImageAccessor: The Dimensions of ImageAccessor and ImageDataItem are not equal."
77  << " m_ImageDataItem->GetDimension(): " << m_ImageDataItem->GetDimension() << " , VDimension: " << VDimension;
78  }
79  }
80 
81  if (!( image->GetPixelType() == mitk::MakePixelType< itk::Image< TPixel, VDimension > >() ||
82  image->GetPixelType() == mitk::MakePixelType< itk::VectorImage< TPixel, VDimension > >
83  ( image->GetPixelType().GetNumberOfComponents() )
84  ) )
85  {
86  mitkThrow() << "Invalid ImageAccessor: PixelTypes of Image and ImageAccessor are not equal."
87  << " image->GetPixelType(): " << typeid(image->GetPixelType()).name()
88  << "\n m_ImageDataItem->GetDimension(): " << m_ImageDataItem->GetDimension()
89  << " , VDimension: " << VDimension
90  << " , TPixel: " << typeid(TPixel).name()
91  << " , NumberOfComponents: " << image->GetPixelType().GetNumberOfComponents() << std::endl;
92  }
93  }
94 
97 
103 
109  itk::ImageRegion<VDimension> *m_SubRegion;
110 
115 
117  unsigned int GetOffset(const IndexType &idx) const
118  {
119  const unsigned int *imageDims = m_ImageDataItem->m_Dimensions;
120 
121  unsigned int offset = 0;
122  switch (VDimension)
123  {
124  case 4:
125  offset += idx[3] * imageDims[0] * imageDims[1] * imageDims[2];
126  /* FALLTHRU */
127  case 3:
128  offset += idx[2] * imageDims[0] * imageDims[1];
129  /* FALLTHRU */
130  case 2:
131  offset += idx[0] + idx[1] * imageDims[0];
132  /* FALLTHRU */
133  default:
134  break;
135  }
136  return offset;
137  }
138  };
139 }
140 
141 #endif
mitk::ImagePixelAccessor::m_SubRegion
itk::ImageRegion< VDimension > * m_SubRegion
A Subregion defines an arbitrary area within the image. If no SubRegion is defined,...
Definition: mitkImagePixelAccessor.h:109
mitk::MakePixelType
MITKCORE_EXPORT mitk::PixelType MakePixelType(vtkImageData *vtkimagedata)
deduct the PixelType for a given vtk image
mitkImage.h
mitk::ImagePixelAccessor::GetOffset
unsigned int GetOffset(const IndexType &idx) const
Definition: mitkImagePixelAccessor.h:117
mitk::ImagePixelAccessor::IndexType
itk::Index< VDimension > IndexType
Definition: mitkImagePixelAccessor.h:33
mitk::ImageDataItem
Internal class for managing references on sub-images.
Definition: mitkImageDataItem.h:43
mitk::ImagePixelAccessor::CheckData
void CheckData(const Image *image)
Definition: mitkImagePixelAccessor.h:60
mitk::Image
Image class for storing images.
Definition: mitkImage.h:69
mitk::ImagePixelAccessor::~ImagePixelAccessor
virtual ~ImagePixelAccessor()
Definition: mitkImagePixelAccessor.h:58
itk::SmartPointer< const Self >
mitk::PixelType::GetNumberOfComponents
size_t GetNumberOfComponents() const
Get the number of components of which each element consists.
mitk::ImagePixelAccessor::ImagePixelAccessor
ImagePixelAccessor(ImageConstPointer iP, const mitk::ImageDataItem *iDI)
Definition: mitkImagePixelAccessor.h:48
mitk::ImagePixelAccessor::ImageConstPointer
Image::ConstPointer ImageConstPointer
Definition: mitkImagePixelAccessor.h:35
mitk::ImagePixelAccessor::m_ImageDataItem
const ImageDataItem * m_ImageDataItem
Definition: mitkImagePixelAccessor.h:96
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::Image::GetPixelType
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
mitk::ImagePixelAccessor::GetDimension
int GetDimension(int i) const
Definition: mitkImagePixelAccessor.h:38
mitk::Image::GetDimension
unsigned int GetDimension() const
Get dimension of the image.
mitk::ImagePixelAccessor::ImagePixelAccessorType
ImagePixelAccessor< TPixel, VDimension > ImagePixelAccessorType
Definition: mitkImagePixelAccessor.h:34
mitk::ImagePixelAccessor
Provides templated image access for all inheriting classes.
Definition: mitkImagePixelAccessor.h:30
mitk::ImageDataItem::GetDimension
int GetDimension() const
Definition: mitkImageDataItem.h:93
mitkImageDataItem.h
mitkThrow
#define mitkThrow()
Definition: mitkExceptionMacro.h:27
mitk::ImagePixelAccessor::m_Options
int m_Options
Stores all extended properties of an ImageAccessor. The different flags in mitk::ImageAccessorBase::O...
Definition: mitkImagePixelAccessor.h:114
mitk::ImagePixelAccessor::m_Geometry
BaseGeometry::Pointer m_Geometry
Pointer to the used Geometry. Since Geometry can be different to the Image (if memory was forced to b...
Definition: mitkImagePixelAccessor.h:102