diff --git a/src/messaging/nmvSwc/index.ts b/src/messaging/nmvSwc/index.ts index 6dc9abb482da80c3ffaf76c2478211587de31255..d7bd4d6a767d013e2e357cb98d79202a7ecfed08 100644 --- a/src/messaging/nmvSwc/index.ts +++ b/src/messaging/nmvSwc/index.ts @@ -13,12 +13,30 @@ const NM_IDS = { MNI152_2009C_ASYM: 'hbp:ICBM_Asym_r2009c(um)', } -export const IAV_IDS = { +const IAV_IDS = { AMBA_V3: 'minds/core/referencespace/v1.0.0/265d32a0-3d84-40a5-926f-bf89f68212b9', WAXHOLM_V1_01: 'minds/core/referencespace/v1.0.0/d5717c4a-0fa1-46e6-918c-b8003069ade8', BIG_BRAIN: 'minds/core/referencespace/v1.0.0/a1655b99-82f1-420f-a3c2-fe80fd4c8588', COLIN: 'minds/core/referencespace/v1.0.0/7f39f7be-445b-47c0-9791-e971c0b6d992', MNI152_2009C_ASYM: 'minds/core/referencespace/v1.0.0/dafcffc5-4826-4bf1-8ff6-46b8a31ff8e2', +} as const + +type SPACE_ID = typeof IAV_IDS[keyof typeof IAV_IDS] + +const DEFAULT_PARC: Record<SPACE_ID, string> = { + [IAV_IDS.AMBA_V3]: "minds/core/parcellationatlas/v1.0.0/05655b58-3b6f-49db-b285-64b5a0276f83", + [IAV_IDS.WAXHOLM_V1_01]: "minds/core/parcellationatlas/v1.0.0/ebb923ba-b4d5-4b82-8088-fa9215c2e1fe-v4", + [IAV_IDS.BIG_BRAIN]: "minds/core/parcellationatlas/v1.0.0/94c1125b-b87e-45e4-901c-00daee7f2579-290", + [IAV_IDS.COLIN]: "minds/core/parcellationatlas/v1.0.0/94c1125b-b87e-45e4-901c-00daee7f2579-300", + [IAV_IDS.MNI152_2009C_ASYM]: "minds/core/parcellationatlas/v1.0.0/94c1125b-b87e-45e4-901c-00daee7f2579-300", +} + +const DEFAULT_ATLAS: Record<SPACE_ID, string> = { + [IAV_IDS.AMBA_V3]: "juelich/iav/atlas/v1.0.0/2", + [IAV_IDS.WAXHOLM_V1_01]: "minds/core/parcellationatlas/v1.0.0/522b368e-49a3-49fa-88d3-0870a307974a", + [IAV_IDS.BIG_BRAIN]: "juelich/iav/atlas/v1.0.0/1", + [IAV_IDS.COLIN]: "juelich/iav/atlas/v1.0.0/1", + [IAV_IDS.MNI152_2009C_ASYM]: "juelich/iav/atlas/v1.0.0/1", } /** @@ -60,6 +78,14 @@ const translateSpace = (spaceId: string) => { return null } +const getDefaultParcellation = (spaceId: SPACE_ID) => { + return DEFAULT_PARC[spaceId] +} + +const getAtlas = (spaceId: SPACE_ID) => { + return DEFAULT_ATLAS[spaceId] +} + const getVoxelFromSpace = (spaceId: string) => { for (const key in NM_IDS){ if (NM_IDS[key] === spaceId) return IAV_VOXEL_SIZES_NM[key] @@ -97,7 +123,15 @@ export const processJsonLd = (json: { [key: string]: any }): Observable<IMessagi subject.next({ type: 'loadTemplate', payload: { - ['@id']: iavSpace + template: { + id: iavSpace + }, + parcellation: { + id: getDefaultParcellation(iavSpace) + }, + atlas: { + id: getAtlas(iavSpace) + } } }) @@ -130,9 +164,9 @@ export const processJsonLd = (json: { [key: string]: any }): Observable<IMessagi * 1e3 / voxelSize */ const scaleUmToVoxelFixed = [ - 1e3 / voxelSize[0], - 1e3 / voxelSize[1], - 1e3 / voxelSize[2], + voxelSize[0], + voxelSize[1], + voxelSize[2], ] // NG translation works on nm scale const scaleUmToNm = 1e3 diff --git a/src/messaging/types.ts b/src/messaging/types.ts index 6eb83f851f40a7da56d1e8aad529d573a32f31a9..2786617dc244902b234647836983f9f036cd4f79 100644 --- a/src/messaging/types.ts +++ b/src/messaging/types.ts @@ -1,7 +1,15 @@ import { InjectionToken } from "@angular/core"; interface ILoadTemplateByIdPayload { - ['@id']: string + atlas: { + id: string + } + template: { + id: string + } + parcellation: { + id: string + } } interface IResourceType { diff --git a/src/messagingGlue.ts b/src/messagingGlue.ts index 33506b4852f4774b142bb79d4e7e2916057572bd..ae415e68cff96abaaf964e6606a2a93df8cbc782 100644 --- a/src/messagingGlue.ts +++ b/src/messagingGlue.ts @@ -40,7 +40,18 @@ export class MessagingGlue implements IWindowMessaging, OnDestroy { * and enforce single direction flow when possible */ loadTempladById( payload: IMessagingActionTmpl['loadTemplate'] ){ - const atlasId = this.tmplSpIdToAtlasId.get(payload['@id']) + const { + parcellation: { + id: parcellationId + }, + template: { + id: templateId + }, + atlas: { + id: atlasId + } + } = payload + if (!atlasId) { return this.store.dispatch( generalActions.generalActionError({ @@ -51,7 +62,8 @@ export class MessagingGlue implements IWindowMessaging, OnDestroy { this.store.dispatch( atlasSelection.actions.selectATPById({ atlasId, - templateId: payload["@id"] + templateId, + parcellationId }) ) } diff --git a/src/state/atlasSelection/effects.ts b/src/state/atlasSelection/effects.ts index ce8f52dc9b38828a0b42f239f88ec9d9f0d9685f..cf5dcdf1b2ec753291f699413e0a6d4cb92bd1b1 100644 --- a/src/state/atlasSelection/effects.ts +++ b/src/state/atlasSelection/effects.ts @@ -315,9 +315,59 @@ export class Effect { */ onSelectATPById = createEffect(() => this.action.pipe( ofType(actions.selectATPById), - mapTo(mainActions.generalActionError({ - message: `NYI, onSelectATPById` - })) + switchMap(({ atlasId, parcellationId, templateId }) => + this.sapiSvc.atlases$.pipe( + switchMap(atlases => { + + const selectedAtlas = atlasId + ? atlases.find(atlas => atlas.id === atlasId) + : atlases[0] + + if (!selectedAtlas) { + return of( + mainActions.generalActionError({ + message: `Atlas with id ${atlasId} not found!` + }) + ) + } + return this.sapiSvc.getAllParcellations(selectedAtlas).pipe( + switchMap(parcs => { + const selectedParcellation = parcellationId + ? parcs.find(parc => parc.id === parcellationId) + : parcs[0] + if (!selectedParcellation) { + return of( + mainActions.generalActionError({ + message: `Parcellation with id ${parcellationId} not found!` + }) + ) + } + return this.sapiSvc.getSupportedTemplates(selectedAtlas, selectedParcellation).pipe( + switchMap(templates => { + const selectedTemplate = templateId + ? templates.find(tmpl => tmpl.id === templateId) + : templates[0] + if (!selectedTemplate) { + return of( + mainActions.generalActionError({ + message: `Template with id ${templateId} not found` + }) + ) + } + return of( + actions.setAtlasSelectionState({ + selectedAtlas, + selectedParcellation, + selectedTemplate + }) + ) + }) + ) + }) + ) + }) + ) + ) )) onClearViewerMode = createEffect(() => this.action.pipe(