Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions src/components/CurrentImageProvider.vue

This file was deleted.

34 changes: 6 additions & 28 deletions src/components/LayoutGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
<div v-for="(item, i) in items" :key="i" class="d-flex flex-equal">
<layout-grid v-if="item.type === 'layout'" :layout="item" />
<div v-else class="layout-item">
<current-image-provider :image-id="selectedImageID">
<component
:is="item.component"
:key="item.id"
:id="item.id"
v-bind="item.props"
/>
</current-image-provider>
<component
:is="item.component"
:key="item.id"
:id="item.id"
v-bind="item.props"
/>
</div>
</div>
</div>
Expand All @@ -23,9 +21,6 @@
<script lang="ts">
import { Component, computed, defineComponent, PropType, toRefs } from 'vue';
import { storeToRefs } from 'pinia';
import { useDatasetStore } from '@/src/store/datasets';
import { useDICOMStore } from '@/src/store/datasets-dicom';
import CurrentImageProvider from '@/src/components/CurrentImageProvider.vue';
import VtkTwoView from './VtkTwoView.vue';
import VtkThreeView from './VtkThreeView.vue';
import { Layout, LayoutDirection } from '../types/layout';
Expand All @@ -45,27 +40,11 @@ export default defineComponent({
required: true,
},
},
components: {
CurrentImageProvider,
},
setup(props) {
const { layout } = toRefs(props);
const viewStore = useViewStore();
const { viewSpecs } = storeToRefs(viewStore);

const selectedImageID = computed(() => {
const { primarySelection } = useDatasetStore();
const { volumeToImageID } = useDICOMStore();

if (primarySelection?.type === 'image') {
return primarySelection.dataID;
}
if (primarySelection?.type === 'dicom') {
return volumeToImageID[primarySelection.volumeKey] || null;
}
return null;
});

const flexFlow = computed(() => {
return layout.value.direction === LayoutDirection.H
? 'flex-column'
Expand Down Expand Up @@ -94,7 +73,6 @@ export default defineComponent({
return {
items,
flexFlow,
selectedImageID,
};
},
});
Expand Down
6 changes: 3 additions & 3 deletions src/components/VtkTwoView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export default defineComponent({
get: () => windowingStore.getConfig(viewID.value, curImageID.value),
set: (newValue) => {
const imageID = curImageID.value;
if (imageID != null && newValue != null) {
if (imageID !== null && newValue != null) {
windowingStore.updateConfig(viewID.value, imageID, newValue);
}
},
Expand All @@ -320,7 +320,7 @@ export default defineComponent({
const windowLevel = computed(() => wlConfig.value?.level);
const dicomInfo = computed(() => {
if (
curImageID.value != null &&
curImageID.value !== null &&
curImageID.value in dicomStore.imageIDToVolumeKey
) {
const volumeKey = dicomStore.imageIDToVolumeKey[curImageID.value];
Expand Down Expand Up @@ -362,7 +362,7 @@ export default defineComponent({
// --- setters --- //

const setSlice = (slice: number) => {
if (curImageID.value != null) {
if (curImageID.value !== null) {
viewSliceStore.updateConfig(viewID.value, curImageID.value, {
slice,
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/tools/SliceScrollTool.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default defineComponent({
range.step,
() => scrollVal.value,
(slice) => {
if (currentImageID.value != null) {
if (currentImageID.value !== null) {
viewSliceStore.updateConfig(viewID.value, currentImageID.value, {
slice,
});
Expand Down
109 changes: 56 additions & 53 deletions src/composables/useCurrentImage.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
import { InjectionKey, Ref, inject } from 'vue';
import { Maybe } from '@/src/types';
import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
import { ImageMetadata } from '@/src/types/image';
import { Vector2 } from '@kitware/vtk.js/types';
import { computed } from 'vue';
import { useDatasetStore } from '../store/datasets';
import { useDICOMStore } from '../store/datasets-dicom';
import { defaultImageMetadata, useImageStore } from '../store/datasets-images';
import { Layer, useLayersStore } from '../store/datasets-layers';
import { useLayersStore } from '../store/datasets-layers';
import { createLPSBounds, getAxisBounds } from '../utils/lps';

type SpatialExtent = {
Sagittal: Vector2;
Coronal: Vector2;
Axial: Vector2;
};

export interface CurrentImageContext {
id: Ref<Maybe<string>>;
imageData: Ref<Maybe<vtkImageData>>;
metadata: Ref<ImageMetadata>;
extent: Ref<SpatialExtent>;
isLoading: Ref<boolean>;
layers: Ref<Layer[]>;
}

export const CurrentImageInjectionKey = Symbol(
'CurrentImage'
) as InjectionKey<CurrentImageContext>;

// Returns a spatially inflated image extent
export function getImageSpatialExtent(imageID: Maybe<string>) {
export function getImageSpatialExtent(imageID: string | null) {
const imageStore = useImageStore();

if (imageID && imageID in imageStore.metadata) {
Expand All @@ -45,38 +24,62 @@ export function getImageSpatialExtent(imageID: Maybe<string>) {
return createLPSBounds();
}

export function getImageMetadata(imageID: Maybe<string>) {
const { metadata } = useImageStore();
return imageID ? metadata[imageID] : defaultImageMetadata();
}
export function useCurrentImage() {
const dataStore = useDatasetStore();
const dicomStore = useDICOMStore();
const imageStore = useImageStore();
const layersStore = useLayersStore();

export function getImageData(imageID: Maybe<string>) {
const { dataIndex } = useImageStore();
return imageID ? dataIndex[imageID] : null;
}
const currentImageID = computed(() => {
const { primarySelection } = dataStore;
const { volumeToImageID } = dicomStore;

export function getIsImageLoading(imageID: Maybe<string>) {
// TODO imageID -> loading status
return !imageID;
}
if (primarySelection?.type === 'image') {
return primarySelection.dataID;
}
if (primarySelection?.type === 'dicom') {
return volumeToImageID[primarySelection.volumeKey] || null;
}
return null;
});

export function getImageLayers(imageID: Maybe<string>) {
const layersStore = useLayersStore();
return layersStore
.getLayers(imageID ? { type: 'image', dataID: imageID } : null)
.filter(({ id }) => id in layersStore.layerImages);
}
const currentImageMetadata = computed(() => {
const { metadata } = imageStore;
const imageID = currentImageID.value;

export function useCurrentImage() {
const context = inject(CurrentImageInjectionKey);
if (!context) throw new Error('useCurrentImage: no CurrentImageContext!');
if (imageID) {
return metadata[imageID];
}
return defaultImageMetadata();
});

const currentImageData = computed(() => {
if (currentImageID.value)
// assumed to be only images for now
return imageStore.dataIndex[currentImageID.value];
return undefined;
});

const currentImageExtent = computed(() =>
getImageSpatialExtent(currentImageID.value)
);

const isImageLoading = computed(() => {
return !!dataStore.primarySelection && !dataStore.primaryDataset;
});

const currentLayers = computed(() =>
layersStore
.getLayers(dataStore.primarySelection)
.filter(({ id }) => id in layersStore.layerImages)
);

return {
currentImageData: context.imageData,
currentImageID: context.id,
currentImageMetadata: context.metadata,
currentImageExtent: context.extent,
isImageLoading: context.isLoading,
currentLayers: context.layers,
currentImageData,
currentImageID,
currentImageMetadata,
currentImageExtent,
isImageLoading,
currentLayers,
};
}
13 changes: 6 additions & 7 deletions src/composables/usePersistCameraConfig.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { manageVTKSubscription } from '@/src/composables/manageVTKSubscription';
import { Ref } from 'vue';
import { Maybe } from '@/src/types';
import { CameraConfig } from '../store/view-configs/types';
import { vtkLPSViewProxy } from '../types/vtk-types';
import useViewCameraStore from '../store/view-configs/camera';

export function usePersistCameraConfig(
viewID: Ref<string>,
dataID: Ref<Maybe<string>>,
dataID: Ref<string | null>,
viewProxy: Ref<vtkLPSViewProxy>,
...toPersist: (keyof CameraConfig)[]
) {
Expand All @@ -20,7 +19,7 @@ export function usePersistCameraConfig(

if (toPersist.indexOf('position') > -1) {
persist.push(() => {
if (dataID.value != null && persistCameraConfig) {
if (dataID.value !== null && persistCameraConfig) {
viewCameraStore.updateConfig(viewID.value, dataID.value, {
position: viewProxy.value.getCamera().getPosition(),
});
Expand All @@ -29,7 +28,7 @@ export function usePersistCameraConfig(
}
if (toPersist.indexOf('viewUp') > -1) {
persist.push(() => {
if (dataID.value != null && persistCameraConfig) {
if (dataID.value !== null && persistCameraConfig) {
viewCameraStore.updateConfig(viewID.value, dataID.value, {
viewUp: viewProxy.value.getCamera().getViewUp(),
});
Expand All @@ -38,7 +37,7 @@ export function usePersistCameraConfig(
}
if (toPersist.indexOf('focalPoint') > -1) {
persist.push(() => {
if (dataID.value != null && persistCameraConfig) {
if (dataID.value !== null && persistCameraConfig) {
viewCameraStore.updateConfig(viewID.value, dataID.value, {
focalPoint: viewProxy.value.getCamera().getFocalPoint(),
});
Expand All @@ -47,7 +46,7 @@ export function usePersistCameraConfig(
}
if (toPersist.indexOf('directionOfProjection') > -1) {
persist.push(() => {
if (dataID.value != null && persistCameraConfig) {
if (dataID.value !== null && persistCameraConfig) {
viewCameraStore.updateConfig(viewID.value, dataID.value, {
directionOfProjection: viewProxy.value
.getCamera()
Expand All @@ -58,7 +57,7 @@ export function usePersistCameraConfig(
}
if (toPersist.indexOf('parallelScale') > -1) {
persist.push(() => {
if (dataID.value != null && persistCameraConfig) {
if (dataID.value !== null && persistCameraConfig) {
viewCameraStore.updateConfig(viewID.value, dataID.value, {
parallelScale: viewProxy.value.getCamera().getParallelScale(),
});
Expand Down
3 changes: 1 addition & 2 deletions src/composables/useSceneBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import vtkAbstractRepresentationProxy from '@kitware/vtk.js/Proxy/Core/AbstractRepresentationProxy';
import { computed, Ref, watch } from 'vue';
import { Maybe } from '@/src/types';
import { useViewStore } from '../store/views';
import { vtkLPSViewProxy } from '../types/vtk-types';
import { arrayEquals } from '../utils';

interface Scene {
baseImage?: Ref<Maybe<string>>;
baseImage?: Ref<string | null>;
labelmaps?: Ref<string[]>;
layers?: Ref<string[]>;
models?: Ref<string[]>;
Expand Down
3 changes: 1 addition & 2 deletions src/store/tools/crop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { MaybeRef } from '@vueuse/core';
import { vec3 } from 'gl-matrix';
import { defineStore } from 'pinia';
import { arrayEqualsWithComparator } from '@/src/utils';
import { Maybe } from '@/src/types';
import { useImageStore } from '../datasets-images';
import { LPSCroppingPlanes } from '../../types/crop';
import { ImageMetadata } from '../../types/image';
Expand Down Expand Up @@ -61,7 +60,7 @@ export const useCropStore = defineStore('crop', () => {
croppingByImageID: {} as Record<string, LPSCroppingPlanes>,
});

const getComputedVTKPlanes = (imageID: MaybeRef<Maybe<string>>) =>
const getComputedVTKPlanes = (imageID: MaybeRef<string | null>) =>
computed(() => {
const id = unref(imageID);
if (id && id in state.croppingByImageID && id in imageStore.metadata) {
Expand Down
3 changes: 1 addition & 2 deletions src/store/tools/paint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Manifest, StateFile } from '@/src/io/state-file/schema';
import { computed, ref, watch } from 'vue';
import { vec3 } from 'gl-matrix';
import { defineStore } from 'pinia';
import { Maybe } from '@/src/types';
import { Tools } from './types';
import { useLabelmapStore } from '../datasets-labelmaps';

Expand Down Expand Up @@ -35,7 +34,7 @@ export const usePaintToolStore = defineStore('paint', () => {

// --- actions --- //

function selectOrCreateLabelmap(imageID: Maybe<string>) {
function selectOrCreateLabelmap(imageID: string | null) {
if (!imageID) {
activeLabelmapID.value = null;
return;
Expand Down