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
120Array harmonic_interpolation(const Array &array,
121 const Array &mask_fixed_values,
122 int iterations_max = 10000,
123 float tolerance = 1e-3f,
124 float omega = 1.8f);
125
149Array interpolate2d(Vec2<int> shape,
150 const std::vector<float> &x,
151 const std::vector<float> &y,
152 const std::vector<float> &values,
153 InterpolationMethod2D interpolation_method,
154 const Array *p_noise_x = nullptr,
155 const Array *p_noise_y = nullptr,
156 const Array *p_stretching = nullptr,
157 Vec4<float> bbox = {0.f, 1.f, 0.f, 1.f});
158
178Array interpolate2d_nearest(Vec2<int> shape,
179 const std::vector<float> &x,
180 const std::vector<float> &y,
181 const std::vector<float> &values,
182 const Array *p_noise_x = nullptr,
183 const Array *p_noise_y = nullptr,
184 const Array *p_stretching = nullptr,
185 Vec4<float> bbox = {0.f, 1.f, 0.f, 1.f});
186
207Array interpolate2d_delaunay(Vec2<int> shape,
208 const std::vector<float> &x,
209 const std::vector<float> &y,
210 const std::vector<float> &values,
211 const Array *p_noise_x = nullptr,
212 const Array *p_noise_y = nullptr,
213 const Array *p_stretching = nullptr,
214 Vec4<float> bbox = {0.f, 1.f, 0.f, 1.f});
215
216} // 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
Array harmonic_interpolation(const Array &array, const Array &mask_fixed_values, int iterations_max=10000, float tolerance=1e-3f, float omega=1.8f)
Perform harmonic interpolation on a 2D array using the Successive Over-Relaxation (SOR) method.
Definition harmonic_interpolation.cpp:11
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