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
50 #include "device_functions.h"
\r
52 namespace cv { namespace gpu { namespace device
\r
56 using thrust::unary_function;
\r
57 using thrust::binary_function;
\r
59 // Arithmetic Operations
\r
60 template <typename T> struct plus : binary_function<T, T, T>
\r
62 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a,
\r
63 typename TypeTraits<T>::ParameterType b) const
\r
67 __device__ __forceinline__ plus(const plus& other):binary_function<T,T,T>(){}
\r
68 __device__ __forceinline__ plus():binary_function<T,T,T>(){}
\r
71 template <typename T> struct minus : binary_function<T, T, T>
\r
73 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a,
\r
74 typename TypeTraits<T>::ParameterType b) const
\r
78 __device__ __forceinline__ minus(const minus& other):binary_function<T,T,T>(){}
\r
79 __device__ __forceinline__ minus():binary_function<T,T,T>(){}
\r
82 template <typename T> struct multiplies : binary_function<T, T, T>
\r
84 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a,
\r
85 typename TypeTraits<T>::ParameterType b) const
\r
89 __device__ __forceinline__ multiplies(const multiplies& other):binary_function<T,T,T>(){}
\r
90 __device__ __forceinline__ multiplies():binary_function<T,T,T>(){}
\r
93 template <typename T> struct divides : binary_function<T, T, T>
\r
95 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a,
\r
96 typename TypeTraits<T>::ParameterType b) const
\r
100 __device__ __forceinline__ divides(const divides& other):binary_function<T,T,T>(){}
\r
101 __device__ __forceinline__ divides():binary_function<T,T,T>(){}
\r
104 template <typename T> struct modulus : binary_function<T, T, T>
\r
106 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a,
\r
107 typename TypeTraits<T>::ParameterType b) const
\r
111 __device__ __forceinline__ modulus(const modulus& other):binary_function<T,T,T>(){}
\r
112 __device__ __forceinline__ modulus():binary_function<T,T,T>(){}
\r
115 template <typename T> struct negate : unary_function<T, T>
\r
117 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a) const
\r
121 __device__ __forceinline__ negate(const negate& other):unary_function<T,T>(){}
\r
122 __device__ __forceinline__ negate():unary_function<T,T>(){}
\r
125 // Comparison Operations
\r
126 template <typename T> struct equal_to : binary_function<T, T, bool>
\r
128 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a,
\r
129 typename TypeTraits<T>::ParameterType b) const
\r
133 __device__ __forceinline__ equal_to(const equal_to& other):binary_function<T,T,bool>(){}
\r
134 __device__ __forceinline__ equal_to():binary_function<T,T,bool>(){}
\r
137 template <typename T> struct not_equal_to : binary_function<T, T, bool>
\r
139 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a,
\r
140 typename TypeTraits<T>::ParameterType b) const
\r
144 __device__ __forceinline__ not_equal_to(const not_equal_to& other):binary_function<T,T,bool>(){}
\r
145 __device__ __forceinline__ not_equal_to():binary_function<T,T,bool>(){}
\r
148 template <typename T> struct greater : binary_function<T, T, bool>
\r
150 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a,
\r
151 typename TypeTraits<T>::ParameterType b) const
\r
155 __device__ __forceinline__ greater(const greater& other):binary_function<T,T,bool>(){}
\r
156 __device__ __forceinline__ greater():binary_function<T,T,bool>(){}
\r
159 template <typename T> struct less : binary_function<T, T, bool>
\r
161 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a,
\r
162 typename TypeTraits<T>::ParameterType b) const
\r
166 __device__ __forceinline__ less(const less& other):binary_function<T,T,bool>(){}
\r
167 __device__ __forceinline__ less():binary_function<T,T,bool>(){}
\r
170 template <typename T> struct greater_equal : binary_function<T, T, bool>
\r
172 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a,
\r
173 typename TypeTraits<T>::ParameterType b) const
\r
177 __device__ __forceinline__ greater_equal(const greater_equal& other):binary_function<T,T,bool>(){}
\r
178 __device__ __forceinline__ greater_equal():binary_function<T,T,bool>(){}
\r
181 template <typename T> struct less_equal : binary_function<T, T, bool>
\r
183 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a,
\r
184 typename TypeTraits<T>::ParameterType b) const
\r
188 __device__ __forceinline__ less_equal(const less_equal& other):binary_function<T,T,bool>(){}
\r
189 __device__ __forceinline__ less_equal():binary_function<T,T,bool>(){}
\r
192 // Logical Operations
\r
193 template <typename T> struct logical_and : binary_function<T, T, bool>
\r
195 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a,
\r
196 typename TypeTraits<T>::ParameterType b) const
\r
200 __device__ __forceinline__ logical_and(const logical_and& other):binary_function<T,T,bool>(){}
\r
201 __device__ __forceinline__ logical_and():binary_function<T,T,bool>(){}
\r
204 template <typename T> struct logical_or : binary_function<T, T, bool>
\r
206 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a,
\r
207 typename TypeTraits<T>::ParameterType b) const
\r
211 __device__ __forceinline__ logical_or(const logical_or& other):binary_function<T,T,bool>(){}
\r
212 __device__ __forceinline__ logical_or():binary_function<T,T,bool>(){}
\r
215 template <typename T> struct logical_not : unary_function<T, bool>
\r
217 __device__ __forceinline__ bool operator ()(typename TypeTraits<T>::ParameterType a) const
\r
221 __device__ __forceinline__ logical_not(const logical_not& other):unary_function<T,bool>(){}
\r
222 __device__ __forceinline__ logical_not():unary_function<T,bool>(){}
\r
225 // Bitwise Operations
\r
226 template <typename T> struct bit_and : binary_function<T, T, T>
\r
228 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a,
\r
229 typename TypeTraits<T>::ParameterType b) const
\r
233 __device__ __forceinline__ bit_and(const bit_and& other):binary_function<T,T,T>(){}
\r
234 __device__ __forceinline__ bit_and():binary_function<T,T,T>(){}
\r
237 template <typename T> struct bit_or : binary_function<T, T, T>
\r
239 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a,
\r
240 typename TypeTraits<T>::ParameterType b) const
\r
244 __device__ __forceinline__ bit_or(const bit_or& other):binary_function<T,T,T>(){}
\r
245 __device__ __forceinline__ bit_or():binary_function<T,T,T>(){}
\r
248 template <typename T> struct bit_xor : binary_function<T, T, T>
\r
250 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType a,
\r
251 typename TypeTraits<T>::ParameterType b) const
\r
255 __device__ __forceinline__ bit_xor(const bit_xor& other):binary_function<T,T,T>(){}
\r
256 __device__ __forceinline__ bit_xor():binary_function<T,T,T>(){}
\r
259 template <typename T> struct bit_not : unary_function<T, T>
\r
261 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType v) const
\r
265 __device__ __forceinline__ bit_not(const bit_not& other):unary_function<T,T>(){}
\r
266 __device__ __forceinline__ bit_not():unary_function<T,T>(){}
\r
269 // Generalized Identity Operations
\r
270 template <typename T> struct identity : unary_function<T, T>
\r
272 __device__ __forceinline__ typename TypeTraits<T>::ParameterType operator()(typename TypeTraits<T>::ParameterType x) const
\r
276 __device__ __forceinline__ identity(const identity& other):unary_function<T,T>(){}
\r
277 __device__ __forceinline__ identity():unary_function<T,T>(){}
\r
280 template <typename T1, typename T2> struct project1st : binary_function<T1, T2, T1>
\r
282 __device__ __forceinline__ typename TypeTraits<T1>::ParameterType operator()(typename TypeTraits<T1>::ParameterType lhs, typename TypeTraits<T2>::ParameterType rhs) const
\r
286 __device__ __forceinline__ project1st(const project1st& other):binary_function<T1,T2,T1>(){}
\r
287 __device__ __forceinline__ project1st():binary_function<T1,T2,T1>(){}
\r
290 template <typename T1, typename T2> struct project2nd : binary_function<T1, T2, T2>
\r
292 __device__ __forceinline__ typename TypeTraits<T2>::ParameterType operator()(typename TypeTraits<T1>::ParameterType lhs, typename TypeTraits<T2>::ParameterType rhs) const
\r
296 __device__ __forceinline__ project2nd(const project2nd& other):binary_function<T1,T2,T2>(){}
\r
297 __device__ __forceinline__ project2nd():binary_function<T1,T2,T2>(){}
\r
300 // Min/Max Operations
\r
302 #define OPENCV_GPU_IMPLEMENT_MINMAX(name, type, op) \
\r
303 template <> struct name<type> : binary_function<type, type, type> \
\r
305 __device__ __forceinline__ type operator()(type lhs, type rhs) const {return op(lhs, rhs);} \
\r
306 __device__ __forceinline__ name(const name& other):binary_function<type, type, type>(){}\
\r
307 __device__ __forceinline__ name():binary_function<type, type, type>(){}\
\r
310 template <typename T> struct maximum : binary_function<T, T, T>
\r
312 __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType lhs, typename TypeTraits<T>::ParameterType rhs) const
\r
314 return lhs < rhs ? rhs : lhs;
\r
316 __device__ __forceinline__ maximum(const maximum& other):binary_function<T, T, T>(){}
\r
317 __device__ __forceinline__ maximum():binary_function<T, T, T>(){}
\r
320 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, uchar, ::max)
\r
321 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, schar, ::max)
\r
322 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, char, ::max)
\r
323 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, ushort, ::max)
\r
324 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, short, ::max)
\r
325 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, int, ::max)
\r
326 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, uint, ::max)
\r
327 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, float, ::fmax)
\r
328 OPENCV_GPU_IMPLEMENT_MINMAX(maximum, double, ::fmax)
\r
330 template <typename T> struct minimum : binary_function<T, T, T>
\r
332 __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType lhs, typename TypeTraits<T>::ParameterType rhs) const
\r
334 return lhs < rhs ? lhs : rhs;
\r
336 __device__ __forceinline__ minimum(const minimum& other):binary_function<T, T, T>(){}
\r
337 __device__ __forceinline__ minimum():binary_function<T, T, T>(){}
\r
340 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, uchar, ::min)
\r
341 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, schar, ::min)
\r
342 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, char, ::min)
\r
343 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, ushort, ::min)
\r
344 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, short, ::min)
\r
345 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, int, ::min)
\r
346 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, uint, ::min)
\r
347 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, float, ::fmin)
\r
348 OPENCV_GPU_IMPLEMENT_MINMAX(minimum, double, ::fmin)
\r
350 #undef OPENCV_GPU_IMPLEMENT_MINMAX
\r
353 ///bound=========================================
\r
354 #define OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(name, func) \
\r
355 template <typename T> struct name ## _func : unary_function<T, float> \
\r
357 __device__ __forceinline__ float operator ()(typename TypeTraits<T>::ParameterType v) const \
\r
359 return func ## f(v); \
\r
362 template <> struct name ## _func<double> : unary_function<double, double> \
\r
364 __device__ __forceinline__ double operator ()(double v) const \
\r
370 #define OPENCV_GPU_IMPLEMENT_BIN_FUNCTOR(name, func) \
\r
371 template <typename T> struct name ## _func : binary_function<T, T, float> \
\r
373 __device__ __forceinline__ float operator ()(typename TypeTraits<T>::ParameterType v1, typename TypeTraits<T>::ParameterType v2) const \
\r
375 return func ## f(v1, v2); \
\r
378 template <> struct name ## _func<double> : binary_function<double, double, double> \
\r
380 __device__ __forceinline__ double operator ()(double v1, double v2) const \
\r
382 return func(v1, v2); \
\r
386 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(fabs, ::fabs)
\r
387 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(sqrt, ::sqrt)
\r
388 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(exp, ::exp)
\r
389 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(exp2, ::exp2)
\r
390 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(exp10, ::exp10)
\r
391 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(log, ::log)
\r
392 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(log2, ::log2)
\r
393 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(log10, ::log10)
\r
394 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(sin, ::sin)
\r
395 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(cos, ::cos)
\r
396 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(tan, ::tan)
\r
397 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(asin, ::asin)
\r
398 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(acos, ::acos)
\r
399 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(atan, ::atan)
\r
400 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(sinh, ::sinh)
\r
401 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(cosh, ::cosh)
\r
402 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(tanh, ::tanh)
\r
403 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(asinh, ::asinh)
\r
404 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(acosh, ::acosh)
\r
405 OPENCV_GPU_IMPLEMENT_UN_FUNCTOR(atanh, ::atanh)
\r
407 OPENCV_GPU_IMPLEMENT_BIN_FUNCTOR(hypot, ::hypot)
\r
408 OPENCV_GPU_IMPLEMENT_BIN_FUNCTOR(atan2, ::atan2)
\r
409 OPENCV_GPU_IMPLEMENT_BIN_FUNCTOR(pow, ::pow)
\r
411 #undef OPENCV_GPU_IMPLEMENT_UN_FUNCTOR
\r
412 #undef OPENCV_GPU_IMPLEMENT_UN_FUNCTOR_NO_DOUBLE
\r
413 #undef OPENCV_GPU_IMPLEMENT_BIN_FUNCTOR
\r
415 template<typename T> struct hypot_sqr_func : binary_function<T, T, float>
\r
417 __device__ __forceinline__ T operator ()(typename TypeTraits<T>::ParameterType src1, typename TypeTraits<T>::ParameterType src2) const
\r
419 return src1 * src1 + src2 * src2;
\r
421 __device__ __forceinline__ hypot_sqr_func(const hypot_sqr_func& other) : binary_function<T, T, float>(){}
\r
422 __device__ __forceinline__ hypot_sqr_func() : binary_function<T, T, float>(){}
\r
425 // Saturate Cast Functor
\r
426 template <typename T, typename D> struct saturate_cast_func : unary_function<T, D>
\r
428 __device__ __forceinline__ D operator ()(typename TypeTraits<T>::ParameterType v) const
\r
430 return saturate_cast<D>(v);
\r
432 __device__ __forceinline__ saturate_cast_func(const saturate_cast_func& other):unary_function<T, D>(){}
\r
433 __device__ __forceinline__ saturate_cast_func():unary_function<T, D>(){}
\r
436 // Threshold Functors
\r
437 template <typename T> struct thresh_binary_func : unary_function<T, T>
\r
439 __host__ __device__ __forceinline__ thresh_binary_func(T thresh_, T maxVal_) : thresh(thresh_), maxVal(maxVal_) {}
\r
441 __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType src) const
\r
443 return (src > thresh) * maxVal;
\r
446 __device__ __forceinline__ thresh_binary_func(const thresh_binary_func& other)
\r
447 : unary_function<T, T>(), thresh(other.thresh), maxVal(other.maxVal){}
\r
449 __device__ __forceinline__ thresh_binary_func():unary_function<T, T>(){}
\r
455 template <typename T> struct thresh_binary_inv_func : unary_function<T, T>
\r
457 __host__ __device__ __forceinline__ thresh_binary_inv_func(T thresh_, T maxVal_) : thresh(thresh_), maxVal(maxVal_) {}
\r
459 __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType src) const
\r
461 return (src <= thresh) * maxVal;
\r
464 __device__ __forceinline__ thresh_binary_inv_func(const thresh_binary_inv_func& other)
\r
465 : unary_function<T, T>(), thresh(other.thresh), maxVal(other.maxVal){}
\r
467 __device__ __forceinline__ thresh_binary_inv_func():unary_function<T, T>(){}
\r
473 template <typename T> struct thresh_trunc_func : unary_function<T, T>
\r
475 explicit __host__ __device__ __forceinline__ thresh_trunc_func(T thresh_, T maxVal_ = 0) : thresh(thresh_) {(void)maxVal_;}
\r
477 __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType src) const
\r
479 return minimum<T>()(src, thresh);
\r
482 __device__ __forceinline__ thresh_trunc_func(const thresh_trunc_func& other)
\r
483 : unary_function<T, T>(), thresh(other.thresh){}
\r
485 __device__ __forceinline__ thresh_trunc_func():unary_function<T, T>(){}
\r
490 template <typename T> struct thresh_to_zero_func : unary_function<T, T>
\r
492 explicit __host__ __device__ __forceinline__ thresh_to_zero_func(T thresh_, T maxVal_ = 0) : thresh(thresh_) {(void)maxVal_;}
\r
494 __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType src) const
\r
496 return (src > thresh) * src;
\r
498 __device__ __forceinline__ thresh_to_zero_func(const thresh_to_zero_func& other)
\r
499 : unary_function<T, T>(), thresh(other.thresh){}
\r
501 __device__ __forceinline__ thresh_to_zero_func():unary_function<T, T>(){}
\r
506 template <typename T> struct thresh_to_zero_inv_func : unary_function<T, T>
\r
508 explicit __host__ __device__ __forceinline__ thresh_to_zero_inv_func(T thresh_, T maxVal_ = 0) : thresh(thresh_) {(void)maxVal_;}
\r
510 __device__ __forceinline__ T operator()(typename TypeTraits<T>::ParameterType src) const
\r
512 return (src <= thresh) * src;
\r
514 __device__ __forceinline__ thresh_to_zero_inv_func(const thresh_to_zero_inv_func& other)
\r
515 : unary_function<T, T>(), thresh(other.thresh){}
\r
517 __device__ __forceinline__ thresh_to_zero_inv_func():unary_function<T, T>(){}
\r
521 //bound!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ============>
\r
522 // Function Object Adaptors
\r
523 template <typename Predicate> struct unary_negate : unary_function<typename Predicate::argument_type, bool>
\r
525 explicit __host__ __device__ __forceinline__ unary_negate(const Predicate& p) : pred(p) {}
\r
527 __device__ __forceinline__ bool operator()(typename TypeTraits<typename Predicate::argument_type>::ParameterType x) const
\r
532 __device__ __forceinline__ unary_negate(const unary_negate& other) : unary_function<typename Predicate::argument_type, bool>(){}
\r
533 __device__ __forceinline__ unary_negate() : unary_function<typename Predicate::argument_type, bool>(){}
\r
535 const Predicate pred;
\r
538 template <typename Predicate> __host__ __device__ __forceinline__ unary_negate<Predicate> not1(const Predicate& pred)
\r
540 return unary_negate<Predicate>(pred);
\r
543 template <typename Predicate> struct binary_negate : binary_function<typename Predicate::first_argument_type, typename Predicate::second_argument_type, bool>
\r
545 explicit __host__ __device__ __forceinline__ binary_negate(const Predicate& p) : pred(p) {}
\r
547 __device__ __forceinline__ bool operator()(typename TypeTraits<typename Predicate::first_argument_type>::ParameterType x,
\r
548 typename TypeTraits<typename Predicate::second_argument_type>::ParameterType y) const
\r
552 __device__ __forceinline__ binary_negate(const binary_negate& other)
\r
553 : binary_function<typename Predicate::first_argument_type, typename Predicate::second_argument_type, bool>(){}
\r
555 __device__ __forceinline__ binary_negate() :
\r
556 binary_function<typename Predicate::first_argument_type, typename Predicate::second_argument_type, bool>(){}
\r
558 const Predicate pred;
\r
561 template <typename BinaryPredicate> __host__ __device__ __forceinline__ binary_negate<BinaryPredicate> not2(const BinaryPredicate& pred)
\r
563 return binary_negate<BinaryPredicate>(pred);
\r
566 template <typename Op> struct binder1st : unary_function<typename Op::second_argument_type, typename Op::result_type>
\r
568 __host__ __device__ __forceinline__ binder1st(const Op& op_, const typename Op::first_argument_type& arg1_) : op(op_), arg1(arg1_) {}
\r
570 __device__ __forceinline__ typename Op::result_type operator ()(typename TypeTraits<typename Op::second_argument_type>::ParameterType a) const
\r
572 return op(arg1, a);
\r
575 __device__ __forceinline__ binder1st(const binder1st& other) :
\r
576 unary_function<typename Op::second_argument_type, typename Op::result_type>(){}
\r
579 const typename Op::first_argument_type arg1;
\r
582 template <typename Op, typename T> __host__ __device__ __forceinline__ binder1st<Op> bind1st(const Op& op, const T& x)
\r
584 return binder1st<Op>(op, typename Op::first_argument_type(x));
\r
587 template <typename Op> struct binder2nd : unary_function<typename Op::first_argument_type, typename Op::result_type>
\r
589 __host__ __device__ __forceinline__ binder2nd(const Op& op_, const typename Op::second_argument_type& arg2_) : op(op_), arg2(arg2_) {}
\r
591 __forceinline__ __device__ typename Op::result_type operator ()(typename TypeTraits<typename Op::first_argument_type>::ParameterType a) const
\r
593 return op(a, arg2);
\r
596 __device__ __forceinline__ binder2nd(const binder2nd& other) :
\r
597 unary_function<typename Op::first_argument_type, typename Op::result_type>(), op(other.op), arg2(other.arg2){}
\r
600 const typename Op::second_argument_type arg2;
\r
603 template <typename Op, typename T> __host__ __device__ __forceinline__ binder2nd<Op> bind2nd(const Op& op, const T& x)
\r
605 return binder2nd<Op>(op, typename Op::second_argument_type(x));
\r
609 template <typename F> struct IsUnaryFunction
\r
612 struct No {Yes a[2];};
\r
614 template <typename T, typename D> static Yes check(unary_function<T, D>);
\r
615 static No check(...);
\r
619 enum { value = (sizeof(check(makeF())) == sizeof(Yes)) };
\r
622 template <typename F> struct IsBinaryFunction
\r
625 struct No {Yes a[2];};
\r
627 template <typename T1, typename T2, typename D> static Yes check(binary_function<T1, T2, D>);
\r
628 static No check(...);
\r
632 enum { value = (sizeof(check(makeF())) == sizeof(Yes)) };
\r
635 namespace functional_detail
\r
637 template <size_t src_elem_size, size_t dst_elem_size> struct UnOpShift { enum { shift = 1 }; };
\r
638 template <size_t src_elem_size> struct UnOpShift<src_elem_size, 1> { enum { shift = 4 }; };
\r
639 template <size_t src_elem_size> struct UnOpShift<src_elem_size, 2> { enum { shift = 2 }; };
\r
641 template <typename T, typename D> struct DefaultUnaryShift
\r
643 enum { shift = UnOpShift<sizeof(T), sizeof(D)>::shift };
\r
646 template <size_t src_elem_size1, size_t src_elem_size2, size_t dst_elem_size> struct BinOpShift { enum { shift = 1 }; };
\r
647 template <size_t src_elem_size1, size_t src_elem_size2> struct BinOpShift<src_elem_size1, src_elem_size2, 1> { enum { shift = 4 }; };
\r
648 template <size_t src_elem_size1, size_t src_elem_size2> struct BinOpShift<src_elem_size1, src_elem_size2, 2> { enum { shift = 2 }; };
\r
650 template <typename T1, typename T2, typename D> struct DefaultBinaryShift
\r
652 enum { shift = BinOpShift<sizeof(T1), sizeof(T2), sizeof(D)>::shift };
\r
655 template <typename Func, bool unary = IsUnaryFunction<Func>::value> struct ShiftDispatcher;
\r
656 template <typename Func> struct ShiftDispatcher<Func, true>
\r
658 enum { shift = DefaultUnaryShift<typename Func::argument_type, typename Func::result_type>::shift };
\r
660 template <typename Func> struct ShiftDispatcher<Func, false>
\r
662 enum { shift = DefaultBinaryShift<typename Func::first_argument_type, typename Func::second_argument_type, typename Func::result_type>::shift };
\r
666 template <typename Func> struct DefaultTransformShift
\r
668 enum { shift = functional_detail::ShiftDispatcher<Func>::shift };
\r
671 template <typename Func> struct DefaultTransformFunctorTraits
\r
673 enum { simple_block_dim_x = 16 };
\r
674 enum { simple_block_dim_y = 16 };
\r
676 enum { smart_block_dim_x = 16 };
\r
677 enum { smart_block_dim_y = 16 };
\r
678 enum { smart_shift = DefaultTransformShift<Func>::shift };
\r
681 template <typename Func> struct TransformFunctorTraits : DefaultTransformFunctorTraits<Func> {};
\r
683 #define OPENCV_GPU_TRANSFORM_FUNCTOR_TRAITS(type) \
\r
684 template <> struct TransformFunctorTraits< type > : DefaultTransformFunctorTraits< type >
\r
685 }}} // namespace cv { namespace gpu { namespace device
\r
687 #endif // __OPENCV_GPU_FUNCTIONAL_HPP__
\r