HighMap library (C++)
Loading...
Searching...
No Matches
operator.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
20#include "highmap/array.hpp"
22
23namespace hmap
24{
25
38void add_kernel(Array &array, const Array &kernel, int i, int j);
39
64void add_kernel_maximum_smooth(Array &array,
65 const Array &kernel,
66 float k_smooth,
67 int i,
68 int j);
69
85Array compare(const Array &a,
86 const Array &b,
87 float slice_x_pos,
88 float slice_y_pos);
89
102Array hstack(const Array &array1, const Array &array2);
103
122Array inpainting_diffusion(const Array &array,
123 const Array &mask,
124 int iterations);
125
141std::vector<float> linspace(float start,
142 float stop,
143 int num,
144 bool endpoint = true);
145
164std::vector<float> linspace_jitted(float start,
165 float stop,
166 int num,
167 float ratio,
168 int seed,
169 bool endpoint = true);
170
182std::vector<float> logspace(float start,
183 float stop,
184 int num,
185 bool endpoint = true);
186
215 Array &array,
216 glm::vec4 bbox,
217 const Array *p_ctrl_param,
218 const Array *p_noise_x,
219 const Array *p_noise_y,
220 const Array *p_stretching,
221 std::function<float(float, float, float)> fct_xy);
222
255 Array &array,
256 glm::vec4 bbox,
257 const Array *p_ctrl_param,
258 const Array *p_noise_x,
259 const Array *p_noise_y,
260 const Array *p_stretching,
261 std::function<float(float, float, float)> fct_xy,
262 int subsampling);
263
275void find_vertical_cut_path(const Array &error, std::vector<int> &path_i);
276
289Array generate_mask(glm::ivec2 shape, std::vector<int> cut_path_i, int ir);
290
321Array get_random_patch(const Array &array,
322 glm::ivec2 patch_shape,
323 std::mt19937 &gen,
324 bool patch_flip = false,
325 bool patch_rotate = false,
326 bool patch_transpose = false,
327 std::vector<Array *> *p_secondary_arrays = nullptr,
328 std::vector<Array> *p_secondary_patches = nullptr);
329
343std::vector<float> random_vector(float min, float max, int num, int seed);
344
364void rescale_vector(std::vector<float> &vec, float vmin, float vmax);
365
366std::vector<float> rescaled_vector(const std::vector<float> &vec,
367 float vmin,
368 float vmax);
369
376void swap(Array &a, Array &b);
377
390Array vstack(const Array &array1, const Array &array2);
391
392// === HELPERS
393
405template <typename Fn>
406void apply_with_mask(Array &array, const Array *p_mask, Fn &&fn)
407{
408 if (!p_mask)
409 {
410 fn(array);
411 }
412 else
413 {
414 Array result = array;
415 fn(result);
416 array = lerp(array, result, *p_mask);
417 }
418}
419
432template <typename Fn>
433Array transform_with_mask(const Array &array, const Array *p_mask, Fn &&fn)
434{
435 Array result = fn(array);
436
437 if (p_mask)
438 return lerp(array, result, *p_mask);
439 else
440 return result;
441}
442
443} // namespace hmap
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
Array class, helper to manipulate 2D float array with "(i, j)" indexing.
Definition array.hpp:32
Definition algebra.hpp:23
std::vector< float > linspace_jitted(float start, float stop, int num, float ratio, int seed, bool endpoint=true)
Generate a vector of jittered (noised) numbers over a specified interval.
Definition vector.cpp:70
Array get_random_patch(const Array &array, glm::ivec2 patch_shape, std::mt19937 &gen, bool patch_flip=false, bool patch_rotate=false, bool patch_transpose=false, std::vector< Array * > *p_secondary_arrays=nullptr, std::vector< Array > *p_secondary_patches=nullptr)
Extracts a random sub-array (patch) from the input array, with optional transformations.
Definition stitching_helpers.cpp:138
void apply_with_mask(Array &array, const Array *p_mask, Fn &&fn)
Applies a transformation function with optional masked blending.
Definition operator.hpp:406
void rescale_vector(std::vector< float > &vec, float vmin, float vmax)
Rescales the values of a vector to a specified range.
Definition vector.cpp:148
void add_kernel_maximum_smooth(Array &array, const Array &kernel, float k_smooth, int i, int j)
Adds a smoothed maximum value from a kernel to a specified position in a 2D array.
Definition operator.cpp:38
std::vector< float > linspace(float start, float stop, int num, bool endpoint=true)
Generate a vector of evenly spaced numbers over a specified interval.
Definition vector.cpp:45
std::vector< float > random_vector(float min, float max, int num, int seed)
Generate a vector filled with random values within a specified range.
Definition vector.cpp:137
std::vector< float > rescaled_vector(const std::vector< float > &vec, float vmin, float vmax)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition vector.cpp:180
Array vstack(const Array &array1, const Array &array2)
Vertically stack two arrays.
Definition operator.cpp:94
void fill_array_using_xy_function(Array &array, glm::vec4 bbox, const Array *p_ctrl_param, const Array *p_noise_x, const Array *p_noise_y, const Array *p_stretching, std::function< float(float, float, float)> fct_xy)
Fill an array using a scalar function based on (x, y) coordinates.
Definition fill_array.cpp:13
std::vector< float > logspace(float start, float stop, int num, bool endpoint=true)
Generates a logarithmically spaced vector.
Definition vector.cpp:105
Array transform_with_mask(const Array &array, const Array *p_mask, Fn &&fn)
Applies a transformation function with optional masked blending.
Definition operator.hpp:433
void swap(Array &a, Array &b)
Swaps the contents of two Array objects.
Definition operator.cpp:87
Array inpainting_diffusion(const Array &array, const Array &mask, int iterations)
Perform diffusion-based inpainting to fill a specified region of an array.
Definition inpainting_gaussian.cpp:14
Point lerp(const Point &p1, const Point &p2, float t)
Linearly interpolates between two points.
Definition points.cpp:219
Array compare(const Array &a, const Array &b, float slice_x_pos, float slice_y_pos)
Combines two arrays by selecting values from a or b based on a slice position.
Definition compare.cpp:9
Array hstack(const Array &array1, const Array &array2)
Horizontally stack two arrays side by side.
Definition operator.cpp:71
void find_vertical_cut_path(const Array &error, std::vector< int > &path_i)
Find the vertical cut path with the minimum cost using Dijkstra's algorithm.
Definition stitching_helpers.cpp:27
void add_kernel(Array &array, const Array &kernel, int i, int j)
Add a kernel to a specified position in an array.
Definition operator.cpp:14
Array generate_mask(glm::ivec2 shape, std::vector< int > cut_path_i, int ir)
Generate a smooth mask based on a cut path.
Definition stitching_helpers.cpp:80