Skip to content

Commit

Permalink
feat: 🎸 Fix second wave of bugs (#120)
Browse files Browse the repository at this point in the history
Fix bugs relating to pan resetting the slice thickness.
  • Loading branch information
JamesAPetts authored Oct 15, 2020
1 parent e9ca239 commit 3bab781
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 36 deletions.
7 changes: 7 additions & 0 deletions .webpack/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -70,6 +76,7 @@ module.exports = {
],
},
].concat(vtkRules),
//.concat(shaderLoader),
},
resolve: {
modules: [path.resolve(__dirname, './../node_modules'), SRC_PATH],
Expand Down
4 changes: 1 addition & 3 deletions examples/VTKRotatableCrosshairsExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class VTKRotatableCrosshairsExample extends Component {

const istyle = vtkInteractorStyleRotatableMPRCrosshairs.newInstance();

// // add istyle
// add istyle
api.setInteractorStyle({
istyle,
configuration: {
Expand All @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions src/VTKViewport/vtkInteractorStyleMPRSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down
39 changes: 6 additions & 33 deletions src/VTKViewport/vtkInteractorStyleRotatableMPRCrosshairs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand All @@ -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.
Expand All @@ -384,7 +361,7 @@ function vtkInteractorStyleRotatableMPRCrosshairs(publicAPI, model) {
worldPos[i] += halfSlabThickness * directionOfProjection[i];
}

api.svgWidgets.rotatableCrosshairsWidget.moveCrosshairs(
thisApi.svgWidgets.rotatableCrosshairsWidget.moveCrosshairs(
worldPos,
apis,
apiIndex
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3bab781

Please sign in to comment.