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

A class to represent a multi-channel texture using planar hmap::Array storage. More...

#include <texture.hpp>

Collaboration diagram for hmap::Texture:

Public Member Functions

 Texture ()=default
 Construct an empty Texture object.
 
 Texture (glm::ivec2 shape, int num_channels)
 Construct a new Texture object with shape and channel count.
 
 Texture (glm::ivec2 shape, int num_channels, float fill_value)
 Construct a new Texture object with shape, channel count and fill value.
 
 Texture (const Array &array)
 Construct a single-channel Texture from an Array.
 
 Texture (const Array &r, const Array &g, const Array &b)
 Construct a 3-channel Texture from three Arrays.
 
 Texture (const Array &r, const Array &g, const Array &b, const Array &a)
 Construct a 4-channel Texture from four Arrays.
 
 Texture (const std::vector< Array > &channels)
 Construct a Texture from a list of Arrays.
 
 Texture (const std::string &fname, bool flip_j=false)
 Constructs a new Texture object from an image file.
 
int num_channels () const
 Get the number of channels.
 
Arrayoperator[] (size_t idx)
 Access channel Array by index.
 
const Arrayoperator[] (size_t idx) const
 
Arraychannel (size_t idx)
 Access channel Array by index.
 
const Arraychannel (size_t idx) const
 
float & operator() (int i, int j, int c)
 Access element at (i, j) in channel c.
 
const float & operator() (int i, int j, int c) const
 Access element at (i, j) in channel c (const).
 
glm::vec3 get_pixel3 (int i, int j) const
 Read 3-channel color at (i, j) as glm::vec3.
 
glm::vec4 get_pixel4 (int i, int j) const
 Read 4-channel color at (i, j) as glm::vec4.
 
void set_pixel (int i, int j, const glm::vec3 &color)
 Write 3-channel color at (i, j) from glm::vec3.
 
void set_pixel (int i, int j, const glm::vec4 &color)
 Write 4-channel color at (i, j) from glm::vec4.
 
float max () const
 Find the maximum value in all channels.
 
float min () const
 Find the minimum value in all channels.
 
void remap (float vmin=0.f, float vmax=1.f)
 Remap the texture values to a new range.
 
Texture resample_to_shape (glm::ivec2 new_shape_xy) const
 Resamples the texture to a new 2D shape (x, y).
 
cv::Mat to_cv_mat () const
 Convert the texture to an OpenCV matrix.
 
std::vector< uint8_t > to_img_8bit (bool flip_y=false) const
 Convert the texture to an 8-bit image represented as a vector.
 
void to_png (const std::string &fname, int depth=CV_8U) const
 Saves the Texture as an image file (e.g. PNG).
 

Public Attributes

glm::ivec2 shape = glm::ivec2(0, 0)
 Shape of the texture in 2D space (x, y).
 
std::vector< Arraychannels
 Vector of planar Array channels.
 

Detailed Description

A class to represent a multi-channel texture using planar hmap::Array storage.

The Texture class represents a multi-channel image/texture. Each channel is stored as a separate Array object, allowing direct use of Array functions and operators on individual channels without copying.

Examples
ex_mixbox.cpp.

Constructor & Destructor Documentation

◆ Texture() [1/8]

hmap::Texture::Texture ( )
default

Construct an empty Texture object.

◆ Texture() [2/8]

hmap::Texture::Texture ( glm::ivec2  shape,
int  num_channels 
)

Construct a new Texture object with shape and channel count.

Parameters
shape2D shape of the texture.
num_channelsNumber of channels.

◆ Texture() [3/8]

hmap::Texture::Texture ( glm::ivec2  shape,
int  num_channels,
float  fill_value 
)

Construct a new Texture object with shape, channel count and fill value.

Parameters
shape2D shape of the texture.
num_channelsNumber of channels.
fill_valueThe value to fill all channels with.

◆ Texture() [4/8]

