Image Utilities (IU)
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Groups Pages
volume_allocator_cpu.h
1 #pragma once
2 
3 #include <assert.h>
4 #include <cuda_runtime.h>
5 #include "coredefs.h"
6 
7 namespace iuprivate {
8 
9 //--------------------------------------------------------------------------
10 template <typename PixelType>
12 {
13 public:
14  static PixelType* alloc(unsigned int width, unsigned int height, unsigned int depth, size_t *pitch)
15  {
16  if ((width==0) || (height==0) || (depth==0))
17  throw IuException("width, height or depth is 0", __FILE__,__FUNCTION__, __LINE__);
18  PixelType *buffer = new PixelType[width*height*depth];
19  *pitch = width * sizeof(PixelType);
20  return buffer;
21  }
22 
23  static void free(PixelType *buffer)
24  {
25  delete[] buffer;
26  }
27 
28  static void copy(const PixelType *src, size_t src_pitch,
29  PixelType *dst, size_t dst_pitch, iu::Size<3> size)
30  {
31  size_t src_stride = src_pitch/sizeof(PixelType);
32  size_t dst_stride = dst_pitch/sizeof(PixelType);
33 
34  for(unsigned int z=0; z<size.depth; ++z)
35  {
36  for(unsigned int y=0; y<size.height; ++y)
37  {
38  for(unsigned int x=0; x<size.width; ++x)
39  {
40  dst[z*dst_stride*size.height + y*dst_stride + x] =
41  src[z*src_stride*size.height + y*src_stride + x];
42  }
43  }
44  }
45  }
46 };
47 
48 } // namespace iuprivate
49 
unsigned int & depth
Definition: vector.h:613
unsigned int & height
Definition: vector.h:611
Exceptions with additional error information.
Definition: coredefs.h:32
Template specialization for 3-d unsigned int vectors (size vectors).
Definition: vector.h:605
unsigned int & width
Definition: vector.h:609
Definition: volume_allocator_cpu.h:11