1- import React , { useState , useContext , useMemo } from 'react' ;
1+ import React , { useState , useContext } from 'react' ;
22import vtkColorMaps from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction/ColorMaps.js' ;
33import { SlabTypes } from '@kitware/vtk.js/Rendering/Core/ImageResliceMapper/Constants.js' ;
44import { 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