FAST  3.2.0
Framework for Heterogeneous Medical Image Computing and Visualization
ImageAccess.hpp
Go to the documentation of this file.
1 #pragma once
3 
4 namespace fast {
5 
6 class Image;
7 
8 class FAST_EXPORT ImageAccess {
9  public:
10  ImageAccess(void* data, std::shared_ptr<Image> image);
11  void* get();
12  template <class T>
13  T getScalarFast(uint position, uchar channel = 0) const noexcept;
14  template <class T>
15  T getScalarFast(VectorXi, uchar channel = 0) const noexcept;
16  template <class T>
17  T getScalarFast2D(Vector2i, uchar channel = 0) const noexcept;
18  template <class T>
19  T getScalarFast3D(Vector3i, uchar channel = 0) const noexcept;
20  float getScalar(uint position, uchar channel = 0) const;
21  float getScalar(VectorXi position, uchar channel = 0) const;
22  Vector4f getVector(VectorXi position) const;
23  template <class T>
24  void setScalarFast(uint position, T value, uchar channel = 0) noexcept;
25  template <class T>
26  void setScalarFast(VectorXi position, T value, uchar channel = 0) noexcept;
27  template <class T>
28  void setScalarFast2D(Vector2i position, T value, uchar channel = 0) noexcept;
29  template <class T>
30  void setScalarFast3D(Vector3i position, T value, uchar channel = 0) noexcept;
31  void setScalar(uint position, float value, uchar channel = 0);
32  void setScalar(VectorXi position, float value, uchar channel = 0);
33  void setVector(uint position, Vector4f value);
34  void setVector(VectorXi position, Vector4f value);
35  void release();
36  ~ImageAccess();
37  typedef std::unique_ptr<ImageAccess> pointer;
38  private:
39  ImageAccess(const ImageAccess::pointer other) = delete;
40  ImageAccess::pointer operator=(const ImageAccess::pointer other) = delete;
41  void* mData;
42  const int m_width, m_height, m_depth, m_channels, m_dimensions;
43 
44  std::shared_ptr<Image> mImage;
45 };
46 
47 template <class T>
48 T ImageAccess::getScalarFast(uint position, uchar channel) const noexcept {
49  return ((T*)mData)[position * m_channels + channel];
50 }
51 
52 template <class T>
53 T ImageAccess::getScalarFast(VectorXi position, uchar channel) const noexcept {
54  if(m_dimensions == 2) {
55  return ((T*)mData)[(position.x() + position.y() * m_width) * m_channels + channel];
56  } else {
57  return ((T*)mData)[(position.x() + position.y() * m_width + position.z()*m_width*m_height) * m_channels + channel];
58  }
59 }
60 
61 template <class T>
62 T ImageAccess::getScalarFast2D(Vector2i position, uchar channel) const noexcept {
63  return ((T*)mData)[(position.x() + position.y() * m_width) * m_channels + channel];
64 }
65 
66 template <class T>
67 T ImageAccess::getScalarFast3D(Vector3i position, uchar channel) const noexcept {
68  return ((T*)mData)[(position.x() + position.y() * m_width + position.z()*m_width*m_height) * m_channels + channel];
69 }
70 
71 template <class T>
72 void ImageAccess::setScalarFast(uint position, T value, uchar channel) noexcept {
73  ((T*)mData)[position * m_channels + channel] = value;
74 }
75 
76 template <class T>
77 void ImageAccess::setScalarFast(VectorXi position, T value, uchar channel) noexcept {
78  if(m_dimensions == 2) {
79  ((T*)mData)[(position.x() + position.y() * m_width) * m_channels + channel] = value;
80  } else {
81  ((T*)mData)[(position.x() + position.y() * m_width + position.z()*m_width*m_height) * m_channels + channel] = value;
82  }
83 }
84 
85 template <class T>
86 void ImageAccess::setScalarFast2D(Vector2i position, T value, uchar channel) noexcept {
87  ((T*)mData)[(position.x() + position.y() * m_width) * m_channels + channel] = value;
88 }
89 
90 template <class T>
91 void ImageAccess::setScalarFast3D(Vector3i position, T value, uchar channel) noexcept {
92  ((T*)mData)[(position.x() + position.y() * m_width + position.z()*m_width*m_height) * m_channels + channel] = value;
93 }
94 
95 
96 } // end namespace fast
fast::ImageAccess::setScalarFast3D
void setScalarFast3D(Vector3i position, T value, uchar channel=0) noexcept
Definition: ImageAccess.hpp:91
fast::ImageAccess::setScalarFast2D
void setScalarFast2D(Vector2i position, T value, uchar channel=0) noexcept
Definition: ImageAccess.hpp:86
fast
Definition: AffineTransformation.hpp:7
fast::ImageAccess::getScalarFast2D
T getScalarFast2D(Vector2i, uchar channel=0) const noexcept
Definition: ImageAccess.hpp:62
fast::ImageAccess::getScalarFast3D
T getScalarFast3D(Vector3i, uchar channel=0) const noexcept
Definition: ImageAccess.hpp:67
fast::ImageAccess::setScalarFast
void setScalarFast(uint position, T value, uchar channel=0) noexcept
Definition: ImageAccess.hpp:72
DataTypes.hpp
fast::ImageAccess
Definition: ImageAccess.hpp:8
uint
unsigned int uint
Definition: DataTypes.hpp:16
uchar
unsigned char uchar
Definition: DataTypes.hpp:14
fast::ImageAccess::pointer
std::unique_ptr< ImageAccess > pointer
Definition: ImageAccess.hpp:37
fast::ImageAccess::getScalarFast
T getScalarFast(uint position, uchar channel=0) const noexcept
Definition: ImageAccess.hpp:48