Skip to content

Commit 2db10c4

Browse files
committed
fix
1 parent aa96ee4 commit 2db10c4

File tree

17 files changed

+137
-128
lines changed

17 files changed

+137
-128
lines changed

bun.lock

Lines changed: 55 additions & 22 deletions
Large diffs are not rendered by default.

common/reviews/api/core.api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,9 @@ interface FlipDirection {
11941194
flipVertical?: boolean;
11951195
}
11961196

1197+
// @public (undocumented)
1198+
function fnv1aHash(str: string): string;
1199+
11971200
// @public (undocumented)
11981201
class FrameRange {
11991202
// (undocumented)
@@ -3966,6 +3969,7 @@ declare namespace utilities {
39663969
scaleRGBTransferFunction as scaleRgbTransferFunction,
39673970
triggerEvent,
39683971
imageIdToURI,
3972+
fnv1aHash,
39693973
metadataProvider as calibratedPixelSpacingMetadataProvider,
39703974
clamp,
39713975
uuidv4,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## API Report File for "@cornerstonejs/labelmap-interpolation"
2+
3+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4+
5+
```ts
6+
7+
// @public (undocumented)
8+
export function interpolate({ segmentationId, segmentIndex, configuration, }: {
9+
segmentationId: string;
10+
segmentIndex: number;
11+
configuration?: MorphologicalContourInterpolationOptions & {
12+
preview: boolean;
13+
};
14+
}): Promise<void>;
15+
16+
// (No @packageDocumentation comment for this package)
17+
18+
```

common/reviews/api/tools.api.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3172,15 +3172,6 @@ type InteractionTypes = 'Mouse' | 'Touch';
31723172
// @public (undocumented)
31733173
function internalAddRepresentationData({ segmentationId, type, data, }: AddRepresentationData): void;
31743174

3175-
// @public (undocumented)
3176-
function interpolateLabelmap({ segmentationId, segmentIndex, configuration, }: {
3177-
segmentationId: string;
3178-
segmentIndex: number;
3179-
configuration?: MorphologicalContourInterpolationOptions & {
3180-
preview: boolean;
3181-
};
3182-
}): Promise<void>;
3183-
31843175
// @public (undocumented)
31853176
type InterpolationROIAnnotation = ContourAnnotation & ContourSegmentationAnnotationData & {
31863177
metadata: {
@@ -5309,7 +5300,6 @@ declare namespace segmentation_2 {
53095300
growCut,
53105301
LabelmapMemo,
53115302
IslandRemoval,
5312-
interpolateLabelmap,
53135303
getOrCreateSegmentationVolume,
53145304
getStatistics
53155305
}

packages/ai/src/ONNXSegmentationController.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export default class ONNXSegmentationController {
332332
this.currentImage = null;
333333
this.viewport = viewport;
334334

335-
this.tool = new LabelmapBaseTool(
335+
const brushInstance = new LabelmapBaseTool(
336336
{},
337337
{
338338
configuration: {
@@ -352,6 +352,8 @@ export default class ONNXSegmentationController {
352352
}
353353
);
354354

355+
this.tool = brushInstance;
356+
355357
desiredImage.imageId =
356358
viewport.getCurrentImageId?.() || viewport.getViewReferenceId();
357359
if (desiredImage.imageId.startsWith('volumeId:')) {

packages/core/src/cache/cache.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import imageIdToURI from '../utilities/imageIdToURI';
1616
import eventTarget from '../eventTarget';
1717
import Events from '../enums/Events';
1818
import { ImageQualityStatus } from '../enums';
19+
import fnv1aHash from '../utilities/fnv1aHash';
1920

2021
const ONE_GB = 1073741824;
2122

@@ -52,7 +53,7 @@ class Cache {
5253

5354
let combinedHash = 0x811c9dc5;
5455
for (const id of imageURIs) {
55-
const idHash = this._fnv1aHash(id);
56+
const idHash = fnv1aHash(id);
5657
for (let i = 0; i < idHash.length; i++) {
5758
combinedHash ^= idHash.charCodeAt(i);
5859
combinedHash +=
@@ -1311,21 +1312,6 @@ class Cache {
13111312

13121313
return cachedGeometry.geometryLoadObject;
13131314
};
1314-
1315-
/**
1316-
* Helper function to generate a hash for a string using FNV-1a algorithm
1317-
* @param str - string to hash
1318-
* @returns the hashed string
1319-
*/
1320-
private _fnv1aHash(str: string): string {
1321-
let hash = 0x811c9dc5;
1322-
for (let i = 0; i < str.length; i++) {
1323-
hash ^= str.charCodeAt(i);
1324-
hash +=
1325-
(hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
1326-
}
1327-
return (hash >>> 0).toString(36);
1328-
}
13291315
}
13301316

13311317
/**
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Generates a hash for a string using FNV-1a algorithm
3+
* @param str - string to hash
4+
* @returns the hashed string in base 36
5+
*/
6+
export default function fnv1aHash(str: string): string {
7+
let hash = 0x811c9dc5;
8+
for (let i = 0; i < str.length; i++) {
9+
hash ^= str.charCodeAt(i);
10+
hash +=
11+
(hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
12+
}
13+
return (hash >>> 0).toString(36);
14+
}

packages/core/src/utilities/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import * as color from './color';
8080
import { deepEqual } from './deepEqual';
8181
import type { IViewport } from '../types/IViewport';
8282
import FrameRange from './FrameRange';
83+
import fnv1aHash from './fnv1aHash';
8384

8485
// solving the circular dependency issue
8586
import { _getViewportModality } from './getViewportModality';
@@ -108,6 +109,7 @@ export {
108109
scaleRgbTransferFunction,
109110
triggerEvent,
110111
imageIdToURI,
112+
fnv1aHash,
111113
calibratedPixelSpacingMetadataProvider,
112114
clamp,
113115
uuidv4,

packages/labelmap-interpolation/src/workers/interpolationWorker.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,34 @@ import vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';
55
/**
66
* Dynamically imports ITK WASM modules needed for labelmap interpolation
77
* @param moduleId - The module ID to import ('itk-wasm' or '@itk-wasm/morphological-contour-interpolation')
8-
* @param enableLabelmapInterpolation - Flag indicating if labelmap interpolation is enabled
98
* @returns Promise that resolves to the imported module
109
*/
1110
async function peerImport(moduleId) {
12-
switch (moduleId) {
13-
case 'itk-wasm':
14-
return import('itk-wasm');
15-
case '@itk-wasm/morphological-contour-interpolation':
16-
return import('@itk-wasm/morphological-contour-interpolation');
17-
default:
18-
throw new Error(`Unknown module ID: ${moduleId}`);
11+
try {
12+
switch (moduleId) {
13+
case 'itk-wasm':
14+
return import('itk-wasm');
15+
case '@itk-wasm/morphological-contour-interpolation':
16+
return import('@itk-wasm/morphological-contour-interpolation');
17+
default:
18+
throw new Error(`Unknown module ID: ${moduleId}`);
19+
}
20+
} catch (error) {
21+
console.warn(`Error importing ${moduleId}:`, error);
22+
return null;
1923
}
2024
}
2125

2226
const computeWorker = {
2327
getITKImage: async (args) => {
24-
const { imageData, options, enableLabelmapInterpolation } = args;
28+
const { imageData, options } = args;
2529

2630
const { imageName, scalarData } = options;
2731

2832
let Image, ImageType, IntTypes, FloatTypes, PixelTypes;
2933

3034
try {
31-
const itkModule = await peerImport(
32-
'itk-wasm',
33-
enableLabelmapInterpolation
34-
);
35+
const itkModule = await peerImport('itk-wasm');
3536
if (!itkModule) {
3637
throw new Error('Module not found');
3738
}
@@ -87,16 +88,14 @@ const computeWorker = {
8788
return image;
8889
},
8990
interpolateLabelmap: async (args) => {
90-
const { segmentationInfo, configuration, enableLabelmapInterpolation } =
91-
args;
91+
const { segmentationInfo, configuration } = args;
9292
const { scalarData, dimensions, spacing, origin, direction } =
9393
segmentationInfo;
9494

9595
let itkModule;
9696
try {
9797
itkModule = await peerImport(
98-
'@itk-wasm/morphological-contour-interpolation',
99-
enableLabelmapInterpolation
98+
'@itk-wasm/morphological-contour-interpolation'
10099
);
101100
if (!itkModule) {
102101
throw new Error('Module not found');
@@ -130,7 +129,6 @@ const computeWorker = {
130129
imageName: 'interpolation',
131130
scalarData: scalarData,
132131
},
133-
enableLabelmapInterpolation,
134132
});
135133

136134
if (!inputImage) {

packages/tools/src/config.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/tools/src/init.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { annotationInterpolationEventDispatcher } from './eventDispatchers';
1616
import * as ToolGroupManager from './store/ToolGroupManager';
1717
import { defaultSegmentationStateManager } from './stateManagement/segmentation/SegmentationStateManager';
1818
import segmentationRepresentationModifiedListener from './eventListeners/segmentation/segmentationRepresentationModifiedListener';
19-
import { setConfig } from './config';
19+
2020
let csToolsInitialized = false;
2121

2222
/**
@@ -25,13 +25,11 @@ let csToolsInitialized = false;
2525
* @param defaultConfiguration - A configuration object that will be used to
2626
* initialize the tool.
2727
*/
28-
export function init(defaultConfiguration): void {
28+
export function init(defaultConfiguration = {}): void {
2929
if (csToolsInitialized) {
3030
return;
3131
}
3232

33-
setConfig(defaultConfiguration);
34-
3533
_addCornerstoneEventListeners();
3634
_addCornerstoneToolsEventListeners();
3735

packages/tools/src/stateManagement/segmentation/polySeg/registerPolySegWorker.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { getWebWorkerManager } from '@cornerstonejs/core';
2-
import { getConfig } from '../../../config';
32

43
let registered = false;
54

@@ -30,7 +29,6 @@ export function registerPolySegWorker() {
3029
enabled: true,
3130
idleTimeThreshold: 2000,
3231
},
33-
enablePolySeg: getConfig().enablePolySeg,
3432
};
3533

3634
workerManager.registerWorker('polySeg', workerFn, options);

packages/tools/src/tools/segmentation/strategies/compositions/preview.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,9 @@ export default {
122122
segmentationId,
123123
preview,
124124
} = operationData || {};
125-
126125
if (previewSegmentIndex === undefined) {
127126
return;
128127
}
129-
130128
const segmentIndex = preview?.segmentIndex ?? operationData.segmentIndex;
131129
if (!previewVoxelManager || previewVoxelManager.modifiedSlices.size === 0) {
132130
return;

packages/tools/src/utilities/registerComputeWorker.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { getWebWorkerManager } from '@cornerstonejs/core';
2-
import { getConfig } from '../config';
32
let registered = false;
43

54
export function registerComputeWorker() {
@@ -29,7 +28,6 @@ export function registerComputeWorker() {
2928
enabled: true,
3029
idleTimeThreshold: 2000,
3130
},
32-
enableLabelmapInterpolation: getConfig().enableLabelmapInterpolation,
3331
};
3432

3533
workerManager.registerWorker('compute', workerFn, options);

0 commit comments

Comments
 (0)