HighMap library (C++)
Loading...
Searching...
No Matches
interpolate2d.hpp
Go to the documentation of this file.
1/* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General
2 Public License. The full license is in the file LICENSE, distributed with
3 this software. */
4
18#pragma once
19#include <map>
20
21#include "highmap/array.hpp"
22
23namespace hmap
24{
25
38
46static std::map<InterpolationMethod2D, std::string>
47 interpolation_method_2d_as_string = {{DELAUNAY, "Delaunay linear"},
48 {NEAREST, "nearest neighbor"}};
49
66inline float bilinear_interp(float f00,
67 float f10,
68 float f01,
69 float f11,
70 float u,
71 float v)
72{
73 float a10 = f10 - f00;
74 float a01 = f01 - f00;
75 float a11 = f11 - f10 - f01 + f00;
76 return f00 + a10 * u + a01 * v + a11 * u * v;
77}
78
79inline float cubic_interpolate(float p[4], float x)
80{
81 return p[1] + 0.5 * x *
82 (p[2] - p[0] +
83 x * (2.0 * p[0] - 5.0 * p[1] + 4.0 * p[2] - p[3] +
84 x * (3.0 * (p[1] - p[2]) + p[3] - p[0])));
85}
86
110Array interpolate2d(Vec2<int> shape,
111 const std::vector<float> &x,
112 const std::vector<float> &y,
113 const std::vector<float> &values,
114 InterpolationMethod2D interpolation_method,
115 const Array *p_noise_x = nullptr,
116 const Array *p_noise_y = nullptr,
117 const Array *p_stretching = nullptr,
118 Vec4<float> bbox = {0.f, 1.f, 0.f, 1.f});
119
139Array interpolate2d_nearest(Vec2<int> shape,
140 const std::vector<float> &x,
141 const std::vector<float> &y,
142 const std::vector<float> &values,
143 const Array *p_noise_x = nullptr,
144 const Array *p_noise_y = nullptr,
145 const Array *p_stretching = nullptr,
146 Vec4<float> bbox = {0.f, 1.f, 0.f, 1.f});
147
168Array interpolate2d_delaunay(Vec2<int> shape,
169 const std::vector<float> &x,
170 const std::vector<float> &y,
171 const std::vector<float> &values,
172 const Array *p_noise_x = nullptr,
173 const Array *p_noise_y = nullptr,
174 const Array *p_stretching = nullptr,
175 Vec4<float> bbox = {0.f, 1.f, 0.f, 1.f});
176
177} // namespace hmap
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
Definition algebra.hpp:28
InterpolationMethod2D
Enumeration of 2D interpolation methods.
Definition interpolate2d.hpp:34
@ DELAUNAY
Delaunay triangulation method for 2D interpolation.
Definition interpolate2d.hpp:35
@ NEAREST
Nearest point method for 2D interpolation.
Definition interpolate2d.hpp:36
Array interpolate2d_nearest(Vec2< int > shape, const std::vector< float > &x, const std::vector< float > &y, const std::vector< float > &values, const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr, const Array *p_stretching=nullptr, Vec4< float > bbox={0.f, 1.f, 0.f, 1.f})
2D interpolation using the nearest neighbor method.
Definition interpolate2d.cpp:51
Array interpolate2d(Vec2< int > shape, const std::vector< float > &x, const std::vector< float > &y, const std::vector< float > &values, InterpolationMethod2D interpolation_method, const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr, const Array *p_stretching=nullptr, Vec4< float > bbox={0.f, 1.f, 0.f, 1.f})
Generic 2D interpolation function.
Definition interpolate2d.cpp:16
Array interpolate2d_delaunay(Vec2< int > shape, const std::vector< float > &x, const std::vector< float > &y, const std::vector< float > &values, const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr, const Array *p_stretching=nullptr, Vec4< float > bbox={0.f, 1.f, 0.f, 1.f})
2D interpolation using the Delaunay triangulation method.
Definition interpolate2d.cpp:90
float bilinear_interp(float f00, float f10, float f01, float f11, float u, float v)
Compute the bilinear interpolated value from four input values.
Definition interpolate2d.hpp:66
float cubic_interpolate(float p[4], float x)
Definition interpolate2d.hpp:79