Mercurial > gemma
annotate pkg/octree/builder.go @ 2478:930ca9c4e2a7 octree-diff
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 28 Feb 2019 12:34:47 +0100 |
parents | 9b1f0edf5fdc |
children | 1ec4c5633eb6 |
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" |
2478
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
21 "runtime" |
2474
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 |
2478
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
81 n := runtime.NumCPU() |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
82 |
2478
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
83 steps := make(chan buildStep) |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
84 |
2478
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
85 var wg sync.WaitGroup |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
86 for i := 0; i < n; i++ { |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
87 wg.Add(1) |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
88 go func() { |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
89 defer wg.Done() |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
90 for step := range steps { |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
91 step(steps) |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
92 } |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
93 }() |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
94 } |
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
|
95 |
2478
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
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 |
2478
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
98 root := func(int32) { |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
99 close(steps) |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
100 } |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
101 |
2478
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
102 steps <- tb.buildConcurrent( |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
103 triangles, |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
104 tb.t.Min, tb.t.Max, |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
105 0, |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
106 root) |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
107 |
2478
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
108 wg.Wait() |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
109 |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
110 /* |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
111 tb.buildRecursive(triangles, tb.t.Min, tb.t.Max, 0) |
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
|
112 */ |
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 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
|
114 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
|
115 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
|
116 tb.nodes, tb.leaves, tb.index[0]) |
2474
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 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
119 func (tb *Builder) buildConcurrent( |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
120 triangles []int32, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
121 min, max Vertex, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
122 depth int, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
123 parent func(int32), |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
124 ) buildStep { |
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 return func(steps chan buildStep) { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
127 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
128 // none concurrent for small parts. |
2478
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
129 if len(triangles) <= 1024 || depth > 8 { |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
130 parent(tb.buildRecursive(triangles, min, max, depth)) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
131 return |
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 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
134 bbox := Interpolate(min, max) |
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 bboxes := make([][2]Vertex, len(cubes)) |
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 for i := range cubes { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
139 bboxes[i] = [2]Vertex{ |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
140 bbox(cubes[i][0]), |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
141 bbox(cubes[i][1]), |
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 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
145 var quandrants [8][]int32 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
146 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
147 for _, tri := range triangles { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
148 triangle := tb.t.Triangles[tri] |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
149 v0 := tb.t.Vertices[triangle[0]] |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
150 v1 := tb.t.Vertices[triangle[1]] |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
151 v2 := tb.t.Vertices[triangle[2]] |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
152 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
153 l := v0 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
154 l.Minimize(v1) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
155 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
|
156 |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
157 h := v0 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
158 h.Maximize(v1) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
159 h.Maximize(v2) |
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 for i := range bboxes { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
162 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
|
163 quandrants[i] = append(quandrants[i], tri) |
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 |
2478
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
168 used := new(int32) |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
169 for i := range quandrants { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
170 if len(quandrants[i]) > 0 { |
2478
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
171 *used++ |
2474
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 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
175 pos := tb.allocNode() |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
176 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
177 for i := range quandrants { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
178 if len(quandrants[i]) > 0 { |
2478
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
179 j := int32(i) |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
180 parent := func(v int32) { |
2478
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
181 tb.index[pos+j] = v |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
182 if atomic.AddInt32(used, -1) == 0 { |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
183 parent(pos) |
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 } |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
186 step := tb.buildConcurrent( |
2478
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
187 quandrants[i], |
930ca9c4e2a7
Fixed concurrent octree builder. The iso line cuts are now in the same quantity order of line segments but still differ. Need to have a closer look once we serve the data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2477
diff
changeset
|
188 bboxes[i][0], bboxes[i][1], |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
189 depth+1, |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
190 parent) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
191 select { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
192 case steps <- step: |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
193 default: |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
194 // all slots busy -> execute directly. |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
195 step(steps) |
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 |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
202 func (tb *Builder) allocNode() int32 { |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
203 tb.mu.Lock() |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
204 pos := int32(len(tb.index)) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
205 tb.index = append(tb.index, |
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 0, 0, 0, 0) |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
208 tb.nodes++ |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
209 tb.mu.Unlock() |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
210 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
|
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 |
a4fe07a21ba7
Moved 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 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
|
214 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
|
215 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
|
216 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
|
217 ) 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
|
218 if len(triangles) <= 16 || depth > 8 { |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
219 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
|
220 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
|
221 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
|
222 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
|
223 //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
|
224 tb.leaves++ |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
225 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
|
226 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
|
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 |
a4fe07a21ba7
Moved 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 := 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
|
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 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
|
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 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
|
234 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
|
235 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
|
236 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
|
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 |
a4fe07a21ba7
Moved 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 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
|
241 |
a4fe07a21ba7
Moved 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 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 |
a4fe07a21ba7
Moved 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 := 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
|
249 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
|
250 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
|
251 |
a4fe07a21ba7
Moved 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 := 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
|
253 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
|
254 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
|
255 |
a4fe07a21ba7
Moved 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 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
|
257 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
|
258 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
|
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 } |
a4fe07a21ba7
Moved 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 |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
263 pos := tb.allocNode() |
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
264 |
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 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 depth+1) |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
271 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
|
272 } |
a4fe07a21ba7
Moved 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 } |
2475
25e2578b76f3
Fixed counting of nodes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2474
diff
changeset
|
274 |
2474
f3a9e125f630
Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1691
diff
changeset
|
275 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
|
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 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
278 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
|
279 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
|
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 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
|
282 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
|
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 |
a4fe07a21ba7
Moved 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 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
|
286 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
|
287 |
a4fe07a21ba7
Moved 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 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 } |
a4fe07a21ba7
Moved 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 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
|
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 |
a4fe07a21ba7
Moved 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 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
|
300 } |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
301 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
|
302 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
|
303 |
a4fe07a21ba7
Moved 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 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
|
305 } |
a4fe07a21ba7
Moved 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 |
1320
fbdd7c3cfeac
Unpublish a method to make 'go vet' happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
307 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
|
308 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
|
309 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
|
310 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
|
311 } |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
312 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
|
313 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
|
314 } |
a4fe07a21ba7
Moved 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 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
|
316 } |
973
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
317 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
318 // 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
|
319 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
|
320 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
|
321 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
|
322 return nil, err |
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
323 } |
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
324 return buf.Bytes(), nil |
b6fec8f85599
Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
968
diff
changeset
|
325 } |
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
|
326 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1320
diff
changeset
|
327 // 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
|
328 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
|
329 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
|
330 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
|
331 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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 } |
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
|
337 } |