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 <cstdint>
23#include <vector>
24
25#include "highmap/array.hpp"
26
27namespace hmap
28{
29
30class Texture;
31
46void flip_lr(Array &array);
47
53void flip_lr(Texture &texture);
54
69void flip_ud(Array &array);
70
76void flip_ud(Texture &texture);
77
94void radial_displacement_to_xy(const Array &dr,
95 Array &dx,
96 Array &dy,
97 float smoothing = 1.f,
98 glm::vec2 center = {0.5f, 0.5f},
99 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
100
109void rot180(Array &array);
110
116void rot180(Texture &texture);
117
126void rot270(Array &array);
127
133void rot270(Texture &texture);
134
149void rot90(Array &array);
150
156void rot90(Texture &texture);
157
178void rotate(Array &array,
179 float angle,
180 bool zoom_in = true,
181 bool zero_padding = false);
182
197void rotate_displacement(const Array &delta, float angle, Array &dx, Array &dy);
198
234Array translate(const Array &array,
235 float dx,
236 float dy,
237 bool periodic = false,
238 const Array *p_noise_x = nullptr,
239 const Array *p_noise_y = nullptr,
240 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
241
252Array transpose(const Array &array);
253
260Texture transpose(const Texture &texture);
261
280void warp(Array &array, const Array *p_dx, const Array *p_dy);
281
304void warp_directional(Array &array,
305 float angle,
306 float amount = 0.02f,
307 int ir = 4,
308 bool reverse = false);
309
334void warp_directional(Array &array,
335 float angle,
336 const Array *p_mask,
337 float amount = 0.02f,
338 int ir = 4,
339 bool reverse = false);
340
362void warp_downslope(Array &array,
363 float amount = 0.02f,
364 int ir = 4,
365 bool reverse = false);
366
390void warp_downslope(Array &array,
391 const Array *p_mask,
392 float amount = 0.02f,
393 int ir = 4,
394 bool reverse = false);
395
441Array zoom(const Array &array,
442 float zoom_factor,
443 bool periodic = false,
444 glm::vec2 center = {0.5f, 0.5f},
445 const Array *p_noise_x = nullptr,
446 const Array *p_noise_y = nullptr,
447 glm::vec4 bbox = {0.f, 1.f, 0.f, 1.f});
448
449} // namespace hmap
450
451namespace hmap::gpu
452{
453
497Array advection_particle(const Array &z,
498 const Array &advected_field,
499 int iterations,
500 int nparticles,
501 std::uint32_t seed,
502 bool reverse = false,
503 bool post_filter = true,
504 float post_filter_sigma = 0.125f,
505 float advection_length = 0.1f,
506 float value_persistence = 0.99f,
507 float inertia = 0.f,
508 const Array *p_advection_mask = nullptr,
509 const Array *p_mask = nullptr);
510
511std::vector<Array> advection_particle(const Array &z,
512 const std::vector<Array> &advected_fields,
513 int iterations,
514 int nparticles,
515 std::uint32_t seed,
516 bool reverse = false,
517 bool post_filter = true,
518 float post_filter_sigma = 0.125f,
519 float advection_length = 0.1f,
520 float value_persistence = 0.99f,
521 float inertia = 0.f,
522 const Array *p_advection_mask = nullptr,
523 const Array *p_mask = nullptr);
524
525Array advection_particle(const Array &z,
526 const Array &advected_field,
527 int nparticles,
528 std::uint32_t seed,
529 bool reverse = false,
530 bool post_filter = true,
531 float post_filter_sigma = 0.125f,
532 float advection_length = 0.1f,
533 float value_persistence = 0.99f,
534 float inertia = 0.f,
535 const Array *p_advection_mask = nullptr,
536 const Array *p_mask = nullptr);
537
538std::vector<Array> advection_particle(const Array &z,
539 const std::vector<Array> &advected_fields,
540 int nparticles,
541 std::uint32_t seed,
542 bool reverse = false,
543 bool post_filter = true,
544 float post_filter_sigma = 0.125f,
545 float advection_length = 0.1f,
546 float value_persistence = 0.99f,
547 float inertia = 0.f,
548 const Array *p_advection_mask = nullptr,
549 const Array *p_mask = nullptr);
550
551Array advection_particle(const Array &dx,
552 const Array &dy,
553 const Array &advected_field,
554 int nparticles,
555 std::uint32_t seed,
556 bool reverse = false,
557 bool post_filter = true,
558 float post_filter_sigma = 0.125f,
559 float advection_length = 0.1f,
560 float value_persistence = 0.99f,
561 float inertia = 0.f,
562 const Array *p_advection_mask = nullptr,
563 const Array *p_mask = nullptr);
564
565std::vector<Array> advection_particle(const Array &dx,
566 const Array &dy,
567 const std::vector<Array> &advected_fields,
568 int nparticles,
569 std::uint32_t seed,
570 bool reverse = false,
571 bool post_filter = true,
572 float post_filter_sigma = 0.125f,
573 float advection_length = 0.1f,
574 float value_persistence = 0.99f,
575 float inertia = 0.f,
576 const Array *p_advection_mask = nullptr,
577 const Array *p_mask = nullptr);
578
609Array advection_warp(const Array &z,
610 const Array &advected_field,
611 float advection_length = 0.1f,
612 float value_persistence = 0.9f,
613 const Array *p_mask = nullptr);
614
615Array advection_warp(const Array &z,
616 const Array &advected_field,
617 const Array &dx,
618 const Array &dy,
619 float advection_length = 0.1f,
620 float value_persistence = 0.9f,
621 const Array *p_mask = nullptr);
622
624void rotate(Array &array, float angle, bool zoom_in = true);
625
627void warp(Array &array, const Array *p_dx, const Array *p_dy);
628
629} // namespace hmap::gpu
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
Definition blending.hpp:225
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:22
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:58
void warp(Array &array, const Array *p_dx, const Array *p_dy)
See hmap::warp.
Definition warp_gpu.cpp:15
void rotate(Array &array, float angle, bool zoom_in=true)
See hmap::rotate.
Definition transform_gpu.cpp:15
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:17
void flip_lr(Array &array)
Flip the array horizontally (left/right).
Definition transform.cpp:21
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:196
void flip_ud(Array &array)
Flip the array vertically (up/down).
Definition transform.cpp:30
void rot180(Array &array)
Rotate the array by 180 degrees.
Definition transform.cpp:68
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:84
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:145
void rot270(Array &array)
Rotate the array by 270 degrees.
Definition transform.cpp:76
void rotate(Array &array, float angle, bool zoom_in=true, bool zero_padding=false)
Rotate the array by a specified angle.
Definition transform.cpp:92
Array transpose(const Array &array)
Return the transposed array.
Definition transform.cpp:183
float angle(const Point &p1, const Point &p2)
Computes the angle between two points relative to the x-axis.
Definition points.cpp:52
void rot90(Array &array)
Rotate the array by 90 degrees.
Definition transform.cpp:84
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:34
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:136
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:39