diff --git a/Sources/Rendering/OpenGL/CellArrayBufferObject/helpers.js b/Sources/Rendering/OpenGL/CellArrayBufferObject/helpers.js index 6ca5264941f..326b24ad137 100644 --- a/Sources/Rendering/OpenGL/CellArrayBufferObject/helpers.js +++ b/Sources/Rendering/OpenGL/CellArrayBufferObject/helpers.js @@ -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 @@ -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 }; diff --git a/Sources/Rendering/OpenGL/CellArrayBufferObject/index.js b/Sources/Rendering/OpenGL/CellArrayBufferObject/index.js index 41748baea93..678e42ae441 100644 --- a/Sources/Rendering/OpenGL/CellArrayBufferObject/index.js +++ b/Sources/Rendering/OpenGL/CellArrayBufferObject/index.js @@ -1,10 +1,13 @@ -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; @@ -12,21 +15,6 @@ 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; diff --git a/Sources/Rendering/OpenGL/Glyph3DMapper/index.js b/Sources/Rendering/OpenGL/Glyph3DMapper/index.js index ade5c31ce95..ae1205c333a 100644 --- a/Sources/Rendering/OpenGL/Glyph3DMapper/index.js +++ b/Sources/Rendering/OpenGL/Glyph3DMapper/index.js @@ -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'; @@ -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 // ---------------------------------------------------------------------------- @@ -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); } } diff --git a/Sources/Widgets/Widgets3D/ResliceCursorWidget/example/index.js b/Sources/Widgets/Widgets3D/ResliceCursorWidget/example/index.js index 0317bf167b8..740395b20d7 100644 --- a/Sources/Widgets/Widgets3D/ResliceCursorWidget/example/index.js +++ b/Sources/Widgets/Widgets3D/ResliceCursorWidget/example/index.js @@ -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(() => { @@ -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); }); }); @@ -577,7 +578,7 @@ slabFolder updateViews(); }); -slabFolder +slabNumberOfSlices = slabFolder .add(guiParams, 'SlabNumberOfSlices', 1, 100, 1) .name('Slab slices') .onChange((value) => {