Mercurial > gemma
annotate pkg/octree/contours.go @ 1234:1a5564655f2a
refac: Sidebar reorganized
In order to make context switches between administrative tasks
which are map related and those which are system related, we now have
a category "administration" and "systemadministration".
The Riverbedmorphology does nothing than display the map, so it is
renamed to that (map). In case the context of "systemadministration"
is chosen, the "map" brings you just back to the map.
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Tue, 20 Nov 2018 09:54:53 +0100 |
parents | ba0d8c327b0b |
children | 5443f5c9154c |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
977
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:
977
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:
977
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
977
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:
977
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:
977
diff
changeset
|
6 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
977
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
977
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
977
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
977
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
977
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
977
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:
977
diff
changeset
|
13 |
976
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package octree |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 "runtime" |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "sync" |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 ) |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
977
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
21 type ContourResult struct { |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
22 Height float64 |
4a2ca0e20006
Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
976
diff
changeset
|
23 Lines MultiLineStringZ |
1134
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
24 |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
25 done bool |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
26 mu sync.Mutex |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
27 cond *sync.Cond |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
28 } |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
29 |
1186
ba0d8c327b0b
Made code more idiomatic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
30 func NewContourResult(height float64) *ContourResult { |
1134
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
31 cr := ContourResult{Height: height} |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
32 cr.cond = sync.NewCond(&cr.mu) |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
33 return &cr |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
34 } |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
35 |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
36 func (cr *ContourResult) wait() { |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
37 cr.cond.L.Lock() |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
38 for !cr.done { |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
39 cr.cond.Wait() |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
40 } |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
41 cr.cond.L.Unlock() |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
42 } |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
43 |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
44 func (cr *ContourResult) get() float64 { |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
45 cr.cond.L.Lock() |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
46 defer cr.cond.L.Unlock() |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
47 return cr.Height |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
48 } |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
49 |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
50 func (cr *ContourResult) set(lines MultiLineStringZ) { |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
51 cr.cond.L.Lock() |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
52 defer cr.cond.L.Unlock() |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
53 cr.Lines = lines |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
54 cr.done = true |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
55 cr.cond.Signal() |
976
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 } |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 |
1184
064d44ccc6f2
Adjust contour lines heights to multiples of step width
Tom Gottfried <tom@intevation.de>
parents:
1134
diff
changeset
|
58 func DoContours(tree *Tree, heights []float64, store func(*ContourResult)) { |
976
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 |
1186
ba0d8c327b0b
Made code more idiomatic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
60 contours := make([]*ContourResult, len(heights)) |
ba0d8c327b0b
Made code more idiomatic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
61 |
ba0d8c327b0b
Made code more idiomatic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
62 for i, h := range heights { |
ba0d8c327b0b
Made code more idiomatic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1184
diff
changeset
|
63 contours[i] = NewContourResult(h) |
1134
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
64 } |
976
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 |
1134
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
66 jobs := make(chan *ContourResult) |
976
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 var wg sync.WaitGroup |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 for i, n := 0, runtime.NumCPU(); i < n; i++ { |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 wg.Add(1) |
1134
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
71 go processLevels(tree, jobs, &wg) |
976
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 } |
1134
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
73 |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
74 done := make(chan struct{}) |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
75 go func() { |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
76 defer close(done) |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
77 for _, cr := range contours { |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
78 cr.wait() |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
79 store(cr) |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
80 } |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
81 }() |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
82 |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
83 for _, cr := range contours { |
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
84 jobs <- cr |
976
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 } |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 close(jobs) |
1134
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
87 |
976
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 wg.Wait() |
1134
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
89 <-done |
976
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 } |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 func processLevels( |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 tree *Tree, |
1134
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
94 jobs <-chan *ContourResult, |
976
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 wg *sync.WaitGroup, |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 ) { |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 defer wg.Done() |
1134
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
98 for cr := range jobs { |
976
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 var lines MultiLineStringZ |
1134
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
100 h := cr.get() |
976
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 tree.Horizontal(h, func(t *Triangle) { |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 line := t.IntersectHorizontal(h) |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 if len(line) > 1 { |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 lines = append(lines, line) |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 } |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 }) |
1134
0420761c1c3f
Store contour lines in deterministic order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
107 cr.set(lines.Merge()) |
976
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 } |
c397fdd8c327
Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 } |