Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion Sources/Rendering/OpenGL/CellArrayBufferObject/helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { mat4, quat, vec3 } from 'gl-matrix';

export function computeCoordShiftAndScale(points) {
// Find out if shift scale should be used
// Compute squares of diagonal size and distance from the origin
Expand Down Expand Up @@ -41,4 +43,19 @@ export function computeCoordShiftAndScale(points) {
};
}

export default { computeCoordShiftAndScale };
export function computeInverseShiftAndScaleMatrix(coordShift, coordScale) {
const inverseScale = new Float64Array(3);
vec3.inverse(inverseScale, coordScale);

const matrix = new Float64Array(16);
mat4.fromRotationTranslationScale(
matrix,
quat.create(),
coordShift,
inverseScale
);

return matrix;
}

export default { computeCoordShiftAndScale, computeInverseShiftAndScaleMatrix };
22 changes: 5 additions & 17 deletions Sources/Rendering/OpenGL/CellArrayBufferObject/index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
import { mat4, quat, vec3 } from 'gl-matrix';
import { vec3 } from 'gl-matrix';

import macro from 'vtk.js/Sources/macros';
import vtkBufferObject from 'vtk.js/Sources/Rendering/OpenGL/BufferObject';
import { ObjectType } from 'vtk.js/Sources/Rendering/OpenGL/BufferObject/Constants';
import { Representation } from 'vtk.js/Sources/Rendering/Core/Property/Constants';
import { computeCoordShiftAndScale } from 'vtk.js/Sources/Rendering/OpenGL/CellArrayBufferObject/helpers';
import {
computeCoordShiftAndScale,
computeInverseShiftAndScaleMatrix,
} from 'vtk.js/Sources/Rendering/OpenGL/CellArrayBufferObject/helpers';

const { vtkErrorMacro } = macro;

// ----------------------------------------------------------------------------
// Static functions
// ----------------------------------------------------------------------------

function computeInverseShiftAndScaleMatrix(coordShift, coordScale) {
const inverseScale = new Float64Array(3);
vec3.inverse(inverseScale, coordScale);

const matrix = new Float64Array(16);
mat4.fromRotationTranslationScale(
matrix,
quat.create(),
coordShift,
inverseScale
);

return matrix;
}

function shouldApplyCoordShiftAndScale(coordShift, coordScale) {
if (coordShift === null || coordScale === null) {
return false;
Expand Down
22 changes: 10 additions & 12 deletions Sources/Rendering/OpenGL/Glyph3DMapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import vtkHardwareSelector from 'vtk.js/Sources/Rendering/OpenGL/HardwareSelecto
import vtkProperty from 'vtk.js/Sources/Rendering/Core/Property';
import vtkOpenGLPolyDataMapper from 'vtk.js/Sources/Rendering/OpenGL/PolyDataMapper';
import vtkShaderProgram from 'vtk.js/Sources/Rendering/OpenGL/ShaderProgram';
import { computeCoordShiftAndScale } from 'vtk.js/Sources/Rendering/OpenGL/CellArrayBufferObject/helpers';
import {
computeCoordShiftAndScale,
computeInverseShiftAndScaleMatrix,
} from 'vtk.js/Sources/Rendering/OpenGL/CellArrayBufferObject/helpers';

import { registerOverride } from 'vtk.js/Sources/Rendering/OpenGL/ViewNodeFactory';
import { primTypes } from '../Helper';
Expand All @@ -23,16 +26,6 @@ const EndEvent = { type: 'EndEvent' };
const MAT4_BYTE_SIZE = 64;
const MAT4_ELEMENT_COUNT = 16;

function applyShiftScaleToMat(mat, shift, scale) {
// the translation component of a 4x4 column-major matrix
mat[12] = (mat[12] - shift[0]) * scale[0];
mat[13] = (mat[13] - shift[1]) * scale[1];
mat[14] = (mat[14] - shift[2]) * scale[2];
mat[0] *= scale[0];
mat[5] *= scale[1];
mat[10] *= scale[2];
}

// ----------------------------------------------------------------------------
// vtkOpenGLSphereMapper methods
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -714,13 +707,18 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {

if (useShiftAndScale) {
const buf = garray.buffer;
const shiftScaleMat = computeInverseShiftAndScaleMatrix(
coordShift,
coordScale
);
mat4.invert(shiftScaleMat, shiftScaleMat);
for (
let ptIdx = 0;
ptIdx < garray.byteLength;
ptIdx += MAT4_BYTE_SIZE
) {
const mat = new Float32Array(buf, ptIdx, MAT4_ELEMENT_COUNT);
applyShiftScaleToMat(mat, coordShift, coordScale);
mat4.multiply(mat, shiftScaleMat, mat);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ function updateReslice(
return modified;
}

let slabNumberOfSlices = null;
const reader = vtkHttpDataSetReader.newInstance({ fetchGzip: true });
reader.setUrl(`${__BASE_PATH__}/data/volume/LIDC2.vti`).then(() => {
reader.loadData().then(() => {
Expand Down Expand Up @@ -464,7 +465,7 @@ reader.setUrl(`${__BASE_PATH__}/data/volume/LIDC2.vti`).then(() => {

// set max number of slices to slider.
const maxNumberOfSlices = vec3.length(image.getDimensions());
document.getElementById('slabNumber').max = maxNumberOfSlices;
slabNumberOfSlices?.max(maxNumberOfSlices);
});
});

Expand Down Expand Up @@ -577,7 +578,7 @@ slabFolder
updateViews();
});

slabFolder
slabNumberOfSlices = slabFolder
.add(guiParams, 'SlabNumberOfSlices', 1, 100, 1)
.name('Slab slices')
.onChange((value) => {
Expand Down