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_REMAP_HPP__ 47 #define __OPENCV_CUDEV_PTR2D_REMAP_HPP__ 48 49 #include "opencv2/core/base.hpp" 50 #include "../common.hpp" 51 #include "../grid/copy.hpp" 52 #include "traits.hpp" 53 #include "gpumat.hpp" 54 55 namespace cv { namespace cudev { 56 57 //! @addtogroup cudev 58 //! @{ 59 60 template <class SrcPtr, class MapPtr> struct RemapPtr1 61 { 62 typedef typename PtrTraits<SrcPtr>::value_type value_type; 63 typedef typename PtrTraits<MapPtr>::index_type index_type; 64 65 SrcPtr src; 66 MapPtr map; 67 68 __device__ __forceinline__ typename PtrTraits<SrcPtr>::value_type operator ()(typename PtrTraits<MapPtr>::index_type y, typename PtrTraits<MapPtr>::index_type x) const 69 { 70 const typename PtrTraits<MapPtr>::value_type coord = map(y, x); 71 return src(coord.y, coord.x); 72 } 73 }; 74 75 template <class SrcPtr, class MapXPtr, class MapYPtr> struct RemapPtr2 76 { 77 typedef typename PtrTraits<SrcPtr>::value_type value_type; 78 typedef typename PtrTraits<MapXPtr>::index_type index_type; 79 80 SrcPtr src; 81 MapXPtr mapx; 82 MapYPtr mapy; 83 84 __device__ __forceinline__ typename PtrTraits<SrcPtr>::value_type operator ()(typename PtrTraits<MapXPtr>::index_type y, typename PtrTraits<MapXPtr>::index_type x) const 85 { 86 const typename PtrTraits<MapXPtr>::value_type nx = mapx(y, x); 87 const typename PtrTraits<MapYPtr>::value_type ny = mapy(y, x); 88 return src(ny, nx); 89 } 90 }; 91 92 template <class SrcPtr, class MapPtr> struct RemapPtr1Sz : RemapPtr1<SrcPtr, MapPtr> 93 { 94 int rows, cols; 95 96 template <typename T> 97 __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const 98 { 99 gridCopy(*this, dst, stream); 100 } 101 }; 102 103 template <class SrcPtr, class MapXPtr, class MapYPtr> struct RemapPtr2Sz : RemapPtr2<SrcPtr, MapXPtr, MapYPtr> 104 { 105 int rows, cols; 106 107 template <typename T> 108 __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const 109 { 110 gridCopy(*this, dst, stream); 111 } 112 }; 113 114 template <class SrcPtr, class MapPtr> 115 __host__ RemapPtr1Sz<typename PtrTraits<SrcPtr>::ptr_type, typename PtrTraits<MapPtr>::ptr_type> 116 remapPtr(const SrcPtr& src, const MapPtr& map) 117 { 118 const int rows = getRows(map); 119 const int cols = getCols(map); 120 121 RemapPtr1Sz<typename PtrTraits<SrcPtr>::ptr_type, typename PtrTraits<MapPtr>::ptr_type> r; 122 r.src = shrinkPtr(src); 123 r.map = shrinkPtr(map); 124 r.rows = rows; 125 r.cols = cols; 126 return r; 127 } 128 129 template <class SrcPtr, class MapXPtr, class MapYPtr> 130 __host__ RemapPtr2Sz<typename PtrTraits<SrcPtr>::ptr_type, typename PtrTraits<MapXPtr>::ptr_type, typename PtrTraits<MapYPtr>::ptr_type> 131 remapPtr(const SrcPtr& src, const MapXPtr& mapx, const MapYPtr& mapy) 132 { 133 const int rows = getRows(mapx); 134 const int cols = getCols(mapx); 135 136 CV_Assert( getRows(mapy) == rows && getCols(mapy) == cols ); 137 138 RemapPtr2Sz<typename PtrTraits<SrcPtr>::ptr_type, typename PtrTraits<MapXPtr>::ptr_type, typename PtrTraits<MapYPtr>::ptr_type> r; 139 r.src = shrinkPtr(src); 140 r.mapx = shrinkPtr(mapx); 141 r.mapy = shrinkPtr(mapy); 142 r.rows = rows; 143 r.cols = cols; 144 return r; 145 } 146 147 template <class SrcPtr, class MapPtr> struct PtrTraits< RemapPtr1Sz<SrcPtr, MapPtr> > : PtrTraitsBase<RemapPtr1Sz<SrcPtr, MapPtr>, RemapPtr1<SrcPtr, MapPtr> > 148 { 149 }; 150 151 template <class SrcPtr, class MapXPtr, class MapYPtr> struct PtrTraits< RemapPtr2Sz<SrcPtr, MapXPtr, MapYPtr> > : PtrTraitsBase<RemapPtr2Sz<SrcPtr, MapXPtr, MapYPtr>, RemapPtr2<SrcPtr, MapXPtr, MapYPtr> > 152 { 153 }; 154 155 //! @} 156 157 }} 158 159 #endif 160