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

Namespaces

namespace  gltf_io
 
namespace  obj_io
 Functions for reading OBJ files.
 
namespace  ply_io
 Functions for reading PLY files.
 
namespace  stl_io
 Functions for reading and writing STL files.
 

Classes

struct  ApplyColormapResult
 Result of apply_colormap() for a single dataset. More...
 
struct  Camera
 A virtual camera that defines the viewpoint for rendering. More...
 
struct  ClipPlane
 A clipping plane that can hide parts of the scene. More...
 
struct  ClipVertex
 A processed vertex in clip space, ready for perspective divide. More...
 
struct  Color
 An RGBA color with floating-point components. More...
 
struct  ColorMap
 Self-contained colormap — owns a colour lookup table and supports linearly interpolated sampling. More...
 
struct  Image
 A 2D RGBA image buffer. More...
 
struct  Light
 A light source for the Blinn-Phong shading model. More...
 
struct  Mesh
 A 3D triangle mesh using an indexed face set representation. More...
 
struct  MultiApplyColormapResult
 Aggregate result of apply_colormap() for multiple datasets. More...
 
struct  Rasterizer
 Low-level triangle rasterizer with depth buffering and lighting. More...
 
class  Renderer
 The main rendering engine. More...
 
struct  RenderOptions
 All settings that control rendering output. More...
 
struct  Scene
 A collection of Mesh objects to be rendered together. More...
 
struct  SceneNodeRef
 A lightweight, non-owning reference to one mesh in a scene, together with its placement transform (and optional name). More...
 
struct  Triangle
 A triangle defined by three vertex indices. More...
 
struct  ViewClipVertex
 

Typedefs

using Vec2 = glm::vec2
 2-component floating-point vector (xy).
 
using Vec3 = glm::vec3
 3-component floating-point vector (xyz).
 
using Vec4 = glm::vec4
 4-component floating-point vector (xyzw).
 
using Mat4 = glm::mat4
 4×4 floating-point matrix.
 

Enumerations

enum class  ProjectionType { ORTHOGRAPHIC , PERSPECTIVE }
 The type of 3D→2D projection used by the camera. More...
 
enum class  MergeDirection { LEFT , RIGHT , TOP , BOTTOM }
 Direction for the merge() operation. More...
 
enum class  CropContentDirection {
  LEFT , RIGHT , HORIZONTAL , TOP ,
  BOTTOM , VERTICAL , ALL
}
 Direction(s) for the crop_to_content() operation. More...
 
enum class  FitMode { PAD , SCALE }
 Strategy for normalizing images to a common cell size in grid_arrange(). More...
 
enum class  ShadingMode { SMOOTH , FLAT }
 How surface normals are interpolated across triangles. More...
 

Functions

Camera camera_look_at (const Vec3 &center, float radius, const Vec3 &direction, const Vec3 &up, float fov_degrees, float margin=1.1f, ProjectionType projection=ProjectionType::PERSPECTIVE)
 Create a camera that looks at a point from a given distance and direction.
 
Camera camera_fit_scene (const Scene &scene, const Vec3 &direction, const Vec3 &up, float fov_degrees, float margin=1.1f, ProjectionType projection=ProjectionType::PERSPECTIVE)
 Create a camera that automatically frames an entire Scene.
 
Camera camera_fit_mesh (const Mesh &mesh, const Vec3 &direction, const Vec3 &up, float fov_degrees, float margin=1.1f, ProjectionType projection=ProjectionType::PERSPECTIVE)
 Create a camera that automatically frames a single Mesh.
 
Camera camera_orbit (const Camera &camera, const Vec3 &axis, float angle_degrees)
 Orbit the camera around its look-at point.
 
int clip_triangle_near_plane (const ClipVertex &v0, const ClipVertex &v1, const ClipVertex &v2, std::vector< ClipVertex > &output_vertices, std::vector< Triangle > &output_triangles)
 Clip a triangle against the near clipping plane in clip space.
 
int clip_triangle_view_plane (const Vec3 &v0, const Vec3 &v1, const Vec3 &v2, const Vec3 &n0, const Vec3 &n1, const Vec3 &n2, const Color &c0, const Color &c1, const Color &c2, const Vec2 &uv0, const Vec2 &uv1, const Vec2 &uv2, const ClipPlane &plane, std::vector< ClipVertex > &output_vertices, std::vector< Triangle > &output_triangles)
 Clip a triangle against an arbitrary plane in view space.
 
ApplyColormapResult 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 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.
 
Image grid_arrange (const std::vector< Image > &images, int ncol=0, int nrow=0, FitMode fit_mode=FitMode::PAD, const Color &background=Color(1.0f, 1.0f, 1.0f, 1.0f))
 Arrange a list of images into a grid layout.
 
void compute_vertex_normals (const Mesh &mesh, std::vector< Vec3 > &normals)
 Compute per-vertex normals by averaging adjacent face normals.
 
Mesh generate_sphere (const Vec3 &center, float radius, int segments, const Color &color)
 Generate a UV-sphere (latitude/longitude tessellation).
 
Mesh generate_cylinder (const Vec3 &start, const Vec3 &end, float radius, int segments, const Color &color)
 Generate a cylinder between two endpoints.
 
Mesh generate_cone (const Vec3 &base, const Vec3 &tip, float radius, int segments, const Color &color)
 Generate a cone from a base circle to a tip point.
 
Mesh generate_arrow (const Vec3 &from, const Vec3 &to, float shaft_radius, float head_radius, float head_length, int segments, const Color &color)
 Generate a 3D arrow from from to to.
 
void merge_mesh (Mesh &dst, const Mesh &src)
 Merge one mesh into another (append geometry).
 
Mesh generate_multi_spheres (const std::vector< Vec3 > &centers, const std::vector< float > &radii, const std::vector< Color > &colors, int segments=16)
 Generate multiple spheres in a single mesh (efficient batching).
 
Mesh generate_multi_cylinders (const std::vector< Vec3 > &starts, const std::vector< Vec3 > &ends, const std::vector< float > &radii, const std::vector< Color > &colors, int segments=12)
 Generate multiple cylinders in a single mesh (efficient batching).
 
Mesh generate_cuboid (const Vec3 &center, const Vec3 &half_extents, const Color &color)
 Generate an axis-aligned cuboid (rectangular box).
 
Mesh generate_pyramid (const Vec3 &base_center, const Vec3 &apex, float half_width, const Color &color)
 Generate a square-based pyramid.
 
Mesh generate_tetrahedron (const Vec3 &p0, const Vec3 &p1, const Vec3 &p2, const Vec3 &p3, const Color &color)
 Generate a tetrahedron (triangular pyramid) from four points.
 
Mesh generate_torus (const Vec3 &center, float major_radius, float minor_radius, int major_segments, int minor_segments, const Color &color)
 Generate a torus (donut shape).
 
Mesh generate_plane (const Vec3 &center, const Vec3 &normal, float half_size_x, float half_size_y, const Color &color)
 Generate a flat rectangular plane.
 
void translate_mesh (Mesh &mesh, const Vec3 &translation)
 Translate (move) a mesh by a displacement vector.
 
void scale_mesh (Mesh &mesh, const Vec3 &scale)
 Scale a mesh non-uniformly along each axis.
 
void scale_mesh (Mesh &mesh, float uniform_scale)
 Scale a mesh uniformly in all directions.
 
void rotate_mesh (Mesh &mesh, float angle_radians, const Vec3 &axis)
 Rotate a mesh around an arbitrary axis.
 
void transform_mesh (Mesh &mesh, const Mat4 &matrix)
 Apply an arbitrary 4×4 transformation matrix to a mesh.
 
Mesh mesh_from_fs (const std::vector< float > &fs_vertices, const std::vector< uint32_t > &fs_faces, const std::vector< float > &per_vertex_values={}, const std::vector< uint8_t > &rgb_bytes={}, bool detect_transparency=false)
 Convert a FreeSurfer-format mesh (flat vertex/face arrays) to a scimesh Mesh.
 
float perp_extent_radius (const Vec3 &bmin, const Vec3 &bmax, const Vec3 &center, const Vec3 &dir, float fov_radians, float *out_dist=nullptr)
 Compute the "perpendicular extent radius" of an axis-aligned bounding box relative to a view direction.
 
float max_ortho_extent (const Vec3 &bmin, const Vec3 &bmax, const Vec3 &center, const Vec3 &dir)
 Compute the maximum perpendicular extent of an AABB from a view ray (for orthographic projection framing).
 
Mesh convert_fs_mesh (const fs::Mesh &fs_mesh)
 Convert a FreeSurfer mesh to a scimesh Mesh (no colors).
 
Mesh convert_fs_mesh (const fs::Mesh &fs_mesh, const Color &solid_color)
 Convert a FreeSurfer mesh to a scimesh Mesh with a solid color.
 
Mesh convert_fs_mesh (const fs::Mesh &fs_mesh, const std::vector< uint8_t > &rgb_colors)
 Convert a FreeSurfer mesh with per-vertex RGB coloring.
 
Mesh convert_fs_mesh (const fs::Mesh &fs_mesh, const std::vector< float > &morph_data, const std::vector< uint8_t > &rgb_colors)
 Convert a FreeSurfer mesh with per-vertex morphological data and RGB coloring.
 
Image stack_horizontal (const std::vector< Image > &images, FitMode fit_mode=FitMode::PAD, const Color &background=Color(1.0f, 1.0f, 1.0f, 1.0f))
 Stack images horizontally in a single row.
 
Image stack_vertical (const std::vector< Image > &images, FitMode fit_mode=FitMode::PAD, const Color &background=Color(1.0f, 1.0f, 1.0f, 1.0f))
 Stack images vertically in a single column.
 
Vec3 compute_face_normal (const Vec3 &v0, const Vec3 &v1, const Vec3 &v2)
 Compute the unit-length normal vector of a triangle face.
 
Vec3 transform_point (const Mat4 &m, const Vec3 &p)
 Transform a point by a 4×4 matrix (with implicit w=1).
 
Vec4 transform_point_homogeneous (const Mat4 &m, const Vec3 &p)
 Transform a point by a 4×4 matrix, returning the full Vec4 result.
 
Vec3 transform_direction (const Mat4 &m, const Vec3 &d)
 Transform a direction vector by a 4×4 matrix (with implicit w=0).
 
Vec3 perspective_divide (const Vec4 &clip)
 Perform perspective division: divide xyz by w.
 
void ndc_to_screen (const Vec3 &ndc, int width, int height, float &screen_x, float &screen_y, float &depth)
 Convert from normalized device coordinates (NDC) to screen (pixel) coordinates.
 
void compute_barycentric (float px, float py, float x0, float y0, float x1, float y1, float x2, float y2, float &u, float &v, float &w)
 Compute barycentric coordinates (u, v, w) of a point in a triangle.
 
Color shade_pixel (const Color &base_color, const Vec3 &normal, const Vec3 &light_direction, const Color &specular_color=Color(0, 0, 0, 0), float shininess=0.0f)
 Compute the shaded color of a pixel with a single directional light.
 
Color shade_pixel_multi (const Color &base_color, const Vec3 &normal, const std::vector< Light > &lights, float ambient, const Color &specular_color=Color(0, 0, 0, 0), float shininess=0.0f)
 Compute the shaded color with multiple light sources.
 
const char * str_projection (ProjectionType p)
 
const char * str_shading (ShadingMode s)
 
const char * str_merge (MergeDirection d)
 
const char * str_crop (CropContentDirection d)
 
std::string fmt_count (size_t n)
 
std::string fmt_size_bytes (size_t bytes)
 
std::ostream & operator<< (std::ostream &os, const Color &c)
 
std::ostream & operator<< (std::ostream &os, const Vec3 &v)
 
std::ostream & operator<< (std::ostream &os, const Triangle &t)
 
std::ostream & operator<< (std::ostream &os, ShadingMode s)
 
std::ostream & operator<< (std::ostream &os, ProjectionType p)
 
std::ostream & operator<< (std::ostream &os, const Light &l)
 
std::ostream & operator<< (std::ostream &os, const ClipPlane &cp)
 
std::ostream & operator<< (std::ostream &os, const Camera &cam)
 
std::ostream & operator<< (std::ostream &os, const Mesh &m)
 
std::ostream & operator<< (std::ostream &os, const Scene &s)
 
std::ostream & operator<< (std::ostream &os, const Image &img)
 
std::ostream & operator<< (std::ostream &os, const RenderOptions &opts)
 

Variables

constexpr Color DEFAULT_COLOR {0.7f, 0.7f, 0.7f, 1.0f}
 The default mesh color: a neutral light gray (0.7, 0.7, 0.7).
 
constexpr Color TRANSPARENT_BLACK {0.0f, 0.0f, 0.0f, 0.0f}
 A fully transparent black color (0, 0, 0, 0).
 
constexpr Color WHITE {1.0f, 1.0f, 1.0f, 1.0f}
 An opaque white color (1, 1, 1, 1).
 

Typedef Documentation

◆ Mat4

using scimesh::Mat4 = typedef glm::mat4

4×4 floating-point matrix.

Used for model, view, and projection transforms. GLM matrices are column-major, matching OpenGL conventions.

Example
Mat4 identity(1.0f); // identity matrix
Mat4 scaled = glm::scale(identity, Vec3(2.0f)); // scale by 2
glm::mat4 Mat4
4×4 floating-point matrix.
Definition types.h:65
glm::vec3 Vec3
3-component floating-point vector (xyz).
Definition types.h:46
See also
Vec3, Vec4

Definition at line 65 of file types.h.

◆ Vec2

using scimesh::Vec2 = typedef glm::vec2

2-component floating-point vector (xy).

Use v.x, v.y to access components.

See also
Vec3, Vec4, Mat4

Definition at line 32 of file types.h.

◆ Vec3

using scimesh::Vec3 = typedef glm::vec3

3-component floating-point vector (xyz).

This is the workhorse type for positions, directions, and normals. Access components with .x, .y, .z.

Example
Vec3 pos(1.0f, 2.0f, 3.0f); // a point in 3D space
Vec3 dir = glm::normalize(pos); // convert to unit-length direction
float dot = glm::dot(pos, dir); // dot product
See also
Vec2, Vec4, Mat4

Definition at line 46 of file types.h.

◆ Vec4

using scimesh::Vec4 = typedef glm::vec4

4-component floating-point vector (xyzw).

Primarily used internally for homogeneous clip-space coordinates.

See also
Vec3, Mat4

Definition at line 52 of file types.h.

Enumeration Type Documentation

◆ CropContentDirection

enum class scimesh::CropContentDirection
strong

Direction(s) for the crop_to_content() operation.

Specifies which edges to crop. You can crop individual edges or combinations.

See also
Image::crop_to_content()
Enumerator
LEFT 

Crop left edge only.

RIGHT 

Crop right edge only.

HORIZONTAL 

Crop both left and right edges.

TOP 

Crop top edge only.

BOTTOM 

Crop bottom edge only.

VERTICAL 

Crop both top and bottom edges.

ALL 

Crop all four edges.

Definition at line 37 of file image.h.

◆ FitMode

enum class scimesh::FitMode
strong

Strategy for normalizing images to a common cell size in grid_arrange().

See also
grid_arrange()
Enumerator
PAD 

Pad smaller images with background color (content stays pixel-perfect).

SCALE 

Scale all images to match the largest cell dimensions.

Definition at line 50 of file image.h.

◆ MergeDirection

enum class scimesh::MergeDirection
strong

Direction for the merge() operation.

Controls which side of the base image the other image is attached to.

See also
Image::merge()
Enumerator
LEFT 

Attach other to the left side.

RIGHT 

Attach other to the right side.

TOP 

Attach other above.

BOTTOM 

Attach other below.

Definition at line 25 of file image.h.

◆ ProjectionType

enum class scimesh::ProjectionType
strong

The type of 3D→2D projection used by the camera.

See also
Camera, Camera::projection
Enumerator
ORTHOGRAPHIC 

Orthographic projection: parallel lines stay parallel.

Objects do not get smaller with distance.  Useful for technical
diagrams, architectural plans, and when you need to preserve
relative sizes regardless of depth. 
PERSPECTIVE 

Perspective projection: objects farther away appear smaller.

This mimics how the human eye and real cameras work.  The field of
view (FOV) controls how "wide" the lens is.  This is the default. 

Definition at line 23 of file camera.h.

◆ ShadingMode

enum class scimesh::ShadingMode
strong

How surface normals are interpolated across triangles.

See also
RenderOptions::shading
Enumerator
SMOOTH 

Smooth (Gouraud) shading: normals are interpolated across each triangle, producing a smooth, rounded appearance.

Best for curved surfaces like spheres. Requires per-vertex normals (use compute_vertex_normals() to generate them).

FLAT 

Flat shading: each triangle uses a single normal, giving a faceted, low-poly look.

Best for mechanical parts, cubes, or when you want to emphasize the mesh structure.

Definition at line 22 of file render_options.h.

Function Documentation

◆ apply_colormap() [1/2]

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.

Each element of data is normalised to [0, 1] based on the effective data range and then mapped through the colormap. NaN / Inf values receive nan_color.

Parameters
dataPer-vertex (or per-element) numeric values. NaN / Inf allowed — they will be mapped to nan_color.
colormapThe colour lookup table to sample from.
vminLower bound of the data range. NAN = auto-detect from finite values (after winsorizing, if applicable).
vmaxUpper bound of the data range. NAN = auto-detect.
nan_colorRGBA colour for NaN / Inf positions.
lo_pctLower percentile for winsorizing (0.0 = off). E.g., 2.0 → clip values below the 2nd percentile.
hi_pctUpper percentile for winsorizing (100.0 = off). E.g., 98.0 → clip values above the 98th percentile.
Returns
An ApplyColormapResult with the mapped colours and metadata.
Example — single dataset with winsorizing
std::vector<float> data = {1.2f, 3.4f, NAN, 2.1f, 99.0f, 2.8f};
ColorMap cmap = build_viridis(); // user-supplied 256-entry colormap
auto r = apply_colormap(data, cmap, NAN, NAN,
Color(1,1,1,1), // white NaN
5.0f, 95.0f); // clip 5th/95th percentiles
// r.colors[i] — colour for data[i]
// r.data_min/max — effective range (after winsorizing) → use for colourbar
// r.winsor_lo/hi — the actual percentile cutoff values
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

Definition at line 345 of file colormap.cpp.

◆ apply_colormap() [2/2]

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.

This is the multi-dataset overload. Each dataset (e.g., per-vertex data for the left and right brain hemispheres) is mapped independently, and pooled statistics across all datasets are always computed.

Parameters
datasetsOne or more per-vertex (or per-element) data vectors.
colormapThe colour lookup table.
vminLower bound. NAN = auto-detect.
vmaxUpper bound. NAN = auto-detect.
nan_colorRGBA colour for NaN / Inf positions.
lo_pctLower percentile for winsorizing (0.0 = off).
hi_pctUpper percentile for winsorizing (100.0 = off).
global_rangeIf true, compute vmin/vmax from all datasets pooled together, so both hemispheres use the same colour scale. If false, each dataset gets its own independent range (unless vmin/vmax are explicitly set, which overrides everything).
Returns
A MultiApplyColormapResult with per-dataset colours and pooled metadata.
Example — two hemispheres, shared colour scale
std::vector<float> lh_thickness = {2.3f, 2.1f, NAN, ...};
std::vector<float> rh_thickness = {2.5f, 2.0f, NAN, ...};
auto r = apply_colormap({lh_thickness, rh_thickness}, cmap,
NAN, NAN,
Color(1,1,1,1), // white NaN (medial wall)
2.0f, 98.0f, // clip outliers
true); // shared range
// r.per_dataset[0].colors — colours for left hemisphere
// r.per_dataset[1].colors — colours for right hemisphere
// r.pooled_data_min/max — shared range → use for colourbar

Definition at line 397 of file colormap.cpp.

◆ camera_fit_mesh()

Camera scimesh::camera_fit_mesh ( const Mesh mesh,
const Vec3 direction,
const Vec3 up,
float  fov_degrees,
float  margin = 1.1f,
ProjectionType  projection = ProjectionType::PERSPECTIVE 
)

Create a camera that automatically frames a single Mesh.

Convenience wrapper around camera_fit_scene() for the common case of rendering a single mesh.

Parameters
meshThe mesh to frame.
directionView direction.
upUp vector.
fov_degreesField of view in degrees.
marginExtra zoom margin.
projectionProjection type.
Returns
A configured Camera.
Example
Mesh brain = scimesh::obj_io::read_obj("brain.obj");
Camera cam = camera_fit_mesh(brain, {0,0,1}, {0,1,0}, 45.0f);
Mesh read_obj(const std::string &path)
Load a mesh from a Wavefront OBJ file.
Definition obj_io.cpp:8
Camera camera_fit_mesh(const Mesh &mesh, const Vec3 &direction, const Vec3 &up, float fov_degrees, float margin, ProjectionType projection)
Create a camera that automatically frames a single Mesh.
Definition camera.cpp:75
A virtual camera that defines the viewpoint for rendering.
Definition camera.h:77
A 3D triangle mesh using an indexed face set representation.
Definition mesh.h:76
See also
camera_fit_scene(), camera_look_at()

Definition at line 75 of file camera.cpp.

◆ camera_fit_scene()

Camera scimesh::camera_fit_scene ( const Scene scene,
const Vec3 direction,
const Vec3 up,
float  fov_degrees,
float  margin = 1.1f,
ProjectionType  projection = ProjectionType::PERSPECTIVE 
)

Create a camera that automatically frames an entire Scene.

Computes the combined bounding box of all meshes and sets up the camera to show everything.

Parameters
sceneThe scene to frame.
directionView direction (e.g., {0,0,1} for front view).
upUp vector (e.g., {0,1,0}).
fov_degreesField of view in degrees.
marginExtra zoom margin (default 1.1 = 10% padding).
projectionProjection type (default: PERSPECTIVE).
Returns
A configured Camera.
Example
Scene scene;
scene.meshes.push_back(sphere1);
scene.meshes.push_back(cube1);
Camera cam = camera_fit_scene(scene, {1,1,1}, {0,1,0}, 45.0f);
// camera now frames both objects from a diagonal viewpoint
Camera camera_fit_scene(const Scene &scene, const Vec3 &direction, const Vec3 &up, float fov_degrees, float margin, ProjectionType projection)
Create a camera that automatically frames an entire Scene.
Definition camera.cpp:58
A collection of Mesh objects to be rendered together.
Definition scene.h:57
std::vector< Mesh > meshes
The meshes in this scene, drawn in order.
Definition scene.h:59
See also
camera_fit_mesh(), camera_look_at()

Definition at line 58 of file camera.cpp.

◆ camera_look_at()

Camera scimesh::camera_look_at ( const Vec3 center,
float  radius,
const Vec3 direction,
const Vec3 up,
float  fov_degrees,
float  margin = 1.1f,
ProjectionType  projection = ProjectionType::PERSPECTIVE 
)

Create a camera that looks at a point from a given distance and direction.

This is the low-level function for camera setup. It computes the exact eye position needed to frame a sphere of radius centered at center.

Parameters
centerThe point to look at (becomes Camera::center).
radiusThe radius of a bounding sphere around the subject.
directionView direction vector (e.g., {0,0,1} for front view).
upUp vector (usually {0,1,0}).
fov_degreesVertical field of view in degrees.
marginExtra margin factor (>1.0 = zoomed out, <1.0 = tighter). Default 1.1 gives 10% padding.
projectionProjection type (default: PERSPECTIVE).
Returns
A configured Camera.
Example
Camera cam = camera_look_at({0,0,0}, 5.0f, {0,0,1}, {0,1,0}, 45.0f, 1.2f);
// Looks at origin from +Z, framing a sphere of radius 5, with 20% margin
Camera camera_look_at(const Vec3 &center, float radius, const Vec3 &direction, const Vec3 &up, float fov_degrees, float margin, ProjectionType projection)
Create a camera that looks at a point from a given distance and direction.
Definition camera.cpp:38
See also
camera_fit_mesh(), camera_fit_scene()

Definition at line 38 of file camera.cpp.

◆ camera_orbit()

Camera scimesh::camera_orbit ( const Camera camera,
const Vec3 axis,
float  angle_degrees 
)

Orbit the camera around its look-at point.

Rotates the camera's eye position around camera.center by the given angle around the given axis. The up vector is also rotated.

Parameters
cameraThe camera to orbit (modified copy returned).
axisRotation axis (should pass through camera.center).
angle_degreesRotation angle in degrees.
Returns
A new Camera with the rotated eye position.
Example
Camera cam = camera_fit_mesh(mesh, {0,0,1}, {0,1,0}, 45.0f);
// Rotate 30° around the Y axis (horizontal orbit)
Camera cam2 = camera_orbit(cam, {0,1,0}, 30.0f);
Camera camera_orbit(const Camera &camera, const Vec3 &axis, float angle_degrees)
Orbit the camera around its look-at point.
Definition camera.cpp:92
See also
camera_look_at()

Definition at line 92 of file camera.cpp.

◆ clip_triangle_near_plane()

int scimesh::clip_triangle_near_plane ( const ClipVertex v0,
const ClipVertex v1,
const ClipVertex v2,
std::vector< ClipVertex > &  output_vertices,
std::vector< Triangle > &  output_triangles 
)

Clip a triangle against the near clipping plane in clip space.

This is part of the rendering pipeline — triangles that cross the near plane are split so that only the visible portion (w > 0) is kept.

Parameters
v0,v1,v2Three vertices of the input triangle (in homogeneous clip space).
[out]output_verticesClipped vertices are appended here.
[out]output_trianglesResulting triangle indices (0, 1, or 2 triangles) are appended here.
Returns
Number of output triangles (0, 1, or 2). 0 means the triangle is entirely behind the near plane and should be discarded.
See also
clip_triangle_view_plane(), Renderer::render_pipeline()

Definition at line 67 of file clipping.cpp.

◆ clip_triangle_view_plane()

int scimesh::clip_triangle_view_plane ( const Vec3 v0,
const Vec3 v1,
const Vec3 v2,
const Vec3 n0,
const Vec3 n1,
const Vec3 n2,
const Color c0,
const Color c1,
const Color c2,
const Vec2 uv0,
const Vec2 uv1,
const Vec2 uv2,
const ClipPlane plane,
std::vector< ClipVertex > &  output_vertices,
std::vector< Triangle > &  output_triangles 
)

Clip a triangle against an arbitrary plane in view space.

This is used for user-specified clip planes (see ClipPlane). A vertex is considered "inside" (kept) when: dot(view_pos, plane.normal) + plane.offset >= 0.

Parameters
v0,v1,v2Triangle vertex positions in view space.
n0,n1,n2Per-vertex normals (view space).
c0,c1,c2Per-vertex colors.
uv0,uv1,uv2Per-vertex texture coordinates.
planeThe clipping plane.
[out]output_verticesClipped vertices (positions are in view space — caller must transform to clip space).
[out]output_trianglesResulting triangle indices.
Returns
Number of output triangles (0, 1, or 2).
See also
clip_triangle_near_plane(), ClipPlane, RenderOptions::clip_planes

Definition at line 162 of file clipping.cpp.

◆ compute_barycentric()

void scimesh::compute_barycentric ( float  px,
float  py,
float  x0,
float  y0,
float  x1,
float  y1,
float  x2,
float  y2,
float &  u,
float &  v,
float &  w 
)
inline

Compute barycentric coordinates (u, v, w) of a point in a triangle.

Barycentric coordinates tell you how much each vertex contributes to a point inside the triangle. They are used for interpolating colors, normals, and depth across the triangle surface.

  • u + v + w = 1.0
  • All three are in [0, 1] if and only if the point is inside the triangle.
Parameters
px,pyThe query point (2D screen coords).
x0,y0,x1,y1,x2,y2Triangle vertices (2D screen coords).
[out]u,v,wOutput barycentric weights.
Example: checking if a point is inside a triangle
float u, v, w;
compute_barycentric(px, py, x0, y0, x1, y1, x2, y2, u, v, w);
if (u >= 0 && v >= 0 && w >= 0) {
// point is inside the triangle
}
void compute_barycentric(float px, float py, float x0, float y0, float x1, float y1, float x2, float y2, float &u, float &v, float &w)
Compute barycentric coordinates (u, v, w) of a point in a triangle.
Definition math_utils.h:158

Definition at line 158 of file math_utils.h.

◆ compute_face_normal()

Vec3 scimesh::compute_face_normal ( const Vec3 v0,
const Vec3 v1,
const Vec3 v2 
)
inline

Compute the unit-length normal vector of a triangle face.

Uses the cross product of two edges. The normal points according to the right-hand rule: if vertices are ordered counter-clockwise when viewed from the front, the normal points toward the viewer.

Parameters
v0,v1,v2The three triangle vertex positions.
Returns
A unit-length Vec3 perpendicular to the triangle. Returns (0, 0, 1) for degenerate (zero-area) triangles.
Example
Vec3 n = compute_face_normal({0,0,0}, {1,0,0}, {0,1,0});
// n = (0, 0, 1) — pointing out of the XY plane
Vec3 compute_face_normal(const Vec3 &v0, const Vec3 &v1, const Vec3 &v2)
Compute the unit-length normal vector of a triangle face.
Definition math_utils.h:37
See also
compute_vertex_normals()

Definition at line 37 of file math_utils.h.

◆ compute_vertex_normals()

void scimesh::compute_vertex_normals ( const Mesh mesh,
std::vector< Vec3 > &  normals 
)

Compute per-vertex normals by averaging adjacent face normals.

For each vertex, this function finds all triangles that share that vertex, computes each triangle's face normal using compute_face_normal(), and averages them together (weighted equally). The resulting normals are suitable for smooth (Gouraud) shading.

Parameters
[in]meshThe input mesh (only vertices and triangles are read).
[out]normalsOutput array — will be resized to mesh.vertices.size() and filled with unit-length normal vectors.
When do I need this?
Most file formats (OBJ, PLY, STL) may or may not include normals. If you load a mesh and mesh.has_normals() returns false, call this function to compute them before rendering with ShadingMode::SMOOTH.
Example
if (!m.has_normals()) {
}
// now render with smooth shading
void compute_vertex_normals(const Mesh &mesh, std::vector< Vec3 > &normals)
Compute per-vertex normals by averaging adjacent face normals.
Definition normals.cpp:5
std::vector< Vec3 > normals
Per-vertex surface normals (unit-length direction vectors).
Definition mesh.h:125
bool has_normals() const
Does the mesh have per-vertex normals?
Definition mesh.h:187
See also
compute_face_normal(), Mesh::normals, Mesh::has_normals(), ShadingMode

Definition at line 5 of file normals.cpp.

◆ convert_fs_mesh() [1/4]

Mesh scimesh::convert_fs_mesh ( const fs::Mesh &  fs_mesh)
inline

Convert a FreeSurfer mesh to a scimesh Mesh (no colors).

Copies vertex positions and face indices. No colors are set — you should set Mesh::default_color or populate Mesh::colors before rendering.

Parameters
fs_meshThe FreeSurfer mesh to convert.
Returns
A scimesh Mesh with vertices and triangles populated.
Example
fs::Mesh fs_brain = fs::read_fs_mesh("lh.white");
Mesh brain = scimesh::convert_fs_mesh(fs_brain);
brain.default_color = Color(0.7f, 0.7f, 0.7f);
Mesh convert_fs_mesh(const fs::Mesh &fs_mesh)
Convert a FreeSurfer mesh to a scimesh Mesh (no colors).
An RGBA color with floating-point components.
Definition types.h:88
Color default_color
Fallback color when no per-vertex or per-face color is set.
Definition mesh.h:160
See also
convert_fs_mesh(const fs::Mesh&, const Color&), convert_fs_mesh(const fs::Mesh&, const std::vector<uint8_t>&)

Definition at line 37 of file fs_mesh_converter.h.

◆ convert_fs_mesh() [2/4]

Mesh scimesh::convert_fs_mesh ( const fs::Mesh &  fs_mesh,
const Color solid_color 
)
inline

Convert a FreeSurfer mesh to a scimesh Mesh with a solid color.

All vertices are assigned the same solid_color. This is a convenience wrapper — it calls the basic converter, then fills mesh.colors.

Parameters
fs_meshThe FreeSurfer mesh to convert.
solid_colorThe uniform color to assign to all vertices.
Returns
A scimesh Mesh with vertices, triangles, and per-vertex colors.
Example
fs::Mesh fs_brain = fs::read_fs_mesh("lh.white");
Mesh brain = scimesh::convert_fs_mesh(fs_brain, Color(0.5f, 0.5f, 0.5f));
See also
convert_fs_mesh(const fs::Mesh&)

Definition at line 74 of file fs_mesh_converter.h.

◆ convert_fs_mesh() [3/4]

Mesh scimesh::convert_fs_mesh ( const fs::Mesh &  fs_mesh,
const std::vector< float > &  morph_data,
const std::vector< uint8_t > &  rgb_colors 
)
inline

Convert a FreeSurfer mesh with per-vertex morphological data and RGB coloring.

This is the most feature-rich converter. Each vertex gets:

  • An RGB color from rgb_colors (3 bytes per vertex).
  • If morph_data[i] is NaN, the vertex is colored white (often used to mark the medial wall or "unknown" regions in brain surface data).
Parameters
fs_meshThe FreeSurfer mesh to convert.
morph_dataPer-vertex scalar values (NaN = mark as white).
rgb_colorsFlat array of RGB bytes (size = 3 × vertex count).
Returns
A scimesh Mesh with per-vertex colors.
Example
fs::Mesh fs_brain = fs::read_fs_mesh("lh.white");
std::vector<float> curv = fs::read_curv("lh.thickness");
std::vector<uint8_t> rgb = fs_mesh.get_vertex_rgb();
Mesh brain = scimesh::convert_fs_mesh(fs_brain, curv, rgb);
See also
convert_fs_mesh(const fs::Mesh&, const std::vector<uint8_t>&)

Definition at line 137 of file fs_mesh_converter.h.

◆ convert_fs_mesh() [4/4]

Mesh scimesh::convert_fs_mesh ( const fs::Mesh &  fs_mesh,
const std::vector< uint8_t > &  rgb_colors 
)
inline

Convert a FreeSurfer mesh with per-vertex RGB coloring.

Each vertex gets a color from the rgb_colors array (3 bytes per vertex: red, green, blue, each 0–255).

Parameters
fs_meshThe FreeSurfer mesh to convert.
rgb_colorsFlat array of RGB bytes (size = 3 × vertex count).
Returns
A scimesh Mesh with per-vertex colors.
Example
std::vector<uint8_t> rgb = fs_mesh.get_vertex_rgb();
Mesh brain = scimesh::convert_fs_mesh(fs_mesh, rgb);
See also
convert_fs_mesh(const fs::Mesh&, const Color&)

Definition at line 100 of file fs_mesh_converter.h.

◆ fmt_count()

std::string scimesh::fmt_count ( size_t  n)
inline

Definition at line 48 of file to_string.h.

◆ fmt_size_bytes()

std::string scimesh::fmt_size_bytes ( size_t  bytes)
inline

Definition at line 62 of file to_string.h.

◆ generate_arrow()

Mesh scimesh::generate_arrow ( const Vec3 from,
const Vec3 to,
float  shaft_radius,
float  head_radius,
float  head_length,
int  segments,
const Color color 
)

Generate a 3D arrow from from to to.

An arrow consists of a cylindrical shaft and a conical head. The arrow points from from toward to. Both parts share the same color.

Parameters
fromStarting point (tail of the arrow).
toEnding point (tip of the arrowhead).
shaft_radiusRadius of the cylindrical shaft.
head_radiusRadius of the cone base (arrowhead width).
head_lengthLength of the arrowhead along the arrow direction.
segmentsNumber of sides around the circumference.
colorUniform color.
Returns
A new Mesh with normals.
Example
// Red arrow from origin to (3, 0, 0)
Mesh arrow = generate_arrow({0,0,0}, {3,0,0}, 0.1f, 0.3f, 0.6f, 16,
Color(1,0,0));
Mesh generate_arrow(const Vec3 &from, const Vec3 &to, float shaft_radius, float head_radius, float head_length, int segments, const Color &color)
Generate a 3D arrow from from to to.
See also
generate_cylinder(), generate_cone()

Definition at line 268 of file primitives.cpp.

◆ generate_cone()

Mesh scimesh::generate_cone ( const Vec3 base,
const Vec3 tip,
float  radius,
int  segments,
const Color color 
)

Generate a cone from a base circle to a tip point.

The cone has a circular base centered at base, tapering to a point at tip. The base cap is included.

Parameters
baseCenter of the circular base.
tipThe apex (pointy end) of the cone.
radiusRadius of the base.
segmentsNumber of sides (≥ 3).
colorUniform color.
Returns
A new Mesh with normals.
Example
Mesh cone = generate_cone({0,0,0}, {0,3,0}, 1.0f, 16,
Color(1.0f, 0.5f, 0.0f));
Mesh generate_cone(const Vec3 &base, const Vec3 &tip, float radius, int segments, const Color &color)
Generate a cone from a base circle to a tip point.
See also
generate_cylinder(), generate_pyramid()

Definition at line 192 of file primitives.cpp.

◆ generate_cuboid()

Mesh scimesh::generate_cuboid ( const Vec3 center,
const Vec3 half_extents,
const Color color 
)

Generate an axis-aligned cuboid (rectangular box).

The box is centered at center and extends half_extents in each direction (i.e., the full dimensions are 2 * half_extents).

Parameters
centerCenter of the box.
half_extentsHalf-width, half-height, half-depth (all positive).
colorUniform color.
Returns
A new Mesh with normals.
Example
// A 2×1×3 box centered at the origin
Mesh box = generate_cuboid({0,0,0}, {1, 0.5, 1.5}, Color(0.5, 0.5, 0.5));
Mesh generate_cuboid(const Vec3 &center, const Vec3 &half, const Color &color)
Generate an axis-aligned cuboid (rectangular box).
See also
generate_sphere(), generate_pyramid()

Definition at line 332 of file primitives.cpp.

◆ generate_cylinder()

Mesh scimesh::generate_cylinder ( const Vec3 start,
const Vec3 end,
float  radius,
int  segments,
const Color color 
)

Generate a cylinder between two endpoints.

The cylinder runs from start to end with a circular cross-section of the given radius. End caps are included.

Parameters
startStarting point (center of bottom cap).
endEnding point (center of top cap).
radiusRadius of the cylinder.
segmentsNumber of sides around the circumference (≥ 3).
colorUniform color.
Returns
A new Mesh with normals.
Example
Mesh pillar = generate_cylinder({0,0,0}, {0,5,0}, 0.5f, 16,
Color(0.7f, 0.7f, 0.7f));
Mesh generate_cylinder(const Vec3 &start, const Vec3 &end, float radius, int segments, const Color &color)
Generate a cylinder between two endpoints.
See also
generate_cone(), generate_arrow()

Definition at line 95 of file primitives.cpp.

◆ generate_multi_cylinders()

Mesh scimesh::generate_multi_cylinders ( const std::vector< Vec3 > &  starts,
const std::vector< Vec3 > &  ends,
const std::vector< float > &  radii,
const std::vector< Color > &  colors,
int  segments = 12 
)

Generate multiple cylinders in a single mesh (efficient batching).

Much faster than calling generate_cylinder() many times — all cylinders share a single mesh.

Parameters
startsArray of start points.
endsArray of end points (same length as starts).
radiiArray of radii (same length).
colorsArray of colors (same length).
segmentsSubdivisions per cylinder (default: 12).
Returns
A single Mesh containing all cylinders.
Example
std::vector<Vec3> starts = {{0,0,0}, {1,0,0}};
std::vector<Vec3> ends = {{0,3,0}, {1,3,0}};
std::vector<float> rads = {0.1f, 0.1f};
std::vector<Color> cols = {Color(1,1,1), Color(1,1,1)};
Mesh pillars = generate_multi_cylinders(starts, ends, rads, cols, 12);
Mesh generate_multi_cylinders(const std::vector< Vec3 > &starts, const std::vector< Vec3 > &ends, const std::vector< float > &radii, const std::vector< Color > &colors, int segments)
Generate multiple cylinders in a single mesh (efficient batching).
See also
generate_cylinder(), generate_multi_spheres()

Definition at line 316 of file primitives.cpp.

◆ generate_multi_spheres()

Mesh scimesh::generate_multi_spheres ( const std::vector< Vec3 > &  centers,
const std::vector< float > &  radii,
const std::vector< Color > &  colors,
int  segments = 16 
)

Generate multiple spheres in a single mesh (efficient batching).

Much faster than calling generate_sphere() many times and merging — all spheres share a single mesh with one vertex/triangle array.

Parameters
centersArray of center points.
radiiArray of radii (same length as centers).
colorsArray of colors (same length as centers).
segmentsSubdivisions per sphere (default: 16).
Returns
A single Mesh containing all spheres.
Example
std::vector<Vec3> pts = {{0,0,0}, {2,0,0}, {0,2,0}};
std::vector<float> rads = {0.5, 0.3, 0.4};
std::vector<Color> cls = {Color(1,0,0), Color(0,1,0), Color(0,0,1)};
Mesh spheres = generate_multi_spheres(pts, rads, cls, 16);
Mesh generate_multi_spheres(const std::vector< Vec3 > &centers, const std::vector< float > &radii, const std::vector< Color > &colors, int segments)
Generate multiple spheres in a single mesh (efficient batching).
See also
generate_sphere(), generate_multi_cylinders()

Definition at line 301 of file primitives.cpp.

◆ generate_plane()

Mesh scimesh::generate_plane ( const Vec3 center,
const Vec3 normal,
float  half_size_x,
float  half_size_y,
const Color color 
)

Generate a flat rectangular plane.

The plane is a single quad (two triangles) centered at center, oriented perpendicular to the given normal.

Parameters
centerCenter point of the plane.
normalSurface normal (direction the plane faces).
half_size_xHalf the width in the local X direction.
half_size_yHalf the height in the local Y direction.
colorUniform color.
Returns
A new Mesh with normals.
Example
Mesh floor = generate_plane({0,-1,0}, {0,1,0}, 10.0f, 10.0f,
Color(0.3f, 0.3f, 0.3f));
Mesh generate_plane(const Vec3 &center, const Vec3 &normal, float hx, float hy, const Color &color)
Generate a flat rectangular plane.
See also
generate_cuboid()

Definition at line 561 of file primitives.cpp.

◆ generate_pyramid()

Mesh scimesh::generate_pyramid ( const Vec3 base_center,
const Vec3 apex,
float  half_width,
const Color color 
)

Generate a square-based pyramid.

The base is a square in the XZ plane centered at base_center. The apex is above the base.

Parameters
base_centerCenter of the square base.
apexThe top point (tip) of the pyramid.
half_widthHalf the side length of the square base.
colorUniform color.
Returns
A new Mesh with normals.
Example
Mesh pyramid = generate_pyramid({0,0,0}, {0,2,0}, 1.0f,
Color(0.8f, 0.6f, 0.2f));
Mesh generate_pyramid(const Vec3 &base_center, const Vec3 &apex, float hw, const Color &color)
Generate a square-based pyramid.
See also
generate_cone(), generate_tetrahedron()

Definition at line 395 of file primitives.cpp.

◆ generate_sphere()

Mesh scimesh::generate_sphere ( const Vec3 center,
float  radius,
int  segments,
const Color color 
)

Generate a UV-sphere (latitude/longitude tessellation).

The sphere is centered at center with the given radius. The segments parameter controls how smooth it looks — more segments = rounder but more triangles.

Parameters
centerCenter point of the sphere.
radiusRadius (half the diameter).
segmentsNumber of subdivisions (≥ 3). Typical: 16 (low-poly) to 64 (smooth). The sphere has segments * segments * 2 triangles.
colorUniform color for all vertices.
Returns
A new Mesh with vertices, triangles, and per-vertex normals.
Example
Mesh ball = generate_sphere({0,0,0}, 1.0f, 32, Color(0.2f, 0.5f, 0.8f));
Mesh generate_sphere(const Vec3 &center, float radius, int segments, const Color &color)
Generate a UV-sphere (latitude/longitude tessellation).
See also
generate_torus(), generate_cylinder()

Definition at line 20 of file primitives.cpp.

◆ generate_tetrahedron()

Mesh scimesh::generate_tetrahedron ( const Vec3 p0,
const Vec3 p1,
const Vec3 p2,
const Vec3 p3,
const Color color 
)

Generate a tetrahedron (triangular pyramid) from four points.

A tetrahedron is the simplest 3D shape — a pyramid with a triangular base and three triangular sides.

Parameters
p0,p1,p2,p3The four corner points.
colorUniform color.
Returns
A new Mesh.
Example
{0,0,0}, {1,0,0}, {0,1,0}, {0,0,1},
Color(0.3f, 0.7f, 0.3f));
Mesh generate_tetrahedron(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2, const Vec3 &p3, const Color &color)
Generate a tetrahedron (triangular pyramid) from four points.
See also
generate_pyramid()

Definition at line 458 of file primitives.cpp.

◆ generate_torus()

Mesh scimesh::generate_torus ( const Vec3 center,
float  major_radius,
float  minor_radius,
int  major_segments,
int  minor_segments,
const Color color 
)

Generate a torus (donut shape).

A torus is the surface of a ring. major_radius is the distance from the center of the hole to the center of the tube. minor_radius is the radius of the tube itself.

Parameters
centerCenter of the torus.
major_radiusDistance from hole center to tube center.
minor_radiusRadius of the tube cross-section.
major_segmentsSubdivisions around the ring (≥ 4).
minor_segmentsSubdivisions around the tube (≥ 4).
colorUniform color.
Returns
A new Mesh with normals.
Example
Mesh donut = generate_torus({0,0,0}, 2.0f, 0.5f, 32, 16,
Color(0.9f, 0.6f, 0.3f));
Mesh generate_torus(const Vec3 &center, float R, float r, int seg_major, int seg_minor, const Color &color)
Generate a torus (donut shape).
See also
generate_sphere(), generate_cylinder()

Definition at line 504 of file primitives.cpp.

◆ grid_arrange()

Image scimesh::grid_arrange ( const std::vector< Image > &  images,
int  ncol = 0,
int  nrow = 0,
FitMode  fit_mode = FitMode::PAD,
const Color background = Color(1.0f, 1.0f, 1.0f, 1.0f) 
)

Arrange a list of images into a grid layout.

Images are placed left-to-right, top-to-bottom in an ncol × nrow grid. If the number of images is less than ncol * nrow, remaining cells are filled with background. Before placement, all images are normalized to the same cell size using fit_mode.

Parameters
imagesThe list of images to arrange.
ncolNumber of columns (0 = auto-compute from nrow).
nrowNumber of rows (0 = auto-compute from ncol). If both are 0, a square-ish layout is chosen.
fit_modeHow to handle size mismatches (PAD or SCALE).
backgroundFill color for padding and empty cells.
Returns
A new Image containing the arranged grid.
Example
Image grid = grid_arrange({view1, view2, view3, view4}, 2, 2,
FitMode::PAD, Color(1,1,1));
Image grid_arrange(const std::vector< Image > &images, int ncol, int nrow, FitMode fit_mode, const Color &background)
Arrange a list of images into a grid layout.
Definition image.cpp:560
@ PAD
Pad smaller images with background color (content stays pixel-perfect).
A 2D RGBA image buffer.
Definition image.h:87
See also
FitMode, Image::pad_to_size(), Image::scale()

Definition at line 560 of file image.cpp.

◆ max_ortho_extent()

float scimesh::max_ortho_extent ( const Vec3 bmin,
const Vec3 bmax,
const Vec3 center,
const Vec3 dir 
)
inline

Compute the maximum perpendicular extent of an AABB from a view ray (for orthographic projection framing).

Unlike perp_extent_radius(), this does not depend on field of view — it is used to set the orthographic frustum size.

Parameters
bminMinimum corner of the AABB.
bmaxMaximum corner of the AABB.
centerThe center point the camera looks at.
dirThe view direction.
Returns
The maximum perpendicular distance from the ray through center.
See also
perp_extent_radius(), camera_look_at()

Definition at line 196 of file camera.h.

◆ merge_mesh()

void scimesh::merge_mesh ( Mesh dst,
const Mesh src 
)

Merge one mesh into another (append geometry).

All vertices, triangles, colors, normals, and UVs from src are appended to dst. Triangle indices in src are offset to account for existing vertices in dst.

Parameters
[in,out]dstThe destination mesh (modified in-place).
srcThe source mesh (not modified).
Example
Mesh combined = generate_sphere({-1,0,0}, 0.5f, 16, Color(1,0,0));
merge_mesh(combined, generate_sphere({1,0,0}, 0.5f, 16, Color(0,1,0)));
// combined now has two spheres
void merge_mesh(Mesh &dst, const Mesh &src)
Merge one mesh into another (append geometry).
See also
generate_multi_spheres(), generate_multi_cylinders()

Definition at line 288 of file primitives.cpp.

◆ mesh_from_fs()

Mesh scimesh::mesh_from_fs ( const std::vector< float > &  fs_vertices,
const std::vector< uint32_t > &  fs_faces,
const std::vector< float > &  per_vertex_values = {},
const std::vector< uint8_t > &  rgb_bytes = {},
bool  detect_transparency = false 
)

Convert a FreeSurfer-format mesh (flat vertex/face arrays) to a scimesh Mesh.

FreeSurfer is a neuroimaging software suite. Its mesh format stores vertices as a flat float array (3 per vertex) and faces as a flat uint32_t array (3 per face). This function converts those raw arrays into a scimesh Mesh with optional per-vertex coloring.

Parameters
fs_verticesFlat array of vertex coordinates (x0,y0,z0, x1,y1,z1, ...).
fs_facesFlat array of face indices (v0,v1,v2, v0,v1,v2, ...).
per_vertex_valuesOptional scalar per-vertex values for coloring.
rgb_bytesOptional RGB color bytes (3 per vertex: r,g,b, ...).
detect_transparencyIf true, check for NaN values indicating transparent regions (common in brain surface data).
Returns
A scimesh Mesh.
Example
std::vector<float> verts = {0,0,0, 1,0,0, 0,1,0, 1,1,0};
std::vector<uint32_t> faces = {0,1,2, 1,3,2};
Mesh m = mesh_from_fs(verts, faces);
Mesh mesh_from_fs(const std::vector< float > &fs_vertices, const std::vector< uint32_t > &fs_faces, const std::vector< float > &per_vertex_values, const std::vector< uint8_t > &rgb_bytes, bool detect_transparency)
Convert a FreeSurfer-format mesh (flat vertex/face arrays) to a scimesh Mesh.
See also
Mesh, fs_mesh_converter.h

Definition at line 38 of file transforms.cpp.

◆ ndc_to_screen()

void scimesh::ndc_to_screen ( const Vec3 ndc,
int  width,
int  height,
float &  screen_x,
float &  screen_y,
float &  depth 
)
inline

Convert from normalized device coordinates (NDC) to screen (pixel) coordinates.

NDC space is a cube from (-1,-1,-1) to (1,1,1). This maps it to pixel coordinates where (0,0) is the top-left corner.

Parameters
ndcInput NDC coordinates.
widthScreen width in pixels.
heightScreen height in pixels.
[out]screen_xOutput X pixel coordinate.
[out]screen_yOutput Y pixel coordinate (0 = top).
[out]depthOutput depth value (passed through from NDC z).
See also
perspective_divide()

Definition at line 125 of file math_utils.h.

◆ operator<<() [1/12]

std::ostream & scimesh::operator<< ( std::ostream &  os,
const Camera cam 
)
inline

Definition at line 117 of file to_string.h.

◆ operator<<() [2/12]

std::ostream & scimesh::operator<< ( std::ostream &  os,
const ClipPlane cp 
)
inline

Definition at line 112 of file to_string.h.

◆ operator<<() [3/12]

std::ostream & scimesh::operator<< ( std::ostream &  os,
const Color c 
)
inline

Definition at line 78 of file to_string.h.

◆ operator<<() [4/12]

std::ostream & scimesh::operator<< ( std::ostream &  os,
const Image img 
)
inline

Definition at line 156 of file to_string.h.

◆ operator<<() [5/12]

std::ostream & scimesh::operator<< ( std::ostream &  os,
const Light l 
)
inline

Definition at line 105 of file to_string.h.

◆ operator<<() [6/12]

std::ostream & scimesh::operator<< ( std::ostream &  os,
const Mesh m 
)
inline

Definition at line 127 of file to_string.h.

◆ operator<<() [7/12]

std::ostream & scimesh::operator<< ( std::ostream &  os,
const RenderOptions opts 
)
inline

Definition at line 163 of file to_string.h.

◆ operator<<() [8/12]

std::ostream & scimesh::operator<< ( std::ostream &  os,
const Scene s 
)
inline

Definition at line 145 of file to_string.h.

◆ operator<<() [9/12]

std::ostream & scimesh::operator<< ( std::ostream &  os,
const Triangle t 
)
inline

Definition at line 88 of file to_string.h.

◆ operator<<() [10/12]

std::ostream & scimesh::operator<< ( std::ostream &  os,
const Vec3 v 
)
inline

Definition at line 83 of file to_string.h.

◆ operator<<() [11/12]

std::ostream & scimesh::operator<< ( std::ostream &  os,
ProjectionType  p 
)
inline

Definition at line 98 of file to_string.h.

◆ operator<<() [12/12]

std::ostream & scimesh::operator<< ( std::ostream &  os,
ShadingMode  s 
)
inline

Definition at line 93 of file to_string.h.

◆ perp_extent_radius()

float scimesh::perp_extent_radius ( const Vec3 bmin,
const Vec3 bmax,
const Vec3 center,
const Vec3 dir,
float  fov_radians,
float *  out_dist = nullptr 
)
inline

Compute the "perpendicular extent radius" of an axis-aligned bounding box relative to a view direction.

This is an internal helper used by camera_look_at() to compute how far the camera needs to be to keep the entire bounding box in view. It is tighter than a simple sphere-based method because it accounts for the actual box shape.

Parameters
bminMinimum corner of the AABB.
bmaxMaximum corner of the AABB.
centerThe center point the camera looks at.
dirThe view direction (forward vector).
fov_radiansVertical FOV in radians.
[out]out_distOptional: receives the computed camera distance.
Returns
The equivalent sphere radius.
See also
camera_look_at()

Definition at line 149 of file camera.h.

◆ perspective_divide()

Vec3 scimesh::perspective_divide ( const Vec4 clip)
inline

Perform perspective division: divide xyz by w.

Converts from homogeneous clip space to normalized device coordinates (NDC). If w is near zero (the point is at the camera plane), the result is clamped to avoid division by zero.

Parameters
clipA point in homogeneous clip space.
Returns
The point after division by w.
See also
transform_point_homogeneous(), ndc_to_screen()

Definition at line 105 of file math_utils.h.

◆ rotate_mesh()

void scimesh::rotate_mesh ( Mesh mesh,
float  angle_radians,
const Vec3 axis 
)

Rotate a mesh around an arbitrary axis.

Uses the right-hand rule: positive angle = counter-clockwise when looking along the axis toward the origin.

Parameters
[in,out]meshThe mesh to modify.
angle_radiansRotation angle in radians.
axisRotation axis (does not need to be normalized).
Example
#include <cmath>
rotate_mesh(mesh, M_PI / 2.0f, Vec3(0, 1, 0)); // 90° around Y axis
void rotate_mesh(Mesh &mesh, float angle_radians, const Vec3 &axis)
Rotate a mesh around an arbitrary axis.
See also
translate_mesh(), transform_mesh()

Definition at line 25 of file transforms.cpp.

◆ scale_mesh() [1/2]

void scimesh::scale_mesh ( Mesh mesh,
const Vec3 scale 
)

Scale a mesh non-uniformly along each axis.

Multiplies each vertex position component-wise by scale.

Parameters
[in,out]meshThe mesh to modify.
scaleScale factors per axis (e.g., {2,1,1} doubles width).
Example
scale_mesh(mesh, Vec3(2.0f, 1.0f, 0.5f)); // double X, halve Z
void scale_mesh(Mesh &mesh, const Vec3 &scale)
Scale a mesh non-uniformly along each axis.
See also
scale_mesh(Mesh&, float), rotate_mesh(), translate_mesh()

Definition at line 14 of file transforms.cpp.

◆ scale_mesh() [2/2]

void scimesh::scale_mesh ( Mesh mesh,
float  uniform_scale 
)

Scale a mesh uniformly in all directions.

Multiplies every vertex position by uniform_scale.

Parameters
[in,out]meshThe mesh to modify.
uniform_scaleScale factor (1.0 = unchanged, 2.0 = double size).
Example
scale_mesh(mesh, 0.5f); // half size
See also
scale_mesh(Mesh&, const Vec3&)

Definition at line 21 of file transforms.cpp.

◆ shade_pixel()

Color scimesh::shade_pixel ( const Color base_color,
const Vec3 normal,
const Vec3 light_direction,
const Color specular_color = Color(0, 0, 0, 0),
float  shininess = 0.0f 
)
inline

Compute the shaded color of a pixel with a single directional light.

Uses the Blinn-Phong reflection model with ambient and diffuse terms. The ambient term prevents completely black shadows.

Parameters
base_colorThe surface (unlit) color.
normalSurface normal at this pixel (should be unit-length).
light_directionDirection TO the light (should be unit-length).
specular_colorSpecular highlight color (transparent = no specular).
shininessShininess exponent (higher = sharper highlights).
Returns
The final lit color.
See also
shade_pixel_multi(), Light

Definition at line 191 of file math_utils.h.

◆ shade_pixel_multi()

Color scimesh::shade_pixel_multi ( const Color base_color,
const Vec3 normal,
const std::vector< Light > &  lights,
float  ambient,
const Color specular_color = Color(0, 0, 0, 0),
float  shininess = 0.0f 
)
inline

Compute the shaded color with multiple light sources.

Like shade_pixel(), but sums contributions from all lights in the lights array. Each light's intensity is divided by the number of lights to normalize total brightness.

Parameters
base_colorThe surface (unlit) color.
normalSurface normal (unit-length).
lightsArray of light sources.
ambientAmbient light level (0.0–1.0).
specular_colorSpecular highlight color.
shininessShininess exponent.
Returns
The final lit color.
See also
shade_pixel(), Light, RenderOptions::lights

Definition at line 231 of file math_utils.h.

◆ stack_horizontal()

Image scimesh::stack_horizontal ( const std::vector< Image > &  images,
FitMode  fit_mode = FitMode::PAD,
const Color background = Color(1.0f, 1.0f, 1.0f, 1.0f) 
)
inline

Stack images horizontally in a single row.

Convenience wrapper around grid_arrange() for the common case of placing images side-by-side. Equivalent to grid_arrange(images, images.size(), 1, ...).

Parameters
imagesThe list of images to arrange left-to-right.
fit_modeHow to handle size mismatches (PAD or SCALE).
backgroundFill color for padding.
Returns
A new Image containing the horizontal strip.
See also
grid_arrange(), stack_vertical()

Definition at line 427 of file image.h.

◆ stack_vertical()

Image scimesh::stack_vertical ( const std::vector< Image > &  images,
FitMode  fit_mode = FitMode::PAD,
const Color background = Color(1.0f, 1.0f, 1.0f, 1.0f) 
)
inline

Stack images vertically in a single column.

Convenience wrapper around grid_arrange() for the common case of placing images one above the other. Equivalent to grid_arrange(images, 1, images.size(), ...).

Parameters
imagesThe list of images to arrange top-to-bottom.
fit_modeHow to handle size mismatches (PAD or SCALE).
backgroundFill color for padding.
Returns
A new Image containing the vertical strip.
See also
grid_arrange(), stack_horizontal()

Definition at line 446 of file image.h.

◆ str_crop()

const char * scimesh::str_crop ( CropContentDirection  d)
inline

Definition at line 35 of file to_string.h.

◆ str_merge()

const char * scimesh::str_merge ( MergeDirection  d)
inline

Definition at line 25 of file to_string.h.

◆ str_projection()

const char * scimesh::str_projection ( ProjectionType  p)
inline

Definition at line 17 of file to_string.h.

◆ str_shading()

const char * scimesh::str_shading ( ShadingMode  s)
inline

Definition at line 21 of file to_string.h.

◆ transform_direction()

Vec3 scimesh::transform_direction ( const Mat4 m,
const Vec3 d 
)
inline

Transform a direction vector by a 4×4 matrix (with implicit w=0).

Direction vectors use w=0 so that translation does not affect them — only rotation and scale are applied. Use for transforming normals and light directions.

Parameters
mThe transformation matrix.
dThe input direction.
Returns
The transformed direction.
See also
transform_point()

Definition at line 90 of file math_utils.h.

◆ transform_mesh()

void scimesh::transform_mesh ( Mesh mesh,
const Mat4 matrix 
)

Apply an arbitrary 4×4 transformation matrix to a mesh.

Transforms all vertex positions by the matrix. This is the most general transform function — you can combine translation, rotation, and scale into a single matrix using GLM functions like glm::translate(), glm::rotate(), and glm::scale().

Parameters
[in,out]meshThe mesh to modify.
matrixA 4×4 transformation matrix (column-major, GLM style).
Example
Mat4 T = glm::translate(Mat4(1.0f), Vec3(1, 0, 0)); // translate +X
Mat4 R = glm::rotate(Mat4(1.0f), M_PI/2, Vec3(0,1,0)); // rotate 90° Y
Mat4 M = T * R; // combine: rotate, then translate
transform_mesh(mesh, M);
void transform_mesh(Mesh &mesh, const Mat4 &matrix)
Apply an arbitrary 4×4 transformation matrix to a mesh.
See also
translate_mesh(), rotate_mesh(), scale_mesh()

Definition at line 32 of file transforms.cpp.

◆ transform_point()

Vec3 scimesh::transform_point ( const Mat4 m,
const Vec3 p 
)
inline

Transform a point by a 4×4 matrix (with implicit w=1).

Equivalent to (M * vec4(p, 1)).xyz. Use for transforming positions.

Parameters
mThe transformation matrix.
pThe input point.
Returns
The transformed point.
See also
transform_direction(), transform_point_homogeneous()

Definition at line 60 of file math_utils.h.

◆ transform_point_homogeneous()

Vec4 scimesh::transform_point_homogeneous ( const Mat4 m,
const Vec3 p 
)
inline

Transform a point by a 4×4 matrix, returning the full Vec4 result.

Unlike transform_point(), this returns the homogeneous result (including the w component), which is needed for perspective division.

Parameters
mThe transformation matrix.
pThe input point.
Returns
The homogeneous transformed point (Vec4).
See also
transform_point(), perspective_divide()

Definition at line 75 of file math_utils.h.

◆ translate_mesh()

void scimesh::translate_mesh ( Mesh mesh,
const Vec3 translation 
)

Translate (move) a mesh by a displacement vector.

Adds translation to every vertex position.

Parameters
[in,out]meshThe mesh to modify.
translationThe displacement vector to add.
Example
translate_mesh(mesh, Vec3(0.0f, 5.0f, 0.0f)); // move 5 units up
void translate_mesh(Mesh &mesh, const Vec3 &translation)
Translate (move) a mesh by a displacement vector.
Definition transforms.cpp:7
See also
scale_mesh(), rotate_mesh(), transform_mesh()

Definition at line 7 of file transforms.cpp.

Variable Documentation

◆ DEFAULT_COLOR

constexpr Color scimesh::DEFAULT_COLOR {0.7f, 0.7f, 0.7f, 1.0f}
constexpr

The default mesh color: a neutral light gray (0.7, 0.7, 0.7).

Used when no explicit color is assigned to a mesh.

See also
Color, Mesh::default_color

Definition at line 144 of file types.h.

◆ TRANSPARENT_BLACK

constexpr Color scimesh::TRANSPARENT_BLACK {0.0f, 0.0f, 0.0f, 0.0f}
constexpr

A fully transparent black color (0, 0, 0, 0).

Convenience constant for transparent backgrounds or clearing.

See also
Color

Definition at line 150 of file types.h.

◆ WHITE

constexpr Color scimesh::WHITE {1.0f, 1.0f, 1.0f, 1.0f}
constexpr

An opaque white color (1, 1, 1, 1).

Convenience constant for backgrounds.

See also
Color

Definition at line 156 of file types.h.