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_ZIP_HPP__
47 #define __OPENCV_CUDEV_PTR2D_ZIP_HPP__
48
49 #include "../common.hpp"
50 #include "../util/tuple.hpp"
51 #include "traits.hpp"
52
53 namespace cv { namespace cudev {
54
55 //! @addtogroup cudev
56 //! @{
57
58 template <class PtrTuple> struct ZipPtr;
59
60 template <class Ptr0, class Ptr1> struct ZipPtr< tuple<Ptr0, Ptr1> > : tuple<Ptr0, Ptr1>
61 {
62 typedef tuple<typename PtrTraits<Ptr0>::value_type,
63 typename PtrTraits<Ptr1>::value_type> value_type;
64 typedef typename PtrTraits<Ptr0>::index_type index_type;
65
ZipPtrcv::cudev::ZipPtr66 __host__ __device__ __forceinline__ ZipPtr() {}
ZipPtrcv::cudev::ZipPtr67 __host__ __device__ __forceinline__ ZipPtr(const tuple<Ptr0, Ptr1>& t) : tuple<Ptr0, Ptr1>(t) {}
68
operator ()cv::cudev::ZipPtr69 __device__ __forceinline__ value_type operator ()(index_type y, index_type x) const
70 {
71 return make_tuple(cv::cudev::get<0>(*this)(y, x), cv::cudev::get<1>(*this)(y, x));
72 }
73 };
74
75 template <class Ptr0, class Ptr1, class Ptr2> struct ZipPtr< tuple<Ptr0, Ptr1, Ptr2> > : tuple<Ptr0, Ptr1, Ptr2>
76 {
77 typedef tuple<typename PtrTraits<Ptr0>::value_type,
78 typename PtrTraits<Ptr1>::value_type,
79 typename PtrTraits<Ptr2>::value_type> value_type;
80 typedef typename PtrTraits<Ptr0>::index_type index_type;
81
ZipPtrcv::cudev::ZipPtr82 __host__ __device__ __forceinline__ ZipPtr() {}
ZipPtrcv::cudev::ZipPtr83 __host__ __device__ __forceinline__ ZipPtr(const tuple<Ptr0, Ptr1, Ptr2>& t) : tuple<Ptr0, Ptr1, Ptr2>(t) {}
84
operator ()cv::cudev::ZipPtr85 __device__ __forceinline__ value_type operator ()(index_type y, index_type x) const
86 {
87 return make_tuple(cv::cudev::get<0>(*this)(y, x), cv::cudev::get<1>(*this)(y, x), cv::cudev::get<2>(*this)(y, x));
88 }
89 };
90
91 template <class Ptr0, class Ptr1, class Ptr2, class Ptr3> struct ZipPtr< tuple<Ptr0, Ptr1, Ptr2, Ptr3> > : tuple<Ptr0, Ptr1, Ptr2, Ptr3>
92 {
93 typedef tuple<typename PtrTraits<Ptr0>::value_type,
94 typename PtrTraits<Ptr1>::value_type,
95 typename PtrTraits<Ptr2>::value_type,
96 typename PtrTraits<Ptr3>::value_type> value_type;
97 typedef typename PtrTraits<Ptr0>::index_type index_type;
98
ZipPtrcv::cudev::ZipPtr99 __host__ __device__ __forceinline__ ZipPtr() {}
ZipPtrcv::cudev::ZipPtr100 __host__ __device__ __forceinline__ ZipPtr(const tuple<Ptr0, Ptr1, Ptr2, Ptr3>& t) : tuple<Ptr0, Ptr1, Ptr2, Ptr3>(t) {}
101
operator ()cv::cudev::ZipPtr102 __device__ __forceinline__ value_type operator ()(index_type y, index_type x) const
103 {
104 return make_tuple(cv::cudev::get<0>(*this)(y, x), cv::cudev::get<1>(*this)(y, x), cv::cudev::get<2>(*this)(y, x), cv::cudev::get<3>(*this)(y, x));
105 }
106 };
107
108 template <class PtrTuple> struct ZipPtrSz : ZipPtr<PtrTuple>
109 {
110 int rows, cols;
111
ZipPtrSzcv::cudev::ZipPtrSz112 __host__ __device__ __forceinline__ ZipPtrSz() {}
ZipPtrSzcv::cudev::ZipPtrSz113 __host__ __device__ __forceinline__ ZipPtrSz(const PtrTuple& t) : ZipPtr<PtrTuple>(t) {}
114 };
115
116 template <class Ptr0, class Ptr1>
117 __host__ ZipPtrSz< tuple<typename PtrTraits<Ptr0>::ptr_type, typename PtrTraits<Ptr1>::ptr_type> >
zipPtr(const Ptr0 & ptr0,const Ptr1 & ptr1)118 zipPtr(const Ptr0& ptr0, const Ptr1& ptr1)
119 {
120 const int rows = getRows(ptr0);
121 const int cols = getCols(ptr0);
122
123 CV_Assert( getRows(ptr1) == rows && getCols(ptr1) == cols );
124
125 ZipPtrSz< tuple<typename PtrTraits<Ptr0>::ptr_type, typename PtrTraits<Ptr1>::ptr_type> >
126 z(make_tuple(shrinkPtr(ptr0), shrinkPtr(ptr1)));
127 z.rows = rows;
128 z.cols = cols;
129
130 return z;
131 }
132
133 template <class Ptr0, class Ptr1, class Ptr2>
134 __host__ ZipPtrSz< tuple<typename PtrTraits<Ptr0>::ptr_type, typename PtrTraits<Ptr1>::ptr_type, typename PtrTraits<Ptr2>::ptr_type> >
zipPtr(const Ptr0 & ptr0,const Ptr1 & ptr1,const Ptr2 & ptr2)135 zipPtr(const Ptr0& ptr0, const Ptr1& ptr1, const Ptr2& ptr2)
136 {
137 const int rows = getRows(ptr0);
138 const int cols = getCols(ptr0);
139
140 CV_Assert( getRows(ptr1) == rows && getCols(ptr1) == cols );
141 CV_Assert( getRows(ptr2) == rows && getCols(ptr2) == cols );
142
143 ZipPtrSz< tuple<typename PtrTraits<Ptr0>::ptr_type, typename PtrTraits<Ptr1>::ptr_type, typename PtrTraits<Ptr2>::ptr_type> >
144 z(make_tuple(shrinkPtr(ptr0), shrinkPtr(ptr1), shrinkPtr(ptr2)));
145 z.rows = rows;
146 z.cols = cols;
147
148 return z;
149 }
150
151 template <class Ptr0, class Ptr1, class Ptr2, class Ptr3>
152 __host__ ZipPtrSz< tuple<typename PtrTraits<Ptr0>::ptr_type, typename PtrTraits<Ptr1>::ptr_type, typename PtrTraits<Ptr2>::ptr_type, typename PtrTraits<Ptr3>::ptr_type> >
zipPtr(const Ptr0 & ptr0,const Ptr1 & ptr1,const Ptr2 & ptr2,const Ptr3 & ptr3)153 zipPtr(const Ptr0& ptr0, const Ptr1& ptr1, const Ptr2& ptr2, const Ptr3& ptr3)
154 {
155 const int rows = getRows(ptr0);
156 const int cols = getCols(ptr0);
157
158 CV_Assert( getRows(ptr1) == rows && getCols(ptr1) == cols );
159 CV_Assert( getRows(ptr2) == rows && getCols(ptr2) == cols );
160 CV_Assert( getRows(ptr3) == rows && getCols(ptr3) == cols );
161
162 ZipPtrSz< tuple<typename PtrTraits<Ptr0>::ptr_type, typename PtrTraits<Ptr1>::ptr_type, typename PtrTraits<Ptr2>::ptr_type, typename PtrTraits<Ptr3>::ptr_type> >
163 z(make_tuple(shrinkPtr(ptr0), shrinkPtr(ptr1), shrinkPtr(ptr2), shrinkPtr(ptr3)));
164 z.rows = rows;
165 z.cols = cols;
166
167 return z;
168 }
169
170 template <class PtrTuple> struct PtrTraits< ZipPtrSz<PtrTuple> > : PtrTraitsBase<ZipPtrSz<PtrTuple>, ZipPtr<PtrTuple> >
171 {
172 };
173
174 //! @}
175
176 }}
177
178 #endif
179