Skip to content

Commit

Permalink
feat(configJson): add io.matchNames option
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Apr 29, 2024
1 parent f53f5e4 commit 72c920c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
18 changes: 17 additions & 1 deletion documentation/content/doc/configuration_file.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,26 @@ VolView will include in the volview.zip file.
}
```

These are the supported file formats:
Working segment group file formats:

hdf5, iwi.cbor, mha, nii, nii.gz, nrrd, vtk

## Automatic Segment Groups by File Name

When loading files, VolView can automatically convert images to segment groups
if they follow this naming convention: An image with name like `foo.segmentation.bar`
will be converted to a segment group for a base image named like `foo.baz`.
The key is the `segmentation` extension to identify the segment group image.
Also the `matchNames` key must be set to `true`. The default is false.

```json
{
"io": {
"matchNames": true
}
}
```

## Keyboard Shortcuts

Configure the keys to activate tools, change selected labels, and more.
Expand Down
3 changes: 3 additions & 0 deletions src/io/import/configJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useViewStore } from '@/src/store/views';
import { actionToKey } from '@/src/composables/useKeyboardShortcuts';
import { useSegmentGroupStore } from '@/src/store/segmentGroups';
import { AnnotationToolStore } from '@/src/store/tools/useAnnotationTool';
import useLoadDataStore from '@/src/store/load-data';

const layout = z
.object({
Expand Down Expand Up @@ -59,6 +60,7 @@ const labels = z
const io = z
.object({
segmentGroupSaveFormat: z.string().optional(),
matchNames: z.boolean().optional(),
})
.optional();

Expand Down Expand Up @@ -129,6 +131,7 @@ const applyIo = (manifest: Config) => {

if (manifest.io.segmentGroupSaveFormat)
useSegmentGroupStore().saveFormat = manifest.io.segmentGroupSaveFormat;
useLoadDataStore().matchNames = manifest.io.matchNames ?? false;
};

export const applyConfig = (manifest: Config) => {
Expand Down
18 changes: 11 additions & 7 deletions src/store/load-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,14 @@ function loadLayers(
// - DataSources that have a name like foo.segmentation.bar and the primary DataSource is named foo.baz
function loadSegmentations(
primaryDataSource: VolumeResult,
succeeded: Array<PipelineResultSuccess<ImportResult>>
succeeded: Array<PipelineResultSuccess<ImportResult>>,
matchNames: boolean
) {
const matchingNames = filterMatchingNames(
primaryDataSource,
succeeded,
'segmentation'
).filter(isVolumeResult); // filter out models
const matchingNames = matchNames
? filterMatchingNames(primaryDataSource, succeeded, 'segmentation').filter(
isVolumeResult // filter out models
)
: [];

const dicomStore = useDICOMStore();
const otherSegVolumesInStudy = filterOtherVolumesInStudy(
Expand Down Expand Up @@ -297,6 +298,8 @@ const useLoadDataStore = defineStore('loadData', () => {
};
};

const matchNames = ref(false);

const loadDataSources = wrapWithLoading(async (sources: DataSource[]) => {
const dataStore = useDatasetStore();

Expand All @@ -316,7 +319,7 @@ const useLoadDataStore = defineStore('loadData', () => {
const selection = toDataSelection(primaryDataSource);
dataStore.setPrimarySelection(selection);
loadLayers(primaryDataSource, succeeded);
loadSegmentations(primaryDataSource, succeeded);
loadSegmentations(primaryDataSource, succeeded, matchNames.value);
} // then must be primaryDataSource.type === 'model'
}

Expand All @@ -340,6 +343,7 @@ const useLoadDataStore = defineStore('loadData', () => {

return {
isLoading,
matchNames,
loadDataSources,
};
});
Expand Down

0 comments on commit 72c920c

Please sign in to comment.