# HG changeset patch # User Sascha L. Teichmann # Date 1551702752 -3600 # Node ID 12ed6feefea5da6fc504f4bdecaad47e366a4719 # Parent 98bc023750cff30d72c19471f82db9f023ab6f7d Use octree clipping. Not working, yet! diff -r 98bc023750cf -r 12ed6feefea5 cmd/octreediff/main.go --- a/cmd/octreediff/main.go Mon Mar 04 12:45:44 2019 +0100 +++ b/cmd/octreediff/main.go Mon Mar 04 13:32:32 2019 +0100 @@ -375,6 +375,12 @@ return err } + var clippingPolygon octree.Polygon + if err := clippingPolygon.FromWKB(clip); err != nil { + return err + } + clippingPolygon.Indexify() + now = time.Now() log.Printf("loading clipping polygon took %v\n", now.Sub(last)) last = now @@ -396,6 +402,11 @@ last = now tree := builder.Tree() + tree.Clip(&clippingPolygon) + + now = time.Now() + log.Printf("clipping octree took %v\n", now.Sub(last)) + last = now log.Printf("min/max: %f %f\n", tree.Min.Z, tree.Max.Z) @@ -430,7 +441,7 @@ var dataSize int - stmt, err := tx.PrepareContext(ctx, insertContourSQLClipped) + stmt, err := tx.PrepareContext(ctx, insertContourSQL) if err != nil { return err } @@ -444,13 +455,10 @@ dataSize += len(wkb) _, err = stmt.ExecContext( ctx, - bottleneck, + wkb, first.EPSG, - firstDate, - secondDate, + contourTolerance, res.Height, - wkb, - contourTolerance, ) } }) diff -r 98bc023750cf -r 12ed6feefea5 pkg/octree/tree.go --- 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) {