Mercurial > gemma
annotate pkg/octree/builder.go @ 2475:25e2578b76f3 octree-diff
Fixed counting of nodes.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 27 Feb 2019 17:44:44 +0100 |
parents | f3a9e125f630 |
children | 9b1f0edf5fdc |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
974
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
974
diff
changeset
|
2 // without warranty, see README.md and license for details. |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
974
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
974
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
974
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
974
diff
changeset
|
6 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
974
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
974
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
974
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
974
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
974
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
974
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
974
diff
changeset
|
13 |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package octree |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
973
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
17 "bytes" |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "encoding/binary" |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "io" |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "log" |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
21 "runtime" |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
22 "sync" |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
23 "sync/atomic" |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 "github.com/golang/snappy" |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 ) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
28 // Builder is used to turn a TIN into an Octree. |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 type Builder struct { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 t *Tin |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 nodes int |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 leaves int |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 index []int32 |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
34 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
35 mu sync.Mutex |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
38 type buildStep func(chan buildStep) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
39 |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 var cubes = [8][2]Vertex{ |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 makeCube(0), |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 makeCube(1), |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 makeCube(2), |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 makeCube(3), |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 makeCube(4), |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 makeCube(5), |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 makeCube(6), |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 makeCube(7), |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 func makeCube(i int) [2]Vertex { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 var d Vertex |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 if i&1 == 1 { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 d.X = 0.5 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 if i&2 == 2 { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 d.Y = 0.5 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 if i&4 == 4 { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 d.Z = 0.5 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 return [2]Vertex{ |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 Vertex{0.0, 0.0, 0.0}.Add(d), |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 Vertex{0.5, 0.5, 0.5}.Add(d), |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
68 // NewBuilder creates a new Builder for a TIN. |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 func NewBuilder(t *Tin) *Builder { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 return &Builder{t: t} |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
73 // Build builds the Octree. |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 func (tb *Builder) Build() { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 triangles := make([]int32, len(tb.t.Triangles)) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 for i := range triangles { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 triangles[i] = int32(i) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
81 n := runtime.NumCPU() |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
82 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
83 steps := make(chan buildStep, n) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
84 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
85 var wg sync.WaitGroup |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
86 for i := 0; i < n; i++ { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
87 wg.Add(1) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
88 go func() { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
89 defer wg.Done() |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
90 for step := range steps { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
91 step(steps) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
92 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
93 }() |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
94 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
95 |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 tb.index = append(tb.index, 0) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
98 root := func(pos int32) { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
99 tb.index[0] = pos |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
100 close(steps) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
101 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
102 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
103 steps <- tb.buildConcurrent( |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
104 triangles, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
105 tb.t.Min, tb.t.Max, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
106 0, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
107 root) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
108 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
109 wg.Wait() |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
110 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
111 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
112 func (tb *Builder) buildConcurrent( |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
113 triangles []int32, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
114 min, max Vertex, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
115 depth int, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
116 parent func(int32), |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
117 ) buildStep { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
118 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
119 return func(steps chan buildStep) { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
120 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
121 // none concurrent for small parts. |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
122 if len(triangles) < 1024 || depth > 8 { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
123 parent(tb.buildRecursive(triangles, min, max, depth)) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
124 return |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
125 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
126 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
127 bbox := Interpolate(min, max) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
128 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
129 bboxes := make([][2]Vertex, len(cubes)) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
130 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
131 for i := range cubes { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
132 bboxes[i] = [2]Vertex{ |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
133 bbox(cubes[i][0]), |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
134 bbox(cubes[i][1]), |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
135 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
136 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
137 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
138 var quandrants [8][]int32 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
139 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
140 for _, tri := range triangles { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
141 triangle := tb.t.Triangles[tri] |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
142 v0 := tb.t.Vertices[triangle[0]] |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
143 v1 := tb.t.Vertices[triangle[1]] |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
144 v2 := tb.t.Vertices[triangle[2]] |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
145 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
146 l := v0 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
147 l.Minimize(v1) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
148 l.Minimize(v2) |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
150 h := v0 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
151 h.Maximize(v1) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
152 h.Maximize(v2) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
153 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
154 for i := range bboxes { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
155 if !(h.Less(bboxes[i][0]) || bboxes[i][1].Less(l)) { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
156 quandrants[i] = append(quandrants[i], tri) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
157 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
158 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
159 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
160 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
161 var used int32 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
162 for i := range quandrants { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
163 if len(quandrants[i]) > 0 { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
164 used++ |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
165 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
166 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
167 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
168 pos := tb.allocNode() |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
169 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
170 for i := range quandrants { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
171 if len(quandrants[i]) > 0 { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
172 j := i |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
173 parent := func(v int32) { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
174 tb.index[j] = v |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
175 if atomic.AddInt32(&used, -1) == 0 { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
176 parent(pos) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
177 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
178 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
179 step := tb.buildConcurrent( |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
180 quandrants[j], |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
181 bboxes[j][0], bboxes[j][1], |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
182 depth+1, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
183 parent) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
184 select { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
185 case steps <- step: |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
186 default: |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
187 // all slots busy -> execute directly. |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
188 step(steps) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
189 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
190 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
191 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
192 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
193 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
194 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
195 func (tb *Builder) allocNode() int32 { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
196 tb.mu.Lock() |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
197 pos := int32(len(tb.index)) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
198 tb.index = append(tb.index, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
199 0, 0, 0, 0, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
200 0, 0, 0, 0) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
201 tb.nodes++ |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
202 tb.mu.Unlock() |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
203 return pos |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 func (tb *Builder) buildRecursive( |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 triangles []int32, |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 min, max Vertex, |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 depth int, |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 ) int32 { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 if len(triangles) <= 16 || depth > 8 { |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
212 tb.mu.Lock() |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 pos := len(tb.index) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 tb.index = append(tb.index, int32(len(triangles))) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 tb.index = append(tb.index, triangles...) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 //log.Printf("leaf entries: %d (%d)\n", len(triangles), depth) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 tb.leaves++ |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
218 tb.mu.Unlock() |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 return int32(-(pos + 1)) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
222 bbox := Interpolate(min, max) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 bboxes := make([][2]Vertex, len(cubes)) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
226 for i := range cubes { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 bboxes[i] = [2]Vertex{ |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 bbox(cubes[i][0]), |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
229 bbox(cubes[i][1]), |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 var quandrants [8][]int32 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 for _, tri := range triangles { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 triangle := tb.t.Triangles[tri] |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 v0 := tb.t.Vertices[triangle[0]] |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 v1 := tb.t.Vertices[triangle[1]] |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
239 v2 := tb.t.Vertices[triangle[2]] |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
240 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
241 l := v0 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 l.Minimize(v1) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
243 l.Minimize(v2) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 h := v0 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 h.Maximize(v1) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 h.Maximize(v2) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 for i := range bboxes { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 if !(h.Less(bboxes[i][0]) || bboxes[i][1].Less(l)) { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 quandrants[i] = append(quandrants[i], tri) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
254 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
256 pos := tb.allocNode() |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
257 |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
258 for i := range quandrants { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 if len(quandrants[i]) > 0 { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
260 child := tb.buildRecursive( |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
261 quandrants[i], |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
262 bboxes[i][0], bboxes[i][1], |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
263 depth+1) |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
264 tb.index[pos+int32(i)] = child |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
266 } |
2475
25e2578b76f3
Fixed counting of nodes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2474
diff
changeset
|
267 |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
268 return pos |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
269 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
270 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
271 func (tb *Builder) serialize(w io.Writer) error { |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
272 var buf [binary.MaxVarintLen32]byte |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
273 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
274 if err := binary.Write(w, binary.LittleEndian, tb.index[0]); err != nil { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
275 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
276 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
277 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
278 var last int32 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
279 var written int |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
280 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
281 for _, x := range tb.index[1:] { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
282 delta := x - last |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
283 n := binary.PutVarint(buf[:], int64(delta)) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
284 for p := buf[:n]; len(p) > 0; p = p[n:] { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
285 var err error |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
286 if n, err = w.Write(p); err != nil { |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
287 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
288 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
289 written += n |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
290 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
291 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
292 last = x |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
293 } |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
294 log.Printf("info: compressed octree index in bytes: %d (%d)\n", |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
295 written, 4*len(tb.index)) |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
296 |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
297 return nil |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
298 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
299 |
1320
fbdd7c3cfeac
Unpublish a method to make 'go vet' happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
300 func (tb *Builder) writeTo(w io.Writer) error { |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
301 out := snappy.NewBufferedWriter(w) |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
302 if err := tb.t.serialize(out); err != nil { |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
303 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
304 } |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
305 if err := tb.serialize(out); err != nil { |
968
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
306 return err |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
307 } |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
308 return out.Flush() |
a4fe07a21ba7
Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
309 } |
973
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
310 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
311 // Bytes serializes an Octree into a byte slice. |
973
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
312 func (tb *Builder) Bytes() ([]byte, error) { |
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
313 var buf bytes.Buffer |
1320
fbdd7c3cfeac
Unpublish a method to make 'go vet' happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
314 if err := tb.writeTo(&buf); err != nil { |
973
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
315 return nil, err |
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
316 } |
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
317 return buf.Bytes(), nil |
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
318 } |
974
7a89313f0ead
Fetch the octree directly from the builder. No need to deserialize it from the blob.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
973
diff
changeset
|
319 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
320 // Tree returns an Octree from the Builder. |
974
7a89313f0ead
Fetch the octree directly from the builder. No need to deserialize it from the blob.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
973
diff
changeset
|
321 func (tb *Builder) Tree() *Tree { |
7a89313f0ead
Fetch the octree directly from the builder. No need to deserialize it from the blob.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
973
diff
changeset
|
322 return &Tree{ |
7a89313f0ead
Fetch the octree directly from the builder. No need to deserialize it from the blob.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
973
diff
changeset
|
323 EPSG: tb.t.EPSG, |
7a89313f0ead
Fetch the octree directly from the builder. No need to deserialize it from the blob.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
973
diff
changeset
|
324 vertices: tb.t.Vertices, |
7a89313f0ead
Fetch the octree directly from the builder. No need to deserialize it from the blob.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
973
diff
changeset
|
325 triangles: tb.t.Triangles, |
7a89313f0ead
Fetch the octree directly from the builder. No need to deserialize it from the blob.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
973
diff
changeset
|
326 index: tb.index, |
7a89313f0ead
Fetch the octree directly from the builder. No need to deserialize it from the blob.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
973
diff
changeset
|
327 Min: tb.t.Min, |
7a89313f0ead
Fetch the octree directly from the builder. No need to deserialize it from the blob.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
973
diff
changeset
|
328 Max: tb.t.Max, |
7a89313f0ead
Fetch the octree directly from the builder. No need to deserialize it from the blob.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
973
diff
changeset
|
329 } |
7a89313f0ead
Fetch the octree directly from the builder. No need to deserialize it from the blob.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
973
diff
changeset
|
330 } |