Interpolation functions

group Interpolation functions

Functions

template<NVCVInterpolationType I, int Position = 1, typename IndexType = int64_t>
constexpr IndexType __host__ __device__ GetIndexForInterpolation(float c)

Function to get an integer index from a float coordinate for interpolation purpose.

Note

When IndexType is an integer type, the input coordinate is first clamped to [TypeTraits<IndexType>min / 4, TypeTraits<IndexType>max / 4] to guarantee that common downstream arithmetic performed by callers stays within IndexType's range: x + 1, ix + cx (CUBIC, cx in [-1, 2]), xmin - 1, loop ++cx, as well as GetIndexWithBorder’s 2*c + 1 - s2 (REFLECT) and c % (2*s - 2) (REFLECT101). Without this clamp, an ill-conditioned transform producing |c| >= IndexType::max would let __float2{int,ll}_rd saturate at IndexType::max; the subsequent x + 1 signed-overflows, and the resulting undefined behaviour lets the compiler elide the bounds check in GetIndexWithBorder for REPLICATE borders, leading to a cudaErrorIllegalAddress when the wild index is dereferenced by TensorWrap::ptr (CVCUDA issue #249). For any realistic pixel offset the clamp is a no-op; only pathological coordinates (orders of magnitude outside any real tensor) are clipped, in which case the returned index is well-defined but not mathematically exact.

Template Parameters:
  • I – Interpolation type, one of NVCVInterpolationType.

  • Position – Interpolation position, 1 for the first index and 2 for the second index.

  • IndexType – Type of the returned value. Defaults to int64_t; callers storing the result in a narrower integer type (e.g. int32_t) should pass that type here so the overflow-prevention clamp targets the final storage width.

Parameters:

c[in] Coordinate in floating-point to convert to index in integer.

Returns:

Index in integer suitable for interpolation computation.

inline void __host__ __device__ GetCubicCoeffs(float delta, float &w0, float &w1, float &w2, float &w3)