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 // Copyright (C) 2013, OpenCV Foundation, all rights reserved. 16 // Third party copyrights are property of their respective owners. 17 // 18 // Redistribution and use in source and binary forms, with or without modification, 19 // are permitted provided that the following conditions are met: 20 // 21 // * Redistribution's of source code must retain the above copyright notice, 22 // this list of conditions and the following disclaimer. 23 // 24 // * Redistribution's in binary form must reproduce the above copyright notice, 25 // this list of conditions and the following disclaimer in the documentation 26 // and/or other materials provided with the distribution. 27 // 28 // * The name of the copyright holders may not be used to endorse or promote products 29 // derived from this software without specific prior written permission. 30 // 31 // This software is provided by the copyright holders and contributors "as is" and 32 // any express or implied warranties, including, but not limited to, the implied 33 // warranties of merchantability and fitness for a particular purpose are disclaimed. 34 // In no event shall the Intel Corporation or contributors be liable for any direct, 35 // indirect, incidental, special, exemplary, or consequential damages 36 // (including, but not limited to, procurement of substitute goods or services; 37 // loss of use, data, or profits; or business interruption) however caused 38 // and on any theory of liability, whether in contract, strict liability, 39 // or tort (including negligence or otherwise) arising in any way out of 40 // the use of this software, even if advised of the possibility of such damage. 41 // 42 //M*/ 43 44 #pragma once 45 46 #ifndef __OPENCV_CUDEV_PTR2D_GLOB_HPP__ 47 #define __OPENCV_CUDEV_PTR2D_GLOB_HPP__ 48 49 #include "../common.hpp" 50 #include "traits.hpp" 51 52 namespace cv { namespace cudev { 53 54 //! @addtogroup cudev 55 //! @{ 56 57 /** @brief Structure similar to cv::cudev::GlobPtrSz but containing only a pointer and row step. 58 59 Width and height fields are excluded due to performance reasons. The structure is intended 60 for internal use or for users who write device code. 61 */ 62 template <typename T> struct GlobPtr 63 { 64 typedef T value_type; 65 typedef int index_type; 66 67 T* data; 68 69 //! stride between two consecutive rows in bytes. Step is stored always and everywhere in bytes!!! 70 size_t step; 71 72 __device__ __forceinline__ T* row(int y) { return ( T*)( ( uchar*)data + y * step); } 73 __device__ __forceinline__ const T* row(int y) const { return (const T*)( (const uchar*)data + y * step); } 74 75 __device__ __forceinline__ T& operator ()(int y, int x) { return row(y)[x]; } 76 __device__ __forceinline__ const T& operator ()(int y, int x) const { return row(y)[x]; } 77 }; 78 79 /** @brief Lightweight class encapsulating pitched memory on a GPU and passed to nvcc-compiled code (CUDA 80 kernels). 81 82 Typically, it is used internally by OpenCV and by users who write device code. You can call 83 its members from both host and device code. 84 */ 85 template <typename T> struct GlobPtrSz : GlobPtr<T> 86 { 87 int rows, cols; 88 }; 89 90 template <typename T> 91 __host__ __device__ GlobPtr<T> globPtr(T* data, size_t step) 92 { 93 GlobPtr<T> p; 94 p.data = data; 95 p.step = step; 96 return p; 97 } 98 99 template <typename T> 100 __host__ __device__ GlobPtrSz<T> globPtr(T* data, size_t step, int rows, int cols) 101 { 102 GlobPtrSz<T> p; 103 p.data = data; 104 p.step = step; 105 p.rows = rows; 106 p.cols = cols; 107 return p; 108 } 109 110 template <typename T> 111 __host__ GlobPtrSz<T> globPtr(const GpuMat& mat) 112 { 113 GlobPtrSz<T> p; 114 p.data = (T*) mat.data; 115 p.step = mat.step; 116 p.rows = mat.rows; 117 p.cols = mat.cols; 118 return p; 119 } 120 121 template <typename T> struct PtrTraits< GlobPtrSz<T> > : PtrTraitsBase<GlobPtrSz<T>, GlobPtr<T> > 122 { 123 }; 124 125 //! @} 126 127 }} 128 129 #endif 130