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
21extern "C" // order matters
22{
23#include "config.h"
24//
25#include "nn.h"
26//
27#include "nncommon.h"
28//
29#include "delaunay.h"
30}
31
32#include "highmap/array.hpp"
33
34namespace hmap
35{
36
52
54{
55public:
58
59 void build(const std::vector<float> &xin, const std::vector<float> &yin);
60
61 void setup_output_points(const std::vector<float> &x,
62 const std::vector<float> &y);
63
64 void interpolate(const std::vector<float> &values_in,
65 std::vector<float> &values_out) const;
66
67private:
68 nnai *handle = nullptr;
69 delaunay *d = nullptr;
70 std::vector<double> xout;
71 std::vector<double> yout;
72 size_t nout = 0;
73};
74
91inline float bilinear_interp(float f00,
92 float f10,
93 float f01,
94 float f11,
95 float u,
96 float v)
97{
98 float a10 = f10 - f00;
99 float a01 = f01 - f00;
100 float a11 = f11 - f10 - f01 + f00;
101 return f00 + a10 * u + a01 * v + a11 * u * v;
102}
103
104inline float cubic_interpolate(float p[4], float x)
105{
106 return p[1] + 0.5 * x *
107 (p[2] - p[0] +
108 x * (2.0 * p[0] - 5.0 * p[1] + 4.0 * p[2] - p[3] +
109 x * (3.0 * (p[1] - p[2]) + p[3] - p[0])));
110}
111
145Array harmonic_interpolation(const Array &array,
146 const Array &mask_fixed_values,
147 int iterations_max = 500,
148 float tolerance = 1e-5f,
149 float omega = 1.8f);
150
172Array interpolate2d(glm::ivec2 shape,
173 const std::vector<float> &x,
174 const std::vector<float> &y,
175 const std::vector<float> &values,
176 InterpolationMethod2D interpolation_method,
177 const Array *p_noise_x = nullptr,
178 const Array *p_noise_y = nullptr,
179 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
180
199Array interpolate2d_delaunay(glm::ivec2 shape,
200 const std::vector<float> &x,
201 const std::vector<float> &y,
202 const std::vector<float> &values,
203 const Array *p_noise_x = nullptr,
204 const Array *p_noise_y = nullptr,
205 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
206
210Array interpolate2d_gaussian(glm::ivec2 shape,
211 const std::vector<float> &x,
212 const std::vector<float> &y,
213 const std::vector<float> &values,
214 const Array *p_noise_x = nullptr,
215 const Array *p_noise_y = nullptr,
216 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f},
217 float sigma = 0.1f);
218
222Array interpolate2d_idw(glm::ivec2 shape,
223 const std::vector<float> &x,
224 const std::vector<float> &y,
225 const std::vector<float> &values,
226 const Array *p_noise_x = nullptr,
227 const Array *p_noise_y = nullptr,
228 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f},
229 float distance_exp = 2.f);
230
248Array interpolate2d_nearest(glm::ivec2 shape,
249 const std::vector<float> &x,
250 const std::vector<float> &y,
251 const std::vector<float> &values,
252 const Array *p_noise_x = nullptr,
253 const Array *p_noise_y = nullptr,
254 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
255
259Array interpolate2d_nni(glm::ivec2 shape,
260 const std::vector<float> &x,
261 const std::vector<float> &y,
262 const std::vector<float> &values,
263 const Array *p_noise_x = nullptr,
264 const Array *p_noise_y = nullptr,
265 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
266
267} // namespace hmap
268
269namespace hmap::gpu
270{
271
273Array harmonic_interpolation(const Array &array,
274 const Array &mask_fixed_values,
275 int iterations_max = 500);
276
277} // namespace hmap::gpu
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
Definition interpolate2d.hpp:54
void build(const std::vector< float > &xin, const std::vector< float > &yin)
Definition natural_neighbor_interpolator.cpp:19
void interpolate(const std::vector< float > &values_in, std::vector< float > &values_out) const
Definition natural_neighbor_interpolator.cpp:40
~NaturalNeighborInterpolator()
Definition natural_neighbor_interpolator.cpp:13
void setup_output_points(const std::vector< float > &x, const std::vector< float > &y)
Definition natural_neighbor_interpolator.cpp:60
Definition blending.hpp:186
Definition algebra.hpp:23
Array interpolate2d_delaunay(glm::ivec2 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, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f})
2D interpolation using the Delaunay triangulation method.
Definition interpolate2d.cpp:70
Array interpolate2d_gaussian(glm::ivec2 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, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f}, float sigma=0.1f)
2D interpolation using the Gaussian kernel method.
Definition interpolate2d.cpp:224
Array interpolate2d_idw(glm::ivec2 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, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f}, float distance_exp=2.f)
2D interpolation using the IDW method.
Definition interpolate2d.cpp:272
Array interpolate2d_nearest(glm::ivec2 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, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f})
2D interpolation using the nearest neighbor method.
Definition interpolate2d.cpp:319
InterpolationMethod2D
Enumeration of 2D interpolation methods.
Definition interpolate2d.hpp:45
@ ITP2D_IDW
Inverse Distance Weighting.
Definition interpolate2d.hpp:48
@ ITP2D_DELAUNAY
Delaunay triangulation method for 2D interpolation.
Definition interpolate2d.hpp:46
@ ITP2D_NNI
Natural Neighbor Interpolation.
Definition interpolate2d.hpp:50
@ ITP2D_GAUSSIAN
Gaussian Distance Weighting.
Definition interpolate2d.hpp:49
@ ITP2D_NEAREST
Nearest point method for 2D interpolation.
Definition interpolate2d.hpp:47
Array harmonic_interpolation(const Array &array, const Array &mask_fixed_values, int iterations_max=500, float tolerance=1e-5f, float omega=1.8f)
Perform harmonic interpolation on a 2D array using the Successive Over-Relaxation (SOR) method.
Definition harmonic_interpolation.cpp:11
Array interpolate2d_nni(glm::ivec2 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, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f})
2D interpolation using the Natural Neighbor Interpolation method.
Definition interpolate2d.cpp:357
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:91
Array interpolate2d(glm::ivec2 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, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f})
Generic 2D interpolation function.
Definition interpolate2d.cpp:18
float cubic_interpolate(float p[4], float x)
Definition interpolate2d.hpp:104