scimesh
0.3.4
Headless CPU-only 3D software renderer for scientific mesh visualization
Loading...
Searching...
No Matches
fs_mesh_converter.h
Go to the documentation of this file.
1
8
9
#pragma once
10
11
#include <
scimesh/mesh.h
>
12
#include "libfs.h"
13
14
#include <vector>
15
#include <cmath>
16
17
namespace
scimesh
{
18
37
inline
Mesh
convert_fs_mesh
(
const
fs::Mesh &
fs_mesh
) {
38
Mesh
out
;
39
size_t
nv
=
fs_mesh
.num_vertices();
40
out
.
vertices
.reserve(
nv
);
41
for
(
size_t
i
= 0;
i
<
nv
;
i
++) {
42
out
.vertices.push_back(
Vec3
(
43
fs_mesh
.vertices[
i
* 3],
44
fs_mesh
.vertices[
i
* 3 + 1],
45
fs_mesh
.vertices[
i
* 3 + 2]));
46
}
47
size_t
nf
=
fs_mesh
.num_faces();
48
out
.triangles.reserve(
nf
);
49
for
(
size_t
i
= 0;
i
<
nf
;
i
++) {
50
out
.triangles.push_back(
Triangle
{
51
static_cast<
uint32_t
>
(
fs_mesh
.faces[
i
* 3]),
52
static_cast<
uint32_t
>
(
fs_mesh
.faces[
i
* 3 + 1]),
53
static_cast<
uint32_t
>
(
fs_mesh
.faces[
i
* 3 + 2])});
54
}
55
return
out
;
56
}
57
74
inline
Mesh
convert_fs_mesh
(
const
fs::Mesh &
fs_mesh
,
const
Color
&
solid_color
) {
75
Mesh
out
=
convert_fs_mesh
(
fs_mesh
);
76
size_t
nv
=
out
.vertices.size();
77
out
.colors.reserve(
nv
);
78
for
(
size_t
i
= 0;
i
<
nv
;
i
++) {
79
out
.colors.push_back(
solid_color
);
80
}
81
out
.update_transparency();
82
return
out
;
83
}
84
101
inline
Mesh
convert_fs_mesh
(
const
fs::Mesh &
fs_mesh
,
102
const
std::vector<uint8_t> &
rgb_colors
) {
103
Mesh
out
=
convert_fs_mesh
(
fs_mesh
);
104
size_t
nv
=
out
.vertices.size();
105
out
.colors.reserve(
nv
);
106
for
(
size_t
i
= 0;
i
<
nv
;
i
++) {
107
out
.colors.push_back(
Color
(
108
rgb_colors
[
i
* 3] / 255.0f,
109
rgb_colors
[
i
* 3 + 1] / 255.0f,
110
rgb_colors
[
i
* 3 + 2] / 255.0f,
111
1.0f));
112
}
113
out
.update_transparency();
114
return
out
;
115
}
116
148
inline
Mesh
convert_fs_mesh
(
const
fs::Mesh &
fs_mesh
,
149
const
std::vector<float> &
morph_data
,
150
const
std::vector<uint8_t> &
rgb_colors
,
151
float
nan_alpha
= 1.0f) {
152
Mesh
out
=
convert_fs_mesh
(
fs_mesh
);
153
size_t
nv
=
out
.vertices.size();
154
out
.colors.reserve(
nv
);
155
for
(
size_t
i
= 0;
i
<
nv
;
i
++) {
156
if
(std::isnan(
morph_data
[
i
])) {
157
out
.colors.push_back(
Color
(1.0f, 1.0f, 1.0f,
nan_alpha
));
158
}
else
{
159
out
.colors.push_back(
Color
(
160
rgb_colors
[
i
* 3] / 255.0f,
161
rgb_colors
[
i
* 3 + 1] / 255.0f,
162
rgb_colors
[
i
* 3 + 2] / 255.0f,
163
1.0f));
164
}
165
}
166
out
.update_transparency();
167
return
out
;
168
}
169
170
}
// namespace scimesh
mesh.h
The Mesh — the central data structure for 3D geometry in scimesh.
scimesh
Definition
camera.cpp:8
scimesh::convert_fs_mesh
Mesh convert_fs_mesh(const fs::Mesh &fs_mesh)
Convert a FreeSurfer mesh to a scimesh Mesh (no colors).
Definition
fs_mesh_converter.h:37
scimesh::Vec3
glm::vec3 Vec3
3-component floating-point vector (xyz).
Definition
types.h:46
scimesh::Color
An RGBA color with floating-point components.
Definition
types.h:88
scimesh::Mesh
A 3D triangle mesh using an indexed face set representation.
Definition
mesh.h:76
scimesh::Mesh::vertices
std::vector< Vec3 > vertices
3D vertex positions.
Definition
mesh.h:86
scimesh::Triangle
A triangle defined by three vertex indices.
Definition
types.h:127
x
int x
Left edge of the bitmap, in image pixels.
Definition
text.cpp:223
src
core
scimesh
fs_mesh_converter.h
Generated by
1.9.8