comparison cmd/octree2contour/main.go @ 727:41c8dc61f38f

Moved octree loading stuff to octree package.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sat, 22 Sep 2018 21:57:30 +0200
parents 5af9ab39e715
children 39b5cf9a6b8f
comparison
equal deleted inserted replaced
726:5af9ab39e715 727:41c8dc61f38f
5 "log" 5 "log"
6 "runtime" 6 "runtime"
7 "sort" 7 "sort"
8 "sync" 8 "sync"
9 "time" 9 "time"
10
11 "gemma.intevation.de/gemma/pkg/octree"
10 ) 12 )
11 13
12 var ( 14 var (
13 one = flag.Bool("o", false, "create only a single contour") 15 one = flag.Bool("o", false, "create only a single contour")
14 step = flag.Float64("s", 0.5, "step with") 16 step = flag.Float64("s", 0.5, "step with")
15 max = flag.Float64("m", 10, "max height from lowest point") 17 max = flag.Float64("m", 10, "max height from lowest point")
16 ) 18 )
17 19
18 func processLevels( 20 func processLevels(
19 tree *Octree, 21 tree *octree.Tree,
20 jobs <-chan float64, 22 jobs <-chan float64,
21 results chan<- result, 23 results chan<- result,
22 wg *sync.WaitGroup, 24 wg *sync.WaitGroup,
23 ) { 25 ) {
24 defer wg.Done() 26 defer wg.Done()
25 for h := range jobs { 27 for h := range jobs {
26 var lines MultiLineStringZ 28 var lines octree.MultiLineStringZ
27 tree.Horizontal(h, func(t *Triangle) { 29 tree.Horizontal(h, func(t *octree.Triangle) {
28 line := t.IntersectHorizontal(h) 30 line := t.IntersectHorizontal(h)
29 if len(line) > 1 { 31 if len(line) > 1 {
30 lines = append(lines, line) 32 lines = append(lines, line)
31 } 33 }
32 }) 34 })
33 results <- result{h, lines} 35 results <- result{h, lines}
34 } 36 }
35 } 37 }
36 38
37 func process(tree *Octree) []result { 39 func process(tree *octree.Tree) []result {
38 40
39 if *one { 41 if *one {
40 var lines MultiLineStringZ 42 var lines octree.MultiLineStringZ
41 tree.Horizontal(*step, func(t *Triangle) { 43 tree.Horizontal(*step, func(t *octree.Triangle) {
42 line := t.IntersectHorizontal(*step) 44 line := t.IntersectHorizontal(*step)
43 if len(line) > 0 { 45 if len(line) > 0 {
44 lines = append(lines, line) 46 lines = append(lines, line)
45 } 47 }
46 }) 48 })
66 jobs := make(chan float64) 68 jobs := make(chan float64)
67 for i, n := 0, runtime.NumCPU(); i < n; i++ { 69 for i, n := 0, runtime.NumCPU(); i < n; i++ {
68 wg.Add(1) 70 wg.Add(1)
69 go processLevels(tree, jobs, results, &wg) 71 go processLevels(tree, jobs, results, &wg)
70 } 72 }
71 for h := tree.Min.z; h <= tree.Max.z; h += *step { 73 for h := tree.Min.Z; h <= tree.Max.Z; h += *step {
72 jobs <- h 74 jobs <- h
73 } 75 }
74 close(jobs) 76 close(jobs)
75 wg.Wait() 77 wg.Wait()
76 done <- struct{}{} 78 done <- struct{}{}
86 flag.Parse() 88 flag.Parse()
87 89
88 for _, fname := range flag.Args() { 90 for _, fname := range flag.Args() {
89 log.Printf("processing %s\n", fname) 91 log.Printf("processing %s\n", fname)
90 start := time.Now() 92 start := time.Now()
91 tree, err := LoadOctree(fname) 93 tree, err := octree.LoadTree(fname)
92 if err != nil { 94 if err != nil {
93 log.Printf("error: %v\n", err) 95 log.Printf("error: %v\n", err)
94 continue 96 continue
95 } 97 }
96 log.Printf("loading took: %v\n", time.Since(start)) 98 log.Printf("loading took: %v\n", time.Since(start))