Image Utilities (IU)
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Groups Pages
memorydefs.h
1 #pragma once
2 
3 // template includes
4 #include "coredefs.h"
5 #include "vector.h"
6 
7 #include "linearhostmemory.h"
8 #include "lineardevicememory.h"
9 #include "image_allocator_cpu.h"
10 #include "image_cpu.h"
11 #include "image_allocator_gpu.h"
12 #include "image_gpu.h"
13 #include "volume_allocator_cpu.h"
14 #include "volume_cpu.h"
15 #include "volume_allocator_gpu.h"
16 #include "volume_gpu.h"
17 
18 #include "tensor_cpu.h"
19 #include "tensor_gpu.h"
20 
21 /* ***************************************************************************
22  * explicit type definitions for template classes
23  * ***************************************************************************/
24 
25 namespace iu {
26 
27 /* ****************************************************************************
28  * Linear 1D Memory.
29  * There are no typdefs for Nd linear memory any more.
30  * ****************************************************************************/
31 
32 /*
33  Host
34 */
35 // 8-bit
36 
37 typedef LinearHostMemory<unsigned char, 1> LinearHostMemory_8u_C1;
38 typedef LinearHostMemory<uchar2, 1> LinearHostMemory_8u_C2;
39 typedef LinearHostMemory<uchar3, 1> LinearHostMemory_8u_C3;
40 typedef LinearHostMemory<uchar4, 1> LinearHostMemory_8u_C4;
41 // 16-bit
42 typedef LinearHostMemory<unsigned short, 1> LinearHostMemory_16u_C1;
43 typedef LinearHostMemory<ushort2, 1> LinearHostMemory_16u_C2;
44 typedef LinearHostMemory<ushort3, 1> LinearHostMemory_16u_C3;
45 typedef LinearHostMemory<ushort4, 1> LinearHostMemory_16u_C4;
46 
47 // 32-bit
48 typedef LinearHostMemory<float, 1> LinearHostMemory_32f_C1;
49 typedef LinearHostMemory<float2, 1> LinearHostMemory_32f_C2;
50 typedef LinearHostMemory<float3, 1> LinearHostMemory_32f_C3;
51 typedef LinearHostMemory<float4, 1> LinearHostMemory_32f_C4;
52 
53 typedef LinearHostMemory<int, 1> LinearHostMemory_32s_C1;
54 typedef LinearHostMemory<int2, 1> LinearHostMemory_32s_C2;
55 typedef LinearHostMemory<int3, 1> LinearHostMemory_32s_C3;
56 typedef LinearHostMemory<int4, 1> LinearHostMemory_32s_C4;
57 
58 typedef LinearHostMemory<unsigned int, 1> LinearHostMemory_32u_C1;
59 typedef LinearHostMemory<uint2, 1> LinearHostMemory_32u_C2;
60 typedef LinearHostMemory<uint4, 1> LinearHostMemory_32u_C4;
61 
62 // 64-bit
63 typedef LinearHostMemory<double,1> LinearHostMemory_64f_C1;
64 typedef LinearHostMemory<double2,1> LinearHostMemory_64f_C2;
65 typedef LinearHostMemory<double3,1> LinearHostMemory_64f_C3;
66 typedef LinearHostMemory<double4,1> LinearHostMemory_64f_C4;
67 
68 /*
69  Device
70 */
71 // 8-bit
72 
73 typedef LinearDeviceMemory<unsigned char, 1> LinearDeviceMemory_8u_C1;
74 typedef LinearDeviceMemory<uchar2, 1> LinearDeviceMemory_8u_C2;
75 typedef LinearDeviceMemory<uchar3, 1> LinearDeviceMemory_8u_C3;
76 typedef LinearDeviceMemory<uchar4, 1> LinearDeviceMemory_8u_C4;
77 // 16-bit
78 typedef LinearDeviceMemory<unsigned short, 1> LinearDeviceMemory_16u_C1;
79 typedef LinearDeviceMemory<ushort2, 1> LinearDeviceMemory_16u_C2;
80 typedef LinearDeviceMemory<ushort3, 1> LinearDeviceMemory_16u_C3;
81 typedef LinearDeviceMemory<ushort4, 1> LinearDeviceMemory_16u_C4;
82 
83 // 32-bit
84 typedef LinearDeviceMemory<float, 1> LinearDeviceMemory_32f_C1;
85 typedef LinearDeviceMemory<float2, 1> LinearDeviceMemory_32f_C2;
86 typedef LinearDeviceMemory<float3, 1> LinearDeviceMemory_32f_C3;
87 typedef LinearDeviceMemory<float4, 1> LinearDeviceMemory_32f_C4;
88 
89 typedef LinearDeviceMemory<int, 1> LinearDeviceMemory_32s_C1;
90 typedef LinearDeviceMemory<int2, 1> LinearDeviceMemory_32s_C2;
91 typedef LinearDeviceMemory<int3, 1> LinearDeviceMemory_32s_C3;
92 typedef LinearDeviceMemory<int4, 1> LinearDeviceMemory_32s_C4;
93 
94 typedef LinearDeviceMemory<unsigned int, 1> LinearDeviceMemory_32u_C1;
95 typedef LinearDeviceMemory<uint2, 1> LinearDeviceMemory_32u_C2;
96 typedef LinearDeviceMemory<uint4, 1> LinearDeviceMemory_32u_C4;
97 
98 // 64-bit
99 typedef LinearDeviceMemory<double,1> LinearDeviceMemory_64f_C1;
100 typedef LinearDeviceMemory<double2,1> LinearDeviceMemory_64f_C2;
101 typedef LinearDeviceMemory<double3,1> LinearDeviceMemory_64f_C3;
102 typedef LinearDeviceMemory<double4,1> LinearDeviceMemory_64f_C4;
103 
104 /* ****************************************************************************
105  * 2d Image Memory
106  * ****************************************************************************/
107 
108 /*
109  Host
110 */
111 // Cpu Images; 8u
112 typedef ImageCpu<unsigned char, iuprivate::ImageAllocatorCpu<unsigned char> > ImageCpu_8u_C1;
113 typedef ImageCpu<uchar2, iuprivate::ImageAllocatorCpu<uchar2> > ImageCpu_8u_C2;
114 typedef ImageCpu<uchar3, iuprivate::ImageAllocatorCpu<uchar3> > ImageCpu_8u_C3;
115 typedef ImageCpu<uchar4, iuprivate::ImageAllocatorCpu<uchar4> > ImageCpu_8u_C4;
116 
117 // Cpu Images; 16u
118 typedef ImageCpu<unsigned short, iuprivate::ImageAllocatorCpu<unsigned short> > ImageCpu_16u_C1;
119 typedef ImageCpu<ushort2, iuprivate::ImageAllocatorCpu<ushort2> > ImageCpu_16u_C2;
120 typedef ImageCpu<ushort3, iuprivate::ImageAllocatorCpu<ushort3> > ImageCpu_16u_C3;
121 typedef ImageCpu<ushort4, iuprivate::ImageAllocatorCpu<ushort4> > ImageCpu_16u_C4;
122 
123 // Cpu Images; 32s
124 typedef ImageCpu<int, iuprivate::ImageAllocatorCpu<int> > ImageCpu_32s_C1;
125 typedef ImageCpu<int2, iuprivate::ImageAllocatorCpu<int2> > ImageCpu_32s_C2;
126 typedef ImageCpu<int3, iuprivate::ImageAllocatorCpu<int3> > ImageCpu_32s_C3;
127 typedef ImageCpu<int4, iuprivate::ImageAllocatorCpu<int4> > ImageCpu_32s_C4;
128 
129 // Cpu Images; 32u
130 typedef ImageCpu<unsigned int, iuprivate::ImageAllocatorCpu<unsigned int> > ImageCpu_32u_C1;
131 typedef ImageCpu<uint2, iuprivate::ImageAllocatorCpu<uint2> > ImageCpu_32u_C2;
132 typedef ImageCpu<uint4, iuprivate::ImageAllocatorCpu<uint4> > ImageCpu_32u_C4;
133 
134 
135 // Cpu Images; 32f
136 typedef ImageCpu<float, iuprivate::ImageAllocatorCpu<float> > ImageCpu_32f_C1;
137 typedef ImageCpu<float2, iuprivate::ImageAllocatorCpu<float2> > ImageCpu_32f_C2;
138 typedef ImageCpu<float3, iuprivate::ImageAllocatorCpu<float3> > ImageCpu_32f_C3;
139 typedef ImageCpu<float4, iuprivate::ImageAllocatorCpu<float4> > ImageCpu_32f_C4;
140 
141 // Cpu Images; 64f
142 typedef ImageCpu<double, iuprivate::ImageAllocatorCpu<double> > ImageCpu_64f_C1;
143 typedef ImageCpu<double2, iuprivate::ImageAllocatorCpu<double2> > ImageCpu_64f_C2;
144 typedef ImageCpu<double3, iuprivate::ImageAllocatorCpu<double3> > ImageCpu_64f_C3;
145 typedef ImageCpu<double4, iuprivate::ImageAllocatorCpu<double4> > ImageCpu_64f_C4;
146 
147 /*
148  Device
149 */
150 // Gpu Images; 8u
151 typedef ImageGpu<unsigned char, iuprivate::ImageAllocatorGpu<unsigned char> > ImageGpu_8u_C1;
152 typedef ImageGpu<uchar2, iuprivate::ImageAllocatorGpu<uchar2> > ImageGpu_8u_C2;
153 typedef ImageGpu<uchar3, iuprivate::ImageAllocatorGpu<uchar3> > ImageGpu_8u_C3;
154 typedef ImageGpu<uchar4, iuprivate::ImageAllocatorGpu<uchar4> > ImageGpu_8u_C4;
155 
156 // Gpu Images; 16u
157 typedef ImageGpu<unsigned short, iuprivate::ImageAllocatorGpu<unsigned short> > ImageGpu_16u_C1;
158 typedef ImageGpu<ushort2, iuprivate::ImageAllocatorGpu<ushort2> > ImageGpu_16u_C2;
159 typedef ImageGpu<ushort3, iuprivate::ImageAllocatorGpu<ushort3> > ImageGpu_16u_C3;
160 typedef ImageGpu<ushort4, iuprivate::ImageAllocatorGpu<ushort4> > ImageGpu_16u_C4;
161 
162 // Gpu Images; 32s
163 typedef ImageGpu<int, iuprivate::ImageAllocatorGpu<int> > ImageGpu_32s_C1;
164 typedef ImageGpu<int2, iuprivate::ImageAllocatorGpu<int2> > ImageGpu_32s_C2;
165 typedef ImageGpu<int3, iuprivate::ImageAllocatorGpu<int3> > ImageGpu_32s_C3;
166 typedef ImageGpu<int4, iuprivate::ImageAllocatorGpu<int4> > ImageGpu_32s_C4;
167 
168 // Gpu Images; 32u
169 typedef ImageGpu<unsigned int, iuprivate::ImageAllocatorGpu<unsigned int> > ImageGpu_32u_C1;
170 typedef ImageGpu<uint2, iuprivate::ImageAllocatorGpu<uint2> > ImageGpu_32u_C2;
171 typedef ImageGpu<uint4, iuprivate::ImageAllocatorGpu<uint4> > ImageGpu_32u_C4;
172 
173 // Gpu Images; 32f
174 typedef ImageGpu<float, iuprivate::ImageAllocatorGpu<float> > ImageGpu_32f_C1;
175 typedef ImageGpu<float2, iuprivate::ImageAllocatorGpu<float2> > ImageGpu_32f_C2;
176 typedef ImageGpu<float3, iuprivate::ImageAllocatorGpu<float3> > ImageGpu_32f_C3;
177 typedef ImageGpu<float4, iuprivate::ImageAllocatorGpu<float4> > ImageGpu_32f_C4;
178 
179 // Gpu Images; 64f
180 typedef ImageGpu<double, iuprivate::ImageAllocatorGpu<double> > ImageGpu_64f_C1;
181 typedef ImageGpu<double2, iuprivate::ImageAllocatorGpu<double2> > ImageGpu_64f_C2;
182 typedef ImageGpu<double3, iuprivate::ImageAllocatorGpu<double3> > ImageGpu_64f_C3;
183 typedef ImageGpu<double4, iuprivate::ImageAllocatorGpu<double4> > ImageGpu_64f_C4;
184 
185 
186 /* ****************************************************************************
187  * 3d Volume Memory
188  * ****************************************************************************/
189 
190 /*
191  Host
192 */
193 // Cpu Volumes; 8u
194 typedef VolumeCpu<unsigned char, iuprivate::VolumeAllocatorCpu<unsigned char> > VolumeCpu_8u_C1;
195 typedef VolumeCpu<uchar2, iuprivate::VolumeAllocatorCpu<uchar2> > VolumeCpu_8u_C2;
196 typedef VolumeCpu<uchar3, iuprivate::VolumeAllocatorCpu<uchar3> > VolumeCpu_8u_C3;
197 typedef VolumeCpu<uchar4, iuprivate::VolumeAllocatorCpu<uchar4> > VolumeCpu_8u_C4;
198 
199 // Cpu Volumes; 16u
200 typedef VolumeCpu<unsigned short, iuprivate::VolumeAllocatorCpu<unsigned short> > VolumeCpu_16u_C1;
201 
202 // Cpu Volumes; 32u
203 typedef VolumeCpu<unsigned int, iuprivate::VolumeAllocatorCpu<unsigned int> > VolumeCpu_32u_C1;
204 typedef VolumeCpu<uint2, iuprivate::VolumeAllocatorCpu<uint2> > VolumeCpu_32u_C2;
205 typedef VolumeCpu<uint4, iuprivate::VolumeAllocatorCpu<uint4> > VolumeCpu_32u_C4;
206 
207 // Cpu Volumes; 32s
208 typedef VolumeCpu<int, iuprivate::VolumeAllocatorCpu<int> > VolumeCpu_32s_C1;
209 typedef VolumeCpu<int2, iuprivate::VolumeAllocatorCpu<int2> > VolumeCpu_32s_C2;
210 typedef VolumeCpu<int4, iuprivate::VolumeAllocatorCpu<int4> > VolumeCpu_32s_C4;
211 
212 // Cpu Volumes; 32f
213 typedef VolumeCpu<float, iuprivate::VolumeAllocatorCpu<float> > VolumeCpu_32f_C1;
214 typedef VolumeCpu<float2, iuprivate::VolumeAllocatorCpu<float2> > VolumeCpu_32f_C2;
215 typedef VolumeCpu<float3, iuprivate::VolumeAllocatorCpu<float3> > VolumeCpu_32f_C3;
216 typedef VolumeCpu<float4, iuprivate::VolumeAllocatorCpu<float4> > VolumeCpu_32f_C4;
217 
218 // Cpu Volumes; 64f
219 typedef VolumeCpu<double, iuprivate::VolumeAllocatorCpu<double> > VolumeCpu_64f_C1;
220 typedef VolumeCpu<double2, iuprivate::VolumeAllocatorCpu<double2> > VolumeCpu_64f_C2;
221 typedef VolumeCpu<double3, iuprivate::VolumeAllocatorCpu<double3> > VolumeCpu_64f_C3;
222 typedef VolumeCpu<double4, iuprivate::VolumeAllocatorCpu<double4> > VolumeCpu_64f_C4;
223 
224 
225 /*
226  Device
227 */
228 // Gpu Volumes; 8u
229 typedef VolumeGpu<unsigned char, iuprivate::VolumeAllocatorGpu<unsigned char> > VolumeGpu_8u_C1;
230 typedef VolumeGpu<uchar2, iuprivate::VolumeAllocatorGpu<uchar2> > VolumeGpu_8u_C2;
231 typedef VolumeGpu<uchar3, iuprivate::VolumeAllocatorGpu<uchar3> > VolumeGpu_8u_C3;
232 typedef VolumeGpu<uchar4, iuprivate::VolumeAllocatorGpu<uchar4> > VolumeGpu_8u_C4;
233 
234 // Gpu Volumes; 16u
235 typedef VolumeGpu<unsigned short, iuprivate::VolumeAllocatorGpu<unsigned short> > VolumeGpu_16u_C1;
236 
237 // Gpu Volumes; 32u
238 typedef VolumeGpu<unsigned int, iuprivate::VolumeAllocatorGpu<unsigned int> > VolumeGpu_32u_C1;
239 typedef VolumeGpu<uint2, iuprivate::VolumeAllocatorGpu<uint2> > VolumeGpu_32u_C2;
240 typedef VolumeGpu<uint4, iuprivate::VolumeAllocatorGpu<uint4> > VolumeGpu_32u_C4;
241 
242 // Gpu Volumes; 32s
243 typedef VolumeGpu<int, iuprivate::VolumeAllocatorGpu<int> > VolumeGpu_32s_C1;
244 typedef VolumeGpu<int2, iuprivate::VolumeAllocatorGpu<int2> > VolumeGpu_32s_C2;
245 typedef VolumeGpu<int4, iuprivate::VolumeAllocatorGpu<int4> > VolumeGpu_32s_C4;
246 
247 // Gpu Volumes; 32f
248 typedef VolumeGpu<float, iuprivate::VolumeAllocatorGpu<float> > VolumeGpu_32f_C1;
249 typedef VolumeGpu<float2, iuprivate::VolumeAllocatorGpu<float2> > VolumeGpu_32f_C2;
250 typedef VolumeGpu<float3, iuprivate::VolumeAllocatorGpu<float3> > VolumeGpu_32f_C3;
251 typedef VolumeGpu<float4, iuprivate::VolumeAllocatorGpu<float4> > VolumeGpu_32f_C4;
252 
253 // Gpu Volumes; 64f
254 typedef VolumeGpu<double, iuprivate::VolumeAllocatorGpu<double> > VolumeGpu_64f_C1;
255 typedef VolumeGpu<double2, iuprivate::VolumeAllocatorGpu<double2> > VolumeGpu_64f_C2;
256 typedef VolumeGpu<double3, iuprivate::VolumeAllocatorGpu<double3> > VolumeGpu_64f_C3;
257 typedef VolumeGpu<double4, iuprivate::VolumeAllocatorGpu<double4> > VolumeGpu_64f_C4;
258 
259 
260 /* ****************************************************************************
261  * 4D Tensor
262  * ****************************************************************************/
263 
264 /*
265  Host
266 */
267 typedef TensorCpu<unsigned char> TensorCpu_8u;
268 typedef TensorCpu<unsigned short> TensorCpu_16u;
269 typedef TensorCpu<float> TensorCpu_32f;
270 typedef TensorCpu<int> TensorCpu_32s;
271 typedef TensorCpu<double> TensorCpu_64f;
272 
273 /*
274  Device
275 */
276 // 8-bit
277 typedef TensorGpu<unsigned char> TensorGpu_8u;
278 typedef TensorGpu<unsigned short> TensorGpu_16u;
279 typedef TensorGpu<float> TensorGpu_32f;
280 typedef TensorGpu<unsigned int> TensorGpu_32u;
281 typedef TensorGpu<int> TensorGpu_32s;
282 typedef TensorGpu<double> TensorGpu_64f;
283 
284 
285 /* ****************************************************************************
286  * Define size checks
287  * ****************************************************************************/
288 static inline void checkSize(const iu::Volume *volume1, const iu::Volume *volume2,
289  const char* file, const char* function, const int line)
290 {
291  if (volume1->size() != volume2->size())
292  {
293  std::stringstream msg;
294  msg << "Size mismatch! Size of first Volume is " << volume1->size() << ". ";
295  msg << "Size of second Volume is " << volume2->size();
296  throw IuException(msg.str(), file, function, line);
297  }
298 }
299 
300 static inline void checkSize(const iu::Image *image1, const iu::Image *image2,
301  const char* file, const char* function, const int line)
302 {
303  if (image1->size() != image2->size())
304  {
305  std::stringstream msg;
306  msg << "Size mismatch! Size of first Image is " << image1->size() << ". ";
307  msg << "Size of second Image is " << image2->size();
308  throw IuException(msg.str(), file, function, line);
309  }
310 }
311 
312 template<unsigned int Ndim>
313 static inline void checkSize(const iu::LinearMemory<Ndim> *linmem1, const iu::LinearMemory<Ndim> *linmem2,
314  const char* file, const char* function, const int line)
315 {
316  if (linmem1->size() != linmem2->size())
317  {
318  std::stringstream msg;
319  msg << "Size mismatch! size of first LinearMemory is " << linmem1->size() << ". ";
320  msg << "size of second LinearMemory is " << linmem2->size();
321  throw IuException(msg.str(), file, function, line);
322  }
323 }
324 
325 template<unsigned int Ndim>
326 static inline void checkSize(const iu::Size<Ndim> &size1, const iu::Size<Ndim> &size2,
327  const char* file, const char* function, const int line)
328 {
329  if (size1 != size2)
330  {
331  std::stringstream msg;
332  msg << "Size mismatch! First size is " << size1 << ". ";
333  msg << "Second size is " << size2;
334  throw IuException(msg.str(), file, function, line);
335  }
336 }
337 
338 static inline void checkSize(const iu::Image *image, const iu::LinearMemory<1> *linmem,
339  const char* file, const char* function, const int line)
340 {
341  if (image->size().width*image->size().height != linmem->numel())
342  {
343  std::stringstream msg;
344  msg << "Size mismatch! Number of elements in Image is " << image->size().width*image->size().height << ". ";
345  msg << "size of LinearMemory is " << linmem->size();
346  throw IuException(msg.str(), file, function, line);
347  }
348 }
349 
350 #define IU_SIZE_CHECK(variable1, variable2) checkSize(variable1, variable2, __FILE__, __FUNCTION__, __LINE__)
351 } // namespace iu
352 
353 
iu::Size< 2 > size() const
Definition: image.h:64
Base class for 2D images (pitched memory).
Definition: image.h:30
unsigned int & height
Definition: vector.h:531
unsigned int numel() const
Definition: linearmemory.h:105
Exceptions with additional error information.
Definition: coredefs.h:32
unsigned int & width
Definition: vector.h:529
Base class for linear memory classes.
Definition: linearmemory.h:61
Size< Ndim > size() const
Definition: linearmemory.h:121
Base class for 3D volumes (pitched memory).
Definition: volume.h:29
Main class for N-dimensional unsigned int vectors (size vectors).
Definition: vector.h:460
iu::Size< 3 > size() const
Definition: volume.h:73