Skip to content

Commit 7760c6e

Browse files
committed
fix(schema): allow just auto and useAuto for view.windowing
1 parent c1fb113 commit 7760c6e

4 files changed

Lines changed: 30 additions & 13 deletions

File tree

src/io/import/processors/restoreStateFile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ const restoreStateFile: ImportHandler = async (dataSource, context) => {
359359
let manifest: Manifest;
360360
try {
361361
manifest = ManifestSchema.parse(migrated);
362-
} catch (_) {
362+
} catch (e) {
363363
return asErrorResult(
364-
new Error('Unsupported state file schema or version'),
364+
new Error(`Unsupported state file schema or version: ${e}`),
365365
dataSource
366366
);
367367
}

src/io/state-file/schema.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,29 @@ const Vector3 = z.tuple([
131131
]) satisfies z.ZodType<Vector3>;
132132

133133
type AutoRangeKeys = keyof typeof WLAutoRanges;
134-
const WindowLevelConfig = z.object({
135-
width: z.number(),
136-
level: z.number(),
137-
auto: z.string() as z.ZodType<AutoRangeKeys>,
138-
useAuto: z.boolean().optional(),
139-
userTriggered: z.boolean().optional(),
140-
}) satisfies z.ZodType<WindowLevelConfig>;
134+
const WindowLevelConfig = z
135+
.object({
136+
width: z.number().optional(),
137+
level: z.number().optional(),
138+
auto: z.string() as z.ZodType<AutoRangeKeys>,
139+
useAuto: z.boolean().optional(),
140+
userTriggered: z.boolean().optional(),
141+
})
142+
.refine(
143+
(data) => {
144+
// If useAuto is false, width and level must be present
145+
if (
146+
data.useAuto === false &&
147+
(data.width === undefined || data.level === undefined)
148+
) {
149+
return false;
150+
}
151+
return true;
152+
},
153+
{
154+
message: 'width and level are required when useAuto is false',
155+
}
156+
) satisfies z.ZodType<WindowLevelConfig>;
141157

142158
const SliceConfig = z.object({
143159
slice: z.number(),

src/store/image-stats.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineStore } from 'pinia';
22
import { reactive, watch, computed, MaybeRef, unref } from 'vue';
33
import * as Comlink from 'comlink';
44
import vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';
5+
import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
56
import { vtkFieldRef } from '@/src/core/vtk/vtkFieldRef';
67
import { WLAutoRanges, WL_HIST_BINS } from '@/src/constants';
78
import { HistogramWorker } from '@/src/utils/histogram.worker';
@@ -17,8 +18,8 @@ export type ImageStats = {
1718
};
1819

1920
async function computeAutoRangeValues(
20-
imageData: ReturnType<typeof useImage>['imageData']['value'],
21-
isImageLoading: ReturnType<typeof useImage>['isLoading']['value']
21+
imageData: vtkImageData,
22+
isImageLoading: boolean
2223
): Promise<Record<string, [number, number]>> {
2324
if (isImageLoading || !imageData) {
2425
return {};

src/store/view-configs/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export interface VolumeColorConfig {
3636
}
3737

3838
export interface WindowLevelConfig {
39-
width: number;
40-
level: number;
39+
width?: number;
40+
level?: number;
4141
auto: keyof typeof WLAutoRanges; // User-selected percentile range
4242
useAuto?: boolean; // Whether to use the percentage histogram range
4343
userTriggered?: boolean; // Whether the user has changed the window/level

0 commit comments

Comments
 (0)