Image Utilities (IU)
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Groups Pages
copy.h
1 #pragma once
2 
3 //
4 // W A R N I N G
5 // -------------
6 //
7 // This file is not part of the IU API. It exists purely as an
8 // implementation detail. This header file may change from version to
9 // version without notice, or even be removed.
10 //
11 
12 #include "coredefs.h"
13 #include "memorydefs.h"
14 #include "../iucutil.h"
15 
16 namespace iuprivate {
17 
18 /* ****************************************************************************
19  *
20  * 1D copy
21  *
22  **************************************************************************** */
23 
24 // 1D; copy host -> host
25 template <typename PixelType, unsigned int Ndim>
27 {
28  IU_SIZE_CHECK(src, dst);
29  memcpy(dst->data(), src->data(), dst->numel() * sizeof(PixelType));
30 }
31 
32 // 1D; copy device -> device
33 template <typename PixelType, unsigned int Ndim>
35 {
36  IU_SIZE_CHECK(src, dst);
37  IU_CUDA_SAFE_CALL(cudaMemcpy(dst->data(), src->data(), dst->numel() * sizeof(PixelType), cudaMemcpyDeviceToDevice));
38 }
39 
40 // 1D; copy host -> device
41 template <typename PixelType, unsigned int Ndim>
43 {
44  IU_SIZE_CHECK(src, dst);
45  IU_CUDA_SAFE_CALL(cudaMemcpy(dst->data(), src->data(), dst->numel() * sizeof(PixelType), cudaMemcpyHostToDevice));
46 }
47 
48 // 1D; copy device -> host
49 template <typename PixelType, unsigned int Ndim>
51 {
52  IU_SIZE_CHECK(src, dst);
53  IU_CUDA_SAFE_CALL(cudaMemcpy(dst->data(), src->data(), dst->numel() * sizeof(PixelType), cudaMemcpyDeviceToHost));
54 }
55 
56 /* ****************************************************************************
57  *
58  * 2D copy
59  *
60  **************************************************************************** */
61 
62 // 2D; copy host -> host
63 template<typename PixelType, class Allocator >
64 void copy(const iu::ImageCpu<PixelType, Allocator > *src,
66 {
67  IU_SIZE_CHECK(src, dst);
68  Allocator::copy(src->data(), src->pitch(), dst->data(), dst->pitch(), dst->size());
69 }
70 
71 // 2D; copy device -> device
72 template<typename PixelType, class Allocator >
73 void copy(const iu::ImageGpu<PixelType, Allocator > *src,
75 {
76  IU_SIZE_CHECK(src, dst);
77  Allocator::copy(src->data(), src->pitch(), dst->data(), dst->pitch(), dst->size());
78 }
79 
80 // 2D; copy host -> device
81 template<typename PixelType, class AllocatorCpu, class AllocatorGpu >
82 void copy(const iu::ImageCpu<PixelType, AllocatorCpu > *src,
84 {
85  IU_SIZE_CHECK(src, dst);
86  IU_CUDA_SAFE_CALL(cudaMemcpy2D(dst->data(), dst->pitch(),
87  src->data(), src->pitch(),
88  src->width() * sizeof(PixelType), src->height(),
89  cudaMemcpyHostToDevice));
90 }
91 
92 // 2D; copy device -> host
93 template<typename PixelType, class AllocatorGpu, class AllocatorCpu >
94 void copy(const iu::ImageGpu<PixelType, AllocatorGpu > *src,
96 {
97  IU_SIZE_CHECK(src, dst);
98  IU_CUDA_SAFE_CALL(cudaMemcpy2D(dst->data(), dst->pitch(),
99  src->data(), src->pitch(),
100  src->width() * sizeof(PixelType), src->height(),
101  cudaMemcpyDeviceToHost));
102 }
103 
104 /* ****************************************************************************
105  *
106  * 3D copy
107  *
108  **************************************************************************** */
109 
110 // 3D; copy host -> host
111 template<typename PixelType, class Allocator >
112 void copy(const iu::VolumeCpu<PixelType, Allocator > *src,
114 {
115  IU_SIZE_CHECK(src, dst);
116  Allocator::copy(src->data(), src->pitch(), dst->data(), dst->pitch(), dst->size());
117 }
118 
119 // 3D; copy device -> device
120 template<typename PixelType, class Allocator >
121 void copy(const iu::VolumeGpu<PixelType, Allocator > *src,
123 {
124  IU_SIZE_CHECK(src, dst);
125  Allocator::copy(src->data(), src->pitch(), dst->data(), dst->pitch(), dst->size());
126 }
127 
128 // 3D; copy host -> device
129 template<typename PixelType, class AllocatorCpu, class AllocatorGpu >
130 void copy(const iu::VolumeCpu<PixelType, AllocatorCpu > *src,
132 {
133  IU_SIZE_CHECK(src, dst);
134  IU_CUDA_SAFE_CALL(cudaMemcpy2D(dst->data(), dst->pitch(),
135  src->data(), src->pitch(),
136  src->width() * sizeof(PixelType), src->height()*src->depth(),
137  cudaMemcpyHostToDevice));
138 }
139 
140 // 3D; copy device -> host
141 template<typename PixelType, class AllocatorGpu, class AllocatorCpu >
142 void copy(const iu::VolumeGpu<PixelType, AllocatorGpu > *src,
144 {
145  IU_SIZE_CHECK(src, dst);
146  IU_CUDA_SAFE_CALL(cudaMemcpy2D(dst->data(), dst->pitch(),
147  src->data(), src->pitch(),
148  src->width() * sizeof(PixelType), src->height()*src->depth(),
149  cudaMemcpyDeviceToHost));
150 }
151 
152 template<typename PixelType, class AllocatorCpu >
154 {
155  IU_SIZE_CHECK(src, dst);
156  PixelType *dstData = dst->data();
157  for(unsigned int y = 0; y < src->height(); ++y)
158  {
159  for(unsigned int x = 0; x < src->width(); ++x)
160  {
161  dstData[x + y * src->width()] = *(src->data(x, y));
162  }
163  }
164 }
165 
166 // only declaration
167 void copy(const iu::ImageGpu_32f_C1* src, iu::LinearDeviceMemory_32f_C1* dst);
168 
169 
170 } // namespace iuprivate
171 
iu::Size< 2 > size() const
Definition: image.h:64
PixelType * data(unsigned int offset=0)
Definition: lineardevicememory.h:130
unsigned int width() const
Definition: volume.h:81
IUCORE_DLLAPI void copy(const LinearHostMemory_8u_C1 *src, LinearHostMemory_8u_C1 *dst)
unsigned int numel() const
Definition: linearmemory.h:105
Linear host memory class.
Definition: linearhostmemory.h:33
size_t pitch() const
Definition: volume_gpu.h:99
size_t pitch() const
Definition: volume_cpu.h:98
unsigned int height() const
Definition: volume.h:89
unsigned int depth() const
Definition: volume.h:97
PixelType * data(int ox=0, int oy=0, int oz=0)
Definition: volume_gpu.h:141
virtual size_t pitch() const
Definition: image_cpu.h:142
PixelType * data(int ox=0, int oy=0, int oz=0)
Definition: volume_cpu.h:139
unsigned int width() const
Definition: image.h:72
Linear device memory class.
Definition: lineardevicememory.h:18
virtual size_t pitch() const
Definition: image_gpu.h:127
Device 2D image class (pitched memory).
Definition: image_gpu.h:34
PixelType * data(int ox=0, int oy=0)
Definition: image_cpu.h:103
Host 2D image class (pitched memory).
Definition: image_cpu.h:27
PixelType * data(int ox=0, int oy=0)
Definition: image_gpu.h:160
PixelType * data(unsigned int offset=0)
Definition: linearhostmemory.h:137
unsigned int height() const
Definition: image.h:80
iu::Size< 3 > size() const
Definition: volume.h:73
Host 3D volume class (pitched memory).
Definition: volume_cpu.h:13
Device 3D volume class (pitched memory).
Definition: volume_gpu.h:15