我有一个关于OSRM-Project中双线性插值的问题。 我明白“正常”双线性插值。这里从维基百科的图片,什么是疯狂:双线性插值 - OSRM Rastersource
现在我想明白这是在OSRM项目中使用的栅格源数据的双线性插值。
// Query raster source using bilinear interpolation
RasterDatum RasterSource::GetRasterInterpolate(const int lon, const int lat) const
{
if (lon < xmin || lon > xmax || lat < ymin || lat > ymax)
{
return {};
}
const auto xthP = (lon - xmin)/xstep;
const auto ythP =
(ymax - lat)/
ystep; // the raster texture uses a different coordinate system with y pointing downwards
const std::size_t top = static_cast<std::size_t>(fmax(floor(ythP), 0));
const std::size_t bottom = static_cast<std::size_t>(fmin(ceil(ythP), height - 1));
const std::size_t left = static_cast<std::size_t>(fmax(floor(xthP), 0));
const std::size_t right = static_cast<std::size_t>(fmin(ceil(xthP), width - 1));
// Calculate distances from corners for bilinear interpolation
const float fromLeft = xthP - left; // this is the fraction part of xthP
const float fromTop = ythP - top; // this is the fraction part of ythP
const float fromRight = 1 - fromLeft;
const float fromBottom = 1 - fromTop;
return {static_cast<std::int32_t>(raster_data(left, top) * (fromRight * fromBottom) +
raster_data(right, top) * (fromLeft * fromBottom) +
raster_data(left, bottom) * (fromRight * fromTop) +
raster_data(right, bottom) * (fromLeft * fromTop))};
}
有人可以解释我的代码是如何工作的?
输入格式为ASCII格式的SRTM数据。
变量高度和宽度被定义为NROWS和ncolumns。 变量XSTEP和ystep被定义为:
return (max - min)/(static_cast<float>(count) - 1)
凡计数为ystep和宽度为XSTEP,最大和分钟类似高度 。
而另一个问题: 我可以在TIF格式和全世界使用相同的代码数据吗?
如果如你所说,你已经理解双线性插值了,那么你当然应该已经理解了这个代码的大部分? – meowgoesthedog
好的,也许我应该清楚:我理解双线性插值背后的理论。我理解这段代码的基本逻辑,但我不明白为什么变量“底部”是为什么计算的,尤其是“身高 - 1”。以及“fromX”变量的计算如何工作。 –