hmap::Texture::Texture ( const Array array)
explicit

Construct a single-channel Texture from an Array.

Parameters
arrayThe single channel Array.

◆ Texture() [5/8]

hmap::Texture::Texture ( const Array r,
const Array g,
const Array b 
)

Construct a 3-channel Texture from three Arrays.

◆ Texture() [6/8]

hmap::Texture::Texture ( const Array r,
const Array g,
const Array b,
const Array a 
)

Construct a 4-channel Texture from four Arrays.

◆ Texture() [7/8]

hmap::Texture::Texture ( const std::vector< Array > &  channels)
explicit

Construct a Texture from a list of Arrays.

◆ Texture() [8/8]

hmap::Texture::Texture ( const std::string &  fname,
bool  flip_j = false 
)
explicit

Constructs a new Texture object from an image file.

Parameters
fnameThe name of the file to load the texture from.
flip_jIf true, flip the image vertically on load.

Member Function Documentation

◆ num_channels()

int hmap::Texture::num_channels ( ) const
inline

Get the number of channels.

◆ operator[]() [1/2]

Array & hmap::Texture::operator[] ( size_t  idx)
inline

Access channel Array by index.

◆ operator[]() [2/2]

const Array & hmap::Texture::operator[] ( size_t  idx) const
inline

◆ channel() [1/2]

Array & hmap::Texture::channel ( size_t  idx)
inline

Access channel Array by index.

◆ channel() [2/2]

const Array & hmap::Texture::channel ( size_t  idx) const
inline

◆ operator()() [1/2]

float & hmap::Texture::operator() ( int  i,
int  j,
int  c 
)
inline

Access element at (i, j) in channel c.

◆ operator()() [2/2]

const float & hmap::Texture::operator() ( int  i,
int  j,
int  c 
) const
inline

Access element at (i, j) in channel c (const).

◆ get_pixel3()

glm::vec3 hmap::Texture::get_pixel3 ( int  i,
int  j 
) const

Read 3-channel color at (i, j) as glm::vec3.

◆ get_pixel4()

glm::vec4 hmap::Texture::get_pixel4 ( int  i,
int  j 
) const

Read 4-channel color at (i, j) as glm::vec4.

◆ set_pixel() [1/2]

void hmap::Texture::set_pixel ( int  i,
int  j,
const glm::vec3 &  color 
)

Write 3-channel color at (i, j) from glm::vec3.

◆ set_pixel() [2/2]

void hmap::Texture::set_pixel ( int  i,
int  j,
const glm::vec4 &  color 
)

Write 4-channel color at (i, j) from glm::vec4.

◆ max()

float hmap::Texture::max ( ) const

Find the maximum value in all channels.

◆ min()

float hmap::Texture::min ( ) const

Find the minimum value in all channels.

◆ remap()

void hmap::Texture::remap ( float  vmin = 0.f,
float  vmax = 1.f 
)

Remap the texture values to a new range.

◆ resample_to_shape()

Texture hmap::Texture::resample_to_shape ( glm::ivec2  new_shape_xy) const

Resamples the texture to a new 2D shape (x, y).

◆ to_cv_mat()

cv::Mat hmap::Texture::to_cv_mat ( ) const

Convert the texture to an OpenCV matrix.

◆ to_img_8bit()

std::vector< uint8_t > hmap::Texture::to_img_8bit ( bool  flip_y = false) const

Convert the texture to an 8-bit image represented as a vector.

◆ to_png()

void hmap::Texture::to_png ( const std::string &  fname,
int  depth = CV_8U 
) const

Saves the Texture as an image file (e.g. PNG).

Examples
ex_mixbox.cpp.

Member Data Documentation

◆ shape

glm::ivec2 hmap::Texture::shape = glm::ivec2(0, 0)

Shape of the texture in 2D space (x, y).

◆ channels

std::vector<Array> hmap::Texture::channels

Vector of planar Array channels.


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