Skip to main content

BrainSurface

Namespace: DISP3DLIB  ·  Library: 3D Display Library

#include <disp3D/brainsurface.h>

class DISP3DLIB::BrainSurface

BrainSurface manages the geometry and visual properties of a single brain mesh.

Renderable cortical surface mesh with per-vertex color, curvature data, and GPU buffer management.

src/examples/ex_disp3d_scene/main.cpp
// A 2 x 2 cm flat patch at z = 0 (metres), picked by a ray cast straight down
MatrixX3f patchVertices(4, 3);
patchVertices << 0.0f, 0.0f, 0.0f, 0.02f, 0.0f, 0.0f, 0.02f, 0.02f, 0.0f, 0.0f, 0.02f, 0.0f;
MatrixX3i patchTriangles(2, 3);
patchTriangles << 0, 1, 2, 0, 2, 3;
BrainSurface patch;
patch.createFromData(patchVertices, patchTriangles, Qt::gray);
patch.setHemi(0);
float hitDistance = 0.0f;
int hitVertex = -1;
const bool picked = patch.intersects(QVector3D(0.019f, 0.019f, 0.05f), QVector3D(0.0f, 0.0f, -1.0f), hitDistance, hitVertex);
const VertexData& corner = patch.vertexDataRef().at(2); // interleaved position, normal and packed ABGR colour

Public Methods​

BrainSurface()​

Default Constructor.


~BrainSurface()​

Destructor.


setVisible(visible)​

Set the visibility of the surface.

Parameters:

  • visible : bool True if visible.

isVisible()​

Check if the surface is visible.

Returns:

  • bool — True if visible.

setHemi(hemi)​

Set the hemisphere index.

Parameters:

  • hemi : int 0 for Left, 1 for Right.

setTissueType(type)​

Set the tissue type (Brain, Skin, Skull, etc.).

Parameters:

  • type : TissueType TissueType enum value.

tissueType()​

Get the tissue type.

Returns:

  • TissueType — TissueType enum value.

hemi()​

Get the hemisphere index.

Returns:

  • int — Hemisphere index (0=LH, 1=RH).

fromSurface(surf)​

Load geometry from a FreeSurfer surface.

Parameters:

  • surf : const FsSurface & Input FreeSurfer surface.

fromBemSurface(surf, color)​

Load geometry from a MNE BEM surface.

Parameters:

  • surf : const MNEBemSurface & Input BEM surface.

  • color : const QColor & Base color for the surface.


createFromData(vertices, triangles, color)​

Create surface from raw vertex and triangle data.

Vertex normals are the sums of the adjacent face normals.

Parameters:

  • vertices : const Eigen::MatrixX3f & Nx3 matrix of vertex positions.

  • triangles : const Eigen::MatrixX3i & Mx3 matrix of triangle indices.

  • color : const QColor & FsSurface color.


createFromData(vertices, normals, triangles, color)​

Create surface from raw vertex, normal and triangle data.

Parameters:

  • vertices : const Eigen::MatrixX3f & Nx3 matrix of vertex positions.

  • normals : const Eigen::MatrixX3f & Nx3 matrix of vertex normals.

  • triangles : const Eigen::MatrixX3i & Mx3 matrix of triangle indices.

  • color : const QColor & FsSurface color.


loadAnnotation(path)​

Load annotation data from file.

Parameters:

  • path : const QString & Path to the .annot file.

Returns:

  • bool — True if successful.

addAnnotation(annotation)​

Add annotation data directly.

Parameters:


labelElements(verticesPerElement)​

Give each run of vertices its own label key, so one element of a batched mesh (e.g.

one digitizer sphere) can be highlighted on its own.

Parameters:

  • verticesPerElement : int Number of consecutive vertices per element.

setVisualizationMode(mode)​

Set the visualization mode (FsSurface, FsAnnotation, Scientific).

Parameters:

  • mode : VisualizationMode VisualizationMode enum.

applySourceEstimateColors(colors)​

Apply source estimate colors to vertices.

Parameters:

  • colors : const QVector< uint32_t > & Vector of packed ABGR colors, one per vertex.

clearSourceEstimateColors()​

Clear source estimate overlay colors and restore curvature-based coloring.


geometryStream()​

Returns:


colorStream()​

Returns:

  • GpuStream — Colour stream (packed ABGR per vertex; alpha carries the curvature grey on cortex).

annotationStream()​

Returns:

  • GpuStream — Annotation colour stream (packed ABGR per vertex, 0 where unlabelled).

indexStream()​

Returns:

  • GpuStream — Triangle index stream (three uint32 per triangle).

renderKey()​

Returns:

  • const RenderKey & — Identity of this surface in the renderer's GPU cache.

indexCount()​


vertexCount()​


vertexPositions()​

Get a copy of the current vertex positions.

Returns:

  • Eigen::MatrixX3f — Nx3 matrix of the current (possibly transformed) vertex positions.

vertexNormals()​

Get a copy of the current vertex normals.

Returns:

  • Eigen::MatrixX3f — Nx3 matrix of the current vertex normals.

triangleIndices()​

