1 /*M///////////////////////////////////////////////////////////////////////////////////////
\r
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
\r
5 // By downloading, copying, installing or using the software you agree to this license.
\r
6 // If you do not agree to this license, do not download, install,
\r
7 // copy or use the software.
\r
10 // License Agreement
\r
11 // For Open Source Computer Vision Library
\r
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
\r
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
\r
15 // Third party copyrights are property of their respective owners.
\r
17 // Redistribution and use in source and binary forms, with or without modification,
\r
18 // are permitted provided that the following conditions are met:
\r
20 // * Redistribution's of source code must retain the above copyright notice,
\r
21 // this list of conditions and the following disclaimer.
\r
23 // * Redistribution's in binary form must reproduce the above copyright notice,
\r
24 // this list of conditions and the following disclaimer in the documentation
\r
25 // and/or other materials provided with the distribution.
\r
27 // * The name of the copyright holders may not be used to endorse or promote products
\r
28 // derived from this software without specific prior written permission.
\r
30 // This software is provided by the copyright holders and contributors "as is" and
\r
31 // any express or implied warranties, including, but not limited to, the implied
\r
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
\r
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
\r
34 // indirect, incidental, special, exemplary, or consequential damages
\r
35 // (including, but not limited to, procurement of substitute goods or services;
\r
36 // loss of use, data, or profits; or business interruption) however caused
\r
37 // and on any theory of liability, whether in contract, strict liability,
\r
38 // or tort (including negligence or otherwise) arising in any way out of
\r
39 // the use of this software, even if advised of the possibility of such damage.
\r
43 #ifndef __OPENCV_GPU_FUNCTIONAL_HPP__
\r
44 #define __OPENCV_GPU_FUNCTIONAL_HPP__
\r
46 #include <thrust/functional.h>
\r
47 #include "saturate_cast.hpp"
\r
48 #include "vec_traits.hpp"
\r
49 #include "type_traits.hpp"
\r
51 namespace cv { namespace gpu { namespace device
\r
55 using thrust::unary_function;
\r
56 using thrust::binary_function;
\r
58 // Arithmetic Operations
\r
59 template <typename T> struct plus : binary_function<T, T, T>
\r
61 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a,
\r
62 typename TypeTraits<T>::ParameterType b) const
\r
66 __device__ __forceinline__ plus(const plus& other):binary_function<T,T,T>(){}
\r
67 __device__ __forceinline__ plus():binary_function<T,T,T>(){}
\r
70 template <typename T> struct minus : binary_function<T, T, T>
\r
72 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a,
\r
73 typename TypeTraits<T>::ParameterType b) const
\r
77 __device__ __forceinline__ minus(const minus& other):binary_function<T,T,T>(){}
\r
78 __device__ __forceinline__ minus():binary_function<T,T,T>(){}
\r
81 template <typename T> struct multiplies : binary_function<T, T, T>
\r
83 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a,
\r
84 typename TypeTraits<T>::ParameterType b) const
\r
88 __device__ __forceinline__ multiplies(const multiplies& other):binary_function<T,T,T>(){}
\r
89 __device__ __forceinline__ multiplies():binary_function<T,T,T>(){}
\r
92 template <typename T> struct divides : binary_function<T, T, T>
\r
94 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a,
\r
95 typename TypeTraits<T>::ParameterType b) const
\r
99 __device__ __forceinline__ divides(const divides& other):binary_function<T,T,T>(){}
\r
100 __device__ __forceinline__ divides():binary_function<T,T,T>(){}
\r
103 template <typename T> struct modulus : binary_function<T, T, T>
\r
105 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a,
\r
106 typename TypeTraits<T>::ParameterType b) const
\r
110 __device__ __forceinline__ modulus(const modulus& other):binary_function<T,T,T>(){}
\r
111 __device__ __forceinline__ modulus():binary_function<T,T,T>(){}
\r
114 template <typename T> struct negate : unary_function<T, T>
\r
116 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a) const
\r
120 __device__ __forceinline__ negate(const negate& other):unary_function<T,T>(){}
\r
121 __device__ __forceinline__ negate():unary_function<T,T>(){}
\r
124 // Comparison Operations
\r
125 template <typename T> struct equal_to : binary_function<T, T, bool>
\r
127 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a,
\r
128 typename TypeTraits<T>::ParameterType b) const
\r
132 __device__ __forceinline__ equal_to(const equal_to& other):binary_function<T,T,bool>(){}
\r
133 __device__ __forceinline__ equal_to():binary_function<T,T,bool>(){}
\r
136 template <typename T> struct not_equal_to : binary_function<T, T, bool>
\r
138 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a,
\r
139 typename TypeTraits<T>::ParameterType b) const
\r
143 __device__ __forceinline__ not_equal_to(const not_equal_to& other):binary_function<T,T,bool>(){}
\r
144 __device__ __forceinline__ not_equal_to():binary_function<T,T,bool>(){}
\r
147 template <typename T> struct greater : binary_function<T, T, bool>
\r
149 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a,
\r
150 typename TypeTraits<T>::ParameterType b) const
\r
154 __device__ __forceinline__ greater(const greater& other):binary_function<T,T,bool>(){}
\r
155 __device__ __forceinline__ greater():binary_function<T,T,bool>(){}
\r
158 template <typename T> struct less : binary_function<T, T, bool>
\r
160 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a,
\r
161 typename TypeTraits<T>::ParameterType b) const
\r
165 __device__ __forceinline__ less(const less& other):binary_function<T,T,bool>(){}
\r
166 __device__ __forceinline__ less():binary_function<T,T,bool>(){}
\r
169 template <typename T> struct greater_equal : binary_function<T, T, bool>
\r
171 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a,
\r
172 typename TypeTraits<T>::ParameterType b) const
\r
176 __device__ __forceinline__ greater_equal(const greater_equal& other):binary_function<T,T,bool>(){}
\r
177 __device__ __forceinline__ greater_equal():binary_function<T,T,bool>(){}
\r
180 template <typename T> struct less_equal : binary_function<T, T, bool>
\r
182 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a,
\r
183 typename TypeTraits<T>::ParameterType b) const
\r
187 __device__ __forceinline__ less_equal(const less_equal& other):binary_function<T,T,bool>(){}
\r
188 __device__ __forceinline__ less_equal():binary_function<T,T,bool>(){}
\r
191 // Logical Operations
\r
192 template <typename T> struct logical_and : binary_function<T, T, bool>
\r
194 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a,
\r
195 typename TypeTraits<T>::ParameterType b) const
\r
199 __device__ __forceinline__ logical_and(const logical_and& other):binary_function<T,T,bool>(){}
\r
200 __device__ __forceinline__ logical_and():binary_function<T,T,bool>(){}
\r
203 template <typename T> struct logical_or : binary_function<T, T, bool>
\r
205 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a,
\r
206 typename TypeTraits<T>::ParameterType b) const
\r
210 __device__ __forceinline__ logical_or(const logical_or& other):binary_function<T,T,bool>(){}
\r
211 __device__ __forceinline__ logical_or():binary_function<T,T,bool>(){}
\r
214 template <typename T> struct logical_not : unary_function<T, bool>
\r
216 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a) const
\r
220 __device__ __forceinline__ logical_not(const logical_not& other):unary_function<T,bool>(){}
\r
221 __device__ __forceinline__ logical_not():unary_function<T,bool>(){}
\r
224 // Bitwise Operations
\r
225 template <typename T> struct bit_and : binary_function<T, T, T>
\r
227 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a,
\r
228 typename TypeTraits<T>::ParameterType b) const
\r
232 __device__ __forceinline__ bit_and(const bit_and& other):binary_function<T,T,T>(){}
\r
233 __device__ __forceinline__ bit_and():binary_function<T,T,T>(){}
\r
236 template <typename T> struct bit_or : binary_function<T, T, T>
\r
238 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a,
\r
239 typename TypeTraits<T>::ParameterType b) const
\r
243 __device__ __forceinline__ bit_or(const bit_or& other):binary_function<T,T,T>(){}
\r
244 __device__ __forceinline__ bit_or():binary_function<T,T,T>(){}
\r
247 template <typename T> struct bit_xor : binary_function<T, T, T>
\r
249 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a,
\r
250 typename TypeTraits<T>::ParameterType b) const
\r
254 __device__ __forceinline__ bit_xor(const bit_xor& other):binary_function<T,T,T>(){}
\r
255 __device__ __forceinline__ bit_xor():binary_function<T,T,T>(){}
\r
258 template <typename T> struct bit_not : unary_function<T, T>
\r
260 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType v) const
\r
264 __device__ __forceinline__ bit_not(const bit_not& other):unary_function<T,T>(){}
\r
265 __device__ __forceinline__ bit_not():unary_function<T,T>(){}
\r
268 // Generalized Identity Operations
\r
269 template <typename T> struct identity : unary_function<T, T>
\r
271 __device__ __forceinline__ typename TypeTraits<T>::ParameterType operator()(typename TypeTraits<T>::ParameterType x) const
\r
275 __device__ __forceinline__ identity(const identity& other):unary_function<T,T>(){}
\r
276 __device__ __forceinline__ identity():unary_function<T,T>(){}
\r
279 template <typename T1, typename T2> struct project1st : binary_function<T1, T2, T1>
\r
281 __device__ __forceinline__ typename TypeTraits<T1>::ParameterType operator()(typename TypeTraits<T1>::ParameterType lhs, typename TypeTraits<T2>::ParameterType rhs) const
\r
285 __device__ __forceinline__ project1st(const project1st& other):binary_function<T1,T2,T1>(){}
\r
286 __device__ __forceinline__ project1st():binary_function<T1,T2,T1>(){}
\r
289 template <typename T1, typename T2> struct project2nd : binary_function<T1, T2, T2>
\r
291 __device__ __forceinline__ typename TypeTraits<T2>::ParameterType operator()(typename TypeTraits<T1>::ParameterType lhs, typename TypeTraits<T2>::ParameterType rhs) const
\r
295 __device__ __forceinline__ project2nd(const project2nd& other):binary_function<T1,T2,T2>(){}
\r
296 __device__ __forceinline__ project2nd():binary_function<T1,T2,T2>(){}
\r
299 // Min/Max Operations
\r
301 #define OPENCV_GPU_IMPLEMENT_MINMAX(name, type, op) \
\r
302 template <> struct name<type> : binary_function<type, type, type> \
\r
304 __device__ __forceinline__ type operator()(type lhs, type rhs) const {return op(lhs, rhs);} \
\r
305 __device__ __forceinline__ name(const name& other):binary_function<type, type, type>(){}\
\r
306 __device__ __forceinline__ name():binary_function<type, type, type>(){}\
\r
309 template <typename T> struct maximum : binary_function<T, T, T>
\r
311 __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType lhs, typename TypeTraits<T>::ParameterType rhs) const
\r
313 return lhs < rhs ? rhs : lhs;
\r
315 __device__ __forceinline__ maximum(const maximum& other):binary_function<T, T, T>(){}
\r
316 __device__ __forceinline__ maximum():binary_function<T, T, T>(){}
\r
319 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, uchar, ::max)
\r
320 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, schar, ::max)
\r
321 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, char, ::max)
\r
322 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, ushort, ::max)
\r
323 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, short, ::max)
\r
324 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, int, ::max)
\r
325 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, uint, ::max)
\r
326 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, float, ::fmax)
\r
327 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, double, ::fmax)
\r
329 template <typename T> struct minimum : binary_function<T, T, T>
\r
331 __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType lhs, typename TypeTraits<T>::ParameterType rhs) const
\r
333 return lhs < rhs ? lhs : rhs;
\r
335 __device__ __forceinline__ minimum(const minimum& other):binary_function<T, T, T>(){}
\r
336 __device__ __forceinline__ minimum():binary_function<T, T, T>(){}
\r
339 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, uchar, ::min)
\r
340 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, schar, ::min)
\r
341 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, char, ::min)
\r
342 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, ushort, ::min)
\r
343 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, short, ::min)
\r
344 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, int, ::min)
\r
345 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, uint, ::min)
\r
346 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, float, ::fmin)
\r
347 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, double, ::fmin)
\r
349 #undef OPENCV_GPU_IMPLEMENT_MINMAX
\r
352 ///bound=========================================
\r
353 #define OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(name, func) \
\r
354 template <typename T> struct name ## _func : unary_function<T, float> \
\r
356 __device__ __forceinline__ float operator ()(typename TypeTraits<T>::ParameterType v) const \
\r
358 return func ## f(v); \
\r
361 template <> struct name ## _func<double> : unary_function<double, double> \
\r
363 __device__ __forceinline__ double operator ()(double v) const \
\r
369 #define OPENCV_GPU_IMPLEMENT_BIN_FUNCTOR(name, func) \
\r
370 template <typename T> struct name ## _func : binary_function<T, T, float> \
\r
372 __device__ __forceinline__ float operator ()(typename TypeTraits<T>::ParameterType v1, typename TypeTraits<T>::ParameterType v2) const \
\r
374 return func ## f(v1, v2); \
\r
377 template <> struct name ## _func<double> : binary_function<double, double, double> \
\r
379 __device__ __forceinline__ double operator ()(double v1, double v2) const \
\r
381 return func(v1, v2); \
\r
385 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(fabs, ::fabs)
\r
386 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(sqrt, ::sqrt)
\r
387 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(exp, ::exp)
\r
388 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(exp2, ::exp2)
\r
389 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(exp10, ::exp10)
\r
390 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(log, ::log)
\r
391 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(log2, ::log2)
\r
392 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(log10, ::log10)
\r
393 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(sin, ::sin)
\r
394 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(cos, ::cos)
\r
395 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(tan, ::tan)
\r
396 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(asin, ::asin)
\r
397 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(acos, ::acos)
\r
398 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(atan, ::atan)
\r
399 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(sinh, ::sinh)
\r
400 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(cosh, ::cosh)
\r
401 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(tanh, ::tanh)
\r
402 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(asinh, ::asinh)
\r
403 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(acosh, ::acosh)
\r
404 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(atanh, ::atanh)
\r
406 OPENCV_GPU_IMPLEMENT_BIN_FUNCTOR(hypot, ::hypot)
\r
407 OPENCV_GPU_IMPLEMENT_BIN_FUNCTOR(atan2, ::atan2)
\r
408 OPENCV_GPU_IMPLEMENT_BIN_FUNCTOR(pow, ::pow)
\r
410 #undef OPENCV_GPU_IMPLEMENT_UN_FUNCTOR
\r
411 #undef OPENCV_GPU_IMPLEMENT_BIN_FUNCTOR
\r
413 template<typename T> struct hypot_sqr_func : binary_function<T, T, float>
\r
415 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType src1, typename TypeTraits<T>::ParameterType src2) const
\r
417 return src1 * src1 + src2 * src2;
\r
419 __device__ __forceinline__ hypot_sqr_func(const hypot_sqr_func& other) : binary_function<T, T, float>(){}
\r
420 __device__ __forceinline__ hypot_sqr_func() : binary_function<T, T, float>(){}
\r
423 // Saturate Cast Functor
\r
424 template <typename T, typename D> struct saturate_cast_func : unary_function<T, D>
\r
426 __device__ __forceinline__ D operator ()(typename TypeTraits<T>::ParameterType v) const
\r
428 return saturate_cast<D>(v);
\r
430 __device__ __forceinline__ saturate_cast_func(const saturate_cast_func& other):unary_function<T, D>(){}
\r
431 __device__ __forceinline__ saturate_cast_func():unary_function<T, D>(){}
\r
434 // Threshold Functors
\r
435 template <typename T> struct thresh_binary_func : unary_function<T, T>
\r
437 __host__ __device__ __forceinline__ thresh_binary_func(T thresh_, T maxVal_) : thresh(thresh_), maxVal(maxVal_) {}
\r
439 __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType src) const
\r
441 return (src > thresh) * maxVal;
\r
444 __device__ __forceinline__ thresh_binary_func(const thresh_binary_func& other)
\r
445 : unary_function<T, T>(), thresh(other.thresh), maxVal(other.maxVal){}
\r
447 __device__ __forceinline__ thresh_binary_func():unary_function<T, T>(){}
\r
453 template <typename T> struct thresh_binary_inv_func : unary_function<T, T>
\r
455 __host__ __device__ __forceinline__ thresh_binary_inv_func(T thresh_, T maxVal_) : thresh(thresh_), maxVal(maxVal_) {}
\r
457 __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType src) const
\r
459 return (src <= thresh) * maxVal;
\r
462 __device__ __forceinline__ thresh_binary_inv_func(const thresh_binary_inv_func& other)
\r
463 : unary_function<T, T>(), thresh(other.thresh), maxVal(other.maxVal){}
\r
465 __device__ __forceinline__ thresh_binary_inv_func():unary_function<T, T>(){}
\r
471 template <typename T> struct thresh_trunc_func : unary_function<T, T>
\r
473 explicit __host__ __device__ __forceinline__ thresh_trunc_func(T thresh_, T maxVal_ = 0) : thresh(thresh_) {(void)maxVal_;}
\r
475 __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType src) const
\r
477 return minimum<T>()(src, thresh);
\r
480 __device__ __forceinline__ thresh_trunc_func(const thresh_trunc_func& other)
\r
481 : unary_function<T, T>(), thresh(other.thresh){}
\r
483 __device__ __forceinline__ thresh_trunc_func():unary_function<T, T>(){}
\r
488 template <typename T> struct thresh_to_zero_func : unary_function<T, T>
\r
490 explicit __host__ __device__ __forceinline__ thresh_to_zero_func(T thresh_, T maxVal_ = 0) : thresh(thresh_) {(void)maxVal_;}
\r
492 __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType src) const
\r
494 return (src > thresh) * src;
\r
496 __device__ __forceinline__ thresh_to_zero_func(const thresh_to_zero_func& other)
\r
497 : unary_function<T, T>(), thresh(other.thresh){}
\r
499 __device__ __forceinline__ thresh_to_zero_func():unary_function<T, T>(){}
\r
504 template <typename T> struct thresh_to_zero_inv_func : unary_function<T, T>
\r
506 explicit __host__ __device__ __forceinline__ thresh_to_zero_inv_func(T thresh_, T maxVal_ = 0) : thresh(thresh_) {(void)maxVal_;}
\r
508 __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType src) const
\r
510 return (src <= thresh) * src;
\r
512 __device__ __forceinline__ thresh_to_zero_inv_func(const thresh_to_zero_inv_func& other)
\r
513 : unary_function<T, T>(), thresh(other.thresh){}
\r
515 __device__ __forceinline__ thresh_to_zero_inv_func():unary_function<T, T>(){}
\r
519 //bound!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ============>
\r
520 // Function Object Adaptors
\r
521 template <typename Predicate> struct unary_negate : unary_function<typename Predicate::argument_type, bool>
\r
523 explicit __host__ __device__ __forceinline__ unary_negate(const Predicate& p) : pred(p) {}
\r
525 __device__ __forceinline__ bool operator()(typename TypeTraits<typename Predicate::argument_type>::ParameterType x) const
\r
530 __device__ __forceinline__ unary_negate(const unary_negate& other) : unary_function<typename Predicate::argument_type, bool>(){}
\r
531 __device__ __forceinline__ unary_negate() : unary_function<typename Predicate::argument_type, bool>(){}
\r
533 const Predicate pred;
\r
536 template <typename Predicate> __host__ __device__ __forceinline__ unary_negate<Predicate> not1(const Predicate& pred)
\r
538 return unary_negate<Predicate>(pred);
\r
541 template <typename Predicate> struct binary_negate : binary_function<typename Predicate::first_argument_type, typename Predicate::second_argument_type, bool>
\r
543 explicit __host__ __device__ __forceinline__ binary_negate(const Predicate& p) : pred(p) {}
\r
545 __device__ __forceinline__ bool operator()(typename TypeTraits<typename Predicate::first_argument_type>::ParameterType x,
\r
546 typename TypeTraits<typename Predicate::second_argument_type>::ParameterType y) const
\r
550 __device__ __forceinline__ binary_negate(const binary_negate& other)
\r
551 : binary_function<typename Predicate::first_argument_type, typename Predicate::second_argument_type, bool>(){}
\r
553 __device__ __forceinline__ binary_negate() :
\r
554 binary_function<typename Predicate::first_argument_type, typename Predicate::second_argument_type, bool>(){}
\r
556 const Predicate pred;
\r
559 template <typename BinaryPredicate> __host__ __device__ __forceinline__ binary_negate<BinaryPredicate> not2(const BinaryPredicate& pred)
\r
561 return binary_negate<BinaryPredicate>(pred);
\r
564 template <typename Op> struct binder1st : unary_function<typename Op::second_argument_type, typename Op::result_type>
\r
566 __host__ __device__ __forceinline__ binder1st(const Op& op_, const typename Op::first_argument_type& arg1_) : op(op_), arg1(arg1_) {}
\r
568 __device__ __forceinline__ typename Op::result_type operator ()(typename TypeTraits<typename Op::second_argument_type>::ParameterType a) const
\r
570 return op(arg1, a);
\r
573 __device__ __forceinline__ binder1st(const binder1st& other) :
\r
574 unary_function<typename Op::second_argument_type, typename Op::result_type>(){}
\r
577 const typename Op::first_argument_type arg1;
\r
580 template <typename Op, typename T> __host__ __device__ __forceinline__ binder1st<Op> bind1st(const Op& op, const T& x)
\r
582 return binder1st<Op>(op, typename Op::first_argument_type(x));
\r
585 template <typename Op> struct binder2nd : unary_function<typename Op::first_argument_type, typename Op::result_type>
\r
587 __host__ __device__ __forceinline__ binder2nd(const Op& op_, const typename Op::second_argument_type& arg2_) : op(op_), arg2(arg2_) {}
\r
589 __forceinline__ __device__ typename Op::result_type operator ()(typename TypeTraits<typename Op::first_argument_type>::ParameterType a) const
\r
591 return op(a, arg2);
\r
594 __device__ __forceinline__ binder2nd(const binder2nd& other) :
\r
595 unary_function<typename Op::first_argument_type, typename Op::result_type>(), op(other.op), arg2(other.arg2){}
\r
598 const typename Op::second_argument_type arg2;
\r
601 template <typename Op, typename T> __host__ __device__ __forceinline__ binder2nd<Op> bind2nd(const Op& op, const T& x)
\r
603 return binder2nd<Op>(op, typename Op::second_argument_type(x));
\r
607 template <typename F> struct IsUnaryFunction
\r
610 struct No {Yes a[2];};
\r
612 template <typename T, typename D> static Yes check(unary_function<T, D>);
\r
613 static No check(...);
\r
617 enum { value = (sizeof(check(makeF())) == sizeof(Yes)) };
\r
620 template <typename F> struct IsBinaryFunction
\r
623 struct No {Yes a[2];};
\r
625 template <typename T1, typename T2, typename D> static Yes check(binary_function<T1, T2, D>);
\r
626 static No check(...);
\r
630 enum { value = (sizeof(check(makeF())) == sizeof(Yes)) };
\r
633 namespace functional_detail
\r
635 template <size_t src_elem_size, size_t dst_elem_size> struct UnOpShift { enum { shift = 1 }; };
\r
636 template <size_t src_elem_size> struct UnOpShift<src_elem_size, 1> { enum { shift = 4 }; };
\r
637 template <size_t src_elem_size> struct UnOpShift<src_elem_size, 2> { enum { shift = 2 }; };
\r
639 template <typename T, typename D> struct DefaultUnaryShift
\r
641 enum { shift = UnOpShift<sizeof(T), sizeof(D)>::shift };
\r
644 template <size_t src_elem_size1, size_t src_elem_size2, size_t dst_elem_size> struct BinOpShift { enum { shift = 1 }; };
\r
645 template <size_t src_elem_size1, size_t src_elem_size2> struct BinOpShift<src_elem_size1, src_elem_size2, 1> { enum { shift = 4 }; };
\r
646 template <size_t src_elem_size1, size_t src_elem_size2> struct BinOpShift<src_elem_size1, src_elem_size2, 2> { enum { shift = 2 }; };
\r
648 template <typename T1, typename T2, typename D> struct DefaultBinaryShift
\r
650 enum { shift = BinOpShift<sizeof(T1), sizeof(T2), sizeof(D)>::shift };
\r
653 template <typename Func, bool unary = IsUnaryFunction<Func>::value> struct ShiftDispatcher;
\r
654 template <typename Func> struct ShiftDispatcher<Func, true>
\r
656 enum { shift = DefaultUnaryShift<typename Func::argument_type, typename Func::result_type>::shift };
\r
658 template <typename Func> struct ShiftDispatcher<Func, false>
\r
660 enum { shift = DefaultBinaryShift<typename Func::first_argument_type, typename Func::second_argument_type, typename Func::result_type>::shift };
\r
664 template <typename Func> struct DefaultTransformShift
\r
666 enum { shift = functional_detail::ShiftDispatcher<Func>::shift };
\r
669 template <typename Func> struct DefaultTransformFunctorTraits
\r
671 enum { simple_block_dim_x = 16 };
\r
672 enum { simple_block_dim_y = 16 };
\r
674 enum { smart_block_dim_x = 16 };
\r
675 enum { smart_block_dim_y = 16 };
\r
676 enum { smart_shift = DefaultTransformShift<Func>::shift };
\r
679 template <typename Func> struct TransformFunctorTraits : DefaultTransformFunctorTraits<Func> {};
\r
681 #define OPENCV_GPU_TRANSFORM_FUNCTOR_TRAITS(type) \
\r
682 template <> struct TransformFunctorTraits< type > : DefaultTransformFunctorTraits< type >
\r
683 }}} // namespace cv { namespace gpu { namespace device
\r
685 #endif // __OPENCV_GPU_FUNCTIONAL_HPP__
\r