Mercurial > gemma
diff pkg/octree/tree.go @ 2496:12ed6feefea5 octree-diff
Use octree clipping. Not working, yet!
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 04 Mar 2019 13:32:32 +0100 |
parents | cb55d7eaaa36 |
children | 62adfe9cbbde |
line wrap: on
line diff
--- a/pkg/octree/tree.go Mon Mar 04 12:45:44 2019 +0100 +++ b/pkg/octree/tree.go Mon Mar 04 13:32:32 2019 +0100 @@ -14,6 +14,7 @@ package octree import ( + "log" "math" ) @@ -50,24 +51,35 @@ func (ot *Tree) Clip(p *Polygon) { + log.Printf("info: num triangles: %d\n", len(ot.triangles)) + all := Box2D{ot.Min.X, ot.Min.Y, ot.Max.X, ot.Max.Y} stack := []boxFrame{{1, all}} triChecks := make(map[int32]IntersectionType) + var triangleTests int + var nodeTests int + var nodesClipped int + var trianglesClipped int + var nodesAllInside int + frames: for len(stack) > 0 { top := stack[len(stack)-1] stack = stack[:len(stack)-1] if top.pos > 0 { // node + nodeTests++ switch p.IntersectionBox2D(top.Box2D) { case IntersectionInside: // all inside so nothing to clip. + nodesAllInside++ continue frames case IntersectionOutSide: // all outside -> clip from tree. + nodesClipped++ if index := ot.index[top.pos:]; len(index) > 7 { for i := range index { index[i] = 0 @@ -128,12 +140,14 @@ } what = p.IntersectionWithTriangle(&t) triChecks[triIndex] = what + triangleTests++ } switch what { case IntersectionInside: // triangle inside -> stay. continue tris default: + trianglesClipped++ // outside or not fully covered -> remove. if i < len(indices)-1 { copy(indices[i:], indices[i+1:]) @@ -145,6 +159,11 @@ ot.index[pos] = int32(len(indices)) } } + log.Printf("info: node tests: %d\n", nodeTests) + log.Printf("info: nodes clipped: %d\n", nodesClipped) + log.Printf("info: nodes all inside: %d\n", nodesAllInside) + log.Printf("info: triangle tests: %d\n", triangleTests) + log.Printf("info: triangle clipped: %d\n", trianglesClipped) } func (ot *Tree) Value(x, y float64) (float64, bool) {