Skip to content

Commit 5991fce

Browse files
committed
Revert "Fix camera reset on every render by memoizing camera props"
This reverts commit 9fe333b.
1 parent 9fe333b commit 5991fce

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

usage/src/Volume/ResliceRendering.jsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useContext, useMemo } from 'react';
1+
import React, { useState, useContext } from 'react';
22
import vtkColorMaps from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction/ColorMaps.js';
33
import { SlabTypes } from '@kitware/vtk.js/Rendering/Core/ImageResliceMapper/Constants.js';
44
import { InterpolationType } from '@kitware/vtk.js/Rendering/Core/ImageProperty/Constants.js';
@@ -262,6 +262,7 @@ function OrientationDropDown(props) {
262262
plane.setOrigin(...origin);
263263
props.setOrientation(newOrientation);
264264
props.setSlicePos(cfg.defaultPos);
265+
props.setCamera({ position: cfg.cameraPosition, viewUp: cfg.viewUp });
265266
setTimeout(view.requestRender, 0);
266267
setTimeout(view.resetCamera, 0);
267268
}
@@ -315,12 +316,7 @@ function Example(props) {
315316
const [slicePlane, setSlicePlane] = useState(plane);
316317
const [slicePos, setSlicePos] = useState(127);
317318
const [orientation, setOrientation] = useState('Sagittal');
318-
// Memoize so the object reference only changes when orientation changes,
319-
// preventing useCamera from firing (and resetting the view) on every render.
320-
const cameraProps = useMemo(() => {
321-
const cfg = ORIENTATION_CONFIGS[orientation];
322-
return { position: cfg.cameraPosition, viewUp: cfg.viewUp, parallelProjection: false };
323-
}, [orientation]);
319+
const [camera, setCamera] = useState(ORIENTATION_CONFIGS['Sagittal']);
324320
return (
325321
<div style={{ width: '100%', height: '100%' }}>
326322
<ShareDataSetRoot>
@@ -333,7 +329,7 @@ function Example(props) {
333329
<div style={{ width: '50vw', height: '100%', display: 'inline-block' }}>
334330
<View
335331
id='0'
336-
camera={cameraProps}
332+
camera={{ position: camera.cameraPosition, viewUp: camera.viewUp, parallelProjection: false }}
337333
background={[0.34, 0.35, 0.34]}
338334
>
339335
<Slider
@@ -411,6 +407,7 @@ function Example(props) {
411407
orientation={orientation}
412408
setOrientation={setOrientation}
413409
setSlicePos={setSlicePos}
410+
setCamera={setCamera}
414411
style={{ top: '5px', left: '255px' }}
415412
/>
416413
<PosSlider

0 commit comments

Comments
 (0)