HighMap library (C++)
Loading...
Searching...
No Matches
hmap::PyramidDecomposition Class Reference

Pyramid decomposition class, to handle low-pass pyramids (like Laplacian pyramid). More...

#include <pyramid.hpp>

Collaboration diagram for hmap::PyramidDecomposition:

Public Member Functions

 PyramidDecomposition (Array &array, int nlevels)
 Construct a new Pyramid Decomposition object.
 
void decompose ()
 Generate the pyramid decomposition.
 
Array reconstruct ()
 Reconstruct a field (ideally identical to the input field) based on the pyramid decomposition.
 
void to_png (std::string fname, int cmap, bool hillshading=false)
 Export pyramid as png image file.
 
Array transform (std::function< Array(const Array &, const int current_level)> function, int support=0, std::vector< float > level_weights={}, int finest_level=0)
 Apply a transformation to each component of the pyramid and return the field constructed based on the modified pyramid.
 

Public Attributes

int nlevels
 Number of levels in the pyramid.
 
Array residual
 Residual field (low-pass component) a the coarsest level.
 
std::vector< Arraycomponents = {}
 High-pass component for each level.
 
std::function< Array(const Array &)> low_pass_filter_function
 Reference to the low-pass filter function.
 

Detailed Description

Pyramid decomposition class, to handle low-pass pyramids (like Laplacian pyramid).

Constructor & Destructor Documentation

◆ PyramidDecomposition()

hmap::PyramidDecomposition::PyramidDecomposition ( Array array,
int  nlevels 
)

Construct a new Pyramid Decomposition object.

Parameters
arrayReference to the input array.
nlevelsNumber of levels (if set to a null or negative value, the maximum number of levels is taken minus the number provided).

Example

