changeset 4534:b7d31a449dd2 iso-areas

Find out how many inner triangles can be skipped because they are totally inside a class polygon.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 25 Sep 2019 15:39:55 +0200
parents 3998a9ab69c6
children 508075a5694e
files cmd/isoareas/main.go
diffstat 1 files changed, 33 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/cmd/isoareas/main.go	Wed Sep 25 13:04:08 2019 +0200
+++ b/cmd/isoareas/main.go	Wed Sep 25 15:39:55 2019 +0200
@@ -19,6 +19,7 @@
 	"log"
 	"math"
 	"os"
+	"sort"
 	"strconv"
 	"strings"
 	"time"
@@ -135,7 +136,15 @@
 
 	log.Println("inside classes:")
 	for _, c := range classes {
-		log.Printf("\t%d\n", len(c))
+		var eliminated int
+		for _, idx := range c {
+			if inner(tri, idx, c) {
+				eliminated++
+			}
+		}
+		log.Printf("\t%d (%d) %.2f%%\n",
+			len(c)-eliminated, len(c),
+			100*float64(eliminated)/float64(len(c)))
 	}
 
 	log.Println("cuts:")
@@ -147,6 +156,29 @@
 
 }
 
+func neighbors(t *octree.Triangulation, idx int32) []int32 {
+	idx *= 3
+	return t.Halfedges[idx : idx+3]
+}
+
+func inner(t *octree.Triangulation, idx int32, indices []int32) bool {
+
+	for _, n := range neighbors(t, idx) {
+		if n < 0 {
+			return false
+		}
+		n /= 3
+		p := sort.Search(len(indices), func(i int) bool {
+			return indices[i] >= n
+		})
+		if p >= len(indices) || indices[p] != n {
+			return false
+		}
+	}
+
+	return true
+}
+
 func main() {
 
 	heights, err := octree.ParseClassBreaks(classBreaks)