Image Utilities (IU)
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Groups Pages
volume_cpu.h
1 #pragma once
2 
3 #include "volume.h"
4 #include "volume_allocator_cpu.h"
5 
6 template<typename, int> class ndarray_ref;
7 
8 namespace iu {
12 template<typename PixelType, class Allocator>
13 class VolumeCpu : public Volume
14 {
15 public:
17  typedef PixelType pixel_type;
18 
21  Volume(),
22  data_(0), pitch_(0), ext_data_pointer_(false)
23  {
24  }
25 
27  virtual ~VolumeCpu()
28  {
29  if(!ext_data_pointer_)
30  {
31  // do not delete externally handeled data pointers.
32  Allocator::free(data_);
33  data_ = 0;
34  }
35  pitch_ = 0;
36  }
37 
43  VolumeCpu(unsigned int _width, unsigned int _height, unsigned int _depth) :
44  Volume(_width, _height, _depth),
45  data_(0), pitch_(0),
46  ext_data_pointer_(false)
47  {
48  data_ = Allocator::alloc(_width, _height, _depth, &pitch_);
49  }
50 
55  Volume(size), data_(0), pitch_(0),
56  ext_data_pointer_(false)
57  {
58  data_ = Allocator::alloc(size.width, size.height, size.depth, &pitch_);
59  }
60 
69  VolumeCpu(PixelType* _data, unsigned int _width, unsigned int _height, unsigned int _depth,
70  size_t _pitch, bool ext_data_pointer = false) :
71  Volume(_width, _height, _depth),
72  data_(0), pitch_(0), ext_data_pointer_(ext_data_pointer)
73  {
74  if(ext_data_pointer_)
75  {
76  // This uses the external data pointer as internal data pointer.
77  data_ = _data;
78  pitch_ = _pitch;
79  }
80  else
81  {
82  // allocates an internal data pointer and copies the external data onto it.
83  if(_data == 0)
84  return;
85 
86  data_ = Allocator::alloc(_width, _height, _depth, &pitch_);
87  Allocator::copy(_data, _pitch, data_, pitch_, this->size());
88  }
89  }
90 
92  size_t bytes() const
93  {
94  return depth()*height()*pitch_;
95  }
96 
98  size_t pitch() const
99  {
100  return pitch_;
101  }
102 
104  size_t slice_pitch() const
105  {
106  return height()*pitch_;
107  }
108 
110  size_t stride() const
111  {
112  return pitch_/sizeof(PixelType);
113  }
114 
116  size_t slice_stride() const
117  {
118  return height()*pitch_/sizeof(PixelType);
119  }
120 
122  virtual unsigned int bitDepth() const
123  {
124  return 8*sizeof(PixelType);
125  }
126 
128  virtual bool onDevice() const
129  {
130  return false;
131  }
132 
139  PixelType* data(int ox = 0, int oy = 0, int oz = 0)
140  {
141  return &data_[oz*slice_stride() + oy*stride() + ox];
142  }
143 
150  const PixelType* data(int ox = 0, int oy = 0, int oz = 0) const
151  {
152  return reinterpret_cast<const PixelType*>(
153  &data_[oz*slice_stride() + oy*stride() + ox]);
154  }
155 
162  {
164  }
165 
167  PixelType getPixel(unsigned int x, unsigned int y, unsigned int z)
168  {
169  return *data(x, y, z);
170  }
171 
175  thrust::pointer<PixelType, thrust::host_system_tag> begin(void)
176  {
177  return thrust::pointer<PixelType, thrust::host_system_tag>(data());
178  }
179 
183  thrust::pointer<PixelType, thrust::host_system_tag> end(void)
184  {
185  return thrust::pointer<PixelType, thrust::host_system_tag>(data()+slice_stride()*depth());
186  }
187 
190 
193 
194 protected:
195 
196 private:
198  PixelType* data_;
200  size_t pitch_;
202  bool ext_data_pointer_;
203 
204 private:
206  VolumeCpu(const VolumeCpu&);
208  VolumeCpu& operator=(const VolumeCpu&);
209 };
210 
211 } // namespace iuprivate
212 
213 
size_t bytes() const
Definition: volume_cpu.h:92
VolumeCpu()
Definition: volume_cpu.h:20
unsigned int & depth
Definition: vector.h:613
thrust::pointer< PixelType, thrust::host_system_tag > end(void)
Definition: volume_cpu.h:183
size_t stride() const
Definition: volume_cpu.h:110
PixelType pixel_type
Definition: volume_cpu.h:17
unsigned int width() const
Definition: volume.h:81
ndarray_ref< PixelType, 3 > ref() const
IUCORE_DLLAPI void copy(const LinearHostMemory_8u_C1 *src, LinearHostMemory_8u_C1 *dst)
size_t slice_stride() const
Definition: volume_cpu.h:116
unsigned int & height
Definition: vector.h:611
size_t pitch() const
Definition: volume_cpu.h:98
Template specialization for 3-d unsigned int vectors (size vectors).
Definition: vector.h:605
unsigned int height() const
Definition: volume.h:89
ImageCpu< PixelType, iuprivate::ImageAllocatorCpu< PixelType > > getSlice(int oz)
Definition: volume_cpu.h:161
Definition: image_cpu.h:7
VolumeCpu(const iu::Size< 3 > &size)
Definition: volume_cpu.h:54
unsigned int depth() const
Definition: volume.h:97
virtual bool onDevice() const
Definition: volume_cpu.h:128
VolumeCpu(unsigned int _width, unsigned int _height, unsigned int _depth)
Definition: volume_cpu.h:43
Base class for 3D volumes (pitched memory).
Definition: volume.h:29
virtual unsigned int bitDepth() const
Definition: volume_cpu.h:122
PixelType * data(int ox=0, int oy=0, int oz=0)
Definition: volume_cpu.h:139
unsigned int & width
Definition: vector.h:609
size_t slice_pitch() const
Definition: volume_cpu.h:104
virtual ~VolumeCpu()
Definition: volume_cpu.h:27
VolumeCpu(PixelType *_data, unsigned int _width, unsigned int _height, unsigned int _depth, size_t _pitch, bool ext_data_pointer=false)
Definition: volume_cpu.h:69
thrust::pointer< PixelType, thrust::host_system_tag > begin(void)
Definition: volume_cpu.h:175
const PixelType * data(int ox=0, int oy=0, int oz=0) const
Definition: volume_cpu.h:150
Host 2D image class (pitched memory).
Definition: image_cpu.h:27
PixelType getPixel(unsigned int x, unsigned int y, unsigned int z)
Definition: volume_cpu.h:167
iu::Size< 3 > size() const
Definition: volume.h:73
Host 3D volume class (pitched memory).
Definition: volume_cpu.h:13