diff --git a/src/ui/parcellationRegion/region.base.ts b/src/ui/parcellationRegion/region.base.ts index 9f382991a4d07440f9141bda6ce12055b7a6ed7c..3c7fde6c9c5c37e34453c7e0a93ea33efe6b5d4c 100644 --- a/src/ui/parcellationRegion/region.base.ts +++ b/src/ui/parcellationRegion/region.base.ts @@ -1,5 +1,5 @@ import {EventEmitter, Input, Output} from "@angular/core"; -import { Store } from "@ngrx/store"; +import {select, Store} from "@ngrx/store"; import {SET_CONNECTIVITY_REGION} from "src/services/state/viewerState.store"; import { EXPAND_SIDE_PANEL_CURRENT_VIEW, @@ -7,6 +7,8 @@ import { SHOW_SIDE_PANEL_CONNECTIVITY, } from "src/services/stateStore.service"; import { VIEWERSTATE_CONTROLLER_ACTION_TYPES } from "../viewerStateController/viewerState.base"; +import {distinctUntilChanged, shareReplay} from "rxjs/operators"; +import {Observable} from "rxjs"; export class RegionBase { @@ -20,10 +22,40 @@ export class RegionBase { @Output() public closeRegionMenu: EventEmitter<boolean> = new EventEmitter() + public loadedTemplate$: Observable<any[]> + public templateSelected$: Observable<any[]> + public parcellationSelected$: Observable<any[]> + + protected loadedTemplates: any[] + protected selectedTemplate: any + protected selectedParcellation: any + public sameRegionTemplate: any[] = [] + + private parcellationRegions: any[] = [] + constructor( private store$: Store<IavRootStoreInterface>, ) { + const viewerState$ = this.store$.pipe( + select('viewerState'), + shareReplay(1), + ) + + this.loadedTemplate$ = viewerState$.pipe( + select('fetchedTemplates'), + distinctUntilChanged() + ) + + this.templateSelected$ = viewerState$.pipe( + select('templateSelected'), + distinctUntilChanged(), + ) + + this.parcellationSelected$ = viewerState$.pipe( + select('parcellationSelected'), + distinctUntilChanged(), + ) } public navigateToRegion() { @@ -56,4 +88,71 @@ export class RegionBase { connectivityRegion: regionName, }) } + + getSameParcellationTemplates = () => { + // Get All the templates which includes parcellation equal to selected parcellation + // (E.g. if MNI 152 ICBM Jubrain is selected method returns MNI Colin 27) + this.loadedTemplates.forEach(template => { + if (this.selectedTemplate.name !== template.name + && template.parcellations.map(p => p.name).includes(this.selectedParcellation.name)) { + this.sameRegionTemplate.push(template.name) + } + }) + return null + } + + bigBrainJubrainSwitch = () => { + // If Jubrain or bigbrain is selected and clicked region is included in both of them + // push template name to sameRegionTemplate to change template from menu + this.loadedTemplates.forEach(template => { + if(this.selectedTemplate.name === 'Big Brain (Histology)' + && template.parcellations.map( p => p.name).includes('JuBrain Cytoarchitectonic Atlas')) { + + this.parcellationRegions = [] + + this.getAllRegionsFromParcellation(template.parcellations.filter(p => p.name === 'JuBrain Cytoarchitectonic Atlas')[0].regions) + this.parcellationRegions.forEach(pr => { + if (!pr.name.includes(' - left hemisphere')) { + if (pr.name.includes(' - right hemisphere')) pr.name = pr.name.replace(' - right hemisphere','') + if (!this.sameRegionTemplate.includes(template.name)) this.sameRegionTemplate.push(template.name) + } + }) + } + else if(this.selectedParcellation.name === 'JuBrain Cytoarchitectonic Atlas' + && template.name === 'Big Brain (Histology)') { + let exploreRegion = this.region.name + if (exploreRegion.includes(' - right hemisphere')) exploreRegion = exploreRegion.replace(' - right hemisphere','') + if (exploreRegion.includes(' - left hemisphere')) exploreRegion = exploreRegion.replace(' - left hemisphere','') + this.getAllRegionsFromParcellation(template.parcellations.filter(p => p.name === 'Cytoarchitectonic Maps')[0].regions) + if (this.parcellationRegions.map(pr => pr.name).includes(exploreRegion)) this.sameRegionTemplate.push(template.name) + } + }) + } + + selectTemplate(templateName) { + this.closeRegionMenu.emit() + this.store$.dispatch({ + type: VIEWERSTATE_CONTROLLER_ACTION_TYPES.SELECT_TEMPLATE_WITH_NAME, + payload: { + name: templateName, + }, + }) + } + + + public getAllRegionsFromParcellation = (regions) => { + for (const region of regions) { + if (region.children && region.children.length) { + this.getAllRegionsFromParcellation(region.children) + } else { + this.parcellationRegions.push(region) + } + } + } + + + + + + }