scimesh 0.3.4
Headless CPU-only 3D software renderer for scientific mesh visualization
Loading...
Searching...
No Matches
lines.h
Go to the documentation of this file.
1
11
12#pragma once
13
14#include <scimesh/types.h>
15
16#include <algorithm>
17#include <vector>
18
19namespace scimesh {
20
49struct LineLayer {
51 std::vector<Vec3> from;
52
54 std::vector<Vec3> to;
55
59 std::vector<Color> colors;
60
66 float width = 1.0f;
67
72 bool depth_test = true;
73
79 bool lit = false;
80
97 bool affects_bounds = true;
98
110 bool first = true;
111 auto add = [&](const Vec3 &p) {
112 if (first) {
113 min_bound = p;
114 max_bound = p;
115 first = false;
116 } else {
117 min_bound = glm::min(min_bound, p);
118 max_bound = glm::max(max_bound, p);
119 }
120 };
121 for (const Vec3 &p : from)
122 add(p);
123 for (const Vec3 &p : to)
124 add(p);
125 return !first;
126 }
127
132 size_t size() const { return std::min(from.size(), to.size()); }
133
135 bool empty() const { return size() == 0; }
136
139 Color color_or(size_t i, const Color &fallback) const {
140 if (colors.empty()) {
141 return fallback;
142 }
143 return (i < colors.size()) ? colors[i] : colors.back();
144 }
145};
146
154 const LineLayer *layer = nullptr;
156 std::string name;
157};
158
159} // namespace scimesh
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
An RGBA color with floating-point components.
Definition types.h:88
A batch of independent line segments drawn with a fixed screen-space width.
Definition lines.h:49
size_t size() const
Number of segments in this layer.
Definition lines.h:132
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
bool lit
Whether to apply lighting to the lines (default: false).
Definition lines.h:79
bool depth_test
Whether to test the lines against the depth buffer (default: true).
Definition lines.h:72
bool affects_bounds
Whether this layer contributes to the bounding box of its scene (default: true).
Definition lines.h:97
bool compute_bounding_box(Vec3 &min_bound, Vec3 &max_bound) const
Compute the bounding box of all segment endpoints.
Definition lines.h:109
bool empty() const
Whether this layer holds no segments to draw.
Definition lines.h:135
std::vector< Color > colors
One color per segment; may be empty (then the renderer uses RenderOptions::default_color) or shorter ...
Definition lines.h:59
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.
Definition lines.h:139
std::vector< Vec3 > to
Segment end points, in world space (one per entry in from).
Definition lines.h:54
A non-owning reference to one line layer in a scene, together with its placement transform (and optio...
Definition lines.h:153
const LineLayer * layer
Pointer to the owned layer (never null for a valid node).
Definition lines.h:154
std::string name
Optional node name (used by exporters / debugging).
Definition lines.h:156
Mat4 transform
Model matrix placing the lines in world space.
Definition lines.h:155
int x
Left edge of the bitmap, in image pixels.
Definition text.cpp:223
Fundamental types used throughout the scimesh rendering engine.