1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                           License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 //   * Redistribution's of source code must retain the above copyright notice,
21 //     this list of conditions and the following disclaimer.
22 //
23 //   * Redistribution's in binary form must reproduce the above copyright notice,
24 //     this list of conditions and the following disclaimer in the documentation
25 //     and/or other materials provided with the distribution.
26 //
27 //   * The name of the copyright holders may not be used to endorse or promote products
28 //     derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42 
43 #ifndef __OPENCV_CORE_CUDA_TYPES_HPP__
44 #define __OPENCV_CORE_CUDA_TYPES_HPP__
45 
46 #ifndef __cplusplus
47 #  error cuda_types.hpp header must be compiled as C++
48 #endif
49 
50 /** @file
51  * @deprecated Use @ref cudev instead.
52  */
53 
54 //! @cond IGNORED
55 
56 #ifdef __CUDACC__
57     #define __CV_CUDA_HOST_DEVICE__ __host__ __device__ __forceinline__
58 #else
59     #define __CV_CUDA_HOST_DEVICE__
60 #endif
61 
62 namespace cv
63 {
64     namespace cuda
65     {
66 
67         // Simple lightweight structures that encapsulates information about an image on device.
68         // It is intended to pass to nvcc-compiled code. GpuMat depends on headers that nvcc can't compile
69 
70         template <typename T> struct DevPtr
71         {
72             typedef T elem_type;
73             typedef int index_type;
74 
75             enum { elem_size = sizeof(elem_type) };
76 
77             T* data;
78 
DevPtrcv::cuda::DevPtr79             __CV_CUDA_HOST_DEVICE__ DevPtr() : data(0) {}
DevPtrcv::cuda::DevPtr80             __CV_CUDA_HOST_DEVICE__ DevPtr(T* data_) : data(data_) {}
81 
elemSizecv::cuda::DevPtr82             __CV_CUDA_HOST_DEVICE__ size_t elemSize() const { return elem_size; }
operator T*cv::cuda::DevPtr83             __CV_CUDA_HOST_DEVICE__ operator       T*()       { return data; }
operator const T*cv::cuda::DevPtr84             __CV_CUDA_HOST_DEVICE__ operator const T*() const { return data; }
85         };
86 
87         template <typename T> struct PtrSz : public DevPtr<T>
88         {
PtrSzcv::cuda::PtrSz89             __CV_CUDA_HOST_DEVICE__ PtrSz() : size(0) {}
PtrSzcv::cuda::PtrSz90             __CV_CUDA_HOST_DEVICE__ PtrSz(T* data_, size_t size_) : DevPtr<T>(data_), size(size_) {}
91 
92             size_t size;
93         };
94 
95         template <typename T> struct PtrStep : public DevPtr<T>
96         {
PtrStepcv::cuda::PtrStep97             __CV_CUDA_HOST_DEVICE__ PtrStep() : step(0) {}
PtrStepcv::cuda::PtrStep98             __CV_CUDA_HOST_DEVICE__ PtrStep(T* data_, size_t step_) : DevPtr<T>(data_), step(step_) {}
99 
100             size_t step;
101 
ptrcv::cuda::PtrStep102             __CV_CUDA_HOST_DEVICE__       T* ptr(int y = 0)       { return (      T*)( (      char*)DevPtr<T>::data + y * step); }
ptrcv::cuda::PtrStep103             __CV_CUDA_HOST_DEVICE__ const T* ptr(int y = 0) const { return (const T*)( (const char*)DevPtr<T>::data + y * step); }
104 
operator ()cv::cuda::PtrStep105             __CV_CUDA_HOST_DEVICE__       T& operator ()(int y, int x)       { return ptr(y)[x]; }
operator ()cv::cuda::PtrStep106             __CV_CUDA_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; }
107         };
108 
109         template <typename T> struct PtrStepSz : public PtrStep<T>
110         {
PtrStepSzcv::cuda::PtrStepSz111             __CV_CUDA_HOST_DEVICE__ PtrStepSz() : cols(0), rows(0) {}
PtrStepSzcv::cuda::PtrStepSz112             __CV_CUDA_HOST_DEVICE__ PtrStepSz(int rows_, int cols_, T* data_, size_t step_)
113                 : PtrStep<T>(data_, step_), cols(cols_), rows(rows_) {}
114 
115             template <typename U>
PtrStepSzcv::cuda::PtrStepSz116             explicit PtrStepSz(const PtrStepSz<U>& d) : PtrStep<T>((T*)d.data, d.step), cols(d.cols), rows(d.rows){}
117 
118             int cols;
119             int rows;
120         };
121 
122         typedef PtrStepSz<unsigned char> PtrStepSzb;
123         typedef PtrStepSz<float> PtrStepSzf;
124         typedef PtrStepSz<int> PtrStepSzi;
125 
126         typedef PtrStep<unsigned char> PtrStepb;
127         typedef PtrStep<float> PtrStepf;
128         typedef PtrStep<int> PtrStepi;
129 
130     }
131 }
132 
133 //! @endcond
134 
135 #endif /* __OPENCV_CORE_CUDA_TYPES_HPP__ */
136