Returns pointer to specified element of n-d array
| 1871 | |
| 1872 | // Returns pointer to specified element of n-d array |
| 1873 | CV_IMPL uchar* |
| 1874 | cvPtrND( const CvArr* arr, const int* idx, int* _type, |
| 1875 | int create_node, unsigned* precalc_hashval ) |
| 1876 | { |
| 1877 | uchar* ptr = 0; |
| 1878 | if( !idx ) |
| 1879 | CV_Error( CV_StsNullPtr, "NULL pointer to indices" ); |
| 1880 | |
| 1881 | if( CV_IS_SPARSE_MAT( arr )) |
| 1882 | ptr = icvGetNodePtr( (CvSparseMat*)arr, idx, |
| 1883 | _type, create_node, precalc_hashval ); |
| 1884 | else if( CV_IS_MATND( arr )) |
| 1885 | { |
| 1886 | CvMatND* mat = (CvMatND*)arr; |
| 1887 | int i; |
| 1888 | ptr = mat->data.ptr; |
| 1889 | |
| 1890 | for( i = 0; i < mat->dims; i++ ) |
| 1891 | { |
| 1892 | if( (unsigned)idx[i] >= (unsigned)(mat->dim[i].size) ) |
| 1893 | CV_Error( CV_StsOutOfRange, "index is out of range" ); |
| 1894 | ptr += (size_t)idx[i]*mat->dim[i].step; |
| 1895 | } |
| 1896 | |
| 1897 | if( _type ) |
| 1898 | *_type = CV_MAT_TYPE(mat->type); |
| 1899 | } |
| 1900 | else if( CV_IS_MAT_HDR(arr) || CV_IS_IMAGE_HDR(arr) ) |
| 1901 | ptr = cvPtr2D( arr, idx[0], idx[1], _type ); |
| 1902 | else |
| 1903 | CV_Error( CV_StsBadArg, "unrecognized or unsupported array type" ); |
| 1904 | |
| 1905 | return ptr; |
| 1906 | } |
| 1907 | |
| 1908 | |
| 1909 | // Returns specifed element of n-D array given linear index |
no test coverage detected