changeset 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 98bc023750cf
children c18ae8992070
files cmd/octreediff/main.go pkg/octree/tree.go
diffstat 2 files changed, 33 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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,
 				)
 			}
 		})
--- 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) {