Mercurial > gemma
changeset 2576:647a58ee9ae9
Morphological differences: Centralized generation of height values for differences in octree package.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 11 Mar 2019 15:04:23 +0100 |
parents | 59e7a011d347 |
children | fcb139bfa56b |
files | cmd/octreediff/main.go pkg/controllers/diff.go pkg/octree/contours.go |
diffstat | 3 files changed, 37 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/cmd/octreediff/main.go Mon Mar 11 14:50:04 2019 +0100 +++ b/cmd/octreediff/main.go Mon Mar 11 15:04:23 2019 +0100 @@ -254,33 +254,7 @@ 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) - } - } - + heights := octree.SampleDiffHeights(tree.Min.Z, tree.Max.Z, 0.1) log.Printf("num heights: %d\n", len(heights)) var dataSize int
--- a/pkg/controllers/diff.go Mon Mar 11 14:50:04 2019 +0100 +++ b/pkg/controllers/diff.go Mon Mar 11 15:04:23 2019 +0100 @@ -169,6 +169,13 @@ builder.Build(removed) log.Printf("info: building octree took %v\n", time.Since(start)) + tree := builder.Tree() + + log.Printf("info: min/max: %f %f\n", tree.Min.Z, tree.Max.Z) + + heights := octree.SampleDiffHeights(tree.Min.Z, tree.Max.Z, 0.1) + log.Printf("info: num heights: %d\n", len(heights)) + // TODO: Implement me! return
--- a/pkg/octree/contours.go Mon Mar 11 14:50:04 2019 +0100 +++ b/pkg/octree/contours.go Mon Mar 11 15:04:23 2019 +0100 @@ -19,6 +19,35 @@ "sync" ) +func SampleDiffHeights(min, max, step float64) []float64 { + var heights []float64 + switch { + case min >= 0: // All values positive. + for v := 0.0; v <= max; v += step { + if v >= min { + heights = append(heights, v) + } + } + case max <= 0: // All values negative. + for v := 0.0; v >= min; v -= step { + if v <= max { + heights = append(heights, v) + } + } + default: // Positive and negative. + for v := step; v <= max; v += step { + 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 >= min; v -= step { + heights = append(heights, v) + } + } + return heights +} + // ContourResult stores an calculated iso line for a given height. // Is used as a future variable in the concurrent iso line calculation. type ContourResult struct {