Skip to content

Commit

Permalink
belonging to issue #45. ROIs are now checked if they have the same sh…
Browse files Browse the repository at this point in the history
…ape or if their shapes are transposed to each other, before the values are copied.
  • Loading branch information
gegelle committed Apr 15, 2016
1 parent a153d79 commit b87d46b
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions DataObject/dataobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,8 @@ template<typename _Tp> RetVal DeepCopyPartialFunc(const DataObject &lhs, DataObj

int lhs_numPlanes = lhs.getNumPlanes();
int rhs_numPlanes = rhs.getNumPlanes();
int dims = lhs.getDims();
int dims_lhs = lhs.getDims();
int dims_rhs = rhs.getDims();

const cv::Mat **lhs_mdata = lhs.get_mdata();
cv::Mat **rhs_mdata = rhs.get_mdata();
Expand All @@ -2357,8 +2358,9 @@ template<typename _Tp> RetVal DeepCopyPartialFunc(const DataObject &lhs, DataObj

if (lhs_numPlanes == rhs_numPlanes) //both planes have the same size, line wise or block wise memcpy is possible
{
int sizeX = lhs.getSize(dims - 1);
int sizeY = lhs.getSize(dims - 2);
int sizeX = lhs.getSize(dims_lhs - 1);
int sizeY = lhs.getSize(dims_lhs - 2);
int sizeX_rhs = rhs.getSize(dims_rhs - 1);

int lineBytes = sizeX * sizeof(_Tp);
int planeBytes = sizeY * lineBytes;
Expand All @@ -2375,7 +2377,7 @@ template<typename _Tp> RetVal DeepCopyPartialFunc(const DataObject &lhs, DataObj
{
memcpy(rhs_mat->data, lhs_mat->data, planeBytes);
}
else
else if (sizeX == sizeX_rhs)
{
lhs_ptr = lhs_mat->data;
rhs_ptr = rhs_mat->data;
Expand All @@ -2387,6 +2389,24 @@ template<typename _Tp> RetVal DeepCopyPartialFunc(const DataObject &lhs, DataObj
rhs_ptr += rhs_mat->step[0];
}
}
else //so lhs has shape nXm while rhs is of shape mXn so it is necessary to loop ofer the cv:mats
{
lhs_ptr = lhs_mat->data;
rhs_ptr = rhs_mat->data;
int row;
int col;
int res;

for (row = 0; row < lhs_mat -> rows; ++row)
{
res = row * lineBytes;
for (col=0; col < lhs_mat -> cols; ++col)
{
rhs_mat->ptr(col)[row] = (lhs_ptr + res)[col];
}
}

}
}
}
else
Expand Down

0 comments on commit b87d46b

Please sign in to comment.