Returns specifed element of n-D array given linear index
| 2019 | |
| 2020 | // Returns specifed element of n-D array given linear index |
| 2021 | CV_IMPL double |
| 2022 | cvGetReal1D( const CvArr* arr, int idx ) |
| 2023 | { |
| 2024 | double value = 0; |
| 2025 | int type = 0; |
| 2026 | uchar* ptr; |
| 2027 | |
| 2028 | if( CV_IS_MAT( arr ) && CV_IS_MAT_CONT( ((CvMat*)arr)->type )) |
| 2029 | { |
| 2030 | CvMat* mat = (CvMat*)arr; |
| 2031 | |
| 2032 | type = CV_MAT_TYPE(mat->type); |
| 2033 | int pix_size = CV_ELEM_SIZE(type); |
| 2034 | |
| 2035 | // the first part is mul-free sufficient check |
| 2036 | // that the index is within the matrix |
| 2037 | if( (unsigned)idx >= (unsigned)(mat->rows + mat->cols - 1) && |
| 2038 | (unsigned)idx >= (unsigned)(mat->rows*mat->cols)) |
| 2039 | CV_Error( CV_StsOutOfRange, "index is out of range" ); |
| 2040 | |
| 2041 | ptr = mat->data.ptr + (size_t)idx*pix_size; |
| 2042 | } |
| 2043 | else if( !CV_IS_SPARSE_MAT( arr ) || ((CvSparseMat*)arr)->dims > 1 ) |
| 2044 | ptr = cvPtr1D( arr, idx, &type ); |
| 2045 | else |
| 2046 | ptr = icvGetNodePtr( (CvSparseMat*)arr, &idx, &type, 0, 0 ); |
| 2047 | |
| 2048 | if( ptr ) |
| 2049 | { |
| 2050 | if( CV_MAT_CN( type ) > 1 ) |
| 2051 | CV_Error( CV_BadNumChannels, "cvGetReal* support only single-channel arrays" ); |
| 2052 | |
| 2053 | value = icvGetReal( ptr, type ); |
| 2054 | } |
| 2055 | return value; |
| 2056 | } |
| 2057 | |
| 2058 | |
| 2059 | // Returns specifed element of 2D array |
nothing calls this directly
no test coverage detected