HighMap library (C++)
Loading...
Searching...
No Matches
transform.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
20#pragma once
21
22#include "macrologger.h"
23
24#include "highmap/array.hpp"
25
26namespace hmap
27{
28
43void flip_lr(Array &array);
44
59void flip_ud(Array &array);
60
77void radial_displacement_to_xy(const Array &dr,
78 Array &dx,
79 Array &dy,
80 float smoothing = 1.f,
81 glm::vec2 center = {0.5f, 0.5f},
82 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
83
92void rot180(Array &array);
93
102void rot270(Array &array);
103
118void rot90(Array &array);
119
139void rotate(Array &array,
140 float angle,
141 bool zoom_in = true,
142 bool zero_padding = false);
143
158void rotate_displacement(const Array &delta, float angle, Array &dx, Array &dy);
159
170Array transpose(const Array &array);
171
207Array translate(const Array &array,
208 float dx,
209 float dy,
210 bool periodic = false,
211 const Array *p_noise_x = nullptr,
212 const Array *p_noise_y = nullptr,
213 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
214
233void warp(Array &array, const Array *p_dx, const Array *p_dy);
234
257void warp_directional(Array &array,
258 float angle,
259 float amount = 0.02f,
260 int ir = 4,
261 bool reverse = false);
262
287void warp_directional(Array &array,
288 float angle,
289 const Array *p_mask,
290 float amount = 0.02f,
291 int ir = 4,
292 bool reverse = false);
293
315void warp_downslope(Array &array,
316 float amount = 0.02f,
317 int ir = 4,
318 bool reverse = false);
319
343void warp_downslope(Array &array,
344 const Array *p_mask,
345 float amount = 0.02f,
346 int ir = 4,
347 bool reverse = false);
348
394Array zoom(const Array &array,
395 float zoom_factor,
396 bool periodic = false,
397 glm::vec2 center = {0.5f, 0.5f},
398 const Array *p_noise_x = nullptr,
399 const Array *p_noise_y = nullptr,
400 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
401
402} // namespace hmap
403
404namespace hmap::gpu
405{
406
450Array advection_particle(const Array &z,
451 const Array &advected_field,
452 int iterations,
453 int nparticles,
454 std::uint32_t seed,
455 bool reverse = false,
456 bool post_filter = true,
457 float post_filter_sigma = 0.125f,
458 float advection_length = 0.1f,
459 float value_persistence = 0.99f,
460 float inertia = 0.f,
461 const Array *p_advection_mask = nullptr,
462 const Array *p_mask = nullptr);
463
464Array advection_particle(const Array &z,
465 const Array &advected_field,
466 int nparticles,
467 std::uint32_t seed,
468 bool reverse = false,
469 bool post_filter = true,
470 float post_filter_sigma = 0.125f,
471 float advection_length = 0.1f,
472 float value_persistence = 0.99f,
473 float inertia = 0.f,
474 const Array *p_advection_mask = nullptr,
475 const Array *p_mask = nullptr);
476
477Array advection_particle(const Array &dx,
478 const Array &dy,
479 const Array &advected_field,
480 int nparticles,
481 std::uint32_t seed,
482 bool reverse = false,
483 bool post_filter = true,
484 float post_filter_sigma = 0.125f,
485 float advection_length = 0.1f,
486 float value_persistence = 0.99f,
487 float inertia = 0.f,
488 const Array *p_advection_mask = nullptr,
489 const Array *p_mask = nullptr);
490
521Array advection_warp(const Array &z,
522 const Array &advected_field,
523 float advection_length = 0.1f,
524 float value_persistence = 0.9f,
525 const Array *p_mask = nullptr);
526
527Array advection_warp(const Array &z,
528 const Array &advected_field,
529 const Array &dx,
530 const Array &dy,
531 float advection_length = 0.1f,
532 float value_persistence = 0.9f,
533 const Array *p_mask = nullptr);
534
536void rotate(Array &array, float angle, bool zoom_in = true);
537
539void warp(Array &array, const Array *p_dx, const Array *p_dy);
540
541} // namespace hmap::gpu
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
Definition blending.hpp:186
Array advection_particle(const Array &z, const Array &advected_field, int iterations, int nparticles, std::uint32_t seed, bool reverse=false, bool post_filter=true, float post_filter_sigma=0.125f, float advection_length=0.1f, float value_persistence=0.99f, float inertia=0.f, const Array *p_advection_mask=nullptr, const Array *p_mask=nullptr)
Performs particle-based advection on a scalar field.
Definition advection_particle_gpu.cpp:20
Array advection_warp(const Array &z, const Array &advected_field, float advection_length=0.1f, float value_persistence=0.9f, const Array *p_mask=nullptr)
Performs 2D field advection based on the gradient of a heightmap using a warp-based technic (simplifi...
Definition advection_warp_gpu.cpp:52
void warp(Array &array, const Array *p_dx, const Array *p_dy)
See hmap::warp.
Definition warp_gpu.cpp:14
void rotate(Array &array, float angle, bool zoom_in=true)
See hmap::rotate.
Definition transform_gpu.cpp:14
Definition algebra.hpp:23
void warp(Array &array, const Array *p_dx, const Array *p_dy)
Apply a warping effect to the array.
Definition warp.cpp:16
void flip_lr(Array &array)
Flip the array horizontally (left/right).
Definition transform.cpp:20
Array zoom(const Array &array, float zoom_factor, bool periodic=false, glm::vec2 center={0.5f, 0.5f}, const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f})
Applies a zoom effect to a 2D array with an adjustable center.
Definition transform.cpp:171
void flip_ud(Array &array)
Flip the array vertically (up/down).
Definition transform.cpp:27
void rot180(Array &array)
Rotate the array by 180 degrees.
Definition transform.cpp:61
void warp_downslope(Array &array, float amount=0.02f, int ir=4, bool reverse=false)
Apply a warping effect following the downward local gradient direction (deflate/inflate effect).
Definition warp.cpp:74
Array translate(const Array &array, float dx, float dy, bool periodic=false, const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f})
Translates a 2D array by a specified amount along the x and y axes.
Definition transform.cpp:128
void rot270(Array &array)
Rotate the array by 270 degrees.
Definition transform.cpp:67
void rotate(Array &array, float angle, bool zoom_in=true, bool zero_padding=false)
Rotate the array by a specified angle.
Definition transform.cpp:79
Array transpose(const Array &array)
Return the transposed array.
Definition transform.cpp:160
float angle(const Point &p1, const Point &p2)
Computes the angle between two points relative to the x-axis.
Definition points.cpp:46
void rot90(Array &array)
Rotate the array by 90 degrees.
Definition transform.cpp:73
void warp_directional(Array &array, float angle, float amount=0.02f, int ir=4, bool reverse=false)
Apply a warping effect following the downward local gradient direction (deflate/inflate effect).
Definition warp.cpp:29
void rotate_displacement(const Array &delta, float angle, Array &dx, Array &dy)
Rotates a scalar displacement field into directional X and Y components.
Definition transform.cpp:121
void radial_displacement_to_xy(const Array &dr, Array &dx, Array &dy, float smoothing=1.f, glm::vec2 center={0.5f, 0.5f}, glm::vec4 bbox={0.f, 1.f, 0.f, 1.f})
Interpret the input array dr as a radial displacement and convert it to a pair of displacements dx an...
Definition transform.cpp:34