Mercurial > gemma
annotate pkg/octree/builder.go @ 2477:9b1f0edf5fdc octree-diff
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 28 Feb 2019 12:03:02 +0100 |
parents | 25e2578b76f3 |
children | 930ca9c4e2a7 |
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 "sync" |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
22 "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
|
23 |
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 "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
|
25 ) |
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 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
27 // 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
|
28 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
|
29 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
|
30 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
|
31 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
|
32 index []int32 |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
33 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
34 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
|
35 } |
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 |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
37 type buildStep func(chan buildStep) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
38 |
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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 } |
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 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
|
51 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
|
52 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
|
53 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
|
54 } |
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 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
|
56 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
|
57 } |
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 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
|
59 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
|
60 } |
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 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
|
62 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
|
63 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
|
64 } |
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 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
67 // 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
|
68 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
|
69 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
|
70 } |
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 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
72 // 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
|
73 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
|
74 |
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 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
|
76 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
|
77 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
|
78 } |
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 |
2477
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
80 /* |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
81 n := runtime.NumCPU() |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
82 |
2477
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
83 steps := make(chan buildStep, n) |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
84 |
2477
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
85 var wg sync.WaitGroup |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
86 for i := 0; i < n; i++ { |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
87 wg.Add(1) |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
88 go func() { |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
89 defer wg.Done() |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
90 for step := range steps { |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
91 step(steps) |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
92 } |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
93 }() |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
94 } |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
95 |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
96 tb.index = append(tb.index, 0) |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
97 |
2477
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
98 root := func(int32) { |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
99 close(steps) |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
100 } |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
101 |
2477
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
102 steps <- tb.buildConcurrent( |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
103 triangles, |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
104 tb.t.Min, tb.t.Max, |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
105 0, |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
106 root) |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
107 |
2477
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
108 wg.Wait() |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
109 */ |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
110 |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
111 tb.buildRecursive(triangles, tb.t.Min, tb.t.Max, 0) |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
112 tb.index[0] = int32(len(tb.index)) |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
113 log.Printf("info: num nodes: %d\n", tb.index[0]) |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
114 log.Printf("info: nodes: %d leaves: %d index %d\n", |
9b1f0edf5fdc
The concurrent octree build seems to be buggy. Use the old code instead till the problem is found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2475
diff
changeset
|
115 tb.nodes, tb.leaves, tb.index[0]) |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
116 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
117 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
118 func (tb *Builder) buildConcurrent( |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
119 triangles []int32, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
120 min, max Vertex, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
121 depth int, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
122 parent func(int32), |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
123 ) buildStep { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
124 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
125 return func(steps chan buildStep) { |
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 // none concurrent for small parts. |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
128 if len(triangles) < 1024 || depth > 8 { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
129 parent(tb.buildRecursive(triangles, min, max, depth)) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
130 return |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
131 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
132 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
133 bbox := Interpolate(min, max) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
134 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
135 bboxes := make([][2]Vertex, len(cubes)) |
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 for i := range cubes { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
138 bboxes[i] = [2]Vertex{ |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
139 bbox(cubes[i][0]), |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
140 bbox(cubes[i][1]), |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
141 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
142 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
143 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
144 var quandrants [8][]int32 |
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 for _, tri := range triangles { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
147 triangle := tb.t.Triangles[tri] |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
148 v0 := tb.t.Vertices[triangle[0]] |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
149 v1 := tb.t.Vertices[triangle[1]] |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
150 v2 := tb.t.Vertices[triangle[2]] |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
151 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
152 l := v0 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
153 l.Minimize(v1) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
154 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
|
155 |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
156 h := v0 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
157 h.Maximize(v1) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
158 h.Maximize(v2) |
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 for i := range bboxes { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
161 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
|
162 quandrants[i] = append(quandrants[i], tri) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
163 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
164 } |
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 var used int32 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
168 for i := range quandrants { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
169 if len(quandrants[i]) > 0 { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
170 used++ |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
171 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
172 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
173 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
174 pos := tb.allocNode() |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
175 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
176 for i := range quandrants { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
177 if len(quandrants[i]) > 0 { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
178 j := i |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
179 parent := func(v int32) { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
180 tb.index[j] = v |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
181 if atomic.AddInt32(&used, -1) == 0 { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
182 parent(pos) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
183 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
184 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
185 step := tb.buildConcurrent( |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
186 quandrants[j], |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
187 bboxes[j][0], bboxes[j][1], |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
188 depth+1, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
189 parent) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
190 select { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
191 case steps <- step: |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
192 default: |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
193 // all slots busy -> execute directly. |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
194 step(steps) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
195 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
196 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
197 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
198 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
199 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
200 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
201 func (tb *Builder) allocNode() int32 { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
202 tb.mu.Lock() |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
203 pos := int32(len(tb.index)) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
204 tb.index = append(tb.index, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
205 0, 0, 0, 0, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
206 0, 0, 0, 0) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
207 tb.nodes++ |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
208 tb.mu.Unlock() |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
209 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
|
210 } |
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 |
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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 ) 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
|
217 if len(triangles) <= 16 || depth > 8 { |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
218 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
|
219 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
|
220 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
|
221 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
|
222 //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
|
223 tb.leaves++ |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
224 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
|
225 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
|
226 } |
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 |
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 := 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
|
229 |
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 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
|
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 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
|
233 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
|
234 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
|
235 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
|
236 } |
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 } |
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 |
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 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
|
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 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 |
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 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
|
248 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
|
249 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
|
250 |
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 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
|
252 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
|
253 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
|
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 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
|
256 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
|
257 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
|
258 } |
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 } |
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 } |
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 |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
262 pos := tb.allocNode() |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
263 |
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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 depth+1) |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
270 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
|
271 } |
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 } |
2475
25e2578b76f3
Fixed counting of nodes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2474
diff
changeset
|
273 |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
274 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
|
275 } |
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 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
277 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
|
278 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
|
279 |
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 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
|
281 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
|
282 } |
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 |
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 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
|
285 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
|
286 |
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 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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 } |
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 += 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
|
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 |
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 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
|
299 } |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
300 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
|
301 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
|
302 |
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 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
|
304 } |
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
|
305 |
1320
fbdd7c3cfeac
Unpublish a method to make 'go vet' happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
306 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
|
307 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
|
308 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
|
309 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
|
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 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
|
312 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
|
313 } |
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
|
314 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
|
315 } |
973
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
316 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
317 // 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
|
318 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
|
319 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
|
320 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
|
321 return nil, err |
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
322 } |
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
323 return buf.Bytes(), nil |
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
324 } |
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
|
325 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
326 // 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
|
327 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
|
328 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
|
329 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
|
330 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
|
331 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
|
332 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
|
333 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
|
334 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
|
335 } |
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
|
336 } |