-
Notifications
You must be signed in to change notification settings - Fork 1
/
nimbus_2D.js
95 lines (87 loc) · 2.87 KB
/
nimbus_2D.js
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
import { getColor } from './nimbus_common.js';
var canvas = document.getElementById( '2dAmp' );
var canvasRadial = document.getElementById( '2dRad' );
var ctxAmpl = canvas.getContext('2d');
var ctxRad = canvasRadial.getContext('2d');
var imageDataAmpl = ctxAmpl.getImageData(0, 0, 352,288);
var imageDataRad = ctxRad.getImageData(0, 0, 352,288);
export function render2Dscene( arr, conf, distMin, distMax) {
var ampDisp = new Float32Array(arr.length);
var minAmp = 100000;
var maxAmp = 0;
for(var i = 0; i < arr.length; i++) {
ampDisp[i] = Math.log(arr[i]+1);
minAmp = Math.min(minAmp, ampDisp[i]);
maxAmp = Math.max(maxAmp, ampDisp[i]);
}
maxAmp = Math.max(maxAmp, Math.log(4095+1));
minAmp = 0;
for(var i = 0; i < arr.length; i++) {
if (conf[i] === 0 || conf[i] === 4) //0 valid_normal, 4 valid_short
{
var r = (ampDisp[i]-minAmp)/(maxAmp-minAmp);
var g = (ampDisp[i]-minAmp)/(maxAmp-minAmp);
var b = (ampDisp[i]-minAmp)/(maxAmp-minAmp);
imageDataAmpl.data[4*i] = r*255;
imageDataAmpl.data[4*i+1] = g*255;
imageDataAmpl.data[4*i+2] = b*255;
imageDataAmpl.data[4*i+3] = 255;
}
else if (conf[i] == 2)
{
imageDataAmpl.data[4*i] = 255;
imageDataAmpl.data[4*i+1] = 255;
imageDataAmpl.data[4*i+2] = 255;
imageDataAmpl.data[4*i+3] = 255;
}
else if (conf[i] == 1 || conf[i] == 3)
{
imageDataAmpl.data[4*i] = 0;
imageDataAmpl.data[4*i+1] = 0;
imageDataAmpl.data[4*i+2] = 0;
imageDataAmpl.data[4*i+3] = 255;
}
}
ctxAmpl.putImageData(imageDataAmpl, 0, 0);
}
export function render2DRadialscene( arr, conf, distMin, distMax) {
for(var i = 0; i < arr.length; i++) {
if (conf[i] === 0 || conf[i] === 4) //0 valid_normal, 4 valid_short
{
var col = getColor(arr[i], distMin, distMax);
var r = col[0];
var g = col[1];
var b = col[2];
imageDataRad.data[4*i] = r*255;//(z_arr[i])/255;
imageDataRad.data[4*i+1] = g*255;//(z_arr[i])/255;
imageDataRad.data[4*i+2] = b*255;//(z_arr[i])/255;
imageDataRad.data[4*i+3] = 255;
}
//else if(conf[i] === 4)
//{
// var col = getColor(arr[i], distMin, distMax);
// var r = col[0];
// var g = col[1];
// var b = col[2];
// imageDataRad.data[4*i] = r*220;
// imageDataRad.data[4*i+1] = g*220;
// imageDataRad.data[4*i+2] = b*220;
// imageDataRad.data[4*i+3] = 220;
//}
else if (conf[i] == 2)
{
imageDataRad.data[4*i] = 255;
imageDataRad.data[4*i+1] = 255;
imageDataRad.data[4*i+2] = 255;
imageDataRad.data[4*i+3] = 255;
}
else if (conf[i] == 1 || conf[i] == 3)
{
imageDataRad.data[4*i] = 0;
imageDataRad.data[4*i+1] = 0;
imageDataRad.data[4*i+2] = 0;
imageDataRad.data[4*i+3] = 255;
}
}
ctxRad.putImageData(imageDataRad, 0, 0);
}