changeset 683:a31dc9486bd8 octree

octree: fixed triangle indexing bug in horizontal traversal and deduplicate triangles before sending them to callback.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 19 Sep 2018 21:03:54 +0200
parents b17e3ce53285
children cea77b2bfb8e
files cmd/octree2contour/loader.go
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/cmd/octree2contour/loader.go	Wed Sep 19 20:55:02 2018 +0200
+++ b/cmd/octree2contour/loader.go	Wed Sep 19 21:03:54 2018 +0200
@@ -148,6 +148,8 @@
 
 	stack := []frame{{1, ot.min.z, ot.max.z}}
 
+	dupes := map[int32]struct{}{}
+
 	for len(stack) > 0 {
 		top := stack[len(stack)-1]
 		stack = stack[:len(stack)-1]
@@ -176,7 +178,7 @@
 			//log.Printf("%d %d %d\n", pos, n, len(ot.index))
 			indices := ot.index[pos+1 : pos+1+n]
 
-			for idx := range indices {
+			for _, idx := range indices {
 				tri := ot.triangles[idx]
 				v0 := ot.vertices[tri[0]]
 				v1 := ot.vertices[tri[1]]
@@ -184,7 +186,10 @@
 
 				if !(math.Min(v0.z, math.Min(v1.z, v2.z)) > h ||
 					math.Max(v0.z, math.Max(v1.z, v2.z)) < h) {
-					fn(tri)
+					if _, found := dupes[idx]; !found {
+						dupes[idx] = struct{}{}
+						fn(tri)
+					}
 				}
 			}
 		}