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"
24
25namespace hmap
26{
27
40void add_kernel(Array &array, const Array &kernel, int i, int j);
41
67 const Array &kernel,
68 float k_smooth,
69 int i,
70 int j);
71
87Array compare(const Array &a,
88 const Array &b,
89 float slice_x_pos,
90 float slice_y_pos);
91
104Array hstack(const Array &array1, const Array &array2);
105
124Array inpainting_diffusion(const Array &array,
125 const Array &mask,
126 int iterations);
127
143std::vector<float> linspace(float start,
144 float stop,
145 int num,
146 bool endpoint = true);
147
166std::vector<float> linspace_jitted(float start,
167 float stop,
168 int num,
169 float ratio,
170 int seed,
171 bool endpoint = true);
172
184std::vector<float> logspace(float start,
185 float stop,
186 int num,
187 bool endpoint = true);
188
216template <typename Fn>
218 const UvRect &uv_rect,
219 const Array *p_ctrl_param,
220 const Array *p_noise_x,
221 const Array *p_noise_y,
222 const Array *p_stretching,
223 Fn &&fct_xy);
224
256
258template <typename Fn>
260 const UvRect &uv_rect,
261 const Array *p_ctrl_param,
262 const Array *p_noise_x,
263 const Array *p_noise_y,
264 const Array *p_stretching,
265 Fn &&fct_xy,
266 int subsampling);
267
278void find_vertical_cut_path(const Array &error, std::vector<int> &path_i);
279
292Array generate_mask(glm::ivec2 shape, std::vector<int> cut_path_i, int ir);
293
324Array get_random_patch(const Array &array,
325 glm::ivec2 patch_shape,
326 std::mt19937 &gen,
327 bool patch_flip = false,
328 bool patch_rotate = false,
329 bool patch_transpose = false,
330 std::vector<Array *> *p_secondary_arrays = nullptr,
331 std::vector<Array> *p_secondary_patches = nullptr);
332
346std::vector<float> random_vector(float min, float max, int num, int seed);
347
367void rescale_vector(std::vector<float> &vec, float vmin, float vmax);
368
370std::vector<float> rescaled_vector(const std::vector<float> &vec,
371 float vmin,
372 float vmax);
373
380void swap(Array &a, Array &b);
381
394Array vstack(const Array &array1, const Array &array2);
395
396// === HELPERS
397
409template <typename Fn>
410void apply_with_mask(Array &array, const Array *p_mask, Fn &&fn)
411{
412 if (!validate_non_empty(array)) return;
413 if (p_mask && !validate_same_shape(array, *p_mask)) return;
414
415 if (!p_mask)
416 {
417 fn(array);
418 }
419 else
420 {
421 Array result = array;
422 fn(result);
423 array = lerp(array, result, *p_mask);
424 }
425}
426
439template <typename Fn>
440Array transform_with_mask(const Array &array, const Array *p_mask, Fn &&fn)
441{
442 if (!validate_non_empty(array)) return Array();
443 if (p_mask && !validate_same_shape(array, *p_mask)) return Array(array.shape);
444
445 Array result = fn(array);
446
447 if (p_mask)
448 return lerp(array, result, *p_mask);
449 else
450 return result;
451}
452
453} // namespace hmap
454
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:31
glm::ivec2 shape
The shape of the array {ni, nj}.
Definition array.hpp:37
Definition opencv.hpp:20
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:167
void apply_with_mask(Array &array, const Array *p_mask, Fn &&fn)
Applies a transformation function with optional masked blending.
Definition operator.hpp:410
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:44
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
void fill_array_using_xy_function(Array &array, const UvRect &uv_rect, const Array *p_ctrl_param, const Array *p_noise_x, const Array *p_noise_y, const Array *p_stretching, Fn &&fct_xy)
Fill an array using a scalar function based on (x, y) coordinates.
Definition operator.inl:14
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:118
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:440
void swap(Array &a, Array &b)
Swaps the contents of two Array objects.
Definition operator.cpp:109
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:265
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:79
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 dynamic programming.
Definition stitching_helpers.cpp:25
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:18
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:94
Axis-aligned rectangle in normalized [0, 1]^2 domain/UV space.
Definition uv_rect.hpp:30
Normalized domain/UV rectangle [u_min, u_max] x [v_min, v_max].
Array validation functions with source location logging.