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/texture.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
168Array gradient_norm_filtered(const Array &array, int ir);
169
192Array gradient_norm_prewitt(const Array &array,
193 Array *p_dx = nullptr,
194 Array *p_dy = nullptr);
195
212Array gradient_norm_scharr(const Array &array,
213 Array *p_dx = nullptr,
214 Array *p_dy = nullptr);
215
232Array gradient_norm_sobel(const Array &array,
233 Array *p_dx = nullptr,
234 Array *p_dy = nullptr);
235
250Array gradient_talus(const Array &array);
251
263void gradient_talus(const Array &array, Array &talus);
264
276Array gradient_x(const Array &array);
277
288void gradient_x(const Array &array, Array &dx);
289
301Array gradient_y(const Array &array);
302
313void gradient_y(const Array &array, Array &dy);
314
332Array laplacian(const Array &array);
333
347Texture normal_map(const Array &array);
348
376Array normal_map_to_heightmap(const Texture &nmap);
377
378Array normal_map_to_heightmap_poisson(const Texture &nmap,
379 int iterations = 500,
380 float omega = 1.5f);
381
401void solve_poisson_gauss_seidel(const Array &rhs,
402 Array &h,
403 int iterations = 500,
404 float omega = 1.0f);
405
422Array unwrap_phase(const Array &alpha);
423
424/* See unit tests: @ref test_gradient.cpp */
425Array talus_jump_mask(const Array &z, float threshold, float sigma);
426
427} // namespace hmap
428
429namespace hmap::gpu
430{
431
433Array gradient_angle_circular_smoothing(const Array &array,
434 int ir,
435 bool downward = false);
436
438Array gradient_norm(const Array &array);
439
458Array laplacian_fract(const Array &array, float s, int ir);
459
466void phase_averaging(Array &field_real, Array &field_imag, int ir);
467
493Array phase_field(const Array &array,
494 const glm::vec2 &kw,
495 std::uint32_t seed,
496 float kp,
497 bool rotate90 = false,
498 int n_kernel_samples = 8,
499 const glm::vec2 &jitter = {0.5f, 0.5f},
500 int angle_filter_ir = 8,
501 const Array *p_ctrl_param = nullptr,
502 const Array *p_noise_x = nullptr,
503 const Array *p_noise_y = nullptr,
504 Array *p_modulus = nullptr,
505 Array *p_angle_jump_mask = nullptr,
506 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
507
531Array phase_field(const Array &array,
532 std::uint32_t seed,
533 float kp_global,
534 bool rotate90 = false,
535 int n_kernel_samples = 8,
536 const glm::vec2 &jitter = {0.5f, 0.5f},
537 int angle_filter_ir = 8,
538 const Array *p_ctrl_param = nullptr,
539 const Array *p_noise_x = nullptr,
540 const Array *p_noise_y = nullptr,
541 Array *p_modulus = nullptr,
542 Array *p_angle_jump_mask = nullptr,
543 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
544
545Array phase_field_angle(const Array &angle, // rads
546 const glm::vec2 &kw,
547 std::uint32_t seed,
548 float kp,
549 int n_kernel_samples = 8,
550 const glm::vec2 &jitter = {0.5f, 0.5f},
551 const Array *p_ctrl_param = nullptr,
552 const Array *p_noise_x = nullptr,
553 const Array *p_noise_y = nullptr,
554 Array *p_modulus = nullptr,
555 Array *p_angle_jump_mask = nullptr,
556 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
557
558} // namespace hmap::gpu
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
Definition blending.hpp:225
Array gradient_norm(const Array &array)
See hmap::gradient_norm.
Definition gradient_gpu.cpp:53
Array phase_field_angle(const Array &angle, const glm::vec2 &kw, std::uint32_t seed, float kp, int n_kernel_samples=8, const glm::vec2 &jitter={0.5f, 0.5f}, 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:164
Array laplacian_fract(const Array &array, float s, int ir)
Compute the fractional Laplacian of an array.
Definition gradient_gpu.cpp:75
Array phase_field(const Array &array, const glm::vec2 &kw, std::uint32_t 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:48
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:19
Array gradient_angle_circular_smoothing(const Array &array, int ir, bool downward=false)
See hmap::gradient_angle_circular_smoothing.
Definition gradient_gpu.cpp:18
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:10
Array gradient_x(const Array &array)
Compute the gradient in the x-direction of a 2D array.
Definition gradient.cpp:205
Array talus_jump_mask(const Array &z, float threshold, float sigma)
Definition gradient.cpp:305
Array divergence_from_gradients(const Array &dx, const Array &dy)
Compute the divergence of a 2D gradient field.
Definition gradient.cpp:64
Array threshold(const Array &array, float x0, float x1)
Linear threshold.
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:16
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:191
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:96
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:131
Array gradient_talus(const Array &array)
Compute the gradient talus slope of a 2D array.
Definition gradient.cpp:257
Array normal_map_to_heightmap_poisson(const Texture &nmap, int iterations=500, float omega=1.5f)
Definition normal_map.cpp:73
Array gradient_norm_filtered(const Array &array, int ir)
Compute a smoothed gradient magnitude map.
Definition gradient.cpp:146
Array laplacian(const Array &array)
Compute the Laplacian of a 2D array.
Definition gradient.cpp:290
Array gradient_y(const Array &array)
Compute the gradient in the y-direction of a 2D array.
Definition gradient.cpp:231
float angle(const Point &p1, const Point &p2)
Computes the angle between two points relative to the x-axis.
Definition points.cpp:52
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:161
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:176
Array normal_map_to_heightmap(const Texture &nmap)
Converts a normal map to a heightmap using direct summation of gradients.
Definition normal_map.cpp:38
Texture normal_map(const Array &array)
Generates a normal map from a given 2D array.
Definition normal_map.cpp:16
Array gradient_angle(const Array &array, bool downward=false)
Compute the polar angle of the gradient of a 2D array.
Definition gradient.cpp:73
Header file for the Texture class.