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_EXPR_BINARY_OP_HPP__ 47 #define __OPENCV_CUDEV_EXPR_BINARY_OP_HPP__ 48 49 #include "../common.hpp" 50 #include "../util/type_traits.hpp" 51 #include "../ptr2d/traits.hpp" 52 #include "../ptr2d/transform.hpp" 53 #include "../ptr2d/gpumat.hpp" 54 #include "../ptr2d/texture.hpp" 55 #include "../ptr2d/glob.hpp" 56 #include "../functional/functional.hpp" 57 #include "expr.hpp" 58 59 namespace cv { namespace cudev { 60 61 //! @addtogroup cudev 62 //! @{ 63 64 // Binary Operations 65 66 #define CV_CUDEV_EXPR_BINOP_INST(op, functor) \ 67 template <typename T> \ 68 __host__ Expr<BinaryTransformPtrSz<typename PtrTraits<GpuMat_<T> >::ptr_type, typename PtrTraits<GpuMat_<T> >::ptr_type, functor<T> > > \ 69 operator op(const GpuMat_<T>& src1, const GpuMat_<T>& src2) \ 70 { \ 71 return makeExpr(transformPtr(src1, src2, functor<T>())); \ 72 } \ 73 template <typename T> \ 74 __host__ Expr<BinaryTransformPtrSz<typename PtrTraits<GpuMat_<T> >::ptr_type, typename PtrTraits<GlobPtrSz<T> >::ptr_type, functor<T> > > \ 75 operator op(const GpuMat_<T>& src1, const GlobPtrSz<T>& src2) \ 76 { \ 77 return makeExpr(transformPtr(src1, src2, functor<T>())); \ 78 } \ 79 template <typename T> \ 80 __host__ Expr<BinaryTransformPtrSz<typename PtrTraits<GlobPtrSz<T> >::ptr_type, typename PtrTraits<GpuMat_<T> >::ptr_type, functor<T> > > \ 81 operator op(const GlobPtrSz<T>& src1, const GpuMat_<T>& src2) \ 82 { \ 83 return makeExpr(transformPtr(src1, src2, functor<T>())); \ 84 } \ 85 template <typename T> \ 86 __host__ Expr<BinaryTransformPtrSz<typename PtrTraits<GpuMat_<T> >::ptr_type, typename PtrTraits<Texture<T> >::ptr_type, functor<T> > > \ 87 operator op(const GpuMat_<T>& src1, const Texture<T>& src2) \ 88 { \ 89 return makeExpr(transformPtr(src1, src2, functor<T>())); \ 90 } \ 91 template <typename T> \ 92 __host__ Expr<BinaryTransformPtrSz<typename PtrTraits<Texture<T> >::ptr_type, typename PtrTraits<GpuMat_<T> >::ptr_type, functor<T> > > \ 93 operator op(const Texture<T>& src1, const GpuMat_<T>& src2) \ 94 { \ 95 return makeExpr(transformPtr(src1, src2, functor<T>())); \ 96 } \ 97 template <typename T, class Body> \ 98 __host__ Expr<BinaryTransformPtrSz<typename PtrTraits<GpuMat_<T> >::ptr_type, typename PtrTraits<Body>::ptr_type, functor<typename LargerType<T, typename PtrTraits<Body>::value_type>::type> > > \ 99 operator op(const GpuMat_<T>& src1, const Expr<Body>& src2) \ 100 { \ 101 return makeExpr(transformPtr(src1, src2.body, functor<typename LargerType<T, typename PtrTraits<Body>::value_type>::type>())); \ 102 } \ 103 template <typename T, class Body> \ 104 __host__ Expr<BinaryTransformPtrSz<typename PtrTraits<Body>::ptr_type, typename PtrTraits<GpuMat_<T> >::ptr_type, functor<typename LargerType<T, typename PtrTraits<Body>::value_type>::type> > > \ 105 operator op(const Expr<Body>& src1, const GpuMat_<T>& src2) \ 106 { \ 107 return makeExpr(transformPtr(src1.body, src2, functor<typename LargerType<T, typename PtrTraits<Body>::value_type>::type>())); \ 108 } \ 109 template <typename T> \ 110 __host__ Expr<UnaryTransformPtrSz<typename PtrTraits<GpuMat_<T> >::ptr_type, Binder2nd< functor<T> > > > \ 111 operator op(const GpuMat_<T>& src, T val) \ 112 { \ 113 return makeExpr(transformPtr(src, bind2nd(functor<T>(), val))); \ 114 } \ 115 template <typename T> \ 116 __host__ Expr<UnaryTransformPtrSz<typename PtrTraits<GpuMat_<T> >::ptr_type, Binder1st< functor<T> > > > \ 117 operator op(T val, const GpuMat_<T>& src) \ 118 { \ 119 return makeExpr(transformPtr(src, bind1st(functor<T>(), val))); \ 120 } \ 121 template <typename T> \ 122 __host__ Expr<BinaryTransformPtrSz<typename PtrTraits<GlobPtrSz<T> >::ptr_type, typename PtrTraits<GlobPtrSz<T> >::ptr_type, functor<T> > > \ 123 operator op(const GlobPtrSz<T>& src1, const GlobPtrSz<T>& src2) \ 124 { \ 125 return makeExpr(transformPtr(src1, src2, functor<T>())); \ 126 } \ 127 template <typename T> \ 128 __host__ Expr<BinaryTransformPtrSz<typename PtrTraits<GlobPtrSz<T> >::ptr_type, typename PtrTraits<Texture<T> >::ptr_type, functor<T> > > \ 129 operator op(const GlobPtrSz<T>& src1, const Texture<T>& src2) \ 130 { \ 131 return makeExpr(transformPtr(src1, src2, functor<T>())); \ 132 } \ 133 template <typename T> \ 134 __host__ Expr<BinaryTransformPtrSz<typename PtrTraits<Texture<T> >::ptr_type, typename PtrTraits<GlobPtrSz<T> >::ptr_type, functor<T> > > \ 135 operator op(const Texture<T>& src1, const GlobPtrSz<T>& src2) \ 136 { \ 137 return makeExpr(transformPtr(src1, src2, functor<T>())); \ 138 } \ 139 template <typename T, class Body> \ 140 __host__ Expr<BinaryTransformPtrSz<typename PtrTraits<GlobPtrSz<T> >::ptr_type, typename PtrTraits<Body>::ptr_type, functor<typename LargerType<T, typename PtrTraits<Body>::value_type>::type> > > \ 141 operator op(const GlobPtrSz<T>& src1, const Expr<Body>& src2) \ 142 { \ 143 return makeExpr(transformPtr(src1, src2.body, functor<typename LargerType<T, typename PtrTraits<Body>::value_type>::type>())); \ 144 } \ 145 template <typename T, class Body> \ 146 __host__ Expr<BinaryTransformPtrSz<typename PtrTraits<Body>::ptr_type, typename PtrTraits<GlobPtrSz<T> >::ptr_type, functor<typename LargerType<T, typename PtrTraits<Body>::value_type>::type> > > \ 147 operator op(const Expr<Body>& src1, const GlobPtrSz<T>& src2) \ 148 { \ 149 return makeExpr(transformPtr(src1.body, src2, functor<typename LargerType<T, typename PtrTraits<Body>::value_type>::type>())); \ 150 } \ 151 template <typename T> \ 152 __host__ Expr<UnaryTransformPtrSz<typename PtrTraits<GlobPtrSz<T> >::ptr_type, Binder2nd< functor<T> > > > \ 153 operator op(const GlobPtrSz<T>& src, T val) \ 154 { \ 155 return makeExpr(transformPtr(src, bind2nd(functor<T>(), val))); \ 156 } \ 157 template <typename T> \ 158 __host__ Expr<UnaryTransformPtrSz<typename PtrTraits<GlobPtrSz<T> >::ptr_type, Binder1st< functor<T> > > > \ 159 operator op(T val, const GlobPtrSz<T>& src) \ 160 { \ 161 return makeExpr(transformPtr(src, bind1st(functor<T>(), val))); \ 162 } \ 163 template <typename T> \ 164 __host__ Expr<BinaryTransformPtrSz<typename PtrTraits<Texture<T> >::ptr_type, typename PtrTraits<Texture<T> >::ptr_type, functor<T> > > \ 165 operator op(const Texture<T>& src1, const Texture<T>& src2) \ 166 { \ 167 return makeExpr(transformPtr(src1, src2, functor<T>())); \ 168 } \ 169 template <typename T, class Body> \ 170 __host__ Expr<BinaryTransformPtrSz<typename PtrTraits<Texture<T> >::ptr_type, typename PtrTraits<Body>::ptr_type, functor<typename LargerType<T, typename PtrTraits<Body>::value_type>::type> > > \ 171 operator op(const Texture<T>& src1, const Expr<Body>& src2) \ 172 { \ 173 return makeExpr(transformPtr(src1, src2.body, functor<typename LargerType<T, typename PtrTraits<Body>::value_type>::type>())); \ 174 } \ 175 template <typename T, class Body> \ 176 __host__ Expr<BinaryTransformPtrSz<typename PtrTraits<Body>::ptr_type, typename PtrTraits<Texture<T> >::ptr_type, functor<typename LargerType<T, typename PtrTraits<Body>::value_type>::type> > > \ 177 operator op(const Expr<Body>& src1, const Texture<T>& src2) \ 178 { \ 179 return makeExpr(transformPtr(src1.body, src2, functor<typename LargerType<T, typename PtrTraits<Body>::value_type>::type>())); \ 180 } \ 181 template <typename T> \ 182 __host__ Expr<UnaryTransformPtrSz<typename PtrTraits<Texture<T> >::ptr_type, Binder2nd< functor<T> > > > \ 183 operator op(const Texture<T>& src, T val) \ 184 { \ 185 return makeExpr(transformPtr(src, bind2nd(functor<T>(), val))); \ 186 } \ 187 template <typename T> \ 188 __host__ Expr<UnaryTransformPtrSz<typename PtrTraits<Texture<T> >::ptr_type, Binder1st< functor<T> > > > \ 189 operator op(T val, const Texture<T>& src) \ 190 { \ 191 return makeExpr(transformPtr(src, bind1st(functor<T>(), val))); \ 192 } \ 193 template <class Body1, class Body2> \ 194 __host__ Expr<BinaryTransformPtrSz<typename PtrTraits<Body1>::ptr_type, typename PtrTraits<Body2>::ptr_type, functor<typename LargerType<typename PtrTraits<Body1>::value_type, typename PtrTraits<Body2>::value_type>::type> > > \ 195 operator op(const Expr<Body1>& a, const Expr<Body2>& b) \ 196 { \ 197 return makeExpr(transformPtr(a.body, b.body, functor<typename LargerType<typename PtrTraits<Body1>::value_type, typename PtrTraits<Body2>::value_type>::type>())); \ 198 } \ 199 template <class Body> \ 200 __host__ Expr<UnaryTransformPtrSz<typename PtrTraits<Body>::ptr_type, Binder2nd< functor<typename Body::value_type> > > > \ 201 operator op(const Expr<Body>& a, typename Body::value_type val) \ 202 { \ 203 return makeExpr(transformPtr(a.body, bind2nd(functor<typename Body::value_type>(), val))); \ 204 } \ 205 template <class Body> \ 206 __host__ Expr<UnaryTransformPtrSz<typename PtrTraits<Body>::ptr_type, Binder1st< functor<typename Body::value_type> > > > \ 207 operator op(typename Body::value_type val, const Expr<Body>& a) \ 208 { \ 209 return makeExpr(transformPtr(a.body, bind1st(functor<typename Body::value_type>(), val))); \ 210 } 211 212 CV_CUDEV_EXPR_BINOP_INST(+, plus) 213 CV_CUDEV_EXPR_BINOP_INST(-, minus) 214 CV_CUDEV_EXPR_BINOP_INST(*, multiplies) 215 CV_CUDEV_EXPR_BINOP_INST(/, divides) 216 CV_CUDEV_EXPR_BINOP_INST(%, modulus) 217 218 CV_CUDEV_EXPR_BINOP_INST(==, equal_to) 219 CV_CUDEV_EXPR_BINOP_INST(!=, not_equal_to) 220 CV_CUDEV_EXPR_BINOP_INST(>, greater) 221 CV_CUDEV_EXPR_BINOP_INST(<, less) 222 CV_CUDEV_EXPR_BINOP_INST(>=, greater_equal) 223 CV_CUDEV_EXPR_BINOP_INST(<=, less_equal) 224 225 CV_CUDEV_EXPR_BINOP_INST(&&, logical_and) 226 CV_CUDEV_EXPR_BINOP_INST(||, logical_or) 227 228 CV_CUDEV_EXPR_BINOP_INST(&, bit_and) 229 CV_CUDEV_EXPR_BINOP_INST(|, bit_or) 230 CV_CUDEV_EXPR_BINOP_INST(^, bit_xor) 231 CV_CUDEV_EXPR_BINOP_INST(<<, bit_lshift) 232 CV_CUDEV_EXPR_BINOP_INST(>>, bit_rshift) 233 234 #undef CV_CUDEV_EXPR_BINOP_INST 235 236 //! @} 237 238 }} 239 240 #endif 241