scimesh 0.3.2
Headless CPU-only 3D software renderer for scientific mesh visualization
Loading...
Searching...
No Matches
scimesh::ColorMap Struct Reference

Self-contained colormap — owns a colour lookup table and supports linearly interpolated sampling. More...

#include <colormap.h>

Public Member Functions

Color sample (float t) const
 Sample the colormap at a normalized position using linear interpolation.
 
size_t size () const
 Number of entries in the colormap.
 
bool empty () const
 True if the colormap has no entries.
 

Static Public Member Functions

template<typename T >
static ColorMap from_uint8_colors (const std::vector< T > &cmap)
 Build a ColorMap from a vector of scibar-style uint8_t RGBA colours.
 
static ColorMap from_interleaved (const std::vector< uint8_t > &data, int channels=3)
 Build a ColorMap from a flat interleaved RGB(A) byte array.
 
static const ColorMapviridis ()
 The Viridis perceptually-uniform sequential colormap (256 entries).
 

Public Attributes

std::vector< Colorcolors
 The colour lookup table entries in [0, 1] float RGBA.
 

Detailed Description

Self-contained colormap — owns a colour lookup table and supports linearly interpolated sampling.

A ColorMap is simply a vector of Color entries plus a sample() method that performs linear interpolation between adjacent entries. The first entry corresponds to t = 0.0, the last to t = 1.0.

Note
The minimum useful size is 2 entries. Single-entry colormaps always return that single colour regardless of t.
See also
apply_colormap(), from_uint8_colors()

Definition at line 79 of file colormap.h.

Member Function Documentation

◆ empty()

bool scimesh::ColorMap::empty ( ) const
inline

True if the colormap has no entries.

Definition at line 103 of file colormap.h.

◆ from_interleaved()

static ColorMap scimesh::ColorMap::from_interleaved ( const std::vector< uint8_t > &  data,
int  channels = 3 
)
inlinestatic

Build a ColorMap from a flat interleaved RGB(A) byte array.

Parameters
dataFlat array of RGB bytes (3 × n entries) or RGBA bytes (4 × n entries).
channels3 for RGB data, 4 for RGBA data.
Returns
A new ColorMap with data.size() / channels entries.
Example (libfs viridis output)
std::vector<uint8_t> rgb = fs::util::viridis(sulc_data);
auto cmap = ColorMap::from_interleaved(rgb, 3);
static ColorMap from_interleaved(const std::vector< uint8_t > &data, int channels=3)
Build a ColorMap from a flat interleaved RGB(A) byte array.
Definition colormap.h:151

Definition at line 151 of file colormap.h.

◆ from_uint8_colors()

template<typename T >
static ColorMap scimesh::ColorMap::from_uint8_colors ( const std::vector< T > &  cmap)
inlinestatic

Build a ColorMap from a vector of scibar-style uint8_t RGBA colours.

This is a duck-typed template — it works with any type T that has .r, .g, .b, .a fields as uint8_t in the range [0, 255]. No #include of scibar headers is required; the user simply passes their std::vector<scibar::Color> and it compiles.

Template Parameters
TAny struct with uint8_t r, g, b, a fields.
Parameters
cmapThe source colormap (e.g., from scibar::util::viridis()).
Returns
A new ColorMap with the same entries converted to float [0, 1] RGBA.
Example (scibar → scimesh)
auto scibar_cmap = scibar::util::viridis();
auto scm_cmap = ColorMap::from_uint8_colors(scibar_cmap);
static ColorMap from_uint8_colors(const std::vector< T > &cmap)
Build a ColorMap from a vector of scibar-style uint8_t RGBA colours.
Definition colormap.h:128

Definition at line 128 of file colormap.h.

◆ sample()

Color scimesh::ColorMap::sample ( float  t) const

Sample the colormap at a normalized position using linear interpolation.

Parameters
tNormalized position in [0, 1]. Values outside this range are clamped: t < 0 → first entry, t > 1 → last entry.
Returns
The interpolated colour at position t, or transparent black if the colormap is empty.
Example
Color lo = cmap.sample(0.0f); // first colour
Color mid = cmap.sample(0.5f); // middle
Color hi = cmap.sample(1.0f); // last colour
float lo
Definition colormap.cpp:108
float hi
Definition colormap.cpp:108
An RGBA color with floating-point components.
Definition types.h:88

Definition at line 15 of file colormap.cpp.

◆ size()

size_t scimesh::ColorMap::size ( ) const
inline

Number of entries in the colormap.

Definition at line 100 of file colormap.h.

◆ viridis()

const ColorMap & scimesh::ColorMap::viridis ( )
static

The Viridis perceptually-uniform sequential colormap (256 entries).

Returns a 256-entry RGBA LUT. Viridis is perceptually uniform, colourblind-friendly, and prints well in greyscale. Identical to the matplotlib reference implementation.

Returns
A 256-entry ColorMap (cached after first call).

Definition at line 195 of file colormap.cpp.

Member Data Documentation

◆ colors

std::vector<Color> scimesh::ColorMap::colors

The colour lookup table entries in [0, 1] float RGBA.

Definition at line 81 of file colormap.h.


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