Newer
Older
import { Component, AfterViewInit, OnDestroy } from "@angular/core";
import * as export_nehuba from 'export_nehuba'
import 'export_nehuba/dist/min/chunk_worker.bundle.js'
import { Observable, Observer } from "rxjs";
import { takeUntil } from 'rxjs/operators'
@Component({
templateUrl : './nehubaViewer.template.html',
styleUrls : [
'./nehubaViewer.style.css'
]
})
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
export class NehubaViewerUnit implements AfterViewInit,OnDestroy{
config : any
nehubaViewer : any
parcellationId : string
regionsLabelIndexMap : Map<number,any>
shownSegment$ : any
mouseoverSegment$ : any
private defaultColormap : Map<number,{red:number,green:number,blue:number}>
public mouseOverSegment : number | null
ngAfterViewInit(){
this.nehubaViewer = export_nehuba.createNehubaViewer(this.config,console.warn)
if(this.regionsLabelIndexMap){
this.loadNewParcellation()
}
}
ngOnDestroy(){
this.nehubaViewer.dispose()
this.shownSegment$.unsubscribe()
this.mouseoverSegment$.unsubscribe()
}
public hideAllSeg(){
this.showAllSeg()
this.nehubaViewer.showSegment(0,{
name : this.parcellationId
})
}
public showAllSeg(){
Array.from(this.regionsLabelIndexMap.keys()).forEach(idx=>
this.nehubaViewer.hideSegment(idx,{
name : this.parcellationId
}))
}
public showSegs(array:number[]){
this.showAllSeg()
array.forEach(idx=>
this.nehubaViewer.showSegment(idx,{
name : this.parcellationId
}))
}
private updateColorMap(arrayIdx:number[]){
const set = new Set(arrayIdx)
const newColorMap = new Map(
Array.from(this.defaultColormap.entries())
.map(v=> set.has(v[0]) || set.size === 0 ?
v :
[v[0],{red:255,green:255,blue:255}]) as any
)
this.nehubaViewer.batchAddAndUpdateSegmentColors(newColorMap,{
name:this.parcellationId
})
}
private loadNewParcellation(){
this.nehubaViewer.setMeshesToLoad(
[
...Array.from(this.regionsLabelIndexMap.keys()),
...[65535]
]
)
this.defaultColormap = new Map(
Array.from(
[
...this.regionsLabelIndexMap.entries(),
...[[65535,{}]]
]
).map(val=>([val[0],this.getRgb(val[1].rgb)])) as any)
this.nehubaViewer.batchAddAndUpdateSegmentColors(
this.defaultColormap,
{ name : this.parcellationId })
if(this.shownSegment$) this.shownSegment$.unsubscribe()
if(this.mouseoverSegment$) this.mouseoverSegment$.unsubscribe()
this.shownSegment$ = this.nehubaViewer.getShownSegmentsObservable({
name : this.parcellationId
}).subscribe(arrayIdx=>this.updateColorMap(arrayIdx))
this.mouseoverSegment$ = this.nehubaViewer.mouseOver.segment
.subscribe(obj=>this.mouseOverSegment = obj.segment)
}
private getRgb(rgb?:number[]):{red:number,green:number,blue:number}{
if(typeof rgb === 'undefined' || rgb === null)
return {
red : 255,
green: 255,
blue : 255
}
return {
red : rgb[0],
green: rgb[1],
blue : rgb[2]
}