# HG changeset patch # User Sascha L. Teichmann # Date 1537391823 -7200 # Node ID a8672ba9ebad6473682d12e5c82391792da2f183 # Parent cea77b2bfb8ef23f6f0dde0ddc7e20aa88882892 octree: Tighten code and dedup triangles earlier in horizontal traversal. diff -r cea77b2bfb8e -r a8672ba9ebad cmd/octree2contour/loader.go --- 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) } } }