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_GRID_COPY_HPP__ 47 #define __OPENCV_CUDEV_GRID_COPY_HPP__ 48 49 #include "../common.hpp" 50 #include "../util/tuple.hpp" 51 #include "../ptr2d/traits.hpp" 52 #include "../ptr2d/gpumat.hpp" 53 #include "../ptr2d/glob.hpp" 54 #include "../ptr2d/mask.hpp" 55 #include "../ptr2d/zip.hpp" 56 #include "detail/copy.hpp" 57 58 namespace cv { namespace cudev { 59 60 //! @addtogroup cudev 61 //! @{ 62 63 template <class Policy, class SrcPtr, typename DstType, class MaskPtr> 64 __host__ void gridCopy_(const SrcPtr& src, GpuMat_<DstType>& dst, const MaskPtr& mask, Stream& stream = Stream::Null()) 65 { 66 const int rows = getRows(src); 67 const int cols = getCols(src); 68 69 CV_Assert( getRows(mask) == rows && getCols(mask) == cols ); 70 71 dst.create(rows, cols); 72 73 grid_copy_detail::copy<Policy>(shrinkPtr(src), shrinkPtr(dst), shrinkPtr(mask), rows, cols, StreamAccessor::getStream(stream)); 74 } 75 76 template <class Policy, class SrcPtr, typename DstType, class MaskPtr> 77 __host__ void gridCopy_(const SrcPtr& src, const GlobPtrSz<DstType>& dst, const MaskPtr& mask, Stream& stream = Stream::Null()) 78 { 79 const int rows = getRows(src); 80 const int cols = getCols(src); 81 82 CV_Assert( getRows(dst) == rows && getCols(dst) == cols ); 83 CV_Assert( getRows(mask) == rows && getCols(mask) == cols ); 84 85 grid_copy_detail::copy<Policy>(shrinkPtr(src), shrinkPtr(dst), shrinkPtr(mask), rows, cols, StreamAccessor::getStream(stream)); 86 } 87 88 template <class Policy, class SrcPtr, typename DstType> 89 __host__ void gridCopy_(const SrcPtr& src, GpuMat_<DstType>& dst, Stream& stream = Stream::Null()) 90 { 91 const int rows = getRows(src); 92 const int cols = getCols(src); 93 94 dst.create(rows, cols); 95 96 grid_copy_detail::copy<Policy>(shrinkPtr(src), shrinkPtr(dst), WithOutMask(), rows, cols, StreamAccessor::getStream(stream)); 97 } 98 99 template <class Policy, class SrcPtr, typename DstType> 100 __host__ void gridCopy_(const SrcPtr& src, const GlobPtrSz<DstType>& dst, Stream& stream = Stream::Null()) 101 { 102 const int rows = getRows(src); 103 const int cols = getCols(src); 104 105 CV_Assert( getRows(dst) == rows && getCols(dst) == cols ); 106 107 grid_copy_detail::copy<Policy>(shrinkPtr(src), shrinkPtr(dst), WithOutMask(), rows, cols, StreamAccessor::getStream(stream)); 108 } 109 110 template <class Policy, class SrcPtrTuple, typename D0, typename D1, class MaskPtr> 111 __host__ void gridCopy_(const SrcPtrTuple& src, const tuple< GpuMat_<D0>&, GpuMat_<D1>& >& dst, const MaskPtr& mask, Stream& stream = Stream::Null()) 112 { 113 CV_StaticAssert( tuple_size<SrcPtrTuple>::value == 2, "" ); 114 115 const int rows = getRows(src); 116 const int cols = getCols(src); 117 118 CV_Assert( getRows(mask) == rows && getCols(mask) == cols ); 119 120 get<0>(dst).create(rows, cols); 121 get<1>(dst).create(rows, cols); 122 123 grid_copy_detail::copy_tuple<Policy>(shrinkPtr(src), 124 shrinkPtr(zipPtr(get<0>(dst), get<1>(dst))), 125 shrinkPtr(mask), 126 rows, cols, 127 StreamAccessor::getStream(stream)); 128 } 129 130 template <class Policy, class SrcPtrTuple, typename D0, typename D1, class MaskPtr> 131 __host__ void gridCopy_(const SrcPtrTuple& src, const tuple< GlobPtrSz<D0>, GlobPtrSz<D1> >& dst, const MaskPtr& mask, Stream& stream = Stream::Null()) 132 { 133 CV_StaticAssert( tuple_size<SrcPtrTuple>::value == 2, "" ); 134 135 const int rows = getRows(src); 136 const int cols = getCols(src); 137 138 CV_Assert( getRows(get<0>(dst)) == rows && getCols(get<0>(dst)) == cols ); 139 CV_Assert( getRows(get<1>(dst)) == rows && getCols(get<1>(dst)) == cols ); 140 CV_Assert( getRows(mask) == rows && getCols(mask) == cols ); 141 142 grid_copy_detail::copy_tuple<Policy>(shrinkPtr(src), 143 shrinkPtr(zipPtr(get<0>(dst), get<1>(dst))), 144 shrinkPtr(mask), 145 rows, cols, 146 StreamAccessor::getStream(stream)); 147 } 148 149 template <class Policy, class SrcPtrTuple, typename D0, typename D1> 150 __host__ void gridCopy_(const SrcPtrTuple& src, const tuple< GpuMat_<D0>&, GpuMat_<D1>& >& dst, Stream& stream = Stream::Null()) 151 { 152 CV_StaticAssert( tuple_size<SrcPtrTuple>::value == 2, "" ); 153 154 const int rows = getRows(src); 155 const int cols = getCols(src); 156 157 get<0>(dst).create(rows, cols); 158 get<1>(dst).create(rows, cols); 159 160 grid_copy_detail::copy_tuple<Policy>(shrinkPtr(src), 161 shrinkPtr(zipPtr(get<0>(dst), get<1>(dst))), 162 WithOutMask(), 163 rows, cols, 164 StreamAccessor::getStream(stream)); 165 } 166 167 template <class Policy, class SrcPtrTuple, typename D0, typename D1> 168 __host__ void gridCopy_(const SrcPtrTuple& src, const tuple< GlobPtrSz<D0>, GlobPtrSz<D1> >& dst, Stream& stream = Stream::Null()) 169 { 170 CV_StaticAssert( tuple_size<SrcPtrTuple>::value == 2, "" ); 171 172 const int rows = getRows(src); 173 const int cols = getCols(src); 174 175 CV_Assert( getRows(get<0>(dst)) == rows && getCols(get<0>(dst)) == cols ); 176 CV_Assert( getRows(get<1>(dst)) == rows && getCols(get<1>(dst)) == cols ); 177 178 grid_copy_detail::copy_tuple<Policy>(shrinkPtr(src), 179 shrinkPtr(zipPtr(get<0>(dst), get<1>(dst))), 180 WithOutMask(), 181 rows, cols, 182 StreamAccessor::getStream(stream)); 183 } 184 185 template <class Policy, class SrcPtrTuple, typename D0, typename D1, typename D2, class MaskPtr> 186 __host__ void gridCopy_(const SrcPtrTuple& src, const tuple< GpuMat_<D0>&, GpuMat_<D1>&, GpuMat_<D2>& >& dst, const MaskPtr& mask, Stream& stream = Stream::Null()) 187 { 188 CV_StaticAssert( tuple_size<SrcPtrTuple>::value == 3, "" ); 189 190 const int rows = getRows(src); 191 const int cols = getCols(src); 192 193 CV_Assert( getRows(mask) == rows && getCols(mask) == cols ); 194 195 get<0>(dst).create(rows, cols); 196 get<1>(dst).create(rows, cols); 197 get<2>(dst).create(rows, cols); 198 199 grid_copy_detail::copy_tuple<Policy>(shrinkPtr(src), 200 shrinkPtr(zipPtr(get<0>(dst), get<1>(dst), get<2>(dst))), 201 shrinkPtr(mask), 202 rows, cols, 203 StreamAccessor::getStream(stream)); 204 } 205 206 template <class Policy, class SrcPtrTuple, typename D0, typename D1, typename D2, class MaskPtr> 207 __host__ void gridCopy_(const SrcPtrTuple& src, const tuple< GlobPtrSz<D0>, GlobPtrSz<D1>, GlobPtrSz<D2> >& dst, const MaskPtr& mask, Stream& stream = Stream::Null()) 208 { 209 CV_StaticAssert( tuple_size<SrcPtrTuple>::value == 3, "" ); 210 211 const int rows = getRows(src); 212 const int cols = getCols(src); 213 214 CV_Assert( getRows(get<0>(dst)) == rows && getCols(get<0>(dst)) == cols ); 215 CV_Assert( getRows(get<1>(dst)) == rows && getCols(get<1>(dst)) == cols ); 216 CV_Assert( getRows(get<2>(dst)) == rows && getCols(get<2>(dst)) == cols ); 217 CV_Assert( getRows(mask) == rows && getCols(mask) == cols ); 218 219 grid_copy_detail::copy_tuple<Policy>(shrinkPtr(src), 220 shrinkPtr(zipPtr(get<0>(dst), get<1>(dst), get<2>(dst))), 221 shrinkPtr(mask), 222 rows, cols, 223 StreamAccessor::getStream(stream)); 224 } 225 226 template <class Policy, class SrcPtrTuple, typename D0, typename D1, typename D2> 227 __host__ void gridCopy_(const SrcPtrTuple& src, const tuple< GpuMat_<D0>&, GpuMat_<D1>&, GpuMat_<D2>& >& dst, Stream& stream = Stream::Null()) 228 { 229 CV_StaticAssert( tuple_size<SrcPtrTuple>::value == 3, "" ); 230 231 const int rows = getRows(src); 232 const int cols = getCols(src); 233 234 get<0>(dst).create(rows, cols); 235 get<1>(dst).create(rows, cols); 236 get<2>(dst).create(rows, cols); 237 238 grid_copy_detail::copy_tuple<Policy>(shrinkPtr(src), 239 shrinkPtr(zipPtr(get<0>(dst), get<1>(dst), get<2>(dst))), 240 WithOutMask(), 241 rows, cols, 242 StreamAccessor::getStream(stream)); 243 } 244 245 template <class Policy, class SrcPtrTuple, typename D0, typename D1, typename D2> 246 __host__ void gridCopy_(const SrcPtrTuple& src, const tuple< GlobPtrSz<D0>, GlobPtrSz<D1>, GlobPtrSz<D2> >& dst, Stream& stream = Stream::Null()) 247 { 248 CV_StaticAssert( tuple_size<SrcPtrTuple>::value == 3, "" ); 249 250 const int rows = getRows(src); 251 const int cols = getCols(src); 252 253 CV_Assert( getRows(get<0>(dst)) == rows && getCols(get<0>(dst)) == cols ); 254 CV_Assert( getRows(get<1>(dst)) == rows && getCols(get<1>(dst)) == cols ); 255 CV_Assert( getRows(get<2>(dst)) == rows && getCols(get<2>(dst)) == cols ); 256 257 grid_copy_detail::copy_tuple<Policy>(shrinkPtr(src), 258 shrinkPtr(zipPtr(get<0>(dst), get<1>(dst), get<2>(dst))), 259 WithOutMask(), 260 rows, cols, 261 StreamAccessor::getStream(stream)); 262 } 263 264 template <class Policy, class SrcPtrTuple, typename D0, typename D1, typename D2, typename D3, class MaskPtr> 265 __host__ void gridCopy_(const SrcPtrTuple& src, const tuple< GpuMat_<D0>&, GpuMat_<D1>&, GpuMat_<D2>&, GpuMat_<D3>& >& dst, const MaskPtr& mask, Stream& stream = Stream::Null()) 266 { 267 CV_StaticAssert( tuple_size<SrcPtrTuple>::value == 4, "" ); 268 269 const int rows = getRows(src); 270 const int cols = getCols(src); 271 272 CV_Assert( getRows(mask) == rows && getCols(mask) == cols ); 273 274 get<0>(dst).create(rows, cols); 275 get<1>(dst).create(rows, cols); 276 get<2>(dst).create(rows, cols); 277 get<3>(dst).create(rows, cols); 278 279 grid_copy_detail::copy_tuple<Policy>(shrinkPtr(src), 280 shrinkPtr(zipPtr(get<0>(dst), get<1>(dst), get<2>(dst), get<3>(dst))), 281 shrinkPtr(mask), 282 rows, cols, 283 StreamAccessor::getStream(stream)); 284 } 285 286 template <class Policy, class SrcPtrTuple, typename D0, typename D1, typename D2, typename D3, class MaskPtr> 287 __host__ void gridCopy_(const SrcPtrTuple& src, const tuple< GlobPtrSz<D0>, GlobPtrSz<D1>, GlobPtrSz<D2>, GlobPtrSz<D3> >& dst, const MaskPtr& mask, Stream& stream = Stream::Null()) 288 { 289 CV_StaticAssert( tuple_size<SrcPtrTuple>::value == 4, "" ); 290 291 const int rows = getRows(src); 292 const int cols = getCols(src); 293 294 CV_Assert( getRows(get<0>(dst)) == rows && getCols(get<0>(dst)) == cols ); 295 CV_Assert( getRows(get<1>(dst)) == rows && getCols(get<1>(dst)) == cols ); 296 CV_Assert( getRows(get<2>(dst)) == rows && getCols(get<2>(dst)) == cols ); 297 CV_Assert( getRows(get<3>(dst)) == rows && getCols(get<3>(dst)) == cols ); 298 CV_Assert( getRows(mask) == rows && getCols(mask) == cols ); 299 300 grid_copy_detail::copy_tuple<Policy>(shrinkPtr(src), 301 shrinkPtr(zipPtr(get<0>(dst), get<1>(dst), get<2>(dst), get<3>(dst))), 302 shrinkPtr(mask), 303 rows, cols, 304 StreamAccessor::getStream(stream)); 305 } 306 307 template <class Policy, class SrcPtrTuple, typename D0, typename D1, typename D2, typename D3> 308 __host__ void gridCopy_(const SrcPtrTuple& src, const tuple< GpuMat_<D0>&, GpuMat_<D1>&, GpuMat_<D2>&, GpuMat_<D3>& >& dst, Stream& stream = Stream::Null()) 309 { 310 CV_StaticAssert( tuple_size<SrcPtrTuple>::value == 4, "" ); 311 312 const int rows = getRows(src); 313 const int cols = getCols(src); 314 315 get<0>(dst).create(rows, cols); 316 get<1>(dst).create(rows, cols); 317 get<2>(dst).create(rows, cols); 318 get<3>(dst).create(rows, cols); 319 320 grid_copy_detail::copy_tuple<Policy>(shrinkPtr(src), 321 shrinkPtr(zipPtr(get<0>(dst), get<1>(dst), get<2>(dst), get<3>(dst))), 322 WithOutMask(), 323 rows, cols, 324 StreamAccessor::getStream(stream)); 325 } 326 327 template <class Policy, class SrcPtrTuple, typename D0, typename D1, typename D2, typename D3> 328 __host__ void gridCopy_(const SrcPtrTuple& src, const tuple< GlobPtrSz<D0>, GlobPtrSz<D1>, GlobPtrSz<D2>, GlobPtrSz<D3> >& dst, Stream& stream = Stream::Null()) 329 { 330 CV_StaticAssert( tuple_size<SrcPtrTuple>::value == 4, "" ); 331 332 const int rows = getRows(src); 333 const int cols = getCols(src); 334 335 CV_Assert( getRows(get<0>(dst)) == rows && getCols(get<0>(dst)) == cols ); 336 CV_Assert( getRows(get<1>(dst)) == rows && getCols(get<1>(dst)) == cols ); 337 CV_Assert( getRows(get<2>(dst)) == rows && getCols(get<2>(dst)) == cols ); 338 CV_Assert( getRows(get<3>(dst)) == rows && getCols(get<3>(dst)) == cols ); 339 340 grid_copy_detail::copy_tuple<Policy>(shrinkPtr(src), 341 shrinkPtr(zipPtr(get<0>(dst), get<1>(dst), get<2>(dst), get<3>(dst))), 342 WithOutMask(), 343 rows, cols, 344 StreamAccessor::getStream(stream)); 345 } 346 347 // Default Policy 348 349 struct DefaultCopyPolicy 350 { 351 enum { 352 block_size_x = 32, 353 block_size_y = 8 354 }; 355 }; 356 357 template <class SrcPtr, typename DstType, class MaskPtr> 358 __host__ void gridCopy(const SrcPtr& src, GpuMat_<DstType>& dst, const MaskPtr& mask, Stream& stream = Stream::Null()) 359 { 360 gridCopy_<DefaultCopyPolicy>(src, dst, mask, stream); 361 } 362 363 template <class SrcPtr, typename DstType, class MaskPtr> 364 __host__ void gridCopy(const SrcPtr& src, const GlobPtrSz<DstType>& dst, const MaskPtr& mask, Stream& stream = Stream::Null()) 365 { 366 gridCopy_<DefaultCopyPolicy>(src, dst, mask, stream); 367 } 368 369 template <class SrcPtr, typename DstType> 370 __host__ void gridCopy(const SrcPtr& src, GpuMat_<DstType>& dst, Stream& stream = Stream::Null()) 371 { 372 gridCopy_<DefaultCopyPolicy>(src, dst, stream); 373 } 374 375 template <class SrcPtr, typename DstType> 376 __host__ void gridCopy(const SrcPtr& src, const GlobPtrSz<DstType>& dst, Stream& stream = Stream::Null()) 377 { 378 gridCopy_<DefaultCopyPolicy>(src, dst, stream); 379 } 380 381 template <class SrcPtrTuple, typename D0, typename D1, class MaskPtr> 382 __host__ void gridCopy(const SrcPtrTuple& src, const tuple< GpuMat_<D0>&, GpuMat_<D1>& >& dst, const MaskPtr& mask, Stream& stream = Stream::Null()) 383 { 384 gridCopy_<DefaultCopyPolicy>(src, dst, mask, stream); 385 } 386 387 template <class SrcPtrTuple, typename D0, typename D1, class MaskPtr> 388 __host__ void gridCopy(const SrcPtrTuple& src, const tuple< GlobPtrSz<D0>, GlobPtrSz<D1> >& dst, const MaskPtr& mask, Stream& stream = Stream::Null()) 389 { 390 gridCopy_<DefaultCopyPolicy>(src, dst, mask, stream); 391 } 392 393 template <class SrcPtrTuple, typename D0, typename D1> 394 __host__ void gridCopy(const SrcPtrTuple& src, const tuple< GpuMat_<D0>&, GpuMat_<D1>& >& dst, Stream& stream = Stream::Null()) 395 { 396 gridCopy_<DefaultCopyPolicy>(src, dst, stream); 397 } 398 399 template <class SrcPtrTuple, typename D0, typename D1> 400 __host__ void gridCopy(const SrcPtrTuple& src, const tuple< GlobPtrSz<D0>, GlobPtrSz<D1> >& dst, Stream& stream = Stream::Null()) 401 { 402 gridCopy_<DefaultCopyPolicy>(src, dst, stream); 403 } 404 405 template <class SrcPtrTuple, typename D0, typename D1, typename D2, class MaskPtr> 406 __host__ void gridCopy(const SrcPtrTuple& src, const tuple< GpuMat_<D0>&, GpuMat_<D1>&, GpuMat_<D2>& >& dst, const MaskPtr& mask, Stream& stream = Stream::Null()) 407 { 408 gridCopy_<DefaultCopyPolicy>(src, dst, mask, stream); 409 } 410 411 template <class SrcPtrTuple, typename D0, typename D1, typename D2, class MaskPtr> 412 __host__ void gridCopy(const SrcPtrTuple& src, const tuple< GlobPtrSz<D0>, GlobPtrSz<D1>, GlobPtrSz<D2> >& dst, const MaskPtr& mask, Stream& stream = Stream::Null()) 413 { 414 gridCopy_<DefaultCopyPolicy>(src, dst, mask, stream); 415 } 416 417 template <class SrcPtrTuple, typename D0, typename D1, typename D2> 418 __host__ void gridCopy(const SrcPtrTuple& src, const tuple< GpuMat_<D0>&, GpuMat_<D1>&, GpuMat_<D2>& >& dst, Stream& stream = Stream::Null()) 419 { 420 gridCopy_<DefaultCopyPolicy>(src, dst, stream); 421 } 422 423 template <class SrcPtrTuple, typename D0, typename D1, typename D2> 424 __host__ void gridCopy(const SrcPtrTuple& src, const tuple< GlobPtrSz<D0>, GlobPtrSz<D1>, GlobPtrSz<D2> >& dst, Stream& stream = Stream::Null()) 425 { 426 gridCopy_<DefaultCopyPolicy>(src, dst, stream); 427 } 428 429 template <class SrcPtrTuple, typename D0, typename D1, typename D2, typename D3, class MaskPtr> 430 __host__ void gridCopy(const SrcPtrTuple& src, const tuple< GpuMat_<D0>&, GpuMat_<D1>&, GpuMat_<D2>&, GpuMat_<D3>& >& dst, const MaskPtr& mask, Stream& stream = Stream::Null()) 431 { 432 gridCopy_<DefaultCopyPolicy>(src, dst, mask, stream); 433 } 434 435 template <class SrcPtrTuple, typename D0, typename D1, typename D2, typename D3, class MaskPtr> 436 __host__ void gridCopy(const SrcPtrTuple& src, const tuple< GlobPtrSz<D0>, GlobPtrSz<D1>, GlobPtrSz<D2>, GlobPtrSz<D3> >& dst, const MaskPtr& mask, Stream& stream = Stream::Null()) 437 { 438 gridCopy_<DefaultCopyPolicy>(src, dst, mask, stream); 439 } 440 441 template <class SrcPtrTuple, typename D0, typename D1, typename D2, typename D3> 442 __host__ void gridCopy_(const SrcPtrTuple& src, const tuple< GpuMat_<D0>&, GpuMat_<D1>&, GpuMat_<D2>&, GpuMat_<D3>& >& dst, Stream& stream = Stream::Null()) 443 { 444 gridCopy_<DefaultCopyPolicy>(src, dst, stream); 445 } 446 447 template <class SrcPtrTuple, typename D0, typename D1, typename D2, typename D3> 448 __host__ void gridCopy_(const SrcPtrTuple& src, const tuple< GlobPtrSz<D0>, GlobPtrSz<D1>, GlobPtrSz<D2>, GlobPtrSz<D3> >& dst, Stream& stream = Stream::Null()) 449 { 450 gridCopy_<DefaultCopyPolicy>(src, dst, stream); 451 } 452 453 //! @} 454 455 }} 456 457 #endif 458