|
CGVIS Utils
|
#include <Grid2D.h>
Public Member Functions | |
| Grid2D (size_t width, size_t height) | |
| Construct an empty grid initialized to zeros. | |
| Grid2D (size_t width, size_t height, const std::vector< float > data) | |
| Construct from raw data (size must equal width*height). | |
| Grid2D (const Grid2D &other) | |
| Copy‑construct from another grid. | |
| Grid2D (const Image &image) | |
| Construct from the luminance of an Image. | |
| Grid2D (std::istream &is) | |
| Read grid from a binary stream written by save(). | |
| void | save (std::ostream &os) const |
| Write grid to a binary stream. | |
| std::string | toString () const |
| String dump of values in row‑major order. | |
| std::vector< uint8_t > | toByteArray () const |
| Convert to an 8‑bit RGB byte array (grayscale replicated to RGB). | |
| Grid2D | toSignedDistance (float threshold) const |
| Compute a signed distance field from a binary threshold. | |
| GLTexture2D | toTexture () const |
| Upload to an OpenGL texture (1 channel). | |
| void | setValue (size_t x, size_t y, float value) |
| Set one value. | |
| float | getValueNormalized (float x, float y) const |
| Fetch value using normalized [0,1] coordinates (nearest‑neighbor via index mapping). | |
| float | getValue (size_t x, size_t y) const |
| Fetch value by integer coordinates. | |
| float | sample (float x, float y) const |
| Bilinear sample at normalized coordinates in [0,1]. | |
| float | sample (const Vec2 &pos) const |
| Bilinear sample at normalized coordinates in [0,1]. | |
| Vec3 | normal (float x, float y) const |
| Estimate a normal from local height differences at normalized coords. | |
| Vec3 | normal (const Vec2 &pos) const |
| Estimate a normal from local height differences at normalized coords. | |
| Grid2D | operator* (const float &value) const |
| Per‑element multiply by scalar. | |
| Grid2D | operator/ (const float &value) const |
| Per‑element divide by scalar. | |
| Grid2D | operator+ (const float &value) const |
| Per‑element add scalar. | |
| Grid2D | operator- (const float &value) const |
| Per‑element subtract scalar. | |
| Grid2D | operator+ (const Grid2D &other) const |
| Per‑element addition with resampling if needed. | |
| Grid2D | operator/ (const Grid2D &other) const |
| Per‑element division with resampling if needed. | |
| Grid2D | operator* (const Grid2D &other) const |
| Per‑element multiplication with resampling if needed. | |
| Grid2D | operator- (const Grid2D &other) const |
| Per‑element subtraction with resampling if needed. | |
| void | normalize (const float maxVal=1) |
| Normalize values to [0,maxVal] by affine remapping. | |
| Vec2t< size_t > | maxValue () const |
| Location of the maximum value. | |
| Vec2t< size_t > | minValue () const |
| Location of the minimum value. | |
| void | fill (float value) |
| Fill all elements with a constant. | |
Geometry | |
| size_t | getWidth () const |
| Grid width in elements. | |
| size_t | getHeight () const |
| Grid height in elements. | |
Static Public Member Functions | |
| static Grid2D | genRandom (size_t x, size_t y, uint32_t seed) |
| Generate a grid of random values in [0,1) using a fixed seed. | |
| static Grid2D | genRandom (size_t x, size_t y) |
| Generate a grid of random values in [0,1) using a global RNG. | |
| static Grid2D | fromBMP (const std::string &filename) |
| Create a grid from the luminance of a BMP file. | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const Grid2D &v) |
| Stream insertion (delegates to toString()). | |
| Grid2D::Grid2D | ( | size_t | width, |
| size_t | height ) |
Construct an empty grid initialized to zeros.
| width | Number of columns. |
| height | Number of rows. |
| Grid2D::Grid2D | ( | size_t | width, |
| size_t | height, | ||
| const std::vector< float > | data ) |
Construct from raw data (size must equal width*height).
| width | Number of columns. |
| height | Number of rows. |
| data | Row‑major values copied into the grid. |
| std::runtime_error | If data.size() != width*height. |
| Grid2D::Grid2D | ( | const Grid2D & | other | ) |
Copy‑construct from another grid.
| other | Source grid. |
| Grid2D::Grid2D | ( | const Image & | image | ) |
Construct from the luminance of an Image.
| image | Source image; the first channel is sampled and normalized to [0,1]. Width/height match the image. |
| Grid2D::Grid2D | ( | std::istream & | is | ) |
Read grid from a binary stream written by save().
| is | Input stream; reads width, height, then width*height floats. |
| void Grid2D::fill | ( | float | value | ) |
Fill all elements with a constant.
| value | Value to assign. |
|
static |
|
static |
Generate a grid of random values in [0,1) using a global RNG.
| x | Width. |
| y | Height. |
|
static |
Generate a grid of random values in [0,1) using a fixed seed.
| x | Width. |
| y | Height. |
| seed | Seed for the RNG. |
| size_t Grid2D::getHeight | ( | ) | const |
Grid height in elements.
| float Grid2D::getValue | ( | size_t | x, |
| size_t | y ) const |
Fetch value by integer coordinates.
| x | Column index. |
| y | Row index. |
| float Grid2D::getValueNormalized | ( | float | x, |
| float | y ) const |
Fetch value using normalized [0,1] coordinates (nearest‑neighbor via index mapping).
| x | Normalized x. |
| y | Normalized y. |
| size_t Grid2D::getWidth | ( | ) | const |
Grid width in elements.
| Vec2t< size_t > Grid2D::maxValue | ( | ) | const |
Location of the maximum value.
| Vec2t< size_t > Grid2D::minValue | ( | ) | const |
Location of the minimum value.
Estimate a normal from local height differences at normalized coords.
| pos | (x,y) normalized position. |
| Vec3 Grid2D::normal | ( | float | x, |
| float | y ) const |
Estimate a normal from local height differences at normalized coords.
| x,y | Normalized coordinates. |
| void Grid2D::normalize | ( | const float | maxVal = 1 | ) |
Normalize values to [0,maxVal] by affine remapping.
| maxVal | Upper bound after normalization (default 1). |
| Grid2D Grid2D::operator* | ( | const float & | value | ) | const |
Per‑element multiply by scalar.
Per‑element multiplication with resampling if needed.
| Grid2D Grid2D::operator+ | ( | const float & | value | ) | const |
Per‑element add scalar.
Per‑element addition with resampling if needed.
| Grid2D Grid2D::operator- | ( | const float & | value | ) | const |
Per‑element subtract scalar.
Per‑element subtraction with resampling if needed.
| Grid2D Grid2D::operator/ | ( | const float & | value | ) | const |
Per‑element divide by scalar.
Per‑element division with resampling if needed.
| float Grid2D::sample | ( | const Vec2 & | pos | ) | const |
Bilinear sample at normalized coordinates in [0,1].
| pos | (x,y) normalized position. |
| float Grid2D::sample | ( | float | x, |
| float | y ) const |
Bilinear sample at normalized coordinates in [0,1].
| x | Normalized x. |
| y | Normalized y. |
| void Grid2D::save | ( | std::ostream & | os | ) | const |
Write grid to a binary stream.
| os | Output stream; writes width, height, then width*height floats. |
| void Grid2D::setValue | ( | size_t | x, |
| size_t | y, | ||
| float | value ) |
Set one value.
| x | Column index in [0,width). |
| y | Row index in [0,height). |
| value | New value. |
| std::vector< uint8_t > Grid2D::toByteArray | ( | ) | const |
Convert to an 8‑bit RGB byte array (grayscale replicated to RGB).
| Grid2D Grid2D::toSignedDistance | ( | float | threshold | ) | const |
Compute a signed distance field from a binary threshold.
| threshold | Values ≥ threshold are considered inside. |
| std::string Grid2D::toString | ( | ) | const |
String dump of values in row‑major order.
| GLTexture2D Grid2D::toTexture | ( | ) | const |
Upload to an OpenGL texture (1 channel).
|
friend |
Stream insertion (delegates to toString()).