annotate pkg/octree/builder.go @ 4652:f5492fda097c stree-experiment

Use gzip best speed instead of lz4.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 14 Oct 2019 12:25:32 +0200
parents 4233570de212
children
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
3953
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
40 var cubes = [8]Box{
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
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
3953
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
51 func makeCube(i int) Box {
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
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 }
3953
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
62 return Box{
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
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
3953
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
68 func twoElseOne(b bool) int {
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
69 if b {
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
70 return 2
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
71 }
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
72 return 1
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
73 }
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
74
1691
de09bd3b5c05 Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1320
diff changeset
75 // 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
76 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
77 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
78 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79
1691
de09bd3b5c05 Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1320
diff changeset
80 // Build builds the Octree.
2516
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
81 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
82
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
83 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
84
2516
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
85 if len(removed) > 0 {
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
86 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
87 idx := 0
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
88 for i := range tb.t.Triangles {
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
89 if _, found := removed[int32(i)]; !found {
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
90 triangles[idx] = int32(i)
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
91 idx++
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
92 }
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
93 }
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
94 } else {
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
95 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
96 for i := range triangles {
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
97 triangles[i] = int32(i)
1ec4c5633eb6 Clip STR tree and not Octree.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2478
diff changeset
98 }
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
99 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100
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
101 n := runtime.NumCPU()
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
102
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
103 steps := make(chan buildStep)
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
104
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
105 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
106 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
107 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
108 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
109 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
110 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
111 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
112 }
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 }()
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
114 }
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
115
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
116 tb.index = append(tb.index, 0)
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
117
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
118 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
119 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
120 }
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
121
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
122 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
123 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
124 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
125 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
126 root)
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
127
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
128 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
129
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
130 /*
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
131 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
132 */
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
133 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
134 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
135 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
136 tb.nodes, tb.leaves, tb.index[0])
2474
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
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
139 func (tb *Builder) buildConcurrent(
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
140 triangles []int32,
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
141 min, max Vertex,
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
142 depth int,
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
143 parent func(int32),
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
144 ) buildStep {
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 return func(steps chan buildStep) {
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
147
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
148 // 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
149 if len(triangles) <= 1024 || depth > 8 {
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
150 parent(tb.buildRecursive(triangles, min, max, depth))
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
151 return
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
152 }
3953
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
153 box := Box{min, max}
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
154
3953
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
155 xLimit := twoElseOne(box.HasX())
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
156 yLimit := twoElseOne(box.HasY())
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
157 zLimit := twoElseOne(box.HasZ())
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
158
3953
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
159 indices := make([]byte, 0, 8)
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
160
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
161 bbox := box.Interpolate()
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
162
3953
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
163 var bboxes [8]Box
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
164
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
165 for x := 0; x < xLimit; x++ {
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
166 for y := 0; y < yLimit; y++ {
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
167 for z := 0; z < zLimit; z++ {
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
168 idx := byte(z<<2 | y<<1 | x)
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
169 bboxes[idx] = Box{
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
170 bbox(cubes[idx][0]),
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
171 bbox(cubes[idx][1]),
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
172 }
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
173 indices = append(indices, idx)
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
174 }
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
175 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
176 }
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 var quandrants [8][]int32
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 for _, tri := range triangles {
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
181 triangle := tb.t.Triangles[tri]
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
182 v0 := tb.t.Vertices[triangle[0]]
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
183 v1 := tb.t.Vertices[triangle[1]]
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
184 v2 := tb.t.Vertices[triangle[2]]
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 l := v0
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
187 l.Minimize(v1)
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
188 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
189
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
190 h := v0
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
191 h.Maximize(v1)
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
192 h.Maximize(v2)
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
193
3953
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
194 for _, i := range indices {
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
195 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
196 quandrants[i] = append(quandrants[i], tri)
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
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
201 used := new(int32)
3953
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
202 for _, i := range indices {
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
203 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
204 *used++
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
205 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
206 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
207
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
208 pos := tb.allocNode()
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
209
3953
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
210 if *used == 0 {
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
211 parent(pos)
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
212 return
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
213 }
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
214
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
215 for _, i := range indices {
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
216 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
217 j := int32(i)
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
218 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
219 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
220 if atomic.AddInt32(used, -1) == 0 {
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
221 parent(pos)
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
222 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
223 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
224 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
225 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
226 bboxes[i][0], bboxes[i][1],
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
227 depth+1,
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
228 parent)
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
229 select {
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
230 case steps <- step:
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
231 default:
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
232 // all slots busy -> execute directly.
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
233 step(steps)
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
234 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
235 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
236 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
237 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
238 }
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
239
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
240 func (tb *Builder) allocNode() int32 {
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
241 tb.mu.Lock()
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
242 pos := int32(len(tb.index))
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
243 tb.index = append(tb.index,
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
244 0, 0, 0, 0,
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
245 0, 0, 0, 0)
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
246 tb.nodes++
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
247 tb.mu.Unlock()
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
248 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
249 }
a4fe07a21ba7 Moved 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 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
252 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
253 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
254 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
255 ) 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
256 if len(triangles) <= 16 || depth > 8 {
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
257 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
258 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
259 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
260 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
261 //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
262 tb.leaves++
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
263 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
264 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
265 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
266
3953
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
267 box := Box{min, max}
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
268
3953
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
269 xLimit := twoElseOne(box.HasX())
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
270 yLimit := twoElseOne(box.HasY())
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
271 zLimit := twoElseOne(box.HasZ())
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
272
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
273 indices := make([]byte, 0, 8)
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
274
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
275 bbox := box.Interpolate()
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
3953
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
277 var bboxes [8]Box
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
278
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
279 for x := 0; x < xLimit; x++ {
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
280 for y := 0; y < yLimit; y++ {
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
281 for z := 0; z < zLimit; z++ {
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
282 idx := byte(z<<2 | y<<1 | x)
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
283 bboxes[idx] = Box{
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
284 bbox(cubes[idx][0]),
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
285 bbox(cubes[idx][1]),
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
286 }
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
287 indices = append(indices, idx)
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
288 }
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 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
291
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
292 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
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 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
295 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
296 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
297 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
298 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
299
a4fe07a21ba7 Moved 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 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
301 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
302 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
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 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
305 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
306 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
307
3953
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
308 for _, i := range indices {
968
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
309 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
310 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
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 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
313 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
314
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
315 pos := tb.allocNode()
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
316
3953
4233570de212 Building octrees: Don't cause havok by building ain overly large tree if the points are not really 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2516
diff changeset
317 for _, i := range indices {
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
318 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
319 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
320 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
321 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
322 depth+1)
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
323 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
324 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
325 }
2475
25e2578b76f3 Fixed counting of nodes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2474
diff changeset
326
2474
f3a9e125f630 Made octree builder concurrent.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1691
diff changeset
327 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
328 }
a4fe07a21ba7 Moved 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
1691
de09bd3b5c05 Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1320
diff changeset
330 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
331 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
332
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
333 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
334 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
335 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
336
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
337 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
338 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
339
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
340 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
341 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
342 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
343 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
344 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
345 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
346 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
347 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
348 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
349 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
350
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
351 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
352 }
1691
de09bd3b5c05 Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1320
diff changeset
353 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
354 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
355
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
356 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
357 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
358
1320
fbdd7c3cfeac Unpublish a method to make 'go vet' happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1017
diff changeset
359 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
360 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
361 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
362 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
363 }
1691
de09bd3b5c05 Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1320
diff changeset
364 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
365 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
366 }
a4fe07a21ba7 Moved octree builder into octree package to be reusable by the sounding result import job.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
367 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
368 }
973
b6fec8f85599 Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 968
diff changeset
369
1691
de09bd3b5c05 Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1320
diff changeset
370 // 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
371 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
372 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
373 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
374 return nil, err
b6fec8f85599 Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 968
diff changeset
375 }
b6fec8f85599 Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 968
diff changeset
376 return buf.Bytes(), nil
b6fec8f85599 Generate TINs and octrees in sounding result importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 968
diff changeset
377 }
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
378
1691
de09bd3b5c05 Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 1320
diff changeset
379 // 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
380 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
381 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
382 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
383 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
384 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
385 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
386 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
387 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
388 }
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
389 }