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 <optional>
48#include <vector>
49#include <fs/fs_surface.h>
50#include <fs/fs_annotation.h>
51#include <mne/mne_bem.h>
52
53#include <Eigen/Core>
54
55//=============================================================================================================
56// STRUCTS
57//=============================================================================================================
58
59namespace DISP3DLIB
60{
61
68{
69 QVector3D pos;
70 QVector3D norm;
71};
72
73//=============================================================================================================
82{
83public:
84 //=========================================================================================================
89
90 //=========================================================================================================
95
96 // VisualizationMode is defined in core/rendertypes.h for lightweight inclusion.
97 // These aliases preserve backward compatibility.
103
105 {
108 TissueSkin = 2, // Head/Scalp surface
109 TissueOuterSkull = 3, // Outer skull bone
110 TissueInnerSkull = 4 // Inner skull bone
111 };
112
113 //=========================================================================================================
119 void setVisible(bool visible);
120
121 //=========================================================================================================
127 bool isVisible() const
128 {
129 return m_visible;
130 }
131
132 //=========================================================================================================
138 void setHemi(int hemi)
139 {
140 m_hemi = hemi;
141 }
142
143 //=========================================================================================================
150 {
151 m_tissueType = type;
152 }
153
154 //=========================================================================================================
161 {
162 return m_tissueType;
163 }
164
165 //=========================================================================================================
171 int hemi() const
172 {
173 return m_hemi;
174 }
175
176 //=========================================================================================================
182 void fromSurface(const FSLIB::FsSurface& surf);
183
184 //=========================================================================================================
191 void fromBemSurface(const MNELIB::MNEBemSurface& surf, const QColor& color = Qt::white);
192
193 //=========================================================================================================
201 void createFromData(const Eigen::MatrixX3f& vertices, const Eigen::MatrixX3i& triangles, const QColor& color);
202
203 //=========================================================================================================
212 void createFromData(const Eigen::MatrixX3f& vertices, const Eigen::MatrixX3f& normals, const Eigen::MatrixX3i& triangles, const QColor& color);
213
214 //=========================================================================================================
221 bool loadAnnotation(const QString& path);
222
223 //=========================================================================================================
229 void addAnnotation(const FSLIB::FsAnnotation& annotation);
230
231 //=========================================================================================================
238 void labelElements(int verticesPerElement);
239
240 //=========================================================================================================
246 void setVisualizationMode(VisualizationMode mode);
247
248 //=========================================================================================================
254 void applySourceEstimateColors(const QVector<uint32_t>& colors);
255
259 void clearSourceEstimateColors();
260
261 //=========================================================================================================
265 GpuStream geometryStream() const;
266
270 GpuStream colorStream() const;
271
275 GpuStream annotationStream() const;
276
280 GpuStream indexStream() const;
281
285 const RenderKey& renderKey() const
286 {
287 return m_renderKey;
288 }
289
290 uint32_t indexCount() const
291 {
292 return m_indexCount;
293 }
294 uint32_t vertexCount() const
295 {
296 return m_vertexData.size();
297 }
298
299 //=========================================================================================================
305 Eigen::MatrixX3f vertexPositions() const;
306
307 //=========================================================================================================
313 Eigen::MatrixX3f vertexNormals() const;
314
315 //=========================================================================================================
321 QVector<uint32_t> triangleIndices() const
322 {
323 return m_indexData;
324 }
325
329 const QVector<VertexData>& vertexDataRef() const
330 {
331 return m_vertexData;
332 }
333
337 const QVector<uint32_t>& colorsRef() const
338 {
339 return m_colors;
340 }
341
345 const QVector<uint32_t>& annotationColorsRef() const
346 {
347 return m_annotationColors;
348 }
349
350 //=========================================================================================================
356 float minX() const;
357
358 //=========================================================================================================
364 float maxX() const;
365
366 //=========================================================================================================
373 void boundingBox(QVector3D& min, QVector3D& max) const;
374
375 //=========================================================================================================
388 bool intersects(const QVector3D& rayOrigin, const QVector3D& rayDir, float& dist, int& vertexIdx) const;
389
390 //=========================================================================================================
397 QString getAnnotationLabel(int vertexIdx) const;
398 int getAnnotationLabelId(int vertexIdx) const;
399
400 //=========================================================================================================
406 void setSelectedRegion(int regionId);
412 void translateX(float offset);
413
414 //=========================================================================================================
420 void transform(const QMatrix4x4& m);
421
422 //=========================================================================================================
429 void applyTransform(const QMatrix4x4& m);
430
431 //=========================================================================================================
438 std::vector<Eigen::VectorXi> computeNeighbors() const;
439
440 //=========================================================================================================
446 Eigen::MatrixX3f verticesAsMatrix() const;
447
448 //=========================================================================================================
454 void setUseDefaultColor(bool useDefault);
455
456 //=========================================================================================================
462 void setColor(const QColor& color);
463
464 void setSelected(bool selected);
465 bool isSelected() const
466 {
467 return m_selected;
468 }
470 {
471 return m_selectedRegionId;
472 }
474 {
475 return m_selectedVertexStart;
476 }
477
485 void setSelectedVertexRange(int start, int count);
486
491 std::optional<uint32_t> selectedLabel() const;
492
493private:
494 void updateVertexColors();
495 void setGeometry(QVector<VertexData> vertices, QVector<uint32_t> indices, const QColor& color);
496 void markGeometryDirty();
497
498 QVector<VertexData> m_vertexData;
499 QVector<VertexData> m_originalVertexData;
500 QVector<uint32_t> m_colors;
501 QVector<uint32_t> m_annotationColors;
502 QVector<int> m_vertexLabelIds;
503 QVector<uint32_t> m_indexData;
504 uint32_t m_indexCount = 0;
505
506 RenderKey m_renderKey;
507 quint64 m_geometryGeneration = 0;
508 quint64 m_colorGeneration = 0;
509 quint64 m_annotationGeneration = 0;
510 quint64 m_indexGeneration = 0;
511
512 QColor m_defaultColor = Qt::white;
513 QColor m_baseColor = Qt::white;
514
515 FSLIB::FsAnnotation m_annotation;
516 bool m_hasAnnotation = false;
517 VisualizationMode m_visMode = ModeSurface;
518 QVector<float> m_curvature;
519 QVector<uint32_t> m_stcColors;
520
521 bool m_visible = true;
522 bool m_selected = false;
523 int m_selectedRegionId = -1;
524 int m_selectedVertexStart = -1;
525 int m_selectedVertexCount = 0;
526 int m_hemi = -1; // 0=lh, 1=rh
527 TissueType m_tissueType = TissueUnknown;
528
529 mutable QVector3D m_aabbMin;
530 mutable QVector3D m_aabbMax;
531 mutable bool m_bAABBDirty = true;
532
533 // Bounding volume hierarchy over the triangles, built on the first pick after a geometry change
534 struct Bvh;
535 const Bvh& bvh() const;
536 mutable std::shared_ptr<const Bvh> m_bvh;
537};
538
539} // namespace DISP3DLIB
540
541#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:88
CPU-side contents of one GPU buffer of a renderable.
Definition rendertypes.h:99
Identity of a renderable in the renderer's GPU resource cache.
Geometry of one brain surface vertex: position and normal.
const RenderKey & renderKey() const
const QVector< uint32_t > & annotationColorsRef() const
static constexpr VisualizationMode ModeSurface
TissueType tissueType() const
DISP3DLIB::VisualizationMode VisualizationMode
const QVector< uint32_t > & colorsRef() const
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
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.