comparison cmd/octreediff/main.go @ 2472:db0e4ab57977 octree-diff

Turn new point cloud into WKB form of MultiPointZ.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 26 Feb 2019 12:22:04 +0100
parents 5bd3236f2b1f
children 19beb7d17337
comparison
equal deleted inserted replaced
2471:63475c8e710e 2472:db0e4ab57977
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> 12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
13 13
14 package main 14 package main
15 15
16 import ( 16 import (
17 "bytes"
17 "context" 18 "context"
18 "database/sql" 19 "database/sql"
20 "encoding/binary"
19 "errors" 21 "errors"
20 "flag" 22 "flag"
21 "fmt" 23 "fmt"
22 "log" 24 "log"
25 "math"
23 "runtime" 26 "runtime"
24 "sync" 27 "sync"
25 "time" 28 "time"
26 29
27 "gemma.intevation.de/gemma/pkg/common" 30 "gemma.intevation.de/gemma/pkg/common"
28 "gemma.intevation.de/gemma/pkg/octree" 31 "gemma.intevation.de/gemma/pkg/octree"
32 "gemma.intevation.de/gemma/pkg/wkb"
29 ) 33 )
30 34
31 var ( 35 var (
32 bottleneck = flag.String("bottleneck", "", "name of the bottleneck") 36 bottleneck = flag.String("bottleneck", "", "name of the bottleneck")
33 first = flag.String("first", "", "date of the first sounding result") 37 first = flag.String("first", "", "date of the first sounding result")
52 type point struct { 56 type point struct {
53 x float64 57 x float64
54 y float64 58 y float64
55 } 59 }
56 60
61 type pointMap map[point]float64
62
63 func (pm pointMap) asWKB() []byte {
64 size := 1 + 4 + 4 + len(pm)*(1+4+3*8)
65
66 buf := bytes.NewBuffer(make([]byte, 0, size))
67
68 binary.Write(buf, binary.LittleEndian, wkb.NDR)
69 binary.Write(buf, binary.LittleEndian, wkb.MultiPointZ)
70 binary.Write(buf, binary.LittleEndian, uint32(len(pm)))
71
72 perPoint := bytes.NewBuffer(make([]byte, 0, 1+4))
73 binary.Write(perPoint, binary.LittleEndian, wkb.NDR)
74 binary.Write(perPoint, binary.LittleEndian, wkb.PointZ)
75 hdr := perPoint.Bytes()
76
77 for p, z := range pm {
78 buf.Write(hdr)
79 binary.Write(buf, binary.LittleEndian, math.Float64bits(p.x))
80 binary.Write(buf, binary.LittleEndian, math.Float64bits(p.y))
81 binary.Write(buf, binary.LittleEndian, math.Float64bits(z))
82 }
83
84 return buf.Bytes()
85 }
86
57 func sliceWork( 87 func sliceWork(
58 vs []octree.Vertex, 88 vs []octree.Vertex,
59 dst map[point]float64, 89 dst pointMap,
60 fn func([]octree.Vertex, func([]octree.Vertex) []octree.Vertex), 90 fn func([]octree.Vertex, func([]octree.Vertex) []octree.Vertex),
61 ) { 91 ) {
62 n := runtime.NumCPU() 92 n := runtime.NumCPU()
63 93
64 wg := new(sync.WaitGroup) 94 wg := new(sync.WaitGroup)
211 log.Printf("loading took %v\n", now.Sub(start)) 241 log.Printf("loading took %v\n", now.Sub(start))
212 last := now 242 last := now
213 243
214 firstVs, secondVs := first.Vertices(), second.Vertices() 244 firstVs, secondVs := first.Vertices(), second.Vertices()
215 245
216 result := make(map[point]float64, len(firstVs)+len(secondVs)) 246 result := make(pointMap, len(firstVs)+len(secondVs))
217 247
218 sliceWork( 248 sliceWork(
219 firstVs, 249 firstVs,
220 result, 250 result,
221 func( 251 func(
262 now = time.Now() 292 now = time.Now()
263 log.Printf("setting in took %v\n", now.Sub(last)) 293 log.Printf("setting in took %v\n", now.Sub(last))
264 last = now 294 last = now
265 log.Printf("num points: %d\n", len(result)) 295 log.Printf("num points: %d\n", len(result))
266 296
297 data := result.asWKB()
298
299 now = time.Now()
300 log.Printf("turing into WKB took %v\n", now.Sub(last))
301 last = now
302
303 log.Printf("WKB size %.3fMB\n", float64(len(data))/(1024*1024))
304
267 return nil 305 return nil
268 }) 306 })
269 } 307 }
270 308
271 func main() { 309 func main() {