Mercurial > gemma
comparison cmd/isoareas/main.go @ 4548:befb94e3a953 iso-areas
More debug output.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 30 Sep 2019 11:22:41 +0200 |
parents | 6247f5a42226 |
children | 9c65cef72753 |
comparison
equal
deleted
inserted
replaced
4547:6247f5a42226 | 4548:befb94e3a953 |
---|---|
21 "log" | 21 "log" |
22 "math" | 22 "math" |
23 "math/bits" | 23 "math/bits" |
24 "math/rand" | 24 "math/rand" |
25 "os" | 25 "os" |
26 "sort" | |
26 "strconv" | 27 "strconv" |
27 "strings" | 28 "strings" |
28 "time" | 29 "time" |
29 | 30 |
30 svg "github.com/ajstarks/svgo" | 31 svg "github.com/ajstarks/svgo" |
246 t := octree.Triangle{v0, v1, v2} | 247 t := octree.Triangle{v0, v1, v2} |
247 cut := t.IntersectHorizontal(h) | 248 cut := t.IntersectHorizontal(h) |
248 if len(cut) >= 2 { | 249 if len(cut) >= 2 { |
249 arc := int32(len(arcs)) | 250 arc := int32(len(arcs)) |
250 arcs = append(arcs, cut) | 251 arcs = append(arcs, cut) |
251 cuts[j] = append(cuts[j], indexedArc{arc, i / 3}) | 252 cuts[j] = append(cuts[j], indexedArc{arc: arc, index: i / 3}) |
252 } | 253 } |
253 } | 254 } |
255 } | |
256 | |
257 for l, c := range classes { | |
258 sorted := sort.SliceIsSorted(c, func(i, j int) bool { | |
259 return c[i] < c[j] | |
260 }) | |
261 log.Printf("class[%d] sorted: %t\n", l, sorted) | |
262 } | |
263 | |
264 for l, c := range cuts { | |
265 sorted := sort.SliceIsSorted(c, func(i, j int) bool { | |
266 return c[i].index < c[j].index | |
267 }) | |
268 log.Printf("cut[%d] sorted: %t\n", l, sorted) | |
254 } | 269 } |
255 | 270 |
256 // connect the arcs in a cut list to longer arcs. | 271 // connect the arcs in a cut list to longer arcs. |
257 | 272 |
258 for _, c := range cuts { | 273 for _, c := range cuts { |
267 pb := polygonBuilder{open: list.New()} | 282 pb := polygonBuilder{open: list.New()} |
268 | 283 |
269 usedArcs := map[int32]struct{}{} | 284 usedArcs := map[int32]struct{}{} |
270 var dupes int | 285 var dupes int |
271 | 286 |
272 var isolated, inside int | 287 var isolated, inside, found int |
273 allInClass: | 288 allInClass: |
274 for _, idx := range c { | 289 for _, idx := range c { |
275 ns := neighbors(tri, idx) | 290 ns := neighbors(tri, idx) |
276 mask := where(ns, c) | 291 mask := where(ns, c) |
277 switch bits.OnesCount8(mask) { | 292 switch bits.OnesCount8(mask) { |
289 tri.Points[ti[2]]) | 304 tri.Points[ti[2]]) |
290 continue allInClass | 305 continue allInClass |
291 default: | 306 default: |
292 ti := tri.Triangles[idx*3 : idx*3+3] | 307 ti := tri.Triangles[idx*3 : idx*3+3] |
293 for j := 0; j < 3; j++ { | 308 for j := 0; j < 3; j++ { |
294 if mask&(1<<j) == 0 { | 309 if (mask & (1 << j)) == 0 { |
295 | |
296 // TODO: Look into cuts to see | |
297 // if there are real intersections | |
298 | 310 |
299 var curr octree.LineStringZ | 311 var curr octree.LineStringZ |
300 | 312 |
301 for l := i - 1; l <= i; l++ { | 313 for l := i - 1; l <= i; l++ { |
302 if l < 0 || l >= len(cuts) { | 314 if l < 0 || l >= len(cuts) { |
303 continue | 315 continue |
304 } | 316 } |
305 arcIdx := findArc(ns[j], cuts[l]) | 317 arcIdx := findArc(ns[j]/3, cuts[l]) |
306 if arcIdx == -1 { | 318 if arcIdx == -1 { |
307 continue | 319 continue |
308 } | 320 } |
321 found++ | |
309 aIdx := cuts[l][arcIdx].arc | 322 aIdx := cuts[l][arcIdx].arc |
310 if _, already := usedArcs[aIdx]; already { | 323 if _, already := usedArcs[aIdx]; already { |
311 dupes++ | 324 dupes++ |
312 continue | 325 continue |
313 } | 326 } |
346 } // for all border parts | 359 } // for all border parts |
347 } | 360 } |
348 } | 361 } |
349 } | 362 } |
350 | 363 |
351 log.Printf("\t%d: inside: %d / isolated: %d open: %d closed: %d dupes: %d\n", | 364 log.Printf("\t%d: inside: %d / isolated: %d open: %d closed: %d dupes: %d found: %d\n", |
352 i, inside, isolated, pb.open.Len(), len(pb.polygons), dupes) | 365 i, inside, isolated, pb.open.Len(), len(pb.polygons), dupes, found) |
366 | |
367 /* | |
368 for e := pb.open.Front(); e != nil; e = e.Next() { | |
369 line := e.Value.(octree.LineStringZ) | |
370 pb.polygons = append(pb.polygons, line) | |
371 } | |
372 */ | |
353 | 373 |
354 result[i] = pb.polygons | 374 result[i] = pb.polygons |
355 } | 375 } |
356 | 376 |
357 log.Println("cuts:") | 377 log.Println("cuts:") |