00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef __OPENCV_CORE_MATRIX_OPERATIONS_HPP__
00044 #define __OPENCV_CORE_MATRIX_OPERATIONS_HPP__
00045
00046 #ifndef SKIP_INCLUDES
00047 #include <limits.h>
00048 #include <string.h>
00049 #endif // SKIP_INCLUDES
00050
00051 #ifdef __cplusplus
00052
00053 namespace cv
00054 {
00055
00057
00058 inline Mat::Mat()
00059 : flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
00060 datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
00061 {
00062 }
00063
00064 inline Mat::Mat(int _rows, int _cols, int _type)
00065 : flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
00066 datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
00067 {
00068 create(_rows, _cols, _type);
00069 }
00070
00071 inline Mat::Mat(int _rows, int _cols, int _type, const Scalar& _s)
00072 : flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
00073 datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
00074 {
00075 create(_rows, _cols, _type);
00076 *this = _s;
00077 }
00078
00079 inline Mat::Mat(Size _sz, int _type)
00080 : flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
00081 datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
00082 {
00083 create( _sz.height, _sz.width, _type );
00084 }
00085
00086 inline Mat::Mat(Size _sz, int _type, const Scalar& _s)
00087 : flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
00088 datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
00089 {
00090 create(_sz.height, _sz.width, _type);
00091 *this = _s;
00092 }
00093
00094 inline Mat::Mat(int _dims, const int* _sz, int _type)
00095 : flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
00096 datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
00097 {
00098 create(_dims, _sz, _type);
00099 }
00100
00101 inline Mat::Mat(int _dims, const int* _sz, int _type, const Scalar& _s)
00102 : flags(0), dims(0), rows(0), cols(0), data(0), refcount(0),
00103 datastart(0), dataend(0), datalimit(0), allocator(0), size(&rows)
00104 {
00105 create(_dims, _sz, _type);
00106 *this = _s;
00107 }
00108
00109 inline Mat::Mat(const Mat& m)
00110 : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data),
00111 refcount(m.refcount), datastart(m.datastart), dataend(m.dataend),
00112 datalimit(m.datalimit), allocator(m.allocator), size(&rows)
00113 {
00114 if( refcount )
00115 CV_XADD(refcount, 1);
00116 if( m.dims <= 2 )
00117 {
00118 step[0] = m.step[0]; step[1] = m.step[1];
00119 }
00120 else
00121 {
00122 dims = 0;
00123 copySize(m);
00124 }
00125 }
00126
00127 inline Mat::Mat(int _rows, int _cols, int _type, void* _data, size_t _step)
00128 : flags(MAGIC_VAL + (_type & TYPE_MASK)), dims(2), rows(_rows), cols(_cols),
00129 data((uchar*)_data), refcount(0), datastart((uchar*)_data), dataend(0),
00130 datalimit(0), allocator(0), size(&rows)
00131 {
00132 size_t esz = CV_ELEM_SIZE(_type), minstep = cols*esz;
00133 if( _step == AUTO_STEP )
00134 {
00135 _step = minstep;
00136 flags |= CONTINUOUS_FLAG;
00137 }
00138 else
00139 {
00140 if( rows == 1 ) _step = minstep;
00141 CV_DbgAssert( _step >= minstep );
00142 flags |= _step == minstep ? CONTINUOUS_FLAG : 0;
00143 }
00144 step[0] = _step; step[1] = esz;
00145 datalimit = datastart + _step*rows;
00146 dataend = datalimit - _step + minstep;
00147 }
00148
00149 inline Mat::Mat(Size _sz, int _type, void* _data, size_t _step)
00150 : flags(MAGIC_VAL + (_type & TYPE_MASK)), dims(2), rows(_sz.height), cols(_sz.width),
00151 data((uchar*)_data), refcount(0), datastart((uchar*)_data), dataend(0),
00152 datalimit(0), allocator(0), size(&rows)
00153 {
00154 size_t esz = CV_ELEM_SIZE(_type), minstep = cols*esz;
00155 if( _step == AUTO_STEP )
00156 {
00157 _step = minstep;
00158 flags |= CONTINUOUS_FLAG;
00159 }
00160 else
00161 {
00162 if( rows == 1 ) _step = minstep;
00163 CV_DbgAssert( _step >= minstep );
00164 flags |= _step == minstep ? CONTINUOUS_FLAG : 0;
00165 }
00166 step[0] = _step; step[1] = esz;
00167 datalimit = datastart + _step*rows;
00168 dataend = datalimit - _step + minstep;
00169 }
00170
00171
00172 inline Mat::Mat(const CvMat* m, bool copyData)
00173 : flags(MAGIC_VAL + (m->type & (CV_MAT_TYPE_MASK|CV_MAT_CONT_FLAG))),
00174 dims(2), rows(m->rows), cols(m->cols), data(m->data.ptr), refcount(0),
00175 datastart(m->data.ptr), allocator(0), size(&rows)
00176 {
00177 if( !copyData )
00178 {
00179 size_t esz = CV_ELEM_SIZE(m->type), minstep = cols*esz, _step = m->step;
00180 if( _step == 0 )
00181 _step = minstep;
00182 datalimit = datastart + _step*rows;
00183 dataend = datalimit - _step + minstep;
00184 step[0] = _step; step[1] = esz;
00185 }
00186 else
00187 {
00188 data = datastart = dataend = 0;
00189 Mat(m->rows, m->cols, m->type, m->data.ptr, m->step).copyTo(*this);
00190 }
00191 }
00192
00193 template<typename _Tp> inline Mat::Mat(const vector<_Tp>& vec, bool copyData)
00194 : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG),
00195 dims(2), rows((int)vec.size()), cols(1), data(0), refcount(0),
00196 datastart(0), dataend(0), allocator(0), size(&rows)
00197 {
00198 if(vec.empty())
00199 return;
00200 if( !copyData )
00201 {
00202 step[0] = step[1] = sizeof(_Tp);
00203 data = datastart = (uchar*)&vec[0];
00204 datalimit = dataend = datastart + rows*step[0];
00205 }
00206 else
00207 Mat((int)vec.size(), 1, DataType<_Tp>::type, (uchar*)&vec[0]).copyTo(*this);
00208 }
00209
00210
00211 template<typename _Tp, int n> inline Mat::Mat(const Vec<_Tp, n>& vec, bool copyData)
00212 : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG),
00213 dims(2), rows(n), cols(1), data(0), refcount(0),
00214 datastart(0), dataend(0), allocator(0), size(&rows)
00215 {
00216 if( !copyData )
00217 {
00218 step[0] = step[1] = sizeof(_Tp);
00219 data = datastart = (uchar*)vec.val;
00220 datalimit = dataend = datastart + rows*step[0];
00221 }
00222 else
00223 Mat(n, 1, DataType<_Tp>::type, (void*)vec.val).copyTo(*this);
00224 }
00225
00226
00227 template<typename _Tp, int m, int n> inline Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData)
00228 : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG),
00229 dims(2), rows(m), cols(n), data(0), refcount(0),
00230 datastart(0), dataend(0), allocator(0), size(&rows)
00231 {
00232 if( !copyData )
00233 {
00234 step[0] = cols*sizeof(_Tp);
00235 step[1] = sizeof(_Tp);
00236 data = datastart = (uchar*)M.val;
00237 datalimit = dataend = datastart + rows*step[0];
00238 }
00239 else
00240 Mat(m, n, DataType<_Tp>::type, (uchar*)M.val).copyTo(*this);
00241 }
00242
00243
00244 template<typename _Tp> inline Mat::Mat(const Point_<_Tp>& pt, bool copyData)
00245 : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG),
00246 dims(2), rows(2), cols(1), data(0), refcount(0),
00247 datastart(0), dataend(0), allocator(0), size(&rows)
00248 {
00249 if( !copyData )
00250 {
00251 step[0] = step[1] = sizeof(_Tp);
00252 data = datastart = (uchar*)&pt.x;
00253 datalimit = dataend = datastart + rows*step[0];
00254 }
00255 else
00256 {
00257 create(2, 1, DataType<_Tp>::type);
00258 ((_Tp*)data)[0] = pt.x;
00259 ((_Tp*)data)[1] = pt.y;
00260 }
00261 }
00262
00263
00264 template<typename _Tp> inline Mat::Mat(const Point3_<_Tp>& pt, bool copyData)
00265 : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG),
00266 dims(2), rows(3), cols(1), data(0), refcount(0),
00267 datastart(0), dataend(0), allocator(0), size(&rows)
00268 {
00269 if( !copyData )
00270 {
00271 step[0] = step[1] = sizeof(_Tp);
00272 data = datastart = (uchar*)&pt.x;
00273 datalimit = dataend = datastart + rows*step[0];
00274 }
00275 else
00276 {
00277 create(3, 1, DataType<_Tp>::type);
00278 ((_Tp*)data)[0] = pt.x;
00279 ((_Tp*)data)[1] = pt.y;
00280 ((_Tp*)data)[2] = pt.z;
00281 }
00282 }
00283
00284
00285 template<typename _Tp> inline Mat::Mat(const MatCommaInitializer_<_Tp>& commaInitializer)
00286 : flags(MAGIC_VAL | DataType<_Tp>::type | CV_MAT_CONT_FLAG),
00287 dims(0), rows(0), cols(0), data(0), refcount(0),
00288 datastart(0), dataend(0), allocator(0), size(&rows)
00289 {
00290 *this = *commaInitializer;
00291 }
00292
00293 inline Mat::~Mat()
00294 {
00295 release();
00296 if( step.p != step.buf )
00297 fastFree(step.p);
00298 }
00299
00300 inline Mat& Mat::operator = (const Mat& m)
00301 {
00302 if( this != &m )
00303 {
00304 if( m.refcount )
00305 CV_XADD(m.refcount, 1);
00306 release();
00307 flags = m.flags;
00308 if( dims <= 2 && m.dims <= 2 )
00309 {
00310 dims = m.dims;
00311 rows = m.rows;
00312 cols = m.cols;
00313 step[0] = m.step[0];
00314 step[1] = m.step[1];
00315 }
00316 else
00317 copySize(m);
00318 data = m.data;
00319 datastart = m.datastart;
00320 dataend = m.dataend;
00321 datalimit = m.datalimit;
00322 refcount = m.refcount;
00323 allocator = m.allocator;
00324 }
00325 return *this;
00326 }
00327
00328 inline Mat Mat::row(int y) const { return Mat(*this, Range(y, y+1), Range::all()); }
00329 inline Mat Mat::col(int x) const { return Mat(*this, Range::all(), Range(x, x+1)); }
00330 inline Mat Mat::rowRange(int startrow, int endrow) const
00331 { return Mat(*this, Range(startrow, endrow), Range::all()); }
00332 inline Mat Mat::rowRange(const Range& r) const
00333 { return Mat(*this, r, Range::all()); }
00334 inline Mat Mat::colRange(int startcol, int endcol) const
00335 { return Mat(*this, Range::all(), Range(startcol, endcol)); }
00336 inline Mat Mat::colRange(const Range& r) const
00337 { return Mat(*this, Range::all(), r); }
00338
00339 inline Mat Mat::diag(const Mat& d)
00340 {
00341 Mat m(d.rows, d.rows, d.type(), Scalar(0)), md = m.diag();
00342 d.copyTo(md);
00343 return m;
00344 }
00345
00346 inline Mat Mat::clone() const
00347 {
00348 Mat m;
00349 copyTo(m);
00350 return m;
00351 }
00352
00353 inline void Mat::assignTo( Mat& m, int type ) const
00354 {
00355 if( type < 0 )
00356 m = *this;
00357 else
00358 convertTo(m, type);
00359 }
00360
00361 inline void Mat::create(int _rows, int _cols, int _type)
00362 {
00363 _type &= TYPE_MASK;
00364 if( dims <= 2 && rows == _rows && cols == _cols && type() == _type && data )
00365 return;
00366 int sz[] = {_rows, _cols};
00367 create(2, sz, _type);
00368 }
00369
00370 inline void Mat::create(Size _sz, int _type)
00371 {
00372 create(_sz.height, _sz.width, _type);
00373 }
00374
00375 inline void Mat::addref()
00376 { if( refcount ) CV_XADD(refcount, 1); }
00377
00378 inline void Mat::release()
00379 {
00380 if( refcount && CV_XADD(refcount, -1) == 1 )
00381 deallocate();
00382 data = datastart = dataend = datalimit = 0;
00383 size.p[0] = 0;
00384 refcount = 0;
00385 }
00386
00387 inline Mat Mat::operator()( Range rowRange, Range colRange ) const
00388 {
00389 return Mat(*this, rowRange, colRange);
00390 }
00391
00392 inline Mat Mat::operator()( const Rect& roi ) const
00393 { return Mat(*this, roi); }
00394
00395 inline Mat Mat::operator()(const Range* ranges) const
00396 {
00397 return Mat(*this, ranges);
00398 }
00399
00400 inline Mat::operator CvMat() const
00401 {
00402 CV_DbgAssert(dims <= 2);
00403 CvMat m = cvMat(rows, dims == 1 ? 1 : cols, type(), data);
00404 m.step = (int)step[0];
00405 m.type = (m.type & ~CONTINUOUS_FLAG) | (flags & CONTINUOUS_FLAG);
00406 return m;
00407 }
00408
00409 inline bool Mat::isContinuous() const { return (flags & CONTINUOUS_FLAG) != 0; }
00410 inline bool Mat::isSubmatrix() const { return (flags & SUBMATRIX_FLAG) != 0; }
00411 inline size_t Mat::elemSize() const { return dims > 0 ? step.p[dims-1] : 0; }
00412 inline size_t Mat::elemSize1() const { return CV_ELEM_SIZE1(flags); }
00413 inline int Mat::type() const { return CV_MAT_TYPE(flags); }
00414 inline int Mat::depth() const { return CV_MAT_DEPTH(flags); }
00415 inline int Mat::channels() const { return CV_MAT_CN(flags); }
00416 inline size_t Mat::step1(int i) const { return step.p[i]/elemSize1(); }
00417 inline bool Mat::empty() const { return data == 0 || total() == 0; }
00418 inline size_t Mat::total() const
00419 {
00420 if( dims <= 2 )
00421 return rows*cols;
00422 size_t p = 1;
00423 for( int i = 0; i < dims; i++ )
00424 p *= size[i];
00425 return p;
00426 }
00427
00428 inline uchar* Mat::ptr(int y)
00429 {
00430 CV_DbgAssert( data && dims >= 1 && (unsigned)y < (unsigned)size.p[0] );
00431 return data + step.p[0]*y;
00432 }
00433
00434 inline const uchar* Mat::ptr(int y) const
00435 {
00436 CV_DbgAssert( data && dims >= 1 && (unsigned)y < (unsigned)size.p[0] );
00437 return data + step.p[0]*y;
00438 }
00439
00440 template<typename _Tp> inline _Tp* Mat::ptr(int y)
00441 {
00442 CV_DbgAssert( data && dims >= 1 && (unsigned)y < (unsigned)size.p[0] );
00443 return (_Tp*)(data + step.p[0]*y);
00444 }
00445
00446 template<typename _Tp> inline const _Tp* Mat::ptr(int y) const
00447 {
00448 CV_DbgAssert( dims >= 1 && data && (unsigned)y < (unsigned)size.p[0] );
00449 return (const _Tp*)(data + step.p[0]*y);
00450 }
00451
00452
00453 inline uchar* Mat::ptr(int i0, int i1)
00454 {
00455 CV_DbgAssert( dims >= 2 && data &&
00456 (unsigned)i0 < (unsigned)size.p[0] &&
00457 (unsigned)i1 < (unsigned)size.p[1] );
00458 return data + i0*step.p[0] + i1*step.p[1];
00459 }
00460
00461 inline const uchar* Mat::ptr(int i0, int i1) const
00462 {
00463 CV_DbgAssert( dims >= 2 && data &&
00464 (unsigned)i0 < (unsigned)size.p[0] &&
00465 (unsigned)i1 < (unsigned)size.p[1] );
00466 return data + i0*step.p[0] + i1*step.p[1];
00467 }
00468
00469 inline uchar* Mat::ptr(int i0, int i1, int i2)
00470 {
00471 CV_DbgAssert( dims >= 3 && data &&
00472 (unsigned)i0 < (unsigned)size.p[0] &&
00473 (unsigned)i1 < (unsigned)size.p[1] &&
00474 (unsigned)i2 < (unsigned)size.p[2] );
00475 return data + i0*step.p[0] + i1*step.p[1] + i2*step.p[2];
00476 }
00477
00478 inline const uchar* Mat::ptr(int i0, int i1, int i2) const
00479 {
00480 CV_DbgAssert( dims >= 3 && data &&
00481 (unsigned)i0 < (unsigned)size.p[0] &&
00482 (unsigned)i1 < (unsigned)size.p[1] &&
00483 (unsigned)i2 < (unsigned)size.p[2] );
00484 return data + i0*step.p[0] + i1*step.p[1] + i2*step.p[2];
00485 }
00486
00487 inline uchar* Mat::ptr(const int* idx)
00488 {
00489 int i, d = dims;
00490 uchar* p = data;
00491 CV_DbgAssert( d >= 1 && p );
00492 for( i = 0; i < d; i++ )
00493 {
00494 CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] );
00495 p += idx[i]*step.p[i];
00496 }
00497 return p;
00498 }
00499
00500 inline const uchar* Mat::ptr(const int* idx) const
00501 {
00502 int i, d = dims;
00503 uchar* p = data;
00504 CV_DbgAssert( d >= 1 && p );
00505 for( i = 0; i < d; i++ )
00506 {
00507 CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] );
00508 p += idx[i]*step.p[i];
00509 }
00510 return p;
00511 }
00512
00513 template<typename _Tp> inline _Tp& Mat::at(int i0, int i1)
00514 {
00515 CV_DbgAssert( dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] &&
00516 (unsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channels()) &&
00517 CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1());
00518 return ((_Tp*)(data + step.p[0]*i0))[i1];
00519 }
00520
00521 template<typename _Tp> inline const _Tp& Mat::at(int i0, int i1) const
00522 {
00523 CV_DbgAssert( dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] &&
00524 (unsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channels()) &&
00525 CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1());
00526 return ((const _Tp*)(data + step.p[0]*i0))[i1];
00527 }
00528
00529 template<typename _Tp> inline _Tp& Mat::at(Point pt)
00530 {
00531 CV_DbgAssert( dims <= 2 && data && (unsigned)pt.y < (unsigned)size.p[0] &&
00532 (unsigned)(pt.x*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channels()) &&
00533 CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1());
00534 return ((_Tp*)(data + step.p[0]*pt.y))[pt.x];
00535 }
00536
00537 template<typename _Tp> inline const _Tp& Mat::at(Point pt) const
00538 {
00539 CV_DbgAssert( dims <= 2 && data && (unsigned)pt.y < (unsigned)size.p[0] &&
00540 (unsigned)(pt.x*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channels()) &&
00541 CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1());
00542 return ((const _Tp*)(data + step.p[0]*pt.y))[pt.x];
00543 }
00544
00545 template<typename _Tp> inline _Tp& Mat::at(int i0)
00546 {
00547 CV_DbgAssert( dims <= 2 && data && (size.p[0] == 1 || size.p[1] == 1) &&
00548 (unsigned)i0 < (unsigned)(size.p[0] + size.p[1] - 1) &&
00549 elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) );
00550 return *(_Tp*)(data + step.p[size.p[0]==1]*i0);
00551 }
00552
00553 template<typename _Tp> inline const _Tp& Mat::at(int i0) const
00554 {
00555 CV_DbgAssert( dims <= 2 && data && (size.p[0] == 1 || size.p[1] == 1) &&
00556 (unsigned)i0 < (unsigned)(size.p[0] + size.p[1] - 1) &&
00557 elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) );
00558 return *(_Tp*)(data + step.p[size.p[0]==1]*i0);
00559 }
00560
00561 template<typename _Tp> inline _Tp& Mat::at(int i0, int i1, int i2)
00562 {
00563 CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) );
00564 return *(_Tp*)ptr(i0, i1, i2);
00565 }
00566 template<typename _Tp> inline const _Tp& Mat::at(int i0, int i1, int i2) const
00567 {
00568 CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) );
00569 return *(const _Tp*)ptr(i0, i1, i2);
00570 }
00571 template<typename _Tp> inline _Tp& Mat::at(const int* idx)
00572 {
00573 CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) );
00574 return *(_Tp*)ptr(idx);
00575 }
00576 template<typename _Tp> inline const _Tp& Mat::at(const int* idx) const
00577 {
00578 CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) );
00579 return *(const _Tp*)ptr(idx);
00580 }
00581
00582
00583 template<typename _Tp> inline MatConstIterator_<_Tp> Mat::begin() const
00584 {
00585 CV_DbgAssert( elemSize() == sizeof(_Tp) );
00586 return MatConstIterator_<_Tp>((const Mat_<_Tp>*)this);
00587 }
00588
00589 template<typename _Tp> inline MatConstIterator_<_Tp> Mat::end() const
00590 {
00591 CV_DbgAssert( elemSize() == sizeof(_Tp) );
00592 MatConstIterator_<_Tp> it((const Mat_<_Tp>*)this);
00593 it += total();
00594 return it;
00595 }
00596
00597 template<typename _Tp> inline MatIterator_<_Tp> Mat::begin()
00598 {
00599 CV_DbgAssert( elemSize() == sizeof(_Tp) );
00600 return MatIterator_<_Tp>((Mat_<_Tp>*)this);
00601 }
00602
00603 template<typename _Tp> inline MatIterator_<_Tp> Mat::end()
00604 {
00605 CV_DbgAssert( elemSize() == sizeof(_Tp) );
00606 MatIterator_<_Tp> it((Mat_<_Tp>*)this);
00607 it += total();
00608 return it;
00609 }
00610
00611
00612 template<typename _Tp> inline void Mat::copyTo(vector<_Tp>& v) const
00613 {
00614 int n = checkVector(DataType<_Tp>::channels);
00615 if( empty() || n == 0 )
00616 {
00617 v.clear();
00618 return;
00619 }
00620 CV_Assert( n > 0 );
00621 v.resize(n);
00622 Mat temp(dims, size.p, DataType<_Tp>::type, &v[0]);
00623 convertTo(temp, DataType<_Tp>::type);
00624 }
00625
00626 template<typename _Tp> inline Mat::operator vector<_Tp>() const
00627 {
00628 vector<_Tp> v;
00629 copyTo(v);
00630 return v;
00631 }
00632
00633 template<typename _Tp, int n> inline Mat::operator Vec<_Tp, n>() const
00634 {
00635 CV_Assert( data && dims <= 2 && (rows == 1 || cols == 1) &&
00636 rows + cols - 1 == n && channels() == 1 );
00637
00638 if( isContinuous() && type() == DataType<_Tp>::type )
00639 return Vec<_Tp, n>((_Tp*)data);
00640 Vec<_Tp, n> v; Mat tmp(rows, cols, DataType<_Tp>::type, v.val);
00641 convertTo(tmp, tmp.type());
00642 return v;
00643 }
00644
00645 template<typename _Tp, int m, int n> inline Mat::operator Matx<_Tp, m, n>() const
00646 {
00647 CV_Assert( data && dims <= 2 && rows == m && cols == n && channels() == 1 );
00648
00649 if( isContinuous() && type() == DataType<_Tp>::type )
00650 return Matx<_Tp, m, n>((_Tp*)data);
00651 Matx<_Tp, m, n> mtx; Mat tmp(rows, cols, DataType<_Tp>::type, mtx.val);
00652 convertTo(tmp, tmp.type());
00653 return mtx;
00654 }
00655
00656
00657 template<typename _Tp> inline void Mat::push_back(const _Tp& elem)
00658 {
00659 CV_Assert(DataType<_Tp>::type == type() && cols == 1
00660 );
00661 uchar* tmp = dataend + step[0];
00662 if( !isSubmatrix() && isContinuous() && tmp <= datalimit )
00663 {
00664 *(_Tp*)(data + (size.p[0]++)*step.p[0]) = elem;
00665 dataend = tmp;
00666 }
00667 else
00668 push_back_(&elem);
00669 }
00670
00671 template<typename _Tp> inline void Mat::push_back(const Mat_<_Tp>& m)
00672 {
00673 push_back((const Mat&)m);
00674 }
00675
00676 inline Mat::MSize::MSize(int* _p) : p(_p) {}
00677 inline Size Mat::MSize::operator()() const
00678 {
00679 CV_DbgAssert(p[-1] <= 2);
00680 return Size(p[1], p[0]);
00681 }
00682 inline int Mat::MSize::operator[](int i) const { return p[i]; }
00683 inline int& Mat::MSize::operator[](int i) { return p[i]; }
00684 inline Mat::MSize::operator const int*() const { return p; }
00685
00686 inline bool Mat::MSize::operator == (const MSize& sz) const
00687 {
00688 int d = p[-1], dsz = sz.p[-1];
00689 if( d != dsz )
00690 return false;
00691 if( d == 2 )
00692 return p[0] == sz.p[0] && p[1] == sz.p[1];
00693
00694 for( int i = 0; i < d; i++ )
00695 if( p[i] != sz.p[i] )
00696 return false;
00697 return true;
00698 }
00699
00700 inline bool Mat::MSize::operator != (const MSize& sz) const
00701 {
00702 return !(*this == sz);
00703 }
00704
00705 inline Mat::MStep::MStep() { p = buf; p[0] = p[1] = 0; }
00706 inline Mat::MStep::MStep(size_t s) { p = buf; p[0] = s; p[1] = 0; }
00707 inline size_t Mat::MStep::operator[](int i) const { return p[i]; }
00708 inline size_t& Mat::MStep::operator[](int i) { return p[i]; }
00709 inline Mat::MStep::operator size_t() const
00710 {
00711 CV_DbgAssert( p == buf );
00712 return buf[0];
00713 }
00714 inline Mat::MStep& Mat::MStep::operator = (size_t s)
00715 {
00716 CV_DbgAssert( p == buf );
00717 buf[0] = s;
00718 return *this;
00719 }
00720
00721 static inline Mat cvarrToMatND(const CvArr* arr, bool copyData=false, int coiMode=0)
00722 {
00723 return cvarrToMat(arr, copyData, true, coiMode);
00724 }
00725
00727
00728 inline SVD::SVD() {}
00729 inline SVD::SVD( const Mat& m, int flags ) { operator ()(m, flags); }
00730 inline void SVD::solveZ( const Mat& m, Mat& dst )
00731 {
00732 SVD svd(m);
00733 svd.vt.row(svd.vt.rows-1).reshape(1,svd.vt.cols).copyTo(dst);
00734 }
00735
00736 template<typename _Tp, int m, int n, int nm> inline void
00737 SVD::compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w, Matx<_Tp, m, nm>& u, Matx<_Tp, n, nm>& vt )
00738 {
00739 assert( nm == MIN(m, n));
00740 Mat _a(a, false), _u(u, false), _w(w, false), _vt(vt, false);
00741 SVD::compute(_a, _w, _u, _vt);
00742 CV_Assert(_w.data == (uchar*)&w.val[0] && _u.data == (uchar*)&u.val[0] && _vt.data == (uchar*)&vt.val[0]);
00743 }
00744
00745 template<typename _Tp, int m, int n, int nm> inline void
00746 SVD::compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w )
00747 {
00748 assert( nm == MIN(m, n));
00749 Mat _a(a, false), _w(w, false);
00750 SVD::compute(_a, _w);
00751 CV_Assert(_w.data == (uchar*)&w.val[0]);
00752 }
00753
00754 template<typename _Tp, int m, int n, int nm, int nb> inline void
00755 SVD::backSubst( const Matx<_Tp, nm, 1>& w, const Matx<_Tp, m, nm>& u,
00756 const Matx<_Tp, n, nm>& vt, const Matx<_Tp, m, nb>& rhs,
00757 Matx<_Tp, n, nb>& dst )
00758 {
00759 assert( nm == MIN(m, n));
00760 Mat _u(u, false), _w(w, false), _vt(vt, false), _rhs(rhs, false), _dst(dst, false);
00761 SVD::backSubst(_w, _u, _vt, _rhs, _dst);
00762 CV_Assert(_dst.data == (uchar*)&dst.val[0]);
00763 }
00764
00766
00767 template<typename _Tp> inline Mat_<_Tp>::Mat_()
00768 : Mat() { flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type; }
00769
00770 template<typename _Tp> inline Mat_<_Tp>::Mat_(int _rows, int _cols)
00771 : Mat(_rows, _cols, DataType<_Tp>::type) {}
00772
00773 template<typename _Tp> inline Mat_<_Tp>::Mat_(int _rows, int _cols, const _Tp& value)
00774 : Mat(_rows, _cols, DataType<_Tp>::type) { *this = value; }
00775
00776 template<typename _Tp> inline Mat_<_Tp>::Mat_(Size _sz)
00777 : Mat(_sz.height, _sz.width, DataType<_Tp>::type) {}
00778
00779 template<typename _Tp> inline Mat_<_Tp>::Mat_(Size _sz, const _Tp& value)
00780 : Mat(_sz.height, _sz.width, DataType<_Tp>::type) { *this = value; }
00781
00782 template<typename _Tp> inline Mat_<_Tp>::Mat_(int _dims, const int* _sz)
00783 : Mat(_dims, _sz, DataType<_Tp>::type) {}
00784
00785 template<typename _Tp> inline Mat_<_Tp>::Mat_(int _dims, const int* _sz, const _Tp& _s)
00786 : Mat(_dims, _sz, DataType<_Tp>::type, Scalar(_s)) {}
00787
00788 template<typename _Tp> inline Mat_<_Tp>::Mat_(const Mat_<_Tp>& m, const Range* ranges)
00789 : Mat(m, ranges) {}
00790
00791 template<typename _Tp> inline Mat_<_Tp>::Mat_(const Mat& m)
00792 : Mat() { flags = (flags & ~CV_MAT_TYPE_MASK) | DataType<_Tp>::type; *this = m; }
00793
00794 template<typename _Tp> inline Mat_<_Tp>::Mat_(const Mat_& m)
00795 : Mat(m) {}
00796
00797 template<typename _Tp> inline Mat_<_Tp>::Mat_(int _rows, int _cols, _Tp* _data, size_t steps)
00798 : Mat(_rows, _cols, DataType<_Tp>::type, _data, steps) {}
00799
00800 template<typename _Tp> inline Mat_<_Tp>::Mat_(const Mat_& m, const Range& rowRange, const Range& colRange)
00801 : Mat(m, rowRange, colRange) {}
00802
00803 template<typename _Tp> inline Mat_<_Tp>::Mat_(const Mat_& m, const Rect& roi)
00804 : Mat(m, roi) {}
00805
00806 template<typename _Tp> template<int n> inline
00807 Mat_<_Tp>::Mat_(const Vec<typename DataType<_Tp>::channel_type, n>& vec, bool copyData)
00808 : Mat(n/DataType<_Tp>::channels, 1, DataType<_Tp>::type, (void*)&vec)
00809 {
00810 CV_Assert(n%DataType<_Tp>::channels == 0);
00811 if( copyData )
00812 *this = clone();
00813 }
00814
00815 template<typename _Tp> template<int m, int n> inline
00816 Mat_<_Tp>::Mat_(const Matx<typename DataType<_Tp>::channel_type,m,n>& M, bool copyData)
00817 : Mat(m, n/DataType<_Tp>::channels, DataType<_Tp>::type, (void*)&M)
00818 {
00819 CV_Assert(n % DataType<_Tp>::channels == 0);
00820 if( copyData )
00821 *this = clone();
00822 }
00823
00824 template<typename _Tp> inline Mat_<_Tp>::Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool copyData)
00825 : Mat(2/DataType<_Tp>::channels, 1, DataType<_Tp>::type, (void*)&pt)
00826 {
00827 CV_Assert(2 % DataType<_Tp>::channels == 0);
00828 if( copyData )
00829 *this = clone();
00830 }
00831
00832 template<typename _Tp> inline Mat_<_Tp>::Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData)
00833 : Mat(3/DataType<_Tp>::channels, 1, DataType<_Tp>::type, (void*)&pt)
00834 {
00835 CV_Assert(3 % DataType<_Tp>::channels == 0);
00836 if( copyData )
00837 *this = clone();
00838 }
00839
00840 template<typename _Tp> inline Mat_<_Tp>::Mat_(const MatCommaInitializer_<_Tp>& commaInitializer)
00841 : Mat(commaInitializer) {}
00842
00843 template<typename _Tp> inline Mat_<_Tp>::Mat_(const vector<_Tp>& vec, bool copyData)
00844 : Mat(vec, copyData) {}
00845
00846 template<typename _Tp> inline Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat& m)
00847 {
00848 if( DataType<_Tp>::type == m.type() )
00849 {
00850 Mat::operator = (m);
00851 return *this;
00852 }
00853 if( DataType<_Tp>::depth == m.depth() )
00854 {
00855 return (*this = m.reshape(DataType<_Tp>::channels, m.dims, 0));
00856 }
00857 CV_DbgAssert(DataType<_Tp>::channels == m.channels());
00858 m.convertTo(*this, type());
00859 return *this;
00860 }
00861
00862 template<typename _Tp> inline Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat_& m)
00863 {
00864 Mat::operator=(m);
00865 return *this;
00866 }
00867
00868 template<typename _Tp> inline Mat_<_Tp>& Mat_<_Tp>::operator = (const _Tp& s)
00869 {
00870 typedef typename DataType<_Tp>::vec_type VT;
00871 Mat::operator=(Scalar((const VT&)s));
00872 return *this;
00873 }
00874
00875
00876 template<typename _Tp> inline void Mat_<_Tp>::create(int _rows, int _cols)
00877 {
00878 Mat::create(_rows, _cols, DataType<_Tp>::type);
00879 }
00880
00881 template<typename _Tp> inline void Mat_<_Tp>::create(Size _sz)
00882 {
00883 Mat::create(_sz, DataType<_Tp>::type);
00884 }
00885
00886 template<typename _Tp> inline void Mat_<_Tp>::create(int _dims, const int* _sz)
00887 {
00888 Mat::create(_dims, _sz, DataType<_Tp>::type);
00889 }
00890
00891
00892 template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::cross(const Mat_& m) const
00893 { return Mat_<_Tp>(Mat::cross(m)); }
00894
00895 template<typename _Tp> template<typename T2> inline Mat_<_Tp>::operator Mat_<T2>() const
00896 { return Mat_<T2>(*this); }
00897
00898 template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::row(int y) const
00899 { return Mat_(*this, Range(y, y+1), Range::all()); }
00900 template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::col(int x) const
00901 { return Mat_(*this, Range::all(), Range(x, x+1)); }
00902 template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::diag(int d) const
00903 { return Mat_(Mat::diag(d)); }
00904 template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::clone() const
00905 { return Mat_(Mat::clone()); }
00906
00907 template<typename _Tp> inline size_t Mat_<_Tp>::elemSize() const
00908 {
00909 CV_DbgAssert( Mat::elemSize() == sizeof(_Tp) );
00910 return sizeof(_Tp);
00911 }
00912
00913 template<typename _Tp> inline size_t Mat_<_Tp>::elemSize1() const
00914 {
00915 CV_DbgAssert( Mat::elemSize1() == sizeof(_Tp)/DataType<_Tp>::channels );
00916 return sizeof(_Tp)/DataType<_Tp>::channels;
00917 }
00918 template<typename _Tp> inline int Mat_<_Tp>::type() const
00919 {
00920 CV_DbgAssert( Mat::type() == DataType<_Tp>::type );
00921 return DataType<_Tp>::type;
00922 }
00923 template<typename _Tp> inline int Mat_<_Tp>::depth() const
00924 {
00925 CV_DbgAssert( Mat::depth() == DataType<_Tp>::depth );
00926 return DataType<_Tp>::depth;
00927 }
00928 template<typename _Tp> inline int Mat_<_Tp>::channels() const
00929 {
00930 CV_DbgAssert( Mat::channels() == DataType<_Tp>::channels );
00931 return DataType<_Tp>::channels;
00932 }
00933 template<typename _Tp> inline size_t Mat_<_Tp>::stepT(int i) const { return step.p[i]/elemSize(); }
00934 template<typename _Tp> inline size_t Mat_<_Tp>::step1(int i) const { return step.p[i]/elemSize1(); }
00935
00936 template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::reshape(int _rows) const
00937 { return Mat_<_Tp>(Mat::reshape(0,_rows)); }
00938
00939 template<typename _Tp> inline Mat_<_Tp>& Mat_<_Tp>::adjustROI( int dtop, int dbottom, int dleft, int dright )
00940 { return (Mat_<_Tp>&)(Mat::adjustROI(dtop, dbottom, dleft, dright)); }
00941
00942 template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::operator()( const Range& rowRange, const Range& colRange ) const
00943 { return Mat_<_Tp>(*this, rowRange, colRange); }
00944
00945 template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::operator()( const Rect& roi ) const
00946 { return Mat_<_Tp>(*this, roi); }
00947
00948 template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::operator()( const Range* ranges ) const
00949 { return Mat_<_Tp>(*this, ranges); }
00950
00951 template<typename _Tp> inline _Tp* Mat_<_Tp>::operator [](int y)
00952 { return (_Tp*)ptr(y); }
00953 template<typename _Tp> inline const _Tp* Mat_<_Tp>::operator [](int y) const
00954 { return (const _Tp*)ptr(y); }
00955
00956 template<typename _Tp> inline _Tp& Mat_<_Tp>::operator ()(int i0, int i1)
00957 {
00958 CV_DbgAssert( dims <= 2 && data &&
00959 (unsigned)i0 < (unsigned)size.p[0] &&
00960 (unsigned)i1 < (unsigned)size.p[1] &&
00961 type() == DataType<_Tp>::type );
00962 return ((_Tp*)(data + step.p[0]*i0))[i1];
00963 }
00964
00965 template<typename _Tp> inline const _Tp& Mat_<_Tp>::operator ()(int i0, int i1) const
00966 {
00967 CV_DbgAssert( dims <= 2 && data &&
00968 (unsigned)i0 < (unsigned)size.p[0] &&
00969 (unsigned)i1 < (unsigned)size.p[1] &&
00970 type() == DataType<_Tp>::type );
00971 return ((const _Tp*)(data + step.p[0]*i0))[i1];
00972 }
00973
00974 template<typename _Tp> inline _Tp& Mat_<_Tp>::operator ()(Point pt)
00975 {
00976 CV_DbgAssert( dims <= 2 && data &&
00977 (unsigned)pt.y < (unsigned)size.p[0] &&
00978 (unsigned)pt.x < (unsigned)size.p[1] &&
00979 type() == DataType<_Tp>::type );
00980 return ((_Tp*)(data + step.p[0]*pt.y))[pt.x];
00981 }
00982
00983 template<typename _Tp> inline const _Tp& Mat_<_Tp>::operator ()(Point pt) const
00984 {
00985 CV_DbgAssert( dims <= 2 && data &&
00986 (unsigned)pt.y < (unsigned)size.p[0] &&
00987 (unsigned)pt.x < (unsigned)size.p[1] &&
00988 type() == DataType<_Tp>::type );
00989 return ((const _Tp*)(data + step.p[0]*pt.y))[pt.x];
00990 }
00991
00992 template<typename _Tp> inline _Tp& Mat_<_Tp>::operator ()(const int* idx)
00993 {
00994 return Mat::at<_Tp>(idx);
00995 }
00996
00997 template<typename _Tp> inline const _Tp& Mat_<_Tp>::operator ()(const int* idx) const
00998 {
00999 return Mat::at<_Tp>(idx);
01000 }
01001
01002 template<typename _Tp> inline _Tp& Mat_<_Tp>::operator ()(int i0)
01003 {
01004 return this->at<_Tp>(i0);
01005 }
01006
01007 template<typename _Tp> inline const _Tp& Mat_<_Tp>::operator ()(int i0) const
01008 {
01009 return this->at<_Tp>(i0);
01010 }
01011
01012 template<typename _Tp> inline _Tp& Mat_<_Tp>::operator ()(int i0, int i1, int i2)
01013 {
01014 return this->at<_Tp>(i0, i1, i2);
01015 }
01016
01017 template<typename _Tp> inline const _Tp& Mat_<_Tp>::operator ()(int i0, int i1, int i2) const
01018 {
01019 return this->at<_Tp>(i0, i1, i2);
01020 }
01021
01022
01023 template<typename _Tp> inline Mat_<_Tp>::operator vector<_Tp>() const
01024 {
01025 vector<_Tp> v;
01026 copyTo(v);
01027 return v;
01028 }
01029
01030 template<typename _Tp> template<int n> inline Mat_<_Tp>::operator Vec<typename DataType<_Tp>::channel_type, n>() const
01031 {
01032 CV_Assert(n % DataType<_Tp>::channels == 0);
01033 return this->Mat::operator Vec<typename DataType<_Tp>::channel_type, n>();
01034 }
01035
01036 template<typename _Tp> template<int m, int n> inline Mat_<_Tp>::operator Matx<typename DataType<_Tp>::channel_type, m, n>() const
01037 {
01038 CV_Assert(n % DataType<_Tp>::channels == 0);
01039 return this->Mat::operator Matx<typename DataType<_Tp>::channel_type, m, n>();
01040 }
01041
01042 template<typename T1, typename T2, typename Op> inline void
01043 process( const Mat_<T1>& m1, Mat_<T2>& m2, Op op )
01044 {
01045 int y, x, rows = m1.rows, cols = m1.cols;
01046 int c1 = m1.channels(), c2 = m2.channels();
01047
01048 CV_DbgAssert( m1.size() == m2.size() );
01049
01050 for( y = 0; y < rows; y++ )
01051 {
01052 const T1* src = m1[y];
01053 T2* dst = m2[y];
01054
01055 for( x = 0; x < cols; x++ )
01056 dst[x] = op(src[x]);
01057 }
01058 }
01059
01060 template<typename T1, typename T2, typename T3, typename Op> inline void
01061 process( const Mat_<T1>& m1, const Mat_<T2>& m2, Mat_<T3>& m3, Op op )
01062 {
01063 int y, x, rows = m1.rows, cols = m1.cols;
01064
01065 CV_DbgAssert( m1.size() == m2.size() );
01066
01067 for( y = 0; y < rows; y++ )
01068 {
01069 const T1* src1 = m1[y];
01070 const T2* src2 = m2[y];
01071 T3* dst = m3[y];
01072
01073 for( x = 0; x < cols; x++ )
01074 dst[x] = op( src1[x], src2[x] );
01075 }
01076 }
01077
01079
01080 class CV_EXPORTS MatOp
01081 {
01082 public:
01083 MatOp() {};
01084 virtual ~MatOp() {};
01085
01086 virtual bool elementWise(const MatExpr& expr) const;
01087 virtual void assign(const MatExpr& expr, Mat& m, int type=-1) const = 0;
01088 virtual void roi(const MatExpr& expr, const Range& rowRange,
01089 const Range& colRange, MatExpr& res) const;
01090 virtual void diag(const MatExpr& expr, int d, MatExpr& res) const;
01091 virtual void augAssignAdd(const MatExpr& expr, Mat& m) const;
01092 virtual void augAssignSubtract(const MatExpr& expr, Mat& m) const;
01093 virtual void augAssignMultiply(const MatExpr& expr, Mat& m) const;
01094 virtual void augAssignDivide(const MatExpr& expr, Mat& m) const;
01095 virtual void augAssignAnd(const MatExpr& expr, Mat& m) const;
01096 virtual void augAssignOr(const MatExpr& expr, Mat& m) const;
01097 virtual void augAssignXor(const MatExpr& expr, Mat& m) const;
01098
01099 virtual void add(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const;
01100 virtual void add(const MatExpr& expr1, const Scalar& s, MatExpr& res) const;
01101
01102 virtual void subtract(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const;
01103 virtual void subtract(const Scalar& s, const MatExpr& expr, MatExpr& res) const;
01104
01105 virtual void multiply(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res, double scale=1) const;
01106 virtual void multiply(const MatExpr& expr1, double s, MatExpr& res) const;
01107
01108 virtual void divide(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res, double scale=1) const;
01109 virtual void divide(double s, const MatExpr& expr, MatExpr& res) const;
01110
01111 virtual void abs(const MatExpr& expr, MatExpr& res) const;
01112
01113 virtual void transpose(const MatExpr& expr, MatExpr& res) const;
01114 virtual void matmul(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const;
01115 virtual void invert(const MatExpr& expr, int method, MatExpr& res) const;
01116 };
01117
01118
01119 class CV_EXPORTS MatExpr
01120 {
01121 public:
01122 MatExpr() : op(0), flags(0), a(Mat()), b(Mat()), c(Mat()), alpha(0), beta(0), s(Scalar()) {}
01123 MatExpr(const MatOp* _op, int _flags, const Mat& _a=Mat(), const Mat& _b=Mat(),
01124 const Mat& _c=Mat(), double _alpha=1, double _beta=1, const Scalar& _s=Scalar())
01125 : op(_op), flags(_flags), a(_a), b(_b), c(_c), alpha(_alpha), beta(_beta), s(_s) {}
01126 explicit MatExpr(const Mat& m);
01127 operator Mat() const
01128 {
01129 Mat m;
01130 op->assign(*this, m);
01131 return m;
01132 }
01133
01134 template<typename _Tp> operator Mat_<_Tp>() const
01135 {
01136 Mat_<_Tp> m;
01137 op->assign(*this, m, DataType<_Tp>::type);
01138 return m;
01139 }
01140
01141 MatExpr row(int y) const;
01142 MatExpr col(int x) const;
01143 MatExpr diag(int d=0) const;
01144 MatExpr operator()( const Range& rowRange, const Range& colRange ) const;
01145 MatExpr operator()( const Rect& roi ) const;
01146
01147 Mat cross(const Mat& m) const;
01148 double dot(const Mat& m) const;
01149
01150 MatExpr t() const;
01151 MatExpr inv(int method = DECOMP_LU) const;
01152 MatExpr mul(const MatExpr& e, double scale=1) const;
01153 MatExpr mul(const Mat& m, double scale=1) const;
01154
01155 const MatOp* op;
01156 int flags;
01157
01158 Mat a, b, c;
01159 double alpha, beta;
01160 Scalar s;
01161 };
01162
01163
01164 CV_EXPORTS MatExpr operator + (const Mat& a, const Mat& b);
01165 CV_EXPORTS MatExpr operator + (const Mat& a, const Scalar& s);
01166 CV_EXPORTS MatExpr operator + (const Scalar& s, const Mat& a);
01167 CV_EXPORTS MatExpr operator + (const MatExpr& e, const Mat& m);
01168 CV_EXPORTS MatExpr operator + (const Mat& m, const MatExpr& e);
01169 CV_EXPORTS MatExpr operator + (const MatExpr& e, const Scalar& s);
01170 CV_EXPORTS MatExpr operator + (const Scalar& s, const MatExpr& e);
01171 CV_EXPORTS MatExpr operator + (const MatExpr& e1, const MatExpr& e2);
01172
01173 CV_EXPORTS MatExpr operator - (const Mat& a, const Mat& b);
01174 CV_EXPORTS MatExpr operator - (const Mat& a, const Scalar& s);
01175 CV_EXPORTS MatExpr operator - (const Scalar& s, const Mat& a);
01176 CV_EXPORTS MatExpr operator - (const MatExpr& e, const Mat& m);
01177 CV_EXPORTS MatExpr operator - (const Mat& m, const MatExpr& e);
01178 CV_EXPORTS MatExpr operator - (const MatExpr& e, const Scalar& s);
01179 CV_EXPORTS MatExpr operator - (const Scalar& s, const MatExpr& e);
01180 CV_EXPORTS MatExpr operator - (const MatExpr& e1, const MatExpr& e2);
01181
01182 CV_EXPORTS MatExpr operator - (const Mat& m);
01183 CV_EXPORTS MatExpr operator - (const MatExpr& e);
01184
01185 CV_EXPORTS MatExpr operator * (const Mat& a, const Mat& b);
01186 CV_EXPORTS MatExpr operator * (const Mat& a, double s);
01187 CV_EXPORTS MatExpr operator * (double s, const Mat& a);
01188 CV_EXPORTS MatExpr operator * (const MatExpr& e, const Mat& m);
01189 CV_EXPORTS MatExpr operator * (const Mat& m, const MatExpr& e);
01190 CV_EXPORTS MatExpr operator * (const MatExpr& e, double s);
01191 CV_EXPORTS MatExpr operator * (double s, const MatExpr& e);
01192 CV_EXPORTS MatExpr operator * (const MatExpr& e1, const MatExpr& e2);
01193
01194 CV_EXPORTS MatExpr operator / (const Mat& a, const Mat& b);
01195 CV_EXPORTS MatExpr operator / (const Mat& a, double s);
01196 CV_EXPORTS MatExpr operator / (double s, const Mat& a);
01197 CV_EXPORTS MatExpr operator / (const MatExpr& e, const Mat& m);
01198 CV_EXPORTS MatExpr operator / (const Mat& m, const MatExpr& e);
01199 CV_EXPORTS MatExpr operator / (const MatExpr& e, double s);
01200 CV_EXPORTS MatExpr operator / (double s, const MatExpr& e);
01201 CV_EXPORTS MatExpr operator / (const MatExpr& e1, const MatExpr& e2);
01202
01203 CV_EXPORTS MatExpr operator < (const Mat& a, const Mat& b);
01204 CV_EXPORTS MatExpr operator < (const Mat& a, double s);
01205 CV_EXPORTS MatExpr operator < (double s, const Mat& a);
01206
01207 CV_EXPORTS MatExpr operator <= (const Mat& a, const Mat& b);
01208 CV_EXPORTS MatExpr operator <= (const Mat& a, double s);
01209 CV_EXPORTS MatExpr operator <= (double s, const Mat& a);
01210
01211 CV_EXPORTS MatExpr operator == (const Mat& a, const Mat& b);
01212 CV_EXPORTS MatExpr operator == (const Mat& a, double s);
01213 CV_EXPORTS MatExpr operator == (double s, const Mat& a);
01214
01215 CV_EXPORTS MatExpr operator != (const Mat& a, const Mat& b);
01216 CV_EXPORTS MatExpr operator != (const Mat& a, double s);
01217 CV_EXPORTS MatExpr operator != (double s, const Mat& a);
01218
01219 CV_EXPORTS MatExpr operator >= (const Mat& a, const Mat& b);
01220 CV_EXPORTS MatExpr operator >= (const Mat& a, double s);
01221 CV_EXPORTS MatExpr operator >= (double s, const Mat& a);
01222
01223 CV_EXPORTS MatExpr operator > (const Mat& a, const Mat& b);
01224 CV_EXPORTS MatExpr operator > (const Mat& a, double s);
01225 CV_EXPORTS MatExpr operator > (double s, const Mat& a);
01226
01227 CV_EXPORTS MatExpr min(const Mat& a, const Mat& b);
01228 CV_EXPORTS MatExpr min(const Mat& a, double s);
01229 CV_EXPORTS MatExpr min(double s, const Mat& a);
01230
01231 CV_EXPORTS MatExpr max(const Mat& a, const Mat& b);
01232 CV_EXPORTS MatExpr max(const Mat& a, double s);
01233 CV_EXPORTS MatExpr max(double s, const Mat& a);
01234
01235 template<typename _Tp> static inline MatExpr min(const Mat_<_Tp>& a, const Mat_<_Tp>& b)
01236 {
01237 return cv::min((const Mat&)a, (const Mat&)b);
01238 }
01239
01240 template<typename _Tp> static inline MatExpr min(const Mat_<_Tp>& a, double s)
01241 {
01242 return cv::min((const Mat&)a, s);
01243 }
01244
01245 template<typename _Tp> static inline MatExpr min(double s, const Mat_<_Tp>& a)
01246 {
01247 return cv::min((const Mat&)a, s);
01248 }
01249
01250 template<typename _Tp> static inline MatExpr max(const Mat_<_Tp>& a, const Mat_<_Tp>& b)
01251 {
01252 return cv::max((const Mat&)a, (const Mat&)b);
01253 }
01254
01255 template<typename _Tp> static inline MatExpr max(const Mat_<_Tp>& a, double s)
01256 {
01257 return cv::max((const Mat&)a, s);
01258 }
01259
01260 template<typename _Tp> static inline MatExpr max(double s, const Mat_<_Tp>& a)
01261 {
01262 return cv::max((const Mat&)a, s);
01263 }
01264
01265 CV_EXPORTS MatExpr operator & (const Mat& a, const Mat& b);
01266 CV_EXPORTS MatExpr operator & (const Mat& a, const Scalar& s);
01267 CV_EXPORTS MatExpr operator & (const Scalar& s, const Mat& a);
01268
01269 CV_EXPORTS MatExpr operator | (const Mat& a, const Mat& b);
01270 CV_EXPORTS MatExpr operator | (const Mat& a, const Scalar& s);
01271 CV_EXPORTS MatExpr operator | (const Scalar& s, const Mat& a);
01272
01273 CV_EXPORTS MatExpr operator ^ (const Mat& a, const Mat& b);
01274 CV_EXPORTS MatExpr operator ^ (const Mat& a, const Scalar& s);
01275 CV_EXPORTS MatExpr operator ^ (const Scalar& s, const Mat& a);
01276
01277 CV_EXPORTS MatExpr operator ~(const Mat& m);
01278
01279 CV_EXPORTS MatExpr abs(const Mat& m);
01280 CV_EXPORTS MatExpr abs(const MatExpr& e);
01281
01282 template<typename _Tp> static inline MatExpr abs(const Mat_<_Tp>& m)
01283 {
01284 return cv::abs((const Mat&)m);
01285 }
01286
01288
01289 inline Mat& Mat::operator = (const MatExpr& e)
01290 {
01291 e.op->assign(e, *this);
01292 return *this;
01293 }
01294
01295 template<typename _Tp> Mat_<_Tp>& Mat_<_Tp>::operator = (const MatExpr& e)
01296 {
01297 e.op->assign(e, *this, DataType<_Tp>::type);
01298 return *this;
01299 }
01300
01301 static inline Mat& operator += (const Mat& a, const Mat& b)
01302 {
01303 add(a, b, (Mat&)a);
01304 return (Mat&)a;
01305 }
01306
01307 static inline Mat& operator += (const Mat& a, const Scalar& s)
01308 {
01309 add(a, s, (Mat&)a);
01310 return (Mat&)a;
01311 }
01312
01313 template<typename _Tp> static inline
01314 Mat_<_Tp>& operator += (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
01315 {
01316 add(a, b, (Mat&)a);
01317 return (Mat_<_Tp>&)a;
01318 }
01319
01320 template<typename _Tp> static inline
01321 Mat_<_Tp>& operator += (const Mat_<_Tp>& a, const Scalar& s)
01322 {
01323 add(a, s, (Mat&)a);
01324 return (Mat_<_Tp>&)a;
01325 }
01326
01327 static inline Mat& operator += (const Mat& a, const MatExpr& b)
01328 {
01329 b.op->augAssignAdd(b, (Mat&)a);
01330 return (Mat&)a;
01331 }
01332
01333 template<typename _Tp> static inline
01334 Mat_<_Tp>& operator += (const Mat_<_Tp>& a, const MatExpr& b)
01335 {
01336 b.op->augAssignAdd(b, (Mat&)a);
01337 return (Mat_<_Tp>&)a;
01338 }
01339
01340 static inline Mat& operator -= (const Mat& a, const Mat& b)
01341 {
01342 subtract(a, b, (Mat&)a);
01343 return (Mat&)a;
01344 }
01345
01346 static inline Mat& operator -= (const Mat& a, const Scalar& s)
01347 {
01348 subtract(a, s, (Mat&)a);
01349 return (Mat&)a;
01350 }
01351
01352 template<typename _Tp> static inline
01353 Mat_<_Tp>& operator -= (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
01354 {
01355 subtract(a, b, (Mat&)a);
01356 return (Mat_<_Tp>&)a;
01357 }
01358
01359 template<typename _Tp> static inline
01360 Mat_<_Tp>& operator -= (const Mat_<_Tp>& a, const Scalar& s)
01361 {
01362 subtract(a, s, (Mat&)a);
01363 return (Mat_<_Tp>&)a;
01364 }
01365
01366 static inline Mat& operator -= (const Mat& a, const MatExpr& b)
01367 {
01368 b.op->augAssignSubtract(b, (Mat&)a);
01369 return (Mat&)a;
01370 }
01371
01372 template<typename _Tp> static inline
01373 Mat_<_Tp>& operator -= (const Mat_<_Tp>& a, const MatExpr& b)
01374 {
01375 b.op->augAssignSubtract(b, (Mat&)a);
01376 return (Mat_<_Tp>&)a;
01377 }
01378
01379 static inline Mat& operator *= (const Mat& a, const Mat& b)
01380 {
01381 gemm(a, b, 1, Mat(), 0, (Mat&)a, 0);
01382 return (Mat&)a;
01383 }
01384
01385 static inline Mat& operator *= (const Mat& a, double s)
01386 {
01387 a.convertTo((Mat&)a, -1, s);
01388 return (Mat&)a;
01389 }
01390
01391 template<typename _Tp> static inline
01392 Mat_<_Tp>& operator *= (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
01393 {
01394 gemm(a, b, 1, Mat(), 0, (Mat&)a, 0);
01395 return (Mat_<_Tp>&)a;
01396 }
01397
01398 template<typename _Tp> static inline
01399 Mat_<_Tp>& operator *= (const Mat_<_Tp>& a, double s)
01400 {
01401 a.convertTo((Mat&)a, -1, s);
01402 return (Mat_<_Tp>&)a;
01403 }
01404
01405 static inline Mat& operator *= (const Mat& a, const MatExpr& b)
01406 {
01407 b.op->augAssignMultiply(b, (Mat&)a);
01408 return (Mat&)a;
01409 }
01410
01411 template<typename _Tp> static inline
01412 Mat_<_Tp>& operator *= (const Mat_<_Tp>& a, const MatExpr& b)
01413 {
01414 b.op->augAssignMultiply(b, (Mat&)a);
01415 return (Mat_<_Tp>&)a;
01416 }
01417
01418 static inline Mat& operator /= (const Mat& a, const Mat& b)
01419 {
01420 divide(a, b, (Mat&)a);
01421 return (Mat&)a;
01422 }
01423
01424 static inline Mat& operator /= (const Mat& a, double s)
01425 {
01426 a.convertTo((Mat&)a, -1, 1./s);
01427 return (Mat&)a;
01428 }
01429
01430 template<typename _Tp> static inline
01431 Mat_<_Tp>& operator /= (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
01432 {
01433 divide(a, b, (Mat&)a);
01434 return (Mat_<_Tp>&)a;
01435 }
01436
01437 template<typename _Tp> static inline
01438 Mat_<_Tp>& operator /= (const Mat_<_Tp>& a, double s)
01439 {
01440 a.convertTo((Mat&)a, -1, 1./s);
01441 return (Mat_<_Tp>&)a;
01442 }
01443
01444 static inline Mat& operator /= (const Mat& a, const MatExpr& b)
01445 {
01446 b.op->augAssignDivide(b, (Mat&)a);
01447 return (Mat&)a;
01448 }
01449
01450 template<typename _Tp> static inline
01451 Mat_<_Tp>& operator /= (const Mat_<_Tp>& a, const MatExpr& b)
01452 {
01453 b.op->augAssignDivide(b, (Mat&)a);
01454 return (Mat_<_Tp>&)a;
01455 }
01456
01458
01459 static inline Mat& operator &= (const Mat& a, const Mat& b)
01460 {
01461 bitwise_and(a, b, (Mat&)a);
01462 return (Mat&)a;
01463 }
01464
01465 static inline Mat& operator &= (const Mat& a, const Scalar& s)
01466 {
01467 bitwise_and(a, s, (Mat&)a);
01468 return (Mat&)a;
01469 }
01470
01471 template<typename _Tp> static inline Mat_<_Tp>&
01472 operator &= (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
01473 {
01474 bitwise_and(a, b, (Mat&)a);
01475 return (Mat_<_Tp>&)a;
01476 }
01477
01478 template<typename _Tp> static inline Mat_<_Tp>&
01479 operator &= (const Mat_<_Tp>& a, const Scalar& s)
01480 {
01481 bitwise_and(a, s, (Mat&)a);
01482 return (Mat_<_Tp>&)a;
01483 }
01484
01485 static inline Mat& operator |= (const Mat& a, const Mat& b)
01486 {
01487 bitwise_or(a, b, (Mat&)a);
01488 return (Mat&)a;
01489 }
01490
01491 static inline Mat& operator |= (const Mat& a, const Scalar& s)
01492 {
01493 bitwise_or(a, s, (Mat&)a);
01494 return (Mat&)a;
01495 }
01496
01497 template<typename _Tp> static inline Mat_<_Tp>&
01498 operator |= (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
01499 {
01500 bitwise_or(a, b, (Mat&)a);
01501 return (Mat_<_Tp>&)a;
01502 }
01503
01504 template<typename _Tp> static inline Mat_<_Tp>&
01505 operator |= (const Mat_<_Tp>& a, const Scalar& s)
01506 {
01507 bitwise_or(a, s, (Mat&)a);
01508 return (Mat_<_Tp>&)a;
01509 }
01510
01511 static inline Mat& operator ^= (const Mat& a, const Mat& b)
01512 {
01513 bitwise_xor(a, b, (Mat&)a);
01514 return (Mat&)a;
01515 }
01516
01517 static inline Mat& operator ^= (const Mat& a, const Scalar& s)
01518 {
01519 bitwise_xor(a, s, (Mat&)a);
01520 return (Mat&)a;
01521 }
01522
01523 template<typename _Tp> static inline Mat_<_Tp>&
01524 operator ^= (const Mat_<_Tp>& a, const Mat_<_Tp>& b)
01525 {
01526 bitwise_xor(a, b, (Mat&)a);
01527 return (Mat_<_Tp>&)a;
01528 }
01529
01530 template<typename _Tp> static inline Mat_<_Tp>&
01531 operator ^= (const Mat_<_Tp>& a, const Scalar& s)
01532 {
01533 bitwise_xor(a, s, (Mat&)a);
01534 return (Mat_<_Tp>&)a;
01535 }
01536
01538
01539 template<typename _Tp> void split(const Mat& src, vector<Mat_<_Tp> >& mv)
01540 { split(src, (vector<Mat>&)mv ); }
01541
01543
01544 template<typename _Tp> inline MatExpr Mat_<_Tp>::zeros(int rows, int cols)
01545 {
01546 return Mat::zeros(rows, cols, DataType<_Tp>::type);
01547 }
01548
01549 template<typename _Tp> inline MatExpr Mat_<_Tp>::zeros(Size sz)
01550 {
01551 return Mat::zeros(sz, DataType<_Tp>::type);
01552 }
01553
01554 template<typename _Tp> inline MatExpr Mat_<_Tp>::ones(int rows, int cols)
01555 {
01556 return Mat::ones(rows, cols, DataType<_Tp>::type);
01557 }
01558
01559 template<typename _Tp> inline MatExpr Mat_<_Tp>::ones(Size sz)
01560 {
01561 return Mat::ones(sz, DataType<_Tp>::type);
01562 }
01563
01564 template<typename _Tp> inline MatExpr Mat_<_Tp>::eye(int rows, int cols)
01565 {
01566 return Mat::eye(rows, cols, DataType<_Tp>::type);
01567 }
01568
01569 template<typename _Tp> inline MatExpr Mat_<_Tp>::eye(Size sz)
01570 {
01571 return Mat::eye(sz, DataType<_Tp>::type);
01572 }
01573
01575
01576 inline MatConstIterator::MatConstIterator()
01577 : m(0), elemSize(0), ptr(0), sliceStart(0), sliceEnd(0) {}
01578
01579 inline MatConstIterator::MatConstIterator(const Mat* _m)
01580 : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0)
01581 {
01582 if( m && m->isContinuous() )
01583 {
01584 sliceStart = m->data;
01585 sliceEnd = sliceStart + m->total()*elemSize;
01586 }
01587 seek((const int*)0);
01588 }
01589
01590 inline MatConstIterator::MatConstIterator(const Mat* _m, int _row, int _col)
01591 : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0)
01592 {
01593 CV_Assert(m && m->dims <= 2);
01594 if( m->isContinuous() )
01595 {
01596 sliceStart = m->data;
01597 sliceEnd = sliceStart + m->total()*elemSize;
01598 }
01599 int idx[]={_row, _col};
01600 seek(idx);
01601 }
01602
01603 inline MatConstIterator::MatConstIterator(const Mat* _m, Point _pt)
01604 : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0)
01605 {
01606 CV_Assert(m && m->dims <= 2);
01607 if( m->isContinuous() )
01608 {
01609 sliceStart = m->data;
01610 sliceEnd = sliceStart + m->total()*elemSize;
01611 }
01612 int idx[]={_pt.y, _pt.x};
01613 seek(idx);
01614 }
01615
01616 inline MatConstIterator::MatConstIterator(const MatConstIterator& it)
01617 : m(it.m), elemSize(it.elemSize), ptr(it.ptr), sliceStart(it.sliceStart), sliceEnd(it.sliceEnd)
01618 {}
01619
01620 inline MatConstIterator& MatConstIterator::operator = (const MatConstIterator& it )
01621 {
01622 m = it.m; elemSize = it.elemSize; ptr = it.ptr;
01623 sliceStart = it.sliceStart; sliceEnd = it.sliceEnd;
01624 return *this;
01625 }
01626
01627 inline uchar* MatConstIterator::operator *() const { return ptr; }
01628
01629 inline MatConstIterator& MatConstIterator::operator += (ptrdiff_t ofs)
01630 {
01631 if( !m || ofs == 0 )
01632 return *this;
01633 ptrdiff_t ofsb = ofs*elemSize;
01634 ptr += ofsb;
01635 if( ptr < sliceStart || sliceEnd <= ptr )
01636 {
01637 ptr -= ofsb;
01638 seek(ofs, true);
01639 }
01640 return *this;
01641 }
01642
01643 inline MatConstIterator& MatConstIterator::operator -= (ptrdiff_t ofs)
01644 { return (*this += -ofs); }
01645
01646 inline MatConstIterator& MatConstIterator::operator --()
01647 {
01648 if( m && (ptr -= elemSize) < sliceStart )
01649 {
01650 ptr += elemSize;
01651 seek(-1, true);
01652 }
01653 return *this;
01654 }
01655
01656 inline MatConstIterator MatConstIterator::operator --(int)
01657 {
01658 MatConstIterator b = *this;
01659 *this += -1;
01660 return b;
01661 }
01662
01663 inline MatConstIterator& MatConstIterator::operator ++()
01664 {
01665 if( m && (ptr += elemSize) >= sliceEnd )
01666 {
01667 ptr -= elemSize;
01668 seek(1, true);
01669 }
01670 return *this;
01671 }
01672
01673 inline MatConstIterator MatConstIterator::operator ++(int)
01674 {
01675 MatConstIterator b = *this;
01676 *this += 1;
01677 return b;
01678 }
01679
01680 template<typename _Tp> inline MatConstIterator_<_Tp>::MatConstIterator_() {}
01681
01682 template<typename _Tp> inline MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m)
01683 : MatConstIterator(_m) {}
01684
01685 template<typename _Tp> inline MatConstIterator_<_Tp>::
01686 MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col)
01687 : MatConstIterator(_m, _row, _col) {}
01688
01689 template<typename _Tp> inline MatConstIterator_<_Tp>::
01690 MatConstIterator_(const Mat_<_Tp>* _m, Point _pt)
01691 : MatConstIterator(_m, _pt) {}
01692
01693 template<typename _Tp> inline MatConstIterator_<_Tp>::
01694 MatConstIterator_(const MatConstIterator_& it)
01695 : MatConstIterator(it) {}
01696
01697 template<typename _Tp> inline MatConstIterator_<_Tp>&
01698 MatConstIterator_<_Tp>::operator = (const MatConstIterator_& it )
01699 {
01700 MatConstIterator::operator = (it);
01701 return *this;
01702 }
01703
01704 template<typename _Tp> inline _Tp MatConstIterator_<_Tp>::operator *() const { return *(_Tp*)(this->ptr); }
01705
01706 template<typename _Tp> inline MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator += (ptrdiff_t ofs)
01707 {
01708 MatConstIterator::operator += (ofs);
01709 return *this;
01710 }
01711
01712 template<typename _Tp> inline MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator -= (ptrdiff_t ofs)
01713 { return (*this += -ofs); }
01714
01715 template<typename _Tp> inline MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator --()
01716 {
01717 MatConstIterator::operator --();
01718 return *this;
01719 }
01720
01721 template<typename _Tp> inline MatConstIterator_<_Tp> MatConstIterator_<_Tp>::operator --(int)
01722 {
01723 MatConstIterator_ b = *this;
01724 MatConstIterator::operator --();
01725 return b;
01726 }
01727
01728 template<typename _Tp> inline MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator ++()
01729 {
01730 MatConstIterator::operator ++();
01731 return *this;
01732 }
01733
01734 template<typename _Tp> inline MatConstIterator_<_Tp> MatConstIterator_<_Tp>::operator ++(int)
01735 {
01736 MatConstIterator_ b = *this;
01737 MatConstIterator::operator ++();
01738 return b;
01739 }
01740
01741 template<typename _Tp> inline MatIterator_<_Tp>::MatIterator_() : MatConstIterator_<_Tp>() {}
01742
01743 template<typename _Tp> inline MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m)
01744 : MatConstIterator_<_Tp>(_m) {}
01745
01746 template<typename _Tp> inline MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, int _row, int _col)
01747 : MatConstIterator_<_Tp>(_m, _row, _col) {}
01748
01749 template<typename _Tp> inline MatIterator_<_Tp>::MatIterator_(const Mat_<_Tp>* _m, Point _pt)
01750 : MatConstIterator_<_Tp>(_m, _pt) {}
01751
01752 template<typename _Tp> inline MatIterator_<_Tp>::MatIterator_(const Mat_<_Tp>* _m, const int* _idx)
01753 : MatConstIterator_<_Tp>(_m, _idx) {}
01754
01755 template<typename _Tp> inline MatIterator_<_Tp>::MatIterator_(const MatIterator_& it)
01756 : MatConstIterator_<_Tp>(it) {}
01757
01758 template<typename _Tp> inline MatIterator_<_Tp>& MatIterator_<_Tp>::operator = (const MatIterator_<_Tp>& it )
01759 {
01760 MatConstIterator::operator = (it);
01761 return *this;
01762 }
01763
01764 template<typename _Tp> inline _Tp& MatIterator_<_Tp>::operator *() const { return *(_Tp*)(this->ptr); }
01765
01766 template<typename _Tp> inline MatIterator_<_Tp>& MatIterator_<_Tp>::operator += (ptrdiff_t ofs)
01767 {
01768 MatConstIterator::operator += (ofs);
01769 return *this;
01770 }
01771
01772 template<typename _Tp> inline MatIterator_<_Tp>& MatIterator_<_Tp>::operator -= (ptrdiff_t ofs)
01773 {
01774 MatConstIterator::operator += (-ofs);
01775 return *this;
01776 }
01777
01778 template<typename _Tp> inline MatIterator_<_Tp>& MatIterator_<_Tp>::operator --()
01779 {
01780 MatConstIterator::operator --();
01781 return *this;
01782 }
01783
01784 template<typename _Tp> inline MatIterator_<_Tp> MatIterator_<_Tp>::operator --(int)
01785 {
01786 MatIterator_ b = *this;
01787 MatConstIterator::operator --();
01788 return b;
01789 }
01790
01791 template<typename _Tp> inline MatIterator_<_Tp>& MatIterator_<_Tp>::operator ++()
01792 {
01793 MatConstIterator::operator ++();
01794 return *this;
01795 }
01796
01797 template<typename _Tp> inline MatIterator_<_Tp> MatIterator_<_Tp>::operator ++(int)
01798 {
01799 MatIterator_ b = *this;
01800 MatConstIterator::operator ++();
01801 return b;
01802 }
01803
01804 template<typename _Tp> inline Point MatConstIterator_<_Tp>::pos() const
01805 {
01806 if( !m )
01807 return Point();
01808 CV_DbgAssert( m->dims <= 2 );
01809 if( m->isContinuous() )
01810 {
01811 ptrdiff_t ofs = ptr - (_Tp*)m->data;
01812 int y = (int)(ofs / m->cols), x = (int)(ofs - (ptrdiff_t)y*m->cols);
01813 return Point(x, y);
01814 }
01815 else
01816 {
01817 ptrdiff_t ofs = (uchar*)ptr - m->data;
01818 int y = (int)(ofs / m->step), x = (int)((ofs - y*m->step)/sizeof(_Tp));
01819 return Point(x, y);
01820 }
01821 }
01822
01823 static inline bool
01824 operator == (const MatConstIterator& a, const MatConstIterator& b)
01825 { return a.m == b.m && a.ptr == b.ptr; }
01826
01827 template<typename _Tp> static inline bool
01828 operator != (const MatConstIterator& a, const MatConstIterator& b)
01829 { return !(a == b); }
01830
01831 template<typename _Tp> static inline bool
01832 operator == (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b)
01833 { return a.m == b.m && a.ptr == b.ptr; }
01834
01835 template<typename _Tp> static inline bool
01836 operator != (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b)
01837 { return a.m != b.m || a.ptr != b.ptr; }
01838
01839 template<typename _Tp> static inline bool
01840 operator == (const MatIterator_<_Tp>& a, const MatIterator_<_Tp>& b)
01841 { return a.m == b.m && a.ptr == b.ptr; }
01842
01843 template<typename _Tp> static inline bool
01844 operator != (const MatIterator_<_Tp>& a, const MatIterator_<_Tp>& b)
01845 { return a.m != b.m || a.ptr != b.ptr; }
01846
01847 static inline bool
01848 operator < (const MatConstIterator& a, const MatConstIterator& b)
01849 { return a.ptr < b.ptr; }
01850
01851 static inline bool
01852 operator > (const MatConstIterator& a, const MatConstIterator& b)
01853 { return a.ptr > b.ptr; }
01854
01855 static inline bool
01856 operator <= (const MatConstIterator& a, const MatConstIterator& b)
01857 { return a.ptr <= b.ptr; }
01858
01859 static inline bool
01860 operator >= (const MatConstIterator& a, const MatConstIterator& b)
01861 { return a.ptr >= b.ptr; }
01862
01863 CV_EXPORTS ptrdiff_t operator - (const MatConstIterator& b, const MatConstIterator& a);
01864
01865 static inline MatConstIterator operator + (const MatConstIterator& a, ptrdiff_t ofs)
01866 { MatConstIterator b = a; return b += ofs; }
01867
01868 static inline MatConstIterator operator + (ptrdiff_t ofs, const MatConstIterator& a)
01869 { MatConstIterator b = a; return b += ofs; }
01870
01871 static inline MatConstIterator operator - (const MatConstIterator& a, ptrdiff_t ofs)
01872 { MatConstIterator b = a; return b += -ofs; }
01873
01874 template<typename _Tp> static inline MatConstIterator_<_Tp>
01875 operator + (const MatConstIterator_<_Tp>& a, ptrdiff_t ofs)
01876 { MatConstIterator t = (const MatConstIterator&)a + ofs; return (MatConstIterator_<_Tp>&)t; }
01877
01878 template<typename _Tp> static inline MatConstIterator_<_Tp>
01879 operator + (ptrdiff_t ofs, const MatConstIterator_<_Tp>& a)
01880 { MatConstIterator t = (const MatConstIterator&)a + ofs; return (MatConstIterator_<_Tp>&)t; }
01881
01882 template<typename _Tp> static inline MatConstIterator_<_Tp>
01883 operator - (const MatConstIterator_<_Tp>& a, ptrdiff_t ofs)
01884 { MatConstIterator t = (const MatConstIterator&)a - ofs; return (MatConstIterator_<_Tp>&)t; }
01885
01886 inline uchar* MatConstIterator::operator [](ptrdiff_t i) const
01887 { return *(*this + i); }
01888
01889 template<typename _Tp> inline _Tp MatConstIterator_<_Tp>::operator [](ptrdiff_t i) const
01890 { return *(_Tp*)MatConstIterator::operator [](i); }
01891
01892 template<typename _Tp> static inline MatIterator_<_Tp>
01893 operator + (const MatIterator_<_Tp>& a, ptrdiff_t ofs)
01894 { MatConstIterator t = (const MatConstIterator&)a + ofs; return (MatIterator_<_Tp>&)t; }
01895
01896 template<typename _Tp> static inline MatIterator_<_Tp>
01897 operator + (ptrdiff_t ofs, const MatIterator_<_Tp>& a)
01898 { MatConstIterator t = (const MatConstIterator&)a + ofs; return (MatIterator_<_Tp>&)t; }
01899
01900 template<typename _Tp> static inline MatIterator_<_Tp>
01901 operator - (const MatIterator_<_Tp>& a, ptrdiff_t ofs)
01902 { MatConstIterator t = (const MatConstIterator&)a - ofs; return (MatIterator_<_Tp>&)t; }
01903
01904 template<typename _Tp> inline _Tp& MatIterator_<_Tp>::operator [](ptrdiff_t i) const
01905 { return *(*this + i); }
01906
01907 template<typename _Tp> inline MatConstIterator_<_Tp> Mat_<_Tp>::begin() const
01908 { return Mat::begin<_Tp>(); }
01909
01910 template<typename _Tp> inline MatConstIterator_<_Tp> Mat_<_Tp>::end() const
01911 { return Mat::end<_Tp>(); }
01912
01913 template<typename _Tp> inline MatIterator_<_Tp> Mat_<_Tp>::begin()
01914 { return Mat::begin<_Tp>(); }
01915
01916 template<typename _Tp> inline MatIterator_<_Tp> Mat_<_Tp>::end()
01917 { return Mat::end<_Tp>(); }
01918
01919 template<typename _Tp> inline MatCommaInitializer_<_Tp>::MatCommaInitializer_(Mat_<_Tp>* _m) : it(_m) {}
01920
01921 template<typename _Tp> template<typename T2> inline MatCommaInitializer_<_Tp>&
01922 MatCommaInitializer_<_Tp>::operator , (T2 v)
01923 {
01924 CV_DbgAssert( this->it < ((const Mat_<_Tp>*)this->it.m)->end() );
01925 *this->it = _Tp(v); ++this->it;
01926 return *this;
01927 }
01928
01929 template<typename _Tp> inline Mat_<_Tp> MatCommaInitializer_<_Tp>::operator *() const
01930 {
01931 CV_DbgAssert( this->it == ((const Mat_<_Tp>*)this->it.m)->end() );
01932 return Mat_<_Tp>(*this->it.m);
01933 }
01934
01935 template<typename _Tp> inline MatCommaInitializer_<_Tp>::operator Mat_<_Tp>() const
01936 {
01937 CV_DbgAssert( this->it == ((const Mat_<_Tp>*)this->it.m)->end() );
01938 return Mat_<_Tp>(*this->it.m);
01939 }
01940
01941 template<typename _Tp, typename T2> static inline MatCommaInitializer_<_Tp>
01942 operator << (const Mat_<_Tp>& m, T2 val)
01943 {
01944 MatCommaInitializer_<_Tp> commaInitializer((Mat_<_Tp>*)&m);
01945 return (commaInitializer, val);
01946 }
01947
01949
01950 inline SparseMat::SparseMat()
01951 : flags(MAGIC_VAL), hdr(0)
01952 {
01953 }
01954
01955 inline SparseMat::SparseMat(int _dims, const int* _sizes, int _type)
01956 : flags(MAGIC_VAL), hdr(0)
01957 {
01958 create(_dims, _sizes, _type);
01959 }
01960
01961 inline SparseMat::SparseMat(const SparseMat& m)
01962 : flags(m.flags), hdr(m.hdr)
01963 {
01964 addref();
01965 }
01966
01967 inline SparseMat::~SparseMat()
01968 {
01969 release();
01970 }
01971
01972 inline SparseMat& SparseMat::operator = (const SparseMat& m)
01973 {
01974 if( this != &m )
01975 {
01976 if( m.hdr )
01977 CV_XADD(&m.hdr->refcount, 1);
01978 release();
01979 flags = m.flags;
01980 hdr = m.hdr;
01981 }
01982 return *this;
01983 }
01984
01985 inline SparseMat& SparseMat::operator = (const Mat& m)
01986 { return (*this = SparseMat(m)); }
01987
01988 inline SparseMat SparseMat::clone() const
01989 {
01990 SparseMat temp;
01991 this->copyTo(temp);
01992 return temp;
01993 }
01994
01995
01996 inline void SparseMat::assignTo( SparseMat& m, int type ) const
01997 {
01998 if( type < 0 )
01999 m = *this;
02000 else
02001 convertTo(m, type);
02002 }
02003
02004 inline void SparseMat::addref()
02005 { if( hdr ) CV_XADD(&hdr->refcount, 1); }
02006
02007 inline void SparseMat::release()
02008 {
02009 if( hdr && CV_XADD(&hdr->refcount, -1) == 1 )
02010 delete hdr;
02011 hdr = 0;
02012 }
02013
02014 inline size_t SparseMat::elemSize() const
02015 { return CV_ELEM_SIZE(flags); }
02016
02017 inline size_t SparseMat::elemSize1() const
02018 { return CV_ELEM_SIZE1(flags); }
02019
02020 inline int SparseMat::type() const
02021 { return CV_MAT_TYPE(flags); }
02022
02023 inline int SparseMat::depth() const
02024 { return CV_MAT_DEPTH(flags); }
02025
02026 inline int SparseMat::channels() const
02027 { return CV_MAT_CN(flags); }
02028
02029 inline const int* SparseMat::size() const
02030 {
02031 return hdr ? hdr->size : 0;
02032 }
02033
02034 inline int SparseMat::size(int i) const
02035 {
02036 if( hdr )
02037 {
02038 CV_DbgAssert((unsigned)i < (unsigned)hdr->dims);
02039 return hdr->size[i];
02040 }
02041 return 0;
02042 }
02043
02044 inline int SparseMat::dims() const
02045 {
02046 return hdr ? hdr->dims : 0;
02047 }
02048
02049 inline size_t SparseMat::nzcount() const
02050 {
02051 return hdr ? hdr->nodeCount : 0;
02052 }
02053
02054 inline size_t SparseMat::hash(int i0) const
02055 {
02056 return (size_t)i0;
02057 }
02058
02059 inline size_t SparseMat::hash(int i0, int i1) const
02060 {
02061 return (size_t)(unsigned)i0*HASH_SCALE + (unsigned)i1;
02062 }
02063
02064 inline size_t SparseMat::hash(int i0, int i1, int i2) const
02065 {
02066 return ((size_t)(unsigned)i0*HASH_SCALE + (unsigned)i1)*HASH_SCALE + (unsigned)i2;
02067 }
02068
02069 inline size_t SparseMat::hash(const int* idx) const
02070 {
02071 size_t h = (unsigned)idx[0];
02072 if( !hdr )
02073 return 0;
02074 int i, d = hdr->dims;
02075 for( i = 1; i < d; i++ )
02076 h = h*HASH_SCALE + (unsigned)idx[i];
02077 return h;
02078 }
02079
02080 template<typename _Tp> inline _Tp& SparseMat::ref(int i0, size_t* hashval)
02081 { return *(_Tp*)((SparseMat*)this)->ptr(i0, true, hashval); }
02082
02083 template<typename _Tp> inline _Tp& SparseMat::ref(int i0, int i1, size_t* hashval)
02084 { return *(_Tp*)((SparseMat*)this)->ptr(i0, i1, true, hashval); }
02085
02086 template<typename _Tp> inline _Tp& SparseMat::ref(int i0, int i1, int i2, size_t* hashval)
02087 { return *(_Tp*)((SparseMat*)this)->ptr(i0, i1, i2, true, hashval); }
02088
02089 template<typename _Tp> inline _Tp& SparseMat::ref(const int* idx, size_t* hashval)
02090 { return *(_Tp*)((SparseMat*)this)->ptr(idx, true, hashval); }
02091
02092 template<typename _Tp> inline _Tp SparseMat::value(int i0, size_t* hashval) const
02093 {
02094 const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, false, hashval);
02095 return p ? *p : _Tp();
02096 }
02097
02098 template<typename _Tp> inline _Tp SparseMat::value(int i0, int i1, size_t* hashval) const
02099 {
02100 const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, i1, false, hashval);
02101 return p ? *p : _Tp();
02102 }
02103
02104 template<typename _Tp> inline _Tp SparseMat::value(int i0, int i1, int i2, size_t* hashval) const
02105 {
02106 const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, i1, i2, false, hashval);
02107 return p ? *p : _Tp();
02108 }
02109
02110 template<typename _Tp> inline _Tp SparseMat::value(const int* idx, size_t* hashval) const
02111 {
02112 const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(idx, false, hashval);
02113 return p ? *p : _Tp();
02114 }
02115
02116 template<typename _Tp> inline const _Tp* SparseMat::find(int i0, size_t* hashval) const
02117 { return (const _Tp*)((SparseMat*)this)->ptr(i0, false, hashval); }
02118
02119 template<typename _Tp> inline const _Tp* SparseMat::find(int i0, int i1, size_t* hashval) const
02120 { return (const _Tp*)((SparseMat*)this)->ptr(i0, i1, false, hashval); }
02121
02122 template<typename _Tp> inline const _Tp* SparseMat::find(int i0, int i1, int i2, size_t* hashval) const
02123 { return (const _Tp*)((SparseMat*)this)->ptr(i0, i1, i2, false, hashval); }
02124
02125 template<typename _Tp> inline const _Tp* SparseMat::find(const int* idx, size_t* hashval) const
02126 { return (const _Tp*)((SparseMat*)this)->ptr(idx, false, hashval); }
02127
02128 template<typename _Tp> inline _Tp& SparseMat::value(Node* n)
02129 { return *(_Tp*)((uchar*)n + hdr->valueOffset); }
02130
02131 template<typename _Tp> inline const _Tp& SparseMat::value(const Node* n) const
02132 { return *(const _Tp*)((const uchar*)n + hdr->valueOffset); }
02133
02134 inline SparseMat::Node* SparseMat::node(size_t nidx)
02135 { return (Node*)&hdr->pool[nidx]; }
02136
02137 inline const SparseMat::Node* SparseMat::node(size_t nidx) const
02138 { return (const Node*)&hdr->pool[nidx]; }
02139
02140 inline SparseMatIterator SparseMat::begin()
02141 { return SparseMatIterator(this); }
02142
02143 inline SparseMatConstIterator SparseMat::begin() const
02144 { return SparseMatConstIterator(this); }
02145
02146 inline SparseMatIterator SparseMat::end()
02147 { SparseMatIterator it(this); it.seekEnd(); return it; }
02148
02149 inline SparseMatConstIterator SparseMat::end() const
02150 { SparseMatConstIterator it(this); it.seekEnd(); return it; }
02151
02152 template<typename _Tp> inline SparseMatIterator_<_Tp> SparseMat::begin()
02153 { return SparseMatIterator_<_Tp>(this); }
02154
02155 template<typename _Tp> inline SparseMatConstIterator_<_Tp> SparseMat::begin() const
02156 { return SparseMatConstIterator_<_Tp>(this); }
02157
02158 template<typename _Tp> inline SparseMatIterator_<_Tp> SparseMat::end()
02159 { SparseMatIterator_<_Tp> it(this); it.seekEnd(); return it; }
02160
02161 template<typename _Tp> inline SparseMatConstIterator_<_Tp> SparseMat::end() const
02162 { SparseMatConstIterator_<_Tp> it(this); it.seekEnd(); return it; }
02163
02164
02165 inline SparseMatConstIterator::SparseMatConstIterator()
02166 : m(0), hashidx(0), ptr(0)
02167 {
02168 }
02169
02170 inline SparseMatConstIterator::SparseMatConstIterator(const SparseMatConstIterator& it)
02171 : m(it.m), hashidx(it.hashidx), ptr(it.ptr)
02172 {
02173 }
02174
02175 static inline bool operator == (const SparseMatConstIterator& it1, const SparseMatConstIterator& it2)
02176 { return it1.m == it2.m && it1.hashidx == it2.hashidx && it1.ptr == it2.ptr; }
02177
02178 static inline bool operator != (const SparseMatConstIterator& it1, const SparseMatConstIterator& it2)
02179 { return !(it1 == it2); }
02180
02181
02182 inline SparseMatConstIterator& SparseMatConstIterator::operator = (const SparseMatConstIterator& it)
02183 {
02184 if( this != &it )
02185 {
02186 m = it.m;
02187 hashidx = it.hashidx;
02188 ptr = it.ptr;
02189 }
02190 return *this;
02191 }
02192
02193 template<typename _Tp> inline const _Tp& SparseMatConstIterator::value() const
02194 { return *(_Tp*)ptr; }
02195
02196 inline const SparseMat::Node* SparseMatConstIterator::node() const
02197 {
02198 return ptr && m && m->hdr ?
02199 (const SparseMat::Node*)(ptr - m->hdr->valueOffset) : 0;
02200 }
02201
02202 inline SparseMatConstIterator SparseMatConstIterator::operator ++(int)
02203 {
02204 SparseMatConstIterator it = *this;
02205 ++*this;
02206 return it;
02207 }
02208
02209
02210 inline void SparseMatConstIterator::seekEnd()
02211 {
02212 if( m && m->hdr )
02213 {
02214 hashidx = m->hdr->hashtab.size();
02215 ptr = 0;
02216 }
02217 }
02218
02219 inline SparseMatIterator::SparseMatIterator()
02220 {}
02221
02222 inline SparseMatIterator::SparseMatIterator(SparseMat* _m)
02223 : SparseMatConstIterator(_m)
02224 {}
02225
02226 inline SparseMatIterator::SparseMatIterator(const SparseMatIterator& it)
02227 : SparseMatConstIterator(it)
02228 {
02229 }
02230
02231 inline SparseMatIterator& SparseMatIterator::operator = (const SparseMatIterator& it)
02232 {
02233 (SparseMatConstIterator&)*this = it;
02234 return *this;
02235 }
02236
02237 template<typename _Tp> inline _Tp& SparseMatIterator::value() const
02238 { return *(_Tp*)ptr; }
02239
02240 inline SparseMat::Node* SparseMatIterator::node() const
02241 {
02242 return (SparseMat::Node*)SparseMatConstIterator::node();
02243 }
02244
02245 inline SparseMatIterator& SparseMatIterator::operator ++()
02246 {
02247 SparseMatConstIterator::operator ++();
02248 return *this;
02249 }
02250
02251 inline SparseMatIterator SparseMatIterator::operator ++(int)
02252 {
02253 SparseMatIterator it = *this;
02254 ++*this;
02255 return it;
02256 }
02257
02258
02259 template<typename _Tp> inline SparseMat_<_Tp>::SparseMat_()
02260 { flags = MAGIC_VAL | DataType<_Tp>::type; }
02261
02262 template<typename _Tp> inline SparseMat_<_Tp>::SparseMat_(int _dims, const int* _sizes)
02263 : SparseMat(_dims, _sizes, DataType<_Tp>::type)
02264 {}
02265
02266 template<typename _Tp> inline SparseMat_<_Tp>::SparseMat_(const SparseMat& m)
02267 {
02268 if( m.type() == DataType<_Tp>::type )
02269 *this = (const SparseMat_<_Tp>&)m;
02270 else
02271 m.convertTo(this, DataType<_Tp>::type);
02272 }
02273
02274 template<typename _Tp> inline SparseMat_<_Tp>::SparseMat_(const SparseMat_<_Tp>& m)
02275 {
02276 this->flags = m.flags;
02277 this->hdr = m.hdr;
02278 if( this->hdr )
02279 CV_XADD(&this->hdr->refcount, 1);
02280 }
02281
02282 template<typename _Tp> inline SparseMat_<_Tp>::SparseMat_(const Mat& m)
02283 {
02284 SparseMat sm(m);
02285 *this = sm;
02286 }
02287
02288 template<typename _Tp> inline SparseMat_<_Tp>::SparseMat_(const CvSparseMat* m)
02289 {
02290 SparseMat sm(m);
02291 *this = sm;
02292 }
02293
02294 template<typename _Tp> inline SparseMat_<_Tp>&
02295 SparseMat_<_Tp>::operator = (const SparseMat_<_Tp>& m)
02296 {
02297 if( this != &m )
02298 {
02299 if( m.hdr ) CV_XADD(&m.hdr->refcount, 1);
02300 release();
02301 flags = m.flags;
02302 hdr = m.hdr;
02303 }
02304 return *this;
02305 }
02306
02307 template<typename _Tp> inline SparseMat_<_Tp>&
02308 SparseMat_<_Tp>::operator = (const SparseMat& m)
02309 {
02310 if( m.type() == DataType<_Tp>::type )
02311 return (*this = (const SparseMat_<_Tp>&)m);
02312 m.convertTo(*this, DataType<_Tp>::type);
02313 return *this;
02314 }
02315
02316 template<typename _Tp> inline SparseMat_<_Tp>&
02317 SparseMat_<_Tp>::operator = (const Mat& m)
02318 { return (*this = SparseMat(m)); }
02319
02320 template<typename _Tp> inline SparseMat_<_Tp>
02321 SparseMat_<_Tp>::clone() const
02322 {
02323 SparseMat_<_Tp> m;
02324 this->copyTo(m);
02325 return m;
02326 }
02327
02328 template<typename _Tp> inline void
02329 SparseMat_<_Tp>::create(int _dims, const int* _sizes)
02330 {
02331 SparseMat::create(_dims, _sizes, DataType<_Tp>::type);
02332 }
02333
02334 template<typename _Tp> inline
02335 SparseMat_<_Tp>::operator CvSparseMat*() const
02336 {
02337 return SparseMat::operator CvSparseMat*();
02338 }
02339
02340 template<typename _Tp> inline int SparseMat_<_Tp>::type() const
02341 { return DataType<_Tp>::type; }
02342
02343 template<typename _Tp> inline int SparseMat_<_Tp>::depth() const
02344 { return DataType<_Tp>::depth; }
02345
02346 template<typename _Tp> inline int SparseMat_<_Tp>::channels() const
02347 { return DataType<_Tp>::channels; }
02348
02349 template<typename _Tp> inline _Tp&
02350 SparseMat_<_Tp>::ref(int i0, size_t* hashval)
02351 { return SparseMat::ref<_Tp>(i0, hashval); }
02352
02353 template<typename _Tp> inline _Tp
02354 SparseMat_<_Tp>::operator()(int i0, size_t* hashval) const
02355 { return SparseMat::value<_Tp>(i0, hashval); }
02356
02357 template<typename _Tp> inline _Tp&
02358 SparseMat_<_Tp>::ref(int i0, int i1, size_t* hashval)
02359 { return SparseMat::ref<_Tp>(i0, i1, hashval); }
02360
02361 template<typename _Tp> inline _Tp
02362 SparseMat_<_Tp>::operator()(int i0, int i1, size_t* hashval) const
02363 { return SparseMat::value<_Tp>(i0, i1, hashval); }
02364
02365 template<typename _Tp> inline _Tp&
02366 SparseMat_<_Tp>::ref(int i0, int i1, int i2, size_t* hashval)
02367 { return SparseMat::ref<_Tp>(i0, i1, i2, hashval); }
02368
02369 template<typename _Tp> inline _Tp
02370 SparseMat_<_Tp>::operator()(int i0, int i1, int i2, size_t* hashval) const
02371 { return SparseMat::value<_Tp>(i0, i1, i2, hashval); }
02372
02373 template<typename _Tp> inline _Tp&
02374 SparseMat_<_Tp>::ref(const int* idx, size_t* hashval)
02375 { return SparseMat::ref<_Tp>(idx, hashval); }
02376
02377 template<typename _Tp> inline _Tp
02378 SparseMat_<_Tp>::operator()(const int* idx, size_t* hashval) const
02379 { return SparseMat::value<_Tp>(idx, hashval); }
02380
02381 template<typename _Tp> inline SparseMatIterator_<_Tp> SparseMat_<_Tp>::begin()
02382 { return SparseMatIterator_<_Tp>(this); }
02383
02384 template<typename _Tp> inline SparseMatConstIterator_<_Tp> SparseMat_<_Tp>::begin() const
02385 { return SparseMatConstIterator_<_Tp>(this); }
02386
02387 template<typename _Tp> inline SparseMatIterator_<_Tp> SparseMat_<_Tp>::end()
02388 { SparseMatIterator_<_Tp> it(this); it.seekEnd(); return it; }
02389
02390 template<typename _Tp> inline SparseMatConstIterator_<_Tp> SparseMat_<_Tp>::end() const
02391 { SparseMatConstIterator_<_Tp> it(this); it.seekEnd(); return it; }
02392
02393 template<typename _Tp> inline
02394 SparseMatConstIterator_<_Tp>::SparseMatConstIterator_()
02395 {}
02396
02397 template<typename _Tp> inline
02398 SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMat_<_Tp>* _m)
02399 : SparseMatConstIterator(_m)
02400 {}
02401
02402 template<typename _Tp> inline
02403 SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMatConstIterator_<_Tp>& it)
02404 : SparseMatConstIterator(it)
02405 {}
02406
02407 template<typename _Tp> inline SparseMatConstIterator_<_Tp>&
02408 SparseMatConstIterator_<_Tp>::operator = (const SparseMatConstIterator_<_Tp>& it)
02409 { return ((SparseMatConstIterator&)*this = it); }
02410
02411 template<typename _Tp> inline const _Tp&
02412 SparseMatConstIterator_<_Tp>::operator *() const
02413 { return *(const _Tp*)this->ptr; }
02414
02415 template<typename _Tp> inline SparseMatConstIterator_<_Tp>&
02416 SparseMatConstIterator_<_Tp>::operator ++()
02417 {
02418 SparseMatConstIterator::operator ++();
02419 return *this;
02420 }
02421
02422 template<typename _Tp> inline SparseMatConstIterator_<_Tp>
02423 SparseMatConstIterator_<_Tp>::operator ++(int)
02424 {
02425 SparseMatConstIterator it = *this;
02426 SparseMatConstIterator::operator ++();
02427 return it;
02428 }
02429
02430 template<typename _Tp> inline
02431 SparseMatIterator_<_Tp>::SparseMatIterator_()
02432 {}
02433
02434 template<typename _Tp> inline
02435 SparseMatIterator_<_Tp>::SparseMatIterator_(SparseMat_<_Tp>* _m)
02436 : SparseMatConstIterator_<_Tp>(_m)
02437 {}
02438
02439 template<typename _Tp> inline
02440 SparseMatIterator_<_Tp>::SparseMatIterator_(const SparseMatIterator_<_Tp>& it)
02441 : SparseMatConstIterator_<_Tp>(it)
02442 {}
02443
02444 template<typename _Tp> inline SparseMatIterator_<_Tp>&
02445 SparseMatIterator_<_Tp>::operator = (const SparseMatIterator_<_Tp>& it)
02446 { return ((SparseMatIterator&)*this = it); }
02447
02448 template<typename _Tp> inline _Tp&
02449 SparseMatIterator_<_Tp>::operator *() const
02450 { return *(_Tp*)this->ptr; }
02451
02452 template<typename _Tp> inline SparseMatIterator_<_Tp>&
02453 SparseMatIterator_<_Tp>::operator ++()
02454 {
02455 SparseMatConstIterator::operator ++();
02456 return *this;
02457 }
02458
02459 template<typename _Tp> inline SparseMatIterator_<_Tp>
02460 SparseMatIterator_<_Tp>::operator ++(int)
02461 {
02462 SparseMatIterator it = *this;
02463 SparseMatConstIterator::operator ++();
02464 return it;
02465 }
02466
02467 }
02468
02469 #endif
02470 #endif