#include "highmap.hpp"
int main(void)
{
hmap::Vec2<int> shape = {256, 256};
hmap::Vec2<float> res = {4.f, 4.f};
int seed = 1;
int nlevels = 4;
pyr.decompose();
{
// some intermediate outputs for checking
for (int n = 0; n < pyr.nlevels; n++)
pyr.components[n].to_png("components_" + std::to_string(n) + ".png",
pyr.residual.to_png("components_res.png", hmap::Cmap::JET);
z.to_png("components_initial.png", hmap::Cmap::JET);
}
zr.to_png("components_rebuild.png", hmap::Cmap::JET, false);
pyr.to_png("ex_pyramid_decomposition0.png", hmap::Cmap::MAGMA);
hmap::export_banner_png("ex_pyramid_decomposition1.png",
{z, zr},
}
Array class, helper to manipulate 2D float array with "(i, j)" indexing.
Definition array.hpp:32
void to_png(const std::string &fname, int cmap, bool hillshading=false, int depth=CV_8U) const
Export the array as a PNG image file with a specified colormap and hillshading.
Definition io.cpp:122
Pyramid decomposition class, to handle low-pass pyramids (like Laplacian pyramid).
Definition pyramid.hpp:40
void decompose()
Generate the pyramid decomposition.
Definition pyramid_decomposition.cpp:48
int nlevels
Number of levels in the pyramid.
Definition pyramid.hpp:45
Array reconstruct()
Reconstruct a field (ideally identical to the input field) based on the pyramid decomposition.
Definition pyramid_decomposition.cpp:81
Array residual
Residual field (low-pass component) a the coarsest level.
Definition pyramid.hpp:50
std::vector< Array > components
High-pass component for each level.
Definition pyramid.hpp:55
void to_png(std::string fname, int cmap, bool hillshading=false)
Export pyramid as png image file.
Definition pyramid_decomposition.cpp:101
void export_banner_png(const std::string &fname, const std::vector< Array > &arrays, int cmap, bool hillshading=false)
Exports a set of arrays as a banner PNG image file.
Definition export_banner_png.cpp:11
Array noise_fbm(NoiseType noise_type, Vec2< int > shape, Vec2< float > kw, uint seed, int octaves=8, float weight=0.7f, float persistence=0.5f, float lacunarity=2.f, const Array *p_ctrl_param=nullptr, const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr, const Array *p_stretching=nullptr, Vec4< float > bbox={0.f, 1.f, 0.f, 1.f})
Return an array filled with coherence fbm noise.
Definition noise.cpp:41
@ PERLIN
Perlin.
Definition functions.hpp:64
@ JET
Definition colormaps.hpp:86
@ MAGMA
Definition colormaps.hpp:87
@ INFERNO
Definition colormaps.hpp:85
Vec2 class for basic manipulation of 2D vectors.
Definition algebra.hpp:40

Result

Member Function Documentation

◆ decompose()

void hmap::PyramidDecomposition::decompose ( )

Generate the pyramid decomposition.

◆ reconstruct()

Array hmap::PyramidDecomposition::reconstruct ( )

Reconstruct a field (ideally identical to the input field) based on the pyramid decomposition.

Returns
Array Reconstructed field.

◆ to_png()

void hmap::PyramidDecomposition::to_png ( std::string  fname,
int  cmap,
bool  hillshading = false 
)

Export pyramid as png image file.

Parameters
fnameFile name.
cmapColormap (
See also
cmap).
Parameters
hillshadingActivate hillshading.

◆ transform()

Array hmap::PyramidDecomposition::transform ( std::function< Array(const Array &, const int current_level)>  function,
int  support = 0,
std::vector< float >  level_weights = {},
int  finest_level = 0 
)

Apply a transformation to each component of the pyramid and return the field constructed based on the modified pyramid.

Parameters
functionReference to the function applied to the pyramid components.
supportFunction support, should it be applied to the lowpass components only, the highpass only the full field.
level_weightsWeight in [0, 1] for each level (the resulting component is lerp between no transform and transform according to this weight).
Returns
Array Resulting array.

Example

#include <iostream>
#include "highmap.hpp"
int main(void)
{
hmap::Vec2<int> shape = {256, 256};
shape = {512, 512};
hmap::Vec2<float> res = {4.f, 4.f};
int seed = 1;
int nlevels = 4;
pyr.decompose();
// 'transform' function
auto fct = [&seed](const hmap::Array &input, const int current_level)
{
std::cout << "applying erosion to level and shape: " << current_level << " "
<< input.shape.x << " " << input.shape.y << "\n";
// apply hydraulic erosion to each component
hmap::Array output = input;
float particle_density = 0.4f;
int nparticles = (int)(particle_density * input.size());
hydraulic_particle(output, nparticles, ++seed);
return output;
};
hmap::export_banner_png("ex_pyramid_transform.png",
{z, zr},
true);
}
int size() const
Return the total number of elements in the array.
Definition methods.cpp:333
Vec2< int > shape
The shape of the array {ni, nj}.
Definition array.hpp:38
Array transform(std::function< Array(const Array &, const int current_level)> function, int support=0, std::vector< float > level_weights={}, int finest_level=0)
Apply a transformation to each component of the pyramid and return the field constructed based on the...
Definition pyramid_decomposition.cpp:130
void remap(Array &array, float vmin, float vmax, float from_min, float from_max)
Remap array elements from a starting range to a target range.
Definition range.cpp:374
void hydraulic_particle(Array &z, Array *p_mask, int nparticles, int seed, Array *p_bedrock=nullptr, Array *p_moisture_map=nullptr, Array *p_erosion_map=nullptr, Array *p_deposition_map=nullptr, float c_capacity=10.f, float c_erosion=0.05f, float c_deposition=0.05f, float c_inertia=0.3f, float drag_rate=0.001f, float evap_rate=0.001f, bool post_filtering=false)
Apply hydraulic erosion using a particle based procedure.
Definition hydraulic_particle.cpp:184
@ TERRAIN
Definition colormaps.hpp:90
@ FULL
Complete field (sum of low and high pass)
Definition pyramid.hpp:30
T y
The x and y components of the vector.
Definition algebra.hpp:41
T x
Definition algebra.hpp:41

Result

Member Data Documentation

◆ nlevels

int hmap::PyramidDecomposition::nlevels

Number of levels in the pyramid.

◆ residual

Array hmap::PyramidDecomposition::residual

Residual field (low-pass component) a the coarsest level.

◆ components

std::vector<Array> hmap::PyramidDecomposition::components = {}

High-pass component for each level.

◆ low_pass_filter_function

std::function<Array(const Array &)> hmap::PyramidDecomposition::low_pass_filter_function

Reference to the low-pass filter function.


The documentation for this class was generated from the following files: