|
scimesh 0.3.2
Headless CPU-only 3D software renderer for scientific mesh visualization
|
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 ¢er, 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 ¢er, 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 > ¢ers, 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 ¢er, 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 ¢er, 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 ¢er, 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 ¢er, 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 ¢er, 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). | |
| 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.
| using scimesh::Vec2 = typedef glm::vec2 |
| 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.
| using scimesh::Vec4 = typedef glm::vec4 |
|
strong |
Direction(s) for the crop_to_content() operation.
Specifies which edges to crop. You can crop individual edges or combinations.
|
strong |
Strategy for normalizing images to a common cell size in grid_arrange().
| Enumerator | |
|---|---|
| PAD | Pad smaller images with background color (content stays pixel-perfect). |
| SCALE | Scale all images to match the largest cell dimensions. |
|
strong |
Direction for the merge() operation.
Controls which side of the base image the other image is attached to.
| Enumerator | |
|---|---|
| LEFT | Attach |
| RIGHT | Attach |
| TOP | Attach |
| BOTTOM | Attach |
|
strong |
The type of 3D→2D projection used by the camera.
|
strong |
How surface normals are interpolated across triangles.
| 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.
| 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.
| data | Per-vertex (or per-element) numeric values. NaN / Inf allowed — they will be mapped to nan_color. |
| colormap | The colour lookup table to sample from. |
| vmin | Lower bound of the data range. NAN = auto-detect from finite values (after winsorizing, if applicable). |
| vmax | Upper bound of the data range. NAN = auto-detect. |
| nan_color | RGBA colour for NaN / Inf positions. |
| lo_pct | Lower percentile for winsorizing (0.0 = off). E.g., 2.0 → clip values below the 2nd percentile. |
| hi_pct | Upper percentile for winsorizing (100.0 = off). E.g., 98.0 → clip values above the 98th percentile. |
ApplyColormapResult with the mapped colours and metadata.Definition at line 345 of file colormap.cpp.
| 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.
| datasets | One or more per-vertex (or per-element) data vectors. |
| colormap | The colour lookup table. |
| vmin | Lower bound. NAN = auto-detect. |
| vmax | Upper bound. NAN = auto-detect. |
| nan_color | RGBA colour for NaN / Inf positions. |
| lo_pct | Lower percentile for winsorizing (0.0 = off). |
| hi_pct | Upper percentile for winsorizing (100.0 = off). |
| global_range | If 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). |
MultiApplyColormapResult with per-dataset colours and pooled metadata.Definition at line 397 of file colormap.cpp.
| 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.
| mesh | The mesh to frame. |
| direction | View direction. |
| up | Up vector. |
| fov_degrees | Field of view in degrees. |
| margin | Extra zoom margin. |
| projection | Projection type. |
Definition at line 75 of file camera.cpp.
| 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.
| scene | The scene to frame. |
| direction | View direction (e.g., {0,0,1} for front view). |
| up | Up vector (e.g., {0,1,0}). |
| fov_degrees | Field of view in degrees. |
| margin | Extra zoom margin (default 1.1 = 10% padding). |
| projection | Projection type (default: PERSPECTIVE). |
Definition at line 58 of file camera.cpp.
| 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.
| center | The point to look at (becomes Camera::center). |
| radius | The radius of a bounding sphere around the subject. |
| direction | View direction vector (e.g., {0,0,1} for front view). |
| up | Up vector (usually {0,1,0}). |
| fov_degrees | Vertical field of view in degrees. |
| margin | Extra margin factor (>1.0 = zoomed out, <1.0 = tighter). Default 1.1 gives 10% padding. |
| projection | Projection type (default: PERSPECTIVE). |
Definition at line 38 of file camera.cpp.
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.
| camera | The camera to orbit (modified copy returned). |
| axis | Rotation axis (should pass through camera.center). |
| angle_degrees | Rotation angle in degrees. |
Definition at line 92 of file camera.cpp.
| 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.
| v0,v1,v2 | Three vertices of the input triangle (in homogeneous clip space). | |
| [out] | output_vertices | Clipped vertices are appended here. |
| [out] | output_triangles | Resulting triangle indices (0, 1, or 2 triangles) are appended here. |
Definition at line 67 of file clipping.cpp.
| 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.
| v0,v1,v2 | Triangle vertex positions in view space. | |
| n0,n1,n2 | Per-vertex normals (view space). | |
| c0,c1,c2 | Per-vertex colors. | |
| uv0,uv1,uv2 | Per-vertex texture coordinates. | |
| plane | The clipping plane. | |
| [out] | output_vertices | Clipped vertices (positions are in view space — caller must transform to clip space). |
| [out] | output_triangles | Resulting triangle indices. |
Definition at line 162 of file clipping.cpp.
|
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[0, 1] if and only if the point is inside the triangle.| px,py | The query point (2D screen coords). | |
| x0,y0,x1,y1,x2,y2 | Triangle vertices (2D screen coords). | |
| [out] | u,v,w | Output barycentric weights. |
Definition at line 158 of file math_utils.h.
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.
| v0,v1,v2 | The three triangle vertex positions. |
Definition at line 37 of file math_utils.h.
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.
| [in] | mesh | The input mesh (only vertices and triangles are read). |
| [out] | normals | Output array — will be resized to mesh.vertices.size() and filled with unit-length normal vectors. |
mesh.has_normals() returns false, call this function to compute them before rendering with ShadingMode::SMOOTH.Definition at line 5 of file normals.cpp.
|
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.
| fs_mesh | The FreeSurfer mesh to convert. |
Definition at line 37 of file fs_mesh_converter.h.
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.
| fs_mesh | The FreeSurfer mesh to convert. |
| solid_color | The uniform color to assign to all vertices. |
Definition at line 74 of file fs_mesh_converter.h.
|
inline |
Convert a FreeSurfer mesh with per-vertex morphological data and RGB coloring.
This is the most feature-rich converter. Each vertex gets:
rgb_colors (3 bytes per vertex).morph_data[i] is NaN, the vertex is colored white (often used to mark the medial wall or "unknown" regions in brain surface data).| fs_mesh | The FreeSurfer mesh to convert. |
| morph_data | Per-vertex scalar values (NaN = mark as white). |
| rgb_colors | Flat array of RGB bytes (size = 3 × vertex count). |
Definition at line 137 of file fs_mesh_converter.h.
|
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).
| fs_mesh | The FreeSurfer mesh to convert. |
| rgb_colors | Flat array of RGB bytes (size = 3 × vertex count). |
Definition at line 100 of file fs_mesh_converter.h.
|
inline |
Definition at line 48 of file to_string.h.
|
inline |
Definition at line 62 of file to_string.h.
| 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.
| from | Starting point (tail of the arrow). |
| to | Ending point (tip of the arrowhead). |
| shaft_radius | Radius of the cylindrical shaft. |
| head_radius | Radius of the cone base (arrowhead width). |
| head_length | Length of the arrowhead along the arrow direction. |
| segments | Number of sides around the circumference. |
| color | Uniform color. |
Definition at line 268 of file primitives.cpp.
| 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.
| base | Center of the circular base. |
| tip | The apex (pointy end) of the cone. |
| radius | Radius of the base. |
| segments | Number of sides (≥ 3). |
| color | Uniform color. |
Definition at line 192 of file primitives.cpp.
| 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).
| center | Center of the box. |
| half_extents | Half-width, half-height, half-depth (all positive). |
| color | Uniform color. |
Definition at line 332 of file primitives.cpp.
| 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.
| start | Starting point (center of bottom cap). |
| end | Ending point (center of top cap). |
| radius | Radius of the cylinder. |
| segments | Number of sides around the circumference (≥ 3). |
| color | Uniform color. |
Definition at line 95 of file primitives.cpp.
| 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.
| starts | Array of start points. |
| ends | Array of end points (same length as starts). |
| radii | Array of radii (same length). |
| colors | Array of colors (same length). |
| segments | Subdivisions per cylinder (default: 12). |
Definition at line 316 of file primitives.cpp.
| 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.
| centers | Array of center points. |
| radii | Array of radii (same length as centers). |
| colors | Array of colors (same length as centers). |
| segments | Subdivisions per sphere (default: 16). |
Definition at line 301 of file primitives.cpp.
| 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.
| center | Center point of the plane. |
| normal | Surface normal (direction the plane faces). |
| half_size_x | Half the width in the local X direction. |
| half_size_y | Half the height in the local Y direction. |
| color | Uniform color. |
Definition at line 561 of file primitives.cpp.
| 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.
| base_center | Center of the square base. |
| apex | The top point (tip) of the pyramid. |
| half_width | Half the side length of the square base. |
| color | Uniform color. |
Definition at line 395 of file primitives.cpp.
| 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.
| center | Center point of the sphere. |
| radius | Radius (half the diameter). |
| segments | Number of subdivisions (≥ 3). Typical: 16 (low-poly) to 64 (smooth). The sphere has segments * segments * 2 triangles. |
| color | Uniform color for all vertices. |
Definition at line 20 of file primitives.cpp.
| 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.
| p0,p1,p2,p3 | The four corner points. |
| color | Uniform color. |
Definition at line 458 of file primitives.cpp.
| 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.
| center | Center of the torus. |
| major_radius | Distance from hole center to tube center. |
| minor_radius | Radius of the tube cross-section. |
| major_segments | Subdivisions around the ring (≥ 4). |
| minor_segments | Subdivisions around the tube (≥ 4). |
| color | Uniform color. |
Definition at line 504 of file primitives.cpp.
| 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.
| images | The list of images to arrange. |
| ncol | Number of columns (0 = auto-compute from nrow). |
| nrow | Number of rows (0 = auto-compute from ncol). If both are 0, a square-ish layout is chosen. |
| fit_mode | How to handle size mismatches (PAD or SCALE). |
| background | Fill color for padding and empty cells. |
|
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.
| bmin | Minimum corner of the AABB. |
| bmax | Maximum corner of the AABB. |
| center | The center point the camera looks at. |
| dir | The view direction. |
center.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.
| [in,out] | dst | The destination mesh (modified in-place). |
| src | The source mesh (not modified). |
Definition at line 288 of file primitives.cpp.
| 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.
| fs_vertices | Flat array of vertex coordinates (x0,y0,z0, x1,y1,z1, ...). |
| fs_faces | Flat array of face indices (v0,v1,v2, v0,v1,v2, ...). |
| per_vertex_values | Optional scalar per-vertex values for coloring. |
| rgb_bytes | Optional RGB color bytes (3 per vertex: r,g,b, ...). |
| detect_transparency | If true, check for NaN values indicating transparent regions (common in brain surface data). |
Definition at line 38 of file transforms.cpp.
|
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.
| ndc | Input NDC coordinates. | |
| width | Screen width in pixels. | |
| height | Screen height in pixels. | |
| [out] | screen_x | Output X pixel coordinate. |
| [out] | screen_y | Output Y pixel coordinate (0 = top). |
| [out] | depth | Output depth value (passed through from NDC z). |
Definition at line 125 of file math_utils.h.
|
inline |
Definition at line 117 of file to_string.h.
|
inline |
Definition at line 112 of file to_string.h.
|
inline |
Definition at line 78 of file to_string.h.
|
inline |
Definition at line 156 of file to_string.h.
|
inline |
Definition at line 105 of file to_string.h.
|
inline |
Definition at line 127 of file to_string.h.
|
inline |
Definition at line 163 of file to_string.h.
|
inline |
Definition at line 145 of file to_string.h.
|
inline |
Definition at line 88 of file to_string.h.
|
inline |
Definition at line 83 of file to_string.h.
|
inline |
Definition at line 98 of file to_string.h.
|
inline |
Definition at line 93 of file to_string.h.
|
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.
| bmin | Minimum corner of the AABB. | |
| bmax | Maximum corner of the AABB. | |
| center | The center point the camera looks at. | |
| dir | The view direction (forward vector). | |
| fov_radians | Vertical FOV in radians. | |
| [out] | out_dist | Optional: receives the computed camera distance. |
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.
| clip | A point in homogeneous clip space. |
Definition at line 105 of file math_utils.h.
Rotate a mesh around an arbitrary axis.
Uses the right-hand rule: positive angle = counter-clockwise when looking along the axis toward the origin.
| [in,out] | mesh | The mesh to modify. |
| angle_radians | Rotation angle in radians. | |
| axis | Rotation axis (does not need to be normalized). |
Definition at line 25 of file transforms.cpp.
Scale a mesh non-uniformly along each axis.
Multiplies each vertex position component-wise by scale.
| [in,out] | mesh | The mesh to modify. |
| scale | Scale factors per axis (e.g., {2,1,1} doubles width). |
Definition at line 14 of file transforms.cpp.
| void scimesh::scale_mesh | ( | Mesh & | mesh, |
| float | uniform_scale | ||
| ) |
Scale a mesh uniformly in all directions.
Multiplies every vertex position by uniform_scale.
| [in,out] | mesh | The mesh to modify. |
| uniform_scale | Scale factor (1.0 = unchanged, 2.0 = double size). |
Definition at line 21 of file transforms.cpp.
|
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.
| base_color | The surface (unlit) color. |
| normal | Surface normal at this pixel (should be unit-length). |
| light_direction | Direction TO the light (should be unit-length). |
| specular_color | Specular highlight color (transparent = no specular). |
| shininess | Shininess exponent (higher = sharper highlights). |
Definition at line 191 of file math_utils.h.
|
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.
| base_color | The surface (unlit) color. |
| normal | Surface normal (unit-length). |
| lights | Array of light sources. |
| ambient | Ambient light level (0.0–1.0). |
| specular_color | Specular highlight color. |
| shininess | Shininess exponent. |
Definition at line 231 of file math_utils.h.
|
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, ...).
| images | The list of images to arrange left-to-right. |
| fit_mode | How to handle size mismatches (PAD or SCALE). |
| background | Fill color for padding. |
|
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(), ...).
| images | The list of images to arrange top-to-bottom. |
| fit_mode | How to handle size mismatches (PAD or SCALE). |
| background | Fill color for padding. |
|
inline |
Definition at line 35 of file to_string.h.
|
inline |
Definition at line 25 of file to_string.h.
|
inline |
Definition at line 17 of file to_string.h.
|
inline |
Definition at line 21 of file to_string.h.
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.
| m | The transformation matrix. |
| d | The input direction. |
Definition at line 90 of file math_utils.h.
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().
| [in,out] | mesh | The mesh to modify. |
| matrix | A 4×4 transformation matrix (column-major, GLM style). |
Definition at line 32 of file transforms.cpp.
Transform a point by a 4×4 matrix (with implicit w=1).
Equivalent to (M * vec4(p, 1)).xyz. Use for transforming positions.
| m | The transformation matrix. |
| p | The input point. |
Definition at line 60 of file math_utils.h.
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.
| m | The transformation matrix. |
| p | The input point. |
Definition at line 75 of file math_utils.h.
Translate (move) a mesh by a displacement vector.
Adds translation to every vertex position.
| [in,out] | mesh | The mesh to modify. |
| translation | The displacement vector to add. |
Definition at line 7 of file transforms.cpp.
|
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.
|
constexpr |