Joe Verbout
/
main
opencv on mbed
opencv2/core/mat.inl.hpp@0:ea44dc9ed014, 2016-03-31 (annotated)
- Committer:
- joeverbout
- Date:
- Thu Mar 31 21:16:38 2016 +0000
- Revision:
- 0:ea44dc9ed014
OpenCV on mbed attempt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joeverbout | 0:ea44dc9ed014 | 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 2 | // |
joeverbout | 0:ea44dc9ed014 | 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
joeverbout | 0:ea44dc9ed014 | 4 | // |
joeverbout | 0:ea44dc9ed014 | 5 | // By downloading, copying, installing or using the software you agree to this license. |
joeverbout | 0:ea44dc9ed014 | 6 | // If you do not agree to this license, do not download, install, |
joeverbout | 0:ea44dc9ed014 | 7 | // copy or use the software. |
joeverbout | 0:ea44dc9ed014 | 8 | // |
joeverbout | 0:ea44dc9ed014 | 9 | // |
joeverbout | 0:ea44dc9ed014 | 10 | // License Agreement |
joeverbout | 0:ea44dc9ed014 | 11 | // For Open Source Computer Vision Library |
joeverbout | 0:ea44dc9ed014 | 12 | // |
joeverbout | 0:ea44dc9ed014 | 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 16 | // Copyright (C) 2015, Itseez Inc., all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 17 | // Third party copyrights are property of their respective owners. |
joeverbout | 0:ea44dc9ed014 | 18 | // |
joeverbout | 0:ea44dc9ed014 | 19 | // Redistribution and use in source and binary forms, with or without modification, |
joeverbout | 0:ea44dc9ed014 | 20 | // are permitted provided that the following conditions are met: |
joeverbout | 0:ea44dc9ed014 | 21 | // |
joeverbout | 0:ea44dc9ed014 | 22 | // * Redistribution's of source code must retain the above copyright notice, |
joeverbout | 0:ea44dc9ed014 | 23 | // this list of conditions and the following disclaimer. |
joeverbout | 0:ea44dc9ed014 | 24 | // |
joeverbout | 0:ea44dc9ed014 | 25 | // * Redistribution's in binary form must reproduce the above copyright notice, |
joeverbout | 0:ea44dc9ed014 | 26 | // this list of conditions and the following disclaimer in the documentation |
joeverbout | 0:ea44dc9ed014 | 27 | // and/or other materials provided with the distribution. |
joeverbout | 0:ea44dc9ed014 | 28 | // |
joeverbout | 0:ea44dc9ed014 | 29 | // * The name of the copyright holders may not be used to endorse or promote products |
joeverbout | 0:ea44dc9ed014 | 30 | // derived from this software without specific prior written permission. |
joeverbout | 0:ea44dc9ed014 | 31 | // |
joeverbout | 0:ea44dc9ed014 | 32 | // This software is provided by the copyright holders and contributors "as is" and |
joeverbout | 0:ea44dc9ed014 | 33 | // any express or implied warranties, including, but not limited to, the implied |
joeverbout | 0:ea44dc9ed014 | 34 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
joeverbout | 0:ea44dc9ed014 | 35 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
joeverbout | 0:ea44dc9ed014 | 36 | // indirect, incidental, special, exemplary, or consequential damages |
joeverbout | 0:ea44dc9ed014 | 37 | // (including, but not limited to, procurement of substitute goods or services; |
joeverbout | 0:ea44dc9ed014 | 38 | // loss of use, data, or profits; or business interruption) however caused |
joeverbout | 0:ea44dc9ed014 | 39 | // and on any theory of liability, whether in contract, strict liability, |
joeverbout | 0:ea44dc9ed014 | 40 | // or tort (including negligence or otherwise) arising in any way out of |
joeverbout | 0:ea44dc9ed014 | 41 | // the use of this software, even if advised of the possibility of such damage. |
joeverbout | 0:ea44dc9ed014 | 42 | // |
joeverbout | 0:ea44dc9ed014 | 43 | //M*/ |
joeverbout | 0:ea44dc9ed014 | 44 | |
joeverbout | 0:ea44dc9ed014 | 45 | #ifndef __OPENCV_CORE_MATRIX_OPERATIONS_HPP__ |
joeverbout | 0:ea44dc9ed014 | 46 | #define __OPENCV_CORE_MATRIX_OPERATIONS_HPP__ |
joeverbout | 0:ea44dc9ed014 | 47 | |
joeverbout | 0:ea44dc9ed014 | 48 | #ifndef __cplusplus |
joeverbout | 0:ea44dc9ed014 | 49 | # error mat.inl.hpp header must be compiled as C++ |
joeverbout | 0:ea44dc9ed014 | 50 | #endif |
joeverbout | 0:ea44dc9ed014 | 51 | |
joeverbout | 0:ea44dc9ed014 | 52 | namespace cv |
joeverbout | 0:ea44dc9ed014 | 53 | { |
joeverbout | 0:ea44dc9ed014 | 54 | |
joeverbout | 0:ea44dc9ed014 | 55 | //! @cond IGNORED |
joeverbout | 0:ea44dc9ed014 | 56 | |
joeverbout | 0:ea44dc9ed014 | 57 | //////////////////////// Input/Output Arrays //////////////////////// |
joeverbout | 0:ea44dc9ed014 | 58 | |
joeverbout | 0:ea44dc9ed014 | 59 | inline void _InputArray::init(int _flags, const void* _obj) |
joeverbout | 0:ea44dc9ed014 | 60 | { flags = _flags; obj = (void*)_obj; } |
joeverbout | 0:ea44dc9ed014 | 61 | |
joeverbout | 0:ea44dc9ed014 | 62 | inline void _InputArray::init(int _flags, const void* _obj, Size _sz) |
joeverbout | 0:ea44dc9ed014 | 63 | { flags = _flags; obj = (void*)_obj; sz = _sz; } |
joeverbout | 0:ea44dc9ed014 | 64 | |
joeverbout | 0:ea44dc9ed014 | 65 | inline void* _InputArray::getObj() const { return obj; } |
joeverbout | 0:ea44dc9ed014 | 66 | inline int _InputArray::getFlags() const { return flags; } |
joeverbout | 0:ea44dc9ed014 | 67 | inline Size _InputArray::getSz() const { return sz; } |
joeverbout | 0:ea44dc9ed014 | 68 | |
joeverbout | 0:ea44dc9ed014 | 69 | inline _InputArray::_InputArray() { init(NONE, 0); } |
joeverbout | 0:ea44dc9ed014 | 70 | inline _InputArray::_InputArray(int _flags, void* _obj) { init(_flags, _obj); } |
joeverbout | 0:ea44dc9ed014 | 71 | inline _InputArray::_InputArray(const Mat& m) { init(MAT+ACCESS_READ, &m); } |
joeverbout | 0:ea44dc9ed014 | 72 | inline _InputArray::_InputArray(const std::vector<Mat>& vec) { init(STD_VECTOR_MAT+ACCESS_READ, &vec); } |
joeverbout | 0:ea44dc9ed014 | 73 | inline _InputArray::_InputArray(const UMat& m) { init(UMAT+ACCESS_READ, &m); } |
joeverbout | 0:ea44dc9ed014 | 74 | inline _InputArray::_InputArray(const std::vector<UMat>& vec) { init(STD_VECTOR_UMAT+ACCESS_READ, &vec); } |
joeverbout | 0:ea44dc9ed014 | 75 | |
joeverbout | 0:ea44dc9ed014 | 76 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 77 | _InputArray::_InputArray(const std::vector<_Tp>& vec) |
joeverbout | 0:ea44dc9ed014 | 78 | { init(FIXED_TYPE + STD_VECTOR + DataType<_Tp>::type + ACCESS_READ, &vec); } |
joeverbout | 0:ea44dc9ed014 | 79 | |
joeverbout | 0:ea44dc9ed014 | 80 | inline |
joeverbout | 0:ea44dc9ed014 | 81 | _InputArray::_InputArray(const std::vector<bool>& vec) |
joeverbout | 0:ea44dc9ed014 | 82 | { init(FIXED_TYPE + STD_BOOL_VECTOR + DataType<bool>::type + ACCESS_READ, &vec); } |
joeverbout | 0:ea44dc9ed014 | 83 | |
joeverbout | 0:ea44dc9ed014 | 84 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 85 | _InputArray::_InputArray(const std::vector<std::vector<_Tp> >& vec) |
joeverbout | 0:ea44dc9ed014 | 86 | { init(FIXED_TYPE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_READ, &vec); } |
joeverbout | 0:ea44dc9ed014 | 87 | |
joeverbout | 0:ea44dc9ed014 | 88 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 89 | _InputArray::_InputArray(const std::vector<Mat_<_Tp> >& vec) |
joeverbout | 0:ea44dc9ed014 | 90 | { init(FIXED_TYPE + STD_VECTOR_MAT + DataType<_Tp>::type + ACCESS_READ, &vec); } |
joeverbout | 0:ea44dc9ed014 | 91 | |
joeverbout | 0:ea44dc9ed014 | 92 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 93 | _InputArray::_InputArray(const Matx<_Tp, m, n>& mtx) |
joeverbout | 0:ea44dc9ed014 | 94 | { init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_READ, &mtx, Size(n, m)); } |
joeverbout | 0:ea44dc9ed014 | 95 | |
joeverbout | 0:ea44dc9ed014 | 96 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 97 | _InputArray::_InputArray(const _Tp* vec, int n) |
joeverbout | 0:ea44dc9ed014 | 98 | { init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_READ, vec, Size(n, 1)); } |
joeverbout | 0:ea44dc9ed014 | 99 | |
joeverbout | 0:ea44dc9ed014 | 100 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 101 | _InputArray::_InputArray(const Mat_<_Tp>& m) |
joeverbout | 0:ea44dc9ed014 | 102 | { init(FIXED_TYPE + MAT + DataType<_Tp>::type + ACCESS_READ, &m); } |
joeverbout | 0:ea44dc9ed014 | 103 | |
joeverbout | 0:ea44dc9ed014 | 104 | inline _InputArray::_InputArray(const double& val) |
joeverbout | 0:ea44dc9ed014 | 105 | { init(FIXED_TYPE + FIXED_SIZE + MATX + CV_64F + ACCESS_READ, &val, Size(1,1)); } |
joeverbout | 0:ea44dc9ed014 | 106 | |
joeverbout | 0:ea44dc9ed014 | 107 | inline _InputArray::_InputArray(const MatExpr& expr) |
joeverbout | 0:ea44dc9ed014 | 108 | { init(FIXED_TYPE + FIXED_SIZE + EXPR + ACCESS_READ, &expr); } |
joeverbout | 0:ea44dc9ed014 | 109 | |
joeverbout | 0:ea44dc9ed014 | 110 | inline _InputArray::_InputArray(const cuda::GpuMat& d_mat) |
joeverbout | 0:ea44dc9ed014 | 111 | { init(CUDA_GPU_MAT + ACCESS_READ, &d_mat); } |
joeverbout | 0:ea44dc9ed014 | 112 | |
joeverbout | 0:ea44dc9ed014 | 113 | inline _InputArray::_InputArray(const std::vector<cuda::GpuMat>& d_mat) |
joeverbout | 0:ea44dc9ed014 | 114 | { init(STD_VECTOR_CUDA_GPU_MAT + ACCESS_READ, &d_mat);} |
joeverbout | 0:ea44dc9ed014 | 115 | |
joeverbout | 0:ea44dc9ed014 | 116 | inline _InputArray::_InputArray(const ogl::Buffer& buf) |
joeverbout | 0:ea44dc9ed014 | 117 | { init(OPENGL_BUFFER + ACCESS_READ, &buf); } |
joeverbout | 0:ea44dc9ed014 | 118 | |
joeverbout | 0:ea44dc9ed014 | 119 | inline _InputArray::_InputArray(const cuda::HostMem& cuda_mem) |
joeverbout | 0:ea44dc9ed014 | 120 | { init(CUDA_HOST_MEM + ACCESS_READ, &cuda_mem); } |
joeverbout | 0:ea44dc9ed014 | 121 | |
joeverbout | 0:ea44dc9ed014 | 122 | inline _InputArray::~_InputArray() {} |
joeverbout | 0:ea44dc9ed014 | 123 | |
joeverbout | 0:ea44dc9ed014 | 124 | inline Mat _InputArray::getMat(int i) const |
joeverbout | 0:ea44dc9ed014 | 125 | { |
joeverbout | 0:ea44dc9ed014 | 126 | if( kind() == MAT && i < 0 ) |
joeverbout | 0:ea44dc9ed014 | 127 | return *(const Mat*)obj; |
joeverbout | 0:ea44dc9ed014 | 128 | return getMat_(i); |
joeverbout | 0:ea44dc9ed014 | 129 | } |
joeverbout | 0:ea44dc9ed014 | 130 | |
joeverbout | 0:ea44dc9ed014 | 131 | inline bool _InputArray::isMat() const { return kind() == _InputArray::MAT; } |
joeverbout | 0:ea44dc9ed014 | 132 | inline bool _InputArray::isUMat() const { return kind() == _InputArray::UMAT; } |
joeverbout | 0:ea44dc9ed014 | 133 | inline bool _InputArray::isMatVector() const { return kind() == _InputArray::STD_VECTOR_MAT; } |
joeverbout | 0:ea44dc9ed014 | 134 | inline bool _InputArray::isUMatVector() const { return kind() == _InputArray::STD_VECTOR_UMAT; } |
joeverbout | 0:ea44dc9ed014 | 135 | inline bool _InputArray::isMatx() const { return kind() == _InputArray::MATX; } |
joeverbout | 0:ea44dc9ed014 | 136 | inline bool _InputArray::isVector() const { return kind() == _InputArray::STD_VECTOR || kind() == _InputArray::STD_BOOL_VECTOR; } |
joeverbout | 0:ea44dc9ed014 | 137 | inline bool _InputArray::isGpuMatVector() const { return kind() == _InputArray::STD_VECTOR_CUDA_GPU_MAT; } |
joeverbout | 0:ea44dc9ed014 | 138 | |
joeverbout | 0:ea44dc9ed014 | 139 | //////////////////////////////////////////////////////////////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 140 | |
joeverbout | 0:ea44dc9ed014 | 141 | inline _OutputArray::_OutputArray() { init(ACCESS_WRITE, 0); } |
joeverbout | 0:ea44dc9ed014 | 142 | inline _OutputArray::_OutputArray(int _flags, void* _obj) { init(_flags|ACCESS_WRITE, _obj); } |
joeverbout | 0:ea44dc9ed014 | 143 | inline _OutputArray::_OutputArray(Mat& m) { init(MAT+ACCESS_WRITE, &m); } |
joeverbout | 0:ea44dc9ed014 | 144 | inline _OutputArray::_OutputArray(std::vector<Mat>& vec) { init(STD_VECTOR_MAT+ACCESS_WRITE, &vec); } |
joeverbout | 0:ea44dc9ed014 | 145 | inline _OutputArray::_OutputArray(UMat& m) { init(UMAT+ACCESS_WRITE, &m); } |
joeverbout | 0:ea44dc9ed014 | 146 | inline _OutputArray::_OutputArray(std::vector<UMat>& vec) { init(STD_VECTOR_UMAT+ACCESS_WRITE, &vec); } |
joeverbout | 0:ea44dc9ed014 | 147 | |
joeverbout | 0:ea44dc9ed014 | 148 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 149 | _OutputArray::_OutputArray(std::vector<_Tp>& vec) |
joeverbout | 0:ea44dc9ed014 | 150 | { init(FIXED_TYPE + STD_VECTOR + DataType<_Tp>::type + ACCESS_WRITE, &vec); } |
joeverbout | 0:ea44dc9ed014 | 151 | |
joeverbout | 0:ea44dc9ed014 | 152 | inline |
joeverbout | 0:ea44dc9ed014 | 153 | _OutputArray::_OutputArray(std::vector<bool>&) |
joeverbout | 0:ea44dc9ed014 | 154 | { CV_Error(Error::StsUnsupportedFormat, "std::vector<bool> cannot be an output array\n"); } |
joeverbout | 0:ea44dc9ed014 | 155 | |
joeverbout | 0:ea44dc9ed014 | 156 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 157 | _OutputArray::_OutputArray(std::vector<std::vector<_Tp> >& vec) |
joeverbout | 0:ea44dc9ed014 | 158 | { init(FIXED_TYPE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_WRITE, &vec); } |
joeverbout | 0:ea44dc9ed014 | 159 | |
joeverbout | 0:ea44dc9ed014 | 160 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 161 | _OutputArray::_OutputArray(std::vector<Mat_<_Tp> >& vec) |
joeverbout | 0:ea44dc9ed014 | 162 | { init(FIXED_TYPE + STD_VECTOR_MAT + DataType<_Tp>::type + ACCESS_WRITE, &vec); } |
joeverbout | 0:ea44dc9ed014 | 163 | |
joeverbout | 0:ea44dc9ed014 | 164 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 165 | _OutputArray::_OutputArray(Mat_<_Tp>& m) |
joeverbout | 0:ea44dc9ed014 | 166 | { init(FIXED_TYPE + MAT + DataType<_Tp>::type + ACCESS_WRITE, &m); } |
joeverbout | 0:ea44dc9ed014 | 167 | |
joeverbout | 0:ea44dc9ed014 | 168 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 169 | _OutputArray::_OutputArray(Matx<_Tp, m, n>& mtx) |
joeverbout | 0:ea44dc9ed014 | 170 | { init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_WRITE, &mtx, Size(n, m)); } |
joeverbout | 0:ea44dc9ed014 | 171 | |
joeverbout | 0:ea44dc9ed014 | 172 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 173 | _OutputArray::_OutputArray(_Tp* vec, int n) |
joeverbout | 0:ea44dc9ed014 | 174 | { init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_WRITE, vec, Size(n, 1)); } |
joeverbout | 0:ea44dc9ed014 | 175 | |
joeverbout | 0:ea44dc9ed014 | 176 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 177 | _OutputArray::_OutputArray(const std::vector<_Tp>& vec) |
joeverbout | 0:ea44dc9ed014 | 178 | { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + DataType<_Tp>::type + ACCESS_WRITE, &vec); } |
joeverbout | 0:ea44dc9ed014 | 179 | |
joeverbout | 0:ea44dc9ed014 | 180 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 181 | _OutputArray::_OutputArray(const std::vector<std::vector<_Tp> >& vec) |
joeverbout | 0:ea44dc9ed014 | 182 | { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_WRITE, &vec); } |
joeverbout | 0:ea44dc9ed014 | 183 | |
joeverbout | 0:ea44dc9ed014 | 184 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 185 | _OutputArray::_OutputArray(const std::vector<Mat_<_Tp> >& vec) |
joeverbout | 0:ea44dc9ed014 | 186 | { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + DataType<_Tp>::type + ACCESS_WRITE, &vec); } |
joeverbout | 0:ea44dc9ed014 | 187 | |
joeverbout | 0:ea44dc9ed014 | 188 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 189 | _OutputArray::_OutputArray(const Mat_<_Tp>& m) |
joeverbout | 0:ea44dc9ed014 | 190 | { init(FIXED_TYPE + FIXED_SIZE + MAT + DataType<_Tp>::type + ACCESS_WRITE, &m); } |
joeverbout | 0:ea44dc9ed014 | 191 | |
joeverbout | 0:ea44dc9ed014 | 192 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 193 | _OutputArray::_OutputArray(const Matx<_Tp, m, n>& mtx) |
joeverbout | 0:ea44dc9ed014 | 194 | { init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_WRITE, &mtx, Size(n, m)); } |
joeverbout | 0:ea44dc9ed014 | 195 | |
joeverbout | 0:ea44dc9ed014 | 196 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 197 | _OutputArray::_OutputArray(const _Tp* vec, int n) |
joeverbout | 0:ea44dc9ed014 | 198 | { init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_WRITE, vec, Size(n, 1)); } |
joeverbout | 0:ea44dc9ed014 | 199 | |
joeverbout | 0:ea44dc9ed014 | 200 | inline _OutputArray::_OutputArray(cuda::GpuMat& d_mat) |
joeverbout | 0:ea44dc9ed014 | 201 | { init(CUDA_GPU_MAT + ACCESS_WRITE, &d_mat); } |
joeverbout | 0:ea44dc9ed014 | 202 | |
joeverbout | 0:ea44dc9ed014 | 203 | inline _OutputArray::_OutputArray(std::vector<cuda::GpuMat>& d_mat) |
joeverbout | 0:ea44dc9ed014 | 204 | { init(STD_VECTOR_CUDA_GPU_MAT + ACCESS_WRITE, &d_mat);} |
joeverbout | 0:ea44dc9ed014 | 205 | |
joeverbout | 0:ea44dc9ed014 | 206 | inline _OutputArray::_OutputArray(ogl::Buffer& buf) |
joeverbout | 0:ea44dc9ed014 | 207 | { init(OPENGL_BUFFER + ACCESS_WRITE, &buf); } |
joeverbout | 0:ea44dc9ed014 | 208 | |
joeverbout | 0:ea44dc9ed014 | 209 | inline _OutputArray::_OutputArray(cuda::HostMem& cuda_mem) |
joeverbout | 0:ea44dc9ed014 | 210 | { init(CUDA_HOST_MEM + ACCESS_WRITE, &cuda_mem); } |
joeverbout | 0:ea44dc9ed014 | 211 | |
joeverbout | 0:ea44dc9ed014 | 212 | inline _OutputArray::_OutputArray(const Mat& m) |
joeverbout | 0:ea44dc9ed014 | 213 | { init(FIXED_TYPE + FIXED_SIZE + MAT + ACCESS_WRITE, &m); } |
joeverbout | 0:ea44dc9ed014 | 214 | |
joeverbout | 0:ea44dc9ed014 | 215 | inline _OutputArray::_OutputArray(const std::vector<Mat>& vec) |
joeverbout | 0:ea44dc9ed014 | 216 | { init(FIXED_SIZE + STD_VECTOR_MAT + ACCESS_WRITE, &vec); } |
joeverbout | 0:ea44dc9ed014 | 217 | |
joeverbout | 0:ea44dc9ed014 | 218 | inline _OutputArray::_OutputArray(const UMat& m) |
joeverbout | 0:ea44dc9ed014 | 219 | { init(FIXED_TYPE + FIXED_SIZE + UMAT + ACCESS_WRITE, &m); } |
joeverbout | 0:ea44dc9ed014 | 220 | |
joeverbout | 0:ea44dc9ed014 | 221 | inline _OutputArray::_OutputArray(const std::vector<UMat>& vec) |
joeverbout | 0:ea44dc9ed014 | 222 | { init(FIXED_SIZE + STD_VECTOR_UMAT + ACCESS_WRITE, &vec); } |
joeverbout | 0:ea44dc9ed014 | 223 | |
joeverbout | 0:ea44dc9ed014 | 224 | inline _OutputArray::_OutputArray(const cuda::GpuMat& d_mat) |
joeverbout | 0:ea44dc9ed014 | 225 | { init(FIXED_TYPE + FIXED_SIZE + CUDA_GPU_MAT + ACCESS_WRITE, &d_mat); } |
joeverbout | 0:ea44dc9ed014 | 226 | |
joeverbout | 0:ea44dc9ed014 | 227 | |
joeverbout | 0:ea44dc9ed014 | 228 | inline _OutputArray::_OutputArray(const ogl::Buffer& buf) |
joeverbout | 0:ea44dc9ed014 | 229 | { init(FIXED_TYPE + FIXED_SIZE + OPENGL_BUFFER + ACCESS_WRITE, &buf); } |
joeverbout | 0:ea44dc9ed014 | 230 | |
joeverbout | 0:ea44dc9ed014 | 231 | inline _OutputArray::_OutputArray(const cuda::HostMem& cuda_mem) |
joeverbout | 0:ea44dc9ed014 | 232 | { init(FIXED_TYPE + FIXED_SIZE + CUDA_HOST_MEM + ACCESS_WRITE, &cuda_mem); } |
joeverbout | 0:ea44dc9ed014 | 233 | |
joeverbout | 0:ea44dc9ed014 | 234 | /////////////////////////////////////////////////////////////////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 235 | |
joeverbout | 0:ea44dc9ed014 | 236 | inline _InputOutputArray::_InputOutputArray() { init(ACCESS_RW, 0); } |
joeverbout | 0:ea44dc9ed014 | 237 | inline _InputOutputArray::_InputOutputArray(int _flags, void* _obj) { init(_flags|ACCESS_RW, _obj); } |
joeverbout | 0:ea44dc9ed014 | 238 | inline _InputOutputArray::_InputOutputArray(Mat& m) { init(MAT+ACCESS_RW, &m); } |
joeverbout | 0:ea44dc9ed014 | 239 | inline _InputOutputArray::_InputOutputArray(std::vector<Mat>& vec) { init(STD_VECTOR_MAT+ACCESS_RW, &vec); } |
joeverbout | 0:ea44dc9ed014 | 240 | inline _InputOutputArray::_InputOutputArray(UMat& m) { init(UMAT+ACCESS_RW, &m); } |
joeverbout | 0:ea44dc9ed014 | 241 | inline _InputOutputArray::_InputOutputArray(std::vector<UMat>& vec) { init(STD_VECTOR_UMAT+ACCESS_RW, &vec); } |
joeverbout | 0:ea44dc9ed014 | 242 | |
joeverbout | 0:ea44dc9ed014 | 243 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 244 | _InputOutputArray::_InputOutputArray(std::vector<_Tp>& vec) |
joeverbout | 0:ea44dc9ed014 | 245 | { init(FIXED_TYPE + STD_VECTOR + DataType<_Tp>::type + ACCESS_RW, &vec); } |
joeverbout | 0:ea44dc9ed014 | 246 | |
joeverbout | 0:ea44dc9ed014 | 247 | inline _InputOutputArray::_InputOutputArray(std::vector<bool>&) |
joeverbout | 0:ea44dc9ed014 | 248 | { CV_Error(Error::StsUnsupportedFormat, "std::vector<bool> cannot be an input/output array\n"); } |
joeverbout | 0:ea44dc9ed014 | 249 | |
joeverbout | 0:ea44dc9ed014 | 250 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 251 | _InputOutputArray::_InputOutputArray(std::vector<std::vector<_Tp> >& vec) |
joeverbout | 0:ea44dc9ed014 | 252 | { init(FIXED_TYPE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_RW, &vec); } |
joeverbout | 0:ea44dc9ed014 | 253 | |
joeverbout | 0:ea44dc9ed014 | 254 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 255 | _InputOutputArray::_InputOutputArray(std::vector<Mat_<_Tp> >& vec) |
joeverbout | 0:ea44dc9ed014 | 256 | { init(FIXED_TYPE + STD_VECTOR_MAT + DataType<_Tp>::type + ACCESS_RW, &vec); } |
joeverbout | 0:ea44dc9ed014 | 257 | |
joeverbout | 0:ea44dc9ed014 | 258 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 259 | _InputOutputArray::_InputOutputArray(Mat_<_Tp>& m) |
joeverbout | 0:ea44dc9ed014 | 260 | { init(FIXED_TYPE + MAT + DataType<_Tp>::type + ACCESS_RW, &m); } |
joeverbout | 0:ea44dc9ed014 | 261 | |
joeverbout | 0:ea44dc9ed014 | 262 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 263 | _InputOutputArray::_InputOutputArray(Matx<_Tp, m, n>& mtx) |
joeverbout | 0:ea44dc9ed014 | 264 | { init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_RW, &mtx, Size(n, m)); } |
joeverbout | 0:ea44dc9ed014 | 265 | |
joeverbout | 0:ea44dc9ed014 | 266 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 267 | _InputOutputArray::_InputOutputArray(_Tp* vec, int n) |
joeverbout | 0:ea44dc9ed014 | 268 | { init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_RW, vec, Size(n, 1)); } |
joeverbout | 0:ea44dc9ed014 | 269 | |
joeverbout | 0:ea44dc9ed014 | 270 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 271 | _InputOutputArray::_InputOutputArray(const std::vector<_Tp>& vec) |
joeverbout | 0:ea44dc9ed014 | 272 | { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + DataType<_Tp>::type + ACCESS_RW, &vec); } |
joeverbout | 0:ea44dc9ed014 | 273 | |
joeverbout | 0:ea44dc9ed014 | 274 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 275 | _InputOutputArray::_InputOutputArray(const std::vector<std::vector<_Tp> >& vec) |
joeverbout | 0:ea44dc9ed014 | 276 | { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + DataType<_Tp>::type + ACCESS_RW, &vec); } |
joeverbout | 0:ea44dc9ed014 | 277 | |
joeverbout | 0:ea44dc9ed014 | 278 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 279 | _InputOutputArray::_InputOutputArray(const std::vector<Mat_<_Tp> >& vec) |
joeverbout | 0:ea44dc9ed014 | 280 | { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + DataType<_Tp>::type + ACCESS_RW, &vec); } |
joeverbout | 0:ea44dc9ed014 | 281 | |
joeverbout | 0:ea44dc9ed014 | 282 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 283 | _InputOutputArray::_InputOutputArray(const Mat_<_Tp>& m) |
joeverbout | 0:ea44dc9ed014 | 284 | { init(FIXED_TYPE + FIXED_SIZE + MAT + DataType<_Tp>::type + ACCESS_RW, &m); } |
joeverbout | 0:ea44dc9ed014 | 285 | |
joeverbout | 0:ea44dc9ed014 | 286 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 287 | _InputOutputArray::_InputOutputArray(const Matx<_Tp, m, n>& mtx) |
joeverbout | 0:ea44dc9ed014 | 288 | { init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_RW, &mtx, Size(n, m)); } |
joeverbout | 0:ea44dc9ed014 | 289 | |
joeverbout | 0:ea44dc9ed014 | 290 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 291 | _InputOutputArray::_InputOutputArray(const _Tp* vec, int n) |
joeverbout | 0:ea44dc9ed014 | 292 | { init(FIXED_TYPE + FIXED_SIZE + MATX + DataType<_Tp>::type + ACCESS_RW, vec, Size(n, 1)); } |
joeverbout | 0:ea44dc9ed014 | 293 | |
joeverbout | 0:ea44dc9ed014 | 294 | inline _InputOutputArray::_InputOutputArray(cuda::GpuMat& d_mat) |
joeverbout | 0:ea44dc9ed014 | 295 | { init(CUDA_GPU_MAT + ACCESS_RW, &d_mat); } |
joeverbout | 0:ea44dc9ed014 | 296 | |
joeverbout | 0:ea44dc9ed014 | 297 | inline _InputOutputArray::_InputOutputArray(ogl::Buffer& buf) |
joeverbout | 0:ea44dc9ed014 | 298 | { init(OPENGL_BUFFER + ACCESS_RW, &buf); } |
joeverbout | 0:ea44dc9ed014 | 299 | |
joeverbout | 0:ea44dc9ed014 | 300 | inline _InputOutputArray::_InputOutputArray(cuda::HostMem& cuda_mem) |
joeverbout | 0:ea44dc9ed014 | 301 | { init(CUDA_HOST_MEM + ACCESS_RW, &cuda_mem); } |
joeverbout | 0:ea44dc9ed014 | 302 | |
joeverbout | 0:ea44dc9ed014 | 303 | inline _InputOutputArray::_InputOutputArray(const Mat& m) |
joeverbout | 0:ea44dc9ed014 | 304 | { init(FIXED_TYPE + FIXED_SIZE + MAT + ACCESS_RW, &m); } |
joeverbout | 0:ea44dc9ed014 | 305 | |
joeverbout | 0:ea44dc9ed014 | 306 | inline _InputOutputArray::_InputOutputArray(const std::vector<Mat>& vec) |
joeverbout | 0:ea44dc9ed014 | 307 | { init(FIXED_SIZE + STD_VECTOR_MAT + ACCESS_RW, &vec); } |
joeverbout | 0:ea44dc9ed014 | 308 | |
joeverbout | 0:ea44dc9ed014 | 309 | inline _InputOutputArray::_InputOutputArray(const UMat& m) |
joeverbout | 0:ea44dc9ed014 | 310 | { init(FIXED_TYPE + FIXED_SIZE + UMAT + ACCESS_RW, &m); } |
joeverbout | 0:ea44dc9ed014 | 311 | |
joeverbout | 0:ea44dc9ed014 | 312 | inline _InputOutputArray::_InputOutputArray(const std::vector<UMat>& vec) |
joeverbout | 0:ea44dc9ed014 | 313 | { init(FIXED_SIZE + STD_VECTOR_UMAT + ACCESS_RW, &vec); } |
joeverbout | 0:ea44dc9ed014 | 314 | |
joeverbout | 0:ea44dc9ed014 | 315 | inline _InputOutputArray::_InputOutputArray(const cuda::GpuMat& d_mat) |
joeverbout | 0:ea44dc9ed014 | 316 | { init(FIXED_TYPE + FIXED_SIZE + CUDA_GPU_MAT + ACCESS_RW, &d_mat); } |
joeverbout | 0:ea44dc9ed014 | 317 | inline _InputOutputArray::_InputOutputArray(const std::vector<cuda::GpuMat>& d_mat) |
joeverbout | 0:ea44dc9ed014 | 318 | { init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_CUDA_GPU_MAT + ACCESS_RW, &d_mat);} |
joeverbout | 0:ea44dc9ed014 | 319 | |
joeverbout | 0:ea44dc9ed014 | 320 | inline _InputOutputArray::_InputOutputArray(const ogl::Buffer& buf) |
joeverbout | 0:ea44dc9ed014 | 321 | { init(FIXED_TYPE + FIXED_SIZE + OPENGL_BUFFER + ACCESS_RW, &buf); } |
joeverbout | 0:ea44dc9ed014 | 322 | |
joeverbout | 0:ea44dc9ed014 | 323 | inline _InputOutputArray::_InputOutputArray(const cuda::HostMem& cuda_mem) |
joeverbout | 0:ea44dc9ed014 | 324 | { init(FIXED_TYPE + FIXED_SIZE + CUDA_HOST_MEM + ACCESS_RW, &cuda_mem); } |
joeverbout | 0:ea44dc9ed014 | 325 | |
joeverbout | 0:ea44dc9ed014 | 326 | //////////////////////////////////////////// Mat ////////////////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 327 | |
joeverbout | 0:ea44dc9ed014 | 328 | inline |
joeverbout | 0:ea44dc9ed014 | 329 | Mat::Mat() |
joeverbout | 0:ea44dc9ed014 | 330 | : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), |
joeverbout | 0:ea44dc9ed014 | 331 | datalimit(0), allocator(0), u(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 332 | {} |
joeverbout | 0:ea44dc9ed014 | 333 | |
joeverbout | 0:ea44dc9ed014 | 334 | inline |
joeverbout | 0:ea44dc9ed014 | 335 | Mat::Mat(int _rows, int _cols, int _type) |
joeverbout | 0:ea44dc9ed014 | 336 | : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), |
joeverbout | 0:ea44dc9ed014 | 337 | datalimit(0), allocator(0), u(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 338 | { |
joeverbout | 0:ea44dc9ed014 | 339 | create(_rows, _cols, _type); |
joeverbout | 0:ea44dc9ed014 | 340 | } |
joeverbout | 0:ea44dc9ed014 | 341 | |
joeverbout | 0:ea44dc9ed014 | 342 | inline |
joeverbout | 0:ea44dc9ed014 | 343 | Mat::Mat(int _rows, int _cols, int _type, const Scalar& _s) |
joeverbout | 0:ea44dc9ed014 | 344 | : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), |
joeverbout | 0:ea44dc9ed014 | 345 | datalimit(0), allocator(0), u(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 346 | { |
joeverbout | 0:ea44dc9ed014 | 347 | create(_rows, _cols, _type); |
joeverbout | 0:ea44dc9ed014 | 348 | *this = _s; |
joeverbout | 0:ea44dc9ed014 | 349 | } |
joeverbout | 0:ea44dc9ed014 | 350 | |
joeverbout | 0:ea44dc9ed014 | 351 | inline |
joeverbout | 0:ea44dc9ed014 | 352 | Mat::Mat(Size _sz, int _type) |
joeverbout | 0:ea44dc9ed014 | 353 | : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), |
joeverbout | 0:ea44dc9ed014 | 354 | datalimit(0), allocator(0), u(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 355 | { |
joeverbout | 0:ea44dc9ed014 | 356 | create( _sz.height, _sz.width, _type ); |
joeverbout | 0:ea44dc9ed014 | 357 | } |
joeverbout | 0:ea44dc9ed014 | 358 | |
joeverbout | 0:ea44dc9ed014 | 359 | inline |
joeverbout | 0:ea44dc9ed014 | 360 | Mat::Mat(Size _sz, int _type, const Scalar& _s) |
joeverbout | 0:ea44dc9ed014 | 361 | : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), |
joeverbout | 0:ea44dc9ed014 | 362 | datalimit(0), allocator(0), u(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 363 | { |
joeverbout | 0:ea44dc9ed014 | 364 | create(_sz.height, _sz.width, _type); |
joeverbout | 0:ea44dc9ed014 | 365 | *this = _s; |
joeverbout | 0:ea44dc9ed014 | 366 | } |
joeverbout | 0:ea44dc9ed014 | 367 | |
joeverbout | 0:ea44dc9ed014 | 368 | inline |
joeverbout | 0:ea44dc9ed014 | 369 | Mat::Mat(int _dims, const int* _sz, int _type) |
joeverbout | 0:ea44dc9ed014 | 370 | : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), |
joeverbout | 0:ea44dc9ed014 | 371 | datalimit(0), allocator(0), u(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 372 | { |
joeverbout | 0:ea44dc9ed014 | 373 | create(_dims, _sz, _type); |
joeverbout | 0:ea44dc9ed014 | 374 | } |
joeverbout | 0:ea44dc9ed014 | 375 | |
joeverbout | 0:ea44dc9ed014 | 376 | inline |
joeverbout | 0:ea44dc9ed014 | 377 | Mat::Mat(int _dims, const int* _sz, int _type, const Scalar& _s) |
joeverbout | 0:ea44dc9ed014 | 378 | : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), |
joeverbout | 0:ea44dc9ed014 | 379 | datalimit(0), allocator(0), u(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 380 | { |
joeverbout | 0:ea44dc9ed014 | 381 | create(_dims, _sz, _type); |
joeverbout | 0:ea44dc9ed014 | 382 | *this = _s; |
joeverbout | 0:ea44dc9ed014 | 383 | } |
joeverbout | 0:ea44dc9ed014 | 384 | |
joeverbout | 0:ea44dc9ed014 | 385 | inline |
joeverbout | 0:ea44dc9ed014 | 386 | Mat::Mat(const Mat& m) |
joeverbout | 0:ea44dc9ed014 | 387 | : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data), |
joeverbout | 0:ea44dc9ed014 | 388 | datastart(m.datastart), dataend(m.dataend), datalimit(m.datalimit), allocator(m.allocator), |
joeverbout | 0:ea44dc9ed014 | 389 | u(m.u), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 390 | { |
joeverbout | 0:ea44dc9ed014 | 391 | if( u ) |
joeverbout | 0:ea44dc9ed014 | 392 | CV_XADD(&u->refcount, 1); |
joeverbout | 0:ea44dc9ed014 | 393 | if( m.dims <= 2 ) |
joeverbout | 0:ea44dc9ed014 | 394 | { |
joeverbout | 0:ea44dc9ed014 | 395 | step[0] = m.step[0]; step[1] = m.step[1]; |
joeverbout | 0:ea44dc9ed014 | 396 | } |
joeverbout | 0:ea44dc9ed014 | 397 | else |
joeverbout | 0:ea44dc9ed014 | 398 | { |
joeverbout | 0:ea44dc9ed014 | 399 | dims = 0; |
joeverbout | 0:ea44dc9ed014 | 400 | copySize(m); |
joeverbout | 0:ea44dc9ed014 | 401 | } |
joeverbout | 0:ea44dc9ed014 | 402 | } |
joeverbout | 0:ea44dc9ed014 | 403 | |
joeverbout | 0:ea44dc9ed014 | 404 | inline |
joeverbout | 0:ea44dc9ed014 | 405 | Mat::Mat(int _rows, int _cols, int _type, void* _data, size_t _step) |
joeverbout | 0:ea44dc9ed014 | 406 | : flags(MAGIC_VAL + (_type & TYPE_MASK)), dims(2), rows(_rows), cols(_cols), |
joeverbout | 0:ea44dc9ed014 | 407 | data((uchar*)_data), datastart((uchar*)_data), dataend(0), datalimit(0), |
joeverbout | 0:ea44dc9ed014 | 408 | allocator(0), u(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 409 | { |
joeverbout | 0:ea44dc9ed014 | 410 | CV_Assert(total() == 0 || data != NULL); |
joeverbout | 0:ea44dc9ed014 | 411 | |
joeverbout | 0:ea44dc9ed014 | 412 | size_t esz = CV_ELEM_SIZE(_type), esz1 = CV_ELEM_SIZE1(_type); |
joeverbout | 0:ea44dc9ed014 | 413 | size_t minstep = cols * esz; |
joeverbout | 0:ea44dc9ed014 | 414 | if( _step == AUTO_STEP ) |
joeverbout | 0:ea44dc9ed014 | 415 | { |
joeverbout | 0:ea44dc9ed014 | 416 | _step = minstep; |
joeverbout | 0:ea44dc9ed014 | 417 | flags |= CONTINUOUS_FLAG; |
joeverbout | 0:ea44dc9ed014 | 418 | } |
joeverbout | 0:ea44dc9ed014 | 419 | else |
joeverbout | 0:ea44dc9ed014 | 420 | { |
joeverbout | 0:ea44dc9ed014 | 421 | if( rows == 1 ) _step = minstep; |
joeverbout | 0:ea44dc9ed014 | 422 | CV_DbgAssert( _step >= minstep ); |
joeverbout | 0:ea44dc9ed014 | 423 | |
joeverbout | 0:ea44dc9ed014 | 424 | if (_step % esz1 != 0) |
joeverbout | 0:ea44dc9ed014 | 425 | { |
joeverbout | 0:ea44dc9ed014 | 426 | CV_Error(Error::BadStep, "Step must be a multiple of esz1"); |
joeverbout | 0:ea44dc9ed014 | 427 | } |
joeverbout | 0:ea44dc9ed014 | 428 | |
joeverbout | 0:ea44dc9ed014 | 429 | flags |= _step == minstep ? CONTINUOUS_FLAG : 0; |
joeverbout | 0:ea44dc9ed014 | 430 | } |
joeverbout | 0:ea44dc9ed014 | 431 | step[0] = _step; |
joeverbout | 0:ea44dc9ed014 | 432 | step[1] = esz; |
joeverbout | 0:ea44dc9ed014 | 433 | datalimit = datastart + _step * rows; |
joeverbout | 0:ea44dc9ed014 | 434 | dataend = datalimit - _step + minstep; |
joeverbout | 0:ea44dc9ed014 | 435 | } |
joeverbout | 0:ea44dc9ed014 | 436 | |
joeverbout | 0:ea44dc9ed014 | 437 | inline |
joeverbout | 0:ea44dc9ed014 | 438 | Mat::Mat(Size _sz, int _type, void* _data, size_t _step) |
joeverbout | 0:ea44dc9ed014 | 439 | : flags(MAGIC_VAL + (_type & TYPE_MASK)), dims(2), rows(_sz.height), cols(_sz.width), |
joeverbout | 0:ea44dc9ed014 | 440 | data((uchar*)_data), datastart((uchar*)_data), dataend(0), datalimit(0), |
joeverbout | 0:ea44dc9ed014 | 441 | allocator(0), u(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 442 | { |
joeverbout | 0:ea44dc9ed014 | 443 | CV_Assert(total() == 0 || data != NULL); |
joeverbout | 0:ea44dc9ed014 | 444 | |
joeverbout | 0:ea44dc9ed014 | 445 | size_t esz = CV_ELEM_SIZE(_type), esz1 = CV_ELEM_SIZE1(_type); |
joeverbout | 0:ea44dc9ed014 | 446 | size_t minstep = cols*esz; |
joeverbout | 0:ea44dc9ed014 | 447 | if( _step == AUTO_STEP ) |
joeverbout | 0:ea44dc9ed014 | 448 | { |
joeverbout | 0:ea44dc9ed014 | 449 | _step = minstep; |
joeverbout | 0:ea44dc9ed014 | 450 | flags |= CONTINUOUS_FLAG; |
joeverbout | 0:ea44dc9ed014 | 451 | } |
joeverbout | 0:ea44dc9ed014 | 452 | else |
joeverbout | 0:ea44dc9ed014 | 453 | { |
joeverbout | 0:ea44dc9ed014 | 454 | if( rows == 1 ) _step = minstep; |
joeverbout | 0:ea44dc9ed014 | 455 | CV_DbgAssert( _step >= minstep ); |
joeverbout | 0:ea44dc9ed014 | 456 | |
joeverbout | 0:ea44dc9ed014 | 457 | if (_step % esz1 != 0) |
joeverbout | 0:ea44dc9ed014 | 458 | { |
joeverbout | 0:ea44dc9ed014 | 459 | CV_Error(Error::BadStep, "Step must be a multiple of esz1"); |
joeverbout | 0:ea44dc9ed014 | 460 | } |
joeverbout | 0:ea44dc9ed014 | 461 | |
joeverbout | 0:ea44dc9ed014 | 462 | flags |= _step == minstep ? CONTINUOUS_FLAG : 0; |
joeverbout | 0:ea44dc9ed014 | 463 | } |
joeverbout | 0:ea44dc9ed014 | 464 | step[0] = _step; |
joeverbout | 0:ea44dc9ed014 | 465 | step[1] = esz; |
joeverbout | 0:ea44dc9ed014 | 466 | datalimit = datastart + _step*rows; |
joeverbout | 0:ea44dc9ed014 | 467 | dataend = datalimit - _step + minstep; |
joeverbout | 0:ea44dc9ed014 | 468 | } |
joeverbout | 0:ea44dc9ed014 | 469 | |
joeverbout | 0:ea44dc9ed014 | 470 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 471 | Mat::Mat(const std::vector<_Tp>& vec, bool copyData) |
joeverbout | 0:ea44dc9ed014 | 472 | : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), |
joeverbout | 0:ea44dc9ed014 | 473 | cols(1), data(0), datastart(0), dataend(0), allocator(0), u(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 474 | { |
joeverbout | 0:ea44dc9ed014 | 475 | if(vec.empty()) |
joeverbout | 0:ea44dc9ed014 | 476 | return; |
joeverbout | 0:ea44dc9ed014 | 477 | if( !copyData ) |
joeverbout | 0:ea44dc9ed014 | 478 | { |
joeverbout | 0:ea44dc9ed014 | 479 | step[0] = step[1] = sizeof(_Tp); |
joeverbout | 0:ea44dc9ed014 | 480 | datastart = data = (uchar*)&vec[0]; |
joeverbout | 0:ea44dc9ed014 | 481 | datalimit = dataend = datastart + rows * step[0]; |
joeverbout | 0:ea44dc9ed014 | 482 | } |
joeverbout | 0:ea44dc9ed014 | 483 | else |
joeverbout | 0:ea44dc9ed014 | 484 | Mat((int)vec.size(), 1, DataType<_Tp>::type, (uchar*)&vec[0]).copyTo(*this); |
joeverbout | 0:ea44dc9ed014 | 485 | } |
joeverbout | 0:ea44dc9ed014 | 486 | |
joeverbout | 0:ea44dc9ed014 | 487 | template<typename _Tp, int n> inline |
joeverbout | 0:ea44dc9ed014 | 488 | Mat::Mat(const Vec<_Tp, n>& vec, bool copyData) |
joeverbout | 0:ea44dc9ed014 | 489 | : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows(n), cols(1), data(0), |
joeverbout | 0:ea44dc9ed014 | 490 | datastart(0), dataend(0), allocator(0), u(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 491 | { |
joeverbout | 0:ea44dc9ed014 | 492 | if( !copyData ) |
joeverbout | 0:ea44dc9ed014 | 493 | { |
joeverbout | 0:ea44dc9ed014 | 494 | step[0] = step[1] = sizeof(_Tp); |
joeverbout | 0:ea44dc9ed014 | 495 | datastart = data = (uchar*)vec.val; |
joeverbout | 0:ea44dc9ed014 | 496 | datalimit = dataend = datastart + rows * step[0]; |
joeverbout | 0:ea44dc9ed014 | 497 | } |
joeverbout | 0:ea44dc9ed014 | 498 | else |
joeverbout | 0:ea44dc9ed014 | 499 | Mat(n, 1, DataType<_Tp>::type, (void*)vec.val).copyTo(*this); |
joeverbout | 0:ea44dc9ed014 | 500 | } |
joeverbout | 0:ea44dc9ed014 | 501 | |
joeverbout | 0:ea44dc9ed014 | 502 | |
joeverbout | 0:ea44dc9ed014 | 503 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 504 | Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData) |
joeverbout | 0:ea44dc9ed014 | 505 | : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows(m), cols(n), data(0), |
joeverbout | 0:ea44dc9ed014 | 506 | datastart(0), dataend(0), allocator(0), u(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 507 | { |
joeverbout | 0:ea44dc9ed014 | 508 | if( !copyData ) |
joeverbout | 0:ea44dc9ed014 | 509 | { |
joeverbout | 0:ea44dc9ed014 | 510 | step[0] = cols * sizeof(_Tp); |
joeverbout | 0:ea44dc9ed014 | 511 | step[1] = sizeof(_Tp); |
joeverbout | 0:ea44dc9ed014 | 512 | datastart = data = (uchar*)M.val; |
joeverbout | 0:ea44dc9ed014 | 513 | datalimit = dataend = datastart + rows * step[0]; |
joeverbout | 0:ea44dc9ed014 | 514 | } |
joeverbout | 0:ea44dc9ed014 | 515 | else |
joeverbout | 0:ea44dc9ed014 | 516 | Mat(m, n, DataType<_Tp>::type, (uchar*)M.val).copyTo(*this); |
joeverbout | 0:ea44dc9ed014 | 517 | } |
joeverbout | 0:ea44dc9ed014 | 518 | |
joeverbout | 0:ea44dc9ed014 | 519 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 520 | Mat::Mat(const Point_<_Tp>& pt, bool copyData) |
joeverbout | 0:ea44dc9ed014 | 521 | : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows(2), cols(1), data(0), |
joeverbout | 0:ea44dc9ed014 | 522 | datastart(0), dataend(0), allocator(0), u(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 523 | { |
joeverbout | 0:ea44dc9ed014 | 524 | if( !copyData ) |
joeverbout | 0:ea44dc9ed014 | 525 | { |
joeverbout | 0:ea44dc9ed014 | 526 | step[0] = step[1] = sizeof(_Tp); |
joeverbout | 0:ea44dc9ed014 | 527 | datastart = data = (uchar*)&pt.x; |
joeverbout | 0:ea44dc9ed014 | 528 | datalimit = dataend = datastart + rows * step[0]; |
joeverbout | 0:ea44dc9ed014 | 529 | } |
joeverbout | 0:ea44dc9ed014 | 530 | else |
joeverbout | 0:ea44dc9ed014 | 531 | { |
joeverbout | 0:ea44dc9ed014 | 532 | create(2, 1, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 533 | ((_Tp*)data)[0] = pt.x; |
joeverbout | 0:ea44dc9ed014 | 534 | ((_Tp*)data)[1] = pt.y; |
joeverbout | 0:ea44dc9ed014 | 535 | } |
joeverbout | 0:ea44dc9ed014 | 536 | } |
joeverbout | 0:ea44dc9ed014 | 537 | |
joeverbout | 0:ea44dc9ed014 | 538 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 539 | Mat::Mat(const Point3_<_Tp>& pt, bool copyData) |
joeverbout | 0:ea44dc9ed014 | 540 | : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows(3), cols(1), data(0), |
joeverbout | 0:ea44dc9ed014 | 541 | datastart(0), dataend(0), allocator(0), u(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 542 | { |
joeverbout | 0:ea44dc9ed014 | 543 | if( !copyData ) |
joeverbout | 0:ea44dc9ed014 | 544 | { |
joeverbout | 0:ea44dc9ed014 | 545 | step[0] = step[1] = sizeof(_Tp); |
joeverbout | 0:ea44dc9ed014 | 546 | datastart = data = (uchar*)&pt.x; |
joeverbout | 0:ea44dc9ed014 | 547 | datalimit = dataend = datastart + rows * step[0]; |
joeverbout | 0:ea44dc9ed014 | 548 | } |
joeverbout | 0:ea44dc9ed014 | 549 | else |
joeverbout | 0:ea44dc9ed014 | 550 | { |
joeverbout | 0:ea44dc9ed014 | 551 | create(3, 1, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 552 | ((_Tp*)data)[0] = pt.x; |
joeverbout | 0:ea44dc9ed014 | 553 | ((_Tp*)data)[1] = pt.y; |
joeverbout | 0:ea44dc9ed014 | 554 | ((_Tp*)data)[2] = pt.z; |
joeverbout | 0:ea44dc9ed014 | 555 | } |
joeverbout | 0:ea44dc9ed014 | 556 | } |
joeverbout | 0:ea44dc9ed014 | 557 | |
joeverbout | 0:ea44dc9ed014 | 558 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 559 | Mat::Mat(const MatCommaInitializer_<_Tp>& commaInitializer) |
joeverbout | 0:ea44dc9ed014 | 560 | : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(0), rows(0), cols(0), data(0), |
joeverbout | 0:ea44dc9ed014 | 561 | datastart(0), dataend(0), allocator(0), u(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 562 | { |
joeverbout | 0:ea44dc9ed014 | 563 | *this = commaInitializer.operator Mat_<_Tp>(); |
joeverbout | 0:ea44dc9ed014 | 564 | } |
joeverbout | 0:ea44dc9ed014 | 565 | |
joeverbout | 0:ea44dc9ed014 | 566 | inline |
joeverbout | 0:ea44dc9ed014 | 567 | Mat::~Mat() |
joeverbout | 0:ea44dc9ed014 | 568 | { |
joeverbout | 0:ea44dc9ed014 | 569 | release(); |
joeverbout | 0:ea44dc9ed014 | 570 | if( step.p != step.buf ) |
joeverbout | 0:ea44dc9ed014 | 571 | fastFree(step.p); |
joeverbout | 0:ea44dc9ed014 | 572 | } |
joeverbout | 0:ea44dc9ed014 | 573 | |
joeverbout | 0:ea44dc9ed014 | 574 | inline |
joeverbout | 0:ea44dc9ed014 | 575 | Mat& Mat::operator = (const Mat& m) |
joeverbout | 0:ea44dc9ed014 | 576 | { |
joeverbout | 0:ea44dc9ed014 | 577 | if( this != &m ) |
joeverbout | 0:ea44dc9ed014 | 578 | { |
joeverbout | 0:ea44dc9ed014 | 579 | if( m.u ) |
joeverbout | 0:ea44dc9ed014 | 580 | CV_XADD(&m.u->refcount, 1); |
joeverbout | 0:ea44dc9ed014 | 581 | release(); |
joeverbout | 0:ea44dc9ed014 | 582 | flags = m.flags; |
joeverbout | 0:ea44dc9ed014 | 583 | if( dims <= 2 && m.dims <= 2 ) |
joeverbout | 0:ea44dc9ed014 | 584 | { |
joeverbout | 0:ea44dc9ed014 | 585 | dims = m.dims; |
joeverbout | 0:ea44dc9ed014 | 586 | rows = m.rows; |
joeverbout | 0:ea44dc9ed014 | 587 | cols = m.cols; |
joeverbout | 0:ea44dc9ed014 | 588 | step[0] = m.step[0]; |
joeverbout | 0:ea44dc9ed014 | 589 | step[1] = m.step[1]; |
joeverbout | 0:ea44dc9ed014 | 590 | } |
joeverbout | 0:ea44dc9ed014 | 591 | else |
joeverbout | 0:ea44dc9ed014 | 592 | copySize(m); |
joeverbout | 0:ea44dc9ed014 | 593 | data = m.data; |
joeverbout | 0:ea44dc9ed014 | 594 | datastart = m.datastart; |
joeverbout | 0:ea44dc9ed014 | 595 | dataend = m.dataend; |
joeverbout | 0:ea44dc9ed014 | 596 | datalimit = m.datalimit; |
joeverbout | 0:ea44dc9ed014 | 597 | allocator = m.allocator; |
joeverbout | 0:ea44dc9ed014 | 598 | u = m.u; |
joeverbout | 0:ea44dc9ed014 | 599 | } |
joeverbout | 0:ea44dc9ed014 | 600 | return *this; |
joeverbout | 0:ea44dc9ed014 | 601 | } |
joeverbout | 0:ea44dc9ed014 | 602 | |
joeverbout | 0:ea44dc9ed014 | 603 | inline |
joeverbout | 0:ea44dc9ed014 | 604 | Mat Mat::row(int y) const |
joeverbout | 0:ea44dc9ed014 | 605 | { |
joeverbout | 0:ea44dc9ed014 | 606 | return Mat(*this, Range(y, y + 1), Range::all()); |
joeverbout | 0:ea44dc9ed014 | 607 | } |
joeverbout | 0:ea44dc9ed014 | 608 | |
joeverbout | 0:ea44dc9ed014 | 609 | inline |
joeverbout | 0:ea44dc9ed014 | 610 | Mat Mat::col(int x) const |
joeverbout | 0:ea44dc9ed014 | 611 | { |
joeverbout | 0:ea44dc9ed014 | 612 | return Mat(*this, Range::all(), Range(x, x + 1)); |
joeverbout | 0:ea44dc9ed014 | 613 | } |
joeverbout | 0:ea44dc9ed014 | 614 | |
joeverbout | 0:ea44dc9ed014 | 615 | inline |
joeverbout | 0:ea44dc9ed014 | 616 | Mat Mat::rowRange(int startrow, int endrow) const |
joeverbout | 0:ea44dc9ed014 | 617 | { |
joeverbout | 0:ea44dc9ed014 | 618 | return Mat(*this, Range(startrow, endrow), Range::all()); |
joeverbout | 0:ea44dc9ed014 | 619 | } |
joeverbout | 0:ea44dc9ed014 | 620 | |
joeverbout | 0:ea44dc9ed014 | 621 | inline |
joeverbout | 0:ea44dc9ed014 | 622 | Mat Mat::rowRange(const Range& r) const |
joeverbout | 0:ea44dc9ed014 | 623 | { |
joeverbout | 0:ea44dc9ed014 | 624 | return Mat(*this, r, Range::all()); |
joeverbout | 0:ea44dc9ed014 | 625 | } |
joeverbout | 0:ea44dc9ed014 | 626 | |
joeverbout | 0:ea44dc9ed014 | 627 | inline |
joeverbout | 0:ea44dc9ed014 | 628 | Mat Mat::colRange(int startcol, int endcol) const |
joeverbout | 0:ea44dc9ed014 | 629 | { |
joeverbout | 0:ea44dc9ed014 | 630 | return Mat(*this, Range::all(), Range(startcol, endcol)); |
joeverbout | 0:ea44dc9ed014 | 631 | } |
joeverbout | 0:ea44dc9ed014 | 632 | |
joeverbout | 0:ea44dc9ed014 | 633 | inline |
joeverbout | 0:ea44dc9ed014 | 634 | Mat Mat::colRange(const Range& r) const |
joeverbout | 0:ea44dc9ed014 | 635 | { |
joeverbout | 0:ea44dc9ed014 | 636 | return Mat(*this, Range::all(), r); |
joeverbout | 0:ea44dc9ed014 | 637 | } |
joeverbout | 0:ea44dc9ed014 | 638 | |
joeverbout | 0:ea44dc9ed014 | 639 | inline |
joeverbout | 0:ea44dc9ed014 | 640 | Mat Mat::clone() const |
joeverbout | 0:ea44dc9ed014 | 641 | { |
joeverbout | 0:ea44dc9ed014 | 642 | Mat m; |
joeverbout | 0:ea44dc9ed014 | 643 | copyTo(m); |
joeverbout | 0:ea44dc9ed014 | 644 | return m; |
joeverbout | 0:ea44dc9ed014 | 645 | } |
joeverbout | 0:ea44dc9ed014 | 646 | |
joeverbout | 0:ea44dc9ed014 | 647 | inline |
joeverbout | 0:ea44dc9ed014 | 648 | void Mat::assignTo( Mat& m, int _type ) const |
joeverbout | 0:ea44dc9ed014 | 649 | { |
joeverbout | 0:ea44dc9ed014 | 650 | if( _type < 0 ) |
joeverbout | 0:ea44dc9ed014 | 651 | m = *this; |
joeverbout | 0:ea44dc9ed014 | 652 | else |
joeverbout | 0:ea44dc9ed014 | 653 | convertTo(m, _type); |
joeverbout | 0:ea44dc9ed014 | 654 | } |
joeverbout | 0:ea44dc9ed014 | 655 | |
joeverbout | 0:ea44dc9ed014 | 656 | inline |
joeverbout | 0:ea44dc9ed014 | 657 | void Mat::create(int _rows, int _cols, int _type) |
joeverbout | 0:ea44dc9ed014 | 658 | { |
joeverbout | 0:ea44dc9ed014 | 659 | _type &= TYPE_MASK; |
joeverbout | 0:ea44dc9ed014 | 660 | if( dims <= 2 && rows == _rows && cols == _cols && type() == _type && data ) |
joeverbout | 0:ea44dc9ed014 | 661 | return; |
joeverbout | 0:ea44dc9ed014 | 662 | int sz[] = {_rows, _cols}; |
joeverbout | 0:ea44dc9ed014 | 663 | create(2, sz, _type); |
joeverbout | 0:ea44dc9ed014 | 664 | } |
joeverbout | 0:ea44dc9ed014 | 665 | |
joeverbout | 0:ea44dc9ed014 | 666 | inline |
joeverbout | 0:ea44dc9ed014 | 667 | void Mat::create(Size _sz, int _type) |
joeverbout | 0:ea44dc9ed014 | 668 | { |
joeverbout | 0:ea44dc9ed014 | 669 | create(_sz.height, _sz.width, _type); |
joeverbout | 0:ea44dc9ed014 | 670 | } |
joeverbout | 0:ea44dc9ed014 | 671 | |
joeverbout | 0:ea44dc9ed014 | 672 | inline |
joeverbout | 0:ea44dc9ed014 | 673 | void Mat::addref() |
joeverbout | 0:ea44dc9ed014 | 674 | { |
joeverbout | 0:ea44dc9ed014 | 675 | if( u ) |
joeverbout | 0:ea44dc9ed014 | 676 | CV_XADD(&u->refcount, 1); |
joeverbout | 0:ea44dc9ed014 | 677 | } |
joeverbout | 0:ea44dc9ed014 | 678 | |
joeverbout | 0:ea44dc9ed014 | 679 | inline void Mat::release() |
joeverbout | 0:ea44dc9ed014 | 680 | { |
joeverbout | 0:ea44dc9ed014 | 681 | if( u && CV_XADD(&u->refcount, -1) == 1 ) |
joeverbout | 0:ea44dc9ed014 | 682 | deallocate(); |
joeverbout | 0:ea44dc9ed014 | 683 | u = NULL; |
joeverbout | 0:ea44dc9ed014 | 684 | datastart = dataend = datalimit = data = 0; |
joeverbout | 0:ea44dc9ed014 | 685 | for(int i = 0; i < dims; i++) |
joeverbout | 0:ea44dc9ed014 | 686 | size.p[i] = 0; |
joeverbout | 0:ea44dc9ed014 | 687 | } |
joeverbout | 0:ea44dc9ed014 | 688 | |
joeverbout | 0:ea44dc9ed014 | 689 | inline |
joeverbout | 0:ea44dc9ed014 | 690 | Mat Mat::operator()( Range _rowRange, Range _colRange ) const |
joeverbout | 0:ea44dc9ed014 | 691 | { |
joeverbout | 0:ea44dc9ed014 | 692 | return Mat(*this, _rowRange, _colRange); |
joeverbout | 0:ea44dc9ed014 | 693 | } |
joeverbout | 0:ea44dc9ed014 | 694 | |
joeverbout | 0:ea44dc9ed014 | 695 | inline |
joeverbout | 0:ea44dc9ed014 | 696 | Mat Mat::operator()( const Rect& roi ) const |
joeverbout | 0:ea44dc9ed014 | 697 | { |
joeverbout | 0:ea44dc9ed014 | 698 | return Mat(*this, roi); |
joeverbout | 0:ea44dc9ed014 | 699 | } |
joeverbout | 0:ea44dc9ed014 | 700 | |
joeverbout | 0:ea44dc9ed014 | 701 | inline |
joeverbout | 0:ea44dc9ed014 | 702 | Mat Mat::operator()(const Range* ranges) const |
joeverbout | 0:ea44dc9ed014 | 703 | { |
joeverbout | 0:ea44dc9ed014 | 704 | return Mat(*this, ranges); |
joeverbout | 0:ea44dc9ed014 | 705 | } |
joeverbout | 0:ea44dc9ed014 | 706 | |
joeverbout | 0:ea44dc9ed014 | 707 | inline |
joeverbout | 0:ea44dc9ed014 | 708 | bool Mat::isContinuous() const |
joeverbout | 0:ea44dc9ed014 | 709 | { |
joeverbout | 0:ea44dc9ed014 | 710 | return (flags & CONTINUOUS_FLAG) != 0; |
joeverbout | 0:ea44dc9ed014 | 711 | } |
joeverbout | 0:ea44dc9ed014 | 712 | |
joeverbout | 0:ea44dc9ed014 | 713 | inline |
joeverbout | 0:ea44dc9ed014 | 714 | bool Mat::isSubmatrix() const |
joeverbout | 0:ea44dc9ed014 | 715 | { |
joeverbout | 0:ea44dc9ed014 | 716 | return (flags & SUBMATRIX_FLAG) != 0; |
joeverbout | 0:ea44dc9ed014 | 717 | } |
joeverbout | 0:ea44dc9ed014 | 718 | |
joeverbout | 0:ea44dc9ed014 | 719 | inline |
joeverbout | 0:ea44dc9ed014 | 720 | size_t Mat::elemSize() const |
joeverbout | 0:ea44dc9ed014 | 721 | { |
joeverbout | 0:ea44dc9ed014 | 722 | return dims > 0 ? step.p[dims - 1] : 0; |
joeverbout | 0:ea44dc9ed014 | 723 | } |
joeverbout | 0:ea44dc9ed014 | 724 | |
joeverbout | 0:ea44dc9ed014 | 725 | inline |
joeverbout | 0:ea44dc9ed014 | 726 | size_t Mat::elemSize1() const |
joeverbout | 0:ea44dc9ed014 | 727 | { |
joeverbout | 0:ea44dc9ed014 | 728 | return CV_ELEM_SIZE1(flags); |
joeverbout | 0:ea44dc9ed014 | 729 | } |
joeverbout | 0:ea44dc9ed014 | 730 | |
joeverbout | 0:ea44dc9ed014 | 731 | inline |
joeverbout | 0:ea44dc9ed014 | 732 | int Mat::type() const |
joeverbout | 0:ea44dc9ed014 | 733 | { |
joeverbout | 0:ea44dc9ed014 | 734 | return CV_MAT_TYPE(flags); |
joeverbout | 0:ea44dc9ed014 | 735 | } |
joeverbout | 0:ea44dc9ed014 | 736 | |
joeverbout | 0:ea44dc9ed014 | 737 | inline |
joeverbout | 0:ea44dc9ed014 | 738 | int Mat::depth() const |
joeverbout | 0:ea44dc9ed014 | 739 | { |
joeverbout | 0:ea44dc9ed014 | 740 | return CV_MAT_DEPTH(flags); |
joeverbout | 0:ea44dc9ed014 | 741 | } |
joeverbout | 0:ea44dc9ed014 | 742 | |
joeverbout | 0:ea44dc9ed014 | 743 | inline |
joeverbout | 0:ea44dc9ed014 | 744 | int Mat::channels() const |
joeverbout | 0:ea44dc9ed014 | 745 | { |
joeverbout | 0:ea44dc9ed014 | 746 | return CV_MAT_CN(flags); |
joeverbout | 0:ea44dc9ed014 | 747 | } |
joeverbout | 0:ea44dc9ed014 | 748 | |
joeverbout | 0:ea44dc9ed014 | 749 | inline |
joeverbout | 0:ea44dc9ed014 | 750 | size_t Mat::step1(int i) const |
joeverbout | 0:ea44dc9ed014 | 751 | { |
joeverbout | 0:ea44dc9ed014 | 752 | return step.p[i] / elemSize1(); |
joeverbout | 0:ea44dc9ed014 | 753 | } |
joeverbout | 0:ea44dc9ed014 | 754 | |
joeverbout | 0:ea44dc9ed014 | 755 | inline |
joeverbout | 0:ea44dc9ed014 | 756 | bool Mat::empty() const |
joeverbout | 0:ea44dc9ed014 | 757 | { |
joeverbout | 0:ea44dc9ed014 | 758 | return data == 0 || total() == 0; |
joeverbout | 0:ea44dc9ed014 | 759 | } |
joeverbout | 0:ea44dc9ed014 | 760 | |
joeverbout | 0:ea44dc9ed014 | 761 | inline |
joeverbout | 0:ea44dc9ed014 | 762 | size_t Mat::total() const |
joeverbout | 0:ea44dc9ed014 | 763 | { |
joeverbout | 0:ea44dc9ed014 | 764 | if( dims <= 2 ) |
joeverbout | 0:ea44dc9ed014 | 765 | return (size_t)rows * cols; |
joeverbout | 0:ea44dc9ed014 | 766 | size_t p = 1; |
joeverbout | 0:ea44dc9ed014 | 767 | for( int i = 0; i < dims; i++ ) |
joeverbout | 0:ea44dc9ed014 | 768 | p *= size[i]; |
joeverbout | 0:ea44dc9ed014 | 769 | return p; |
joeverbout | 0:ea44dc9ed014 | 770 | } |
joeverbout | 0:ea44dc9ed014 | 771 | |
joeverbout | 0:ea44dc9ed014 | 772 | inline |
joeverbout | 0:ea44dc9ed014 | 773 | uchar* Mat::ptr(int y) |
joeverbout | 0:ea44dc9ed014 | 774 | { |
joeverbout | 0:ea44dc9ed014 | 775 | CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) ); |
joeverbout | 0:ea44dc9ed014 | 776 | return data + step.p[0] * y; |
joeverbout | 0:ea44dc9ed014 | 777 | } |
joeverbout | 0:ea44dc9ed014 | 778 | |
joeverbout | 0:ea44dc9ed014 | 779 | inline |
joeverbout | 0:ea44dc9ed014 | 780 | const uchar* Mat::ptr(int y) const |
joeverbout | 0:ea44dc9ed014 | 781 | { |
joeverbout | 0:ea44dc9ed014 | 782 | CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) ); |
joeverbout | 0:ea44dc9ed014 | 783 | return data + step.p[0] * y; |
joeverbout | 0:ea44dc9ed014 | 784 | } |
joeverbout | 0:ea44dc9ed014 | 785 | |
joeverbout | 0:ea44dc9ed014 | 786 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 787 | _Tp* Mat::ptr(int y) |
joeverbout | 0:ea44dc9ed014 | 788 | { |
joeverbout | 0:ea44dc9ed014 | 789 | CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) ); |
joeverbout | 0:ea44dc9ed014 | 790 | return (_Tp*)(data + step.p[0] * y); |
joeverbout | 0:ea44dc9ed014 | 791 | } |
joeverbout | 0:ea44dc9ed014 | 792 | |
joeverbout | 0:ea44dc9ed014 | 793 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 794 | const _Tp* Mat::ptr(int y) const |
joeverbout | 0:ea44dc9ed014 | 795 | { |
joeverbout | 0:ea44dc9ed014 | 796 | CV_DbgAssert( y == 0 || (data && dims >= 1 && data && (unsigned)y < (unsigned)size.p[0]) ); |
joeverbout | 0:ea44dc9ed014 | 797 | return (const _Tp*)(data + step.p[0] * y); |
joeverbout | 0:ea44dc9ed014 | 798 | } |
joeverbout | 0:ea44dc9ed014 | 799 | |
joeverbout | 0:ea44dc9ed014 | 800 | inline |
joeverbout | 0:ea44dc9ed014 | 801 | uchar* Mat::ptr(int i0, int i1) |
joeverbout | 0:ea44dc9ed014 | 802 | { |
joeverbout | 0:ea44dc9ed014 | 803 | CV_DbgAssert(dims >= 2); |
joeverbout | 0:ea44dc9ed014 | 804 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 805 | CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); |
joeverbout | 0:ea44dc9ed014 | 806 | CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); |
joeverbout | 0:ea44dc9ed014 | 807 | return data + i0 * step.p[0] + i1 * step.p[1]; |
joeverbout | 0:ea44dc9ed014 | 808 | } |
joeverbout | 0:ea44dc9ed014 | 809 | |
joeverbout | 0:ea44dc9ed014 | 810 | inline |
joeverbout | 0:ea44dc9ed014 | 811 | const uchar* Mat::ptr(int i0, int i1) const |
joeverbout | 0:ea44dc9ed014 | 812 | { |
joeverbout | 0:ea44dc9ed014 | 813 | CV_DbgAssert(dims >= 2); |
joeverbout | 0:ea44dc9ed014 | 814 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 815 | CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); |
joeverbout | 0:ea44dc9ed014 | 816 | CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); |
joeverbout | 0:ea44dc9ed014 | 817 | return data + i0 * step.p[0] + i1 * step.p[1]; |
joeverbout | 0:ea44dc9ed014 | 818 | } |
joeverbout | 0:ea44dc9ed014 | 819 | |
joeverbout | 0:ea44dc9ed014 | 820 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 821 | _Tp* Mat::ptr(int i0, int i1) |
joeverbout | 0:ea44dc9ed014 | 822 | { |
joeverbout | 0:ea44dc9ed014 | 823 | CV_DbgAssert(dims >= 2); |
joeverbout | 0:ea44dc9ed014 | 824 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 825 | CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); |
joeverbout | 0:ea44dc9ed014 | 826 | CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); |
joeverbout | 0:ea44dc9ed014 | 827 | return (_Tp*)(data + i0 * step.p[0] + i1 * step.p[1]); |
joeverbout | 0:ea44dc9ed014 | 828 | } |
joeverbout | 0:ea44dc9ed014 | 829 | |
joeverbout | 0:ea44dc9ed014 | 830 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 831 | const _Tp* Mat::ptr(int i0, int i1) const |
joeverbout | 0:ea44dc9ed014 | 832 | { |
joeverbout | 0:ea44dc9ed014 | 833 | CV_DbgAssert(dims >= 2); |
joeverbout | 0:ea44dc9ed014 | 834 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 835 | CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); |
joeverbout | 0:ea44dc9ed014 | 836 | CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); |
joeverbout | 0:ea44dc9ed014 | 837 | return (const _Tp*)(data + i0 * step.p[0] + i1 * step.p[1]); |
joeverbout | 0:ea44dc9ed014 | 838 | } |
joeverbout | 0:ea44dc9ed014 | 839 | |
joeverbout | 0:ea44dc9ed014 | 840 | inline |
joeverbout | 0:ea44dc9ed014 | 841 | uchar* Mat::ptr(int i0, int i1, int i2) |
joeverbout | 0:ea44dc9ed014 | 842 | { |
joeverbout | 0:ea44dc9ed014 | 843 | CV_DbgAssert(dims >= 3); |
joeverbout | 0:ea44dc9ed014 | 844 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 845 | CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); |
joeverbout | 0:ea44dc9ed014 | 846 | CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); |
joeverbout | 0:ea44dc9ed014 | 847 | CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]); |
joeverbout | 0:ea44dc9ed014 | 848 | return data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2]; |
joeverbout | 0:ea44dc9ed014 | 849 | } |
joeverbout | 0:ea44dc9ed014 | 850 | |
joeverbout | 0:ea44dc9ed014 | 851 | inline |
joeverbout | 0:ea44dc9ed014 | 852 | const uchar* Mat::ptr(int i0, int i1, int i2) const |
joeverbout | 0:ea44dc9ed014 | 853 | { |
joeverbout | 0:ea44dc9ed014 | 854 | CV_DbgAssert(dims >= 3); |
joeverbout | 0:ea44dc9ed014 | 855 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 856 | CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); |
joeverbout | 0:ea44dc9ed014 | 857 | CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); |
joeverbout | 0:ea44dc9ed014 | 858 | CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]); |
joeverbout | 0:ea44dc9ed014 | 859 | return data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2]; |
joeverbout | 0:ea44dc9ed014 | 860 | } |
joeverbout | 0:ea44dc9ed014 | 861 | |
joeverbout | 0:ea44dc9ed014 | 862 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 863 | _Tp* Mat::ptr(int i0, int i1, int i2) |
joeverbout | 0:ea44dc9ed014 | 864 | { |
joeverbout | 0:ea44dc9ed014 | 865 | CV_DbgAssert(dims >= 3); |
joeverbout | 0:ea44dc9ed014 | 866 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 867 | CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); |
joeverbout | 0:ea44dc9ed014 | 868 | CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); |
joeverbout | 0:ea44dc9ed014 | 869 | CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]); |
joeverbout | 0:ea44dc9ed014 | 870 | return (_Tp*)(data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2]); |
joeverbout | 0:ea44dc9ed014 | 871 | } |
joeverbout | 0:ea44dc9ed014 | 872 | |
joeverbout | 0:ea44dc9ed014 | 873 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 874 | const _Tp* Mat::ptr(int i0, int i1, int i2) const |
joeverbout | 0:ea44dc9ed014 | 875 | { |
joeverbout | 0:ea44dc9ed014 | 876 | CV_DbgAssert(dims >= 3); |
joeverbout | 0:ea44dc9ed014 | 877 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 878 | CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); |
joeverbout | 0:ea44dc9ed014 | 879 | CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); |
joeverbout | 0:ea44dc9ed014 | 880 | CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]); |
joeverbout | 0:ea44dc9ed014 | 881 | return (const _Tp*)(data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2]); |
joeverbout | 0:ea44dc9ed014 | 882 | } |
joeverbout | 0:ea44dc9ed014 | 883 | |
joeverbout | 0:ea44dc9ed014 | 884 | inline |
joeverbout | 0:ea44dc9ed014 | 885 | uchar* Mat::ptr(const int* idx) |
joeverbout | 0:ea44dc9ed014 | 886 | { |
joeverbout | 0:ea44dc9ed014 | 887 | int i, d = dims; |
joeverbout | 0:ea44dc9ed014 | 888 | uchar* p = data; |
joeverbout | 0:ea44dc9ed014 | 889 | CV_DbgAssert( d >= 1 && p ); |
joeverbout | 0:ea44dc9ed014 | 890 | for( i = 0; i < d; i++ ) |
joeverbout | 0:ea44dc9ed014 | 891 | { |
joeverbout | 0:ea44dc9ed014 | 892 | CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] ); |
joeverbout | 0:ea44dc9ed014 | 893 | p += idx[i] * step.p[i]; |
joeverbout | 0:ea44dc9ed014 | 894 | } |
joeverbout | 0:ea44dc9ed014 | 895 | return p; |
joeverbout | 0:ea44dc9ed014 | 896 | } |
joeverbout | 0:ea44dc9ed014 | 897 | |
joeverbout | 0:ea44dc9ed014 | 898 | inline |
joeverbout | 0:ea44dc9ed014 | 899 | const uchar* Mat::ptr(const int* idx) const |
joeverbout | 0:ea44dc9ed014 | 900 | { |
joeverbout | 0:ea44dc9ed014 | 901 | int i, d = dims; |
joeverbout | 0:ea44dc9ed014 | 902 | uchar* p = data; |
joeverbout | 0:ea44dc9ed014 | 903 | CV_DbgAssert( d >= 1 && p ); |
joeverbout | 0:ea44dc9ed014 | 904 | for( i = 0; i < d; i++ ) |
joeverbout | 0:ea44dc9ed014 | 905 | { |
joeverbout | 0:ea44dc9ed014 | 906 | CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] ); |
joeverbout | 0:ea44dc9ed014 | 907 | p += idx[i] * step.p[i]; |
joeverbout | 0:ea44dc9ed014 | 908 | } |
joeverbout | 0:ea44dc9ed014 | 909 | return p; |
joeverbout | 0:ea44dc9ed014 | 910 | } |
joeverbout | 0:ea44dc9ed014 | 911 | |
joeverbout | 0:ea44dc9ed014 | 912 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 913 | _Tp& Mat::at(int i0, int i1) |
joeverbout | 0:ea44dc9ed014 | 914 | { |
joeverbout | 0:ea44dc9ed014 | 915 | CV_DbgAssert(dims <= 2); |
joeverbout | 0:ea44dc9ed014 | 916 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 917 | CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); |
joeverbout | 0:ea44dc9ed014 | 918 | CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())); |
joeverbout | 0:ea44dc9ed014 | 919 | CV_DbgAssert(CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1()); |
joeverbout | 0:ea44dc9ed014 | 920 | return ((_Tp*)(data + step.p[0] * i0))[i1]; |
joeverbout | 0:ea44dc9ed014 | 921 | } |
joeverbout | 0:ea44dc9ed014 | 922 | |
joeverbout | 0:ea44dc9ed014 | 923 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 924 | const _Tp& Mat::at(int i0, int i1) const |
joeverbout | 0:ea44dc9ed014 | 925 | { |
joeverbout | 0:ea44dc9ed014 | 926 | CV_DbgAssert(dims <= 2); |
joeverbout | 0:ea44dc9ed014 | 927 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 928 | CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); |
joeverbout | 0:ea44dc9ed014 | 929 | CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())); |
joeverbout | 0:ea44dc9ed014 | 930 | CV_DbgAssert(CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1()); |
joeverbout | 0:ea44dc9ed014 | 931 | return ((const _Tp*)(data + step.p[0] * i0))[i1]; |
joeverbout | 0:ea44dc9ed014 | 932 | } |
joeverbout | 0:ea44dc9ed014 | 933 | |
joeverbout | 0:ea44dc9ed014 | 934 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 935 | _Tp& Mat::at(Point pt) |
joeverbout | 0:ea44dc9ed014 | 936 | { |
joeverbout | 0:ea44dc9ed014 | 937 | CV_DbgAssert(dims <= 2); |
joeverbout | 0:ea44dc9ed014 | 938 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 939 | CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]); |
joeverbout | 0:ea44dc9ed014 | 940 | CV_DbgAssert((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())); |
joeverbout | 0:ea44dc9ed014 | 941 | CV_DbgAssert(CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1()); |
joeverbout | 0:ea44dc9ed014 | 942 | return ((_Tp*)(data + step.p[0] * pt.y))[pt.x]; |
joeverbout | 0:ea44dc9ed014 | 943 | } |
joeverbout | 0:ea44dc9ed014 | 944 | |
joeverbout | 0:ea44dc9ed014 | 945 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 946 | const _Tp& Mat::at(Point pt) const |
joeverbout | 0:ea44dc9ed014 | 947 | { |
joeverbout | 0:ea44dc9ed014 | 948 | CV_DbgAssert(dims <= 2); |
joeverbout | 0:ea44dc9ed014 | 949 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 950 | CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]); |
joeverbout | 0:ea44dc9ed014 | 951 | CV_DbgAssert((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())); |
joeverbout | 0:ea44dc9ed014 | 952 | CV_DbgAssert(CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1()); |
joeverbout | 0:ea44dc9ed014 | 953 | return ((const _Tp*)(data + step.p[0] * pt.y))[pt.x]; |
joeverbout | 0:ea44dc9ed014 | 954 | } |
joeverbout | 0:ea44dc9ed014 | 955 | |
joeverbout | 0:ea44dc9ed014 | 956 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 957 | _Tp& Mat::at(int i0) |
joeverbout | 0:ea44dc9ed014 | 958 | { |
joeverbout | 0:ea44dc9ed014 | 959 | CV_DbgAssert(dims <= 2); |
joeverbout | 0:ea44dc9ed014 | 960 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 961 | CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1])); |
joeverbout | 0:ea44dc9ed014 | 962 | CV_DbgAssert(elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type)); |
joeverbout | 0:ea44dc9ed014 | 963 | if( isContinuous() || size.p[0] == 1 ) |
joeverbout | 0:ea44dc9ed014 | 964 | return ((_Tp*)data)[i0]; |
joeverbout | 0:ea44dc9ed014 | 965 | if( size.p[1] == 1 ) |
joeverbout | 0:ea44dc9ed014 | 966 | return *(_Tp*)(data + step.p[0] * i0); |
joeverbout | 0:ea44dc9ed014 | 967 | int i = i0 / cols, j = i0 - i * cols; |
joeverbout | 0:ea44dc9ed014 | 968 | return ((_Tp*)(data + step.p[0] * i))[j]; |
joeverbout | 0:ea44dc9ed014 | 969 | } |
joeverbout | 0:ea44dc9ed014 | 970 | |
joeverbout | 0:ea44dc9ed014 | 971 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 972 | const _Tp& Mat::at(int i0) const |
joeverbout | 0:ea44dc9ed014 | 973 | { |
joeverbout | 0:ea44dc9ed014 | 974 | CV_DbgAssert(dims <= 2); |
joeverbout | 0:ea44dc9ed014 | 975 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 976 | CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1])); |
joeverbout | 0:ea44dc9ed014 | 977 | CV_DbgAssert(elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type)); |
joeverbout | 0:ea44dc9ed014 | 978 | if( isContinuous() || size.p[0] == 1 ) |
joeverbout | 0:ea44dc9ed014 | 979 | return ((const _Tp*)data)[i0]; |
joeverbout | 0:ea44dc9ed014 | 980 | if( size.p[1] == 1 ) |
joeverbout | 0:ea44dc9ed014 | 981 | return *(const _Tp*)(data + step.p[0] * i0); |
joeverbout | 0:ea44dc9ed014 | 982 | int i = i0 / cols, j = i0 - i * cols; |
joeverbout | 0:ea44dc9ed014 | 983 | return ((const _Tp*)(data + step.p[0] * i))[j]; |
joeverbout | 0:ea44dc9ed014 | 984 | } |
joeverbout | 0:ea44dc9ed014 | 985 | |
joeverbout | 0:ea44dc9ed014 | 986 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 987 | _Tp& Mat::at(int i0, int i1, int i2) |
joeverbout | 0:ea44dc9ed014 | 988 | { |
joeverbout | 0:ea44dc9ed014 | 989 | CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) ); |
joeverbout | 0:ea44dc9ed014 | 990 | return *(_Tp*)ptr(i0, i1, i2); |
joeverbout | 0:ea44dc9ed014 | 991 | } |
joeverbout | 0:ea44dc9ed014 | 992 | |
joeverbout | 0:ea44dc9ed014 | 993 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 994 | const _Tp& Mat::at(int i0, int i1, int i2) const |
joeverbout | 0:ea44dc9ed014 | 995 | { |
joeverbout | 0:ea44dc9ed014 | 996 | CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) ); |
joeverbout | 0:ea44dc9ed014 | 997 | return *(const _Tp*)ptr(i0, i1, i2); |
joeverbout | 0:ea44dc9ed014 | 998 | } |
joeverbout | 0:ea44dc9ed014 | 999 | |
joeverbout | 0:ea44dc9ed014 | 1000 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1001 | _Tp& Mat::at(const int* idx) |
joeverbout | 0:ea44dc9ed014 | 1002 | { |
joeverbout | 0:ea44dc9ed014 | 1003 | CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) ); |
joeverbout | 0:ea44dc9ed014 | 1004 | return *(_Tp*)ptr(idx); |
joeverbout | 0:ea44dc9ed014 | 1005 | } |
joeverbout | 0:ea44dc9ed014 | 1006 | |
joeverbout | 0:ea44dc9ed014 | 1007 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1008 | const _Tp& Mat::at(const int* idx) const |
joeverbout | 0:ea44dc9ed014 | 1009 | { |
joeverbout | 0:ea44dc9ed014 | 1010 | CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) ); |
joeverbout | 0:ea44dc9ed014 | 1011 | return *(const _Tp*)ptr(idx); |
joeverbout | 0:ea44dc9ed014 | 1012 | } |
joeverbout | 0:ea44dc9ed014 | 1013 | |
joeverbout | 0:ea44dc9ed014 | 1014 | template<typename _Tp, int n> inline |
joeverbout | 0:ea44dc9ed014 | 1015 | _Tp& Mat::at(const Vec<int, n>& idx) |
joeverbout | 0:ea44dc9ed014 | 1016 | { |
joeverbout | 0:ea44dc9ed014 | 1017 | CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) ); |
joeverbout | 0:ea44dc9ed014 | 1018 | return *(_Tp*)ptr(idx.val); |
joeverbout | 0:ea44dc9ed014 | 1019 | } |
joeverbout | 0:ea44dc9ed014 | 1020 | |
joeverbout | 0:ea44dc9ed014 | 1021 | template<typename _Tp, int n> inline |
joeverbout | 0:ea44dc9ed014 | 1022 | const _Tp& Mat::at(const Vec<int, n>& idx) const |
joeverbout | 0:ea44dc9ed014 | 1023 | { |
joeverbout | 0:ea44dc9ed014 | 1024 | CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) ); |
joeverbout | 0:ea44dc9ed014 | 1025 | return *(const _Tp*)ptr(idx.val); |
joeverbout | 0:ea44dc9ed014 | 1026 | } |
joeverbout | 0:ea44dc9ed014 | 1027 | |
joeverbout | 0:ea44dc9ed014 | 1028 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1029 | MatConstIterator_<_Tp> Mat::begin() const |
joeverbout | 0:ea44dc9ed014 | 1030 | { |
joeverbout | 0:ea44dc9ed014 | 1031 | CV_DbgAssert( elemSize() == sizeof(_Tp) ); |
joeverbout | 0:ea44dc9ed014 | 1032 | return MatConstIterator_<_Tp>((const Mat_<_Tp>*)this); |
joeverbout | 0:ea44dc9ed014 | 1033 | } |
joeverbout | 0:ea44dc9ed014 | 1034 | |
joeverbout | 0:ea44dc9ed014 | 1035 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1036 | MatConstIterator_<_Tp> Mat::end() const |
joeverbout | 0:ea44dc9ed014 | 1037 | { |
joeverbout | 0:ea44dc9ed014 | 1038 | CV_DbgAssert( elemSize() == sizeof(_Tp) ); |
joeverbout | 0:ea44dc9ed014 | 1039 | MatConstIterator_<_Tp> it((const Mat_<_Tp>*)this); |
joeverbout | 0:ea44dc9ed014 | 1040 | it += total(); |
joeverbout | 0:ea44dc9ed014 | 1041 | return it; |
joeverbout | 0:ea44dc9ed014 | 1042 | } |
joeverbout | 0:ea44dc9ed014 | 1043 | |
joeverbout | 0:ea44dc9ed014 | 1044 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1045 | MatIterator_<_Tp> Mat::begin() |
joeverbout | 0:ea44dc9ed014 | 1046 | { |
joeverbout | 0:ea44dc9ed014 | 1047 | CV_DbgAssert( elemSize() == sizeof(_Tp) ); |
joeverbout | 0:ea44dc9ed014 | 1048 | return MatIterator_<_Tp>((Mat_<_Tp>*)this); |
joeverbout | 0:ea44dc9ed014 | 1049 | } |
joeverbout | 0:ea44dc9ed014 | 1050 | |
joeverbout | 0:ea44dc9ed014 | 1051 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1052 | MatIterator_<_Tp> Mat::end() |
joeverbout | 0:ea44dc9ed014 | 1053 | { |
joeverbout | 0:ea44dc9ed014 | 1054 | CV_DbgAssert( elemSize() == sizeof(_Tp) ); |
joeverbout | 0:ea44dc9ed014 | 1055 | MatIterator_<_Tp> it((Mat_<_Tp>*)this); |
joeverbout | 0:ea44dc9ed014 | 1056 | it += total(); |
joeverbout | 0:ea44dc9ed014 | 1057 | return it; |
joeverbout | 0:ea44dc9ed014 | 1058 | } |
joeverbout | 0:ea44dc9ed014 | 1059 | |
joeverbout | 0:ea44dc9ed014 | 1060 | template<typename _Tp, typename Functor> inline |
joeverbout | 0:ea44dc9ed014 | 1061 | void Mat::forEach(const Functor& operation) { |
joeverbout | 0:ea44dc9ed014 | 1062 | this->forEach_impl<_Tp>(operation); |
joeverbout | 0:ea44dc9ed014 | 1063 | } |
joeverbout | 0:ea44dc9ed014 | 1064 | |
joeverbout | 0:ea44dc9ed014 | 1065 | template<typename _Tp, typename Functor> inline |
joeverbout | 0:ea44dc9ed014 | 1066 | void Mat::forEach(const Functor& operation) const { |
joeverbout | 0:ea44dc9ed014 | 1067 | // call as not const |
joeverbout | 0:ea44dc9ed014 | 1068 | (const_cast<Mat*>(this))->forEach<const _Tp>(operation); |
joeverbout | 0:ea44dc9ed014 | 1069 | } |
joeverbout | 0:ea44dc9ed014 | 1070 | |
joeverbout | 0:ea44dc9ed014 | 1071 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1072 | Mat::operator std::vector<_Tp>() const |
joeverbout | 0:ea44dc9ed014 | 1073 | { |
joeverbout | 0:ea44dc9ed014 | 1074 | std::vector<_Tp> v; |
joeverbout | 0:ea44dc9ed014 | 1075 | copyTo(v); |
joeverbout | 0:ea44dc9ed014 | 1076 | return v; |
joeverbout | 0:ea44dc9ed014 | 1077 | } |
joeverbout | 0:ea44dc9ed014 | 1078 | |
joeverbout | 0:ea44dc9ed014 | 1079 | template<typename _Tp, int n> inline |
joeverbout | 0:ea44dc9ed014 | 1080 | Mat::operator Vec<_Tp, n>() const |
joeverbout | 0:ea44dc9ed014 | 1081 | { |
joeverbout | 0:ea44dc9ed014 | 1082 | CV_Assert( data && dims <= 2 && (rows == 1 || cols == 1) && |
joeverbout | 0:ea44dc9ed014 | 1083 | rows + cols - 1 == n && channels() == 1 ); |
joeverbout | 0:ea44dc9ed014 | 1084 | |
joeverbout | 0:ea44dc9ed014 | 1085 | if( isContinuous() && type() == DataType<_Tp>::type ) |
joeverbout | 0:ea44dc9ed014 | 1086 | return Vec<_Tp, n>((_Tp*)data); |
joeverbout | 0:ea44dc9ed014 | 1087 | Vec<_Tp, n> v; |
joeverbout | 0:ea44dc9ed014 | 1088 | Mat tmp(rows, cols, DataType<_Tp>::type, v.val); |
joeverbout | 0:ea44dc9ed014 | 1089 | convertTo(tmp, tmp.type()); |
joeverbout | 0:ea44dc9ed014 | 1090 | return v; |
joeverbout | 0:ea44dc9ed014 | 1091 | } |
joeverbout | 0:ea44dc9ed014 | 1092 | |
joeverbout | 0:ea44dc9ed014 | 1093 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 1094 | Mat::operator Matx<_Tp, m, n>() const |
joeverbout | 0:ea44dc9ed014 | 1095 | { |
joeverbout | 0:ea44dc9ed014 | 1096 | CV_Assert( data && dims <= 2 && rows == m && cols == n && channels() == 1 ); |
joeverbout | 0:ea44dc9ed014 | 1097 | |
joeverbout | 0:ea44dc9ed014 | 1098 | if( isContinuous() && type() == DataType<_Tp>::type ) |
joeverbout | 0:ea44dc9ed014 | 1099 | return Matx<_Tp, m, n>((_Tp*)data); |
joeverbout | 0:ea44dc9ed014 | 1100 | Matx<_Tp, m, n> mtx; |
joeverbout | 0:ea44dc9ed014 | 1101 | Mat tmp(rows, cols, DataType<_Tp>::type, mtx.val); |
joeverbout | 0:ea44dc9ed014 | 1102 | convertTo(tmp, tmp.type()); |
joeverbout | 0:ea44dc9ed014 | 1103 | return mtx; |
joeverbout | 0:ea44dc9ed014 | 1104 | } |
joeverbout | 0:ea44dc9ed014 | 1105 | |
joeverbout | 0:ea44dc9ed014 | 1106 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1107 | void Mat::push_back(const _Tp& elem) |
joeverbout | 0:ea44dc9ed014 | 1108 | { |
joeverbout | 0:ea44dc9ed014 | 1109 | if( !data ) |
joeverbout | 0:ea44dc9ed014 | 1110 | { |
joeverbout | 0:ea44dc9ed014 | 1111 | *this = Mat(1, 1, DataType<_Tp>::type, (void*)&elem).clone(); |
joeverbout | 0:ea44dc9ed014 | 1112 | return; |
joeverbout | 0:ea44dc9ed014 | 1113 | } |
joeverbout | 0:ea44dc9ed014 | 1114 | CV_Assert(DataType<_Tp>::type == type() && cols == 1 |
joeverbout | 0:ea44dc9ed014 | 1115 | /* && dims == 2 (cols == 1 implies dims == 2) */); |
joeverbout | 0:ea44dc9ed014 | 1116 | const uchar* tmp = dataend + step[0]; |
joeverbout | 0:ea44dc9ed014 | 1117 | if( !isSubmatrix() && isContinuous() && tmp <= datalimit ) |
joeverbout | 0:ea44dc9ed014 | 1118 | { |
joeverbout | 0:ea44dc9ed014 | 1119 | *(_Tp*)(data + (size.p[0]++) * step.p[0]) = elem; |
joeverbout | 0:ea44dc9ed014 | 1120 | dataend = tmp; |
joeverbout | 0:ea44dc9ed014 | 1121 | } |
joeverbout | 0:ea44dc9ed014 | 1122 | else |
joeverbout | 0:ea44dc9ed014 | 1123 | push_back_(&elem); |
joeverbout | 0:ea44dc9ed014 | 1124 | } |
joeverbout | 0:ea44dc9ed014 | 1125 | |
joeverbout | 0:ea44dc9ed014 | 1126 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1127 | void Mat::push_back(const Mat_<_Tp>& m) |
joeverbout | 0:ea44dc9ed014 | 1128 | { |
joeverbout | 0:ea44dc9ed014 | 1129 | push_back((const Mat&)m); |
joeverbout | 0:ea44dc9ed014 | 1130 | } |
joeverbout | 0:ea44dc9ed014 | 1131 | |
joeverbout | 0:ea44dc9ed014 | 1132 | template<> inline |
joeverbout | 0:ea44dc9ed014 | 1133 | void Mat::push_back(const MatExpr& expr) |
joeverbout | 0:ea44dc9ed014 | 1134 | { |
joeverbout | 0:ea44dc9ed014 | 1135 | push_back(static_cast<Mat>(expr)); |
joeverbout | 0:ea44dc9ed014 | 1136 | } |
joeverbout | 0:ea44dc9ed014 | 1137 | |
joeverbout | 0:ea44dc9ed014 | 1138 | #ifdef CV_CXX_MOVE_SEMANTICS |
joeverbout | 0:ea44dc9ed014 | 1139 | |
joeverbout | 0:ea44dc9ed014 | 1140 | inline |
joeverbout | 0:ea44dc9ed014 | 1141 | Mat::Mat(Mat&& m) |
joeverbout | 0:ea44dc9ed014 | 1142 | : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data), |
joeverbout | 0:ea44dc9ed014 | 1143 | datastart(m.datastart), dataend(m.dataend), datalimit(m.datalimit), allocator(m.allocator), |
joeverbout | 0:ea44dc9ed014 | 1144 | u(m.u), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 1145 | { |
joeverbout | 0:ea44dc9ed014 | 1146 | if (m.dims <= 2) // move new step/size info |
joeverbout | 0:ea44dc9ed014 | 1147 | { |
joeverbout | 0:ea44dc9ed014 | 1148 | step[0] = m.step[0]; |
joeverbout | 0:ea44dc9ed014 | 1149 | step[1] = m.step[1]; |
joeverbout | 0:ea44dc9ed014 | 1150 | } |
joeverbout | 0:ea44dc9ed014 | 1151 | else |
joeverbout | 0:ea44dc9ed014 | 1152 | { |
joeverbout | 0:ea44dc9ed014 | 1153 | CV_DbgAssert(m.step.p != m.step.buf); |
joeverbout | 0:ea44dc9ed014 | 1154 | step.p = m.step.p; |
joeverbout | 0:ea44dc9ed014 | 1155 | size.p = m.size.p; |
joeverbout | 0:ea44dc9ed014 | 1156 | m.step.p = m.step.buf; |
joeverbout | 0:ea44dc9ed014 | 1157 | m.size.p = &m.rows; |
joeverbout | 0:ea44dc9ed014 | 1158 | } |
joeverbout | 0:ea44dc9ed014 | 1159 | m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; |
joeverbout | 0:ea44dc9ed014 | 1160 | m.data = NULL; m.datastart = NULL; m.dataend = NULL; m.datalimit = NULL; |
joeverbout | 0:ea44dc9ed014 | 1161 | m.allocator = NULL; |
joeverbout | 0:ea44dc9ed014 | 1162 | m.u = NULL; |
joeverbout | 0:ea44dc9ed014 | 1163 | } |
joeverbout | 0:ea44dc9ed014 | 1164 | |
joeverbout | 0:ea44dc9ed014 | 1165 | inline |
joeverbout | 0:ea44dc9ed014 | 1166 | Mat& Mat::operator = (Mat&& m) |
joeverbout | 0:ea44dc9ed014 | 1167 | { |
joeverbout | 0:ea44dc9ed014 | 1168 | release(); |
joeverbout | 0:ea44dc9ed014 | 1169 | flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols; data = m.data; |
joeverbout | 0:ea44dc9ed014 | 1170 | datastart = m.datastart; dataend = m.dataend; datalimit = m.datalimit; allocator = m.allocator; |
joeverbout | 0:ea44dc9ed014 | 1171 | u = m.u; |
joeverbout | 0:ea44dc9ed014 | 1172 | if (step.p != step.buf) // release self step/size |
joeverbout | 0:ea44dc9ed014 | 1173 | { |
joeverbout | 0:ea44dc9ed014 | 1174 | fastFree(step.p); |
joeverbout | 0:ea44dc9ed014 | 1175 | step.p = step.buf; |
joeverbout | 0:ea44dc9ed014 | 1176 | size.p = &rows; |
joeverbout | 0:ea44dc9ed014 | 1177 | } |
joeverbout | 0:ea44dc9ed014 | 1178 | if (m.dims <= 2) // move new step/size info |
joeverbout | 0:ea44dc9ed014 | 1179 | { |
joeverbout | 0:ea44dc9ed014 | 1180 | step[0] = m.step[0]; |
joeverbout | 0:ea44dc9ed014 | 1181 | step[1] = m.step[1]; |
joeverbout | 0:ea44dc9ed014 | 1182 | } |
joeverbout | 0:ea44dc9ed014 | 1183 | else |
joeverbout | 0:ea44dc9ed014 | 1184 | { |
joeverbout | 0:ea44dc9ed014 | 1185 | CV_DbgAssert(m.step.p != m.step.buf); |
joeverbout | 0:ea44dc9ed014 | 1186 | step.p = m.step.p; |
joeverbout | 0:ea44dc9ed014 | 1187 | size.p = m.size.p; |
joeverbout | 0:ea44dc9ed014 | 1188 | m.step.p = m.step.buf; |
joeverbout | 0:ea44dc9ed014 | 1189 | m.size.p = &m.rows; |
joeverbout | 0:ea44dc9ed014 | 1190 | } |
joeverbout | 0:ea44dc9ed014 | 1191 | m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; |
joeverbout | 0:ea44dc9ed014 | 1192 | m.data = NULL; m.datastart = NULL; m.dataend = NULL; m.datalimit = NULL; |
joeverbout | 0:ea44dc9ed014 | 1193 | m.allocator = NULL; |
joeverbout | 0:ea44dc9ed014 | 1194 | m.u = NULL; |
joeverbout | 0:ea44dc9ed014 | 1195 | return *this; |
joeverbout | 0:ea44dc9ed014 | 1196 | } |
joeverbout | 0:ea44dc9ed014 | 1197 | |
joeverbout | 0:ea44dc9ed014 | 1198 | #endif |
joeverbout | 0:ea44dc9ed014 | 1199 | |
joeverbout | 0:ea44dc9ed014 | 1200 | |
joeverbout | 0:ea44dc9ed014 | 1201 | ///////////////////////////// MatSize //////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 1202 | |
joeverbout | 0:ea44dc9ed014 | 1203 | inline |
joeverbout | 0:ea44dc9ed014 | 1204 | MatSize::MatSize(int* _p) |
joeverbout | 0:ea44dc9ed014 | 1205 | : p(_p) {} |
joeverbout | 0:ea44dc9ed014 | 1206 | |
joeverbout | 0:ea44dc9ed014 | 1207 | inline |
joeverbout | 0:ea44dc9ed014 | 1208 | Size MatSize::operator()() const |
joeverbout | 0:ea44dc9ed014 | 1209 | { |
joeverbout | 0:ea44dc9ed014 | 1210 | CV_DbgAssert(p[-1] <= 2); |
joeverbout | 0:ea44dc9ed014 | 1211 | return Size(p[1], p[0]); |
joeverbout | 0:ea44dc9ed014 | 1212 | } |
joeverbout | 0:ea44dc9ed014 | 1213 | |
joeverbout | 0:ea44dc9ed014 | 1214 | inline |
joeverbout | 0:ea44dc9ed014 | 1215 | const int& MatSize::operator[](int i) const |
joeverbout | 0:ea44dc9ed014 | 1216 | { |
joeverbout | 0:ea44dc9ed014 | 1217 | return p[i]; |
joeverbout | 0:ea44dc9ed014 | 1218 | } |
joeverbout | 0:ea44dc9ed014 | 1219 | |
joeverbout | 0:ea44dc9ed014 | 1220 | inline |
joeverbout | 0:ea44dc9ed014 | 1221 | int& MatSize::operator[](int i) |
joeverbout | 0:ea44dc9ed014 | 1222 | { |
joeverbout | 0:ea44dc9ed014 | 1223 | return p[i]; |
joeverbout | 0:ea44dc9ed014 | 1224 | } |
joeverbout | 0:ea44dc9ed014 | 1225 | |
joeverbout | 0:ea44dc9ed014 | 1226 | inline |
joeverbout | 0:ea44dc9ed014 | 1227 | MatSize::operator const int*() const |
joeverbout | 0:ea44dc9ed014 | 1228 | { |
joeverbout | 0:ea44dc9ed014 | 1229 | return p; |
joeverbout | 0:ea44dc9ed014 | 1230 | } |
joeverbout | 0:ea44dc9ed014 | 1231 | |
joeverbout | 0:ea44dc9ed014 | 1232 | inline |
joeverbout | 0:ea44dc9ed014 | 1233 | bool MatSize::operator == (const MatSize& sz) const |
joeverbout | 0:ea44dc9ed014 | 1234 | { |
joeverbout | 0:ea44dc9ed014 | 1235 | int d = p[-1]; |
joeverbout | 0:ea44dc9ed014 | 1236 | int dsz = sz.p[-1]; |
joeverbout | 0:ea44dc9ed014 | 1237 | if( d != dsz ) |
joeverbout | 0:ea44dc9ed014 | 1238 | return false; |
joeverbout | 0:ea44dc9ed014 | 1239 | if( d == 2 ) |
joeverbout | 0:ea44dc9ed014 | 1240 | return p[0] == sz.p[0] && p[1] == sz.p[1]; |
joeverbout | 0:ea44dc9ed014 | 1241 | |
joeverbout | 0:ea44dc9ed014 | 1242 | for( int i = 0; i < d; i++ ) |
joeverbout | 0:ea44dc9ed014 | 1243 | if( p[i] != sz.p[i] ) |
joeverbout | 0:ea44dc9ed014 | 1244 | return false; |
joeverbout | 0:ea44dc9ed014 | 1245 | return true; |
joeverbout | 0:ea44dc9ed014 | 1246 | } |
joeverbout | 0:ea44dc9ed014 | 1247 | |
joeverbout | 0:ea44dc9ed014 | 1248 | inline |
joeverbout | 0:ea44dc9ed014 | 1249 | bool MatSize::operator != (const MatSize& sz) const |
joeverbout | 0:ea44dc9ed014 | 1250 | { |
joeverbout | 0:ea44dc9ed014 | 1251 | return !(*this == sz); |
joeverbout | 0:ea44dc9ed014 | 1252 | } |
joeverbout | 0:ea44dc9ed014 | 1253 | |
joeverbout | 0:ea44dc9ed014 | 1254 | |
joeverbout | 0:ea44dc9ed014 | 1255 | |
joeverbout | 0:ea44dc9ed014 | 1256 | ///////////////////////////// MatStep //////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 1257 | |
joeverbout | 0:ea44dc9ed014 | 1258 | inline |
joeverbout | 0:ea44dc9ed014 | 1259 | MatStep::MatStep() |
joeverbout | 0:ea44dc9ed014 | 1260 | { |
joeverbout | 0:ea44dc9ed014 | 1261 | p = buf; p[0] = p[1] = 0; |
joeverbout | 0:ea44dc9ed014 | 1262 | } |
joeverbout | 0:ea44dc9ed014 | 1263 | |
joeverbout | 0:ea44dc9ed014 | 1264 | inline |
joeverbout | 0:ea44dc9ed014 | 1265 | MatStep::MatStep(size_t s) |
joeverbout | 0:ea44dc9ed014 | 1266 | { |
joeverbout | 0:ea44dc9ed014 | 1267 | p = buf; p[0] = s; p[1] = 0; |
joeverbout | 0:ea44dc9ed014 | 1268 | } |
joeverbout | 0:ea44dc9ed014 | 1269 | |
joeverbout | 0:ea44dc9ed014 | 1270 | inline |
joeverbout | 0:ea44dc9ed014 | 1271 | const size_t& MatStep::operator[](int i) const |
joeverbout | 0:ea44dc9ed014 | 1272 | { |
joeverbout | 0:ea44dc9ed014 | 1273 | return p[i]; |
joeverbout | 0:ea44dc9ed014 | 1274 | } |
joeverbout | 0:ea44dc9ed014 | 1275 | |
joeverbout | 0:ea44dc9ed014 | 1276 | inline |
joeverbout | 0:ea44dc9ed014 | 1277 | size_t& MatStep::operator[](int i) |
joeverbout | 0:ea44dc9ed014 | 1278 | { |
joeverbout | 0:ea44dc9ed014 | 1279 | return p[i]; |
joeverbout | 0:ea44dc9ed014 | 1280 | } |
joeverbout | 0:ea44dc9ed014 | 1281 | |
joeverbout | 0:ea44dc9ed014 | 1282 | inline MatStep::operator size_t() const |
joeverbout | 0:ea44dc9ed014 | 1283 | { |
joeverbout | 0:ea44dc9ed014 | 1284 | CV_DbgAssert( p == buf ); |
joeverbout | 0:ea44dc9ed014 | 1285 | return buf[0]; |
joeverbout | 0:ea44dc9ed014 | 1286 | } |
joeverbout | 0:ea44dc9ed014 | 1287 | |
joeverbout | 0:ea44dc9ed014 | 1288 | inline MatStep& MatStep::operator = (size_t s) |
joeverbout | 0:ea44dc9ed014 | 1289 | { |
joeverbout | 0:ea44dc9ed014 | 1290 | CV_DbgAssert( p == buf ); |
joeverbout | 0:ea44dc9ed014 | 1291 | buf[0] = s; |
joeverbout | 0:ea44dc9ed014 | 1292 | return *this; |
joeverbout | 0:ea44dc9ed014 | 1293 | } |
joeverbout | 0:ea44dc9ed014 | 1294 | |
joeverbout | 0:ea44dc9ed014 | 1295 | |
joeverbout | 0:ea44dc9ed014 | 1296 | |
joeverbout | 0:ea44dc9ed014 | 1297 | ////////////////////////////// Mat_<_Tp> //////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 1298 | |
joeverbout | 0:ea44dc9ed014 | 1299 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1300 | Mat_<_Tp>::Mat_() |
joeverbout | 0:ea44dc9ed014 | 1301 | : Mat() |
joeverbout | 0:ea44dc9ed014 | 1302 | { |
joeverbout | 0:ea44dc9ed014 | 1303 | flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type; |
joeverbout | 0:ea44dc9ed014 | 1304 | } |
joeverbout | 0:ea44dc9ed014 | 1305 | |
joeverbout | 0:ea44dc9ed014 | 1306 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1307 | Mat_<_Tp>::Mat_(int _rows, int _cols) |
joeverbout | 0:ea44dc9ed014 | 1308 | : Mat(_rows, _cols, DataType<_Tp>::type) |
joeverbout | 0:ea44dc9ed014 | 1309 | { |
joeverbout | 0:ea44dc9ed014 | 1310 | } |
joeverbout | 0:ea44dc9ed014 | 1311 | |
joeverbout | 0:ea44dc9ed014 | 1312 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1313 | Mat_<_Tp>::Mat_(int _rows, int _cols, const _Tp& value) |
joeverbout | 0:ea44dc9ed014 | 1314 | : Mat(_rows, _cols, DataType<_Tp>::type) |
joeverbout | 0:ea44dc9ed014 | 1315 | { |
joeverbout | 0:ea44dc9ed014 | 1316 | *this = value; |
joeverbout | 0:ea44dc9ed014 | 1317 | } |
joeverbout | 0:ea44dc9ed014 | 1318 | |
joeverbout | 0:ea44dc9ed014 | 1319 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1320 | Mat_<_Tp>::Mat_(Size _sz) |
joeverbout | 0:ea44dc9ed014 | 1321 | : Mat(_sz.height, _sz.width, DataType<_Tp>::type) |
joeverbout | 0:ea44dc9ed014 | 1322 | {} |
joeverbout | 0:ea44dc9ed014 | 1323 | |
joeverbout | 0:ea44dc9ed014 | 1324 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1325 | Mat_<_Tp>::Mat_(Size _sz, const _Tp& value) |
joeverbout | 0:ea44dc9ed014 | 1326 | : Mat(_sz.height, _sz.width, DataType<_Tp>::type) |
joeverbout | 0:ea44dc9ed014 | 1327 | { |
joeverbout | 0:ea44dc9ed014 | 1328 | *this = value; |
joeverbout | 0:ea44dc9ed014 | 1329 | } |
joeverbout | 0:ea44dc9ed014 | 1330 | |
joeverbout | 0:ea44dc9ed014 | 1331 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1332 | Mat_<_Tp>::Mat_(int _dims, const int* _sz) |
joeverbout | 0:ea44dc9ed014 | 1333 | : Mat(_dims, _sz, DataType<_Tp>::type) |
joeverbout | 0:ea44dc9ed014 | 1334 | {} |
joeverbout | 0:ea44dc9ed014 | 1335 | |
joeverbout | 0:ea44dc9ed014 | 1336 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1337 | Mat_<_Tp>::Mat_(int _dims, const int* _sz, const _Tp& _s) |
joeverbout | 0:ea44dc9ed014 | 1338 | : Mat(_dims, _sz, DataType<_Tp>::type, Scalar(_s)) |
joeverbout | 0:ea44dc9ed014 | 1339 | {} |
joeverbout | 0:ea44dc9ed014 | 1340 | |
joeverbout | 0:ea44dc9ed014 | 1341 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1342 | Mat_<_Tp>::Mat_(const Mat_<_Tp>& m, const Range* ranges) |
joeverbout | 0:ea44dc9ed014 | 1343 | : Mat(m, ranges) |
joeverbout | 0:ea44dc9ed014 | 1344 | {} |
joeverbout | 0:ea44dc9ed014 | 1345 | |
joeverbout | 0:ea44dc9ed014 | 1346 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1347 | Mat_<_Tp>::Mat_(const Mat& m) |
joeverbout | 0:ea44dc9ed014 | 1348 | : Mat() |
joeverbout | 0:ea44dc9ed014 | 1349 | { |
joeverbout | 0:ea44dc9ed014 | 1350 | flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type; |
joeverbout | 0:ea44dc9ed014 | 1351 | *this = m; |
joeverbout | 0:ea44dc9ed014 | 1352 | } |
joeverbout | 0:ea44dc9ed014 | 1353 | |
joeverbout | 0:ea44dc9ed014 | 1354 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1355 | Mat_<_Tp>::Mat_(const Mat_& m) |
joeverbout | 0:ea44dc9ed014 | 1356 | : Mat(m) |
joeverbout | 0:ea44dc9ed014 | 1357 | {} |
joeverbout | 0:ea44dc9ed014 | 1358 | |
joeverbout | 0:ea44dc9ed014 | 1359 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1360 | Mat_<_Tp>::Mat_(int _rows, int _cols, _Tp* _data, size_t steps) |
joeverbout | 0:ea44dc9ed014 | 1361 | : Mat(_rows, _cols, DataType<_Tp>::type, _data, steps) |
joeverbout | 0:ea44dc9ed014 | 1362 | {} |
joeverbout | 0:ea44dc9ed014 | 1363 | |
joeverbout | 0:ea44dc9ed014 | 1364 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1365 | Mat_<_Tp>::Mat_(const Mat_& m, const Range& _rowRange, const Range& _colRange) |
joeverbout | 0:ea44dc9ed014 | 1366 | : Mat(m, _rowRange, _colRange) |
joeverbout | 0:ea44dc9ed014 | 1367 | {} |
joeverbout | 0:ea44dc9ed014 | 1368 | |
joeverbout | 0:ea44dc9ed014 | 1369 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1370 | Mat_<_Tp>::Mat_(const Mat_& m, const Rect& roi) |
joeverbout | 0:ea44dc9ed014 | 1371 | : Mat(m, roi) |
joeverbout | 0:ea44dc9ed014 | 1372 | {} |
joeverbout | 0:ea44dc9ed014 | 1373 | |
joeverbout | 0:ea44dc9ed014 | 1374 | template<typename _Tp> template<int n> inline |
joeverbout | 0:ea44dc9ed014 | 1375 | Mat_<_Tp>::Mat_(const Vec<typename DataType<_Tp>::channel_type, n>& vec, bool copyData) |
joeverbout | 0:ea44dc9ed014 | 1376 | : Mat(n / DataType<_Tp>::channels, 1, DataType<_Tp>::type, (void*)&vec) |
joeverbout | 0:ea44dc9ed014 | 1377 | { |
joeverbout | 0:ea44dc9ed014 | 1378 | CV_Assert(n%DataType<_Tp>::channels == 0); |
joeverbout | 0:ea44dc9ed014 | 1379 | if( copyData ) |
joeverbout | 0:ea44dc9ed014 | 1380 | *this = clone(); |
joeverbout | 0:ea44dc9ed014 | 1381 | } |
joeverbout | 0:ea44dc9ed014 | 1382 | |
joeverbout | 0:ea44dc9ed014 | 1383 | template<typename _Tp> template<int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 1384 | Mat_<_Tp>::Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n>& M, bool copyData) |
joeverbout | 0:ea44dc9ed014 | 1385 | : Mat(m, n / DataType<_Tp>::channels, DataType<_Tp>::type, (void*)&M) |
joeverbout | 0:ea44dc9ed014 | 1386 | { |
joeverbout | 0:ea44dc9ed014 | 1387 | CV_Assert(n % DataType<_Tp>::channels == 0); |
joeverbout | 0:ea44dc9ed014 | 1388 | if( copyData ) |
joeverbout | 0:ea44dc9ed014 | 1389 | *this = clone(); |
joeverbout | 0:ea44dc9ed014 | 1390 | } |
joeverbout | 0:ea44dc9ed014 | 1391 | |
joeverbout | 0:ea44dc9ed014 | 1392 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1393 | Mat_<_Tp>::Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool copyData) |
joeverbout | 0:ea44dc9ed014 | 1394 | : Mat(2 / DataType<_Tp>::channels, 1, DataType<_Tp>::type, (void*)&pt) |
joeverbout | 0:ea44dc9ed014 | 1395 | { |
joeverbout | 0:ea44dc9ed014 | 1396 | CV_Assert(2 % DataType<_Tp>::channels == 0); |
joeverbout | 0:ea44dc9ed014 | 1397 | if( copyData ) |
joeverbout | 0:ea44dc9ed014 | 1398 | *this = clone(); |
joeverbout | 0:ea44dc9ed014 | 1399 | } |
joeverbout | 0:ea44dc9ed014 | 1400 | |
joeverbout | 0:ea44dc9ed014 | 1401 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1402 | Mat_<_Tp>::Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData) |
joeverbout | 0:ea44dc9ed014 | 1403 | : Mat(3 / DataType<_Tp>::channels, 1, DataType<_Tp>::type, (void*)&pt) |
joeverbout | 0:ea44dc9ed014 | 1404 | { |
joeverbout | 0:ea44dc9ed014 | 1405 | CV_Assert(3 % DataType<_Tp>::channels == 0); |
joeverbout | 0:ea44dc9ed014 | 1406 | if( copyData ) |
joeverbout | 0:ea44dc9ed014 | 1407 | *this = clone(); |
joeverbout | 0:ea44dc9ed014 | 1408 | } |
joeverbout | 0:ea44dc9ed014 | 1409 | |
joeverbout | 0:ea44dc9ed014 | 1410 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1411 | Mat_<_Tp>::Mat_(const MatCommaInitializer_<_Tp>& commaInitializer) |
joeverbout | 0:ea44dc9ed014 | 1412 | : Mat(commaInitializer) |
joeverbout | 0:ea44dc9ed014 | 1413 | {} |
joeverbout | 0:ea44dc9ed014 | 1414 | |
joeverbout | 0:ea44dc9ed014 | 1415 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1416 | Mat_<_Tp>::Mat_(const std::vector<_Tp>& vec, bool copyData) |
joeverbout | 0:ea44dc9ed014 | 1417 | : Mat(vec, copyData) |
joeverbout | 0:ea44dc9ed014 | 1418 | {} |
joeverbout | 0:ea44dc9ed014 | 1419 | |
joeverbout | 0:ea44dc9ed014 | 1420 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1421 | Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat& m) |
joeverbout | 0:ea44dc9ed014 | 1422 | { |
joeverbout | 0:ea44dc9ed014 | 1423 | if( DataType<_Tp>::type == m.type() ) |
joeverbout | 0:ea44dc9ed014 | 1424 | { |
joeverbout | 0:ea44dc9ed014 | 1425 | Mat::operator = (m); |
joeverbout | 0:ea44dc9ed014 | 1426 | return *this; |
joeverbout | 0:ea44dc9ed014 | 1427 | } |
joeverbout | 0:ea44dc9ed014 | 1428 | if( DataType<_Tp>::depth == m.depth() ) |
joeverbout | 0:ea44dc9ed014 | 1429 | { |
joeverbout | 0:ea44dc9ed014 | 1430 | return (*this = m.reshape(DataType<_Tp>::channels, m.dims, 0)); |
joeverbout | 0:ea44dc9ed014 | 1431 | } |
joeverbout | 0:ea44dc9ed014 | 1432 | CV_DbgAssert(DataType<_Tp>::channels == m.channels()); |
joeverbout | 0:ea44dc9ed014 | 1433 | m.convertTo(*this, type()); |
joeverbout | 0:ea44dc9ed014 | 1434 | return *this; |
joeverbout | 0:ea44dc9ed014 | 1435 | } |
joeverbout | 0:ea44dc9ed014 | 1436 | |
joeverbout | 0:ea44dc9ed014 | 1437 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1438 | Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat_& m) |
joeverbout | 0:ea44dc9ed014 | 1439 | { |
joeverbout | 0:ea44dc9ed014 | 1440 | Mat::operator=(m); |
joeverbout | 0:ea44dc9ed014 | 1441 | return *this; |
joeverbout | 0:ea44dc9ed014 | 1442 | } |
joeverbout | 0:ea44dc9ed014 | 1443 | |
joeverbout | 0:ea44dc9ed014 | 1444 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1445 | Mat_<_Tp>& Mat_<_Tp>::operator = (const _Tp& s) |
joeverbout | 0:ea44dc9ed014 | 1446 | { |
joeverbout | 0:ea44dc9ed014 | 1447 | typedef typename DataType<_Tp>::vec_type VT; |
joeverbout | 0:ea44dc9ed014 | 1448 | Mat::operator=(Scalar((const VT&)s)); |
joeverbout | 0:ea44dc9ed014 | 1449 | return *this; |
joeverbout | 0:ea44dc9ed014 | 1450 | } |
joeverbout | 0:ea44dc9ed014 | 1451 | |
joeverbout | 0:ea44dc9ed014 | 1452 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1453 | void Mat_<_Tp>::create(int _rows, int _cols) |
joeverbout | 0:ea44dc9ed014 | 1454 | { |
joeverbout | 0:ea44dc9ed014 | 1455 | Mat::create(_rows, _cols, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 1456 | } |
joeverbout | 0:ea44dc9ed014 | 1457 | |
joeverbout | 0:ea44dc9ed014 | 1458 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1459 | void Mat_<_Tp>::create(Size _sz) |
joeverbout | 0:ea44dc9ed014 | 1460 | { |
joeverbout | 0:ea44dc9ed014 | 1461 | Mat::create(_sz, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 1462 | } |
joeverbout | 0:ea44dc9ed014 | 1463 | |
joeverbout | 0:ea44dc9ed014 | 1464 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1465 | void Mat_<_Tp>::create(int _dims, const int* _sz) |
joeverbout | 0:ea44dc9ed014 | 1466 | { |
joeverbout | 0:ea44dc9ed014 | 1467 | Mat::create(_dims, _sz, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 1468 | } |
joeverbout | 0:ea44dc9ed014 | 1469 | |
joeverbout | 0:ea44dc9ed014 | 1470 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1471 | Mat_<_Tp> Mat_<_Tp>::cross(const Mat_& m) const |
joeverbout | 0:ea44dc9ed014 | 1472 | { |
joeverbout | 0:ea44dc9ed014 | 1473 | return Mat_<_Tp>(Mat::cross(m)); |
joeverbout | 0:ea44dc9ed014 | 1474 | } |
joeverbout | 0:ea44dc9ed014 | 1475 | |
joeverbout | 0:ea44dc9ed014 | 1476 | template<typename _Tp> template<typename T2> inline |
joeverbout | 0:ea44dc9ed014 | 1477 | Mat_<_Tp>::operator Mat_<T2>() const |
joeverbout | 0:ea44dc9ed014 | 1478 | { |
joeverbout | 0:ea44dc9ed014 | 1479 | return Mat_<T2>(*this); |
joeverbout | 0:ea44dc9ed014 | 1480 | } |
joeverbout | 0:ea44dc9ed014 | 1481 | |
joeverbout | 0:ea44dc9ed014 | 1482 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1483 | Mat_<_Tp> Mat_<_Tp>::row(int y) const |
joeverbout | 0:ea44dc9ed014 | 1484 | { |
joeverbout | 0:ea44dc9ed014 | 1485 | return Mat_(*this, Range(y, y+1), Range::all()); |
joeverbout | 0:ea44dc9ed014 | 1486 | } |
joeverbout | 0:ea44dc9ed014 | 1487 | |
joeverbout | 0:ea44dc9ed014 | 1488 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1489 | Mat_<_Tp> Mat_<_Tp>::col(int x) const |
joeverbout | 0:ea44dc9ed014 | 1490 | { |
joeverbout | 0:ea44dc9ed014 | 1491 | return Mat_(*this, Range::all(), Range(x, x+1)); |
joeverbout | 0:ea44dc9ed014 | 1492 | } |
joeverbout | 0:ea44dc9ed014 | 1493 | |
joeverbout | 0:ea44dc9ed014 | 1494 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1495 | Mat_<_Tp> Mat_<_Tp>::diag(int d) const |
joeverbout | 0:ea44dc9ed014 | 1496 | { |
joeverbout | 0:ea44dc9ed014 | 1497 | return Mat_(Mat::diag(d)); |
joeverbout | 0:ea44dc9ed014 | 1498 | } |
joeverbout | 0:ea44dc9ed014 | 1499 | |
joeverbout | 0:ea44dc9ed014 | 1500 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1501 | Mat_<_Tp> Mat_<_Tp>::clone() const |
joeverbout | 0:ea44dc9ed014 | 1502 | { |
joeverbout | 0:ea44dc9ed014 | 1503 | return Mat_(Mat::clone()); |
joeverbout | 0:ea44dc9ed014 | 1504 | } |
joeverbout | 0:ea44dc9ed014 | 1505 | |
joeverbout | 0:ea44dc9ed014 | 1506 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1507 | size_t Mat_<_Tp>::elemSize() const |
joeverbout | 0:ea44dc9ed014 | 1508 | { |
joeverbout | 0:ea44dc9ed014 | 1509 | CV_DbgAssert( Mat::elemSize() == sizeof(_Tp) ); |
joeverbout | 0:ea44dc9ed014 | 1510 | return sizeof(_Tp); |
joeverbout | 0:ea44dc9ed014 | 1511 | } |
joeverbout | 0:ea44dc9ed014 | 1512 | |
joeverbout | 0:ea44dc9ed014 | 1513 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1514 | size_t Mat_<_Tp>::elemSize1() const |
joeverbout | 0:ea44dc9ed014 | 1515 | { |
joeverbout | 0:ea44dc9ed014 | 1516 | CV_DbgAssert( Mat::elemSize1() == sizeof(_Tp) / DataType<_Tp>::channels ); |
joeverbout | 0:ea44dc9ed014 | 1517 | return sizeof(_Tp) / DataType<_Tp>::channels; |
joeverbout | 0:ea44dc9ed014 | 1518 | } |
joeverbout | 0:ea44dc9ed014 | 1519 | |
joeverbout | 0:ea44dc9ed014 | 1520 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1521 | int Mat_<_Tp>::type() const |
joeverbout | 0:ea44dc9ed014 | 1522 | { |
joeverbout | 0:ea44dc9ed014 | 1523 | CV_DbgAssert( Mat::type() == DataType<_Tp>::type ); |
joeverbout | 0:ea44dc9ed014 | 1524 | return DataType<_Tp>::type; |
joeverbout | 0:ea44dc9ed014 | 1525 | } |
joeverbout | 0:ea44dc9ed014 | 1526 | |
joeverbout | 0:ea44dc9ed014 | 1527 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1528 | int Mat_<_Tp>::depth() const |
joeverbout | 0:ea44dc9ed014 | 1529 | { |
joeverbout | 0:ea44dc9ed014 | 1530 | CV_DbgAssert( Mat::depth() == DataType<_Tp>::depth ); |
joeverbout | 0:ea44dc9ed014 | 1531 | return DataType<_Tp>::depth; |
joeverbout | 0:ea44dc9ed014 | 1532 | } |
joeverbout | 0:ea44dc9ed014 | 1533 | |
joeverbout | 0:ea44dc9ed014 | 1534 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1535 | int Mat_<_Tp>::channels() const |
joeverbout | 0:ea44dc9ed014 | 1536 | { |
joeverbout | 0:ea44dc9ed014 | 1537 | CV_DbgAssert( Mat::channels() == DataType<_Tp>::channels ); |
joeverbout | 0:ea44dc9ed014 | 1538 | return DataType<_Tp>::channels; |
joeverbout | 0:ea44dc9ed014 | 1539 | } |
joeverbout | 0:ea44dc9ed014 | 1540 | |
joeverbout | 0:ea44dc9ed014 | 1541 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1542 | size_t Mat_<_Tp>::stepT(int i) const |
joeverbout | 0:ea44dc9ed014 | 1543 | { |
joeverbout | 0:ea44dc9ed014 | 1544 | return step.p[i] / elemSize(); |
joeverbout | 0:ea44dc9ed014 | 1545 | } |
joeverbout | 0:ea44dc9ed014 | 1546 | |
joeverbout | 0:ea44dc9ed014 | 1547 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1548 | size_t Mat_<_Tp>::step1(int i) const |
joeverbout | 0:ea44dc9ed014 | 1549 | { |
joeverbout | 0:ea44dc9ed014 | 1550 | return step.p[i] / elemSize1(); |
joeverbout | 0:ea44dc9ed014 | 1551 | } |
joeverbout | 0:ea44dc9ed014 | 1552 | |
joeverbout | 0:ea44dc9ed014 | 1553 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1554 | Mat_<_Tp>& Mat_<_Tp>::adjustROI( int dtop, int dbottom, int dleft, int dright ) |
joeverbout | 0:ea44dc9ed014 | 1555 | { |
joeverbout | 0:ea44dc9ed014 | 1556 | return (Mat_<_Tp>&)(Mat::adjustROI(dtop, dbottom, dleft, dright)); |
joeverbout | 0:ea44dc9ed014 | 1557 | } |
joeverbout | 0:ea44dc9ed014 | 1558 | |
joeverbout | 0:ea44dc9ed014 | 1559 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1560 | Mat_<_Tp> Mat_<_Tp>::operator()( const Range& _rowRange, const Range& _colRange ) const |
joeverbout | 0:ea44dc9ed014 | 1561 | { |
joeverbout | 0:ea44dc9ed014 | 1562 | return Mat_<_Tp>(*this, _rowRange, _colRange); |
joeverbout | 0:ea44dc9ed014 | 1563 | } |
joeverbout | 0:ea44dc9ed014 | 1564 | |
joeverbout | 0:ea44dc9ed014 | 1565 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1566 | Mat_<_Tp> Mat_<_Tp>::operator()( const Rect& roi ) const |
joeverbout | 0:ea44dc9ed014 | 1567 | { |
joeverbout | 0:ea44dc9ed014 | 1568 | return Mat_<_Tp>(*this, roi); |
joeverbout | 0:ea44dc9ed014 | 1569 | } |
joeverbout | 0:ea44dc9ed014 | 1570 | |
joeverbout | 0:ea44dc9ed014 | 1571 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1572 | Mat_<_Tp> Mat_<_Tp>::operator()( const Range* ranges ) const |
joeverbout | 0:ea44dc9ed014 | 1573 | { |
joeverbout | 0:ea44dc9ed014 | 1574 | return Mat_<_Tp>(*this, ranges); |
joeverbout | 0:ea44dc9ed014 | 1575 | } |
joeverbout | 0:ea44dc9ed014 | 1576 | |
joeverbout | 0:ea44dc9ed014 | 1577 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1578 | _Tp* Mat_<_Tp>::operator [](int y) |
joeverbout | 0:ea44dc9ed014 | 1579 | { |
joeverbout | 0:ea44dc9ed014 | 1580 | CV_DbgAssert( 0 <= y && y < rows ); |
joeverbout | 0:ea44dc9ed014 | 1581 | return (_Tp*)(data + y*step.p[0]); |
joeverbout | 0:ea44dc9ed014 | 1582 | } |
joeverbout | 0:ea44dc9ed014 | 1583 | |
joeverbout | 0:ea44dc9ed014 | 1584 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1585 | const _Tp* Mat_<_Tp>::operator [](int y) const |
joeverbout | 0:ea44dc9ed014 | 1586 | { |
joeverbout | 0:ea44dc9ed014 | 1587 | CV_DbgAssert( 0 <= y && y < rows ); |
joeverbout | 0:ea44dc9ed014 | 1588 | return (const _Tp*)(data + y*step.p[0]); |
joeverbout | 0:ea44dc9ed014 | 1589 | } |
joeverbout | 0:ea44dc9ed014 | 1590 | |
joeverbout | 0:ea44dc9ed014 | 1591 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1592 | _Tp& Mat_<_Tp>::operator ()(int i0, int i1) |
joeverbout | 0:ea44dc9ed014 | 1593 | { |
joeverbout | 0:ea44dc9ed014 | 1594 | CV_DbgAssert(dims <= 2); |
joeverbout | 0:ea44dc9ed014 | 1595 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 1596 | CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); |
joeverbout | 0:ea44dc9ed014 | 1597 | CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); |
joeverbout | 0:ea44dc9ed014 | 1598 | CV_DbgAssert(type() == DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 1599 | return ((_Tp*)(data + step.p[0] * i0))[i1]; |
joeverbout | 0:ea44dc9ed014 | 1600 | } |
joeverbout | 0:ea44dc9ed014 | 1601 | |
joeverbout | 0:ea44dc9ed014 | 1602 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1603 | const _Tp& Mat_<_Tp>::operator ()(int i0, int i1) const |
joeverbout | 0:ea44dc9ed014 | 1604 | { |
joeverbout | 0:ea44dc9ed014 | 1605 | CV_DbgAssert(dims <= 2); |
joeverbout | 0:ea44dc9ed014 | 1606 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 1607 | CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); |
joeverbout | 0:ea44dc9ed014 | 1608 | CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); |
joeverbout | 0:ea44dc9ed014 | 1609 | CV_DbgAssert(type() == DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 1610 | return ((const _Tp*)(data + step.p[0] * i0))[i1]; |
joeverbout | 0:ea44dc9ed014 | 1611 | } |
joeverbout | 0:ea44dc9ed014 | 1612 | |
joeverbout | 0:ea44dc9ed014 | 1613 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1614 | _Tp& Mat_<_Tp>::operator ()(Point pt) |
joeverbout | 0:ea44dc9ed014 | 1615 | { |
joeverbout | 0:ea44dc9ed014 | 1616 | CV_DbgAssert(dims <= 2); |
joeverbout | 0:ea44dc9ed014 | 1617 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 1618 | CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]); |
joeverbout | 0:ea44dc9ed014 | 1619 | CV_DbgAssert((unsigned)pt.x < (unsigned)size.p[1]); |
joeverbout | 0:ea44dc9ed014 | 1620 | CV_DbgAssert(type() == DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 1621 | return ((_Tp*)(data + step.p[0] * pt.y))[pt.x]; |
joeverbout | 0:ea44dc9ed014 | 1622 | } |
joeverbout | 0:ea44dc9ed014 | 1623 | |
joeverbout | 0:ea44dc9ed014 | 1624 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1625 | const _Tp& Mat_<_Tp>::operator ()(Point pt) const |
joeverbout | 0:ea44dc9ed014 | 1626 | { |
joeverbout | 0:ea44dc9ed014 | 1627 | CV_DbgAssert(dims <= 2); |
joeverbout | 0:ea44dc9ed014 | 1628 | CV_DbgAssert(data); |
joeverbout | 0:ea44dc9ed014 | 1629 | CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]); |
joeverbout | 0:ea44dc9ed014 | 1630 | CV_DbgAssert((unsigned)pt.x < (unsigned)size.p[1]); |
joeverbout | 0:ea44dc9ed014 | 1631 | CV_DbgAssert(type() == DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 1632 | return ((const _Tp*)(data + step.p[0] * pt.y))[pt.x]; |
joeverbout | 0:ea44dc9ed014 | 1633 | } |
joeverbout | 0:ea44dc9ed014 | 1634 | |
joeverbout | 0:ea44dc9ed014 | 1635 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1636 | _Tp& Mat_<_Tp>::operator ()(const int* idx) |
joeverbout | 0:ea44dc9ed014 | 1637 | { |
joeverbout | 0:ea44dc9ed014 | 1638 | return Mat::at<_Tp>(idx); |
joeverbout | 0:ea44dc9ed014 | 1639 | } |
joeverbout | 0:ea44dc9ed014 | 1640 | |
joeverbout | 0:ea44dc9ed014 | 1641 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1642 | const _Tp& Mat_<_Tp>::operator ()(const int* idx) const |
joeverbout | 0:ea44dc9ed014 | 1643 | { |
joeverbout | 0:ea44dc9ed014 | 1644 | return Mat::at<_Tp>(idx); |
joeverbout | 0:ea44dc9ed014 | 1645 | } |
joeverbout | 0:ea44dc9ed014 | 1646 | |
joeverbout | 0:ea44dc9ed014 | 1647 | template<typename _Tp> template<int n> inline |
joeverbout | 0:ea44dc9ed014 | 1648 | _Tp& Mat_<_Tp>::operator ()(const Vec<int, n>& idx) |
joeverbout | 0:ea44dc9ed014 | 1649 | { |
joeverbout | 0:ea44dc9ed014 | 1650 | return Mat::at<_Tp>(idx); |
joeverbout | 0:ea44dc9ed014 | 1651 | } |
joeverbout | 0:ea44dc9ed014 | 1652 | |
joeverbout | 0:ea44dc9ed014 | 1653 | template<typename _Tp> template<int n> inline |
joeverbout | 0:ea44dc9ed014 | 1654 | const _Tp& Mat_<_Tp>::operator ()(const Vec<int, n>& idx) const |
joeverbout | 0:ea44dc9ed014 | 1655 | { |
joeverbout | 0:ea44dc9ed014 | 1656 | return Mat::at<_Tp>(idx); |
joeverbout | 0:ea44dc9ed014 | 1657 | } |
joeverbout | 0:ea44dc9ed014 | 1658 | |
joeverbout | 0:ea44dc9ed014 | 1659 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1660 | _Tp& Mat_<_Tp>::operator ()(int i0) |
joeverbout | 0:ea44dc9ed014 | 1661 | { |
joeverbout | 0:ea44dc9ed014 | 1662 | return this->at<_Tp>(i0); |
joeverbout | 0:ea44dc9ed014 | 1663 | } |
joeverbout | 0:ea44dc9ed014 | 1664 | |
joeverbout | 0:ea44dc9ed014 | 1665 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1666 | const _Tp& Mat_<_Tp>::operator ()(int i0) const |
joeverbout | 0:ea44dc9ed014 | 1667 | { |
joeverbout | 0:ea44dc9ed014 | 1668 | return this->at<_Tp>(i0); |
joeverbout | 0:ea44dc9ed014 | 1669 | } |
joeverbout | 0:ea44dc9ed014 | 1670 | |
joeverbout | 0:ea44dc9ed014 | 1671 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1672 | _Tp& Mat_<_Tp>::operator ()(int i0, int i1, int i2) |
joeverbout | 0:ea44dc9ed014 | 1673 | { |
joeverbout | 0:ea44dc9ed014 | 1674 | return this->at<_Tp>(i0, i1, i2); |
joeverbout | 0:ea44dc9ed014 | 1675 | } |
joeverbout | 0:ea44dc9ed014 | 1676 | |
joeverbout | 0:ea44dc9ed014 | 1677 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1678 | const _Tp& Mat_<_Tp>::operator ()(int i0, int i1, int i2) const |
joeverbout | 0:ea44dc9ed014 | 1679 | { |
joeverbout | 0:ea44dc9ed014 | 1680 | return this->at<_Tp>(i0, i1, i2); |
joeverbout | 0:ea44dc9ed014 | 1681 | } |
joeverbout | 0:ea44dc9ed014 | 1682 | |
joeverbout | 0:ea44dc9ed014 | 1683 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1684 | Mat_<_Tp>::operator std::vector<_Tp>() const |
joeverbout | 0:ea44dc9ed014 | 1685 | { |
joeverbout | 0:ea44dc9ed014 | 1686 | std::vector<_Tp> v; |
joeverbout | 0:ea44dc9ed014 | 1687 | copyTo(v); |
joeverbout | 0:ea44dc9ed014 | 1688 | return v; |
joeverbout | 0:ea44dc9ed014 | 1689 | } |
joeverbout | 0:ea44dc9ed014 | 1690 | |
joeverbout | 0:ea44dc9ed014 | 1691 | template<typename _Tp> template<int n> inline |
joeverbout | 0:ea44dc9ed014 | 1692 | Mat_<_Tp>::operator Vec<typename DataType<_Tp>::channel_type, n>() const |
joeverbout | 0:ea44dc9ed014 | 1693 | { |
joeverbout | 0:ea44dc9ed014 | 1694 | CV_Assert(n % DataType<_Tp>::channels == 0); |
joeverbout | 0:ea44dc9ed014 | 1695 | |
joeverbout | 0:ea44dc9ed014 | 1696 | #if defined _MSC_VER |
joeverbout | 0:ea44dc9ed014 | 1697 | const Mat* pMat = (const Mat*)this; // workaround for MSVS <= 2012 compiler bugs (but GCC 4.6 dislikes this workaround) |
joeverbout | 0:ea44dc9ed014 | 1698 | return pMat->operator Vec<typename DataType<_Tp>::channel_type, n>(); |
joeverbout | 0:ea44dc9ed014 | 1699 | #else |
joeverbout | 0:ea44dc9ed014 | 1700 | return this->Mat::operator Vec<typename DataType<_Tp>::channel_type, n>(); |
joeverbout | 0:ea44dc9ed014 | 1701 | #endif |
joeverbout | 0:ea44dc9ed014 | 1702 | } |
joeverbout | 0:ea44dc9ed014 | 1703 | |
joeverbout | 0:ea44dc9ed014 | 1704 | template<typename _Tp> template<int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 1705 | Mat_<_Tp>::operator Matx<typename DataType<_Tp>::channel_type, m, n>() const |
joeverbout | 0:ea44dc9ed014 | 1706 | { |
joeverbout | 0:ea44dc9ed014 | 1707 | CV_Assert(n % DataType<_Tp>::channels == 0); |
joeverbout | 0:ea44dc9ed014 | 1708 | |
joeverbout | 0:ea44dc9ed014 | 1709 | #if defined _MSC_VER |
joeverbout | 0:ea44dc9ed014 | 1710 | const Mat* pMat = (const Mat*)this; // workaround for MSVS <= 2012 compiler bugs (but GCC 4.6 dislikes this workaround) |
joeverbout | 0:ea44dc9ed014 | 1711 | Matx<typename DataType<_Tp>::channel_type, m, n> res = pMat->operator Matx<typename DataType<_Tp>::channel_type, m, n>(); |
joeverbout | 0:ea44dc9ed014 | 1712 | return res; |
joeverbout | 0:ea44dc9ed014 | 1713 | #else |
joeverbout | 0:ea44dc9ed014 | 1714 | Matx<typename DataType<_Tp>::channel_type, m, n> res = this->Mat::operator Matx<typename DataType<_Tp>::channel_type, m, n>(); |
joeverbout | 0:ea44dc9ed014 | 1715 | return res; |
joeverbout | 0:ea44dc9ed014 | 1716 | #endif |
joeverbout | 0:ea44dc9ed014 | 1717 | } |
joeverbout | 0:ea44dc9ed014 | 1718 | |
joeverbout | 0:ea44dc9ed014 | 1719 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1720 | MatConstIterator_<_Tp> Mat_<_Tp>::begin() const |
joeverbout | 0:ea44dc9ed014 | 1721 | { |
joeverbout | 0:ea44dc9ed014 | 1722 | return Mat::begin<_Tp>(); |
joeverbout | 0:ea44dc9ed014 | 1723 | } |
joeverbout | 0:ea44dc9ed014 | 1724 | |
joeverbout | 0:ea44dc9ed014 | 1725 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1726 | MatConstIterator_<_Tp> Mat_<_Tp>::end() const |
joeverbout | 0:ea44dc9ed014 | 1727 | { |
joeverbout | 0:ea44dc9ed014 | 1728 | return Mat::end<_Tp>(); |
joeverbout | 0:ea44dc9ed014 | 1729 | } |
joeverbout | 0:ea44dc9ed014 | 1730 | |
joeverbout | 0:ea44dc9ed014 | 1731 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1732 | MatIterator_<_Tp> Mat_<_Tp>::begin() |
joeverbout | 0:ea44dc9ed014 | 1733 | { |
joeverbout | 0:ea44dc9ed014 | 1734 | return Mat::begin<_Tp>(); |
joeverbout | 0:ea44dc9ed014 | 1735 | } |
joeverbout | 0:ea44dc9ed014 | 1736 | |
joeverbout | 0:ea44dc9ed014 | 1737 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1738 | MatIterator_<_Tp> Mat_<_Tp>::end() |
joeverbout | 0:ea44dc9ed014 | 1739 | { |
joeverbout | 0:ea44dc9ed014 | 1740 | return Mat::end<_Tp>(); |
joeverbout | 0:ea44dc9ed014 | 1741 | } |
joeverbout | 0:ea44dc9ed014 | 1742 | |
joeverbout | 0:ea44dc9ed014 | 1743 | template<typename _Tp> template<typename Functor> inline |
joeverbout | 0:ea44dc9ed014 | 1744 | void Mat_<_Tp>::forEach(const Functor& operation) { |
joeverbout | 0:ea44dc9ed014 | 1745 | Mat::forEach<_Tp, Functor>(operation); |
joeverbout | 0:ea44dc9ed014 | 1746 | } |
joeverbout | 0:ea44dc9ed014 | 1747 | |
joeverbout | 0:ea44dc9ed014 | 1748 | template<typename _Tp> template<typename Functor> inline |
joeverbout | 0:ea44dc9ed014 | 1749 | void Mat_<_Tp>::forEach(const Functor& operation) const { |
joeverbout | 0:ea44dc9ed014 | 1750 | Mat::forEach<_Tp, Functor>(operation); |
joeverbout | 0:ea44dc9ed014 | 1751 | } |
joeverbout | 0:ea44dc9ed014 | 1752 | |
joeverbout | 0:ea44dc9ed014 | 1753 | #ifdef CV_CXX_MOVE_SEMANTICS |
joeverbout | 0:ea44dc9ed014 | 1754 | |
joeverbout | 0:ea44dc9ed014 | 1755 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1756 | Mat_<_Tp>::Mat_(Mat_&& m) |
joeverbout | 0:ea44dc9ed014 | 1757 | : Mat(m) |
joeverbout | 0:ea44dc9ed014 | 1758 | { |
joeverbout | 0:ea44dc9ed014 | 1759 | } |
joeverbout | 0:ea44dc9ed014 | 1760 | |
joeverbout | 0:ea44dc9ed014 | 1761 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1762 | Mat_<_Tp>& Mat_<_Tp>::operator = (Mat_&& m) |
joeverbout | 0:ea44dc9ed014 | 1763 | { |
joeverbout | 0:ea44dc9ed014 | 1764 | Mat::operator = (m); |
joeverbout | 0:ea44dc9ed014 | 1765 | return *this; |
joeverbout | 0:ea44dc9ed014 | 1766 | } |
joeverbout | 0:ea44dc9ed014 | 1767 | |
joeverbout | 0:ea44dc9ed014 | 1768 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1769 | Mat_<_Tp>::Mat_(Mat&& m) |
joeverbout | 0:ea44dc9ed014 | 1770 | : Mat() |
joeverbout | 0:ea44dc9ed014 | 1771 | { |
joeverbout | 0:ea44dc9ed014 | 1772 | flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type; |
joeverbout | 0:ea44dc9ed014 | 1773 | *this = m; |
joeverbout | 0:ea44dc9ed014 | 1774 | } |
joeverbout | 0:ea44dc9ed014 | 1775 | |
joeverbout | 0:ea44dc9ed014 | 1776 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1777 | Mat_<_Tp>& Mat_<_Tp>::operator = (Mat&& m) |
joeverbout | 0:ea44dc9ed014 | 1778 | { |
joeverbout | 0:ea44dc9ed014 | 1779 | if( DataType<_Tp>::type == m.type() ) |
joeverbout | 0:ea44dc9ed014 | 1780 | { |
joeverbout | 0:ea44dc9ed014 | 1781 | Mat::operator = ((Mat&&)m); |
joeverbout | 0:ea44dc9ed014 | 1782 | return *this; |
joeverbout | 0:ea44dc9ed014 | 1783 | } |
joeverbout | 0:ea44dc9ed014 | 1784 | if( DataType<_Tp>::depth == m.depth() ) |
joeverbout | 0:ea44dc9ed014 | 1785 | { |
joeverbout | 0:ea44dc9ed014 | 1786 | Mat::operator = ((Mat&&)m.reshape(DataType<_Tp>::channels, m.dims, 0)); |
joeverbout | 0:ea44dc9ed014 | 1787 | return *this; |
joeverbout | 0:ea44dc9ed014 | 1788 | } |
joeverbout | 0:ea44dc9ed014 | 1789 | CV_DbgAssert(DataType<_Tp>::channels == m.channels()); |
joeverbout | 0:ea44dc9ed014 | 1790 | m.convertTo(*this, type()); |
joeverbout | 0:ea44dc9ed014 | 1791 | return *this; |
joeverbout | 0:ea44dc9ed014 | 1792 | } |
joeverbout | 0:ea44dc9ed014 | 1793 | |
joeverbout | 0:ea44dc9ed014 | 1794 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1795 | Mat_<_Tp>::Mat_(MatExpr&& e) |
joeverbout | 0:ea44dc9ed014 | 1796 | : Mat() |
joeverbout | 0:ea44dc9ed014 | 1797 | { |
joeverbout | 0:ea44dc9ed014 | 1798 | flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type; |
joeverbout | 0:ea44dc9ed014 | 1799 | *this = Mat(e); |
joeverbout | 0:ea44dc9ed014 | 1800 | } |
joeverbout | 0:ea44dc9ed014 | 1801 | |
joeverbout | 0:ea44dc9ed014 | 1802 | #endif |
joeverbout | 0:ea44dc9ed014 | 1803 | |
joeverbout | 0:ea44dc9ed014 | 1804 | ///////////////////////////// SparseMat ///////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 1805 | |
joeverbout | 0:ea44dc9ed014 | 1806 | inline |
joeverbout | 0:ea44dc9ed014 | 1807 | SparseMat::SparseMat() |
joeverbout | 0:ea44dc9ed014 | 1808 | : flags(MAGIC_VAL), hdr(0) |
joeverbout | 0:ea44dc9ed014 | 1809 | {} |
joeverbout | 0:ea44dc9ed014 | 1810 | |
joeverbout | 0:ea44dc9ed014 | 1811 | inline |
joeverbout | 0:ea44dc9ed014 | 1812 | SparseMat::SparseMat(int _dims, const int* _sizes, int _type) |
joeverbout | 0:ea44dc9ed014 | 1813 | : flags(MAGIC_VAL), hdr(0) |
joeverbout | 0:ea44dc9ed014 | 1814 | { |
joeverbout | 0:ea44dc9ed014 | 1815 | create(_dims, _sizes, _type); |
joeverbout | 0:ea44dc9ed014 | 1816 | } |
joeverbout | 0:ea44dc9ed014 | 1817 | |
joeverbout | 0:ea44dc9ed014 | 1818 | inline |
joeverbout | 0:ea44dc9ed014 | 1819 | SparseMat::SparseMat(const SparseMat& m) |
joeverbout | 0:ea44dc9ed014 | 1820 | : flags(m.flags), hdr(m.hdr) |
joeverbout | 0:ea44dc9ed014 | 1821 | { |
joeverbout | 0:ea44dc9ed014 | 1822 | addref(); |
joeverbout | 0:ea44dc9ed014 | 1823 | } |
joeverbout | 0:ea44dc9ed014 | 1824 | |
joeverbout | 0:ea44dc9ed014 | 1825 | inline |
joeverbout | 0:ea44dc9ed014 | 1826 | SparseMat::~SparseMat() |
joeverbout | 0:ea44dc9ed014 | 1827 | { |
joeverbout | 0:ea44dc9ed014 | 1828 | release(); |
joeverbout | 0:ea44dc9ed014 | 1829 | } |
joeverbout | 0:ea44dc9ed014 | 1830 | |
joeverbout | 0:ea44dc9ed014 | 1831 | inline |
joeverbout | 0:ea44dc9ed014 | 1832 | SparseMat& SparseMat::operator = (const SparseMat& m) |
joeverbout | 0:ea44dc9ed014 | 1833 | { |
joeverbout | 0:ea44dc9ed014 | 1834 | if( this != &m ) |
joeverbout | 0:ea44dc9ed014 | 1835 | { |
joeverbout | 0:ea44dc9ed014 | 1836 | if( m.hdr ) |
joeverbout | 0:ea44dc9ed014 | 1837 | CV_XADD(&m.hdr->refcount, 1); |
joeverbout | 0:ea44dc9ed014 | 1838 | release(); |
joeverbout | 0:ea44dc9ed014 | 1839 | flags = m.flags; |
joeverbout | 0:ea44dc9ed014 | 1840 | hdr = m.hdr; |
joeverbout | 0:ea44dc9ed014 | 1841 | } |
joeverbout | 0:ea44dc9ed014 | 1842 | return *this; |
joeverbout | 0:ea44dc9ed014 | 1843 | } |
joeverbout | 0:ea44dc9ed014 | 1844 | |
joeverbout | 0:ea44dc9ed014 | 1845 | inline |
joeverbout | 0:ea44dc9ed014 | 1846 | SparseMat& SparseMat::operator = (const Mat& m) |
joeverbout | 0:ea44dc9ed014 | 1847 | { |
joeverbout | 0:ea44dc9ed014 | 1848 | return (*this = SparseMat(m)); |
joeverbout | 0:ea44dc9ed014 | 1849 | } |
joeverbout | 0:ea44dc9ed014 | 1850 | |
joeverbout | 0:ea44dc9ed014 | 1851 | inline |
joeverbout | 0:ea44dc9ed014 | 1852 | SparseMat SparseMat::clone() const |
joeverbout | 0:ea44dc9ed014 | 1853 | { |
joeverbout | 0:ea44dc9ed014 | 1854 | SparseMat temp; |
joeverbout | 0:ea44dc9ed014 | 1855 | this->copyTo(temp); |
joeverbout | 0:ea44dc9ed014 | 1856 | return temp; |
joeverbout | 0:ea44dc9ed014 | 1857 | } |
joeverbout | 0:ea44dc9ed014 | 1858 | |
joeverbout | 0:ea44dc9ed014 | 1859 | inline |
joeverbout | 0:ea44dc9ed014 | 1860 | void SparseMat::assignTo( SparseMat& m, int _type ) const |
joeverbout | 0:ea44dc9ed014 | 1861 | { |
joeverbout | 0:ea44dc9ed014 | 1862 | if( _type < 0 ) |
joeverbout | 0:ea44dc9ed014 | 1863 | m = *this; |
joeverbout | 0:ea44dc9ed014 | 1864 | else |
joeverbout | 0:ea44dc9ed014 | 1865 | convertTo(m, _type); |
joeverbout | 0:ea44dc9ed014 | 1866 | } |
joeverbout | 0:ea44dc9ed014 | 1867 | |
joeverbout | 0:ea44dc9ed014 | 1868 | inline |
joeverbout | 0:ea44dc9ed014 | 1869 | void SparseMat::addref() |
joeverbout | 0:ea44dc9ed014 | 1870 | { |
joeverbout | 0:ea44dc9ed014 | 1871 | if( hdr ) |
joeverbout | 0:ea44dc9ed014 | 1872 | CV_XADD(&hdr->refcount, 1); |
joeverbout | 0:ea44dc9ed014 | 1873 | } |
joeverbout | 0:ea44dc9ed014 | 1874 | |
joeverbout | 0:ea44dc9ed014 | 1875 | inline |
joeverbout | 0:ea44dc9ed014 | 1876 | void SparseMat::release() |
joeverbout | 0:ea44dc9ed014 | 1877 | { |
joeverbout | 0:ea44dc9ed014 | 1878 | if( hdr && CV_XADD(&hdr->refcount, -1) == 1 ) |
joeverbout | 0:ea44dc9ed014 | 1879 | delete hdr; |
joeverbout | 0:ea44dc9ed014 | 1880 | hdr = 0; |
joeverbout | 0:ea44dc9ed014 | 1881 | } |
joeverbout | 0:ea44dc9ed014 | 1882 | |
joeverbout | 0:ea44dc9ed014 | 1883 | inline |
joeverbout | 0:ea44dc9ed014 | 1884 | size_t SparseMat::elemSize() const |
joeverbout | 0:ea44dc9ed014 | 1885 | { |
joeverbout | 0:ea44dc9ed014 | 1886 | return CV_ELEM_SIZE(flags); |
joeverbout | 0:ea44dc9ed014 | 1887 | } |
joeverbout | 0:ea44dc9ed014 | 1888 | |
joeverbout | 0:ea44dc9ed014 | 1889 | inline |
joeverbout | 0:ea44dc9ed014 | 1890 | size_t SparseMat::elemSize1() const |
joeverbout | 0:ea44dc9ed014 | 1891 | { |
joeverbout | 0:ea44dc9ed014 | 1892 | return CV_ELEM_SIZE1(flags); |
joeverbout | 0:ea44dc9ed014 | 1893 | } |
joeverbout | 0:ea44dc9ed014 | 1894 | |
joeverbout | 0:ea44dc9ed014 | 1895 | inline |
joeverbout | 0:ea44dc9ed014 | 1896 | int SparseMat::type() const |
joeverbout | 0:ea44dc9ed014 | 1897 | { |
joeverbout | 0:ea44dc9ed014 | 1898 | return CV_MAT_TYPE(flags); |
joeverbout | 0:ea44dc9ed014 | 1899 | } |
joeverbout | 0:ea44dc9ed014 | 1900 | |
joeverbout | 0:ea44dc9ed014 | 1901 | inline |
joeverbout | 0:ea44dc9ed014 | 1902 | int SparseMat::depth() const |
joeverbout | 0:ea44dc9ed014 | 1903 | { |
joeverbout | 0:ea44dc9ed014 | 1904 | return CV_MAT_DEPTH(flags); |
joeverbout | 0:ea44dc9ed014 | 1905 | } |
joeverbout | 0:ea44dc9ed014 | 1906 | |
joeverbout | 0:ea44dc9ed014 | 1907 | inline |
joeverbout | 0:ea44dc9ed014 | 1908 | int SparseMat::channels() const |
joeverbout | 0:ea44dc9ed014 | 1909 | { |
joeverbout | 0:ea44dc9ed014 | 1910 | return CV_MAT_CN(flags); |
joeverbout | 0:ea44dc9ed014 | 1911 | } |
joeverbout | 0:ea44dc9ed014 | 1912 | |
joeverbout | 0:ea44dc9ed014 | 1913 | inline |
joeverbout | 0:ea44dc9ed014 | 1914 | const int* SparseMat::size() const |
joeverbout | 0:ea44dc9ed014 | 1915 | { |
joeverbout | 0:ea44dc9ed014 | 1916 | return hdr ? hdr->size : 0; |
joeverbout | 0:ea44dc9ed014 | 1917 | } |
joeverbout | 0:ea44dc9ed014 | 1918 | |
joeverbout | 0:ea44dc9ed014 | 1919 | inline |
joeverbout | 0:ea44dc9ed014 | 1920 | int SparseMat::size(int i) const |
joeverbout | 0:ea44dc9ed014 | 1921 | { |
joeverbout | 0:ea44dc9ed014 | 1922 | if( hdr ) |
joeverbout | 0:ea44dc9ed014 | 1923 | { |
joeverbout | 0:ea44dc9ed014 | 1924 | CV_DbgAssert((unsigned)i < (unsigned)hdr->dims); |
joeverbout | 0:ea44dc9ed014 | 1925 | return hdr->size[i]; |
joeverbout | 0:ea44dc9ed014 | 1926 | } |
joeverbout | 0:ea44dc9ed014 | 1927 | return 0; |
joeverbout | 0:ea44dc9ed014 | 1928 | } |
joeverbout | 0:ea44dc9ed014 | 1929 | |
joeverbout | 0:ea44dc9ed014 | 1930 | inline |
joeverbout | 0:ea44dc9ed014 | 1931 | int SparseMat::dims() const |
joeverbout | 0:ea44dc9ed014 | 1932 | { |
joeverbout | 0:ea44dc9ed014 | 1933 | return hdr ? hdr->dims : 0; |
joeverbout | 0:ea44dc9ed014 | 1934 | } |
joeverbout | 0:ea44dc9ed014 | 1935 | |
joeverbout | 0:ea44dc9ed014 | 1936 | inline |
joeverbout | 0:ea44dc9ed014 | 1937 | size_t SparseMat::nzcount() const |
joeverbout | 0:ea44dc9ed014 | 1938 | { |
joeverbout | 0:ea44dc9ed014 | 1939 | return hdr ? hdr->nodeCount : 0; |
joeverbout | 0:ea44dc9ed014 | 1940 | } |
joeverbout | 0:ea44dc9ed014 | 1941 | |
joeverbout | 0:ea44dc9ed014 | 1942 | inline |
joeverbout | 0:ea44dc9ed014 | 1943 | size_t SparseMat::hash(int i0) const |
joeverbout | 0:ea44dc9ed014 | 1944 | { |
joeverbout | 0:ea44dc9ed014 | 1945 | return (size_t)i0; |
joeverbout | 0:ea44dc9ed014 | 1946 | } |
joeverbout | 0:ea44dc9ed014 | 1947 | |
joeverbout | 0:ea44dc9ed014 | 1948 | inline |
joeverbout | 0:ea44dc9ed014 | 1949 | size_t SparseMat::hash(int i0, int i1) const |
joeverbout | 0:ea44dc9ed014 | 1950 | { |
joeverbout | 0:ea44dc9ed014 | 1951 | return (size_t)(unsigned)i0 * HASH_SCALE + (unsigned)i1; |
joeverbout | 0:ea44dc9ed014 | 1952 | } |
joeverbout | 0:ea44dc9ed014 | 1953 | |
joeverbout | 0:ea44dc9ed014 | 1954 | inline |
joeverbout | 0:ea44dc9ed014 | 1955 | size_t SparseMat::hash(int i0, int i1, int i2) const |
joeverbout | 0:ea44dc9ed014 | 1956 | { |
joeverbout | 0:ea44dc9ed014 | 1957 | return ((size_t)(unsigned)i0 * HASH_SCALE + (unsigned)i1) * HASH_SCALE + (unsigned)i2; |
joeverbout | 0:ea44dc9ed014 | 1958 | } |
joeverbout | 0:ea44dc9ed014 | 1959 | |
joeverbout | 0:ea44dc9ed014 | 1960 | inline |
joeverbout | 0:ea44dc9ed014 | 1961 | size_t SparseMat::hash(const int* idx) const |
joeverbout | 0:ea44dc9ed014 | 1962 | { |
joeverbout | 0:ea44dc9ed014 | 1963 | size_t h = (unsigned)idx[0]; |
joeverbout | 0:ea44dc9ed014 | 1964 | if( !hdr ) |
joeverbout | 0:ea44dc9ed014 | 1965 | return 0; |
joeverbout | 0:ea44dc9ed014 | 1966 | int d = hdr->dims; |
joeverbout | 0:ea44dc9ed014 | 1967 | for(int i = 1; i < d; i++ ) |
joeverbout | 0:ea44dc9ed014 | 1968 | h = h * HASH_SCALE + (unsigned)idx[i]; |
joeverbout | 0:ea44dc9ed014 | 1969 | return h; |
joeverbout | 0:ea44dc9ed014 | 1970 | } |
joeverbout | 0:ea44dc9ed014 | 1971 | |
joeverbout | 0:ea44dc9ed014 | 1972 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1973 | _Tp& SparseMat::ref(int i0, size_t* hashval) |
joeverbout | 0:ea44dc9ed014 | 1974 | { |
joeverbout | 0:ea44dc9ed014 | 1975 | return *(_Tp*)((SparseMat*)this)->ptr(i0, true, hashval); |
joeverbout | 0:ea44dc9ed014 | 1976 | } |
joeverbout | 0:ea44dc9ed014 | 1977 | |
joeverbout | 0:ea44dc9ed014 | 1978 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1979 | _Tp& SparseMat::ref(int i0, int i1, size_t* hashval) |
joeverbout | 0:ea44dc9ed014 | 1980 | { |
joeverbout | 0:ea44dc9ed014 | 1981 | return *(_Tp*)((SparseMat*)this)->ptr(i0, i1, true, hashval); |
joeverbout | 0:ea44dc9ed014 | 1982 | } |
joeverbout | 0:ea44dc9ed014 | 1983 | |
joeverbout | 0:ea44dc9ed014 | 1984 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1985 | _Tp& SparseMat::ref(int i0, int i1, int i2, size_t* hashval) |
joeverbout | 0:ea44dc9ed014 | 1986 | { |
joeverbout | 0:ea44dc9ed014 | 1987 | return *(_Tp*)((SparseMat*)this)->ptr(i0, i1, i2, true, hashval); |
joeverbout | 0:ea44dc9ed014 | 1988 | } |
joeverbout | 0:ea44dc9ed014 | 1989 | |
joeverbout | 0:ea44dc9ed014 | 1990 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1991 | _Tp& SparseMat::ref(const int* idx, size_t* hashval) |
joeverbout | 0:ea44dc9ed014 | 1992 | { |
joeverbout | 0:ea44dc9ed014 | 1993 | return *(_Tp*)((SparseMat*)this)->ptr(idx, true, hashval); |
joeverbout | 0:ea44dc9ed014 | 1994 | } |
joeverbout | 0:ea44dc9ed014 | 1995 | |
joeverbout | 0:ea44dc9ed014 | 1996 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 1997 | _Tp SparseMat::value(int i0, size_t* hashval) const |
joeverbout | 0:ea44dc9ed014 | 1998 | { |
joeverbout | 0:ea44dc9ed014 | 1999 | const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, false, hashval); |
joeverbout | 0:ea44dc9ed014 | 2000 | return p ? *p : _Tp(); |
joeverbout | 0:ea44dc9ed014 | 2001 | } |
joeverbout | 0:ea44dc9ed014 | 2002 | |
joeverbout | 0:ea44dc9ed014 | 2003 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2004 | _Tp SparseMat::value(int i0, int i1, size_t* hashval) const |
joeverbout | 0:ea44dc9ed014 | 2005 | { |
joeverbout | 0:ea44dc9ed014 | 2006 | const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, i1, false, hashval); |
joeverbout | 0:ea44dc9ed014 | 2007 | return p ? *p : _Tp(); |
joeverbout | 0:ea44dc9ed014 | 2008 | } |
joeverbout | 0:ea44dc9ed014 | 2009 | |
joeverbout | 0:ea44dc9ed014 | 2010 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2011 | _Tp SparseMat::value(int i0, int i1, int i2, size_t* hashval) const |
joeverbout | 0:ea44dc9ed014 | 2012 | { |
joeverbout | 0:ea44dc9ed014 | 2013 | const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, i1, i2, false, hashval); |
joeverbout | 0:ea44dc9ed014 | 2014 | return p ? *p : _Tp(); |
joeverbout | 0:ea44dc9ed014 | 2015 | } |
joeverbout | 0:ea44dc9ed014 | 2016 | |
joeverbout | 0:ea44dc9ed014 | 2017 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2018 | _Tp SparseMat::value(const int* idx, size_t* hashval) const |
joeverbout | 0:ea44dc9ed014 | 2019 | { |
joeverbout | 0:ea44dc9ed014 | 2020 | const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(idx, false, hashval); |
joeverbout | 0:ea44dc9ed014 | 2021 | return p ? *p : _Tp(); |
joeverbout | 0:ea44dc9ed014 | 2022 | } |
joeverbout | 0:ea44dc9ed014 | 2023 | |
joeverbout | 0:ea44dc9ed014 | 2024 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2025 | const _Tp* SparseMat::find(int i0, size_t* hashval) const |
joeverbout | 0:ea44dc9ed014 | 2026 | { |
joeverbout | 0:ea44dc9ed014 | 2027 | return (const _Tp*)((SparseMat*)this)->ptr(i0, false, hashval); |
joeverbout | 0:ea44dc9ed014 | 2028 | } |
joeverbout | 0:ea44dc9ed014 | 2029 | |
joeverbout | 0:ea44dc9ed014 | 2030 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2031 | const _Tp* SparseMat::find(int i0, int i1, size_t* hashval) const |
joeverbout | 0:ea44dc9ed014 | 2032 | { |
joeverbout | 0:ea44dc9ed014 | 2033 | return (const _Tp*)((SparseMat*)this)->ptr(i0, i1, false, hashval); |
joeverbout | 0:ea44dc9ed014 | 2034 | } |
joeverbout | 0:ea44dc9ed014 | 2035 | |
joeverbout | 0:ea44dc9ed014 | 2036 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2037 | const _Tp* SparseMat::find(int i0, int i1, int i2, size_t* hashval) const |
joeverbout | 0:ea44dc9ed014 | 2038 | { |
joeverbout | 0:ea44dc9ed014 | 2039 | return (const _Tp*)((SparseMat*)this)->ptr(i0, i1, i2, false, hashval); |
joeverbout | 0:ea44dc9ed014 | 2040 | } |
joeverbout | 0:ea44dc9ed014 | 2041 | |
joeverbout | 0:ea44dc9ed014 | 2042 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2043 | const _Tp* SparseMat::find(const int* idx, size_t* hashval) const |
joeverbout | 0:ea44dc9ed014 | 2044 | { |
joeverbout | 0:ea44dc9ed014 | 2045 | return (const _Tp*)((SparseMat*)this)->ptr(idx, false, hashval); |
joeverbout | 0:ea44dc9ed014 | 2046 | } |
joeverbout | 0:ea44dc9ed014 | 2047 | |
joeverbout | 0:ea44dc9ed014 | 2048 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2049 | _Tp& SparseMat::value(Node* n) |
joeverbout | 0:ea44dc9ed014 | 2050 | { |
joeverbout | 0:ea44dc9ed014 | 2051 | return *(_Tp*)((uchar*)n + hdr->valueOffset); |
joeverbout | 0:ea44dc9ed014 | 2052 | } |
joeverbout | 0:ea44dc9ed014 | 2053 | |
joeverbout | 0:ea44dc9ed014 | 2054 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2055 | const _Tp& SparseMat::value(const Node* n) const |
joeverbout | 0:ea44dc9ed014 | 2056 | { |
joeverbout | 0:ea44dc9ed014 | 2057 | return *(const _Tp*)((const uchar*)n + hdr->valueOffset); |
joeverbout | 0:ea44dc9ed014 | 2058 | } |
joeverbout | 0:ea44dc9ed014 | 2059 | |
joeverbout | 0:ea44dc9ed014 | 2060 | inline |
joeverbout | 0:ea44dc9ed014 | 2061 | SparseMat::Node* SparseMat::node(size_t nidx) |
joeverbout | 0:ea44dc9ed014 | 2062 | { |
joeverbout | 0:ea44dc9ed014 | 2063 | return (Node*)(void*)&hdr->pool[nidx]; |
joeverbout | 0:ea44dc9ed014 | 2064 | } |
joeverbout | 0:ea44dc9ed014 | 2065 | |
joeverbout | 0:ea44dc9ed014 | 2066 | inline |
joeverbout | 0:ea44dc9ed014 | 2067 | const SparseMat::Node* SparseMat::node(size_t nidx) const |
joeverbout | 0:ea44dc9ed014 | 2068 | { |
joeverbout | 0:ea44dc9ed014 | 2069 | return (const Node*)(const void*)&hdr->pool[nidx]; |
joeverbout | 0:ea44dc9ed014 | 2070 | } |
joeverbout | 0:ea44dc9ed014 | 2071 | |
joeverbout | 0:ea44dc9ed014 | 2072 | inline |
joeverbout | 0:ea44dc9ed014 | 2073 | SparseMatIterator SparseMat::begin() |
joeverbout | 0:ea44dc9ed014 | 2074 | { |
joeverbout | 0:ea44dc9ed014 | 2075 | return SparseMatIterator(this); |
joeverbout | 0:ea44dc9ed014 | 2076 | } |
joeverbout | 0:ea44dc9ed014 | 2077 | |
joeverbout | 0:ea44dc9ed014 | 2078 | inline |
joeverbout | 0:ea44dc9ed014 | 2079 | SparseMatConstIterator SparseMat::begin() const |
joeverbout | 0:ea44dc9ed014 | 2080 | { |
joeverbout | 0:ea44dc9ed014 | 2081 | return SparseMatConstIterator(this); |
joeverbout | 0:ea44dc9ed014 | 2082 | } |
joeverbout | 0:ea44dc9ed014 | 2083 | |
joeverbout | 0:ea44dc9ed014 | 2084 | inline |
joeverbout | 0:ea44dc9ed014 | 2085 | SparseMatIterator SparseMat::end() |
joeverbout | 0:ea44dc9ed014 | 2086 | { |
joeverbout | 0:ea44dc9ed014 | 2087 | SparseMatIterator it(this); |
joeverbout | 0:ea44dc9ed014 | 2088 | it.seekEnd(); |
joeverbout | 0:ea44dc9ed014 | 2089 | return it; |
joeverbout | 0:ea44dc9ed014 | 2090 | } |
joeverbout | 0:ea44dc9ed014 | 2091 | |
joeverbout | 0:ea44dc9ed014 | 2092 | inline |
joeverbout | 0:ea44dc9ed014 | 2093 | SparseMatConstIterator SparseMat::end() const |
joeverbout | 0:ea44dc9ed014 | 2094 | { |
joeverbout | 0:ea44dc9ed014 | 2095 | SparseMatConstIterator it(this); |
joeverbout | 0:ea44dc9ed014 | 2096 | it.seekEnd(); |
joeverbout | 0:ea44dc9ed014 | 2097 | return it; |
joeverbout | 0:ea44dc9ed014 | 2098 | } |
joeverbout | 0:ea44dc9ed014 | 2099 | |
joeverbout | 0:ea44dc9ed014 | 2100 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2101 | SparseMatIterator_<_Tp> SparseMat::begin() |
joeverbout | 0:ea44dc9ed014 | 2102 | { |
joeverbout | 0:ea44dc9ed014 | 2103 | return SparseMatIterator_<_Tp>(this); |
joeverbout | 0:ea44dc9ed014 | 2104 | } |
joeverbout | 0:ea44dc9ed014 | 2105 | |
joeverbout | 0:ea44dc9ed014 | 2106 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2107 | SparseMatConstIterator_<_Tp> SparseMat::begin() const |
joeverbout | 0:ea44dc9ed014 | 2108 | { |
joeverbout | 0:ea44dc9ed014 | 2109 | return SparseMatConstIterator_<_Tp>(this); |
joeverbout | 0:ea44dc9ed014 | 2110 | } |
joeverbout | 0:ea44dc9ed014 | 2111 | |
joeverbout | 0:ea44dc9ed014 | 2112 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2113 | SparseMatIterator_<_Tp> SparseMat::end() |
joeverbout | 0:ea44dc9ed014 | 2114 | { |
joeverbout | 0:ea44dc9ed014 | 2115 | SparseMatIterator_<_Tp> it(this); |
joeverbout | 0:ea44dc9ed014 | 2116 | it.seekEnd(); |
joeverbout | 0:ea44dc9ed014 | 2117 | return it; |
joeverbout | 0:ea44dc9ed014 | 2118 | } |
joeverbout | 0:ea44dc9ed014 | 2119 | |
joeverbout | 0:ea44dc9ed014 | 2120 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2121 | SparseMatConstIterator_<_Tp> SparseMat::end() const |
joeverbout | 0:ea44dc9ed014 | 2122 | { |
joeverbout | 0:ea44dc9ed014 | 2123 | SparseMatConstIterator_<_Tp> it(this); |
joeverbout | 0:ea44dc9ed014 | 2124 | it.seekEnd(); |
joeverbout | 0:ea44dc9ed014 | 2125 | return it; |
joeverbout | 0:ea44dc9ed014 | 2126 | } |
joeverbout | 0:ea44dc9ed014 | 2127 | |
joeverbout | 0:ea44dc9ed014 | 2128 | |
joeverbout | 0:ea44dc9ed014 | 2129 | |
joeverbout | 0:ea44dc9ed014 | 2130 | ///////////////////////////// SparseMat_ //////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 2131 | |
joeverbout | 0:ea44dc9ed014 | 2132 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2133 | SparseMat_<_Tp>::SparseMat_() |
joeverbout | 0:ea44dc9ed014 | 2134 | { |
joeverbout | 0:ea44dc9ed014 | 2135 | flags = MAGIC_VAL | DataType<_Tp>::type; |
joeverbout | 0:ea44dc9ed014 | 2136 | } |
joeverbout | 0:ea44dc9ed014 | 2137 | |
joeverbout | 0:ea44dc9ed014 | 2138 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2139 | SparseMat_<_Tp>::SparseMat_(int _dims, const int* _sizes) |
joeverbout | 0:ea44dc9ed014 | 2140 | : SparseMat(_dims, _sizes, DataType<_Tp>::type) |
joeverbout | 0:ea44dc9ed014 | 2141 | {} |
joeverbout | 0:ea44dc9ed014 | 2142 | |
joeverbout | 0:ea44dc9ed014 | 2143 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2144 | SparseMat_<_Tp>::SparseMat_(const SparseMat& m) |
joeverbout | 0:ea44dc9ed014 | 2145 | { |
joeverbout | 0:ea44dc9ed014 | 2146 | if( m.type() == DataType<_Tp>::type ) |
joeverbout | 0:ea44dc9ed014 | 2147 | *this = (const SparseMat_<_Tp>&)m; |
joeverbout | 0:ea44dc9ed014 | 2148 | else |
joeverbout | 0:ea44dc9ed014 | 2149 | m.convertTo(*this, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 2150 | } |
joeverbout | 0:ea44dc9ed014 | 2151 | |
joeverbout | 0:ea44dc9ed014 | 2152 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2153 | SparseMat_<_Tp>::SparseMat_(const SparseMat_<_Tp>& m) |
joeverbout | 0:ea44dc9ed014 | 2154 | { |
joeverbout | 0:ea44dc9ed014 | 2155 | this->flags = m.flags; |
joeverbout | 0:ea44dc9ed014 | 2156 | this->hdr = m.hdr; |
joeverbout | 0:ea44dc9ed014 | 2157 | if( this->hdr ) |
joeverbout | 0:ea44dc9ed014 | 2158 | CV_XADD(&this->hdr->refcount, 1); |
joeverbout | 0:ea44dc9ed014 | 2159 | } |
joeverbout | 0:ea44dc9ed014 | 2160 | |
joeverbout | 0:ea44dc9ed014 | 2161 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2162 | SparseMat_<_Tp>::SparseMat_(const Mat& m) |
joeverbout | 0:ea44dc9ed014 | 2163 | { |
joeverbout | 0:ea44dc9ed014 | 2164 | SparseMat sm(m); |
joeverbout | 0:ea44dc9ed014 | 2165 | *this = sm; |
joeverbout | 0:ea44dc9ed014 | 2166 | } |
joeverbout | 0:ea44dc9ed014 | 2167 | |
joeverbout | 0:ea44dc9ed014 | 2168 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2169 | SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const SparseMat_<_Tp>& m) |
joeverbout | 0:ea44dc9ed014 | 2170 | { |
joeverbout | 0:ea44dc9ed014 | 2171 | if( this != &m ) |
joeverbout | 0:ea44dc9ed014 | 2172 | { |
joeverbout | 0:ea44dc9ed014 | 2173 | if( m.hdr ) CV_XADD(&m.hdr->refcount, 1); |
joeverbout | 0:ea44dc9ed014 | 2174 | release(); |
joeverbout | 0:ea44dc9ed014 | 2175 | flags = m.flags; |
joeverbout | 0:ea44dc9ed014 | 2176 | hdr = m.hdr; |
joeverbout | 0:ea44dc9ed014 | 2177 | } |
joeverbout | 0:ea44dc9ed014 | 2178 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2179 | } |
joeverbout | 0:ea44dc9ed014 | 2180 | |
joeverbout | 0:ea44dc9ed014 | 2181 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2182 | SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const SparseMat& m) |
joeverbout | 0:ea44dc9ed014 | 2183 | { |
joeverbout | 0:ea44dc9ed014 | 2184 | if( m.type() == DataType<_Tp>::type ) |
joeverbout | 0:ea44dc9ed014 | 2185 | return (*this = (const SparseMat_<_Tp>&)m); |
joeverbout | 0:ea44dc9ed014 | 2186 | m.convertTo(*this, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 2187 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2188 | } |
joeverbout | 0:ea44dc9ed014 | 2189 | |
joeverbout | 0:ea44dc9ed014 | 2190 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2191 | SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const Mat& m) |
joeverbout | 0:ea44dc9ed014 | 2192 | { |
joeverbout | 0:ea44dc9ed014 | 2193 | return (*this = SparseMat(m)); |
joeverbout | 0:ea44dc9ed014 | 2194 | } |
joeverbout | 0:ea44dc9ed014 | 2195 | |
joeverbout | 0:ea44dc9ed014 | 2196 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2197 | SparseMat_<_Tp> SparseMat_<_Tp>::clone() const |
joeverbout | 0:ea44dc9ed014 | 2198 | { |
joeverbout | 0:ea44dc9ed014 | 2199 | SparseMat_<_Tp> m; |
joeverbout | 0:ea44dc9ed014 | 2200 | this->copyTo(m); |
joeverbout | 0:ea44dc9ed014 | 2201 | return m; |
joeverbout | 0:ea44dc9ed014 | 2202 | } |
joeverbout | 0:ea44dc9ed014 | 2203 | |
joeverbout | 0:ea44dc9ed014 | 2204 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2205 | void SparseMat_<_Tp>::create(int _dims, const int* _sizes) |
joeverbout | 0:ea44dc9ed014 | 2206 | { |
joeverbout | 0:ea44dc9ed014 | 2207 | SparseMat::create(_dims, _sizes, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 2208 | } |
joeverbout | 0:ea44dc9ed014 | 2209 | |
joeverbout | 0:ea44dc9ed014 | 2210 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2211 | int SparseMat_<_Tp>::type() const |
joeverbout | 0:ea44dc9ed014 | 2212 | { |
joeverbout | 0:ea44dc9ed014 | 2213 | return DataType<_Tp>::type; |
joeverbout | 0:ea44dc9ed014 | 2214 | } |
joeverbout | 0:ea44dc9ed014 | 2215 | |
joeverbout | 0:ea44dc9ed014 | 2216 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2217 | int SparseMat_<_Tp>::depth() const |
joeverbout | 0:ea44dc9ed014 | 2218 | { |
joeverbout | 0:ea44dc9ed014 | 2219 | return DataType<_Tp>::depth; |
joeverbout | 0:ea44dc9ed014 | 2220 | } |
joeverbout | 0:ea44dc9ed014 | 2221 | |
joeverbout | 0:ea44dc9ed014 | 2222 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2223 | int SparseMat_<_Tp>::channels() const |
joeverbout | 0:ea44dc9ed014 | 2224 | { |
joeverbout | 0:ea44dc9ed014 | 2225 | return DataType<_Tp>::channels; |
joeverbout | 0:ea44dc9ed014 | 2226 | } |
joeverbout | 0:ea44dc9ed014 | 2227 | |
joeverbout | 0:ea44dc9ed014 | 2228 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2229 | _Tp& SparseMat_<_Tp>::ref(int i0, size_t* hashval) |
joeverbout | 0:ea44dc9ed014 | 2230 | { |
joeverbout | 0:ea44dc9ed014 | 2231 | return SparseMat::ref<_Tp>(i0, hashval); |
joeverbout | 0:ea44dc9ed014 | 2232 | } |
joeverbout | 0:ea44dc9ed014 | 2233 | |
joeverbout | 0:ea44dc9ed014 | 2234 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2235 | _Tp SparseMat_<_Tp>::operator()(int i0, size_t* hashval) const |
joeverbout | 0:ea44dc9ed014 | 2236 | { |
joeverbout | 0:ea44dc9ed014 | 2237 | return SparseMat::value<_Tp>(i0, hashval); |
joeverbout | 0:ea44dc9ed014 | 2238 | } |
joeverbout | 0:ea44dc9ed014 | 2239 | |
joeverbout | 0:ea44dc9ed014 | 2240 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2241 | _Tp& SparseMat_<_Tp>::ref(int i0, int i1, size_t* hashval) |
joeverbout | 0:ea44dc9ed014 | 2242 | { |
joeverbout | 0:ea44dc9ed014 | 2243 | return SparseMat::ref<_Tp>(i0, i1, hashval); |
joeverbout | 0:ea44dc9ed014 | 2244 | } |
joeverbout | 0:ea44dc9ed014 | 2245 | |
joeverbout | 0:ea44dc9ed014 | 2246 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2247 | _Tp SparseMat_<_Tp>::operator()(int i0, int i1, size_t* hashval) const |
joeverbout | 0:ea44dc9ed014 | 2248 | { |
joeverbout | 0:ea44dc9ed014 | 2249 | return SparseMat::value<_Tp>(i0, i1, hashval); |
joeverbout | 0:ea44dc9ed014 | 2250 | } |
joeverbout | 0:ea44dc9ed014 | 2251 | |
joeverbout | 0:ea44dc9ed014 | 2252 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2253 | _Tp& SparseMat_<_Tp>::ref(int i0, int i1, int i2, size_t* hashval) |
joeverbout | 0:ea44dc9ed014 | 2254 | { |
joeverbout | 0:ea44dc9ed014 | 2255 | return SparseMat::ref<_Tp>(i0, i1, i2, hashval); |
joeverbout | 0:ea44dc9ed014 | 2256 | } |
joeverbout | 0:ea44dc9ed014 | 2257 | |
joeverbout | 0:ea44dc9ed014 | 2258 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2259 | _Tp SparseMat_<_Tp>::operator()(int i0, int i1, int i2, size_t* hashval) const |
joeverbout | 0:ea44dc9ed014 | 2260 | { |
joeverbout | 0:ea44dc9ed014 | 2261 | return SparseMat::value<_Tp>(i0, i1, i2, hashval); |
joeverbout | 0:ea44dc9ed014 | 2262 | } |
joeverbout | 0:ea44dc9ed014 | 2263 | |
joeverbout | 0:ea44dc9ed014 | 2264 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2265 | _Tp& SparseMat_<_Tp>::ref(const int* idx, size_t* hashval) |
joeverbout | 0:ea44dc9ed014 | 2266 | { |
joeverbout | 0:ea44dc9ed014 | 2267 | return SparseMat::ref<_Tp>(idx, hashval); |
joeverbout | 0:ea44dc9ed014 | 2268 | } |
joeverbout | 0:ea44dc9ed014 | 2269 | |
joeverbout | 0:ea44dc9ed014 | 2270 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2271 | _Tp SparseMat_<_Tp>::operator()(const int* idx, size_t* hashval) const |
joeverbout | 0:ea44dc9ed014 | 2272 | { |
joeverbout | 0:ea44dc9ed014 | 2273 | return SparseMat::value<_Tp>(idx, hashval); |
joeverbout | 0:ea44dc9ed014 | 2274 | } |
joeverbout | 0:ea44dc9ed014 | 2275 | |
joeverbout | 0:ea44dc9ed014 | 2276 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2277 | SparseMatIterator_<_Tp> SparseMat_<_Tp>::begin() |
joeverbout | 0:ea44dc9ed014 | 2278 | { |
joeverbout | 0:ea44dc9ed014 | 2279 | return SparseMatIterator_<_Tp>(this); |
joeverbout | 0:ea44dc9ed014 | 2280 | } |
joeverbout | 0:ea44dc9ed014 | 2281 | |
joeverbout | 0:ea44dc9ed014 | 2282 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2283 | SparseMatConstIterator_<_Tp> SparseMat_<_Tp>::begin() const |
joeverbout | 0:ea44dc9ed014 | 2284 | { |
joeverbout | 0:ea44dc9ed014 | 2285 | return SparseMatConstIterator_<_Tp>(this); |
joeverbout | 0:ea44dc9ed014 | 2286 | } |
joeverbout | 0:ea44dc9ed014 | 2287 | |
joeverbout | 0:ea44dc9ed014 | 2288 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2289 | SparseMatIterator_<_Tp> SparseMat_<_Tp>::end() |
joeverbout | 0:ea44dc9ed014 | 2290 | { |
joeverbout | 0:ea44dc9ed014 | 2291 | SparseMatIterator_<_Tp> it(this); |
joeverbout | 0:ea44dc9ed014 | 2292 | it.seekEnd(); |
joeverbout | 0:ea44dc9ed014 | 2293 | return it; |
joeverbout | 0:ea44dc9ed014 | 2294 | } |
joeverbout | 0:ea44dc9ed014 | 2295 | |
joeverbout | 0:ea44dc9ed014 | 2296 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2297 | SparseMatConstIterator_<_Tp> SparseMat_<_Tp>::end() const |
joeverbout | 0:ea44dc9ed014 | 2298 | { |
joeverbout | 0:ea44dc9ed014 | 2299 | SparseMatConstIterator_<_Tp> it(this); |
joeverbout | 0:ea44dc9ed014 | 2300 | it.seekEnd(); |
joeverbout | 0:ea44dc9ed014 | 2301 | return it; |
joeverbout | 0:ea44dc9ed014 | 2302 | } |
joeverbout | 0:ea44dc9ed014 | 2303 | |
joeverbout | 0:ea44dc9ed014 | 2304 | |
joeverbout | 0:ea44dc9ed014 | 2305 | |
joeverbout | 0:ea44dc9ed014 | 2306 | ////////////////////////// MatConstIterator ///////////////////////// |
joeverbout | 0:ea44dc9ed014 | 2307 | |
joeverbout | 0:ea44dc9ed014 | 2308 | inline |
joeverbout | 0:ea44dc9ed014 | 2309 | MatConstIterator::MatConstIterator() |
joeverbout | 0:ea44dc9ed014 | 2310 | : m(0), elemSize(0), ptr(0), sliceStart(0), sliceEnd(0) |
joeverbout | 0:ea44dc9ed014 | 2311 | {} |
joeverbout | 0:ea44dc9ed014 | 2312 | |
joeverbout | 0:ea44dc9ed014 | 2313 | inline |
joeverbout | 0:ea44dc9ed014 | 2314 | MatConstIterator::MatConstIterator(const Mat* _m) |
joeverbout | 0:ea44dc9ed014 | 2315 | : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0) |
joeverbout | 0:ea44dc9ed014 | 2316 | { |
joeverbout | 0:ea44dc9ed014 | 2317 | if( m && m->isContinuous() ) |
joeverbout | 0:ea44dc9ed014 | 2318 | { |
joeverbout | 0:ea44dc9ed014 | 2319 | sliceStart = m->ptr(); |
joeverbout | 0:ea44dc9ed014 | 2320 | sliceEnd = sliceStart + m->total()*elemSize; |
joeverbout | 0:ea44dc9ed014 | 2321 | } |
joeverbout | 0:ea44dc9ed014 | 2322 | seek((const int*)0); |
joeverbout | 0:ea44dc9ed014 | 2323 | } |
joeverbout | 0:ea44dc9ed014 | 2324 | |
joeverbout | 0:ea44dc9ed014 | 2325 | inline |
joeverbout | 0:ea44dc9ed014 | 2326 | MatConstIterator::MatConstIterator(const Mat* _m, int _row, int _col) |
joeverbout | 0:ea44dc9ed014 | 2327 | : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0) |
joeverbout | 0:ea44dc9ed014 | 2328 | { |
joeverbout | 0:ea44dc9ed014 | 2329 | CV_Assert(m && m->dims <= 2); |
joeverbout | 0:ea44dc9ed014 | 2330 | if( m->isContinuous() ) |
joeverbout | 0:ea44dc9ed014 | 2331 | { |
joeverbout | 0:ea44dc9ed014 | 2332 | sliceStart = m->ptr(); |
joeverbout | 0:ea44dc9ed014 | 2333 | sliceEnd = sliceStart + m->total()*elemSize; |
joeverbout | 0:ea44dc9ed014 | 2334 | } |
joeverbout | 0:ea44dc9ed014 | 2335 | int idx[] = {_row, _col}; |
joeverbout | 0:ea44dc9ed014 | 2336 | seek(idx); |
joeverbout | 0:ea44dc9ed014 | 2337 | } |
joeverbout | 0:ea44dc9ed014 | 2338 | |
joeverbout | 0:ea44dc9ed014 | 2339 | inline |
joeverbout | 0:ea44dc9ed014 | 2340 | MatConstIterator::MatConstIterator(const Mat* _m, Point _pt) |
joeverbout | 0:ea44dc9ed014 | 2341 | : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0) |
joeverbout | 0:ea44dc9ed014 | 2342 | { |
joeverbout | 0:ea44dc9ed014 | 2343 | CV_Assert(m && m->dims <= 2); |
joeverbout | 0:ea44dc9ed014 | 2344 | if( m->isContinuous() ) |
joeverbout | 0:ea44dc9ed014 | 2345 | { |
joeverbout | 0:ea44dc9ed014 | 2346 | sliceStart = m->ptr(); |
joeverbout | 0:ea44dc9ed014 | 2347 | sliceEnd = sliceStart + m->total()*elemSize; |
joeverbout | 0:ea44dc9ed014 | 2348 | } |
joeverbout | 0:ea44dc9ed014 | 2349 | int idx[] = {_pt.y, _pt.x}; |
joeverbout | 0:ea44dc9ed014 | 2350 | seek(idx); |
joeverbout | 0:ea44dc9ed014 | 2351 | } |
joeverbout | 0:ea44dc9ed014 | 2352 | |
joeverbout | 0:ea44dc9ed014 | 2353 | inline |
joeverbout | 0:ea44dc9ed014 | 2354 | MatConstIterator::MatConstIterator(const MatConstIterator& it) |
joeverbout | 0:ea44dc9ed014 | 2355 | : m(it.m), elemSize(it.elemSize), ptr(it.ptr), sliceStart(it.sliceStart), sliceEnd(it.sliceEnd) |
joeverbout | 0:ea44dc9ed014 | 2356 | {} |
joeverbout | 0:ea44dc9ed014 | 2357 | |
joeverbout | 0:ea44dc9ed014 | 2358 | inline |
joeverbout | 0:ea44dc9ed014 | 2359 | MatConstIterator& MatConstIterator::operator = (const MatConstIterator& it ) |
joeverbout | 0:ea44dc9ed014 | 2360 | { |
joeverbout | 0:ea44dc9ed014 | 2361 | m = it.m; elemSize = it.elemSize; ptr = it.ptr; |
joeverbout | 0:ea44dc9ed014 | 2362 | sliceStart = it.sliceStart; sliceEnd = it.sliceEnd; |
joeverbout | 0:ea44dc9ed014 | 2363 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2364 | } |
joeverbout | 0:ea44dc9ed014 | 2365 | |
joeverbout | 0:ea44dc9ed014 | 2366 | inline |
joeverbout | 0:ea44dc9ed014 | 2367 | const uchar* MatConstIterator::operator *() const |
joeverbout | 0:ea44dc9ed014 | 2368 | { |
joeverbout | 0:ea44dc9ed014 | 2369 | return ptr; |
joeverbout | 0:ea44dc9ed014 | 2370 | } |
joeverbout | 0:ea44dc9ed014 | 2371 | |
joeverbout | 0:ea44dc9ed014 | 2372 | inline MatConstIterator& MatConstIterator::operator += (ptrdiff_t ofs) |
joeverbout | 0:ea44dc9ed014 | 2373 | { |
joeverbout | 0:ea44dc9ed014 | 2374 | if( !m || ofs == 0 ) |
joeverbout | 0:ea44dc9ed014 | 2375 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2376 | ptrdiff_t ofsb = ofs*elemSize; |
joeverbout | 0:ea44dc9ed014 | 2377 | ptr += ofsb; |
joeverbout | 0:ea44dc9ed014 | 2378 | if( ptr < sliceStart || sliceEnd <= ptr ) |
joeverbout | 0:ea44dc9ed014 | 2379 | { |
joeverbout | 0:ea44dc9ed014 | 2380 | ptr -= ofsb; |
joeverbout | 0:ea44dc9ed014 | 2381 | seek(ofs, true); |
joeverbout | 0:ea44dc9ed014 | 2382 | } |
joeverbout | 0:ea44dc9ed014 | 2383 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2384 | } |
joeverbout | 0:ea44dc9ed014 | 2385 | |
joeverbout | 0:ea44dc9ed014 | 2386 | inline |
joeverbout | 0:ea44dc9ed014 | 2387 | MatConstIterator& MatConstIterator::operator -= (ptrdiff_t ofs) |
joeverbout | 0:ea44dc9ed014 | 2388 | { |
joeverbout | 0:ea44dc9ed014 | 2389 | return (*this += -ofs); |
joeverbout | 0:ea44dc9ed014 | 2390 | } |
joeverbout | 0:ea44dc9ed014 | 2391 | |
joeverbout | 0:ea44dc9ed014 | 2392 | inline |
joeverbout | 0:ea44dc9ed014 | 2393 | MatConstIterator& MatConstIterator::operator --() |
joeverbout | 0:ea44dc9ed014 | 2394 | { |
joeverbout | 0:ea44dc9ed014 | 2395 | if( m && (ptr -= elemSize) < sliceStart ) |
joeverbout | 0:ea44dc9ed014 | 2396 | { |
joeverbout | 0:ea44dc9ed014 | 2397 | ptr += elemSize; |
joeverbout | 0:ea44dc9ed014 | 2398 | seek(-1, true); |
joeverbout | 0:ea44dc9ed014 | 2399 | } |
joeverbout | 0:ea44dc9ed014 | 2400 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2401 | } |
joeverbout | 0:ea44dc9ed014 | 2402 | |
joeverbout | 0:ea44dc9ed014 | 2403 | inline |
joeverbout | 0:ea44dc9ed014 | 2404 | MatConstIterator MatConstIterator::operator --(int) |
joeverbout | 0:ea44dc9ed014 | 2405 | { |
joeverbout | 0:ea44dc9ed014 | 2406 | MatConstIterator b = *this; |
joeverbout | 0:ea44dc9ed014 | 2407 | *this += -1; |
joeverbout | 0:ea44dc9ed014 | 2408 | return b; |
joeverbout | 0:ea44dc9ed014 | 2409 | } |
joeverbout | 0:ea44dc9ed014 | 2410 | |
joeverbout | 0:ea44dc9ed014 | 2411 | inline |
joeverbout | 0:ea44dc9ed014 | 2412 | MatConstIterator& MatConstIterator::operator ++() |
joeverbout | 0:ea44dc9ed014 | 2413 | { |
joeverbout | 0:ea44dc9ed014 | 2414 | if( m && (ptr += elemSize) >= sliceEnd ) |
joeverbout | 0:ea44dc9ed014 | 2415 | { |
joeverbout | 0:ea44dc9ed014 | 2416 | ptr -= elemSize; |
joeverbout | 0:ea44dc9ed014 | 2417 | seek(1, true); |
joeverbout | 0:ea44dc9ed014 | 2418 | } |
joeverbout | 0:ea44dc9ed014 | 2419 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2420 | } |
joeverbout | 0:ea44dc9ed014 | 2421 | |
joeverbout | 0:ea44dc9ed014 | 2422 | inline MatConstIterator MatConstIterator::operator ++(int) |
joeverbout | 0:ea44dc9ed014 | 2423 | { |
joeverbout | 0:ea44dc9ed014 | 2424 | MatConstIterator b = *this; |
joeverbout | 0:ea44dc9ed014 | 2425 | *this += 1; |
joeverbout | 0:ea44dc9ed014 | 2426 | return b; |
joeverbout | 0:ea44dc9ed014 | 2427 | } |
joeverbout | 0:ea44dc9ed014 | 2428 | |
joeverbout | 0:ea44dc9ed014 | 2429 | |
joeverbout | 0:ea44dc9ed014 | 2430 | static inline |
joeverbout | 0:ea44dc9ed014 | 2431 | bool operator == (const MatConstIterator& a, const MatConstIterator& b) |
joeverbout | 0:ea44dc9ed014 | 2432 | { |
joeverbout | 0:ea44dc9ed014 | 2433 | return a.m == b.m && a.ptr == b.ptr; |
joeverbout | 0:ea44dc9ed014 | 2434 | } |
joeverbout | 0:ea44dc9ed014 | 2435 | |
joeverbout | 0:ea44dc9ed014 | 2436 | static inline |
joeverbout | 0:ea44dc9ed014 | 2437 | bool operator != (const MatConstIterator& a, const MatConstIterator& b) |
joeverbout | 0:ea44dc9ed014 | 2438 | { |
joeverbout | 0:ea44dc9ed014 | 2439 | return !(a == b); |
joeverbout | 0:ea44dc9ed014 | 2440 | } |
joeverbout | 0:ea44dc9ed014 | 2441 | |
joeverbout | 0:ea44dc9ed014 | 2442 | static inline |
joeverbout | 0:ea44dc9ed014 | 2443 | bool operator < (const MatConstIterator& a, const MatConstIterator& b) |
joeverbout | 0:ea44dc9ed014 | 2444 | { |
joeverbout | 0:ea44dc9ed014 | 2445 | return a.ptr < b.ptr; |
joeverbout | 0:ea44dc9ed014 | 2446 | } |
joeverbout | 0:ea44dc9ed014 | 2447 | |
joeverbout | 0:ea44dc9ed014 | 2448 | static inline |
joeverbout | 0:ea44dc9ed014 | 2449 | bool operator > (const MatConstIterator& a, const MatConstIterator& b) |
joeverbout | 0:ea44dc9ed014 | 2450 | { |
joeverbout | 0:ea44dc9ed014 | 2451 | return a.ptr > b.ptr; |
joeverbout | 0:ea44dc9ed014 | 2452 | } |
joeverbout | 0:ea44dc9ed014 | 2453 | |
joeverbout | 0:ea44dc9ed014 | 2454 | static inline |
joeverbout | 0:ea44dc9ed014 | 2455 | bool operator <= (const MatConstIterator& a, const MatConstIterator& b) |
joeverbout | 0:ea44dc9ed014 | 2456 | { |
joeverbout | 0:ea44dc9ed014 | 2457 | return a.ptr <= b.ptr; |
joeverbout | 0:ea44dc9ed014 | 2458 | } |
joeverbout | 0:ea44dc9ed014 | 2459 | |
joeverbout | 0:ea44dc9ed014 | 2460 | static inline |
joeverbout | 0:ea44dc9ed014 | 2461 | bool operator >= (const MatConstIterator& a, const MatConstIterator& b) |
joeverbout | 0:ea44dc9ed014 | 2462 | { |
joeverbout | 0:ea44dc9ed014 | 2463 | return a.ptr >= b.ptr; |
joeverbout | 0:ea44dc9ed014 | 2464 | } |
joeverbout | 0:ea44dc9ed014 | 2465 | |
joeverbout | 0:ea44dc9ed014 | 2466 | static inline |
joeverbout | 0:ea44dc9ed014 | 2467 | ptrdiff_t operator - (const MatConstIterator& b, const MatConstIterator& a) |
joeverbout | 0:ea44dc9ed014 | 2468 | { |
joeverbout | 0:ea44dc9ed014 | 2469 | if( a.m != b.m ) |
joeverbout | 0:ea44dc9ed014 | 2470 | return ((size_t)(-1) >> 1); |
joeverbout | 0:ea44dc9ed014 | 2471 | if( a.sliceEnd == b.sliceEnd ) |
joeverbout | 0:ea44dc9ed014 | 2472 | return (b.ptr - a.ptr)/b.elemSize; |
joeverbout | 0:ea44dc9ed014 | 2473 | |
joeverbout | 0:ea44dc9ed014 | 2474 | return b.lpos() - a.lpos(); |
joeverbout | 0:ea44dc9ed014 | 2475 | } |
joeverbout | 0:ea44dc9ed014 | 2476 | |
joeverbout | 0:ea44dc9ed014 | 2477 | static inline |
joeverbout | 0:ea44dc9ed014 | 2478 | MatConstIterator operator + (const MatConstIterator& a, ptrdiff_t ofs) |
joeverbout | 0:ea44dc9ed014 | 2479 | { |
joeverbout | 0:ea44dc9ed014 | 2480 | MatConstIterator b = a; |
joeverbout | 0:ea44dc9ed014 | 2481 | return b += ofs; |
joeverbout | 0:ea44dc9ed014 | 2482 | } |
joeverbout | 0:ea44dc9ed014 | 2483 | |
joeverbout | 0:ea44dc9ed014 | 2484 | static inline |
joeverbout | 0:ea44dc9ed014 | 2485 | MatConstIterator operator + (ptrdiff_t ofs, const MatConstIterator& a) |
joeverbout | 0:ea44dc9ed014 | 2486 | { |
joeverbout | 0:ea44dc9ed014 | 2487 | MatConstIterator b = a; |
joeverbout | 0:ea44dc9ed014 | 2488 | return b += ofs; |
joeverbout | 0:ea44dc9ed014 | 2489 | } |
joeverbout | 0:ea44dc9ed014 | 2490 | |
joeverbout | 0:ea44dc9ed014 | 2491 | static inline |
joeverbout | 0:ea44dc9ed014 | 2492 | MatConstIterator operator - (const MatConstIterator& a, ptrdiff_t ofs) |
joeverbout | 0:ea44dc9ed014 | 2493 | { |
joeverbout | 0:ea44dc9ed014 | 2494 | MatConstIterator b = a; |
joeverbout | 0:ea44dc9ed014 | 2495 | return b += -ofs; |
joeverbout | 0:ea44dc9ed014 | 2496 | } |
joeverbout | 0:ea44dc9ed014 | 2497 | |
joeverbout | 0:ea44dc9ed014 | 2498 | |
joeverbout | 0:ea44dc9ed014 | 2499 | inline |
joeverbout | 0:ea44dc9ed014 | 2500 | const uchar* MatConstIterator::operator [](ptrdiff_t i) const |
joeverbout | 0:ea44dc9ed014 | 2501 | { |
joeverbout | 0:ea44dc9ed014 | 2502 | return *(*this + i); |
joeverbout | 0:ea44dc9ed014 | 2503 | } |
joeverbout | 0:ea44dc9ed014 | 2504 | |
joeverbout | 0:ea44dc9ed014 | 2505 | |
joeverbout | 0:ea44dc9ed014 | 2506 | |
joeverbout | 0:ea44dc9ed014 | 2507 | ///////////////////////// MatConstIterator_ ///////////////////////// |
joeverbout | 0:ea44dc9ed014 | 2508 | |
joeverbout | 0:ea44dc9ed014 | 2509 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2510 | MatConstIterator_<_Tp>::MatConstIterator_() |
joeverbout | 0:ea44dc9ed014 | 2511 | {} |
joeverbout | 0:ea44dc9ed014 | 2512 | |
joeverbout | 0:ea44dc9ed014 | 2513 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2514 | MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m) |
joeverbout | 0:ea44dc9ed014 | 2515 | : MatConstIterator(_m) |
joeverbout | 0:ea44dc9ed014 | 2516 | {} |
joeverbout | 0:ea44dc9ed014 | 2517 | |
joeverbout | 0:ea44dc9ed014 | 2518 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2519 | MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col) |
joeverbout | 0:ea44dc9ed014 | 2520 | : MatConstIterator(_m, _row, _col) |
joeverbout | 0:ea44dc9ed014 | 2521 | {} |
joeverbout | 0:ea44dc9ed014 | 2522 | |
joeverbout | 0:ea44dc9ed014 | 2523 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2524 | MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m, Point _pt) |
joeverbout | 0:ea44dc9ed014 | 2525 | : MatConstIterator(_m, _pt) |
joeverbout | 0:ea44dc9ed014 | 2526 | {} |
joeverbout | 0:ea44dc9ed014 | 2527 | |
joeverbout | 0:ea44dc9ed014 | 2528 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2529 | MatConstIterator_<_Tp>::MatConstIterator_(const MatConstIterator_& it) |
joeverbout | 0:ea44dc9ed014 | 2530 | : MatConstIterator(it) |
joeverbout | 0:ea44dc9ed014 | 2531 | {} |
joeverbout | 0:ea44dc9ed014 | 2532 | |
joeverbout | 0:ea44dc9ed014 | 2533 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2534 | MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator = (const MatConstIterator_& it ) |
joeverbout | 0:ea44dc9ed014 | 2535 | { |
joeverbout | 0:ea44dc9ed014 | 2536 | MatConstIterator::operator = (it); |
joeverbout | 0:ea44dc9ed014 | 2537 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2538 | } |
joeverbout | 0:ea44dc9ed014 | 2539 | |
joeverbout | 0:ea44dc9ed014 | 2540 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2541 | _Tp MatConstIterator_<_Tp>::operator *() const |
joeverbout | 0:ea44dc9ed014 | 2542 | { |
joeverbout | 0:ea44dc9ed014 | 2543 | return *(_Tp*)(this->ptr); |
joeverbout | 0:ea44dc9ed014 | 2544 | } |
joeverbout | 0:ea44dc9ed014 | 2545 | |
joeverbout | 0:ea44dc9ed014 | 2546 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2547 | MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator += (ptrdiff_t ofs) |
joeverbout | 0:ea44dc9ed014 | 2548 | { |
joeverbout | 0:ea44dc9ed014 | 2549 | MatConstIterator::operator += (ofs); |
joeverbout | 0:ea44dc9ed014 | 2550 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2551 | } |
joeverbout | 0:ea44dc9ed014 | 2552 | |
joeverbout | 0:ea44dc9ed014 | 2553 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2554 | MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator -= (ptrdiff_t ofs) |
joeverbout | 0:ea44dc9ed014 | 2555 | { |
joeverbout | 0:ea44dc9ed014 | 2556 | return (*this += -ofs); |
joeverbout | 0:ea44dc9ed014 | 2557 | } |
joeverbout | 0:ea44dc9ed014 | 2558 | |
joeverbout | 0:ea44dc9ed014 | 2559 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2560 | MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator --() |
joeverbout | 0:ea44dc9ed014 | 2561 | { |
joeverbout | 0:ea44dc9ed014 | 2562 | MatConstIterator::operator --(); |
joeverbout | 0:ea44dc9ed014 | 2563 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2564 | } |
joeverbout | 0:ea44dc9ed014 | 2565 | |
joeverbout | 0:ea44dc9ed014 | 2566 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2567 | MatConstIterator_<_Tp> MatConstIterator_<_Tp>::operator --(int) |
joeverbout | 0:ea44dc9ed014 | 2568 | { |
joeverbout | 0:ea44dc9ed014 | 2569 | MatConstIterator_ b = *this; |
joeverbout | 0:ea44dc9ed014 | 2570 | MatConstIterator::operator --(); |
joeverbout | 0:ea44dc9ed014 | 2571 | return b; |
joeverbout | 0:ea44dc9ed014 | 2572 | } |
joeverbout | 0:ea44dc9ed014 | 2573 | |
joeverbout | 0:ea44dc9ed014 | 2574 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2575 | MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator ++() |
joeverbout | 0:ea44dc9ed014 | 2576 | { |
joeverbout | 0:ea44dc9ed014 | 2577 | MatConstIterator::operator ++(); |
joeverbout | 0:ea44dc9ed014 | 2578 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2579 | } |
joeverbout | 0:ea44dc9ed014 | 2580 | |
joeverbout | 0:ea44dc9ed014 | 2581 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2582 | MatConstIterator_<_Tp> MatConstIterator_<_Tp>::operator ++(int) |
joeverbout | 0:ea44dc9ed014 | 2583 | { |
joeverbout | 0:ea44dc9ed014 | 2584 | MatConstIterator_ b = *this; |
joeverbout | 0:ea44dc9ed014 | 2585 | MatConstIterator::operator ++(); |
joeverbout | 0:ea44dc9ed014 | 2586 | return b; |
joeverbout | 0:ea44dc9ed014 | 2587 | } |
joeverbout | 0:ea44dc9ed014 | 2588 | |
joeverbout | 0:ea44dc9ed014 | 2589 | |
joeverbout | 0:ea44dc9ed014 | 2590 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2591 | Point MatConstIterator_<_Tp>::pos() const |
joeverbout | 0:ea44dc9ed014 | 2592 | { |
joeverbout | 0:ea44dc9ed014 | 2593 | if( !m ) |
joeverbout | 0:ea44dc9ed014 | 2594 | return Point(); |
joeverbout | 0:ea44dc9ed014 | 2595 | CV_DbgAssert( m->dims <= 2 ); |
joeverbout | 0:ea44dc9ed014 | 2596 | if( m->isContinuous() ) |
joeverbout | 0:ea44dc9ed014 | 2597 | { |
joeverbout | 0:ea44dc9ed014 | 2598 | ptrdiff_t ofs = (const _Tp*)ptr - (const _Tp*)m->data; |
joeverbout | 0:ea44dc9ed014 | 2599 | int y = (int)(ofs / m->cols); |
joeverbout | 0:ea44dc9ed014 | 2600 | int x = (int)(ofs - (ptrdiff_t)y * m->cols); |
joeverbout | 0:ea44dc9ed014 | 2601 | return Point(x, y); |
joeverbout | 0:ea44dc9ed014 | 2602 | } |
joeverbout | 0:ea44dc9ed014 | 2603 | else |
joeverbout | 0:ea44dc9ed014 | 2604 | { |
joeverbout | 0:ea44dc9ed014 | 2605 | ptrdiff_t ofs = (uchar*)ptr - m->data; |
joeverbout | 0:ea44dc9ed014 | 2606 | int y = (int)(ofs / m->step); |
joeverbout | 0:ea44dc9ed014 | 2607 | int x = (int)((ofs - y * m->step)/sizeof(_Tp)); |
joeverbout | 0:ea44dc9ed014 | 2608 | return Point(x, y); |
joeverbout | 0:ea44dc9ed014 | 2609 | } |
joeverbout | 0:ea44dc9ed014 | 2610 | } |
joeverbout | 0:ea44dc9ed014 | 2611 | |
joeverbout | 0:ea44dc9ed014 | 2612 | |
joeverbout | 0:ea44dc9ed014 | 2613 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 2614 | bool operator == (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b) |
joeverbout | 0:ea44dc9ed014 | 2615 | { |
joeverbout | 0:ea44dc9ed014 | 2616 | return a.m == b.m && a.ptr == b.ptr; |
joeverbout | 0:ea44dc9ed014 | 2617 | } |
joeverbout | 0:ea44dc9ed014 | 2618 | |
joeverbout | 0:ea44dc9ed014 | 2619 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 2620 | bool operator != (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b) |
joeverbout | 0:ea44dc9ed014 | 2621 | { |
joeverbout | 0:ea44dc9ed014 | 2622 | return a.m != b.m || a.ptr != b.ptr; |
joeverbout | 0:ea44dc9ed014 | 2623 | } |
joeverbout | 0:ea44dc9ed014 | 2624 | |
joeverbout | 0:ea44dc9ed014 | 2625 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 2626 | MatConstIterator_<_Tp> operator + (const MatConstIterator_<_Tp>& a, ptrdiff_t ofs) |
joeverbout | 0:ea44dc9ed014 | 2627 | { |
joeverbout | 0:ea44dc9ed014 | 2628 | MatConstIterator t = (const MatConstIterator&)a + ofs; |
joeverbout | 0:ea44dc9ed014 | 2629 | return (MatConstIterator_<_Tp>&)t; |
joeverbout | 0:ea44dc9ed014 | 2630 | } |
joeverbout | 0:ea44dc9ed014 | 2631 | |
joeverbout | 0:ea44dc9ed014 | 2632 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 2633 | MatConstIterator_<_Tp> operator + (ptrdiff_t ofs, const MatConstIterator_<_Tp>& a) |
joeverbout | 0:ea44dc9ed014 | 2634 | { |
joeverbout | 0:ea44dc9ed014 | 2635 | MatConstIterator t = (const MatConstIterator&)a + ofs; |
joeverbout | 0:ea44dc9ed014 | 2636 | return (MatConstIterator_<_Tp>&)t; |
joeverbout | 0:ea44dc9ed014 | 2637 | } |
joeverbout | 0:ea44dc9ed014 | 2638 | |
joeverbout | 0:ea44dc9ed014 | 2639 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 2640 | MatConstIterator_<_Tp> operator - (const MatConstIterator_<_Tp>& a, ptrdiff_t ofs) |
joeverbout | 0:ea44dc9ed014 | 2641 | { |
joeverbout | 0:ea44dc9ed014 | 2642 | MatConstIterator t = (const MatConstIterator&)a - ofs; |
joeverbout | 0:ea44dc9ed014 | 2643 | return (MatConstIterator_<_Tp>&)t; |
joeverbout | 0:ea44dc9ed014 | 2644 | } |
joeverbout | 0:ea44dc9ed014 | 2645 | |
joeverbout | 0:ea44dc9ed014 | 2646 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2647 | _Tp MatConstIterator_<_Tp>::operator [](ptrdiff_t i) const |
joeverbout | 0:ea44dc9ed014 | 2648 | { |
joeverbout | 0:ea44dc9ed014 | 2649 | return *(_Tp*)MatConstIterator::operator [](i); |
joeverbout | 0:ea44dc9ed014 | 2650 | } |
joeverbout | 0:ea44dc9ed014 | 2651 | |
joeverbout | 0:ea44dc9ed014 | 2652 | |
joeverbout | 0:ea44dc9ed014 | 2653 | |
joeverbout | 0:ea44dc9ed014 | 2654 | //////////////////////////// MatIterator_ /////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 2655 | |
joeverbout | 0:ea44dc9ed014 | 2656 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2657 | MatIterator_<_Tp>::MatIterator_() |
joeverbout | 0:ea44dc9ed014 | 2658 | : MatConstIterator_<_Tp>() |
joeverbout | 0:ea44dc9ed014 | 2659 | {} |
joeverbout | 0:ea44dc9ed014 | 2660 | |
joeverbout | 0:ea44dc9ed014 | 2661 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2662 | MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m) |
joeverbout | 0:ea44dc9ed014 | 2663 | : MatConstIterator_<_Tp>(_m) |
joeverbout | 0:ea44dc9ed014 | 2664 | {} |
joeverbout | 0:ea44dc9ed014 | 2665 | |
joeverbout | 0:ea44dc9ed014 | 2666 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2667 | MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, int _row, int _col) |
joeverbout | 0:ea44dc9ed014 | 2668 | : MatConstIterator_<_Tp>(_m, _row, _col) |
joeverbout | 0:ea44dc9ed014 | 2669 | {} |
joeverbout | 0:ea44dc9ed014 | 2670 | |
joeverbout | 0:ea44dc9ed014 | 2671 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2672 | MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, Point _pt) |
joeverbout | 0:ea44dc9ed014 | 2673 | : MatConstIterator_<_Tp>(_m, _pt) |
joeverbout | 0:ea44dc9ed014 | 2674 | {} |
joeverbout | 0:ea44dc9ed014 | 2675 | |
joeverbout | 0:ea44dc9ed014 | 2676 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2677 | MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, const int* _idx) |
joeverbout | 0:ea44dc9ed014 | 2678 | : MatConstIterator_<_Tp>(_m, _idx) |
joeverbout | 0:ea44dc9ed014 | 2679 | {} |
joeverbout | 0:ea44dc9ed014 | 2680 | |
joeverbout | 0:ea44dc9ed014 | 2681 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2682 | MatIterator_<_Tp>::MatIterator_(const MatIterator_& it) |
joeverbout | 0:ea44dc9ed014 | 2683 | : MatConstIterator_<_Tp>(it) |
joeverbout | 0:ea44dc9ed014 | 2684 | {} |
joeverbout | 0:ea44dc9ed014 | 2685 | |
joeverbout | 0:ea44dc9ed014 | 2686 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2687 | MatIterator_<_Tp>& MatIterator_<_Tp>::operator = (const MatIterator_<_Tp>& it ) |
joeverbout | 0:ea44dc9ed014 | 2688 | { |
joeverbout | 0:ea44dc9ed014 | 2689 | MatConstIterator::operator = (it); |
joeverbout | 0:ea44dc9ed014 | 2690 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2691 | } |
joeverbout | 0:ea44dc9ed014 | 2692 | |
joeverbout | 0:ea44dc9ed014 | 2693 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2694 | _Tp& MatIterator_<_Tp>::operator *() const |
joeverbout | 0:ea44dc9ed014 | 2695 | { |
joeverbout | 0:ea44dc9ed014 | 2696 | return *(_Tp*)(this->ptr); |
joeverbout | 0:ea44dc9ed014 | 2697 | } |
joeverbout | 0:ea44dc9ed014 | 2698 | |
joeverbout | 0:ea44dc9ed014 | 2699 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2700 | MatIterator_<_Tp>& MatIterator_<_Tp>::operator += (ptrdiff_t ofs) |
joeverbout | 0:ea44dc9ed014 | 2701 | { |
joeverbout | 0:ea44dc9ed014 | 2702 | MatConstIterator::operator += (ofs); |
joeverbout | 0:ea44dc9ed014 | 2703 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2704 | } |
joeverbout | 0:ea44dc9ed014 | 2705 | |
joeverbout | 0:ea44dc9ed014 | 2706 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2707 | MatIterator_<_Tp>& MatIterator_<_Tp>::operator -= (ptrdiff_t ofs) |
joeverbout | 0:ea44dc9ed014 | 2708 | { |
joeverbout | 0:ea44dc9ed014 | 2709 | MatConstIterator::operator += (-ofs); |
joeverbout | 0:ea44dc9ed014 | 2710 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2711 | } |
joeverbout | 0:ea44dc9ed014 | 2712 | |
joeverbout | 0:ea44dc9ed014 | 2713 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2714 | MatIterator_<_Tp>& MatIterator_<_Tp>::operator --() |
joeverbout | 0:ea44dc9ed014 | 2715 | { |
joeverbout | 0:ea44dc9ed014 | 2716 | MatConstIterator::operator --(); |
joeverbout | 0:ea44dc9ed014 | 2717 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2718 | } |
joeverbout | 0:ea44dc9ed014 | 2719 | |
joeverbout | 0:ea44dc9ed014 | 2720 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2721 | MatIterator_<_Tp> MatIterator_<_Tp>::operator --(int) |
joeverbout | 0:ea44dc9ed014 | 2722 | { |
joeverbout | 0:ea44dc9ed014 | 2723 | MatIterator_ b = *this; |
joeverbout | 0:ea44dc9ed014 | 2724 | MatConstIterator::operator --(); |
joeverbout | 0:ea44dc9ed014 | 2725 | return b; |
joeverbout | 0:ea44dc9ed014 | 2726 | } |
joeverbout | 0:ea44dc9ed014 | 2727 | |
joeverbout | 0:ea44dc9ed014 | 2728 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2729 | MatIterator_<_Tp>& MatIterator_<_Tp>::operator ++() |
joeverbout | 0:ea44dc9ed014 | 2730 | { |
joeverbout | 0:ea44dc9ed014 | 2731 | MatConstIterator::operator ++(); |
joeverbout | 0:ea44dc9ed014 | 2732 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2733 | } |
joeverbout | 0:ea44dc9ed014 | 2734 | |
joeverbout | 0:ea44dc9ed014 | 2735 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2736 | MatIterator_<_Tp> MatIterator_<_Tp>::operator ++(int) |
joeverbout | 0:ea44dc9ed014 | 2737 | { |
joeverbout | 0:ea44dc9ed014 | 2738 | MatIterator_ b = *this; |
joeverbout | 0:ea44dc9ed014 | 2739 | MatConstIterator::operator ++(); |
joeverbout | 0:ea44dc9ed014 | 2740 | return b; |
joeverbout | 0:ea44dc9ed014 | 2741 | } |
joeverbout | 0:ea44dc9ed014 | 2742 | |
joeverbout | 0:ea44dc9ed014 | 2743 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2744 | _Tp& MatIterator_<_Tp>::operator [](ptrdiff_t i) const |
joeverbout | 0:ea44dc9ed014 | 2745 | { |
joeverbout | 0:ea44dc9ed014 | 2746 | return *(*this + i); |
joeverbout | 0:ea44dc9ed014 | 2747 | } |
joeverbout | 0:ea44dc9ed014 | 2748 | |
joeverbout | 0:ea44dc9ed014 | 2749 | |
joeverbout | 0:ea44dc9ed014 | 2750 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 2751 | bool operator == (const MatIterator_<_Tp>& a, const MatIterator_<_Tp>& b) |
joeverbout | 0:ea44dc9ed014 | 2752 | { |
joeverbout | 0:ea44dc9ed014 | 2753 | return a.m == b.m && a.ptr == b.ptr; |
joeverbout | 0:ea44dc9ed014 | 2754 | } |
joeverbout | 0:ea44dc9ed014 | 2755 | |
joeverbout | 0:ea44dc9ed014 | 2756 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 2757 | bool operator != (const MatIterator_<_Tp>& a, const MatIterator_<_Tp>& b) |
joeverbout | 0:ea44dc9ed014 | 2758 | { |
joeverbout | 0:ea44dc9ed014 | 2759 | return a.m != b.m || a.ptr != b.ptr; |
joeverbout | 0:ea44dc9ed014 | 2760 | } |
joeverbout | 0:ea44dc9ed014 | 2761 | |
joeverbout | 0:ea44dc9ed014 | 2762 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 2763 | MatIterator_<_Tp> operator + (const MatIterator_<_Tp>& a, ptrdiff_t ofs) |
joeverbout | 0:ea44dc9ed014 | 2764 | { |
joeverbout | 0:ea44dc9ed014 | 2765 | MatConstIterator t = (const MatConstIterator&)a + ofs; |
joeverbout | 0:ea44dc9ed014 | 2766 | return (MatIterator_<_Tp>&)t; |
joeverbout | 0:ea44dc9ed014 | 2767 | } |
joeverbout | 0:ea44dc9ed014 | 2768 | |
joeverbout | 0:ea44dc9ed014 | 2769 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 2770 | MatIterator_<_Tp> operator + (ptrdiff_t ofs, const MatIterator_<_Tp>& a) |
joeverbout | 0:ea44dc9ed014 | 2771 | { |
joeverbout | 0:ea44dc9ed014 | 2772 | MatConstIterator t = (const MatConstIterator&)a + ofs; |
joeverbout | 0:ea44dc9ed014 | 2773 | return (MatIterator_<_Tp>&)t; |
joeverbout | 0:ea44dc9ed014 | 2774 | } |
joeverbout | 0:ea44dc9ed014 | 2775 | |
joeverbout | 0:ea44dc9ed014 | 2776 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 2777 | MatIterator_<_Tp> operator - (const MatIterator_<_Tp>& a, ptrdiff_t ofs) |
joeverbout | 0:ea44dc9ed014 | 2778 | { |
joeverbout | 0:ea44dc9ed014 | 2779 | MatConstIterator t = (const MatConstIterator&)a - ofs; |
joeverbout | 0:ea44dc9ed014 | 2780 | return (MatIterator_<_Tp>&)t; |
joeverbout | 0:ea44dc9ed014 | 2781 | } |
joeverbout | 0:ea44dc9ed014 | 2782 | |
joeverbout | 0:ea44dc9ed014 | 2783 | |
joeverbout | 0:ea44dc9ed014 | 2784 | |
joeverbout | 0:ea44dc9ed014 | 2785 | /////////////////////// SparseMatConstIterator ////////////////////// |
joeverbout | 0:ea44dc9ed014 | 2786 | |
joeverbout | 0:ea44dc9ed014 | 2787 | inline |
joeverbout | 0:ea44dc9ed014 | 2788 | SparseMatConstIterator::SparseMatConstIterator() |
joeverbout | 0:ea44dc9ed014 | 2789 | : m(0), hashidx(0), ptr(0) |
joeverbout | 0:ea44dc9ed014 | 2790 | {} |
joeverbout | 0:ea44dc9ed014 | 2791 | |
joeverbout | 0:ea44dc9ed014 | 2792 | inline |
joeverbout | 0:ea44dc9ed014 | 2793 | SparseMatConstIterator::SparseMatConstIterator(const SparseMatConstIterator& it) |
joeverbout | 0:ea44dc9ed014 | 2794 | : m(it.m), hashidx(it.hashidx), ptr(it.ptr) |
joeverbout | 0:ea44dc9ed014 | 2795 | {} |
joeverbout | 0:ea44dc9ed014 | 2796 | |
joeverbout | 0:ea44dc9ed014 | 2797 | inline SparseMatConstIterator& SparseMatConstIterator::operator = (const SparseMatConstIterator& it) |
joeverbout | 0:ea44dc9ed014 | 2798 | { |
joeverbout | 0:ea44dc9ed014 | 2799 | if( this != &it ) |
joeverbout | 0:ea44dc9ed014 | 2800 | { |
joeverbout | 0:ea44dc9ed014 | 2801 | m = it.m; |
joeverbout | 0:ea44dc9ed014 | 2802 | hashidx = it.hashidx; |
joeverbout | 0:ea44dc9ed014 | 2803 | ptr = it.ptr; |
joeverbout | 0:ea44dc9ed014 | 2804 | } |
joeverbout | 0:ea44dc9ed014 | 2805 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2806 | } |
joeverbout | 0:ea44dc9ed014 | 2807 | |
joeverbout | 0:ea44dc9ed014 | 2808 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2809 | const _Tp& SparseMatConstIterator::value() const |
joeverbout | 0:ea44dc9ed014 | 2810 | { |
joeverbout | 0:ea44dc9ed014 | 2811 | return *(const _Tp*)ptr; |
joeverbout | 0:ea44dc9ed014 | 2812 | } |
joeverbout | 0:ea44dc9ed014 | 2813 | |
joeverbout | 0:ea44dc9ed014 | 2814 | inline |
joeverbout | 0:ea44dc9ed014 | 2815 | const SparseMat::Node* SparseMatConstIterator::node() const |
joeverbout | 0:ea44dc9ed014 | 2816 | { |
joeverbout | 0:ea44dc9ed014 | 2817 | return (ptr && m && m->hdr) ? (const SparseMat::Node*)(const void*)(ptr - m->hdr->valueOffset) : 0; |
joeverbout | 0:ea44dc9ed014 | 2818 | } |
joeverbout | 0:ea44dc9ed014 | 2819 | |
joeverbout | 0:ea44dc9ed014 | 2820 | inline |
joeverbout | 0:ea44dc9ed014 | 2821 | SparseMatConstIterator SparseMatConstIterator::operator ++(int) |
joeverbout | 0:ea44dc9ed014 | 2822 | { |
joeverbout | 0:ea44dc9ed014 | 2823 | SparseMatConstIterator it = *this; |
joeverbout | 0:ea44dc9ed014 | 2824 | ++*this; |
joeverbout | 0:ea44dc9ed014 | 2825 | return it; |
joeverbout | 0:ea44dc9ed014 | 2826 | } |
joeverbout | 0:ea44dc9ed014 | 2827 | |
joeverbout | 0:ea44dc9ed014 | 2828 | inline |
joeverbout | 0:ea44dc9ed014 | 2829 | void SparseMatConstIterator::seekEnd() |
joeverbout | 0:ea44dc9ed014 | 2830 | { |
joeverbout | 0:ea44dc9ed014 | 2831 | if( m && m->hdr ) |
joeverbout | 0:ea44dc9ed014 | 2832 | { |
joeverbout | 0:ea44dc9ed014 | 2833 | hashidx = m->hdr->hashtab.size(); |
joeverbout | 0:ea44dc9ed014 | 2834 | ptr = 0; |
joeverbout | 0:ea44dc9ed014 | 2835 | } |
joeverbout | 0:ea44dc9ed014 | 2836 | } |
joeverbout | 0:ea44dc9ed014 | 2837 | |
joeverbout | 0:ea44dc9ed014 | 2838 | |
joeverbout | 0:ea44dc9ed014 | 2839 | static inline |
joeverbout | 0:ea44dc9ed014 | 2840 | bool operator == (const SparseMatConstIterator& it1, const SparseMatConstIterator& it2) |
joeverbout | 0:ea44dc9ed014 | 2841 | { |
joeverbout | 0:ea44dc9ed014 | 2842 | return it1.m == it2.m && it1.ptr == it2.ptr; |
joeverbout | 0:ea44dc9ed014 | 2843 | } |
joeverbout | 0:ea44dc9ed014 | 2844 | |
joeverbout | 0:ea44dc9ed014 | 2845 | static inline |
joeverbout | 0:ea44dc9ed014 | 2846 | bool operator != (const SparseMatConstIterator& it1, const SparseMatConstIterator& it2) |
joeverbout | 0:ea44dc9ed014 | 2847 | { |
joeverbout | 0:ea44dc9ed014 | 2848 | return !(it1 == it2); |
joeverbout | 0:ea44dc9ed014 | 2849 | } |
joeverbout | 0:ea44dc9ed014 | 2850 | |
joeverbout | 0:ea44dc9ed014 | 2851 | |
joeverbout | 0:ea44dc9ed014 | 2852 | |
joeverbout | 0:ea44dc9ed014 | 2853 | ///////////////////////// SparseMatIterator ///////////////////////// |
joeverbout | 0:ea44dc9ed014 | 2854 | |
joeverbout | 0:ea44dc9ed014 | 2855 | inline |
joeverbout | 0:ea44dc9ed014 | 2856 | SparseMatIterator::SparseMatIterator() |
joeverbout | 0:ea44dc9ed014 | 2857 | {} |
joeverbout | 0:ea44dc9ed014 | 2858 | |
joeverbout | 0:ea44dc9ed014 | 2859 | inline |
joeverbout | 0:ea44dc9ed014 | 2860 | SparseMatIterator::SparseMatIterator(SparseMat* _m) |
joeverbout | 0:ea44dc9ed014 | 2861 | : SparseMatConstIterator(_m) |
joeverbout | 0:ea44dc9ed014 | 2862 | {} |
joeverbout | 0:ea44dc9ed014 | 2863 | |
joeverbout | 0:ea44dc9ed014 | 2864 | inline |
joeverbout | 0:ea44dc9ed014 | 2865 | SparseMatIterator::SparseMatIterator(const SparseMatIterator& it) |
joeverbout | 0:ea44dc9ed014 | 2866 | : SparseMatConstIterator(it) |
joeverbout | 0:ea44dc9ed014 | 2867 | {} |
joeverbout | 0:ea44dc9ed014 | 2868 | |
joeverbout | 0:ea44dc9ed014 | 2869 | inline |
joeverbout | 0:ea44dc9ed014 | 2870 | SparseMatIterator& SparseMatIterator::operator = (const SparseMatIterator& it) |
joeverbout | 0:ea44dc9ed014 | 2871 | { |
joeverbout | 0:ea44dc9ed014 | 2872 | (SparseMatConstIterator&)*this = it; |
joeverbout | 0:ea44dc9ed014 | 2873 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2874 | } |
joeverbout | 0:ea44dc9ed014 | 2875 | |
joeverbout | 0:ea44dc9ed014 | 2876 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2877 | _Tp& SparseMatIterator::value() const |
joeverbout | 0:ea44dc9ed014 | 2878 | { |
joeverbout | 0:ea44dc9ed014 | 2879 | return *(_Tp*)ptr; |
joeverbout | 0:ea44dc9ed014 | 2880 | } |
joeverbout | 0:ea44dc9ed014 | 2881 | |
joeverbout | 0:ea44dc9ed014 | 2882 | inline |
joeverbout | 0:ea44dc9ed014 | 2883 | SparseMat::Node* SparseMatIterator::node() const |
joeverbout | 0:ea44dc9ed014 | 2884 | { |
joeverbout | 0:ea44dc9ed014 | 2885 | return (SparseMat::Node*)SparseMatConstIterator::node(); |
joeverbout | 0:ea44dc9ed014 | 2886 | } |
joeverbout | 0:ea44dc9ed014 | 2887 | |
joeverbout | 0:ea44dc9ed014 | 2888 | inline |
joeverbout | 0:ea44dc9ed014 | 2889 | SparseMatIterator& SparseMatIterator::operator ++() |
joeverbout | 0:ea44dc9ed014 | 2890 | { |
joeverbout | 0:ea44dc9ed014 | 2891 | SparseMatConstIterator::operator ++(); |
joeverbout | 0:ea44dc9ed014 | 2892 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2893 | } |
joeverbout | 0:ea44dc9ed014 | 2894 | |
joeverbout | 0:ea44dc9ed014 | 2895 | inline |
joeverbout | 0:ea44dc9ed014 | 2896 | SparseMatIterator SparseMatIterator::operator ++(int) |
joeverbout | 0:ea44dc9ed014 | 2897 | { |
joeverbout | 0:ea44dc9ed014 | 2898 | SparseMatIterator it = *this; |
joeverbout | 0:ea44dc9ed014 | 2899 | ++*this; |
joeverbout | 0:ea44dc9ed014 | 2900 | return it; |
joeverbout | 0:ea44dc9ed014 | 2901 | } |
joeverbout | 0:ea44dc9ed014 | 2902 | |
joeverbout | 0:ea44dc9ed014 | 2903 | |
joeverbout | 0:ea44dc9ed014 | 2904 | |
joeverbout | 0:ea44dc9ed014 | 2905 | ////////////////////// SparseMatConstIterator_ ////////////////////// |
joeverbout | 0:ea44dc9ed014 | 2906 | |
joeverbout | 0:ea44dc9ed014 | 2907 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2908 | SparseMatConstIterator_<_Tp>::SparseMatConstIterator_() |
joeverbout | 0:ea44dc9ed014 | 2909 | {} |
joeverbout | 0:ea44dc9ed014 | 2910 | |
joeverbout | 0:ea44dc9ed014 | 2911 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2912 | SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMat_<_Tp>* _m) |
joeverbout | 0:ea44dc9ed014 | 2913 | : SparseMatConstIterator(_m) |
joeverbout | 0:ea44dc9ed014 | 2914 | {} |
joeverbout | 0:ea44dc9ed014 | 2915 | |
joeverbout | 0:ea44dc9ed014 | 2916 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2917 | SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMat* _m) |
joeverbout | 0:ea44dc9ed014 | 2918 | : SparseMatConstIterator(_m) |
joeverbout | 0:ea44dc9ed014 | 2919 | { |
joeverbout | 0:ea44dc9ed014 | 2920 | CV_Assert( _m->type() == DataType<_Tp>::type ); |
joeverbout | 0:ea44dc9ed014 | 2921 | } |
joeverbout | 0:ea44dc9ed014 | 2922 | |
joeverbout | 0:ea44dc9ed014 | 2923 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2924 | SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMatConstIterator_<_Tp>& it) |
joeverbout | 0:ea44dc9ed014 | 2925 | : SparseMatConstIterator(it) |
joeverbout | 0:ea44dc9ed014 | 2926 | {} |
joeverbout | 0:ea44dc9ed014 | 2927 | |
joeverbout | 0:ea44dc9ed014 | 2928 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2929 | SparseMatConstIterator_<_Tp>& SparseMatConstIterator_<_Tp>::operator = (const SparseMatConstIterator_<_Tp>& it) |
joeverbout | 0:ea44dc9ed014 | 2930 | { |
joeverbout | 0:ea44dc9ed014 | 2931 | return reinterpret_cast<SparseMatConstIterator_<_Tp>&> |
joeverbout | 0:ea44dc9ed014 | 2932 | (*reinterpret_cast<SparseMatConstIterator*>(this) = |
joeverbout | 0:ea44dc9ed014 | 2933 | reinterpret_cast<const SparseMatConstIterator&>(it)); |
joeverbout | 0:ea44dc9ed014 | 2934 | } |
joeverbout | 0:ea44dc9ed014 | 2935 | |
joeverbout | 0:ea44dc9ed014 | 2936 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2937 | const _Tp& SparseMatConstIterator_<_Tp>::operator *() const |
joeverbout | 0:ea44dc9ed014 | 2938 | { |
joeverbout | 0:ea44dc9ed014 | 2939 | return *(const _Tp*)this->ptr; |
joeverbout | 0:ea44dc9ed014 | 2940 | } |
joeverbout | 0:ea44dc9ed014 | 2941 | |
joeverbout | 0:ea44dc9ed014 | 2942 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2943 | SparseMatConstIterator_<_Tp>& SparseMatConstIterator_<_Tp>::operator ++() |
joeverbout | 0:ea44dc9ed014 | 2944 | { |
joeverbout | 0:ea44dc9ed014 | 2945 | SparseMatConstIterator::operator ++(); |
joeverbout | 0:ea44dc9ed014 | 2946 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2947 | } |
joeverbout | 0:ea44dc9ed014 | 2948 | |
joeverbout | 0:ea44dc9ed014 | 2949 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2950 | SparseMatConstIterator_<_Tp> SparseMatConstIterator_<_Tp>::operator ++(int) |
joeverbout | 0:ea44dc9ed014 | 2951 | { |
joeverbout | 0:ea44dc9ed014 | 2952 | SparseMatConstIterator_<_Tp> it = *this; |
joeverbout | 0:ea44dc9ed014 | 2953 | SparseMatConstIterator::operator ++(); |
joeverbout | 0:ea44dc9ed014 | 2954 | return it; |
joeverbout | 0:ea44dc9ed014 | 2955 | } |
joeverbout | 0:ea44dc9ed014 | 2956 | |
joeverbout | 0:ea44dc9ed014 | 2957 | |
joeverbout | 0:ea44dc9ed014 | 2958 | |
joeverbout | 0:ea44dc9ed014 | 2959 | ///////////////////////// SparseMatIterator_ //////////////////////// |
joeverbout | 0:ea44dc9ed014 | 2960 | |
joeverbout | 0:ea44dc9ed014 | 2961 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2962 | SparseMatIterator_<_Tp>::SparseMatIterator_() |
joeverbout | 0:ea44dc9ed014 | 2963 | {} |
joeverbout | 0:ea44dc9ed014 | 2964 | |
joeverbout | 0:ea44dc9ed014 | 2965 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2966 | SparseMatIterator_<_Tp>::SparseMatIterator_(SparseMat_<_Tp>* _m) |
joeverbout | 0:ea44dc9ed014 | 2967 | : SparseMatConstIterator_<_Tp>(_m) |
joeverbout | 0:ea44dc9ed014 | 2968 | {} |
joeverbout | 0:ea44dc9ed014 | 2969 | |
joeverbout | 0:ea44dc9ed014 | 2970 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2971 | SparseMatIterator_<_Tp>::SparseMatIterator_(SparseMat* _m) |
joeverbout | 0:ea44dc9ed014 | 2972 | : SparseMatConstIterator_<_Tp>(_m) |
joeverbout | 0:ea44dc9ed014 | 2973 | {} |
joeverbout | 0:ea44dc9ed014 | 2974 | |
joeverbout | 0:ea44dc9ed014 | 2975 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2976 | SparseMatIterator_<_Tp>::SparseMatIterator_(const SparseMatIterator_<_Tp>& it) |
joeverbout | 0:ea44dc9ed014 | 2977 | : SparseMatConstIterator_<_Tp>(it) |
joeverbout | 0:ea44dc9ed014 | 2978 | {} |
joeverbout | 0:ea44dc9ed014 | 2979 | |
joeverbout | 0:ea44dc9ed014 | 2980 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2981 | SparseMatIterator_<_Tp>& SparseMatIterator_<_Tp>::operator = (const SparseMatIterator_<_Tp>& it) |
joeverbout | 0:ea44dc9ed014 | 2982 | { |
joeverbout | 0:ea44dc9ed014 | 2983 | return reinterpret_cast<SparseMatIterator_<_Tp>&> |
joeverbout | 0:ea44dc9ed014 | 2984 | (*reinterpret_cast<SparseMatConstIterator*>(this) = |
joeverbout | 0:ea44dc9ed014 | 2985 | reinterpret_cast<const SparseMatConstIterator&>(it)); |
joeverbout | 0:ea44dc9ed014 | 2986 | } |
joeverbout | 0:ea44dc9ed014 | 2987 | |
joeverbout | 0:ea44dc9ed014 | 2988 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2989 | _Tp& SparseMatIterator_<_Tp>::operator *() const |
joeverbout | 0:ea44dc9ed014 | 2990 | { |
joeverbout | 0:ea44dc9ed014 | 2991 | return *(_Tp*)this->ptr; |
joeverbout | 0:ea44dc9ed014 | 2992 | } |
joeverbout | 0:ea44dc9ed014 | 2993 | |
joeverbout | 0:ea44dc9ed014 | 2994 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 2995 | SparseMatIterator_<_Tp>& SparseMatIterator_<_Tp>::operator ++() |
joeverbout | 0:ea44dc9ed014 | 2996 | { |
joeverbout | 0:ea44dc9ed014 | 2997 | SparseMatConstIterator::operator ++(); |
joeverbout | 0:ea44dc9ed014 | 2998 | return *this; |
joeverbout | 0:ea44dc9ed014 | 2999 | } |
joeverbout | 0:ea44dc9ed014 | 3000 | |
joeverbout | 0:ea44dc9ed014 | 3001 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 3002 | SparseMatIterator_<_Tp> SparseMatIterator_<_Tp>::operator ++(int) |
joeverbout | 0:ea44dc9ed014 | 3003 | { |
joeverbout | 0:ea44dc9ed014 | 3004 | SparseMatIterator_<_Tp> it = *this; |
joeverbout | 0:ea44dc9ed014 | 3005 | SparseMatConstIterator::operator ++(); |
joeverbout | 0:ea44dc9ed014 | 3006 | return it; |
joeverbout | 0:ea44dc9ed014 | 3007 | } |
joeverbout | 0:ea44dc9ed014 | 3008 | |
joeverbout | 0:ea44dc9ed014 | 3009 | |
joeverbout | 0:ea44dc9ed014 | 3010 | |
joeverbout | 0:ea44dc9ed014 | 3011 | //////////////////////// MatCommaInitializer_ /////////////////////// |
joeverbout | 0:ea44dc9ed014 | 3012 | |
joeverbout | 0:ea44dc9ed014 | 3013 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 3014 | MatCommaInitializer_<_Tp>::MatCommaInitializer_(Mat_<_Tp>* _m) |
joeverbout | 0:ea44dc9ed014 | 3015 | : it(_m) |
joeverbout | 0:ea44dc9ed014 | 3016 | {} |
joeverbout | 0:ea44dc9ed014 | 3017 | |
joeverbout | 0:ea44dc9ed014 | 3018 | template<typename _Tp> template<typename T2> inline |
joeverbout | 0:ea44dc9ed014 | 3019 | MatCommaInitializer_<_Tp>& MatCommaInitializer_<_Tp>::operator , (T2 v) |
joeverbout | 0:ea44dc9ed014 | 3020 | { |
joeverbout | 0:ea44dc9ed014 | 3021 | CV_DbgAssert( this->it < ((const Mat_<_Tp>*)this->it.m)->end() ); |
joeverbout | 0:ea44dc9ed014 | 3022 | *this->it = _Tp(v); |
joeverbout | 0:ea44dc9ed014 | 3023 | ++this->it; |
joeverbout | 0:ea44dc9ed014 | 3024 | return *this; |
joeverbout | 0:ea44dc9ed014 | 3025 | } |
joeverbout | 0:ea44dc9ed014 | 3026 | |
joeverbout | 0:ea44dc9ed014 | 3027 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 3028 | MatCommaInitializer_<_Tp>::operator Mat_<_Tp>() const |
joeverbout | 0:ea44dc9ed014 | 3029 | { |
joeverbout | 0:ea44dc9ed014 | 3030 | CV_DbgAssert( this->it == ((const Mat_<_Tp>*)this->it.m)->end() ); |
joeverbout | 0:ea44dc9ed014 | 3031 | return Mat_<_Tp>(*this->it.m); |
joeverbout | 0:ea44dc9ed014 | 3032 | } |
joeverbout | 0:ea44dc9ed014 | 3033 | |
joeverbout | 0:ea44dc9ed014 | 3034 | |
joeverbout | 0:ea44dc9ed014 | 3035 | template<typename _Tp, typename T2> static inline |
joeverbout | 0:ea44dc9ed014 | 3036 | MatCommaInitializer_<_Tp> operator << (const Mat_<_Tp>& m, T2 val) |
joeverbout | 0:ea44dc9ed014 | 3037 | { |
joeverbout | 0:ea44dc9ed014 | 3038 | MatCommaInitializer_<_Tp> commaInitializer((Mat_<_Tp>*)&m); |
joeverbout | 0:ea44dc9ed014 | 3039 | return (commaInitializer, val); |
joeverbout | 0:ea44dc9ed014 | 3040 | } |
joeverbout | 0:ea44dc9ed014 | 3041 | |
joeverbout | 0:ea44dc9ed014 | 3042 | |
joeverbout | 0:ea44dc9ed014 | 3043 | |
joeverbout | 0:ea44dc9ed014 | 3044 | ///////////////////////// Matrix Expressions //////////////////////// |
joeverbout | 0:ea44dc9ed014 | 3045 | |
joeverbout | 0:ea44dc9ed014 | 3046 | inline |
joeverbout | 0:ea44dc9ed014 | 3047 | Mat& Mat::operator = (const MatExpr& e) |
joeverbout | 0:ea44dc9ed014 | 3048 | { |
joeverbout | 0:ea44dc9ed014 | 3049 | e.op->assign(e, *this); |
joeverbout | 0:ea44dc9ed014 | 3050 | return *this; |
joeverbout | 0:ea44dc9ed014 | 3051 | } |
joeverbout | 0:ea44dc9ed014 | 3052 | |
joeverbout | 0:ea44dc9ed014 | 3053 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 3054 | Mat_<_Tp>::Mat_(const MatExpr& e) |
joeverbout | 0:ea44dc9ed014 | 3055 | { |
joeverbout | 0:ea44dc9ed014 | 3056 | e.op->assign(e, *this, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 3057 | } |
joeverbout | 0:ea44dc9ed014 | 3058 | |
joeverbout | 0:ea44dc9ed014 | 3059 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 3060 | Mat_<_Tp>& Mat_<_Tp>::operator = (const MatExpr& e) |
joeverbout | 0:ea44dc9ed014 | 3061 | { |
joeverbout | 0:ea44dc9ed014 | 3062 | e.op->assign(e, *this, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 3063 | return *this; |
joeverbout | 0:ea44dc9ed014 | 3064 | } |
joeverbout | 0:ea44dc9ed014 | 3065 | |
joeverbout | 0:ea44dc9ed014 | 3066 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 3067 | MatExpr Mat_<_Tp>::zeros(int rows, int cols) |
joeverbout | 0:ea44dc9ed014 | 3068 | { |
joeverbout | 0:ea44dc9ed014 | 3069 | return Mat::zeros(rows, cols, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 3070 | } |
joeverbout | 0:ea44dc9ed014 | 3071 | |
joeverbout | 0:ea44dc9ed014 | 3072 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 3073 | MatExpr Mat_<_Tp>::zeros(Size sz) |
joeverbout | 0:ea44dc9ed014 | 3074 | { |
joeverbout | 0:ea44dc9ed014 | 3075 | return Mat::zeros(sz, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 3076 | } |
joeverbout | 0:ea44dc9ed014 | 3077 | |
joeverbout | 0:ea44dc9ed014 | 3078 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 3079 | MatExpr Mat_<_Tp>::ones(int rows, int cols) |
joeverbout | 0:ea44dc9ed014 | 3080 | { |
joeverbout | 0:ea44dc9ed014 | 3081 | return Mat::ones(rows, cols, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 3082 | } |
joeverbout | 0:ea44dc9ed014 | 3083 | |
joeverbout | 0:ea44dc9ed014 | 3084 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 3085 | MatExpr Mat_<_Tp>::ones(Size sz) |
joeverbout | 0:ea44dc9ed014 | 3086 | { |
joeverbout | 0:ea44dc9ed014 | 3087 | return Mat::ones(sz, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 3088 | } |
joeverbout | 0:ea44dc9ed014 | 3089 | |
joeverbout | 0:ea44dc9ed014 | 3090 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 3091 | MatExpr Mat_<_Tp>::eye(int rows, int cols) |
joeverbout | 0:ea44dc9ed014 | 3092 | { |
joeverbout | 0:ea44dc9ed014 | 3093 | return Mat::eye(rows, cols, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 3094 | } |
joeverbout | 0:ea44dc9ed014 | 3095 | |
joeverbout | 0:ea44dc9ed014 | 3096 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 3097 | MatExpr Mat_<_Tp>::eye(Size sz) |
joeverbout | 0:ea44dc9ed014 | 3098 | { |
joeverbout | 0:ea44dc9ed014 | 3099 | return Mat::eye(sz, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 3100 | } |
joeverbout | 0:ea44dc9ed014 | 3101 | |
joeverbout | 0:ea44dc9ed014 | 3102 | inline |
joeverbout | 0:ea44dc9ed014 | 3103 | MatExpr::MatExpr() |
joeverbout | 0:ea44dc9ed014 | 3104 | : op(0), flags(0), a(Mat()), b(Mat()), c(Mat()), alpha(0), beta(0), s() |
joeverbout | 0:ea44dc9ed014 | 3105 | {} |
joeverbout | 0:ea44dc9ed014 | 3106 | |
joeverbout | 0:ea44dc9ed014 | 3107 | inline |
joeverbout | 0:ea44dc9ed014 | 3108 | MatExpr::MatExpr(const MatOp* _op, int _flags, const Mat& _a, const Mat& _b, |
joeverbout | 0:ea44dc9ed014 | 3109 | const Mat& _c, double _alpha, double _beta, const Scalar& _s) |
joeverbout | 0:ea44dc9ed014 | 3110 | : op(_op), flags(_flags), a(_a), b(_b), c(_c), alpha(_alpha), beta(_beta), s(_s) |
joeverbout | 0:ea44dc9ed014 | 3111 | {} |
joeverbout | 0:ea44dc9ed014 | 3112 | |
joeverbout | 0:ea44dc9ed014 | 3113 | inline |
joeverbout | 0:ea44dc9ed014 | 3114 | MatExpr::operator Mat() const |
joeverbout | 0:ea44dc9ed014 | 3115 | { |
joeverbout | 0:ea44dc9ed014 | 3116 | Mat m; |
joeverbout | 0:ea44dc9ed014 | 3117 | op->assign(*this, m); |
joeverbout | 0:ea44dc9ed014 | 3118 | return m; |
joeverbout | 0:ea44dc9ed014 | 3119 | } |
joeverbout | 0:ea44dc9ed014 | 3120 | |
joeverbout | 0:ea44dc9ed014 | 3121 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 3122 | MatExpr::operator Mat_<_Tp>() const |
joeverbout | 0:ea44dc9ed014 | 3123 | { |
joeverbout | 0:ea44dc9ed014 | 3124 | Mat_<_Tp> m; |
joeverbout | 0:ea44dc9ed014 | 3125 | op->assign(*this, m, DataType<_Tp>::type); |
joeverbout | 0:ea44dc9ed014 | 3126 | return m; |
joeverbout | 0:ea44dc9ed014 | 3127 | } |
joeverbout | 0:ea44dc9ed014 | 3128 | |
joeverbout | 0:ea44dc9ed014 | 3129 | |
joeverbout | 0:ea44dc9ed014 | 3130 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 3131 | MatExpr min(const Mat_<_Tp>& a, const Mat_<_Tp>& b) |
joeverbout | 0:ea44dc9ed014 | 3132 | { |
joeverbout | 0:ea44dc9ed014 | 3133 | return cv::min((const Mat&)a, (const Mat&)b); |
joeverbout | 0:ea44dc9ed014 | 3134 | } |
joeverbout | 0:ea44dc9ed014 | 3135 | |
joeverbout | 0:ea44dc9ed014 | 3136 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 3137 | MatExpr min(const Mat_<_Tp>& a, double s) |
joeverbout | 0:ea44dc9ed014 | 3138 | { |
joeverbout | 0:ea44dc9ed014 | 3139 | return cv::min((const Mat&)a, s); |
joeverbout | 0:ea44dc9ed014 | 3140 | } |
joeverbout | 0:ea44dc9ed014 | 3141 | |
joeverbout | 0:ea44dc9ed014 | 3142 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 3143 | MatExpr min(double s, const Mat_<_Tp>& a) |
joeverbout | 0:ea44dc9ed014 | 3144 | { |
joeverbout | 0:ea44dc9ed014 | 3145 | return cv::min((const Mat&)a, s); |
joeverbout | 0:ea44dc9ed014 | 3146 | } |
joeverbout | 0:ea44dc9ed014 | 3147 | |
joeverbout | 0:ea44dc9ed014 | 3148 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 3149 | MatExpr max(const Mat_<_Tp>& a, const Mat_<_Tp>& b) |
joeverbout | 0:ea44dc9ed014 | 3150 | { |
joeverbout | 0:ea44dc9ed014 | 3151 | return cv::max((const Mat&)a, (const Mat&)b); |
joeverbout | 0:ea44dc9ed014 | 3152 | } |
joeverbout | 0:ea44dc9ed014 | 3153 | |
joeverbout | 0:ea44dc9ed014 | 3154 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 3155 | MatExpr max(const Mat_<_Tp>& a, double s) |
joeverbout | 0:ea44dc9ed014 | 3156 | { |
joeverbout | 0:ea44dc9ed014 | 3157 | return cv::max((const Mat&)a, s); |
joeverbout | 0:ea44dc9ed014 | 3158 | } |
joeverbout | 0:ea44dc9ed014 | 3159 | |
joeverbout | 0:ea44dc9ed014 | 3160 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 3161 | MatExpr max(double s, const Mat_<_Tp>& a) |
joeverbout | 0:ea44dc9ed014 | 3162 | { |
joeverbout | 0:ea44dc9ed014 | 3163 | return cv::max((const Mat&)a, s); |
joeverbout | 0:ea44dc9ed014 | 3164 | } |
joeverbout | 0:ea44dc9ed014 | 3165 | |
joeverbout | 0:ea44dc9ed014 | 3166 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 3167 | MatExpr abs(const Mat_<_Tp>& m) |
joeverbout | 0:ea44dc9ed014 | 3168 | { |
joeverbout | 0:ea44dc9ed014 | 3169 | return cv::abs((const Mat&)m); |
joeverbout | 0:ea44dc9ed014 | 3170 | } |
joeverbout | 0:ea44dc9ed014 | 3171 | |
joeverbout | 0:ea44dc9ed014 | 3172 | |
joeverbout | 0:ea44dc9ed014 | 3173 | static inline |
joeverbout | 0:ea44dc9ed014 | 3174 | Mat& operator += (Mat& a, const MatExpr& b) |
joeverbout | 0:ea44dc9ed014 | 3175 | { |
joeverbout | 0:ea44dc9ed014 | 3176 | b.op->augAssignAdd(b, a); |
joeverbout | 0:ea44dc9ed014 | 3177 | return a; |
joeverbout | 0:ea44dc9ed014 | 3178 | } |
joeverbout | 0:ea44dc9ed014 | 3179 | |
joeverbout | 0:ea44dc9ed014 | 3180 | static inline |
joeverbout | 0:ea44dc9ed014 | 3181 | const Mat& operator += (const Mat& a, const MatExpr& b) |
joeverbout | 0:ea44dc9ed014 | 3182 | { |
joeverbout | 0:ea44dc9ed014 | 3183 | b.op->augAssignAdd(b, (Mat&)a); |
joeverbout | 0:ea44dc9ed014 | 3184 | return a; |
joeverbout | 0:ea44dc9ed014 | 3185 | } |
joeverbout | 0:ea44dc9ed014 | 3186 | |
joeverbout | 0:ea44dc9ed014 | 3187 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 3188 | Mat_<_Tp>& operator += (Mat_<_Tp>& a, const MatExpr& b) |
joeverbout | 0:ea44dc9ed014 | 3189 | { |
joeverbout | 0:ea44dc9ed014 | 3190 | b.op->augAssignAdd(b, a); |
joeverbout | 0:ea44dc9ed014 | 3191 | return a; |
joeverbout | 0:ea44dc9ed014 | 3192 | } |
joeverbout | 0:ea44dc9ed014 | 3193 | |
joeverbout | 0:ea44dc9ed014 | 3194 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 3195 | const Mat_<_Tp>& operator += (const Mat_<_Tp>& a, const MatExpr& b) |
joeverbout | 0:ea44dc9ed014 | 3196 | { |
joeverbout | 0:ea44dc9ed014 | 3197 | b.op->augAssignAdd(b, (Mat&)a); |
joeverbout | 0:ea44dc9ed014 | 3198 | return a; |
joeverbout | 0:ea44dc9ed014 | 3199 | } |
joeverbout | 0:ea44dc9ed014 | 3200 | |
joeverbout | 0:ea44dc9ed014 | 3201 | static inline |
joeverbout | 0:ea44dc9ed014 | 3202 | Mat& operator -= (Mat& a, const MatExpr& b) |
joeverbout | 0:ea44dc9ed014 | 3203 | { |
joeverbout | 0:ea44dc9ed014 | 3204 | b.op->augAssignSubtract(b, a); |
joeverbout | 0:ea44dc9ed014 | 3205 | return a; |
joeverbout | 0:ea44dc9ed014 | 3206 | } |
joeverbout | 0:ea44dc9ed014 | 3207 | |
joeverbout | 0:ea44dc9ed014 | 3208 | static inline |
joeverbout | 0:ea44dc9ed014 | 3209 | const Mat& operator -= (const Mat& a, const MatExpr& b) |
joeverbout | 0:ea44dc9ed014 | 3210 | { |
joeverbout | 0:ea44dc9ed014 | 3211 | b.op->augAssignSubtract(b, (Mat&)a); |
joeverbout | 0:ea44dc9ed014 | 3212 | return a; |
joeverbout | 0:ea44dc9ed014 | 3213 | } |
joeverbout | 0:ea44dc9ed014 | 3214 | |
joeverbout | 0:ea44dc9ed014 | 3215 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 3216 | Mat_<_Tp>& operator -= (Mat_<_Tp>& a, const MatExpr& b) |
joeverbout | 0:ea44dc9ed014 | 3217 | { |
joeverbout | 0:ea44dc9ed014 | 3218 | b.op->augAssignSubtract(b, a); |
joeverbout | 0:ea44dc9ed014 | 3219 | return a; |
joeverbout | 0:ea44dc9ed014 | 3220 | } |
joeverbout | 0:ea44dc9ed014 | 3221 | |
joeverbout | 0:ea44dc9ed014 | 3222 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 3223 | const Mat_<_Tp>& operator -= (const Mat_<_Tp>& a, const MatExpr& b) |
joeverbout | 0:ea44dc9ed014 | 3224 | { |
joeverbout | 0:ea44dc9ed014 | 3225 | b.op->augAssignSubtract(b, (Mat&)a); |
joeverbout | 0:ea44dc9ed014 | 3226 | return a; |
joeverbout | 0:ea44dc9ed014 | 3227 | } |
joeverbout | 0:ea44dc9ed014 | 3228 | |
joeverbout | 0:ea44dc9ed014 | 3229 | static inline |
joeverbout | 0:ea44dc9ed014 | 3230 | Mat& operator *= (Mat& a, const MatExpr& b) |
joeverbout | 0:ea44dc9ed014 | 3231 | { |
joeverbout | 0:ea44dc9ed014 | 3232 | b.op->augAssignMultiply(b, a); |
joeverbout | 0:ea44dc9ed014 | 3233 | return a; |
joeverbout | 0:ea44dc9ed014 | 3234 | } |
joeverbout | 0:ea44dc9ed014 | 3235 | |
joeverbout | 0:ea44dc9ed014 | 3236 | static inline |
joeverbout | 0:ea44dc9ed014 | 3237 | const Mat& operator *= (const Mat& a, const MatExpr& b) |
joeverbout | 0:ea44dc9ed014 | 3238 | { |
joeverbout | 0:ea44dc9ed014 | 3239 | b.op->augAssignMultiply(b, (Mat&)a); |
joeverbout | 0:ea44dc9ed014 | 3240 | return a; |
joeverbout | 0:ea44dc9ed014 | 3241 | } |
joeverbout | 0:ea44dc9ed014 | 3242 | |
joeverbout | 0:ea44dc9ed014 | 3243 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 3244 | Mat_<_Tp>& operator *= (Mat_<_Tp>& a, const MatExpr& b) |
joeverbout | 0:ea44dc9ed014 | 3245 | { |
joeverbout | 0:ea44dc9ed014 | 3246 | b.op->augAssignMultiply(b, a); |
joeverbout | 0:ea44dc9ed014 | 3247 | return a; |
joeverbout | 0:ea44dc9ed014 | 3248 | } |
joeverbout | 0:ea44dc9ed014 | 3249 | |
joeverbout | 0:ea44dc9ed014 | 3250 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 3251 | const Mat_<_Tp>& operator *= (const Mat_<_Tp>& a, const MatExpr& b) |
joeverbout | 0:ea44dc9ed014 | 3252 | { |
joeverbout | 0:ea44dc9ed014 | 3253 | b.op->augAssignMultiply(b, (Mat&)a); |
joeverbout | 0:ea44dc9ed014 | 3254 | return a; |
joeverbout | 0:ea44dc9ed014 | 3255 | } |
joeverbout | 0:ea44dc9ed014 | 3256 | |
joeverbout | 0:ea44dc9ed014 | 3257 | static inline |
joeverbout | 0:ea44dc9ed014 | 3258 | Mat& operator /= (Mat& a, const MatExpr& b) |
joeverbout | 0:ea44dc9ed014 | 3259 | { |
joeverbout | 0:ea44dc9ed014 | 3260 | b.op->augAssignDivide(b, a); |
joeverbout | 0:ea44dc9ed014 | 3261 | return a; |
joeverbout | 0:ea44dc9ed014 | 3262 | } |
joeverbout | 0:ea44dc9ed014 | 3263 | |
joeverbout | 0:ea44dc9ed014 | 3264 | static inline |
joeverbout | 0:ea44dc9ed014 | 3265 | const Mat& operator /= (const Mat& a, const MatExpr& b) |
joeverbout | 0:ea44dc9ed014 | 3266 | { |
joeverbout | 0:ea44dc9ed014 | 3267 | b.op->augAssignDivide(b, (Mat&)a); |
joeverbout | 0:ea44dc9ed014 | 3268 | return a; |
joeverbout | 0:ea44dc9ed014 | 3269 | } |
joeverbout | 0:ea44dc9ed014 | 3270 | |
joeverbout | 0:ea44dc9ed014 | 3271 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 3272 | Mat_<_Tp>& operator /= (Mat_<_Tp>& a, const MatExpr& b) |
joeverbout | 0:ea44dc9ed014 | 3273 | { |
joeverbout | 0:ea44dc9ed014 | 3274 | b.op->augAssignDivide(b, a); |
joeverbout | 0:ea44dc9ed014 | 3275 | return a; |
joeverbout | 0:ea44dc9ed014 | 3276 | } |
joeverbout | 0:ea44dc9ed014 | 3277 | |
joeverbout | 0:ea44dc9ed014 | 3278 | template<typename _Tp> static inline |
joeverbout | 0:ea44dc9ed014 | 3279 | const Mat_<_Tp>& operator /= (const Mat_<_Tp>& a, const MatExpr& b) |
joeverbout | 0:ea44dc9ed014 | 3280 | { |
joeverbout | 0:ea44dc9ed014 | 3281 | b.op->augAssignDivide(b, (Mat&)a); |
joeverbout | 0:ea44dc9ed014 | 3282 | return a; |
joeverbout | 0:ea44dc9ed014 | 3283 | } |
joeverbout | 0:ea44dc9ed014 | 3284 | |
joeverbout | 0:ea44dc9ed014 | 3285 | |
joeverbout | 0:ea44dc9ed014 | 3286 | //////////////////////////////// UMat //////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 3287 | |
joeverbout | 0:ea44dc9ed014 | 3288 | inline |
joeverbout | 0:ea44dc9ed014 | 3289 | UMat::UMat(UMatUsageFlags _usageFlags) |
joeverbout | 0:ea44dc9ed014 | 3290 | : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 3291 | {} |
joeverbout | 0:ea44dc9ed014 | 3292 | |
joeverbout | 0:ea44dc9ed014 | 3293 | inline |
joeverbout | 0:ea44dc9ed014 | 3294 | UMat::UMat(int _rows, int _cols, int _type, UMatUsageFlags _usageFlags) |
joeverbout | 0:ea44dc9ed014 | 3295 | : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 3296 | { |
joeverbout | 0:ea44dc9ed014 | 3297 | create(_rows, _cols, _type); |
joeverbout | 0:ea44dc9ed014 | 3298 | } |
joeverbout | 0:ea44dc9ed014 | 3299 | |
joeverbout | 0:ea44dc9ed014 | 3300 | inline |
joeverbout | 0:ea44dc9ed014 | 3301 | UMat::UMat(int _rows, int _cols, int _type, const Scalar& _s, UMatUsageFlags _usageFlags) |
joeverbout | 0:ea44dc9ed014 | 3302 | : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 3303 | { |
joeverbout | 0:ea44dc9ed014 | 3304 | create(_rows, _cols, _type); |
joeverbout | 0:ea44dc9ed014 | 3305 | *this = _s; |
joeverbout | 0:ea44dc9ed014 | 3306 | } |
joeverbout | 0:ea44dc9ed014 | 3307 | |
joeverbout | 0:ea44dc9ed014 | 3308 | inline |
joeverbout | 0:ea44dc9ed014 | 3309 | UMat::UMat(Size _sz, int _type, UMatUsageFlags _usageFlags) |
joeverbout | 0:ea44dc9ed014 | 3310 | : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 3311 | { |
joeverbout | 0:ea44dc9ed014 | 3312 | create( _sz.height, _sz.width, _type ); |
joeverbout | 0:ea44dc9ed014 | 3313 | } |
joeverbout | 0:ea44dc9ed014 | 3314 | |
joeverbout | 0:ea44dc9ed014 | 3315 | inline |
joeverbout | 0:ea44dc9ed014 | 3316 | UMat::UMat(Size _sz, int _type, const Scalar& _s, UMatUsageFlags _usageFlags) |
joeverbout | 0:ea44dc9ed014 | 3317 | : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 3318 | { |
joeverbout | 0:ea44dc9ed014 | 3319 | create(_sz.height, _sz.width, _type); |
joeverbout | 0:ea44dc9ed014 | 3320 | *this = _s; |
joeverbout | 0:ea44dc9ed014 | 3321 | } |
joeverbout | 0:ea44dc9ed014 | 3322 | |
joeverbout | 0:ea44dc9ed014 | 3323 | inline |
joeverbout | 0:ea44dc9ed014 | 3324 | UMat::UMat(int _dims, const int* _sz, int _type, UMatUsageFlags _usageFlags) |
joeverbout | 0:ea44dc9ed014 | 3325 | : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 3326 | { |
joeverbout | 0:ea44dc9ed014 | 3327 | create(_dims, _sz, _type); |
joeverbout | 0:ea44dc9ed014 | 3328 | } |
joeverbout | 0:ea44dc9ed014 | 3329 | |
joeverbout | 0:ea44dc9ed014 | 3330 | inline |
joeverbout | 0:ea44dc9ed014 | 3331 | UMat::UMat(int _dims, const int* _sz, int _type, const Scalar& _s, UMatUsageFlags _usageFlags) |
joeverbout | 0:ea44dc9ed014 | 3332 | : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 3333 | { |
joeverbout | 0:ea44dc9ed014 | 3334 | create(_dims, _sz, _type); |
joeverbout | 0:ea44dc9ed014 | 3335 | *this = _s; |
joeverbout | 0:ea44dc9ed014 | 3336 | } |
joeverbout | 0:ea44dc9ed014 | 3337 | |
joeverbout | 0:ea44dc9ed014 | 3338 | inline |
joeverbout | 0:ea44dc9ed014 | 3339 | UMat::UMat(const UMat& m) |
joeverbout | 0:ea44dc9ed014 | 3340 | : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), allocator(m.allocator), |
joeverbout | 0:ea44dc9ed014 | 3341 | usageFlags(m.usageFlags), u(m.u), offset(m.offset), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 3342 | { |
joeverbout | 0:ea44dc9ed014 | 3343 | addref(); |
joeverbout | 0:ea44dc9ed014 | 3344 | if( m.dims <= 2 ) |
joeverbout | 0:ea44dc9ed014 | 3345 | { |
joeverbout | 0:ea44dc9ed014 | 3346 | step[0] = m.step[0]; step[1] = m.step[1]; |
joeverbout | 0:ea44dc9ed014 | 3347 | } |
joeverbout | 0:ea44dc9ed014 | 3348 | else |
joeverbout | 0:ea44dc9ed014 | 3349 | { |
joeverbout | 0:ea44dc9ed014 | 3350 | dims = 0; |
joeverbout | 0:ea44dc9ed014 | 3351 | copySize(m); |
joeverbout | 0:ea44dc9ed014 | 3352 | } |
joeverbout | 0:ea44dc9ed014 | 3353 | } |
joeverbout | 0:ea44dc9ed014 | 3354 | |
joeverbout | 0:ea44dc9ed014 | 3355 | |
joeverbout | 0:ea44dc9ed014 | 3356 | template<typename _Tp> inline |
joeverbout | 0:ea44dc9ed014 | 3357 | UMat::UMat(const std::vector<_Tp>& vec, bool copyData) |
joeverbout | 0:ea44dc9ed014 | 3358 | : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), |
joeverbout | 0:ea44dc9ed014 | 3359 | cols(1), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 3360 | { |
joeverbout | 0:ea44dc9ed014 | 3361 | if(vec.empty()) |
joeverbout | 0:ea44dc9ed014 | 3362 | return; |
joeverbout | 0:ea44dc9ed014 | 3363 | if( !copyData ) |
joeverbout | 0:ea44dc9ed014 | 3364 | { |
joeverbout | 0:ea44dc9ed014 | 3365 | // !!!TODO!!! |
joeverbout | 0:ea44dc9ed014 | 3366 | CV_Error(Error::StsNotImplemented, ""); |
joeverbout | 0:ea44dc9ed014 | 3367 | } |
joeverbout | 0:ea44dc9ed014 | 3368 | else |
joeverbout | 0:ea44dc9ed014 | 3369 | Mat((int)vec.size(), 1, DataType<_Tp>::type, (uchar*)&vec[0]).copyTo(*this); |
joeverbout | 0:ea44dc9ed014 | 3370 | } |
joeverbout | 0:ea44dc9ed014 | 3371 | |
joeverbout | 0:ea44dc9ed014 | 3372 | |
joeverbout | 0:ea44dc9ed014 | 3373 | inline |
joeverbout | 0:ea44dc9ed014 | 3374 | UMat& UMat::operator = (const UMat& m) |
joeverbout | 0:ea44dc9ed014 | 3375 | { |
joeverbout | 0:ea44dc9ed014 | 3376 | if( this != &m ) |
joeverbout | 0:ea44dc9ed014 | 3377 | { |
joeverbout | 0:ea44dc9ed014 | 3378 | const_cast<UMat&>(m).addref(); |
joeverbout | 0:ea44dc9ed014 | 3379 | release(); |
joeverbout | 0:ea44dc9ed014 | 3380 | flags = m.flags; |
joeverbout | 0:ea44dc9ed014 | 3381 | if( dims <= 2 && m.dims <= 2 ) |
joeverbout | 0:ea44dc9ed014 | 3382 | { |
joeverbout | 0:ea44dc9ed014 | 3383 | dims = m.dims; |
joeverbout | 0:ea44dc9ed014 | 3384 | rows = m.rows; |
joeverbout | 0:ea44dc9ed014 | 3385 | cols = m.cols; |
joeverbout | 0:ea44dc9ed014 | 3386 | step[0] = m.step[0]; |
joeverbout | 0:ea44dc9ed014 | 3387 | step[1] = m.step[1]; |
joeverbout | 0:ea44dc9ed014 | 3388 | } |
joeverbout | 0:ea44dc9ed014 | 3389 | else |
joeverbout | 0:ea44dc9ed014 | 3390 | copySize(m); |
joeverbout | 0:ea44dc9ed014 | 3391 | allocator = m.allocator; |
joeverbout | 0:ea44dc9ed014 | 3392 | if (usageFlags == USAGE_DEFAULT) |
joeverbout | 0:ea44dc9ed014 | 3393 | usageFlags = m.usageFlags; |
joeverbout | 0:ea44dc9ed014 | 3394 | u = m.u; |
joeverbout | 0:ea44dc9ed014 | 3395 | offset = m.offset; |
joeverbout | 0:ea44dc9ed014 | 3396 | } |
joeverbout | 0:ea44dc9ed014 | 3397 | return *this; |
joeverbout | 0:ea44dc9ed014 | 3398 | } |
joeverbout | 0:ea44dc9ed014 | 3399 | |
joeverbout | 0:ea44dc9ed014 | 3400 | inline |
joeverbout | 0:ea44dc9ed014 | 3401 | UMat UMat::row(int y) const |
joeverbout | 0:ea44dc9ed014 | 3402 | { |
joeverbout | 0:ea44dc9ed014 | 3403 | return UMat(*this, Range(y, y + 1), Range::all()); |
joeverbout | 0:ea44dc9ed014 | 3404 | } |
joeverbout | 0:ea44dc9ed014 | 3405 | |
joeverbout | 0:ea44dc9ed014 | 3406 | inline |
joeverbout | 0:ea44dc9ed014 | 3407 | UMat UMat::col(int x) const |
joeverbout | 0:ea44dc9ed014 | 3408 | { |
joeverbout | 0:ea44dc9ed014 | 3409 | return UMat(*this, Range::all(), Range(x, x + 1)); |
joeverbout | 0:ea44dc9ed014 | 3410 | } |
joeverbout | 0:ea44dc9ed014 | 3411 | |
joeverbout | 0:ea44dc9ed014 | 3412 | inline |
joeverbout | 0:ea44dc9ed014 | 3413 | UMat UMat::rowRange(int startrow, int endrow) const |
joeverbout | 0:ea44dc9ed014 | 3414 | { |
joeverbout | 0:ea44dc9ed014 | 3415 | return UMat(*this, Range(startrow, endrow), Range::all()); |
joeverbout | 0:ea44dc9ed014 | 3416 | } |
joeverbout | 0:ea44dc9ed014 | 3417 | |
joeverbout | 0:ea44dc9ed014 | 3418 | inline |
joeverbout | 0:ea44dc9ed014 | 3419 | UMat UMat::rowRange(const Range& r) const |
joeverbout | 0:ea44dc9ed014 | 3420 | { |
joeverbout | 0:ea44dc9ed014 | 3421 | return UMat(*this, r, Range::all()); |
joeverbout | 0:ea44dc9ed014 | 3422 | } |
joeverbout | 0:ea44dc9ed014 | 3423 | |
joeverbout | 0:ea44dc9ed014 | 3424 | inline |
joeverbout | 0:ea44dc9ed014 | 3425 | UMat UMat::colRange(int startcol, int endcol) const |
joeverbout | 0:ea44dc9ed014 | 3426 | { |
joeverbout | 0:ea44dc9ed014 | 3427 | return UMat(*this, Range::all(), Range(startcol, endcol)); |
joeverbout | 0:ea44dc9ed014 | 3428 | } |
joeverbout | 0:ea44dc9ed014 | 3429 | |
joeverbout | 0:ea44dc9ed014 | 3430 | inline |
joeverbout | 0:ea44dc9ed014 | 3431 | UMat UMat::colRange(const Range& r) const |
joeverbout | 0:ea44dc9ed014 | 3432 | { |
joeverbout | 0:ea44dc9ed014 | 3433 | return UMat(*this, Range::all(), r); |
joeverbout | 0:ea44dc9ed014 | 3434 | } |
joeverbout | 0:ea44dc9ed014 | 3435 | |
joeverbout | 0:ea44dc9ed014 | 3436 | inline |
joeverbout | 0:ea44dc9ed014 | 3437 | UMat UMat::clone() const |
joeverbout | 0:ea44dc9ed014 | 3438 | { |
joeverbout | 0:ea44dc9ed014 | 3439 | UMat m; |
joeverbout | 0:ea44dc9ed014 | 3440 | copyTo(m); |
joeverbout | 0:ea44dc9ed014 | 3441 | return m; |
joeverbout | 0:ea44dc9ed014 | 3442 | } |
joeverbout | 0:ea44dc9ed014 | 3443 | |
joeverbout | 0:ea44dc9ed014 | 3444 | inline |
joeverbout | 0:ea44dc9ed014 | 3445 | void UMat::assignTo( UMat& m, int _type ) const |
joeverbout | 0:ea44dc9ed014 | 3446 | { |
joeverbout | 0:ea44dc9ed014 | 3447 | if( _type < 0 ) |
joeverbout | 0:ea44dc9ed014 | 3448 | m = *this; |
joeverbout | 0:ea44dc9ed014 | 3449 | else |
joeverbout | 0:ea44dc9ed014 | 3450 | convertTo(m, _type); |
joeverbout | 0:ea44dc9ed014 | 3451 | } |
joeverbout | 0:ea44dc9ed014 | 3452 | |
joeverbout | 0:ea44dc9ed014 | 3453 | inline |
joeverbout | 0:ea44dc9ed014 | 3454 | void UMat::create(int _rows, int _cols, int _type, UMatUsageFlags _usageFlags) |
joeverbout | 0:ea44dc9ed014 | 3455 | { |
joeverbout | 0:ea44dc9ed014 | 3456 | _type &= TYPE_MASK; |
joeverbout | 0:ea44dc9ed014 | 3457 | if( dims <= 2 && rows == _rows && cols == _cols && type() == _type && u ) |
joeverbout | 0:ea44dc9ed014 | 3458 | return; |
joeverbout | 0:ea44dc9ed014 | 3459 | int sz[] = {_rows, _cols}; |
joeverbout | 0:ea44dc9ed014 | 3460 | create(2, sz, _type, _usageFlags); |
joeverbout | 0:ea44dc9ed014 | 3461 | } |
joeverbout | 0:ea44dc9ed014 | 3462 | |
joeverbout | 0:ea44dc9ed014 | 3463 | inline |
joeverbout | 0:ea44dc9ed014 | 3464 | void UMat::create(Size _sz, int _type, UMatUsageFlags _usageFlags) |
joeverbout | 0:ea44dc9ed014 | 3465 | { |
joeverbout | 0:ea44dc9ed014 | 3466 | create(_sz.height, _sz.width, _type, _usageFlags); |
joeverbout | 0:ea44dc9ed014 | 3467 | } |
joeverbout | 0:ea44dc9ed014 | 3468 | |
joeverbout | 0:ea44dc9ed014 | 3469 | inline |
joeverbout | 0:ea44dc9ed014 | 3470 | void UMat::addref() |
joeverbout | 0:ea44dc9ed014 | 3471 | { |
joeverbout | 0:ea44dc9ed014 | 3472 | if( u ) |
joeverbout | 0:ea44dc9ed014 | 3473 | CV_XADD(&(u->urefcount), 1); |
joeverbout | 0:ea44dc9ed014 | 3474 | } |
joeverbout | 0:ea44dc9ed014 | 3475 | |
joeverbout | 0:ea44dc9ed014 | 3476 | inline void UMat::release() |
joeverbout | 0:ea44dc9ed014 | 3477 | { |
joeverbout | 0:ea44dc9ed014 | 3478 | if( u && CV_XADD(&(u->urefcount), -1) == 1 ) |
joeverbout | 0:ea44dc9ed014 | 3479 | deallocate(); |
joeverbout | 0:ea44dc9ed014 | 3480 | for(int i = 0; i < dims; i++) |
joeverbout | 0:ea44dc9ed014 | 3481 | size.p[i] = 0; |
joeverbout | 0:ea44dc9ed014 | 3482 | u = 0; |
joeverbout | 0:ea44dc9ed014 | 3483 | } |
joeverbout | 0:ea44dc9ed014 | 3484 | |
joeverbout | 0:ea44dc9ed014 | 3485 | inline |
joeverbout | 0:ea44dc9ed014 | 3486 | UMat UMat::operator()( Range _rowRange, Range _colRange ) const |
joeverbout | 0:ea44dc9ed014 | 3487 | { |
joeverbout | 0:ea44dc9ed014 | 3488 | return UMat(*this, _rowRange, _colRange); |
joeverbout | 0:ea44dc9ed014 | 3489 | } |
joeverbout | 0:ea44dc9ed014 | 3490 | |
joeverbout | 0:ea44dc9ed014 | 3491 | inline |
joeverbout | 0:ea44dc9ed014 | 3492 | UMat UMat::operator()( const Rect& roi ) const |
joeverbout | 0:ea44dc9ed014 | 3493 | { |
joeverbout | 0:ea44dc9ed014 | 3494 | return UMat(*this, roi); |
joeverbout | 0:ea44dc9ed014 | 3495 | } |
joeverbout | 0:ea44dc9ed014 | 3496 | |
joeverbout | 0:ea44dc9ed014 | 3497 | inline |
joeverbout | 0:ea44dc9ed014 | 3498 | UMat UMat::operator()(const Range* ranges) const |
joeverbout | 0:ea44dc9ed014 | 3499 | { |
joeverbout | 0:ea44dc9ed014 | 3500 | return UMat(*this, ranges); |
joeverbout | 0:ea44dc9ed014 | 3501 | } |
joeverbout | 0:ea44dc9ed014 | 3502 | |
joeverbout | 0:ea44dc9ed014 | 3503 | inline |
joeverbout | 0:ea44dc9ed014 | 3504 | bool UMat::isContinuous() const |
joeverbout | 0:ea44dc9ed014 | 3505 | { |
joeverbout | 0:ea44dc9ed014 | 3506 | return (flags & CONTINUOUS_FLAG) != 0; |
joeverbout | 0:ea44dc9ed014 | 3507 | } |
joeverbout | 0:ea44dc9ed014 | 3508 | |
joeverbout | 0:ea44dc9ed014 | 3509 | inline |
joeverbout | 0:ea44dc9ed014 | 3510 | bool UMat::isSubmatrix() const |
joeverbout | 0:ea44dc9ed014 | 3511 | { |
joeverbout | 0:ea44dc9ed014 | 3512 | return (flags & SUBMATRIX_FLAG) != 0; |
joeverbout | 0:ea44dc9ed014 | 3513 | } |
joeverbout | 0:ea44dc9ed014 | 3514 | |
joeverbout | 0:ea44dc9ed014 | 3515 | inline |
joeverbout | 0:ea44dc9ed014 | 3516 | size_t UMat::elemSize() const |
joeverbout | 0:ea44dc9ed014 | 3517 | { |
joeverbout | 0:ea44dc9ed014 | 3518 | return dims > 0 ? step.p[dims - 1] : 0; |
joeverbout | 0:ea44dc9ed014 | 3519 | } |
joeverbout | 0:ea44dc9ed014 | 3520 | |
joeverbout | 0:ea44dc9ed014 | 3521 | inline |
joeverbout | 0:ea44dc9ed014 | 3522 | size_t UMat::elemSize1() const |
joeverbout | 0:ea44dc9ed014 | 3523 | { |
joeverbout | 0:ea44dc9ed014 | 3524 | return CV_ELEM_SIZE1(flags); |
joeverbout | 0:ea44dc9ed014 | 3525 | } |
joeverbout | 0:ea44dc9ed014 | 3526 | |
joeverbout | 0:ea44dc9ed014 | 3527 | inline |
joeverbout | 0:ea44dc9ed014 | 3528 | int UMat::type() const |
joeverbout | 0:ea44dc9ed014 | 3529 | { |
joeverbout | 0:ea44dc9ed014 | 3530 | return CV_MAT_TYPE(flags); |
joeverbout | 0:ea44dc9ed014 | 3531 | } |
joeverbout | 0:ea44dc9ed014 | 3532 | |
joeverbout | 0:ea44dc9ed014 | 3533 | inline |
joeverbout | 0:ea44dc9ed014 | 3534 | int UMat::depth() const |
joeverbout | 0:ea44dc9ed014 | 3535 | { |
joeverbout | 0:ea44dc9ed014 | 3536 | return CV_MAT_DEPTH(flags); |
joeverbout | 0:ea44dc9ed014 | 3537 | } |
joeverbout | 0:ea44dc9ed014 | 3538 | |
joeverbout | 0:ea44dc9ed014 | 3539 | inline |
joeverbout | 0:ea44dc9ed014 | 3540 | int UMat::channels() const |
joeverbout | 0:ea44dc9ed014 | 3541 | { |
joeverbout | 0:ea44dc9ed014 | 3542 | return CV_MAT_CN(flags); |
joeverbout | 0:ea44dc9ed014 | 3543 | } |
joeverbout | 0:ea44dc9ed014 | 3544 | |
joeverbout | 0:ea44dc9ed014 | 3545 | inline |
joeverbout | 0:ea44dc9ed014 | 3546 | size_t UMat::step1(int i) const |
joeverbout | 0:ea44dc9ed014 | 3547 | { |
joeverbout | 0:ea44dc9ed014 | 3548 | return step.p[i] / elemSize1(); |
joeverbout | 0:ea44dc9ed014 | 3549 | } |
joeverbout | 0:ea44dc9ed014 | 3550 | |
joeverbout | 0:ea44dc9ed014 | 3551 | inline |
joeverbout | 0:ea44dc9ed014 | 3552 | bool UMat::empty() const |
joeverbout | 0:ea44dc9ed014 | 3553 | { |
joeverbout | 0:ea44dc9ed014 | 3554 | return u == 0 || total() == 0; |
joeverbout | 0:ea44dc9ed014 | 3555 | } |
joeverbout | 0:ea44dc9ed014 | 3556 | |
joeverbout | 0:ea44dc9ed014 | 3557 | inline |
joeverbout | 0:ea44dc9ed014 | 3558 | size_t UMat::total() const |
joeverbout | 0:ea44dc9ed014 | 3559 | { |
joeverbout | 0:ea44dc9ed014 | 3560 | if( dims <= 2 ) |
joeverbout | 0:ea44dc9ed014 | 3561 | return (size_t)rows * cols; |
joeverbout | 0:ea44dc9ed014 | 3562 | size_t p = 1; |
joeverbout | 0:ea44dc9ed014 | 3563 | for( int i = 0; i < dims; i++ ) |
joeverbout | 0:ea44dc9ed014 | 3564 | p *= size[i]; |
joeverbout | 0:ea44dc9ed014 | 3565 | return p; |
joeverbout | 0:ea44dc9ed014 | 3566 | } |
joeverbout | 0:ea44dc9ed014 | 3567 | |
joeverbout | 0:ea44dc9ed014 | 3568 | #ifdef CV_CXX_MOVE_SEMANTICS |
joeverbout | 0:ea44dc9ed014 | 3569 | |
joeverbout | 0:ea44dc9ed014 | 3570 | inline |
joeverbout | 0:ea44dc9ed014 | 3571 | UMat::UMat(UMat&& m) |
joeverbout | 0:ea44dc9ed014 | 3572 | : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), allocator(m.allocator), |
joeverbout | 0:ea44dc9ed014 | 3573 | usageFlags(m.usageFlags), u(m.u), offset(m.offset), size(&rows) |
joeverbout | 0:ea44dc9ed014 | 3574 | { |
joeverbout | 0:ea44dc9ed014 | 3575 | if (m.dims <= 2) // move new step/size info |
joeverbout | 0:ea44dc9ed014 | 3576 | { |
joeverbout | 0:ea44dc9ed014 | 3577 | step[0] = m.step[0]; |
joeverbout | 0:ea44dc9ed014 | 3578 | step[1] = m.step[1]; |
joeverbout | 0:ea44dc9ed014 | 3579 | } |
joeverbout | 0:ea44dc9ed014 | 3580 | else |
joeverbout | 0:ea44dc9ed014 | 3581 | { |
joeverbout | 0:ea44dc9ed014 | 3582 | CV_DbgAssert(m.step.p != m.step.buf); |
joeverbout | 0:ea44dc9ed014 | 3583 | step.p = m.step.p; |
joeverbout | 0:ea44dc9ed014 | 3584 | size.p = m.size.p; |
joeverbout | 0:ea44dc9ed014 | 3585 | m.step.p = m.step.buf; |
joeverbout | 0:ea44dc9ed014 | 3586 | m.size.p = &m.rows; |
joeverbout | 0:ea44dc9ed014 | 3587 | } |
joeverbout | 0:ea44dc9ed014 | 3588 | m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; |
joeverbout | 0:ea44dc9ed014 | 3589 | m.allocator = NULL; |
joeverbout | 0:ea44dc9ed014 | 3590 | m.u = NULL; |
joeverbout | 0:ea44dc9ed014 | 3591 | m.offset = 0; |
joeverbout | 0:ea44dc9ed014 | 3592 | } |
joeverbout | 0:ea44dc9ed014 | 3593 | |
joeverbout | 0:ea44dc9ed014 | 3594 | inline |
joeverbout | 0:ea44dc9ed014 | 3595 | UMat& UMat::operator = (UMat&& m) |
joeverbout | 0:ea44dc9ed014 | 3596 | { |
joeverbout | 0:ea44dc9ed014 | 3597 | release(); |
joeverbout | 0:ea44dc9ed014 | 3598 | flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols; |
joeverbout | 0:ea44dc9ed014 | 3599 | allocator = m.allocator; usageFlags = m.usageFlags; |
joeverbout | 0:ea44dc9ed014 | 3600 | u = m.u; |
joeverbout | 0:ea44dc9ed014 | 3601 | offset = m.offset; |
joeverbout | 0:ea44dc9ed014 | 3602 | if (step.p != step.buf) // release self step/size |
joeverbout | 0:ea44dc9ed014 | 3603 | { |
joeverbout | 0:ea44dc9ed014 | 3604 | fastFree(step.p); |
joeverbout | 0:ea44dc9ed014 | 3605 | step.p = step.buf; |
joeverbout | 0:ea44dc9ed014 | 3606 | size.p = &rows; |
joeverbout | 0:ea44dc9ed014 | 3607 | } |
joeverbout | 0:ea44dc9ed014 | 3608 | if (m.dims <= 2) // move new step/size info |
joeverbout | 0:ea44dc9ed014 | 3609 | { |
joeverbout | 0:ea44dc9ed014 | 3610 | step[0] = m.step[0]; |
joeverbout | 0:ea44dc9ed014 | 3611 | step[1] = m.step[1]; |
joeverbout | 0:ea44dc9ed014 | 3612 | } |
joeverbout | 0:ea44dc9ed014 | 3613 | else |
joeverbout | 0:ea44dc9ed014 | 3614 | { |
joeverbout | 0:ea44dc9ed014 | 3615 | CV_DbgAssert(m.step.p != m.step.buf); |
joeverbout | 0:ea44dc9ed014 | 3616 | step.p = m.step.p; |
joeverbout | 0:ea44dc9ed014 | 3617 | size.p = m.size.p; |
joeverbout | 0:ea44dc9ed014 | 3618 | m.step.p = m.step.buf; |
joeverbout | 0:ea44dc9ed014 | 3619 | m.size.p = &m.rows; |
joeverbout | 0:ea44dc9ed014 | 3620 | } |
joeverbout | 0:ea44dc9ed014 | 3621 | m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; |
joeverbout | 0:ea44dc9ed014 | 3622 | m.allocator = NULL; |
joeverbout | 0:ea44dc9ed014 | 3623 | m.u = NULL; |
joeverbout | 0:ea44dc9ed014 | 3624 | m.offset = 0; |
joeverbout | 0:ea44dc9ed014 | 3625 | return *this; |
joeverbout | 0:ea44dc9ed014 | 3626 | } |
joeverbout | 0:ea44dc9ed014 | 3627 | |
joeverbout | 0:ea44dc9ed014 | 3628 | #endif |
joeverbout | 0:ea44dc9ed014 | 3629 | |
joeverbout | 0:ea44dc9ed014 | 3630 | |
joeverbout | 0:ea44dc9ed014 | 3631 | inline bool UMatData::hostCopyObsolete() const { return (flags & HOST_COPY_OBSOLETE) != 0; } |
joeverbout | 0:ea44dc9ed014 | 3632 | inline bool UMatData::deviceCopyObsolete() const { return (flags & DEVICE_COPY_OBSOLETE) != 0; } |
joeverbout | 0:ea44dc9ed014 | 3633 | inline bool UMatData::deviceMemMapped() const { return (flags & DEVICE_MEM_MAPPED) != 0; } |
joeverbout | 0:ea44dc9ed014 | 3634 | inline bool UMatData::copyOnMap() const { return (flags & COPY_ON_MAP) != 0; } |
joeverbout | 0:ea44dc9ed014 | 3635 | inline bool UMatData::tempUMat() const { return (flags & TEMP_UMAT) != 0; } |
joeverbout | 0:ea44dc9ed014 | 3636 | inline bool UMatData::tempCopiedUMat() const { return (flags & TEMP_COPIED_UMAT) == TEMP_COPIED_UMAT; } |
joeverbout | 0:ea44dc9ed014 | 3637 | |
joeverbout | 0:ea44dc9ed014 | 3638 | inline void UMatData::markDeviceMemMapped(bool flag) |
joeverbout | 0:ea44dc9ed014 | 3639 | { |
joeverbout | 0:ea44dc9ed014 | 3640 | if(flag) |
joeverbout | 0:ea44dc9ed014 | 3641 | flags |= DEVICE_MEM_MAPPED; |
joeverbout | 0:ea44dc9ed014 | 3642 | else |
joeverbout | 0:ea44dc9ed014 | 3643 | flags &= ~DEVICE_MEM_MAPPED; |
joeverbout | 0:ea44dc9ed014 | 3644 | } |
joeverbout | 0:ea44dc9ed014 | 3645 | |
joeverbout | 0:ea44dc9ed014 | 3646 | inline void UMatData::markHostCopyObsolete(bool flag) |
joeverbout | 0:ea44dc9ed014 | 3647 | { |
joeverbout | 0:ea44dc9ed014 | 3648 | if(flag) |
joeverbout | 0:ea44dc9ed014 | 3649 | flags |= HOST_COPY_OBSOLETE; |
joeverbout | 0:ea44dc9ed014 | 3650 | else |
joeverbout | 0:ea44dc9ed014 | 3651 | flags &= ~HOST_COPY_OBSOLETE; |
joeverbout | 0:ea44dc9ed014 | 3652 | } |
joeverbout | 0:ea44dc9ed014 | 3653 | inline void UMatData::markDeviceCopyObsolete(bool flag) |
joeverbout | 0:ea44dc9ed014 | 3654 | { |
joeverbout | 0:ea44dc9ed014 | 3655 | if(flag) |
joeverbout | 0:ea44dc9ed014 | 3656 | flags |= DEVICE_COPY_OBSOLETE; |
joeverbout | 0:ea44dc9ed014 | 3657 | else |
joeverbout | 0:ea44dc9ed014 | 3658 | flags &= ~DEVICE_COPY_OBSOLETE; |
joeverbout | 0:ea44dc9ed014 | 3659 | } |
joeverbout | 0:ea44dc9ed014 | 3660 | |
joeverbout | 0:ea44dc9ed014 | 3661 | inline UMatDataAutoLock::UMatDataAutoLock(UMatData* _u) : u(_u) { u->lock(); } |
joeverbout | 0:ea44dc9ed014 | 3662 | inline UMatDataAutoLock::~UMatDataAutoLock() { u->unlock(); } |
joeverbout | 0:ea44dc9ed014 | 3663 | |
joeverbout | 0:ea44dc9ed014 | 3664 | //! @endcond |
joeverbout | 0:ea44dc9ed014 | 3665 | |
joeverbout | 0:ea44dc9ed014 | 3666 | } //cv |
joeverbout | 0:ea44dc9ed014 | 3667 | |
joeverbout | 0:ea44dc9ed014 | 3668 | #endif |
joeverbout | 0:ea44dc9ed014 | 3669 |