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"
23
24namespace hmap
25{
26
39void add_kernel(Array &array, const Array &kernel, int i, int j);
40
65void add_kernel_maximum_smooth(Array &array,
66 const Array &kernel,
67 float k_smooth,
68 int i,
69 int j);
70
86Array compare(const Array &a,
87 const Array &b,
88 float slice_x_pos,
89 float slice_y_pos);
90
103Array hstack(const Array &array1, const Array &array2);
104
123Array inpainting_diffusion(const Array &array,
124 const Array &mask,
125 int iterations);
126
142std::vector<float> linspace(float start,
143 float stop,
144 int num,
145 bool endpoint = true);
146
165std::vector<float> linspace_jitted(float start,
166 float stop,
167 int num,
168 float ratio,
169 int seed,
170 bool endpoint = true);
171
183std::vector<float> logspace(float start,
184 float stop,
185 int num,
186 bool endpoint = true);
187
216 Array &array,
217 glm::vec4 bbox,
218 const Array *p_ctrl_param,
219 const Array *p_noise_x,
220 const Array *p_noise_y,
221 const Array *p_stretching,
222 std::function<float(float, float, float)> fct_xy);
223
256 Array &array,
257 glm::vec4 bbox,
258 const Array *p_ctrl_param,
259 const Array *p_noise_x,
260 const Array *p_noise_y,
261 const Array *p_stretching,
262 std::function<float(float, float, float)> fct_xy,
263 int subsampling);
264
276void find_vertical_cut_path(const Array &error, std::vector<int> &path_i);
277
290Array generate_mask(glm::ivec2 shape, std::vector<int> cut_path_i, int ir);
291
322Array get_random_patch(const Array &array,
323 glm::ivec2 patch_shape,
324 std::mt19937 &gen,
325 bool patch_flip = false,
326 bool patch_rotate = false,
327 bool patch_transpose = false,
328 std::vector<Array *> *p_secondary_arrays = nullptr,
329 std::vector<Array> *p_secondary_patches = nullptr);
330
344std::vector<float> random_vector(float min, float max, int num, int seed);
345
365void rescale_vector(std::vector<float> &vec, float vmin, float vmax);
366
367std::vector<float> rescaled_vector(const std::vector<float> &vec,
368 float vmin,
369 float vmax);
370
377void swap(Array &a, Array &b);
378
391Array vstack(const Array &array1, const Array &array2);
392
393// === HELPERS
394
406template <typename Fn>
407void apply_with_mask(Array &array, const Array *p_mask, Fn &&fn)
408{
409 if (!validate_non_empty(array)) return;
410 if (p_mask && !validate_same_shape(array, *p_mask)) return;
411
412 if (!p_mask)
413 {
414 fn(array);
415 }
416 else
417 {
418 Array result = array;
419 fn(result);
420 array = lerp(array, result, *p_mask);
421 }
422}
423
436template <typename Fn>
437Array transform_with_mask(const Array &array, const Array *p_mask, Fn &&fn)
438{
439 if (!validate_non_empty(array)) return Array();
440 if (p_mask && !validate_same_shape(array, *p_mask)) return Array(array.shape);
441
442 Array result = fn(array);
443
444 if (p_mask)
445 return lerp(array, result, *p_mask);
446 else
447 return result;
448}
449
450} // 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
glm::ivec2 shape
The shape of the array {ni, nj}.
Definition array.hpp:38
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:76
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:152
void apply_with_mask(Array &array, const Array *p_mask, Fn &&fn)
Applies a transformation function with optional masked blending.
Definition operator.hpp:407
void rescale_vector(std::vector< float > &vec, float vmin, float vmax)
Rescales the values of a vector to a specified range.
Definition vector.cpp:154
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:41
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:51
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:143
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:186
Array vstack(const Array &array1, const Array &array2)
Vertically stack two arrays.
Definition operator.cpp:115
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:14
std::vector< float > logspace(float start, float stop, int num, bool endpoint=true)
Generates a logarithmically spaced vector.
Definition vector.cpp:111
Array transform_with_mask(const Array &array, const Array *p_mask, Fn &&fn)
Applies a transformation function with optional masked blending.
Definition operator.hpp:437
void swap(Array &a, Array &b)
Swaps the contents of two Array objects.
Definition operator.cpp:106
bool validate_same_shape(const Array &a, const Array &b, const std::source_location &loc=std::source_location::current())
Validates that two arrays have identical shapes and buffer sizes.
Definition validation.hpp:152
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:15
Point lerp(const Point &p1, const Point &p2, float t)
Linearly interpolates between two points.
Definition points.cpp:225
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:10
Array hstack(const Array &array1, const Array &array2)
Horizontally stack two arrays side by side.
Definition operator.cpp:76
bool validate_non_empty(const Array &array, const std::source_location &loc=std::source_location::current())
Validates that an array is initialized, non-empty, and has a consistent buffer size.
Definition validation.hpp:58
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:28
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:15
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:83
Array validation functions with source location logging.