Commit 3b3f3c2
BUG: Fix infinite loop in VoronoiDiagram2DGenerator::ConstructDiagram
Fix an infinite loop in ConstructDiagram() that occurs with certain
degenerate seed configurations (ITK issue InsightSoftwareConsortium#4386, supersedes PR InsightSoftwareConsortium#5400).
Root cause: Fortune's algorithm produces near-zero-length edges when
boundary intersection points coincide within floating-point tolerance
but receive different vertex IDs. These edges cannot attach to the
growing cell boundary chain because:
1. Their vertex IDs don't match any chain endpoint.
2. The chain may already be closed (front == back).
3. Boundary-bridging logic doesn't apply when chain endpoints are
interior (not on the domain boundary).
The fix has three parts:
1. Explicit degenerate edge detection: before attempting attachment,
each edge is checked with the existing differentPoint() tolerance
(DIFF_TOLERENCE = 0.001). Edges whose endpoints are geometrically
identical are discarded immediately — they carry no geometric
information and are floating-point artifacts.
2. Stall detection: a counter tracks assembly progress and resets
whenever an edge attaches (since new attachments change the chain
endpoints and may make previously unattachable edges attachable).
When a full pass through the deque makes no progress, the loop
terminates. This improves on PR InsightSoftwareConsortium#5400's simple countdown which
terminated too early, breaking itkVoronoiPartitioningImageFilterTest2.
3. Exception on unexpected residuals: after assembly, if any
non-degenerate edges remain, itkExceptionMacro fires to ensure
unexpected geometric configurations are reported rather than
silently producing incomplete diagrams.
A regression test using the seed configuration from issue InsightSoftwareConsortium#4386
verifies termination and validates all cell boundaries.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 80b191f commit 3b3f3c2
File tree
3 files changed
+149
-1
lines changed- Modules/Segmentation/Voronoi
- include
- test
3 files changed
+149
-1
lines changedLines changed: 63 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
273 | 273 | | |
274 | 274 | | |
275 | 275 | | |
276 | | - | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
277 | 300 | | |
| 301 | + | |
278 | 302 | | |
279 | 303 | | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
280 | 323 | | |
281 | 324 | | |
| 325 | + | |
282 | 326 | | |
283 | 327 | | |
284 | 328 | | |
| |||
353 | 397 | | |
354 | 398 | | |
355 | 399 | | |
| 400 | + | |
356 | 401 | | |
357 | 402 | | |
358 | 403 | | |
359 | 404 | | |
360 | 405 | | |
| 406 | + | |
361 | 407 | | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
362 | 424 | | |
363 | 425 | | |
364 | 426 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
12 | 20 | | |
13 | 21 | | |
14 | 22 | | |
| |||
Lines changed: 78 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
0 commit comments