Mercurial > gemma
comparison pkg/imports/sr.go @ 3604:6248a4bc10c7
Moved triangle elimination to triangulation code.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 05 Jun 2019 11:39:25 +0200 |
parents | 6590733e2ebc |
children | e1021fd60190 |
comparison
equal
deleted
inserted
replaced
3603:2cf7e167dad9 | 3604:6248a4bc10c7 |
---|---|
26 "io" | 26 "io" |
27 "math" | 27 "math" |
28 "os" | 28 "os" |
29 "path" | 29 "path" |
30 "path/filepath" | 30 "path/filepath" |
31 "sort" | |
32 "strconv" | 31 "strconv" |
33 "strings" | 32 "strings" |
34 "time" | 33 "time" |
35 | 34 |
36 shp "github.com/jonas-p/go-shp" | 35 shp "github.com/jonas-p/go-shp" |
37 "gonum.org/v1/gonum/stat" | |
38 | 36 |
39 "gemma.intevation.de/gemma/pkg/common" | 37 "gemma.intevation.de/gemma/pkg/common" |
40 "gemma.intevation.de/gemma/pkg/misc" | 38 "gemma.intevation.de/gemma/pkg/misc" |
41 "gemma.intevation.de/gemma/pkg/models" | 39 "gemma.intevation.de/gemma/pkg/models" |
42 "gemma.intevation.de/gemma/pkg/octree" | 40 "gemma.intevation.de/gemma/pkg/octree" |
364 | 362 |
365 if boundary == nil { | 363 if boundary == nil { |
366 feedback.Info("No boundary given.") | 364 feedback.Info("No boundary given.") |
367 feedback.Info("Eliminate triangles with long edges.") | 365 feedback.Info("Eliminate triangles with long edges.") |
368 | 366 |
369 lens := make([]float64, len(tri.Triangles)/3) | 367 tri.ConcaveHull(0.98) |
370 for i := 0; i < len(tri.Triangles); i += 3 { | |
371 vs := tri.Triangles[i : i+3] | |
372 var max float64 | |
373 for j := 0; j < 3; j++ { | |
374 k := (j + 1) % 3 | |
375 if l := tri.Points[vs[j]].SquaredDistance2D(tri.Points[vs[k]]); l > max { | |
376 max = l | |
377 } | |
378 } | |
379 lens[i/3] = max | |
380 } | |
381 qs := make([]float64, len(lens)) | |
382 copy(qs, lens) | |
383 sort.Float64s(qs) | |
384 q := stat.Quantile(0.98, stat.LinInterp, qs, nil) | |
385 feedback.Info("98%% quantile of the edge lengths: %.2f\n", math.Sqrt(q)) | |
386 | |
387 ts := tri.Triangles | |
388 | |
389 for i := len(lens) - 1; i >= 0; i-- { | |
390 if lens[i] >= q { | |
391 if i != len(lens)-1 { | |
392 copy(ts[i*3:], ts[(i+1)*3:]) | |
393 } | |
394 ts = ts[:len(ts)-3] | |
395 } | |
396 } | |
397 feedback.Info("Remaining triangles: %d (%.2f%%)\n", | |
398 len(ts)/3, float64(len(ts))/float64(len(tri.Triangles))*100.0) | |
399 } | 368 } |
400 | 369 |
401 // TODO: Implement me! | 370 // TODO: Implement me! |
402 return nil, errors.New("Not implemented, yet!") | 371 return nil, errors.New("Not implemented, yet!") |
403 } | 372 } |