scimesh 0.3.2
Headless CPU-only 3D software renderer for scientific mesh visualization
Loading...
Searching...
No Matches
colormap.h File Reference

Colormap data structure and data-to-color mapping utilities. More...

#include <scimesh/types.h>
#include <vector>
#include <cstdint>
#include <cmath>
#include <cstddef>
Include dependency graph for colormap.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  scimesh::ColorMap
 Self-contained colormap — owns a colour lookup table and supports linearly interpolated sampling. More...
 
struct  scimesh::ApplyColormapResult
 Result of apply_colormap() for a single dataset. More...
 
struct  scimesh::MultiApplyColormapResult
 Aggregate result of apply_colormap() for multiple datasets. More...
 

Namespaces

namespace  scimesh
 

Functions

ApplyColormapResult scimesh::apply_colormap (const std::vector< float > &data, const ColorMap &colormap, float vmin=NAN, float vmax=NAN, const Color &nan_color=Color{0.5f, 0.5f, 0.5f, 1.0f}, float lo_pct=0.0f, float hi_pct=100.0f)
 Map a single vector of numeric data to RGBA colours using a colormap.
 
MultiApplyColormapResult scimesh::apply_colormap (const std::vector< std::vector< float > > &datasets, const ColorMap &colormap, float vmin=NAN, float vmax=NAN, const Color &nan_color=Color{0.5f, 0.5f, 0.5f, 1.0f}, float lo_pct=0.0f, float hi_pct=100.0f, bool global_range=false)
 Map multiple vectors of numeric data through a single colormap.
 

Detailed Description

Colormap data structure and data-to-color mapping utilities.

Provides a self-contained ColorMap type for sampling colors at normalized positions, and the apply_colormap() family of functions that map per-vertex (or per-element) scalar data to RGBA colors.

Key features
  • Self-contained: ColorMap owns its LUT, no external colormap library required.
  • Multi-dataset: apply a single colormap across multiple data vectors (e.g., two brain hemispheres) with an optional shared range.
  • NaN handling: NaN/Inf values are mapped to a configurable color.
  • Winsorizing: clip outliers by percentile before mapping.
  • scibar interop: ColorMap::from_uint8_colors() duck-typed factory converts scibar colormaps without any #include dependency on scibar headers.
Quick start
// Build a colormap from scratch (linear blue→red gradient, 8 entries)
ColorMap cmap;
cmap.colors = {
Color(0.0f, 0.0f, 0.5f), Color(0.1f, 0.1f, 0.7f),
Color(0.3f, 0.2f, 0.9f), Color(0.5f, 0.3f, 1.0f),
Color(0.7f, 0.3f, 0.8f), Color(0.9f, 0.2f, 0.5f),
Color(1.0f, 0.1f, 0.3f), Color(1.0f, 0.0f, 0.0f)
};
// Per-vertex thickness data with some missing values (NaN = medial wall)
std::vector<float> thickness = {2.3f, 2.1f, NAN, 3.4f, 2.9f, NAN, ...};
// Apply colormap: auto-range, white for NaN, clip 2nd/98th percentiles
auto result = apply_colormap(thickness, cmap, NAN, NAN,
Color(1,1,1,1), // white NaN
2.0f, 98.0f); // winsorize
// result.colors[i] is the color for thickness[i]
// result.data_min / data_max hold the effective range (use for colorbar)
Colormap data structure and data-to-color mapping utilities.
ApplyColormapResult apply_colormap(const std::vector< float > &data, const ColorMap &colormap, float vmin, float vmax, const Color &nan_color, float lo_pct, float hi_pct)
Map a single vector of numeric data to RGBA colours using a colormap.
Definition colormap.cpp:345
scibar interop (no coupling)
#include <scibar.hpp> // user includes scibar, not scimesh
auto scibar_cmap = scibar::util::viridis(); // std::vector<scibar::Color>
auto scm_cmap = ColorMap::from_uint8_colors(scibar_cmap); // duck-typed copy
auto result = apply_colormap(data, scm_cmap);

Definition in file colormap.h.