cDMatrix& cDMatrix::ReAlloc(uint theNRow, uint theNCol) { if (GetNRows() == theNRow && GetNCols() == theNCol) return *this ; Delete() ; Initialize(theNRow, theNCol) ; return *this ; }
void CDepthMapSkt::ShiftNN(int column, int row) { CDepthMapSkt bufDepthMap; CopyDepthMapTo(bufDepthMap); if(column < 0 || row < 0) { return; } int r,c; for(r=0; r<GetNRows(); r++) { for(c=0; c<GetNCols(); c++) { if(r < row || c < column) { SetItem(r,c, 0.0); } else { float shiftedValue = bufDepthMap.GetItem(r-row, c-column); SetItem(r, c, shiftedValue); } } } return; }
//scale the depth values void CDepthMap::Scale(float s) { int r,c; for(r=0; r<GetNRows(); r++) { for(c=0; c<GetNCols(); c++) { float temp = GetItem(r,c); SetItem(r,c, temp*s); } } }
void CDepthMap::CopyDepthMapTo(CDepthMap & dstMap) const { dstMap.SetSize(m_ncols, m_nrows); int r,c; for(r=0; r<GetNRows(); r++) { for(c=0; c<GetNCols(); c++) { float temp = GetItem(r,c); dstMap.SetItem(r,c, temp); } } }
int CDepthMap::NumberOfNonZeroPoints() const { int count=0; int r,c; for(r=0; r<GetNRows(); r++) { for(c=0; c<GetNCols(); c++) { float temp = GetItem(r,c); if(temp != 0) { count++; } } } return count; }
float CDepthMap::AvgNonZeroDepth() const { int count=0; float sum = 0; int r,c; for(r=0; r<GetNRows(); r++) { for(c=0; c<GetNCols(); c++) { float temp = GetItem(r,c); if(temp != 0) { count++; sum += temp; } } } if(count == 0) return 0; else return sum/count; }
//scale the dimensions: //ncols = floor(scaleFactor * ncols), nrows = floor(scaleFactor * nrows) void CDepthMap::ScaleSizeNN(float scaleFactor) { //buffer the original depthmap CDepthMap bufDepthMap; CopyDepthMapTo(bufDepthMap); int new_ncols = floor(m_ncols * scaleFactor); int new_nrows = floor(m_nrows * scaleFactor); SetSize(new_ncols, new_nrows); int r,c; for(r=0; r<GetNRows(); r++) { for(c=0; c<GetNCols(); c++) { int origR = floor(r/scaleFactor); int origC = floor(c/scaleFactor); float origVal = bufDepthMap.GetItem(origR, origC); SetItem(r,c, origVal); } } }