From 3bab7813ffb1b2e7a2247f1eedf8774b0460429b Mon Sep 17 00:00:00 2001 From: James Petts Date: Thu, 15 Oct 2020 13:24:39 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Fix=20second=20wave=20of?= =?UTF-8?q?=20bugs=20(#120)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix bugs relating to pan resetting the slice thickness. --- .webpack/webpack.dev.js | 7 ++++ examples/VTKRotatableCrosshairsExample.js | 4 +- src/VTKViewport/vtkInteractorStyleMPRSlice.js | 10 +++++ ...tkInteractorStyleRotatableMPRCrosshairs.js | 39 +++---------------- 4 files changed, 24 insertions(+), 36 deletions(-) diff --git a/.webpack/webpack.dev.js b/.webpack/webpack.dev.js index cecf4a27..75a5e58f 100644 --- a/.webpack/webpack.dev.js +++ b/.webpack/webpack.dev.js @@ -36,6 +36,12 @@ const ENTRY_EXAMPLES = path.join(__dirname, './../examples/index.js'); const SRC_PATH = path.join(__dirname, './../src'); const OUT_PATH = path.join(__dirname, './../dist'); +// Add this additional call so we can yarn link vtk.js +// const shaderLoader = { +// test: /\.glsl$/i, +// loader: 'shader-loader', +// }; + module.exports = { entry: { examples: ENTRY_EXAMPLES, @@ -70,6 +76,7 @@ module.exports = { ], }, ].concat(vtkRules), + //.concat(shaderLoader), }, resolve: { modules: [path.resolve(__dirname, './../node_modules'), SRC_PATH], diff --git a/examples/VTKRotatableCrosshairsExample.js b/examples/VTKRotatableCrosshairsExample.js index 8fbc2f4b..475955fe 100644 --- a/examples/VTKRotatableCrosshairsExample.js +++ b/examples/VTKRotatableCrosshairsExample.js @@ -123,7 +123,7 @@ class VTKRotatableCrosshairsExample extends Component { const istyle = vtkInteractorStyleRotatableMPRCrosshairs.newInstance(); - // // add istyle + // add istyle api.setInteractorStyle({ istyle, configuration: { @@ -132,8 +132,6 @@ class VTKRotatableCrosshairsExample extends Component { }, }); - //api.setInteractorStyle({ istyle }); - // set blend mode to MIP. const mapper = api.volumes[0].getMapper(); if (mapper.setBlendModeToMaximumIntensity) { diff --git a/src/VTKViewport/vtkInteractorStyleMPRSlice.js b/src/VTKViewport/vtkInteractorStyleMPRSlice.js index c31d3d4f..dde0e5c8 100644 --- a/src/VTKViewport/vtkInteractorStyleMPRSlice.js +++ b/src/VTKViewport/vtkInteractorStyleMPRSlice.js @@ -165,6 +165,7 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) { // should be set after pos and distance camera.setDirectionOfProjection(..._normal); camera.setViewAngle(angle); + camera.setThicknessFromFocalPoint(model.slabThickness); publicAPI.setCenterOfRotation(center); @@ -280,6 +281,15 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) { superHandleMouseMove(callData); } + const { apis, apiIndex } = model; + const thisApi = apis[apiIndex]; + + // This stops the clipping range being randomly reset. + const renderer = thisApi.genericRenderWindow.getRenderer(); + const camera = renderer.getActiveCamera(); + + camera.setThicknessFromFocalPoint(model.slabThickness); + if (model.state === States.IS_PAN) { const { apis, apiIndex } = model; const api = apis[apiIndex]; diff --git a/src/VTKViewport/vtkInteractorStyleRotatableMPRCrosshairs.js b/src/VTKViewport/vtkInteractorStyleRotatableMPRCrosshairs.js index 2c35f159..dedb8d2a 100644 --- a/src/VTKViewport/vtkInteractorStyleRotatableMPRCrosshairs.js +++ b/src/VTKViewport/vtkInteractorStyleRotatableMPRCrosshairs.js @@ -281,32 +281,9 @@ function vtkInteractorStyleRotatableMPRCrosshairs(publicAPI, model) { const { rotatableCrosshairsWidget } = thisApi.svgWidgets; - const point = rotatableCrosshairsWidget.getPoint(); - - const renderer = callData.pokedRenderer; - const dPos = vtkCoordinate.newInstance(); - dPos.setCoordinateSystemToDisplay(); - - dPos.setValue(point[0], point[1], 0); - let worldPos = dPos.getComputedWorldValue(renderer); - - const camera = renderer.getActiveCamera(); - const directionOfProjection = camera.getDirectionOfProjection(); - - const halfSlabThickness = thisApi.getSlabThickness() / 2; - - // Add half of the slab thickness to the world position, such that we select - // The center of the slice. + const worldPos = thisApi.get('cachedCrosshairWorldPosition'); - for (let i = 0; i < worldPos.length; i++) { - worldPos[i] += halfSlabThickness * directionOfProjection[i]; - } - - thisApi.svgWidgets.rotatableCrosshairsWidget.moveCrosshairs( - worldPos, - apis, - apiIndex - ); + rotatableCrosshairsWidget.moveCrosshairs(worldPos, apis, apiIndex); } function snapPosToLine(position, lineIndex) { @@ -364,7 +341,7 @@ function vtkInteractorStyleRotatableMPRCrosshairs(publicAPI, model) { function moveCrosshairs(pos, renderer) { const { apis, apiIndex } = model; - const api = apis[apiIndex]; + const thisApi = apis[apiIndex]; const dPos = vtkCoordinate.newInstance(); dPos.setCoordinateSystemToDisplay(); @@ -375,7 +352,7 @@ function vtkInteractorStyleRotatableMPRCrosshairs(publicAPI, model) { const camera = renderer.getActiveCamera(); const directionOfProjection = camera.getDirectionOfProjection(); - const halfSlabThickness = api.getSlabThickness() / 2; + const halfSlabThickness = thisApi.getSlabThickness() / 2; // Add half of the slab thickness to the world position, such that we select // The center of the slice. @@ -384,7 +361,7 @@ function vtkInteractorStyleRotatableMPRCrosshairs(publicAPI, model) { worldPos[i] += halfSlabThickness * directionOfProjection[i]; } - api.svgWidgets.rotatableCrosshairsWidget.moveCrosshairs( + thisApi.svgWidgets.rotatableCrosshairsWidget.moveCrosshairs( worldPos, apis, apiIndex @@ -467,11 +444,7 @@ function vtkInteractorStyleRotatableMPRCrosshairs(publicAPI, model) { }; // Move point. - moveCrosshairs( - displayCoordinate, - //{ x: newCenterPointSVG[0], y: newCenterPointSVG[1] }, - renderer - ); + moveCrosshairs(displayCoordinate, renderer); } function getDisplayCoordinateScrollIncrement(point) {