1793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/*M/////////////////////////////////////////////////////////////////////////////////////// 2793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 3793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 5793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// By downloading, copying, installing or using the software you agree to this license. 6793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// If you do not agree to this license, do not download, install, 7793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// copy or use the software. 8793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 9793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 10793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// License Agreement 11793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// For Open Source Computer Vision Library 12793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 13793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Copyright (C) 2013, OpenCV Foundation, all rights reserved. 16793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Third party copyrights are property of their respective owners. 17793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 18793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Redistribution and use in source and binary forms, with or without modification, 19793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// are permitted provided that the following conditions are met: 20793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 21793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// * Redistribution's of source code must retain the above copyright notice, 22793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// this list of conditions and the following disclaimer. 23793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 24793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// * Redistribution's in binary form must reproduce the above copyright notice, 25793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// this list of conditions and the following disclaimer in the documentation 26793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// and/or other materials provided with the distribution. 27793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 28793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// * The name of the copyright holders may not be used to endorse or promote products 29793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// derived from this software without specific prior written permission. 30793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 31793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// This software is provided by the copyright holders and contributors "as is" and 32793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// any express or implied warranties, including, but not limited to, the implied 33793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// warranties of merchantability and fitness for a particular purpose are disclaimed. 34793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// In no event shall the Intel Corporation or contributors be liable for any direct, 35793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// indirect, incidental, special, exemplary, or consequential damages 36793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// (including, but not limited to, procurement of substitute goods or services; 37793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// loss of use, data, or profits; or business interruption) however caused 38793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// and on any theory of liability, whether in contract, strict liability, 39793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// or tort (including negligence or otherwise) arising in any way out of 40793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// the use of this software, even if advised of the possibility of such damage. 41793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 42793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//M*/ 43793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 44793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#pragma once 45793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 46793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef __OPENCV_CUDEV_PTR2D_REMAP_HPP__ 47793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define __OPENCV_CUDEV_PTR2D_REMAP_HPP__ 48793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 49793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/base.hpp" 50793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "../common.hpp" 51793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "../grid/copy.hpp" 52793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "traits.hpp" 53793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "gpumat.hpp" 54793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 55793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernamespace cv { namespace cudev { 56793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 57793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @addtogroup cudev 58793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @{ 59793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 60793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate <class SrcPtr, class MapPtr> struct RemapPtr1 61793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 62793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler typedef typename PtrTraits<SrcPtr>::value_type value_type; 63793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler typedef typename PtrTraits<MapPtr>::index_type index_type; 64793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 65793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler SrcPtr src; 66793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler MapPtr map; 67793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 68793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler __device__ __forceinline__ typename PtrTraits<SrcPtr>::value_type operator ()(typename PtrTraits<MapPtr>::index_type y, typename PtrTraits<MapPtr>::index_type x) const 69793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 70793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const typename PtrTraits<MapPtr>::value_type coord = map(y, x); 71793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return src(coord.y, coord.x); 72793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 73793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}; 74793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 75793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate <class SrcPtr, class MapXPtr, class MapYPtr> struct RemapPtr2 76793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 77793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler typedef typename PtrTraits<SrcPtr>::value_type value_type; 78793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler typedef typename PtrTraits<MapXPtr>::index_type index_type; 79793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 80793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler SrcPtr src; 81793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler MapXPtr mapx; 82793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler MapYPtr mapy; 83793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 84793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler __device__ __forceinline__ typename PtrTraits<SrcPtr>::value_type operator ()(typename PtrTraits<MapXPtr>::index_type y, typename PtrTraits<MapXPtr>::index_type x) const 85793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 86793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const typename PtrTraits<MapXPtr>::value_type nx = mapx(y, x); 87793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const typename PtrTraits<MapYPtr>::value_type ny = mapy(y, x); 88793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return src(ny, nx); 89793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 90793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}; 91793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 92793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate <class SrcPtr, class MapPtr> struct RemapPtr1Sz : RemapPtr1<SrcPtr, MapPtr> 93793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 94793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int rows, cols; 95793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 96793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler template <typename T> 97793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const 98793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 99793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler gridCopy(*this, dst, stream); 100793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 101793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}; 102793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 103793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate <class SrcPtr, class MapXPtr, class MapYPtr> struct RemapPtr2Sz : RemapPtr2<SrcPtr, MapXPtr, MapYPtr> 104793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 105793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int rows, cols; 106793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 107793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler template <typename T> 108793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler __host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const 109793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 110793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler gridCopy(*this, dst, stream); 111793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 112793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}; 113793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 114793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate <class SrcPtr, class MapPtr> 115793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler__host__ RemapPtr1Sz<typename PtrTraits<SrcPtr>::ptr_type, typename PtrTraits<MapPtr>::ptr_type> 116793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerremapPtr(const SrcPtr& src, const MapPtr& map) 117793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 118793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const int rows = getRows(map); 119793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const int cols = getCols(map); 120793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 121793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler RemapPtr1Sz<typename PtrTraits<SrcPtr>::ptr_type, typename PtrTraits<MapPtr>::ptr_type> r; 122793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler r.src = shrinkPtr(src); 123793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler r.map = shrinkPtr(map); 124793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler r.rows = rows; 125793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler r.cols = cols; 126793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return r; 127793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 128793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 129793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate <class SrcPtr, class MapXPtr, class MapYPtr> 130793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler__host__ RemapPtr2Sz<typename PtrTraits<SrcPtr>::ptr_type, typename PtrTraits<MapXPtr>::ptr_type, typename PtrTraits<MapYPtr>::ptr_type> 131793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerremapPtr(const SrcPtr& src, const MapXPtr& mapx, const MapYPtr& mapy) 132793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 133793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const int rows = getRows(mapx); 134793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const int cols = getCols(mapx); 135793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 136793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler CV_Assert( getRows(mapy) == rows && getCols(mapy) == cols ); 137793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 138793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler RemapPtr2Sz<typename PtrTraits<SrcPtr>::ptr_type, typename PtrTraits<MapXPtr>::ptr_type, typename PtrTraits<MapYPtr>::ptr_type> r; 139793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler r.src = shrinkPtr(src); 140793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler r.mapx = shrinkPtr(mapx); 141793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler r.mapy = shrinkPtr(mapy); 142793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler r.rows = rows; 143793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler r.cols = cols; 144793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return r; 145793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 146793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 147793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate <class SrcPtr, class MapPtr> struct PtrTraits< RemapPtr1Sz<SrcPtr, MapPtr> > : PtrTraitsBase<RemapPtr1Sz<SrcPtr, MapPtr>, RemapPtr1<SrcPtr, MapPtr> > 148793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 149793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}; 150793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 151793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslertemplate <class SrcPtr, class MapXPtr, class MapYPtr> struct PtrTraits< RemapPtr2Sz<SrcPtr, MapXPtr, MapYPtr> > : PtrTraitsBase<RemapPtr2Sz<SrcPtr, MapXPtr, MapYPtr>, RemapPtr2<SrcPtr, MapXPtr, MapYPtr> > 152793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 153793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}; 154793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 155793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//! @} 156793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 157793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}} 158793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 159793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif 160