Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { Component, Input, OnChanges, SimpleChanges, ViewChild } from "@angular/core";
import { Store } from "@ngrx/store";
import { Subject } from "rxjs";
import { ngViewerActionAddNgLayer } from "src/services/state/ngViewerState/actions";
import { getNgIds, getMultiNgIdsRegionsLabelIndexMap } from "../constants";
import { IViewer, TViewerEvent } from "../../viewer.interface";
import { NehubaViewerUnit } from "../nehubaViewer/nehubaViewer.component";
import { NehubaViewerContainerDirective } from "../nehubaViewerInterface/nehubaViewerInterface.directive";
interface INgLayerInterface {
name: string // displayName
source: string
mixability: string // base | mixable | nonmixable
annotation?: string //
id?: string // unique identifier
visible?: boolean
shader?: string
transform?: any
}
@Component({
selector: 'iav-cmp-viewer-nehuba-glue',
templateUrl: './nehubaViewerGlue.template.html',
styleUrls: [
'./nehubaViewerGlue.style.css'
]
})
export class NehubaGlueCmp implements IViewer, OnChanges{
@ViewChild(NehubaViewerContainerDirective, { static: true })
public nehubaContainerDirective: NehubaViewerContainerDirective
public viewerEvents$ = new Subject<TViewerEvent>()
private viewerUnit: NehubaViewerUnit
private ngLayersRegister: {layers: INgLayerInterface[]} = {
layers: []
}
private multiNgIdsRegionsLabelIndexMap: Map<string, Map<number, any>>
@Input()
public selectedParcellation: any
@Input()
public selectedTemplate: any
ngOnChanges(sc: SimpleChanges){
const {
selectedParcellation,
selectedTemplate
} = sc
if (selectedTemplate.currentValue !== selectedTemplate.previousValue) {
this.loadTmpl(selectedTemplate.currentValue, selectedParcellation.currentValue)
} else if (selectedParcellation.currentValue !== selectedParcellation.previousValue) {
}
}
private loadParc(parcellation: any) {
/**
* parcellaiton may be undefined
*/
if ( !(parcellation && parcellation.regions)) {
return
}
/**
* first, get all all the ngIds, including parent id from parcellation (if defined)
*/
const ngIds = getNgIds(parcellation.regions).concat( parcellation.ngId ? parcellation.ngId : [])
this.multiNgIdsRegionsLabelIndexMap = getMultiNgIdsRegionsLabelIndexMap(parcellation)
this.viewerUnit.multiNgIdsLabelIndexMap = this.multiNgIdsRegionsLabelIndexMap
this.viewerUnit.auxilaryMeshIndices = parcellation.auxillaryMeshIndices || []
/* TODO replace with proper KG id */
/**
* need to set unique array of ngIds, or else workers will be overworked
*/
this.viewerUnit.ngIds = Array.from(new Set(ngIds))
}
private async loadTmpl(template: any, parcellation: any) {
this.nehubaContainerDirective.createNehubaInstance(template)
this.viewerUnit = this.nehubaContainerDirective.nehubaViewerInstance
const foundParcellation = parcellation
&& template?.parcellations?.find(p => parcellation.name === p.name)
this.loadParc(foundParcellation || template.parcellations[0])
const nehubaConfig = template.nehubaConfig
const initialSpec = nehubaConfig.dataset.initialNgState
const {layers} = initialSpec
const dispatchLayers = Object.keys(layers).map(key => {
const layer = {
name : key,
source : layers[key].source,
mixability : layers[key].type === 'image'
? 'base'
: 'mixable',
visible : typeof layers[key].visible === 'undefined'
? true
: layers[key].visible,
transform : typeof layers[key].transform === 'undefined'
? null
: layers[key].transform,
}
this.ngLayersRegister.layers.push(layer)
return layer
})
this.store.dispatch(ngViewerActionAddNgLayer({
layer: dispatchLayers
}))
}
constructor(
private store: Store<any>
){
this.viewerEvents$.next({
type: 'MOUSEOVER_ANNOTATION',
data: {}
})
}
handleViewerLoadedEvent(flag: boolean) {
this.viewerEvents$.next({
type: 'VIEWERLOADED',
data: flag
})
}
}