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

A batch of independent line segments drawn with a fixed screen-space width. More...

#include <lines.h>

Public Member Functions

bool compute_bounding_box (Vec3 &min_bound, Vec3 &max_bound) const
 Compute the bounding box of all segment endpoints.
 
size_t size () const
 Number of segments in this layer.
 
bool empty () const
 Whether this layer holds no segments to draw.
 
Color color_or (size_t i, const Color &fallback) const
 Color of segment i, falling back to fallback when the layer holds no colors at all.
 

Public Attributes

std::vector< Vec3 > from
 Segment start points, in world space.
 
std::vector< Vec3 > to
 Segment end points, in world space (one per entry in from).
 
std::vector< Color > colors
 One color per segment; may be empty (then the renderer uses RenderOptions::default_color) or shorter than from (the last entry is reused for the remaining segments).
 
float width = 1.0f
 Line width in screen pixels (default: 1.0).
 
bool depth_test = true
 Whether to test the lines against the depth buffer (default: true).
 
bool lit = false
 Whether to apply lighting to the lines (default: false).
 
bool affects_bounds = true
 Whether this layer contributes to the bounding box of its scene (default: true).
 

Detailed Description

A batch of independent line segments drawn with a fixed screen-space width.

A line layer belongs to a Scene (see Scene::add_lines()) and is drawn by the Renderer in the same pass as the meshes: same camera, same depth buffer, so lines can be occluded by meshes and vice versa. Segments whose colors have an alpha value below 1 are drawn in the blended pass, back-to-front, exactly like translucent triangles.

Line layers are deliberately not meshes:

  • They contribute to the bounding box of their scene (see LineLayer::affects_bounds), which is what makes a scene that consists only of lines renderable, but a layer can opt out of it when it is decoration rather than content, e.g. a leader line to a label or an axis cross.
  • The mesh exporters (write_gltf(), write_stl(), ...) skip them.
Example
LineLayer layer;
layer.from = {{0,0,0}, {1,0,0}};
layer.to = {{0,1,0}, {1,1,0}};
layer.colors = {Color(1,0,0), Color(0,0,1)};
layer.width = 2.0f;
scene.add_lines(layer);
A batch of independent line segments drawn with a fixed screen-space width.
Definition lines.h:49
std::vector< Vec3 > from
Segment start points, in world space.
Definition lines.h:51
float width
Line width in screen pixels (default: 1.0).
Definition lines.h:66
std::vector< Color > colors
One color per segment; may be empty (then the renderer uses RenderOptions::default_color) or shorter ...
Definition lines.h:59
std::vector< Vec3 > to
Segment end points, in world space (one per entry in from).
Definition lines.h:54
int x
Left edge of the bitmap, in image pixels.
Definition text.cpp:223
See also
Scene::add_lines(), Rasterizer::rasterize_line()

Definition at line 49 of file lines.h.

Member Function Documentation

◆ color_or()

Color scimesh::LineLayer::color_or ( size_t  i,
const Color &  fallback 
) const
inline

Color of segment i, falling back to fallback when the layer holds no colors at all.

Definition at line 139 of file lines.h.

◆ compute_bounding_box()

bool scimesh::LineLayer::compute_bounding_box ( Vec3 &  min_bound,
Vec3 &  max_bound 
) const
inline

Compute the bounding box of all segment endpoints.

Both the from and the to points are considered, the width of the segments is a screen-space property and does not affect the box.

Parameters
[out]min_boundLower corner of the box (unchanged when empty).
[out]max_boundUpper corner of the box (unchanged when empty).
Returns
true if the layer contains at least one point, false otherwise.
See also
Scene::compute_bounding_box()

Definition at line 109 of file lines.h.

◆ empty()

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

Whether this layer holds no segments to draw.

Definition at line 135 of file lines.h.

◆ size()

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

Number of segments in this layer.

The from and to arrays are expected to have the same length; if they differ, the shorter one limits the number of drawn segments.

Definition at line 132 of file lines.h.

Member Data Documentation

◆ affects_bounds

bool scimesh::LineLayer::affects_bounds = true

Whether this layer contributes to the bounding box of its scene (default: true).

Line layers usually are the content of a figure (graph or connectome edges, streamlines, tracts), so they define the extent that the camera has to cover, exactly like the meshes of the scene do. Set this to false for a layer that is decoration, e.g. a leader line pointing at a label outside the anatomy, or an axis cross: such a layer is then ignored by Scene::compute_bounding_box() and can never push the camera away from the data.

Note that a scene without any mesh is framed by its line layers even if they all opted out, because there would otherwise be no geometry to derive a camera from, see Scene::compute_bounding_box().

See also
Scene::set_line_affects_bounds()

Definition at line 97 of file lines.h.

◆ colors

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

One color per segment; may be empty (then the renderer uses RenderOptions::default_color) or shorter than from (the last entry is reused for the remaining segments).

Definition at line 59 of file lines.h.

◆ depth_test

bool scimesh::LineLayer::depth_test = true

Whether to test the lines against the depth buffer (default: true).

Set to false to draw the lines on top of everything (e.g. annotation overlays), which is only useful together with an opaque color.

Definition at line 72 of file lines.h.

◆ from

std::vector<Vec3> scimesh::LineLayer::from

Segment start points, in world space.

Definition at line 51 of file lines.h.

◆ lit

bool scimesh::LineLayer::lit = false

Whether to apply lighting to the lines (default: false).

Lines are flat by default, like hardware-rendered lines. When set to true, the shading uses a fixed surface normal of (0, 0, 1) in view space, which is rarely what you want for thin lines.

Definition at line 79 of file lines.h.

◆ to

std::vector<Vec3> scimesh::LineLayer::to

Segment end points, in world space (one per entry in from).

Definition at line 54 of file lines.h.

◆ width

float scimesh::LineLayer::width = 1.0f

Line width in screen pixels (default: 1.0).

The value is interpreted in output pixels; the renderer scales it by the supersampling factor internally. A width of 1.0 draws a single-pixel line, values below 0.5 are treated as 0.5 to keep the line visible.

Definition at line 66 of file lines.h.


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