v2.0.0
Loading...
Searching...
No Matches
brainsurface.h
Go to the documentation of this file.
1//=============================================================================================================
34
35#ifndef BRAINSURFACE_H
36#define BRAINSURFACE_H
37
38//=============================================================================================================
39// INCLUDES
40//=============================================================================================================
41
42#include "../disp3D_global.h"
43
44#include "../core/rendertypes.h"
45
46#include <QVector>
47#include <QVector3D>
48#include <QColor>
49#include <memory>
50#include <vector>
51#include <fs/fs_surface.h>
52#include <fs/fs_annotation.h>
53#include <mne/mne_bem.h>
54
55#include <Eigen/Core>
56
57// Forward-declare QRhi types so that this header stays QRhi-free
58class QRhi;
59class QRhiBuffer;
60class QRhiResourceUpdateBatch;
61
62//=============================================================================================================
63// STRUCTS
64//=============================================================================================================
65
69struct VertexData {
70 QVector3D pos;
71 QVector3D norm;
72 uint32_t color; // curvature / base / STC color (ABGR packed)
73 uint32_t colorAnnotation; // annotation region color (ABGR packed)
74 float surfaceId = 0.0f; // WORKAROUND(QRhi-GLES2): surface ID for merged
75 // single-drawIndexed on WASM. Always 0 for
76 // individual surfaces; set by merged path.
77};
78
79//=============================================================================================================
86{
87public:
88 //=========================================================================================================
93
94 //=========================================================================================================
99
100 // VisualizationMode is defined in core/rendertypes.h for lightweight inclusion.
101 // These aliases preserve backward compatibility.
107
111 TissueSkin = 2, // Head/Scalp surface
112 TissueOuterSkull = 3, // Outer skull bone
113 TissueInnerSkull = 4 // Inner skull bone
114 };
115
116 //=========================================================================================================
122 void setVisible(bool visible);
123
124 //=========================================================================================================
130 bool isVisible() const { return m_visible; }
131
132 //=========================================================================================================
138 void setHemi(int hemi) { m_hemi = hemi; }
139
140 //=========================================================================================================
146 void setTissueType(TissueType type) { m_tissueType = type; }
147
148 //=========================================================================================================
154 TissueType tissueType() const { return m_tissueType; }
155
156 //=========================================================================================================
162 int hemi() const { return m_hemi; }
163
164 //=========================================================================================================
170 void fromSurface(const FSLIB::FsSurface &surf);
171
172 //=========================================================================================================
179 void fromBemSurface(const MNELIB::MNEBemSurface &surf, const QColor &color = Qt::white);
180
181 //=========================================================================================================
189 void createFromData(const Eigen::MatrixX3f &vertices, const Eigen::MatrixX3i &triangles, const QColor &color);
190
191 //=========================================================================================================
200 void createFromData(const Eigen::MatrixX3f &vertices, const Eigen::MatrixX3f &normals, const Eigen::MatrixX3i &triangles, const QColor &color);
201
202 //=========================================================================================================
209 bool loadAnnotation(const QString &path);
210
211 //=========================================================================================================
217 void addAnnotation(const FSLIB::FsAnnotation &annotation);
218
219 //=========================================================================================================
225 void setVisualizationMode(VisualizationMode mode);
226
227 //=========================================================================================================
233 void applySourceEstimateColors(const QVector<uint32_t> &colors);
234
238 void clearSourceEstimateColors();
239
240 //=========================================================================================================
247 void updateBuffers(QRhi *rhi, QRhiResourceUpdateBatch *u);
248
249 QRhiBuffer* vertexBuffer() const;
250 QRhiBuffer* indexBuffer() const;
251 uint32_t indexCount() const { return m_indexCount; }
252 uint32_t vertexCount() const { return m_vertexData.size(); }
253
254 //=========================================================================================================
258 Eigen::MatrixX3f vertexPositions() const;
259
260 //=========================================================================================================
264 Eigen::MatrixX3f vertexNormals() const;
265
266 //=========================================================================================================
270 QVector<uint32_t> triangleIndices() const { return m_indexData; }
271
273 const QVector<VertexData>& vertexDataRef() const { return m_vertexData; }
275 const QVector<uint32_t>& indexDataRef() const { return m_indexData; }
276
278 quint64 vertexGeneration() const { return m_vertexGeneration; }
279
280 //=========================================================================================================
286 float minX() const;
287
288 //=========================================================================================================
294 float maxX() const;
295
296 //=========================================================================================================
303 void boundingBox(QVector3D &min, QVector3D &max) const;
304
305 //=========================================================================================================
317 bool intersects(const QVector3D &rayOrigin, const QVector3D &rayDir, float &dist, int &vertexIdx) const;
318
319 //=========================================================================================================
326 QString getAnnotationLabel(int vertexIdx) const;
327 int getAnnotationLabelId(int vertexIdx) const;
328
329 //=========================================================================================================
335 void setSelectedRegion(int regionId);
341 void translateX(float offset);
342
343 //=========================================================================================================
349 void transform(const QMatrix4x4 &m);
350
351 //=========================================================================================================
358 void applyTransform(const QMatrix4x4 &m);
359
360 //=========================================================================================================
367 std::vector<Eigen::VectorXi> computeNeighbors() const;
368
369 //=========================================================================================================
375 Eigen::MatrixX3f verticesAsMatrix() const;
376
377 //=========================================================================================================
381 void setUseDefaultColor(bool useDefault);
382
383 void setSelected(bool selected);
384 bool isSelected() const { return m_selected; }
385 int selectedRegionId() const { return m_selectedRegionId; }
386 int selectedVertexStart() const { return m_selectedVertexStart; }
387
395 void setSelectedVertexRange(int start, int count);
396
397private:
398 void updateVertexColors();
399 void markVertexDirty();
400
401 QVector<VertexData> m_vertexData;
402 QVector<VertexData> m_originalVertexData;
403 QVector<uint32_t> m_indexData;
404 uint32_t m_indexCount = 0;
405
406 QColor m_defaultColor = Qt::white;
407 QColor m_baseColor = Qt::white;
408
409 FSLIB::FsAnnotation m_annotation;
410 bool m_hasAnnotation = false;
411 VisualizationMode m_visMode = ModeSurface;
412 QVector<float> m_curvature;
413 QVector<uint32_t> m_stcColors;
414
415 bool m_visible = true;
416 bool m_selected = false;
417 int m_selectedRegionId = -1;
418 int m_selectedVertexStart = -1;
419 int m_selectedVertexCount = 0;
420 int m_hemi = -1; // 0=lh, 1=rh
421 TissueType m_tissueType = TissueUnknown;
422
424 struct GpuBuffers;
425 std::unique_ptr<GpuBuffers> m_gpu;
426
427 quint64 m_vertexGeneration = 0;
428
429 mutable QVector3D m_aabbMin;
430 mutable QVector3D m_aabbMax;
431 mutable bool m_bAABBDirty = true;
432};
433
434#endif // BRAINSURFACE_H
Lightweight render-related enums shared across the disp3D library.
VisualizationMode
Definition rendertypes.h:90
@ ModeSurface
Definition rendertypes.h:91
disp3D library export/import macros.
#define DISP3DSHARED_EXPORT
FsSurface class declaration.
FsAnnotation class declaration.
MNEBem class declaration.
Interleaved vertex attributes (position, normal, color, curvature) for brain surface GPU upload.
uint32_t colorAnnotation
QVector3D norm
QVector3D pos
uint32_t color
float surfaceId
uint32_t indexCount() const
const QVector< VertexData > & vertexDataRef() const
Const-ref access to CPU-side vertex data (used by merged rendering).
void setHemi(int hemi)
TissueType tissueType() const
static constexpr VisualizationMode ModeAnnotation
static constexpr VisualizationMode ModeScientific
int selectedVertexStart() const
::VisualizationMode VisualizationMode
bool isSelected() const
static constexpr VisualizationMode ModeSourceEstimate
quint64 vertexGeneration() const
Monotonically increasing counter bumped whenever vertex data changes.
QVector< uint32_t > triangleIndices() const
uint32_t vertexCount() const
int hemi() const
const QVector< uint32_t > & indexDataRef() const
Const-ref access to CPU-side index data (used by merged rendering).
int selectedRegionId() const
void setTissueType(TissueType type)
bool isVisible() const
static constexpr VisualizationMode ModeSurface
Free surfer annotation.
FreeSurfer surface mesh.
Definition fs_surface.h:83
BEM surface provides geometry information.