annotate pkg/octree/builder.go @ 2516:1ec4c5633eb6 octree-diff

Clip STR tree and not Octree.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 05 Mar 2019 17:08:16 +0100
parents 930ca9c4e2a7
children 4233570de212
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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.
2516
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
74 func (tb *Builder) Build(removed map[int32]struct{}) {
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
75
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
76 var triangles []int32
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
77
2516
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
78 if len(removed) > 0 {
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
79 triangles = make([]int32, len(tb.t.Triangles)-len(removed))
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
80 idx := 0
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
81 for i := range tb.t.Triangles {
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
82 if _, found := removed[int32(i)]; !found {
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
83 triangles[idx] = int32(i)
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
84 idx++
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
85 }
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
86 }
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
87 } else {
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
88 triangles = make([]int32, len(tb.t.Triangles))
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
89 for i := range triangles {
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
90 triangles[i] = int32(i)
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
91 }
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
92 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93
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
94 n := runtime.NumCPU()
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
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 steps := make(chan buildStep)
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 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
99 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
100 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
101 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
102 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
103 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
104 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
105 }
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 }()
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
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
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
109 tb.index = append(tb.index, 0)
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
110
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
111 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
112 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
113 }
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
114
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
115 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
116 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
117 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
118 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
119 root)
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
120
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
121 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
122
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
123 /*
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
124 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
125 */
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
126 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
127 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
128 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
129 tb.nodes, tb.leaves, tb.index[0])
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
130 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
131
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
132 func (tb *Builder) buildConcurrent(
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
133 triangles []int32,
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
134 min, max Vertex,
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
135 depth int,
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
136 parent func(int32),
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
137 ) buildStep {
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
138
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
139 return func(steps chan buildStep) {
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
140
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
141 // 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
142 if len(triangles) <= 1024 || depth > 8 {
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
143 parent(tb.buildRecursive(triangles, min, max, depth))
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
144 return
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
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
147 bbox := Interpolate(min, max)
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
148
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
149 bboxes := make([][2]Vertex, len(cubes))
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
150
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
151 for i := range cubes {
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
152 bboxes[i] = [2]Vertex{
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
153 bbox(cubes[i][0]),
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
154 bbox(cubes[i][1]),
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
155 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
156 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
157
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
158 var quandrants [8][]int32
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 _, tri := range triangles {
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
161 triangle := tb.t.Triangles[tri]
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
162 v0 := tb.t.Vertices[triangle[0]]
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
163 v1 := tb.t.Vertices[triangle[1]]
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
164 v2 := tb.t.Vertices[triangle[2]]
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 l := v0
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
167 l.Minimize(v1)
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
168 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
169
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
170 h := v0
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
171 h.Maximize(v1)
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
172 h.Maximize(v2)
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 for i := range bboxes {
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
175 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
176 quandrants[i] = append(quandrants[i], tri)
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
177 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
178 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
179 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
180
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 used := new(int32)
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
182 for i := range quandrants {
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
183 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
184 *used++
2474
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 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
187
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
188 pos := tb.allocNode()
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
189
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
190 for i := range quandrants {
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
191 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
192 j := int32(i)
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
193 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
194 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
195 if atomic.AddInt32(used, -1) == 0 {
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
196 parent(pos)
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 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
200 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
201 bboxes[i][0], bboxes[i][1],
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
202 depth+1,
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
203 parent)
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
204 select {
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
205 case steps <- step:
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
206 default:
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
207 // all slots busy -> execute directly.
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
208 step(steps)
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
209 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
210 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
211 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
212 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
213 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
214
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
215 func (tb *Builder) allocNode() int32 {
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
216 tb.mu.Lock()
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
217 pos := int32(len(tb.index))
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
218 tb.index = append(tb.index,
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
219 0, 0, 0, 0,
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
220 0, 0, 0, 0)
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
221 tb.nodes++
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
222 tb.mu.Unlock()
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
223 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
224 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
225
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
226 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
227 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
228 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
229 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
230 ) 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
231 if len(triangles) <= 16 || depth > 8 {
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
232 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
233 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
234 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
235 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
236 //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
237 tb.leaves++
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
238 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
239 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
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
a4fe07a21ba7 Moved 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 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
243
a4fe07a21ba7 Moved 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 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
245
a4fe07a21ba7 Moved 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 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
247 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
248 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
249 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
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 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
252
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
253 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
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 _, 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
256 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
257 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
258 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
259 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
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 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
262 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
263 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
264
a4fe07a21ba7 Moved 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 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
266 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
267 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
268
a4fe07a21ba7 Moved 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 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
270 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
271 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
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 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
274 }
a4fe07a21ba7 Moved 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
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
276 pos := tb.allocNode()
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
277
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 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
279 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
280 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
281 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
282 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
283 depth+1)
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
284 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
285 }
a4fe07a21ba7 Moved 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 }
2475
25e2578b76f3 Fixed counting of nodes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2474
diff changeset
287
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
288 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
289 }
a4fe07a21ba7 Moved 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
1691
de09bd3b5c05 Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1320
diff changeset
291 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
292 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
293
a4fe07a21ba7 Moved 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 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
295 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
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 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
299 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
300
a4fe07a21ba7 Moved 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 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
302 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
303 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
304 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
305 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
306 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
307 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
308 }
a4fe07a21ba7 Moved 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 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
310 }
a4fe07a21ba7 Moved 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
a4fe07a21ba7 Moved 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 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
313 }
1691
de09bd3b5c05 Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1320
diff changeset
314 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
315 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
316
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
317 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
318 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
319
1320
fbdd7c3cfeac Unpublish a method to make 'go vet' happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
320 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
321 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
322 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
323 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
324 }
1691
de09bd3b5c05 Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1320
diff changeset
325 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
326 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
327 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
328 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
329 }
973
b6fec8f85599 Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 968
diff changeset
330
1691
de09bd3b5c05 Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1320
diff changeset
331 // 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
332 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
333 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
334 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
335 return nil, err
b6fec8f85599 Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 968
diff changeset
336 }
b6fec8f85599 Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 968
diff changeset
337 return buf.Bytes(), nil
b6fec8f85599 Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 968
diff changeset
338 }
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
339
1691
de09bd3b5c05 Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1320
diff changeset
340 // 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
341 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
342 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
343 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
344 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
345 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
346 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
347 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
348 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
349 }
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
350 }