Get the triangle index buffer.

Returns:

  • QVector< uint32_t > — Copy of the index data, three vertex indices per triangle.

vertexDataRef()​

Returns:

  • const QVector< VertexData > & — Current vertex geometry, valid while this surface lives.

colorsRef()​

Returns:

  • const QVector< uint32_t > & — Per-vertex packed ABGR colours, valid while this surface lives.

annotationColorsRef()​

Returns:

  • const QVector< uint32_t > & — Per-vertex packed ABGR annotation colours, valid while this surface lives.

minX()​

Get minimum X coordinate.

Returns:

  • float — Minimum X value.

maxX()​

Get maximum X coordinate.

Returns:

  • float — Maximum X value.

boundingBox(min, max)​

Get bounding box of the surface.

Parameters:

  • min : QVector3D & Minimum coordinates.

  • max : QVector3D & Maximum coordinates.


intersects(rayOrigin, rayDir, dist, vertexIdx)​

Test ray intersection with this surface.

Parameters:

  • rayOrigin : const QVector3D & Ray origin in world/local space (object is assumed at 0,0,0 usually unless transformed externally). Note: The BrainSurface vertices are typically already transformed (e.g. by View3D model matrix logic? No, BrainView applies matrix in shader. The vertices here are raw. So ray must be transformed to local space OR vertices transformed to world.

  • rayDir : const QVector3D & Ray direction (normalized).

  • dist : float & Distance to intersection.

  • vertexIdx : int & Index of the vertex closest to the intersection.

Returns:

  • bool — True if intersected.

getAnnotationLabel(vertexIdx)​

Get the annotation label name for a given vertex.

Parameters:

  • vertexIdx : int Index of the vertex.

Returns:

  • QString — FsLabel name.

getAnnotationLabelId(vertexIdx)​


setSelectedRegion(regionId)​

Set the selected region for highlighting.

Parameters:

  • regionId : int The ID of the region to highlight.

translateX(offset)​

Translate all vertices along the X axis.

Parameters:

  • offset : float Amount to translate.

transform(m)​

Apply a generic 4x4 transformation matrix to all vertices and normals.

Parameters:

  • m : const QMatrix4x4 & Transformation matrix.

applyTransform(m)​

Apply a transformation to the surface starting from the original data.

Note: This prevents transformation accumulation.

Parameters:

  • m : const QMatrix4x4 & Transformation matrix.

computeNeighbors()​

Compute neighbor vertices from triangle connectivity.

Required for surface-constrained distance calculations.

Returns:

  • std::vector< Eigen::VectorXi > — Vector of neighbor indices for each vertex.

verticesAsMatrix()​

Get vertex positions as Eigen matrix.

Returns:

  • Eigen::MatrixX3f — Nx3 matrix of vertex positions.

setUseDefaultColor(useDefault)​

Set/Get whether to use the default surface color.

Parameters:

  • useDefault : bool True to use the surface's default color as base, false for white.

setColor(color)​

Set the colour of a surface without curvature (BEM, sensors, digitizers, source spaces).

Parameters:

  • color : const QColor & New colour; its alpha is the opacity of the holographic shader.

setSelected(selected)​


isSelected()​


selectedRegionId()​


selectedVertexStart()​


setSelectedVertexRange(start, count)​

Highlight a contiguous range of vertices (e.g.

a single sphere in a batched mesh). Pass start=-1 to clear the vertex range highlight.

Parameters:

  • start : int First vertex index to highlight (-1 to clear).

  • count : int Number of vertices to highlight.


selectedLabel()​

Returns:

  • std::optional< uint32_t > — Annotation-stream value of the highlighted vertices (selected region or vertex range), or nothing when no part of the surface is highlighted.

Example​

Used in examples​

ex_disp3d_scene​

Disp3D scene data: sensor-to-surface interpolation, electrodes, MRI slices, video overlay and layers.

src/examples/ex_disp3d_scene/main.cpp, line 225
patchVertices << 0.0f, 0.0f, 0.0f, 0.02f, 0.0f, 0.0f, 0.02f, 0.02f, 0.0f, 0.0f, 0.02f, 0.0f;
MatrixX3i patchTriangles(2, 3);
patchTriangles << 0, 1, 2, 0, 2, 3;
BrainSurface patch;
patch.createFromData(patchVertices, patchTriangles, Qt::gray);
patch.setHemi(0);
float hitDistance = 0.0f;
int hitVertex = -1;
const bool picked = patch.intersects(QVector3D(0.019f, 0.019f, 0.05f), QVector3D(0.0f, 0.0f, -1.0f), hitDistance, hitVertex);
const VertexData& corner = patch.vertexDataRef().at(2); // interleaved position, normal and packed ABGR colour
ok &= expect(picked && std::abs(hitDistance - 0.05f) < 1e-6f && hitVertex == 2 && corner.pos == QVector3D(0.02f, 0.02f, 0.0f) && std::abs(std::abs(corner.norm.z()) - 1.0f) < 1e-6f,
"BrainSurface: a downward ray hits the patch 5 cm below, nearest vertex 2");

Authors of this file​