changeset 3769:6838526df94c simplify-sounding-results

Initial partitioning of the input data.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 25 Jun 2019 18:28:34 +0200
parents 9e3d92785918
children 71164b817d6e
files cmd/srsimplify/main.go
diffstat 1 files changed, 85 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/cmd/srsimplify/main.go	Tue Jun 25 17:44:20 2019 +0200
+++ b/cmd/srsimplify/main.go	Tue Jun 25 18:28:34 2019 +0200
@@ -19,6 +19,7 @@
 	"fmt"
 	"io"
 	"log"
+	"math"
 	"os"
 	"strconv"
 	"strings"
@@ -71,6 +72,90 @@
 
 func simplify(points octree.MultiPointZ, tolerance float64) octree.MultiPointZ {
 
+	if len(points) < 2 {
+		return points
+	}
+
+	min := octree.Vertex{X: math.MaxFloat64, Y: math.MaxFloat64, Z: math.MaxFloat64}
+	max := octree.Vertex{X: -math.MaxFloat64, Y: -math.MaxFloat64, Z: -math.MaxFloat64}
+
+	var maxIdx int
+
+	for i, v := range points {
+		min.Minimize(v)
+
+		if v.X < min.X {
+			min.X = v.X
+		}
+		if v.X > max.X {
+			max.X = v.X
+		}
+		if v.Y < min.Y {
+			min.Y = v.Y
+		}
+		if v.Y > max.Y {
+			max.Y = v.Y
+		}
+		if v.Z < min.Z {
+			min.Z = v.Z
+		}
+		if v.Z > max.Z {
+			max.Z = v.Z
+			maxIdx = i
+		}
+
+		max.Maximize(v)
+	}
+
+	log.Printf("(%.5f, %.5f, %.5f) - (%.5f, %.5f, %.5f)\n",
+		min.X, min.Y, min.Z,
+		max.X, max.Y, max.Z)
+
+	below := min.Z - 2*tolerance
+	xMin := min.X - 1
+	xMax := max.X + 1
+	yMin := min.Y - 1
+	yMax := max.Y + 1
+
+	corners := []octree.Vertex{
+		{xMin, yMin, below},
+		{xMax, yMin, below},
+		{xMax, yMax, below},
+		{xMin, yMax, below},
+	}
+
+	top := points[maxIdx]
+
+	tris := make([]octree.Triangle, len(corners))
+
+	for i, v1 := range corners {
+		v2 := corners[(i+1)%len(corners)]
+		tris[i] = octree.Triangle{v1, v2, top}
+	}
+
+	parts := make([][]octree.Vertex, len(tris))
+	var rest int
+
+nextPoint:
+	for i, v := range points {
+		if i == maxIdx {
+			continue
+		}
+
+		for j := range tris {
+			if tris[j].Contains(v.X, v.Y) {
+				parts[j] = append(parts[j], v)
+				continue nextPoint
+			}
+		}
+		rest++
+	}
+
+	for i, part := range parts {
+		log.Printf("%d: %d\n", i, len(part))
+	}
+	log.Printf("rest: %d\n", rest)
+
 	// TODO: Implement me!
 	return points
 }