annotate pkg/mesh/areas.go @ 4827:f4abfd0ee8ad remove-octree-debris

Renamed octree package to mesh as there is no octree any more.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 05 Nov 2019 14:30:22 +0100
parents pkg/octree/areas.go@a2f16bbcc846
children 181c2c05b12a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4570
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 // This is Free Software under GNU Affero General Public License v >= 3.0
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2 // without warranty, see README.md and license for details.
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 //
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 // SPDX-License-Identifier: AGPL-3.0-or-later
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 // License-Filename: LICENSES/AGPL-3.0.txt
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 //
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 // Copyright (C) 2018 by via donau
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 // – Österreichische Wasserstraßen-Gesellschaft mbH
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 // Software engineering by Intevation GmbH
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 //
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 // Author(s):
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
4827
f4abfd0ee8ad Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4768
diff changeset
14 package mesh
4570
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import (
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 "runtime"
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 "sync"
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 "gemma.intevation.de/gemma/pkg/common"
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 )
4b3a298b94f8 Moved area tracing to octree package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22
4654
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
23 func GenerateRandomVertices(
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
24 n int,
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
25 min, max Vertex,
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
26 eval func(float64, float64) (float64, bool),
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
27 callback func([]Vertex),
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
28 ) {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
29 var wg sync.WaitGroup
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
30
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
31 jobs := make(chan int)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
32 out := make(chan []Vertex)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
33 done := make(chan struct{})
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
34
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
35 cpus := runtime.NumCPU()
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
36
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
37 free := make(chan []Vertex, cpus)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
38
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
39 for i := 0; i < cpus; i++ {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
40 wg.Add(1)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
41 go func() {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
42 defer wg.Done()
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
43 xRange := common.Random(min.X, max.X)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
44 yRange := common.Random(min.Y, max.Y)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
45
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
46 for size := range jobs {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
47 var vertices []Vertex
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
48 select {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
49 case vertices = <-free:
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
50 default:
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
51 vertices = make([]Vertex, 0, 1000)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
52 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
53 for len(vertices) < size {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
54 x, y := xRange(), yRange()
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
55 if z, ok := eval(x, y); ok {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
56 vertices = append(vertices, Vertex{X: x, Y: y, Z: z})
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
57 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
58 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
59 out <- vertices
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
60 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
61 }()
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
62 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
63
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
64 go func() {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
65 defer close(done)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
66 for vertices := range out {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
67 callback(vertices)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
68 select {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
69 case free <- vertices[:0]:
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
70 default:
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
71 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
72 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
73 }()
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
74
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
75 for remain := n; remain > 0; {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
76 if remain > 1000 {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
77 jobs <- 1000
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
78 remain -= 1000
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
79 } else {
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
80 jobs <- remain
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
81 remain = 0
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
82 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
83 }
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
84 close(jobs)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
85 wg.Wait()
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
86 close(out)
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
87 <-done
3eda5a7215ab Generate STRTrees instaead of Octree during sounding result imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4640
diff changeset
88 }