changeset 4532:769f723c2581 iso-areas

Cut triangles against class breaks.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 24 Sep 2019 18:03:43 +0200
parents c9b6be8d81c8
children 3998a9ab69c6
files cmd/isoareas/main.go
diffstat 1 files changed, 49 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/cmd/isoareas/main.go	Tue Sep 24 17:19:52 2019 +0200
+++ b/cmd/isoareas/main.go	Tue Sep 24 18:03:43 2019 +0200
@@ -17,9 +17,11 @@
 	"bufio"
 	"io"
 	"log"
+	"math"
 	"os"
 	"strconv"
 	"strings"
+	"time"
 
 	"gemma.intevation.de/gemma/pkg/octree"
 )
@@ -81,6 +83,49 @@
 	}
 }
 
+func intersectTriangles(tri *octree.Triangulation, heights []float64) {
+
+	type indexedCut struct {
+		cut   octree.LineStringZ
+		index int
+	}
+
+	cuts := make([][]indexedCut, len(heights))
+
+	for i := 0; i < len(tri.Triangles); i += 3 {
+		ti := tri.Triangles[i : i+3]
+		t := octree.Triangle{
+			tri.Points[ti[0]],
+			tri.Points[ti[1]],
+			tri.Points[ti[2]],
+		}
+		min := math.Min(t[0].Z, math.Min(t[1].Z, t[2].Z))
+		max := math.Max(t[0].Z, math.Max(t[1].Z, t[2].Z))
+
+		for j, h := range heights {
+			if h < min {
+				continue
+			}
+			if h > max {
+				break
+			}
+			cut := t.IntersectHorizontal(h)
+			if len(cut) < 2 {
+				continue
+			}
+			cuts[j] = append(cuts[j], indexedCut{cut, i})
+		}
+	}
+
+	log.Println("cuts")
+	for i := range cuts {
+		log.Printf("%.3f: %d\n", heights[i], len(cuts[i]))
+	}
+
+	// TODO: sew segments together.
+
+}
+
 func main() {
 
 	heights, err := octree.ParseClassBreaks(classBreaks)
@@ -99,13 +144,12 @@
 
 	heights = octree.ExtrapolateClassBreaks(heights, min.Z, max.Z)
 
-	log.Println("classes:")
-	for i, v := range heights {
-		log.Printf("\t%d: %.3f\n", i+1, v)
-	}
+	log.Printf("classes: %d\n", len(heights))
 
 	tri, err := octree.Triangulate(xyz)
 	check(err)
 
-	_ = tri
+	start := time.Now()
+	intersectTriangles(tri, heights)
+	log.Printf("intersecting triangles took %v.\n", time.Since(start))
 }