-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolume.go
125 lines (115 loc) · 2.63 KB
/
volume.go
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
package rendr
import (
"fmt"
"github.com/sbinet/npyio"
"gonum.org/v1/gonum/mat"
"math"
"os"
)
func rndVolumeNew() *rndVolume {
ret := rndVolume{
Content: "",
Size: [3]uint{0},
ItoW: [16]float64{0},
Dtype: rndTypeUnknown,
Data: nil,
}
return &ret
}
func (v *rndVolume) loadVolume(datafile string, metadatafile string) {
f, _ := os.Open(datafile)
r, err := npyio.NewReader(f)
if err!=nil || r==nil{
fmt.Printf("Failed to open file %s\n", datafile)
os.Exit(1)
}
fmt.Println(r.Header)
shape := r.Header.Descr.Shape
v.Size = [3]uint{uint(shape[0]),uint(shape[1]),uint(shape[2])}
raw := make([]float64, shape[0]*shape[1]*shape[2])
err = r.Read(&raw)
if err!=nil {
fmt.Printf(err.Error())
}
v.Data = raw
v.Dtype = rndTypefloat64
f, _ = os.Open(metadatafile)
r2, err2 := npyio.NewReader(f)
if err2!=nil || r2==nil {
fmt.Printf("failed to open file %s\n", metadatafile)
os.Exit(1)
}
shape2 := r2.Header.Descr.Shape
fmt.Println(shape2)
data2:= make([]float64, shape2[0]*shape2[1])
err2 = r2.Read(&data2)
if err2!=nil {
fmt.Printf(err.Error())
}
copy(v.ItoW[:], data2)
}
func (txf *_txf) loadLut(datafile string) {
f, _ := os.Open(datafile)
r, err := npyio.NewReader(f)
if err!=nil || r==nil{
fmt.Printf("Failed to open file %s\n", datafile)
os.Exit(1)
}
fmt.Println(r.Header)
shape := r.Header.Descr.Shape
txf.len = uint(shape[1])
raw := make([]float64, shape[0]*shape[1])
err = r.Read(&raw)
if err!=nil {
fmt.Printf(err.Error())
os.Exit(1)
}
txf.rgba = raw
}
func (ctx *rndCtx) rndCtxLightUpdate() {
var vdir = [4]float64{
ctx.Light.dir[0], ctx.Light.dir[1], ctx.Light.dir[2], 0,
}
vtowMat := mat.NewDense(4,4,ctx.Cam.VtoW[:])
vdirVec := mat.NewVecDense(4, vdir[:])
var tmp [4]float64
result := mat.NewVecDense(4, tmp[:])
result.MulVec(vtowMat, vdirVec)
dist:= math.Sqrt(tmp[0]*tmp[0] + tmp[1]*tmp[1] + tmp[2]*tmp[2])
ctx.Light.xyz = [3]float64{
tmp[0]/dist, tmp[1]/dist,tmp[2]/dist,
}
}
func rndImageNew() *rndImage {
return &rndImage{
Content: "",
Channel: 0,
Size: [2]uint{},
Dtype: 0,
Data: nil,
}
}
func rndNewRay() *rndRay {
return &rndRay{
hi: 0,
vi: 0,
result: [4]float64{},
sms0: [2]int64{},
sms1: [2]int64{},
millisecs: 0,
r_img: [3]float64{},
r0: [3]float64{},
r_step: [3]float64{},
rgb: [3]float64{},
rgb_material: [3]float64{},
k: 0,
set: 0,
T: 0,
delta: 0,
p: [4]float64{},
mid_result: [4]float64{},
litresult: [4]float64{},
VdirView: [4]float64{},
Vdir: [4]float64{},
}
}