C++双线性插值-片段

2021-07-04 08:04

阅读:546

标签:map   last   otto   set   off   直接   offset   for   ott   

代码不能直接使用。

	for (int j = strRY; j(j);

		for (int i = strRX; i (j - strRY, i - strRY);
			float y = m_mapY.at(j - strRY, i - strRY);

			// whether out of range.
			if (x = src2.cols || y = src2.rows)
				continue;

			int lRow = static_cast(y);
			int nRow = lRow + 1;

			int lCol = static_cast(x);
			int nCol = lCol + 1;

			double u = y - lRow;
			double v = x - lCol;

			// interpolation
			// right bottom.
			if (lRow >= src2.rows - 1 && lCol >= src2.cols - 1)
			{
				float data = m_mapZ.at(lRow, lCol);
				if (data == -1.0e6)
					continue;

				z = (1 - u) * (1 - v) *	data;
			}
			else if (lRow >= src2.rows - 1)//last row
			{
				float data = m_mapZ.at(lRow, lCol);
				float data2 = m_mapZ.at(lRow, nCol);
				if (data == -1.0e6 || data2 == -1.0e6)
					continue;

				z = (1 - u) * (1 - v) *	data +
					(1 - u) * v * data2;
			}
			else if (lCol >= src2.cols - 1)//last col
			{
				float data = m_mapZ.at(lRow, lCol);
				float data3 = m_mapZ.at(nRow, lCol);

				if (data == -1.0e6 || data3 == -1.0e6)
					continue;
				z = (1 - u) * (1 - v) *	data + u * (1 - v) * data3;
			}
			else
			{
				float data = m_mapZ.at(lRow, lCol);
				float data2 = m_mapZ.at(lRow, nCol);
				float data3 = m_mapZ.at(nRow, lCol);
				float data4 = m_mapZ.at(nRow, nCol);
				if (data == -1.0e6 || data2 == -1.0e6 || data3 == -1.0e6 || data4 == -1.0e6)
					continue;

				z = (1 - u) * (1 - v) *	data + (1 - u) * v * data2 +
					u * (1 - v) * data3 + u * v * data4;
			}

			pR[i] = pR[i] == -1.0e6 ? z : 0.5*(pR[i] + z);

		}
	}

  

 

C++双线性插值-片段

标签:map   last   otto   set   off   直接   offset   for   ott   

原文地址:https://www.cnblogs.com/alexYuin/p/9614133.html


评论


亲,登录后才可以留言!