-
-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathExample9.cs
More file actions
83 lines (65 loc) · 1.98 KB
/
Example9.cs
File metadata and controls
83 lines (65 loc) · 1.98 KB
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
79
80
81
82
83
namespace TriangleNet.Examples
{
using System.Collections.Generic;
using TriangleNet;
using TriangleNet.Meshing.Iterators;
using TriangleNet.Tools;
/// <summary>
/// Compute the adjacency matrix of the mesh vertices.
/// </summary>
public class Example9 : IExample
{
public bool Run(bool print)
{
var mesh = (Mesh)Example4.CreateMesh();
return FindAdjacencyMatrix(mesh);
}
private static bool FindAdjacencyMatrix(Mesh mesh)
{
mesh.Renumber();
var ap = new List<int>(mesh.Vertices.Count); // Column pointers.
var ai = new List<int>(4 * mesh.Vertices.Count); // Row indices.
var circulator = new VertexCirculator(mesh);
int k = 0;
foreach (var vertex in mesh.Vertices)
{
var star = circulator.EnumerateVertices(vertex);
ap.Add(k);
// Each vertex is adjacent to itself.
ai.Add(vertex.ID);
k++;
foreach (var item in star)
{
ai.Add(item.ID);
k++;
}
}
ap.Add(k);
var matrix1 = new AdjacencyMatrix(ap.ToArray(), ai.ToArray());
var matrix2 = new AdjacencyMatrix(mesh);
// Column pointers should be exactly the same.
if (!CompareArray(matrix1.ColumnPointers, matrix2.ColumnPointers))
{
return false;
}
return true;
}
private static bool CompareArray(int[] a, int[] b)
{
int length = a.Length;
if (b.Length != length)
{
return false;
}
for (int i = 0; i < length; i++)
{
if (a[i] != b[i])
{
return false;
}
}
return true;
}
}
}