v2.0.0
Loading...
Searching...
No Matches
brainsurface.h
Go to the documentation of this file.
1//=============================================================================================================
31
32#ifndef BRAINSURFACE_H
33#define BRAINSURFACE_H
34
35//=============================================================================================================
36// INCLUDES
37//=============================================================================================================
38
39#include "../disp3D_global.h"
40
41#include "../core/rendertypes.h"
42
43#include <QVector>
44#include <QVector3D>
45#include <QColor>
46#include <memory>
47#include <vector>
48#include <fs/fs_surface.h>
49#include <fs/fs_annotation.h>
50#include <mne/mne_bem.h>
51
52#include <Eigen/Core>
53
54// Forward-declare QRhi types so that this header stays QRhi-free
55class QRhi;
56class QRhiBuffer;
57class QRhiResourceUpdateBatch;
58
59//=============================================================================================================
60// STRUCTS
61//=============================================================================================================
62
63namespace DISP3DLIB
64{
65
72{
73 QVector3D pos;
74 QVector3D norm;
75 uint32_t color; // curvature / base / STC color (ABGR packed)
76 uint32_t colorAnnotation; // annotation region color (ABGR packed)
77 float surfaceId = 0.0f; // WORKAROUND(QRhi-GLES2): surface ID for merged
78 // single-drawIndexed on WASM. Always 0 for
79 // individual surfaces; set by merged path.
80};
81
82//=============================================================================================================
91{
92public:
93 //=========================================================================================================
98
99 //=========================================================================================================
104
105 // VisualizationMode is defined in core/rendertypes.h for lightweight inclusion.
106 // These aliases preserve backward compatibility.
112
114 {
117 TissueSkin = 2, // Head/Scalp surface
118 TissueOuterSkull = 3, // Outer skull bone
119 TissueInnerSkull = 4 // Inner skull bone
120 };
121
122 //=========================================================================================================
128 void setVisible(bool visible);
129
130 //=========================================================================================================
136 bool isVisible() const
137 {
138 return m_visible;
139 }
140
141 //=========================================================================================================
147 void setHemi(int hemi)
148 {
149 m_hemi = hemi;
150 }
151
152 //=========================================================================================================
159 {
160 m_tissueType = type;
161 }
162
163 //=========================================================================================================
170 {
171 return m_tissueType;
172 }
173
174 //=========================================================================================================
180 int hemi() const
181 {
182 return m_hemi;
183 }
184
185 //=========================================================================================================
191 void fromSurface(const FSLIB::FsSurface& surf);
192
193 //=========================================================================================================
200 void fromBemSurface(const MNELIB::MNEBemSurface& surf, const QColor& color = Qt::white);
201
202 //=========================================================================================================
210 void createFromData(const Eigen::MatrixX3f& vertices, const Eigen::MatrixX3i& triangles, const QColor& color);
211
212 //=========================================================================================================
221 void createFromData(const Eigen::MatrixX3f& vertices, const Eigen::MatrixX3f& normals, const Eigen::MatrixX3i& triangles, const QColor& color);
222
223 //=========================================================================================================
230 bool loadAnnotation(const QString& path);
231
232 //=========================================================================================================
238 void addAnnotation(const FSLIB::FsAnnotation& annotation);
239
240 //=========================================================================================================
246 void setVisualizationMode(VisualizationMode mode);
247
248 //=========================================================================================================
254 void applySourceEstimateColors(const QVector<uint32_t>& colors);
255
259 void clearSourceEstimateColors();
260
261 //=========================================================================================================
268 void updateBuffers(QRhi* rhi, QRhiResourceUpdateBatch* u);
269
270 QRhiBuffer* vertexBuffer() const;
271 QRhiBuffer* indexBuffer() const;
272 uint32_t indexCount() const
273 {
274 return m_indexCount;
275 }
276 uint32_t vertexCount() const
277 {
278 return m_vertexData.size();
279 }
280
281 //=========================================================================================================
287 Eigen::MatrixX3f vertexPositions() const;
288
289 //=========================================================================================================
295 Eigen::MatrixX3f vertexNormals() const;
296
297 //=========================================================================================================
303 QVector<uint32_t> triangleIndices() const
304 {
305 return m_indexData;
306 }
307
313 const QVector<VertexData>& vertexDataRef() const
314 {
315 return m_vertexData;
316 }
317
322 const QVector<uint32_t>& indexDataRef() const
323 {
324 return m_indexData;
325 }
326
332 quint64 vertexGeneration() const
333 {
334 return m_vertexGeneration;
335 }
336
337 //=========================================================================================================
343 float minX() const;
344
345 //=========================================================================================================
351 float maxX() const;
352
353 //=========================================================================================================
360 void boundingBox(QVector3D& min, QVector3D& max) const;
361
362 //=========================================================================================================
375 bool intersects(const QVector3D& rayOrigin, const QVector3D& rayDir, float& dist, int& vertexIdx) const;
376
377 //=========================================================================================================
384 QString getAnnotationLabel(int vertexIdx) const;
385 int getAnnotationLabelId(int vertexIdx) const;
386
387 //=========================================================================================================
393 void setSelectedRegion(int regionId);
399 void translateX(float offset);
400
401 //=========================================================================================================
407 void transform(const QMatrix4x4& m);
408
409 //=========================================================================================================
416 void applyTransform(const QMatrix4x4& m);
417
418 //=========================================================================================================
425 std::vector<Eigen::VectorXi> computeNeighbors() const;
426
427 //=========================================================================================================
433 Eigen::MatrixX3f verticesAsMatrix() const;
434
435 //=========================================================================================================
441 void setUseDefaultColor(bool useDefault);
442
443 //=========================================================================================================
449 void setColor(const QColor& color);
450
451 void setSelected(bool selected);
452 bool isSelected() const
453 {
454 return m_selected;
455 }
457 {
458 return m_selectedRegionId;
459 }
461 {
462 return m_selectedVertexStart;
463 }
464
472 void setSelectedVertexRange(int start, int count);
473
474private:
475 void updateVertexColors();
476 void markVertexDirty();
477
478 QVector<VertexData> m_vertexData;
479 QVector<VertexData> m_originalVertexData;
480 QVector<uint32_t> m_indexData;
481 uint32_t m_indexCount = 0;
482
483 QColor m_defaultColor = Qt::white;
484 QColor m_baseColor = Qt::white;
485
486 FSLIB::FsAnnotation m_annotation;
487 bool m_hasAnnotation = false;
488 VisualizationMode m_visMode = ModeSurface;
489 QVector<float> m_curvature;
490 QVector<uint32_t> m_stcColors;
491
492 bool m_visible = true;
493 bool m_selected = false;
494 int m_selectedRegionId = -1;
495 int m_selectedVertexStart = -1;
496 int m_selectedVertexCount = 0;
497 int m_hemi = -1; // 0=lh, 1=rh
498 TissueType m_tissueType = TissueUnknown;
499
501 struct GpuBuffers;
502 std::unique_ptr<GpuBuffers> m_gpu;
503
504 quint64 m_vertexGeneration = 0;
505
506 mutable QVector3D m_aabbMin;
507 mutable QVector3D m_aabbMax;
508 mutable bool m_bAABBDirty = true;
509};
510
511} // namespace DISP3DLIB
512
513#endif // BRAINSURFACE_H
Library export/import macros and namespace marker for the disp3D library.
#define DISP3DSHARED_EXPORT
Lightweight render-related enums (ShaderMode, VisualizationMode) shared across disp3D.
Reader for FreeSurfer per-vertex annotation (parcellation) files such as lh.aparc....
Reader and in-memory representation of a single FreeSurfer triangular surface (e.g....
Boundary element model bundle (inner skull, outer skull, outer skin) loaded from -bem....
3-D brain visualisation using the Qt RHI rendering backend.
@ ModeSourceEstimate
Definition rendertypes.h:85
Interleaved vertex attributes (position, normal, color, curvature) for brain surface GPU upload.
quint64 vertexGeneration() const
Monotonically increasing counter bumped whenever vertex data changes.
const QVector< uint32_t > & indexDataRef() const
Const-ref access to CPU-side index data (used by merged rendering).
static constexpr VisualizationMode ModeSurface
TissueType tissueType() const
DISP3DLIB::VisualizationMode VisualizationMode
uint32_t indexCount() const
void setTissueType(TissueType type)
QVector< uint32_t > triangleIndices() const
static constexpr VisualizationMode ModeScientific
static constexpr VisualizationMode ModeAnnotation
const QVector< VertexData > & vertexDataRef() const
Const-ref access to CPU-side vertex data (used by merged rendering).
uint32_t vertexCount() const
int selectedVertexStart() const
static constexpr VisualizationMode ModeSourceEstimate
Single-hemisphere FreeSurfer parcellation: vertex → region label plus embedded colortable.
In-memory FreeSurfer triangular cortical surface for one hemisphere.
Definition fs_surface.h:94
BEM surface provides geometry information.