Exception in Triangle.NET

Apr 19, 2012 at 3:55 PM

I testet Triangle.NET and it works well with some simple polygones, but I got always an Exception with some complex polygones.

I wand to triangulate a simple box with a number of complex hole polygones inside.

Doing this I got always an Exception at Ori.cs in the Org() function. A breakpoint shows triangle == null.

I followed the problem until the call of InsertSegment in FormSkeleton where sometimes endpoint1 or endpoint2 have trie.triangle == null.

   System.NullReferenceException: Object reference not set to an instance of an object.
   at TriangleNet.Data.Otri.Dest() in \Triangle\Data\Otri.cs:line 346
   at TriangleNet.Mesh.ScoutSegment(Otri& searchtri, Vertex endpoint2, Int32 newmark) in \Triangle\Mesh.cs:line 2598
   at TriangleNet.Mesh.InsertSegment(Vertex endpoint1, Vertex endpoint2, Int32 newmark) in \Triangle\Mesh.cs:line 3040
   at TriangleNet.Mesh.FormSkeleton(MeshData data) in \Triangle\Mesh.cs:line 3200
   at TriangleNet.Mesh.Triangulate(MeshData input) in \Triangle\Mesh.cs:line 226

 

Coordinator
Apr 19, 2012 at 4:55 PM
Edited Apr 19, 2012 at 4:57 PM

My first guess: do you have duplicate points in the input?

If so, I'm aware of the issue: duplicate points are dismissed by the triangulation algorithm, but still some segments could reference those points.

For example, the following input will lead to a crash:

# Simple box with hole
9 2 0 0
# Outer square
  1  -2 -2
  2   2 -2
  3   2  2
  4  -2  2
# Inner square (hole)
  5  -1 -1
  6   1 -1
  7   1  1
  8  -1  1
# Duplicate vertex
  9  -1  1

# Segments
8 0
  1  1 2
  2  2 3
  3  3 4
  4  4 1
  5  5 6
  6  6 7
  7  7 8
# Oops, trouble ahead ...
  8  9 5

# Inner square is a hole
1
  1   0 0

If this isn't the problem, you can send me your polygon file. By the way: to check, if there are duplicate input points just debug into the Triangulate method in Dwyer.cs.

Apr 19, 2012 at 5:07 PM

A demo poly file with the exception is:

 

35 2 0 0
1 1110428 6173914
2 1110386 6174387
3 1110441 6174403
4 1110489 6174226
5 1110600 6174058
6 1110465 6174008
7 1110474 6173970
8 1110529 6173802
9 1110248 6173802
10 1110237 6173852
11 1110428 6173914
12 1108329 6172421
13 1108492 6172440
14 1108532 6172470
15 1108632 6172281
16 1108608 6172134
17 1108386 6172117
18 1108345 6172251
19 1108239 6172225
20 1108206 6172403
21 1108329 6172421
22 1105631 6173102
23 1105716 6173135
24 1105634 6173336
25 1105555 6173306
26 1105631 6173102
27 1100513 6159201
28 1100506 6159115
29 1100763 6159063
30 1100787 6159150
31 1100513 6159201
32 167015 8160342
33 167015 5688800
34 1738756 5688800
35 1738756 8160342
35 0
1 1 2
2 2 3
3 3 4
4 4 5
5 5 6
6 6 7
7 7 8
8 8 9
9 9 10
10 10 11
11 11 1
12 12 13
13 13 14
14 14 15
15 15 16
16 16 17
17 17 18
18 18 19
19 19 20
20 20 21
21 21 12
22 22 23
23 23 24
24 24 25
25 25 26
26 26 22
27 27 28
28 28 29
29 29 30
30 30 31
31 31 27
32 32 33
33 33 34
34 34 35
35 35 32
0

Apr 19, 2012 at 5:22 PM

OK, I found duplicate points.

Thanx for your help.

Coordinator
Apr 19, 2012 at 5:22 PM

Ok, just what I guessed: Duplicate vertices

1 = 11
12 = 21
22 = 26
27 = 31

I'll fix this for the next release (or at least there will be a warning message if duplicates appear).

Coordinator
Apr 20, 2012 at 8:27 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.