added Mat::push_back, pop_back and related operations; enabled reading/writing/creating/copying matrices with zero dimensions.

This commit is contained in:
Vadim Pisarevsky
2010-10-18 08:51:46 +00:00
parent bddaa00e03
commit 02885b8b49
8 changed files with 392 additions and 147 deletions

View File

@@ -166,38 +166,45 @@ static SetMaskFunc setMaskFuncTab[] =
/* dst = src */
void Mat::copyTo( Mat& dst ) const
{
if( data == dst.data )
if( data == dst.data && data != 0 )
return;
if( dims > 2 )
{
dst.create( dims, size, type() );
const Mat* arrays[] = { this, &dst, 0 };
Mat planes[2];
NAryMatIterator it(arrays, planes);
CV_DbgAssert(it.planes[0].isContinuous() &&
it.planes[1].isContinuous());
size_t planeSize = it.planes[0].elemSize()*it.planes[0].rows*it.planes[0].cols;
for( int i = 0; i < it.nplanes; i++, ++it )
memcpy(it.planes[1].data, it.planes[0].data, planeSize);
if( total() != 0 )
{
const Mat* arrays[] = { this, &dst, 0 };
Mat planes[2];
NAryMatIterator it(arrays, planes);
CV_DbgAssert(it.planes[0].isContinuous() &&
it.planes[1].isContinuous());
size_t planeSize = it.planes[0].elemSize()*it.planes[0].rows*it.planes[0].cols;
for( int i = 0; i < it.nplanes; i++, ++it )
memcpy(it.planes[1].data, it.planes[0].data, planeSize);
}
return;
}
dst.create( rows, cols, type() );
Size sz = size();
const uchar* sptr = data;
uchar* dptr = dst.data;
sz.width *= (int)elemSize();
if( isContinuous() && dst.isContinuous() )
if( rows > 0 && cols > 0 )
{
sz.width *= sz.height;
sz.height = 1;
}
const uchar* sptr = data;
uchar* dptr = dst.data;
for( ; sz.height--; sptr += step, dptr += dst.step )
memcpy( dptr, sptr, sz.width );
size_t width = sz.width*elemSize();
if( isContinuous() && dst.isContinuous() )
{
width *= sz.height;
sz.height = 1;
}
for( ; sz.height--; sptr += step, dptr += dst.step )
memcpy( dptr, sptr, width );
}
}
void Mat::copyTo( Mat& dst, const Mat& mask ) const