annotate pkg/octree/contours.go @ 991:a301d240905f

Decoupled import job creation and job execution with a factory function. This is needed for persistence purposes.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 22 Oct 2018 10:45:17 +0200
parents 4a2ca0e20006
children a244b18cb916
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
976
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 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
2
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import (
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 "runtime"
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 "sync"
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 )
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7
977
4a2ca0e20006 Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 976
diff changeset
8 type ContourResult struct {
4a2ca0e20006 Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 976
diff changeset
9 Height float64
4a2ca0e20006 Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 976
diff changeset
10 Lines MultiLineStringZ
976
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 }
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
977
4a2ca0e20006 Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 976
diff changeset
13 func DoContours(tree *Tree, step 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
14
977
4a2ca0e20006 Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 976
diff changeset
15 results := 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
16 done := make(chan struct{})
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 jobs := make(chan float64)
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 go func() {
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 for {
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 select {
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 case r := <-results:
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 store(r)
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 case <-done:
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 return
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 }
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 }
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 }()
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 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
31 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
32 wg.Add(1)
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 go processLevels(tree, jobs, results, &wg)
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 }
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 for h := tree.Min.Z; h <= tree.Max.Z; h += step {
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 jobs <- h
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 }
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 close(jobs)
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 wg.Wait()
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 done <- struct{}{}
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 }
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 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
44 tree *Tree,
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 jobs <-chan float64,
977
4a2ca0e20006 Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 976
diff changeset
46 results 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
47 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
48 ) {
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 defer wg.Done()
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 for h := range jobs {
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 var lines MultiLineStringZ
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 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
53 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
54 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
55 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
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 })
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 lines = lines.Merge()
977
4a2ca0e20006 Fixed build error.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 976
diff changeset
59 results <- &ContourResult{h, lines}
976
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 }
c397fdd8c327 Generate the contour lines of the sounding result during the import, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 }