changeset 685:a8672ba9ebad octree

octree: Tighten code and dedup triangles earlier in horizontal traversal.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 19 Sep 2018 23:17:03 +0200
parents cea77b2bfb8e
children a2f107f1e4e7
files cmd/octree2contour/loader.go
diffstat 1 files changed, 12 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/cmd/octree2contour/loader.go	Wed Sep 19 21:08:35 2018 +0200
+++ b/cmd/octree2contour/loader.go	Wed Sep 19 23:17:03 2018 +0200
@@ -149,24 +149,24 @@
 		top := stack[len(stack)-1]
 		stack = stack[:len(stack)-1]
 
-		pos, min, max := top.pos, top.min, top.max
+		pos := top.pos
 		if pos == 0 {
 			continue
 		}
+		min, max := top.min, top.max
 
 		if pos > 0 { // node
-			var zbit int32
 			if mid := (max-min)*0.5 + min; h >= mid {
-				zbit = 4
+				pos += 4 // nodes with z-bit set
 				min = mid
 			} else {
 				max = mid
 			}
 			stack = append(stack,
-				frame{ot.index[pos+0+zbit], min, max},
-				frame{ot.index[pos+1+zbit], min, max},
-				frame{ot.index[pos+2+zbit], min, max},
-				frame{ot.index[pos+3+zbit], min, max})
+				frame{ot.index[pos+0], min, max},
+				frame{ot.index[pos+1], min, max},
+				frame{ot.index[pos+2], min, max},
+				frame{ot.index[pos+3], min, max})
 		} else { // leaf
 			pos = -pos - 1
 			n := ot.index[pos]
@@ -174,6 +174,9 @@
 			indices := ot.index[pos+1 : pos+1+n]
 
 			for _, idx := range indices {
+				if _, found := dupes[idx]; found {
+					continue
+				}
 				tri := ot.triangles[idx]
 				v0 := ot.vertices[tri[0]]
 				v1 := ot.vertices[tri[1]]
@@ -181,10 +184,8 @@
 
 				if !(math.Min(v0.z, math.Min(v1.z, v2.z)) > h ||
 					math.Max(v0.z, math.Max(v1.z, v2.z)) < h) {
-					if _, found := dupes[idx]; !found {
-						dupes[idx] = struct{}{}
-						fn(tri)
-					}
+					dupes[idx] = struct{}{}
+					fn(tri)
 				}
 			}
 		}