This source file includes following definitions.
- assignTo
- transformPtr
- assignTo
- transformPtr
#pragma once
#ifndef __OPENCV_CUDEV_PTR2D_TRANSFORM_HPP__
#define __OPENCV_CUDEV_PTR2D_TRANSFORM_HPP__
#include "../common.hpp"
#include "../grid/copy.hpp"
#include "traits.hpp"
#include "gpumat.hpp"
namespace cv { namespace cudev {
template <class SrcPtr, class Op> struct UnaryTransformPtr
{
typedef typename Op::result_type value_type;
typedef typename PtrTraits<SrcPtr>::index_type index_type;
SrcPtr src;
Op op;
__device__ __forceinline__ typename Op::result_type operator ()(typename PtrTraits<SrcPtr>::index_type y, typename PtrTraits<SrcPtr>::index_type x) const
{
return op(src(y, x));
}
};
template <class SrcPtr, class Op> struct UnaryTransformPtrSz : UnaryTransformPtr<SrcPtr, Op>
{
int rows, cols;
template <typename T>
__host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const
{
gridCopy(*this, dst, stream);
}
};
template <class SrcPtr, class Op>
__host__ UnaryTransformPtrSz<typename PtrTraits<SrcPtr>::ptr_type, Op>
transformPtr(const SrcPtr& src, const Op& op)
{
UnaryTransformPtrSz<typename PtrTraits<SrcPtr>::ptr_type, Op> ptr;
ptr.src = shrinkPtr(src);
ptr.op = op;
ptr.rows = getRows(src);
ptr.cols = getCols(src);
return ptr;
}
template <class SrcPtr, class Op> struct PtrTraits< UnaryTransformPtrSz<SrcPtr, Op> > : PtrTraitsBase<UnaryTransformPtrSz<SrcPtr, Op>, UnaryTransformPtr<SrcPtr, Op> >
{
};
template <class Src1Ptr, class Src2Ptr, class Op> struct BinaryTransformPtr
{
typedef typename Op::result_type value_type;
typedef typename PtrTraits<Src1Ptr>::index_type index_type;
Src1Ptr src1;
Src2Ptr src2;
Op op;
__device__ __forceinline__ typename Op::result_type operator ()(typename PtrTraits<Src1Ptr>::index_type y, typename PtrTraits<Src1Ptr>::index_type x) const
{
return op(src1(y, x), src2(y, x));
}
};
template <class Src1Ptr, class Src2Ptr, class Op> struct BinaryTransformPtrSz : BinaryTransformPtr<Src1Ptr, Src2Ptr, Op>
{
int rows, cols;
template <typename T>
__host__ void assignTo(GpuMat_<T>& dst, Stream& stream = Stream::Null()) const
{
gridCopy(*this, dst, stream);
}
};
template <class Src1Ptr, class Src2Ptr, class Op>
__host__ BinaryTransformPtrSz<typename PtrTraits<Src1Ptr>::ptr_type, typename PtrTraits<Src2Ptr>::ptr_type, Op>
transformPtr(const Src1Ptr& src1, const Src2Ptr& src2, const Op& op)
{
const int rows = getRows(src1);
const int cols = getCols(src1);
CV_Assert( getRows(src2) == rows && getCols(src2) == cols );
BinaryTransformPtrSz<typename PtrTraits<Src1Ptr>::ptr_type, typename PtrTraits<Src2Ptr>::ptr_type, Op> ptr;
ptr.src1 = shrinkPtr(src1);
ptr.src2 = shrinkPtr(src2);
ptr.op = op;
ptr.rows = rows;
ptr.cols = cols;
return ptr;
}
template <class Src1Ptr, class Src2Ptr, class Op> struct PtrTraits< BinaryTransformPtrSz<Src1Ptr, Src2Ptr, Op> > : PtrTraitsBase<BinaryTransformPtrSz<Src1Ptr, Src2Ptr, Op>, BinaryTransformPtr<Src1Ptr, Src2Ptr, Op> >
{
};
}}
#endif