Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(viewport-sync): Enable re-sync image slices in a different position when needed #3984

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { synchronizers, SynchronizerManager, Synchronizer } from '@cornerstonejs/tools';
import { getRenderingEngines } from '@cornerstonejs/core';
import { getRenderingEngines, utilities } from '@cornerstonejs/core';

import { pubSubServiceInterface, Types, ServicesManager } from '@ohif/core';

Expand Down Expand Up @@ -184,6 +184,11 @@ export default class SyncGroupService {
return;
}

// Only image slice synchronizer register spatial registration
if (this.isImageSliceSyncronizer(synchronizer)) {
this.unRegisterSpatialRegistration(synchronizer);
}

synchronizer.remove({
viewportId,
renderingEngineId,
Expand All @@ -198,4 +203,45 @@ export default class SyncGroupService {
}
});
}
/**
* Clean up the spatial registration metadata created by synchronizer
* This is needed to be able to re-sync images slices if needed
* @param synchronizer
*/
unRegisterSpatialRegistration(synchronizer: Synchronizer) {
const sourceViewports = synchronizer.getSourceViewports().map(vp => vp.viewportId);
const targetViewports = synchronizer.getTargetViewports().map(vp => vp.viewportId);

// Create an array of pair of viewports to remove from spatialRegistrationMetadataProvider
// All sourceViewports combined with all targetViewports
const toUnregister = sourceViewports
.map((sourceViewportId: string) => {
return targetViewports.map(targetViewportId => [targetViewportId, sourceViewportId]);
})
.reduce((acc, c) => acc.concat(c), []);

toUnregister.forEach(viewportIdPair => {
utilities.spatialRegistrationMetadataProvider.add(viewportIdPair, undefined);
});
}
/**
* Check if the synchronizer type is IMAGE_SLICE
* Need to convert to lowercase here because the types are lowercase
* e.g: synchronizerCreators
* @param synchronizer
*/
isImageSliceSyncronizer(synchronizer: Synchronizer) {
return this.getSynchronizerType(synchronizer).toLowerCase() === IMAGE_SLICE;
}
/**
* Returns the syncronizer type
* @param synchronizer
*/
getSynchronizerType(synchronizer: Synchronizer): string {
const synchronizerTypes = Object.keys(this.synchronizersByType);
const syncType = synchronizerTypes.find(syncType =>
this.getSynchronizersOfType(syncType).includes(synchronizer)
);
return syncType;
}
}