Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef MITKIMAGEPIXELACCESSOR_H
18 #define MITKIMAGEPIXELACCESSOR_H
19 
20 #include "mitkImage.h"
21 #include "mitkImageDataItem.h"
22 
23 namespace mitk
24 {
31  template <class TPixel, unsigned int VDimension = 3>
33  {
34  friend class Image;
35 
36  public:
40 
42  int GetDimension(int i) const { return m_ImageDataItem->GetDimension(i); }
43  protected:
45  ImagePixelAccessor(ImageConstPointer iP, const mitk::ImageDataItem *iDI) : m_ImageDataItem(iDI)
46  {
47  if (iDI == nullptr)
48  {
49  m_ImageDataItem = iP->GetChannelData();
50  }
51  CheckData(iP.GetPointer());
52  }
53 
55  virtual ~ImagePixelAccessor() {}
56  void CheckData(const Image *image)
57  {
58  // Check if Dimensions are correct
59  if (m_ImageDataItem == nullptr)
60  {
61  if (image->GetDimension() != VDimension)
62  {
63  mitkThrow() << "Invalid ImageAccessor: The Dimensions of ImageAccessor and Image are not equal. They have to "
64  "be equal if an entire image is requested";
65  }
66  }
67  else
68  {
69  if (m_ImageDataItem->GetDimension() != VDimension)
70  {
71  mitkThrow() << "Invalid ImageAccessor: The Dimensions of ImageAccessor and ImageDataItem are not equal.";
72  }
73  }
74 
75  // Check if PixelType is correct
76  if (!(image->GetPixelType() == mitk::MakePixelType<itk::Image<TPixel, VDimension>>() ||
77  image->GetPixelType() ==
78  mitk::MakePixelType<itk::VectorImage<TPixel, VDimension>>(image->GetPixelType().GetNumberOfComponents())))
79  {
80  mitkThrow() << "Invalid ImageAccessor: PixelTypes of Image and ImageAccessor are not equal";
81  }
82  }
83 
84  protected:
85  // protected members
86 
89 
95 
101  itk::ImageRegion<VDimension> *m_SubRegion;
102 
107 
109  unsigned int GetOffset(const IndexType &idx) const
110  {
111  const unsigned int *imageDims = m_ImageDataItem->m_Dimensions;
112 
113  unsigned int offset = 0;
114  switch (VDimension)
115  {
116  case 4:
117  offset += idx[3] * imageDims[0] * imageDims[1] * imageDims[2];
118  case 3:
119  offset += idx[2] * imageDims[0] * imageDims[1];
120  case 2:
121  offset += idx[0] + idx[1] * imageDims[0];
122  break;
123  }
124  return offset;
125  }
126  };
127 }
128 
129 #endif // MITKIMAGEACCESSOR_H
ImagePixelAccessor< TPixel, VDimension > ImagePixelAccessorType
int m_Options
Stores all extended properties of an ImageAccessor. The different flags in mitk::ImageAccessorBase::O...
Provides templated image access for all inheriting classes.
DataCollection - Class to facilitate loading/accessing structured data.
BaseGeometry::Pointer m_Geometry
Pointer to the used Geometry. Since Geometry can be different to the Image (if memory was forced to b...
static Vector3D offset
itk::Index< VDimension > IndexType
#define mitkThrow()
Image class for storing images.
Definition: mitkImage.h:76
void CheckData(const Image *image)
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
Definition: mitkImage.cpp:105
itk::ImageRegion< VDimension > * m_SubRegion
A Subregion defines an arbitrary area within the image. If no SubRegion is defined, the whole ImageDataItem or Image is regarded. A subregion (e.g. subvolume) can lead to non-coherent memory access where every dimension has a start- and end-offset.
Image::ConstPointer ImageConstPointer
const ImageDataItem * m_ImageDataItem
unsigned int GetOffset(const IndexType &idx) const
vcl_size_t GetNumberOfComponents() const
Get the number of components of which each element consists.
Internal class for managing references on sub-images.
unsigned int GetDimension() const
Get dimension of the image.
Definition: mitkImage.cpp:110
ImagePixelAccessor(ImageConstPointer iP, const mitk::ImageDataItem *iDI)