Hi. I am trying to synchronize transformation changes between two StackViewports.
viewport.setProperties({ rotation: rotation + 90 });
I see that setProperties
for a StackViewport
calls setRotation and there CAMERA_MODIFIED
event is triggered. So I wrote this synchronizer (based on already existing createCameraPositionSynchronizer
)
export default function createExtendedCameraPositionSynchronizer(
synchronizerName,
) {
const synchronizer = cornerstoneTools.SynchronizerManager.createSynchronizer(
synchronizerName,
CAMERA_MODIFIED,
(
synchronizerInstance,
sourceViewport,
targetViewport,
cameraModifiedEvent,
) => {
const { rotation, camera } = cameraModifiedEvent.detail;
const renderingEngine = getRenderingEngine(targetViewport.renderingEngineId);
if (!renderingEngine) {
throw new Error(
`No RenderingEngine for Id: ${targetViewport.renderingEngineId}`
);
}
const tViewport = renderingEngine.getViewport(targetViewport.viewportId);
tViewport.setProperties({ rotation });
tViewport.setCamera(camera);
tViewport.render();
}
);
return synchronizer;
}
It is very similar to a createCameraPositionSynchronizer
. I just added that it would change properties alongside with camera.
Unfortunately it doesn’t work. After I change properties in a viewport this synchronization callback is triggered, but rotation
is always equal to 0.
I investigated further. It turns out that this callback reacts not on a CAMERA_MODIFIED
event from StackViewport.setRotation
, as I would expected, but from Viewport.triggerCameraModifiedEventIfNecessary
. Moreover, though I can see in a debugger that setRotation indeed triggers a CAMERA_MODIFIED
event, it is not intercepted by a synchronizer and a callback is not called.
I don’t know if it is bug, or I am doing something wrong. I am confused. Could somebody please help me with writing a synchronizer that will synchronize rotation properties between two StackViewports? Thank you!
What steps can we follow to reproduce the bug?
- Create a synchronizer I described above
- Initialize two Stack viewports and add them to that synchronizer
- Add a button that will apply a rotation change in the first viewport on click
- Notice that after a click the synchronizer callback function is called but rotation is always equal to zero.