comparison cmd/octreediff/main.go @ 2476:efe332e985b9 octree-diff

Calculate the iso lines of the difference.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 28 Feb 2019 11:51:31 +0100
parents 19beb7d17337
children c85b16db8a02
comparison
equal deleted inserted replaced
2475:25e2578b76f3 2476:efe332e985b9
325 builder.Build() 325 builder.Build()
326 326
327 now = time.Now() 327 now = time.Now()
328 log.Printf("building octree took %v\n", now.Sub(last)) 328 log.Printf("building octree took %v\n", now.Sub(last))
329 last = now 329 last = now
330
331 tree := builder.Tree()
332
333 log.Printf("min/max: %f %f\n", tree.Min.Z, tree.Max.Z)
334
335 var heights []float64
336
337 switch {
338 case tree.Min.Z >= 0: // All values positive.
339 for v := 0.0; v <= tree.Max.Z; v += 0.1 {
340 if v >= tree.Min.Z {
341 heights = append(heights, v)
342 }
343 }
344 case tree.Max.Z <= 0: // All values negative.
345 for v := 0.0; v >= tree.Min.Z; v -= 0.1 {
346 if v <= tree.Max.Z {
347 heights = append(heights, v)
348 }
349 }
350 default: // Positive and negative.
351 for v := 0.1; v <= tree.Max.Z; v += 0.1 {
352 heights = append(heights, v)
353 }
354 for i, j := 0, len(heights)-1; i < j; i, j = i+1, j-1 {
355 heights[i], heights[j] = heights[j], heights[i]
356 }
357 for v := 0.0; v >= tree.Min.Z; v -= 0.1 {
358 heights = append(heights, v)
359 }
360 }
361
362 var dataSize int
363
364 octree.DoContours(tree, heights, func(res *octree.ContourResult) {
365 // TODO: Store them.
366 log.Printf("%f: segments: %d\n", res.Height, len(res.Lines))
367 dataSize += len(res.Lines.AsWKB2D())
368 })
369
370 now = time.Now()
371 log.Printf("Number of iso lines: %d\n", len(heights))
372 log.Printf("Total WKB size: %.2fMB\n", float64(dataSize)/(1024*1024))
373 log.Printf("generating iso lines took %v\n", now.Sub(last))
374 last = now
375
330 return nil 376 return nil
331 }) 377 })
332 } 378 }
333 379
334 func main() { 380 func main() {