QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
BilinearUV.h
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 *
5 * QGroundControl is licensed according to the terms in the file
6 * COPYING.md in the root of the source code directory.
7 *
8 ****************************************************************************/
9
10#pragma once
11
12#include <QtCore/QtMinMax>
13
14#include <cmath>
15
23template <typename SampleAt>
24double bilinearAtUV(int w, int h, double u, double v, SampleAt at)
25{
26 if ((w <= 0) || (h <= 0)) {
27 return 0.0;
28 }
29 const double px = (u * w) - 0.5;
30 const double py = (v * h) - 0.5;
31 const int x0 = qBound(0, static_cast<int>(std::floor(px)), w - 1);
32 const int y0 = qBound(0, static_cast<int>(std::floor(py)), h - 1);
33 const int x1 = qMin(x0 + 1, w - 1);
34 const int y1 = qMin(y0 + 1, h - 1);
35 const double fx = qBound(0.0, px - x0, 1.0);
36 const double fy = qBound(0.0, py - y0, 1.0);
37
38 const double north = (at(x0, y0) * (1.0 - fx)) + (at(x1, y0) * fx);
39 const double south = (at(x0, y1) * (1.0 - fx)) + (at(x1, y1) * fx);
40 return (north * (1.0 - fy)) + (south * fy);
41}
double bilinearAtUV(int w, int h, double u, double v, SampleAt at)
Definition BilinearUV.h:24