-
Notifications
You must be signed in to change notification settings - Fork 341
/
Copy pathconfig.ts
106 lines (89 loc) · 2.83 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import type { ContourSegmentationData } from './types';
import type { Types } from '@cornerstonejs/core';
import type { LabelmapSegmentationData } from './types/LabelmapTypes';
import type { SurfaceSegmentationData } from './types/SurfaceTypes';
import type SegmentationRepresentations from './enums/SegmentationRepresentations';
/**
* Options for converting between segmentation representations using PolySeg
* set
*/
export type PolySegConversionOptions = {
/** Optional array of segment indices to convert */
segmentIndices?: number[];
/** ID of the segmentation to convert */
segmentationId?: string;
/** Viewport to use for conversion */
viewport?: Types.IStackViewport | Types.IVolumeViewport;
};
/**
* Interface for the PolySeg add-on that handles segmentation representation conversions
*/
type ComputeRepresentationFn<T> = (
segmentationId: string,
options: PolySegConversionOptions
) => Promise<T>;
type PolySegAddOn = {
/** Checks if a representation type can be computed for a segmentation */
canComputeRequestedRepresentation: (
segmentationId: string,
representationType: SegmentationRepresentations
) => boolean;
/** Initializes the PolySeg add-on */
init: () => void;
/** Computes different segmentation representation data */
computeContourData: ComputeRepresentationFn<ContourSegmentationData>;
computeLabelmapData: ComputeRepresentationFn<LabelmapSegmentationData>;
computeSurfaceData: ComputeRepresentationFn<SurfaceSegmentationData>;
/** Updates different segmentation representation data */
updateSurfaceData: ComputeRepresentationFn<SurfaceSegmentationData>;
};
/**
* Available add-ons that can be configured
*/
type AddOns = {
polySeg: PolySegAddOn;
};
/**
* Configuration type containing add-ons
*/
export type Config = {
addons: AddOns;
};
let config = {} as Config;
/**
* Gets the current configuration
*/
export function getConfig(): Config {
return config;
}
/**
* Sets a new configuration
*/
export function setConfig(newConfig: Config): void {
config = newConfig;
}
/**
* Gets configured add-ons
*/
export function getAddOns(): AddOns {
return config.addons;
}
let polysegInitialized = false;
/**
* Gets the PolySeg add-on, initializing it if needed
* @returns The PolySeg add-on instance or null if not configured
*/
export function getPolySeg() {
if (!config.addons?.polySeg) {
console.warn(
'PolySeg add-on not configured. This will prevent automatic conversion between segmentation representations (labelmap, contour, surface). To enable these features, install @cornerstonejs/polymorphic-segmentation and register it during initialization: cornerstoneTools.init({ addons: { polySeg } }).'
);
return null;
}
const polyseg = config.addons.polySeg;
if (!polysegInitialized) {
polyseg.init();
polysegInitialized = true;
}
return polyseg;
}