Mercurial > gemma
changeset 3623:1973fa69b2bb single-beam
More SVG debug output.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 05 Jun 2019 18:17:01 +0200 |
parents | 2893ee8ce06f |
children | 943c454d5633 |
files | pkg/octree/triangulation.go |
diffstat | 1 files changed, 72 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/octree/triangulation.go Wed Jun 05 16:34:52 2019 +0200 +++ b/pkg/octree/triangulation.go Wed Jun 05 18:17:01 2019 +0200 @@ -43,6 +43,29 @@ } func (t *Triangulation) ConcaveHull(tooLong float64) []int32 { + var ( + minX float64 = math.MaxFloat64 + minY float64 = math.MaxFloat64 + maxX float64 = -math.MaxFloat64 + maxY float64 = -math.MaxFloat64 + ) + + linear := func(x1, y1, x2, y2 float64) func(float64) float64 { + // y1 = x1*m + b + // y2 = x2*m + b + // b = y1 - x1*m + // y1-y2 = (x1-x2)*m + // m = (y1-y2)/(x1-x2) for x1 != x2 + + if x1 == x2 { + return func(float64) float64 { return (y1 + y2) * 0.5 } + } + + m := (y1 - y2) / (x1 - x2) + b := y1 - x1*m + + return func(x float64) float64 { return m*x + b } + } tooLong *= tooLong @@ -76,10 +99,53 @@ return false } + for _, i := range candidates { + vs := t.Triangles[i*3 : i*3+3] + for _, vj := range vs { + p := t.Points[vj] + minX = math.Min(p.X, minX) + maxX = math.Max(p.X, maxX) + minY = math.Min(p.Y, minY) + maxY = math.Max(p.Y, maxY) + } + } + + xf := linear(minX, 0, maxX, 1500) + yf := linear(minY, 1500, maxY, 0) + + f, err := os.Create("/tmp/prehull.svg") + if err == nil { + canvas := svg.New(f) + canvas.Start(1500, 1500) + + for _, i := range candidates { + var style string + if isBorder(i) { + style = "stroke:red" + } else { + style = "stroke:black" + } + vs := t.Triangles[i*3 : i*3+3] + for j, vj := range vs { + p0 := t.Points[vj] + p1 := t.Points[vs[(j+1)%3]] + + x1 := int(math.Floor(xf(p0.X))) + y1 := int(math.Floor(yf(p0.Y))) + x2 := int(math.Floor(xf(p1.X))) + y2 := int(math.Floor(yf(p1.Y))) + canvas.Line(x1, y1, x2, y2, style) + } + + } + canvas.End() + f.Close() + } + var newCandidates []int32 + log.Printf("info: candidates: %d\n", len(candidates)) for len(candidates) > 0 { - log.Printf("info: candidates: %d\n", len(candidates)) oldRemoved := len(removed) @@ -114,6 +180,7 @@ for j := int32(0); j < 3; j++ { e := n + j if t.Halfedges[e] < 0 || removed[e/3] { + //if t.Halfedges[e] < 0 { edges = append(edges, [2]int32{ t.Triangles[e], t.Triangles[n+(j+1)%3], @@ -126,50 +193,12 @@ fmt.Printf("%d - %d\n", edges[i][0], edges[i][1]) } + log.Printf("num vertices: %d\n", len(t.Points)) + log.Printf("num of border triangles: %d\n", len(edges)) log.Printf("len convex hull: %d\n", len(t.ConvexHull)) - var ( - minX float64 = math.MaxFloat64 - minY float64 = math.MaxFloat64 - maxX float64 = -math.MaxFloat64 - maxY float64 = -math.MaxFloat64 - ) - - for i := range edges { - p0 := t.Points[edges[i][0]] - p1 := t.Points[edges[i][1]] - - minX = math.Min(p0.X, minX) - maxX = math.Max(p0.X, maxX) - minY = math.Min(p0.Y, minY) - maxY = math.Max(p0.Y, maxY) - - minX = math.Min(p1.X, minX) - maxX = math.Max(p1.X, maxX) - minY = math.Min(p1.Y, minY) - maxY = math.Max(p1.Y, maxY) - } - linear := func(x1, y1, x2, y2 float64) func(float64) float64 { - // y1 = x1*m + b - // y2 = x2*m + b - // b = y1 - x1*m - // y1-y2 = (x1-x2)*m - // m = (y1-y2)/(x1-x2) for x1 != x2 - - if x1 == x2 { - return func(float64) float64 { return (y1 + y2) * 0.5 } - } - - m := (y1 - y2) / (x1 - x2) - b := y1 - x1*m - - return func(x float64) float64 { return m*x + b } - } - xf := linear(minX, 0, maxX, 1499) - yf := linear(minY, 0, maxY, 1499) - - f, err := os.Create("/tmp/hull.svg") + f, err = os.Create("/tmp/hull.svg") if err == nil { canvas := svg.New(f) @@ -188,6 +217,7 @@ canvas.End() f.Close() } + log.Println("after draw") return nil }