Skip to content

Commit

Permalink
feat(voiSync): add optoins to turn of invert sync for voisync (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
sedghi committed Jul 28, 2023
1 parent 04ab515 commit 4f5b5c3
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 14 deletions.
8 changes: 4 additions & 4 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1230,13 +1230,13 @@ function createMergedLabelmapForIndex(labelmaps: Array<Types_2.IImageVolume>, se
function createStackImageSynchronizer(synchronizerName: string): Synchronizer;

// @public (undocumented)
function createSynchronizer(synchronizerId: string, eventName: string, eventHandler: ISynchronizerEventHandler): Synchronizer;
function createSynchronizer(synchronizerId: string, eventName: string, eventHandler: ISynchronizerEventHandler, options?: any): Synchronizer;

// @public (undocumented)
function createToolGroup(toolGroupId: string): IToolGroup | undefined;

// @public (undocumented)
function createVOISynchronizer(synchronizerName: string): Synchronizer;
function createVOISynchronizer(synchronizerName: string, options?: VOISynchronizerOptions): Synchronizer;

// @public (undocumented)
function createZoomPanSynchronizer(synchronizerName: string): Synchronizer;
Expand Down Expand Up @@ -2890,7 +2890,7 @@ function isViewportPreScaled(viewport: Types_2.IStackViewport | Types_2.IVolumeV
// @public (undocumented)
interface ISynchronizerEventHandler {
// (undocumented)
(synchronizer: Synchronizer, sourceViewport: Types_2.IViewportId, targetViewport: Types_2.IViewportId, sourceEvent: any): void;
(synchronizer: Synchronizer, sourceViewport: Types_2.IViewportId, targetViewport: Types_2.IViewportId, sourceEvent: any, options?: any): void;
}

// @public (undocumented)
Expand Down Expand Up @@ -4945,7 +4945,7 @@ enum Swipe {

// @public (undocumented)
export class Synchronizer {
constructor(synchronizerId: string, eventName: string, eventHandler: ISynchronizerEventHandler);
constructor(synchronizerId: string, eventName: string, eventHandler: ISynchronizerEventHandler, options?: any);
// (undocumented)
add(viewportInfo: Types_2.IViewportId): void;
// (undocumented)
Expand Down
2 changes: 1 addition & 1 deletion packages/dicomImageLoader/.webpack/webpack-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = {
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
cacheDirectory: false,
},
},
},
Expand Down
13 changes: 11 additions & 2 deletions packages/tools/src/store/SynchronizerManager/Synchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@ class Synchronizer {
private _sourceViewports: Array<Types.IViewportId>;
private _targetViewports: Array<Types.IViewportId>;
private _viewportOptions: Record<string, Record<string, unknown>> = {};
private _options: any;
public id: string;

constructor(
synchronizerId: string,
eventName: string,
eventHandler: ISynchronizerEventHandler
eventHandler: ISynchronizerEventHandler,
options?: any
) {
this._enabled = true;
this._eventName = eventName;
this._eventHandler = eventHandler;
this._ignoreFiredEvents = false;
this._sourceViewports = [];
this._targetViewports = [];
this._options = options || {};

//
this.id = synchronizerId;
Expand Down Expand Up @@ -212,7 +215,13 @@ class Synchronizer {
continue;
}

this._eventHandler(this, sourceViewport, targetViewport, sourceEvent);
this._eventHandler(
this,
sourceViewport,
targetViewport,
sourceEvent,
this._options
);
}
} catch (ex) {
console.warn(`Synchronizer, for: ${this._eventName}`, ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { ISynchronizerEventHandler } from '../../types';
* synchronizer.
* @param eventHandler - The event handler that will be
* called when the event is emitted.
* @param options - Options for the synchronizer.
* @returns A reference to the synchronizer.
*/
function createSynchronizer(
synchronizerId: string,
eventName: string,
eventHandler: ISynchronizerEventHandler
eventHandler: ISynchronizerEventHandler,
options?: any
): Synchronizer {
const synchronizerWithSameIdExists = state.synchronizers.some(
(sync) => sync.id === synchronizerId
Expand All @@ -28,7 +30,8 @@ function createSynchronizer(
const synchronizer = new Synchronizer(
synchronizerId,
eventName,
eventHandler
eventHandler,
options
);

// Update state
Expand Down
6 changes: 4 additions & 2 deletions packages/tools/src/synchronizers/callbacks/voiSyncCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import {
* @param sourceViewport - The list of IDs defining the source viewport.
* @param targetViewport - The list of IDs defining the target viewport.
* @param voiModifiedEvent - The VOI_MODIFIED event.
* @param options - Options for the synchronizer.
*/
export default function voiSyncCallback(
synchronizerInstance,
sourceViewport: Types.IViewportId,
targetViewport: Types.IViewportId,
voiModifiedEvent: Types.EventTypes.VoiModifiedEvent
voiModifiedEvent: Types.EventTypes.VoiModifiedEvent,
options?: any
): void {
const eventDetail = voiModifiedEvent.detail;
const { volumeId, range, invertStateChanged, invert } = eventDetail;
Expand All @@ -37,7 +39,7 @@ export default function voiSyncCallback(
voiRange: range,
};

if (invertStateChanged) {
if (options.syncInvertState && invertStateChanged) {
tProperties.invert = invert;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,30 @@ import { Enums } from '@cornerstonejs/core';
import voiSyncCallback from '../callbacks/voiSyncCallback';
import Synchronizer from '../../store/SynchronizerManager/Synchronizer';

type VOISynchronizerOptions = {
syncInvertState: boolean;
};

/**
* A helper that creates a new `Synchronizer`
* which listens to the `VOI_MODIFIED` rendering event and calls the `voiSyncCallback`.
*
* @param synchronizerName - The name of the synchronizer.
* @param options - The options for the synchronizer. By default the voi
* synchronizer will also sync the invert state of the volume, but this can be
* disabled by setting `syncInvertState` to false.
*
* @returns A new `Synchronizer` instance.
*/
export default function createVOISynchronizer(
synchronizerName: string
synchronizerName: string,
options = { syncInvertState: true } as VOISynchronizerOptions
): Synchronizer {
const VOISynchronizer = createSynchronizer(
synchronizerName,
Enums.Events.VOI_MODIFIED,
voiSyncCallback
voiSyncCallback,
options
);

return VOISynchronizer;
Expand Down
3 changes: 2 additions & 1 deletion packages/tools/src/types/ISynchronizerEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default interface ISynchronizerEventHandler {
synchronizer: Synchronizer,
sourceViewport: Types.IViewportId,
targetViewport: Types.IViewportId,
sourceEvent: any
sourceEvent: any,
options?: any
): void;
}

0 comments on commit 4f5b5c3

Please sign in to comment.