HighMap library (C++)
Loading...
Searching...
No Matches
gradient.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
16#pragma once
17
18#include "highmap/array.hpp"
19#include "highmap/tensor.hpp"
20
21namespace hmap
22{
23
52Array divergence_from_gradients(const Array &dx, const Array &dy);
53
63std::vector<float> gradient1d(const std::vector<float> &v);
64
85Array gradient_angle(const Array &array, bool downward = false);
86
121Array gradient_angle_circular_smoothing(const Array &array,
122 int ir,
123 bool downward = false);
124
147Array gradient_norm(const Array &array,
148 Array *p_dx = nullptr,
149 Array *p_dy = nullptr);
150
173Array gradient_norm_prewitt(const Array &array,
174 Array *p_dx = nullptr,
175 Array *p_dy = nullptr);
176
193Array gradient_norm_scharr(const Array &array,
194 Array *p_dx = nullptr,
195 Array *p_dy = nullptr);
196
213Array gradient_norm_sobel(const Array &array,
214 Array *p_dx = nullptr,
215 Array *p_dy = nullptr);
216
231Array gradient_talus(const Array &array);
232
244void gradient_talus(const Array &array, Array &talus);
245
257Array gradient_x(const Array &array);
258
269void gradient_x(const Array &array, Array &dx);
270
282Array gradient_y(const Array &array);
283
294void gradient_y(const Array &array, Array &dy);
295
313Array laplacian(const Array &array);
314
328Tensor normal_map(const Array &array);
329
357Array normal_map_to_heightmap(const Tensor &nmap);
358
359Array normal_map_to_heightmap_poisson(const Tensor &nmap,
360 int iterations = 500,
361 float omega = 1.5f);
362
382void solve_poisson_gauss_seidel(const Array &rhs,
383 Array &h,
384 int iterations = 500,
385 float omega = 1.0f);
386
403Array unwrap_phase(const Array &alpha);
404
405/* See unit tests: @ref test_gradient.cpp */
406Array talus_jump_mask(const Array &z, float threshold, float sigma);
407
408} // namespace hmap
409
410namespace hmap::gpu
411{
412
414Array gradient_angle_circular_smoothing(const Array &array,
415 int ir,
416 bool downward = false);
417
419Array gradient_norm(const Array &array);
420
439Array laplacian_fract(const Array &array, float s, int ir);
440
447void phase_averaging(Array &field_real, Array &field_imag, int ir);
448
474Array phase_field(const Array &array,
475 const glm::vec2 &kw,
476 uint seed,
477 float kp,
478 bool rotate90 = false,
479 int n_kernel_samples = 8,
480 const glm::vec2 &jitter = {0.5f, 0.5f},
481 int angle_filter_ir = 8,
482 const Array *p_ctrl_param = nullptr,
483 const Array *p_noise_x = nullptr,
484 const Array *p_noise_y = nullptr,
485 Array *p_modulus = nullptr,
486 Array *p_angle_jump_mask = nullptr,
487 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
488
512Array phase_field(const Array &array,
513 uint seed,
514 float kp_global,
515 bool rotate90 = false,
516 int n_kernel_samples = 8,
517 const glm::vec2 &jitter = {0.5f, 0.5f},
518 int angle_filter_ir = 8,
519 const Array *p_ctrl_param = nullptr,
520 const Array *p_noise_x = nullptr,
521 const Array *p_noise_y = nullptr,
522 Array *p_modulus = nullptr,
523 Array *p_angle_jump_mask = nullptr,
524 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
525
526Array phase_field_angle(const Array &angle, // rads
527 const glm::vec2 &kw,
528 uint seed,
529 float kp,
530 int n_kernel_samples = 8,
531 const glm::vec2 &jitter = {0.5f, 0.5f},
532 int angle_filter_ir = 8,
533 const Array *p_ctrl_param = nullptr,
534 const Array *p_noise_x = nullptr,
535 const Array *p_noise_y = nullptr,
536 Array *p_modulus = nullptr,
537 Array *p_angle_jump_mask = nullptr,
538 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
539
540} // namespace hmap::gpu
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
unsigned int uint
Definition array.hpp:14
Definition blending.hpp:186
Array phase_field(const Array &array, const glm::vec2 &kw, uint seed, float kp, bool rotate90=false, int n_kernel_samples=8, const glm::vec2 &jitter={0.5f, 0.5f}, int angle_filter_ir=8, const Array *p_ctrl_param=nullptr, const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr, Array *p_modulus=nullptr, Array *p_angle_jump_mask=nullptr, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f})
Compute a phase field from an input array using local orientation and noise.
Definition phase_field.cpp:40
Array gradient_norm(const Array &array)
See hmap::gradient_norm.
Definition gradient_gpu.cpp:46
Array laplacian_fract(const Array &array, float s, int ir)
Compute the fractional Laplacian of an array.
Definition gradient_gpu.cpp:66
void phase_averaging(Array &field_real, Array &field_imag, int ir)
Apply phase averaging on real and imaginary fields using a GPU kernel.
Definition phase_field.cpp:17
Array gradient_angle_circular_smoothing(const Array &array, int ir, bool downward=false)
See hmap::gradient_angle_circular_smoothing.
Definition gradient_gpu.cpp:13
Array phase_field_angle(const Array &angle, const glm::vec2 &kw, uint seed, float kp, int n_kernel_samples=8, const glm::vec2 &jitter={0.5f, 0.5f}, int angle_filter_ir=8, const Array *p_ctrl_param=nullptr, const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr, Array *p_modulus=nullptr, Array *p_angle_jump_mask=nullptr, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f})
Definition phase_field.cpp:140
Definition algebra.hpp:23
void solve_poisson_gauss_seidel(const Array &rhs, Array &h, int iterations=500, float omega=1.0f)
Solve the Poisson equation ∇²h = rhs using Gauss–Seidel iteration.
Definition solve_poisson_gauss_seidel.cpp:9
Array gradient_x(const Array &array)
Compute the gradient in the x-direction of a 2D array.
Definition gradient.cpp:173
Array talus_jump_mask(const Array &z, float threshold, float sigma)
Definition gradient.cpp:256
Array normal_map_to_heightmap(const Tensor &nmap)
Converts a normal map to a heightmap using direct summation of gradients.
Definition normal_map.cpp:32
Array divergence_from_gradients(const Array &dx, const Array &dy)
Compute the divergence of a 2D gradient field.
Definition gradient.cpp:61
float threshold(float x, float x0, float x1)
Applies a linear threshold to a scalar value.
Definition math.cpp:498
Array unwrap_phase(const Array &alpha)
Unwraps a 2D phase array to correct discontinuities in phase data.
Definition unwrap_phase.cpp:14
Array gradient_norm_scharr(const Array &array, Array *p_dx=nullptr, Array *p_dy=nullptr)
Compute the gradient norm of a 2D array using the Scharr filter.
Definition gradient.cpp:161
Array normal_map_to_heightmap_poisson(const Tensor &nmap, int iterations=500, float omega=1.5f)
Definition normal_map.cpp:65
Array gradient_angle_circular_smoothing(const Array &array, int ir, bool downward=false)
Computes a smoothed gradient angle (aspect) field with circular unwrapping.
Definition gradient.cpp:89
Array gradient_norm(const Array &array, Array *p_dx=nullptr, Array *p_dy=nullptr)
Compute the gradient norm of a 2D array.
Definition gradient.cpp:122
Array gradient_talus(const Array &array)
Compute the gradient talus slope of a 2D array.
Definition gradient.cpp:215
Array laplacian(const Array &array)
Compute the Laplacian of a 2D array.
Definition gradient.cpp:243
Array gradient_y(const Array &array)
Compute the gradient in the y-direction of a 2D array.
Definition gradient.cpp:194
float angle(const Point &p1, const Point &p2)
Computes the angle between two points relative to the x-axis.
Definition points.cpp:42
Array gradient_norm_prewitt(const Array &array, Array *p_dx=nullptr, Array *p_dy=nullptr)
Compute the gradient norm of a 2D array using the Prewitt filter.
Definition gradient.cpp:135
std::vector< float > gradient1d(const std::vector< float > &v)
Compute the gradient of a 1D vector.
Definition vector.cpp:17
Array gradient_norm_sobel(const Array &array, Array *p_dx=nullptr, Array *p_dy=nullptr)
Compute the gradient norm of a 2D array using the Sobel filter.
Definition gradient.cpp:148
Array gradient_angle(const Array &array, bool downward=false)
Compute the polar angle of the gradient of a 2D array.
Definition gradient.cpp:68
Tensor normal_map(const Array &array)
Generates a normal map from a given 2D array.
Definition normal_map.cpp:12
Header file for the Tensor class.