Newer
Older
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
export const NEHUBA_VIEWER_FEATURE_KEY = 'ngViewerFeature'
export interface INgLayerInterface {
name: string // displayName
source: string
mixability: string // base | mixable | nonmixable
annotation?: string //
id?: string // unique identifier
visible?: boolean
shader?: string
transform?: any
}
export function getMultiNgIdsRegionsLabelIndexMap(parcellation: any = {}, inheritAttrsOpt: any = { ngId: 'root' }): Map<string, Map<number, any>> {
const map: Map<string, Map<number, any>> = new Map()
const inheritAttrs = Object.keys(inheritAttrsOpt)
if (inheritAttrs.indexOf('children') >=0 ) throw new Error(`children attr cannot be inherited`)
const processRegion = (region: any) => {
const { ngId: rNgId } = region
const existingMap = map.get(rNgId)
const labelIndex = Number(region.labelIndex)
if (labelIndex) {
if (!existingMap) {
const newMap = new Map()
newMap.set(labelIndex, region)
map.set(rNgId, newMap)
} else {
existingMap.set(labelIndex, region)
}
}
if (region.children && Array.isArray(region.children)) {
for (const r of region.children) {
const copiedRegion = { ...r }
for (const attr of inheritAttrs){
copiedRegion[attr] = copiedRegion[attr] || region[attr] || parcellation[attr]
}
processRegion(copiedRegion)
}
}
}
if (!parcellation) throw new Error(`parcellation needs to be defined`)
if (!parcellation.regions) throw new Error(`parcellation.regions needs to be defined`)
if (!Array.isArray(parcellation.regions)) throw new Error(`parcellation.regions needs to be an array`)
for (const region of parcellation.regions){
const copiedregion = { ...region }
for (const attr of inheritAttrs){
copiedregion[attr] = copiedregion[attr] || parcellation[attr]
}
processRegion(copiedregion)
}
return map
}