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

Sequential 2D inverse transform point sampler based on a 2D density array. More...

#include <inverse_sampler_2d.hpp>

Public Member Functions

 InverseSampler2D ()=default
 InverseSampler2D (const Array &density, std::uint32_t seed=0, const BBox2D &bbox=BBox2D{})
 Constructs an inverse sampler for a 2D density array.
glm::vec2 sample ()
 Samples a single point sequentially using the internal RNG.
glm::vec2 sample (float u, float u2)
 Samples a single point with user-provided uniform random numbers.
std::array< std::vector< float >, 2 > sample (size_t count)
 Samples multiple points sequentially.
glm::vec2 sample (const BBox2D &restricted_bbox)
 Samples a single point sequentially within a restricted bounding box.
glm::vec2 sample (const BBox2D &restricted_bbox, float u, float u2)
 Samples a single point within a restricted bounding box with user-provided uniform random numbers.
void update_region (const Array &updated_array, const glm::ivec2 &range_i, const glm::ivec2 &range_j)
 Updates the density in the sub-region [imin, imax] x [jmin, jmax] from another array.
void update_region (const std::function< float(int i, int j, float current)> &updater, const glm::ivec2 &range_i, const glm::ivec2 &range_j)
 Updates the density in the sub-region [imin, imax] x [jmin, jmax] using a modifier function.
void reset (const Array &density, std::uint32_t seed=0, const BBox2D &bbox=BBox2D{})
 Reinitializes the sampler with a new density array.
const BBox2D & get_bbox () const
 Gets the bounding box.
const Array & get_density () const
 Gets the current density array.
float get_total_weight () const
 Gets the total integrated weight.
void set_bbox (const BBox2D &bbox)
 Sets the bounding box.
void set_seed (std::uint32_t seed)
 Sets the RNG seed.

Detailed Description

Sequential 2D inverse transform point sampler based on a 2D density array.

Supports generating points one-by-one and dynamically updating density in local bounding box or index sub-regions [imin, imax] x [jmin, jmax].

Constructor & Destructor Documentation

◆ InverseSampler2D() [1/2]

hmap::InverseSampler2D::InverseSampler2D ( )
default

◆ InverseSampler2D() [2/2]

hmap::InverseSampler2D::InverseSampler2D ( const Array & density,
std::uint32_t seed = 0,
const BBox2D & bbox = BBox2D{} )

Constructs an inverse sampler for a 2D density array.

Parameters
density2D density array.
seedRandom number generator seed.
bboxBounding box (xmin, xmax, ymin, ymax). Defaults to unit square.

Member Function Documentation

◆ sample() [1/5]

glm::vec2 hmap::InverseSampler2D::sample ( )

Samples a single point sequentially using the internal RNG.

Returns
2D point coordinates within the bounding box.

◆ sample() [2/5]

glm::vec2 hmap::InverseSampler2D::sample ( float u,
float u2 )

Samples a single point with user-provided uniform random numbers.

Parameters
uUniform random number in [0, 1) for row selection.
u2Uniform random number in [0, 1) for column selection.
Returns
2D point coordinates within the bounding box.

◆ sample() [3/5]

std::array< std::vector< float >, 2 > hmap::InverseSampler2D::sample ( size_t count)

Samples multiple points sequentially.

Parameters
countNumber of points to sample.
Returns
A pair of coordinate vectors {x_coords, y_coords}.

◆ sample() [4/5]

glm::vec2 hmap::InverseSampler2D::sample ( const BBox2D & restricted_bbox)

Samples a single point sequentially within a restricted bounding box.

Parameters
restricted_bboxBounding box {xmin, xmax, ymin, ymax} defining the sub-region.
Returns
2D point coordinates within the restricted bounding box.

◆ sample() [5/5]

glm::vec2 hmap::InverseSampler2D::sample ( const BBox2D & restricted_bbox,
float u,
float u2 )

Samples a single point within a restricted bounding box with user-provided uniform random numbers.

Parameters
restricted_bboxBounding box {xmin, xmax, ymin, ymax} defining the sub-region.
uUniform random number in [0, 1) for row selection.
u2Uniform random number in [0, 1) for column selection.
Returns
2D point coordinates within the restricted bounding box.

◆ update_region() [1/2]

void hmap::InverseSampler2D::update_region ( const Array & updated_array,
const glm::ivec2 & range_i,
const glm::ivec2 & range_j )

Updates the density in the sub-region [imin, imax] x [jmin, jmax] from another array.

Parameters
updated_arrayArray containing updated density values.
range_iColumn index range {imin, imax} (inclusive).
range_jRow index range {jmin, jmax} (inclusive).

◆ update_region() [2/2]

void hmap::InverseSampler2D::update_region ( const std::function< float(int i, int j, float current)> & updater,
const glm::ivec2 & range_i,
const glm::ivec2 & range_j )

Updates the density in the sub-region [imin, imax] x [jmin, jmax] using a modifier function.

Parameters
updaterCallback f(i, j, current_val) returning the new density value.
range_iColumn index range {imin, imax} (inclusive).
range_jRow index range {jmin, jmax} (inclusive).

◆ reset()

void hmap::InverseSampler2D::reset ( const Array & density,
std::uint32_t seed = 0,
const BBox2D & bbox = BBox2D{} )

Reinitializes the sampler with a new density array.

Parameters
density2D density array.
seedRandom number generator seed.
bboxBounding box (xmin, xmax, ymin, ymax).

◆ get_bbox()

const BBox2D & hmap::InverseSampler2D::get_bbox ( ) const

Gets the bounding box.

◆ get_density()

const Array & hmap::InverseSampler2D::get_density ( ) const

Gets the current density array.

◆ get_total_weight()

float hmap::InverseSampler2D::get_total_weight ( ) const

Gets the total integrated weight.

◆ set_bbox()

void hmap::InverseSampler2D::set_bbox ( const BBox2D & bbox)

Sets the bounding box.

◆ set_seed()

void hmap::InverseSampler2D::set_seed ( std::uint32_t seed)

Sets the RNG seed.


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