feat(segmentation): segment statistics, labelmap interpolation and segment bidirectional (#4865)

This commit is contained in:
Alireza authored and GitHub committed 2025-03-17 22:34:34 -04:00
1 parent 694f3e9611
commit ec79b5523e
73 files changed
+3603 -1563

No files matched your search

+1 -1
View File
@@ -37,7 +37,7 @@
"@cornerstonejs/codec-libjpeg-turbo-8bit": "^1.2.2",
"@cornerstonejs/codec-openjpeg": "^1.2.4",
"@cornerstonejs/codec-openjph": "^2.4.5",
"@cornerstonejs/dicom-image-loader": "^3.5.0",
"@cornerstonejs/dicom-image-loader": "^3.7.0",
"@ohif/ui": "3.10.0-beta.125",
"cornerstone-math": "0.1.9",
"dicom-parser": "^1.8.21"
@@ -585,7 +585,11 @@ export default class ToolbarService extends PubSubService {
});
props.evaluate = args => {
const results = evaluators.map(evaluator => evaluator(args));
const results = evaluators.map(evaluator => evaluator(args)).filter(Boolean);
// had at least one disabled button, so we need to disable the button
const hasDisabledButton = results?.some(result => result.disabled);
const mergedResult = results.reduce((acc, result) => {
return {
...acc,
@@ -593,6 +597,10 @@ export default class ToolbarService extends PubSubService {
};
}, {});
if (hasDisabledButton) {
mergedResult.disabled = true;
}
return mergedResult;
};
@@ -1,4 +1,5 @@
import guid from '../../utils/guid';
import debounce from '../../utils/debounce';
/**
* Consumer must implement:
@@ -92,14 +93,14 @@ function _broadcastEvent(eventName, callbackProps) {
/** Export a PubSubService class to be used instead of the individual items */
export class PubSubService {
EVENTS: any;
subscribe: (eventName: string, callback: Function) => { unsubscribe: () => any };
_broadcastEvent: (eventName: string, callbackProps: any) => void;
EVENTS: Record<string, string>;
subscribe: (eventName: string, callback: (data: unknown) => void) => { unsubscribe: () => void };
_broadcastEvent: (eventName: string, callbackProps: unknown) => void;
_unsubscribe: (eventName: string, listenerId: string) => void;
_isValidEvent: (eventName: string) => boolean;
listeners: {};
unsubscriptions: any[];
constructor(EVENTS) {
listeners: Record<string, Array<{ id: string; callback: (data: unknown) => void }> | undefined>;
unsubscriptions: Array<() => void>;
constructor(EVENTS: Record<string, string>) {
this.EVENTS = EVENTS;
this.subscribe = subscribe;
this._broadcastEvent = _broadcastEvent;
@@ -109,6 +110,27 @@ export class PubSubService {
this.unsubscriptions = [];
}
/**
* Subscribe to updates with debouncing to limit callback execution frequency
* @param eventName - The name of the event
* @param callback - Events callback
* @param wait - Debounce wait time in milliseconds
* @param immediate - If true, trigger on the leading edge instead of trailing
*/
subscribeDebounced(
eventName: string,
callback: (data: unknown) => void,
wait = 300,
immediate = false
) {
if (this._isValidEvent(eventName)) {
const debouncedCallback = debounce(callback, wait, immediate);
return this.subscribe(eventName, debouncedCallback);
} else {
throw new Error(`Event ${eventName} not supported.`);
}
}
reset() {
this.unsubscriptions.forEach(unsub => unsub());
this.unsubscriptions = [];
@@ -120,7 +142,9 @@ export class PubSubService {
* Check eventData.isConsumed to see if it is consumed or not.
* @param props - to include in the event
*/
protected createConsumableEvent(props) {
protected createConsumableEvent<T extends Record<string, unknown>>(
props: T
): T & { isConsumed: boolean; consume: () => void } {
return {
...props,
isConsumed: false,