This source file includes following definitions.
- brdConstant
 
- brdConstant
 
- idx_row
 
- idx_col
 
- idx_low
 
- idx_high
 
- brdReplicate
 
- idx_low
 
- idx_high
 
- brdReflect101
 
- idx_low
 
- idx_high
 
- brdReflect
 
- idx_low
 
- idx_high
 
- brdWrap
 
#pragma once
#ifndef __OPENCV_CUDEV_PTR2D_EXTRAPOLATION_HPP__
#define __OPENCV_CUDEV_PTR2D_EXTRAPOLATION_HPP__
#include "../common.hpp"
#include "../util/vec_traits.hpp"
#include "traits.hpp"
namespace cv { namespace cudev {
template <class SrcPtr> struct BrdConstant
{
    typedef typename PtrTraits<SrcPtr>::value_type value_type;
    typedef int                                    index_type;
    SrcPtr src;
    int rows, cols;
    typename PtrTraits<SrcPtr>::value_type val;
    __device__ __forceinline__ typename PtrTraits<SrcPtr>::value_type operator ()(int y, int x) const
    {
        return (x >= 0 && x < cols && y >= 0 && y < rows) ? src(y, x) : val;
    }
};
template <class SrcPtr>
__host__ BrdConstant<typename PtrTraits<SrcPtr>::ptr_type> brdConstant(const SrcPtr& src, typename PtrTraits<SrcPtr>::value_type val)
{
    BrdConstant<typename PtrTraits<SrcPtr>::ptr_type> b;
    b.src = shrinkPtr(src);
    b.rows = getRows(src);
    b.cols = getCols(src);
    b.val = val;
    return b;
}
template <class SrcPtr>
__host__ BrdConstant<typename PtrTraits<SrcPtr>::ptr_type> brdConstant(const SrcPtr& src)
{
    return brdConstant(src, VecTraits<typename PtrTraits<SrcPtr>::value_type>::all(0));
}
template <class BrdImpl, class SrcPtr> struct BrdBase
{
    typedef typename PtrTraits<SrcPtr>::value_type value_type;
    typedef int                                    index_type;
    SrcPtr src;
    int rows, cols;
    __device__ __forceinline__ int idx_row(int y) const
    {
        return BrdImpl::idx_low(BrdImpl::idx_high(y, rows), rows);
    }
    __device__ __forceinline__ int idx_col(int x) const
    {
        return BrdImpl::idx_low(BrdImpl::idx_high(x, cols), cols);
    }
    __device__ __forceinline__ typename PtrTraits<SrcPtr>::value_type operator ()(int y, int x) const
    {
        return src(idx_row(y), idx_col(x));
    }
};
struct BrdReplicate
{
    __device__ __forceinline__ static int idx_low(int i, int len)
    {
        return ::max(i, 0);
    }
    __device__ __forceinline__ static int idx_high(int i, int len)
    {
        return ::min(i, len - 1);
    }
};
template <class SrcPtr>
__host__ BrdBase<BrdReplicate, typename PtrTraits<SrcPtr>::ptr_type> brdReplicate(const SrcPtr& src)
{
    BrdBase<BrdReplicate, typename PtrTraits<SrcPtr>::ptr_type> b;
    b.src = shrinkPtr(src);
    b.rows = getRows(src);
    b.cols = getCols(src);
    return b;
}
struct BrdReflect101
{
    __device__ __forceinline__ static int idx_low(int i, int len)
    {
        return ::abs(i) % len;
    }
    __device__ __forceinline__ static int idx_high(int i, int len)
    {
        const int last_ind = len - 1;
        return ::abs(last_ind - ::abs(last_ind - i)) % len;
    }
};
template <class SrcPtr>
__host__ BrdBase<BrdReflect101, typename PtrTraits<SrcPtr>::ptr_type> brdReflect101(const SrcPtr& src)
{
    BrdBase<BrdReflect101, typename PtrTraits<SrcPtr>::ptr_type> b;
    b.src = shrinkPtr(src);
    b.rows = getRows(src);
    b.cols = getCols(src);
    return b;
}
struct BrdReflect
{
    __device__ __forceinline__ static int idx_low(int i, int len)
    {
        return (::abs(i) - (i < 0)) % len;
    }
    __device__ __forceinline__ static int idx_high(int i, int len)
    {
        const int last_ind = len - 1;
        return (last_ind - ::abs(last_ind - i) + (i > last_ind));
    }
};
template <class SrcPtr>
__host__ BrdBase<BrdReflect, typename PtrTraits<SrcPtr>::ptr_type> brdReflect(const SrcPtr& src)
{
    BrdBase<BrdReflect, typename PtrTraits<SrcPtr>::ptr_type> b;
    b.src = shrinkPtr(src);
    b.rows = getRows(src);
    b.cols = getCols(src);
    return b;
}
struct BrdWrap
{
    __device__ __forceinline__ static int idx_low(int i, int len)
    {
        return (i >= 0) * i + (i < 0) * (i - ((i - len + 1) / len) * len);
    }
    __device__ __forceinline__ static int idx_high(int i, int len)
    {
        return (i < len) * i + (i >= len) * (i % len);
    }
};
template <class SrcPtr>
__host__ BrdBase<BrdWrap, typename PtrTraits<SrcPtr>::ptr_type> brdWrap(const SrcPtr& src)
{
    BrdBase<BrdWrap, typename PtrTraits<SrcPtr>::ptr_type> b;
    b.src = shrinkPtr(src);
    b.rows = getRows(src);
    b.cols = getCols(src);
    return b;
}
}}
#endif