Mercurial > gemma
annotate cmd/tin2octree/builder.go @ 718:c0bba602b60e octree
octree: define a type for LineStringZ.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 21 Sep 2018 14:47:44 +0200 |
parents | b17e3ce53285 |
children | b0bd242ff821 |
rev | line source |
---|---|
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package main |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import ( |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 "encoding/binary" |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 "io" |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 "log" |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 ) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 type treeBuilder struct { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 t *tin |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 nodes int |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 leaves int |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 index []int32 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 var cubes = [8][2]vertex{ |
682
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
17 makeCube(0), |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
18 makeCube(1), |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
19 makeCube(2), |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
20 makeCube(3), |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
21 makeCube(4), |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
22 makeCube(5), |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
23 makeCube(6), |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
24 makeCube(7), |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
25 } |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
26 |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
27 func makeCube(i int) [2]vertex { |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
28 var d vertex |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
29 if i&1 == 1 { |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
30 d.x = 0.5 |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
31 } |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
32 if i&2 == 2 { |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
33 d.y = 0.5 |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
34 } |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
35 if i&4 == 4 { |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
36 d.z = 0.5 |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
37 } |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
38 return [2]vertex{ |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
39 vertex{0.0, 0.0, 0.0}.add(d), |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
40 vertex{0.5, 0.5, 0.5}.add(d), |
b17e3ce53285
octree: simplified cube indexing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
678
diff
changeset
|
41 } |
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 func (tb *treeBuilder) build() { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 triangles := make([]int32, len(tb.t.triangles)) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 for i := range triangles { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 triangles[i] = int32(i) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 tb.index = append(tb.index, 0) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 tb.buildRecursive(triangles, tb.t.min, tb.t.max, 0) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 tb.index[0] = int32(len(tb.index)) |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
671
diff
changeset
|
55 log.Printf("num nodes: %d\n", tb.index[0]) |
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 log.Printf("nodes: %d leaves: %d index %d\n", |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 tb.nodes, tb.leaves, tb.index[0]) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 func (tb *treeBuilder) buildRecursive( |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 triangles []int32, |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 min, max vertex, |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 depth int, |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 ) int32 { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 if len(triangles) <= 16 || depth > 8 { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 pos := len(tb.index) |
678
7bb961d750b6
octree: traverse horizontally over tree to find out which triangles to process.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
675
diff
changeset
|
68 tb.index = append(tb.index, int32(len(triangles))) |
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 tb.index = append(tb.index, triangles...) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 //log.Printf("leaf entries: %d (%d)\n", len(triangles), depth) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 tb.leaves++ |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 return int32(-(pos + 1)) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 pos := len(tb.index) |
675
1cb565d244cf
octree: Allocate 8 child nodes per node not 4.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
76 tb.index = append(tb.index, |
1cb565d244cf
octree: Allocate 8 child nodes per node not 4.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
77 0, 0, 0, 0, |
1cb565d244cf
octree: Allocate 8 child nodes per node not 4.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
78 0, 0, 0, 0) |
661
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 bbox := interpolate(min, max) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 bboxes := make([][2]vertex, len(cubes)) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 for i := range cubes { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 bboxes[i] = [2]vertex{ |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 bbox(cubes[i][0]), |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 bbox(cubes[i][1]), |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 var quandrants [8][]int32 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 for _, tri := range triangles { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 triangle := tb.t.triangles[tri] |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 v0 := tb.t.vertices[triangle[0]] |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 v1 := tb.t.vertices[triangle[1]] |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 v2 := tb.t.vertices[triangle[2]] |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 l := v0 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 l.minimize(v1) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 l.minimize(v2) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 h := v0 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 h.maximize(v1) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 h.maximize(v2) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 for i := range bboxes { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 if !(h.less(bboxes[i][0]) || bboxes[i][1].less(l)) { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 quandrants[i] = append(quandrants[i], tri) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 for i := range quandrants { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 if len(quandrants[i]) > 0 { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 child := tb.buildRecursive( |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 quandrants[i], |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 bboxes[i][0], bboxes[i][1], |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 depth+1) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 tb.index[pos+i] = child |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 tb.nodes++ |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 return int32(pos) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 func (tb *treeBuilder) Serialize(w io.Writer) error { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 var buf [binary.MaxVarintLen32]byte |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 if err := binary.Write(w, binary.LittleEndian, tb.index[0]); err != nil { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 return err |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 var last int32 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 var written int |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 for _, x := range tb.index[1:] { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 delta := x - last |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 n := binary.PutVarint(buf[:], int64(delta)) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 for p := buf[:n]; len(p) > 0; p = p[n:] { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 var err error |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 if n, err = w.Write(p); err != nil { |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 return err |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 written += n |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 last = x |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 } |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 log.Printf("compressed octree index in bytes: %d (%d)\n", |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 written, 4*len(tb.index)) |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 return nil |
af1d4d44a88a
Experimental tin octree indexer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 } |