scimesh 0.3.2
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
17namespace scimesh {
18
37inline 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
74inline 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 return out;
82}
83
100inline Mesh convert_fs_mesh(const fs::Mesh &fs_mesh,
101 const std::vector<uint8_t> &rgb_colors) {
102 Mesh out = convert_fs_mesh(fs_mesh);
103 size_t nv = out.vertices.size();
104 out.colors.reserve(nv);
105 for (size_t i = 0; i < nv; i++) {
106 out.colors.push_back(Color(
107 rgb_colors[i * 3] / 255.0f,
108 rgb_colors[i * 3 + 1] / 255.0f,
109 rgb_colors[i * 3 + 2] / 255.0f,
110 1.0f));
111 }
112 return out;
113}
114
137inline Mesh convert_fs_mesh(const fs::Mesh &fs_mesh,
138 const std::vector<float> &morph_data,
139 const std::vector<uint8_t> &rgb_colors) {
140 Mesh out = convert_fs_mesh(fs_mesh);
141 size_t nv = out.vertices.size();
142 out.colors.reserve(nv);
143 for (size_t i = 0; i < nv; i++) {
144 if (std::isnan(morph_data[i])) {
145 out.colors.push_back(Color(1.0f, 1.0f, 1.0f, 1.0f));
146 } else {
147 out.colors.push_back(Color(
148 rgb_colors[i * 3] / 255.0f,
149 rgb_colors[i * 3 + 1] / 255.0f,
150 rgb_colors[i * 3 + 2] / 255.0f,
151 1.0f));
152 }
153 }
154 return out;
155}
156
157} // namespace scimesh
The Mesh — the central data structure for 3D geometry in scimesh.
Mesh convert_fs_mesh(const fs::Mesh &fs_mesh)
Convert a FreeSurfer mesh to a scimesh Mesh (no colors).
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 3D triangle mesh using an indexed face set representation.
Definition mesh.h:76
std::vector< Color > colors
Per-vertex RGBA colors.
Definition mesh.h:107
std::vector< Vec3 > vertices
3D vertex positions.
Definition mesh.h:86
std::vector< Triangle > triangles
Triangle index triplets.
Definition mesh.h:94
A triangle defined by three vertex indices.
Definition types.h:127