Skip to main content

SliceObject

Namespace: DISP3DLIB  ·  Library: 3D Display Library

#include <disp3D/sliceobject.h>

class DISP3DLIB::SliceObject

Data model for a single 2-D MRI volume slice.

Holds the greyscale slice image, orientation metadata, and the slice-to-world transform. Generates a textured quad and vertex/UV data for upload to a QRhi renderer via the slice.vert / slice.frag shaders.

src/examples/ex_disp3d_scene/main.cpp
QImage axial(256, 256, QImage::Format_Grayscale8);
axial.fill(128);
Matrix4d voxelToWorld = Matrix4d::Identity(); // 1 mm voxels, origin at the volume centre
voxelToWorld.block<3, 1>(0, 3) = Vector3d(-128.0, -128.0, -128.0);
SliceObject slice;
slice.setSlice(axial, SliceOrientation::Axial, 128, voxelToWorld); // the z = 0 mm plane
slice.setWindowLevel(100.0f, 200.0f);
QVector<float> quad; // 4 corners x (x, y, z, u, v)
slice.generateQuadVertices(quad);

Public Methods​

SliceObject()​


setSlice(image, orientation, sliceIndex, voxelToWorld)​

Set the slice image data and orientation.

Parameters:

  • image : const QImage & Greyscale slice image (QImage::Format_Grayscale8 or 16).

  • orientation : SliceOrientation Axial, Sagittal, or Coronal.

  • sliceIndex : int Index along the perpendicular axis (voxel units).

  • voxelToWorld : const Eigen::Matrix4d & 4×4 voxel-to-RAS transform from the MRI header.


setSliceToWorld(image, orientation, sliceIndex, imageToWorld)​

Set the slice image data with an explicit image-to-world transform.

Parameters:

  • image : const QImage & Greyscale slice image (QImage::Format_Grayscale8 or 16).

  • orientation : SliceOrientation Anatomical orientation of the slice.

  • sliceIndex : int Index along the perpendicular voxel axis.

  • imageToWorld : const Eigen::Matrix4d & 4x4 transform from image coordinates (column, row, 0) to RAS.


orientation()​

Returns:

  • SliceOrientation — Current slice orientation.

sliceIndex()​

Returns:

  • int — Current slice index (voxel units along the perpendicular axis).

image()​

Returns:

  • const QImage & — The slice image.

sliceToWorld()​

Returns:

  • QMatrix4x4 — 4×4 matrix that maps the unit quad [0,1]² into world (RAS) coordinates.

setWindowLevel(center, width)​

Intensity windowing parameters for the fragment shader.

Parameters:

  • center : float Window center in normalised intensity [0,1].

  • width : float Window width in normalised intensity [0,1].


windowCenter()​

Returns:

  • float — Window center.

windowWidth()​

Returns:

  • float — Window width.

setOpacity(opacity)​

Parameters:

  • opacity : float Slice transparency [0,1].

opacity()​

Returns:

  • float — Current opacity.

generateQuadVertices(vertices)​

Generate quad vertex buffer: 4 vertices × (3 pos + 2 UV) = 20 floats.

Parameters:

  • vertices : QVector< float > & Output vertex data.

Static Methods​

generateQuadIndices(indices)​

Generate quad index buffer: 2 triangles = 6 indices.

Parameters:

  • indices : QVector< unsigned int > & Output index data.

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 150
axial.fill(128);
Matrix4d voxelToWorld = Matrix4d::Identity(); // 1 mm voxels, origin at the volume centre
voxelToWorld.block<3, 1>(0, 3) = Vector3d(-128.0, -128.0, -128.0);
SliceObject slice;
slice.setSlice(axial, SliceOrientation::Axial, 128, voxelToWorld); // the z = 0 mm plane
slice.setWindowLevel(100.0f, 200.0f);
QVector<float> quad; // 4 corners x (x, y, z, u, v)
slice.generateQuadVertices(quad);
ok &= expect(quad.size() == 20 && quad[0] == -128.0f && quad[1] == -128.0f && quad[2] == 0.0f && quad[15] == 128.0f && quad[16] == 128.0f && quad[17] == 0.0f && quad[18] == 1.0f && slice.windowWidth() == 200.0f,
"SliceObject: the axial slice 128 spans [-128, 128] mm in x and y at z = 0");

Authors of this file​