Mercurial > gemma
comparison pkg/octree/loader.go @ 1879:9a2fbeaabd52 dev-pdf-generation
merging in from branch default
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Tue, 15 Jan 2019 10:07:10 +0100 |
parents | f4dcbe8941a1 |
children | 86c7a023400e |
comparison
equal
deleted
inserted
replaced
1878:f030182f82f1 | 1879:9a2fbeaabd52 |
---|---|
16 import ( | 16 import ( |
17 "bufio" | 17 "bufio" |
18 "bytes" | 18 "bytes" |
19 "encoding/binary" | 19 "encoding/binary" |
20 "log" | 20 "log" |
21 "os" | |
22 | 21 |
23 "github.com/golang/snappy" | 22 "github.com/golang/snappy" |
24 ) | 23 ) |
25 | 24 |
26 func loadReader(r *bufio.Reader) (*Tree, error) { | 25 func loadReader(r *bufio.Reader) (*Tree, error) { |
28 | 27 |
29 if err := binary.Read(r, binary.LittleEndian, &tree.EPSG); err != nil { | 28 if err := binary.Read(r, binary.LittleEndian, &tree.EPSG); err != nil { |
30 return nil, err | 29 return nil, err |
31 } | 30 } |
32 | 31 |
33 log.Printf("EPSG: %d\n", tree.EPSG) | 32 log.Printf("info: EPSG: %d\n", tree.EPSG) |
34 | 33 |
35 if err := tree.Min.Read(r); err != nil { | 34 if err := tree.Min.Read(r); err != nil { |
36 return nil, err | 35 return nil, err |
37 } | 36 } |
38 | 37 |
39 if err := tree.Max.Read(r); err != nil { | 38 if err := tree.Max.Read(r); err != nil { |
40 return nil, err | 39 return nil, err |
41 } | 40 } |
42 | 41 |
43 log.Printf("BBOX: [[%f, %f, %f], [%f, %f, %f]]\n", | 42 log.Printf("info: BBOX: [[%f, %f, %f], [%f, %f, %f]]\n", |
44 tree.Min.X, tree.Min.Y, tree.Min.Z, | 43 tree.Min.X, tree.Min.Y, tree.Min.Z, |
45 tree.Max.X, tree.Max.Y, tree.Max.Z) | 44 tree.Max.X, tree.Max.Y, tree.Max.Z) |
46 | 45 |
47 var numVertices uint32 | 46 var numVertices uint32 |
48 if err := binary.Read(r, binary.LittleEndian, &numVertices); err != nil { | 47 if err := binary.Read(r, binary.LittleEndian, &numVertices); err != nil { |
49 return nil, err | 48 return nil, err |
50 } | 49 } |
51 | 50 |
52 log.Printf("vertices: %d\n", numVertices) | 51 log.Printf("info: vertices: %d\n", numVertices) |
53 | 52 |
54 vertices := make([]Vertex, numVertices) | 53 vertices := make([]Vertex, numVertices) |
55 tree.vertices = vertices | 54 tree.vertices = vertices |
56 | 55 |
57 for i := range vertices { | 56 for i := range vertices { |
63 var numTriangles uint32 | 62 var numTriangles uint32 |
64 if err := binary.Read(r, binary.LittleEndian, &numTriangles); err != nil { | 63 if err := binary.Read(r, binary.LittleEndian, &numTriangles); err != nil { |
65 return nil, err | 64 return nil, err |
66 } | 65 } |
67 | 66 |
68 log.Printf("triangles: %d\n", numTriangles) | 67 log.Printf("info: triangles: %d\n", numTriangles) |
69 | 68 |
70 indices := make([]int32, 3*numTriangles) | 69 indices := make([]int32, 3*numTriangles) |
71 triangles := make([][]int32, numTriangles) | 70 triangles := make([][]int32, numTriangles) |
72 tree.triangles = triangles | 71 tree.triangles = triangles |
73 | 72 |
91 var numNodes uint32 | 90 var numNodes uint32 |
92 if err := binary.Read(r, binary.LittleEndian, &numNodes); err != nil { | 91 if err := binary.Read(r, binary.LittleEndian, &numNodes); err != nil { |
93 return nil, err | 92 return nil, err |
94 } | 93 } |
95 | 94 |
96 log.Printf("num nodes: %d\n", numNodes) | 95 log.Printf("info: num nodes: %d\n", numNodes) |
97 | 96 |
98 tree.index = make([]int32, numNodes) | 97 tree.index = make([]int32, numNodes) |
99 entries := tree.index[1:] | 98 entries := tree.index[1:] |
100 | 99 |
101 last = 0 | 100 last = 0 |
110 } | 109 } |
111 | 110 |
112 return tree, nil | 111 return tree, nil |
113 } | 112 } |
114 | 113 |
115 func LoadTree(fname string) (*Tree, error) { | 114 func deserialize(data []byte) (*Tree, error) { |
116 | |
117 f, err := os.Open(fname) | |
118 if err != nil { | |
119 return nil, err | |
120 } | |
121 defer f.Close() | |
122 return loadReader( | |
123 bufio.NewReader( | |
124 snappy.NewReader(f))) | |
125 } | |
126 | |
127 func Deserialize(data []byte) (*Tree, error) { | |
128 return loadReader( | 115 return loadReader( |
129 bufio.NewReader( | 116 bufio.NewReader( |
130 snappy.NewReader( | 117 snappy.NewReader( |
131 bytes.NewReader(data)))) | 118 bytes.NewReader(data)))) |
132 } | 119 } |