changeset 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 25e2578b76f3
children 9b1f0edf5fdc
files cmd/octreediff/main.go
diffstat 1 files changed, 46 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/cmd/octreediff/main.go	Wed Feb 27 17:44:44 2019 +0100
+++ b/cmd/octreediff/main.go	Thu Feb 28 11:51:31 2019 +0100
@@ -327,6 +327,52 @@
 		now = time.Now()
 		log.Printf("building octree took %v\n", now.Sub(last))
 		last = now
+
+		tree := builder.Tree()
+
+		log.Printf("min/max: %f %f\n", tree.Min.Z, tree.Max.Z)
+
+		var heights []float64
+
+		switch {
+		case tree.Min.Z >= 0: // All values positive.
+			for v := 0.0; v <= tree.Max.Z; v += 0.1 {
+				if v >= tree.Min.Z {
+					heights = append(heights, v)
+				}
+			}
+		case tree.Max.Z <= 0: // All values negative.
+			for v := 0.0; v >= tree.Min.Z; v -= 0.1 {
+				if v <= tree.Max.Z {
+					heights = append(heights, v)
+				}
+			}
+		default: // Positive and negative.
+			for v := 0.1; v <= tree.Max.Z; v += 0.1 {
+				heights = append(heights, v)
+			}
+			for i, j := 0, len(heights)-1; i < j; i, j = i+1, j-1 {
+				heights[i], heights[j] = heights[j], heights[i]
+			}
+			for v := 0.0; v >= tree.Min.Z; v -= 0.1 {
+				heights = append(heights, v)
+			}
+		}
+
+		var dataSize int
+
+		octree.DoContours(tree, heights, func(res *octree.ContourResult) {
+			// TODO: Store them.
+			log.Printf("%f: segments: %d\n", res.Height, len(res.Lines))
+			dataSize += len(res.Lines.AsWKB2D())
+		})
+
+		now = time.Now()
+		log.Printf("Number of iso lines: %d\n", len(heights))
+		log.Printf("Total WKB size: %.2fMB\n", float64(dataSize)/(1024*1024))
+		log.Printf("generating iso lines took %v\n", now.Sub(last))
+		last = now
+
 		return nil
 	})
 }