scripts
This commit is contained in:
@@ -0,0 +1,192 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TriangleNet.Data;
|
||||
using TriangleNet.Geometry;
|
||||
using TriangleNet.Log;
|
||||
|
||||
namespace TriangleNet.IO
|
||||
{
|
||||
// Token: 0x02000024 RID: 36
|
||||
internal static class DataReader
|
||||
{
|
||||
// Token: 0x06000128 RID: 296 RVA: 0x00015400 File Offset: 0x00013600
|
||||
public static int Reconstruct(Mesh mesh, InputGeometry input, ITriangle[] triangles)
|
||||
{
|
||||
int num = 0;
|
||||
Otri otri = default(Otri);
|
||||
Otri otri2 = default(Otri);
|
||||
Otri otri3 = default(Otri);
|
||||
Otri otri4 = default(Otri);
|
||||
Otri otri5 = default(Otri);
|
||||
Osub osub = default(Osub);
|
||||
int[] array = new int[3];
|
||||
int[] array2 = new int[2];
|
||||
int num2 = ((triangles == null) ? 0 : triangles.Length);
|
||||
int count = input.segments.Count;
|
||||
mesh.inelements = num2;
|
||||
mesh.regions.AddRange(input.regions);
|
||||
int i;
|
||||
for (i = 0; i < mesh.inelements; i++)
|
||||
{
|
||||
mesh.MakeTriangle(ref otri);
|
||||
}
|
||||
if (mesh.behavior.Poly)
|
||||
{
|
||||
mesh.insegments = count;
|
||||
for (i = 0; i < mesh.insegments; i++)
|
||||
{
|
||||
mesh.MakeSegment(ref osub);
|
||||
}
|
||||
}
|
||||
List<Otri>[] array3 = new List<Otri>[mesh.vertices.Count];
|
||||
for (i = 0; i < mesh.vertices.Count; i++)
|
||||
{
|
||||
Otri otri6 = default(Otri);
|
||||
otri6.triangle = Mesh.dummytri;
|
||||
array3[i] = new List<Otri>(3);
|
||||
array3[i].Add(otri6);
|
||||
}
|
||||
i = 0;
|
||||
foreach (Triangle triangle in mesh.triangles.Values)
|
||||
{
|
||||
otri.triangle = triangle;
|
||||
array[0] = triangles[i].P0;
|
||||
array[1] = triangles[i].P1;
|
||||
array[2] = triangles[i].P2;
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
if (array[j] < 0 || array[j] >= mesh.invertices)
|
||||
{
|
||||
SimpleLog.Instance.Error("Triangle has an invalid vertex index.", "MeshReader.Reconstruct()");
|
||||
throw new Exception("Triangle has an invalid vertex index.");
|
||||
}
|
||||
}
|
||||
otri.triangle.region = triangles[i].Region;
|
||||
if (mesh.behavior.VarArea)
|
||||
{
|
||||
otri.triangle.area = triangles[i].Area;
|
||||
}
|
||||
otri.orient = 0;
|
||||
otri.SetOrg(mesh.vertices[array[0]]);
|
||||
otri.SetDest(mesh.vertices[array[1]]);
|
||||
otri.SetApex(mesh.vertices[array[2]]);
|
||||
otri.orient = 0;
|
||||
while (otri.orient < 3)
|
||||
{
|
||||
int num3 = array[otri.orient];
|
||||
int num4 = array3[num3].Count - 1;
|
||||
Otri otri7 = array3[num3][num4];
|
||||
array3[num3].Add(otri);
|
||||
otri3 = otri7;
|
||||
if (otri3.triangle != Mesh.dummytri)
|
||||
{
|
||||
Vertex vertex = otri.Dest();
|
||||
Vertex vertex2 = otri.Apex();
|
||||
do
|
||||
{
|
||||
Vertex vertex3 = otri3.Dest();
|
||||
Vertex vertex4 = otri3.Apex();
|
||||
if (vertex2 == vertex3)
|
||||
{
|
||||
otri.Lprev(ref otri2);
|
||||
otri2.Bond(ref otri3);
|
||||
}
|
||||
if (vertex == vertex4)
|
||||
{
|
||||
otri3.Lprev(ref otri4);
|
||||
otri.Bond(ref otri4);
|
||||
}
|
||||
num4--;
|
||||
otri7 = array3[num3][num4];
|
||||
otri3 = otri7;
|
||||
}
|
||||
while (otri3.triangle != Mesh.dummytri);
|
||||
}
|
||||
otri.orient++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
num = 0;
|
||||
if (mesh.behavior.Poly)
|
||||
{
|
||||
i = 0;
|
||||
foreach (Segment segment in mesh.subsegs.Values)
|
||||
{
|
||||
osub.seg = segment;
|
||||
array2[0] = input.segments[i].P0;
|
||||
array2[1] = input.segments[i].P1;
|
||||
int boundary = input.segments[i].Boundary;
|
||||
for (int k = 0; k < 2; k++)
|
||||
{
|
||||
if (array2[k] < 0 || array2[k] >= mesh.invertices)
|
||||
{
|
||||
SimpleLog.Instance.Error("Segment has an invalid vertex index.", "MeshReader.Reconstruct()");
|
||||
throw new Exception("Segment has an invalid vertex index.");
|
||||
}
|
||||
}
|
||||
osub.orient = 0;
|
||||
Vertex vertex5 = mesh.vertices[array2[0]];
|
||||
Vertex vertex6 = mesh.vertices[array2[1]];
|
||||
osub.SetOrg(vertex5);
|
||||
osub.SetDest(vertex6);
|
||||
osub.SetSegOrg(vertex5);
|
||||
osub.SetSegDest(vertex6);
|
||||
osub.seg.boundary = boundary;
|
||||
osub.orient = 0;
|
||||
while (osub.orient < 2)
|
||||
{
|
||||
int num3 = array2[1 - osub.orient];
|
||||
int num5 = array3[num3].Count - 1;
|
||||
Otri otri8 = array3[num3][num5];
|
||||
Otri otri7 = array3[num3][num5];
|
||||
otri3 = otri7;
|
||||
Vertex vertex7 = osub.Org();
|
||||
bool flag = true;
|
||||
while (flag && otri3.triangle != Mesh.dummytri)
|
||||
{
|
||||
Vertex vertex3 = otri3.Dest();
|
||||
if (vertex7 == vertex3)
|
||||
{
|
||||
array3[num3].Remove(otri8);
|
||||
otri3.SegBond(ref osub);
|
||||
otri3.Sym(ref otri5);
|
||||
if (otri5.triangle == Mesh.dummytri)
|
||||
{
|
||||
mesh.InsertSubseg(ref otri3, 1);
|
||||
num++;
|
||||
}
|
||||
flag = false;
|
||||
}
|
||||
num5--;
|
||||
otri8 = array3[num3][num5];
|
||||
otri7 = array3[num3][num5];
|
||||
otri3 = otri7;
|
||||
}
|
||||
osub.orient++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < mesh.vertices.Count; i++)
|
||||
{
|
||||
int num6 = array3[i].Count - 1;
|
||||
Otri otri7 = array3[i][num6];
|
||||
otri3 = otri7;
|
||||
while (otri3.triangle != Mesh.dummytri)
|
||||
{
|
||||
num6--;
|
||||
otri7 = array3[i][num6];
|
||||
otri3.SegDissolve();
|
||||
otri3.Sym(ref otri5);
|
||||
if (otri5.triangle == Mesh.dummytri)
|
||||
{
|
||||
mesh.InsertSubseg(ref otri3, 1);
|
||||
num++;
|
||||
}
|
||||
otri3 = otri7;
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using TriangleNet.Data;
|
||||
using TriangleNet.Geometry;
|
||||
|
||||
namespace TriangleNet.IO
|
||||
{
|
||||
// Token: 0x02000025 RID: 37
|
||||
internal class DebugWriter
|
||||
{
|
||||
// Token: 0x0600012A RID: 298 RVA: 0x00013025 File Offset: 0x00011225
|
||||
private DebugWriter()
|
||||
{
|
||||
}
|
||||
|
||||
// Token: 0x17000057 RID: 87
|
||||
// (get) Token: 0x0600012B RID: 299 RVA: 0x00015A67 File Offset: 0x00013C67
|
||||
public static DebugWriter Session
|
||||
{
|
||||
get
|
||||
{
|
||||
return DebugWriter.instance;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600012C RID: 300 RVA: 0x00015A6E File Offset: 0x00013C6E
|
||||
public void Start(string session)
|
||||
{
|
||||
this.iteration = 0;
|
||||
this.session = session;
|
||||
if (this.stream != null)
|
||||
{
|
||||
throw new Exception("A session is active. Finish before starting a new.");
|
||||
}
|
||||
this.tmpFile = Path.GetTempFileName();
|
||||
this.stream = new StreamWriter(this.tmpFile);
|
||||
}
|
||||
|
||||
// Token: 0x0600012D RID: 301 RVA: 0x00015AAD File Offset: 0x00013CAD
|
||||
public void Write(Mesh mesh, bool skip)
|
||||
{
|
||||
this.WriteMesh(mesh, skip);
|
||||
this.triangles = mesh.Triangles.Count;
|
||||
}
|
||||
|
||||
// Token: 0x0600012E RID: 302 RVA: 0x00015AC8 File Offset: 0x00013CC8
|
||||
public void Write(Mesh mesh)
|
||||
{
|
||||
this.Write(mesh, false);
|
||||
}
|
||||
|
||||
// Token: 0x0600012F RID: 303 RVA: 0x00015AD2 File Offset: 0x00013CD2
|
||||
public void Finish()
|
||||
{
|
||||
this.Finish(this.session + ".mshx");
|
||||
}
|
||||
|
||||
// Token: 0x06000130 RID: 304 RVA: 0x00015AEC File Offset: 0x00013CEC
|
||||
private void Finish(string path)
|
||||
{
|
||||
if (this.stream != null)
|
||||
{
|
||||
this.stream.Flush();
|
||||
this.stream.Dispose();
|
||||
this.stream = null;
|
||||
string text = "#!N" + this.iteration + Environment.NewLine;
|
||||
using (FileStream fileStream = new FileStream(path, FileMode.Create))
|
||||
{
|
||||
using (GZipStream gzipStream = new GZipStream(fileStream, CompressionMode.Compress, false))
|
||||
{
|
||||
byte[] array = Encoding.UTF8.GetBytes(text);
|
||||
gzipStream.Write(array, 0, array.Length);
|
||||
array = File.ReadAllBytes(this.tmpFile);
|
||||
gzipStream.Write(array, 0, array.Length);
|
||||
}
|
||||
}
|
||||
File.Delete(this.tmpFile);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000131 RID: 305 RVA: 0x00015BB8 File Offset: 0x00013DB8
|
||||
private void WriteGeometry(InputGeometry geometry)
|
||||
{
|
||||
TextWriter textWriter = this.stream;
|
||||
string text = "#!G{0}";
|
||||
int num = this.iteration;
|
||||
this.iteration = num + 1;
|
||||
textWriter.WriteLine(text, num);
|
||||
}
|
||||
|
||||
// Token: 0x06000132 RID: 306 RVA: 0x00015BEC File Offset: 0x00013DEC
|
||||
private void WriteMesh(Mesh mesh, bool skip)
|
||||
{
|
||||
if (this.triangles == mesh.triangles.Count && skip)
|
||||
{
|
||||
return;
|
||||
}
|
||||
TextWriter textWriter = this.stream;
|
||||
string text = "#!M{0}";
|
||||
int num = this.iteration;
|
||||
this.iteration = num + 1;
|
||||
textWriter.WriteLine(text, num);
|
||||
if (this.VerticesChanged(mesh))
|
||||
{
|
||||
this.HashVertices(mesh);
|
||||
this.stream.WriteLine("{0}", mesh.vertices.Count);
|
||||
using (Dictionary<int, Vertex>.ValueCollection.Enumerator enumerator = mesh.vertices.Values.GetEnumerator())
|
||||
{
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
Vertex vertex = enumerator.Current;
|
||||
this.stream.WriteLine("{0} {1} {2} {3}", new object[]
|
||||
{
|
||||
vertex.hash,
|
||||
vertex.x.ToString(DebugWriter.nfi),
|
||||
vertex.y.ToString(DebugWriter.nfi),
|
||||
vertex.mark
|
||||
});
|
||||
}
|
||||
goto IL_116;
|
||||
}
|
||||
}
|
||||
this.stream.WriteLine("0");
|
||||
IL_116:
|
||||
this.stream.WriteLine("{0}", mesh.subsegs.Count);
|
||||
Osub osub = default(Osub);
|
||||
osub.orient = 0;
|
||||
foreach (Segment segment in mesh.subsegs.Values)
|
||||
{
|
||||
if (segment.hash > 0)
|
||||
{
|
||||
osub.seg = segment;
|
||||
Vertex vertex2 = osub.Org();
|
||||
Vertex vertex3 = osub.Dest();
|
||||
this.stream.WriteLine("{0} {1} {2} {3}", new object[]
|
||||
{
|
||||
osub.seg.hash,
|
||||
vertex2.hash,
|
||||
vertex3.hash,
|
||||
osub.seg.boundary
|
||||
});
|
||||
}
|
||||
}
|
||||
Otri otri = default(Otri);
|
||||
Otri otri2 = default(Otri);
|
||||
otri.orient = 0;
|
||||
this.stream.WriteLine("{0}", mesh.triangles.Count);
|
||||
foreach (Triangle triangle in mesh.triangles.Values)
|
||||
{
|
||||
otri.triangle = triangle;
|
||||
Vertex vertex2 = otri.Org();
|
||||
Vertex vertex3 = otri.Dest();
|
||||
Vertex vertex4 = otri.Apex();
|
||||
int num2 = ((vertex2 == null) ? (-1) : vertex2.hash);
|
||||
int num3 = ((vertex3 == null) ? (-1) : vertex3.hash);
|
||||
int num4 = ((vertex4 == null) ? (-1) : vertex4.hash);
|
||||
this.stream.Write("{0} {1} {2} {3}", new object[]
|
||||
{
|
||||
otri.triangle.hash,
|
||||
num2,
|
||||
num3,
|
||||
num4
|
||||
});
|
||||
otri.orient = 1;
|
||||
otri.Sym(ref otri2);
|
||||
int hash = otri2.triangle.hash;
|
||||
otri.orient = 2;
|
||||
otri.Sym(ref otri2);
|
||||
int hash2 = otri2.triangle.hash;
|
||||
otri.orient = 0;
|
||||
otri.Sym(ref otri2);
|
||||
int hash3 = otri2.triangle.hash;
|
||||
this.stream.WriteLine(" {0} {1} {2}", hash, hash2, hash3);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000133 RID: 307 RVA: 0x00015FE0 File Offset: 0x000141E0
|
||||
private bool VerticesChanged(Mesh mesh)
|
||||
{
|
||||
if (this.vertices == null || mesh.Vertices.Count != this.vertices.Length)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
int num = 0;
|
||||
using (IEnumerator<Vertex> enumerator = mesh.Vertices.GetEnumerator())
|
||||
{
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
if (enumerator.Current.id != this.vertices[num++])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Token: 0x06000134 RID: 308 RVA: 0x00016060 File Offset: 0x00014260
|
||||
private void HashVertices(Mesh mesh)
|
||||
{
|
||||
if (this.vertices == null || mesh.Vertices.Count != this.vertices.Length)
|
||||
{
|
||||
this.vertices = new int[mesh.Vertices.Count];
|
||||
}
|
||||
int num = 0;
|
||||
foreach (Vertex vertex in mesh.Vertices)
|
||||
{
|
||||
this.vertices[num++] = vertex.id;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x040000E0 RID: 224
|
||||
private static NumberFormatInfo nfi = CultureInfo.InvariantCulture.NumberFormat;
|
||||
|
||||
// Token: 0x040000E1 RID: 225
|
||||
private int iteration;
|
||||
|
||||
// Token: 0x040000E2 RID: 226
|
||||
private string session;
|
||||
|
||||
// Token: 0x040000E3 RID: 227
|
||||
private StreamWriter stream;
|
||||
|
||||
// Token: 0x040000E4 RID: 228
|
||||
private string tmpFile;
|
||||
|
||||
// Token: 0x040000E5 RID: 229
|
||||
private int[] vertices;
|
||||
|
||||
// Token: 0x040000E6 RID: 230
|
||||
private int triangles;
|
||||
|
||||
// Token: 0x040000E7 RID: 231
|
||||
private static readonly DebugWriter instance = new DebugWriter();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,486 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using TriangleNet.Geometry;
|
||||
using TriangleNet.Log;
|
||||
|
||||
namespace TriangleNet.IO
|
||||
{
|
||||
// Token: 0x0200002A RID: 42
|
||||
public static class FileReader
|
||||
{
|
||||
// Token: 0x06000154 RID: 340 RVA: 0x000171D4 File Offset: 0x000153D4
|
||||
private static bool TryReadLine(StreamReader reader, out string[] token)
|
||||
{
|
||||
token = null;
|
||||
if (reader.EndOfStream)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string text = reader.ReadLine().Trim();
|
||||
while (string.IsNullOrEmpty(text.Trim()) || text.StartsWith("#"))
|
||||
{
|
||||
if (reader.EndOfStream)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
text = reader.ReadLine().Trim();
|
||||
}
|
||||
token = text.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Token: 0x06000155 RID: 341 RVA: 0x00017248 File Offset: 0x00015448
|
||||
private static void ReadVertex(InputGeometry data, int index, string[] line, int attributes, int marks)
|
||||
{
|
||||
double num = double.Parse(line[1], FileReader.nfi);
|
||||
double num2 = double.Parse(line[2], FileReader.nfi);
|
||||
int num3 = 0;
|
||||
double[] array = ((attributes == 0) ? null : new double[attributes]);
|
||||
for (int i = 0; i < attributes; i++)
|
||||
{
|
||||
if (line.Length > 3 + i)
|
||||
{
|
||||
array[i] = double.Parse(line[3 + i], FileReader.nfi);
|
||||
}
|
||||
}
|
||||
if (marks > 0 && line.Length > 3 + attributes)
|
||||
{
|
||||
num3 = int.Parse(line[3 + attributes]);
|
||||
}
|
||||
data.AddPoint(num, num2, num3, array);
|
||||
}
|
||||
|
||||
// Token: 0x06000156 RID: 342 RVA: 0x000172D0 File Offset: 0x000154D0
|
||||
public static void Read(string filename, out InputGeometry geometry)
|
||||
{
|
||||
geometry = null;
|
||||
string text = Path.ChangeExtension(filename, ".poly");
|
||||
if (File.Exists(text))
|
||||
{
|
||||
geometry = FileReader.ReadPolyFile(text);
|
||||
return;
|
||||
}
|
||||
text = Path.ChangeExtension(filename, ".node");
|
||||
geometry = FileReader.ReadNodeFile(text);
|
||||
}
|
||||
|
||||
// Token: 0x06000157 RID: 343 RVA: 0x00017314 File Offset: 0x00015514
|
||||
public static void Read(string filename, out InputGeometry geometry, out List<ITriangle> triangles)
|
||||
{
|
||||
triangles = null;
|
||||
FileReader.Read(filename, out geometry);
|
||||
string text = Path.ChangeExtension(filename, ".ele");
|
||||
if (File.Exists(text) && geometry != null)
|
||||
{
|
||||
triangles = FileReader.ReadEleFile(text);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000158 RID: 344 RVA: 0x0001734C File Offset: 0x0001554C
|
||||
public static InputGeometry Read(string filename)
|
||||
{
|
||||
InputGeometry inputGeometry = null;
|
||||
FileReader.Read(filename, out inputGeometry);
|
||||
return inputGeometry;
|
||||
}
|
||||
|
||||
// Token: 0x06000159 RID: 345 RVA: 0x00017364 File Offset: 0x00015564
|
||||
public static InputGeometry ReadNodeFile(string nodefilename)
|
||||
{
|
||||
return FileReader.ReadNodeFile(nodefilename, false);
|
||||
}
|
||||
|
||||
// Token: 0x0600015A RID: 346 RVA: 0x00017370 File Offset: 0x00015570
|
||||
public static InputGeometry ReadNodeFile(string nodefilename, bool readElements)
|
||||
{
|
||||
FileReader.startIndex = 0;
|
||||
int num = 0;
|
||||
int num2 = 0;
|
||||
InputGeometry inputGeometry;
|
||||
using (StreamReader streamReader = new StreamReader(nodefilename))
|
||||
{
|
||||
string[] array;
|
||||
if (!FileReader.TryReadLine(streamReader, out array))
|
||||
{
|
||||
throw new Exception("Can't read input file.");
|
||||
}
|
||||
int num3 = int.Parse(array[0]);
|
||||
if (num3 < 3)
|
||||
{
|
||||
throw new Exception("Input must have at least three input vertices.");
|
||||
}
|
||||
if (array.Length > 1 && int.Parse(array[1]) != 2)
|
||||
{
|
||||
throw new Exception("Triangle only works with two-dimensional meshes.");
|
||||
}
|
||||
if (array.Length > 2)
|
||||
{
|
||||
num = int.Parse(array[2]);
|
||||
}
|
||||
if (array.Length > 3)
|
||||
{
|
||||
num2 = int.Parse(array[3]);
|
||||
}
|
||||
inputGeometry = new InputGeometry(num3);
|
||||
if (num3 > 0)
|
||||
{
|
||||
for (int i = 0; i < num3; i++)
|
||||
{
|
||||
if (!FileReader.TryReadLine(streamReader, out array))
|
||||
{
|
||||
throw new Exception("Can't read input file (vertices).");
|
||||
}
|
||||
if (array.Length < 3)
|
||||
{
|
||||
throw new Exception("Invalid vertex.");
|
||||
}
|
||||
if (i == 0)
|
||||
{
|
||||
FileReader.startIndex = int.Parse(array[0], FileReader.nfi);
|
||||
}
|
||||
FileReader.ReadVertex(inputGeometry, i, array, num, num2);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (readElements)
|
||||
{
|
||||
string text = Path.ChangeExtension(nodefilename, ".ele");
|
||||
if (File.Exists(text))
|
||||
{
|
||||
FileReader.ReadEleFile(text, true);
|
||||
}
|
||||
}
|
||||
return inputGeometry;
|
||||
}
|
||||
|
||||
// Token: 0x0600015B RID: 347 RVA: 0x000174A0 File Offset: 0x000156A0
|
||||
public static InputGeometry ReadPolyFile(string polyfilename)
|
||||
{
|
||||
return FileReader.ReadPolyFile(polyfilename, false, false);
|
||||
}
|
||||
|
||||
// Token: 0x0600015C RID: 348 RVA: 0x000174AA File Offset: 0x000156AA
|
||||
public static InputGeometry ReadPolyFile(string polyfilename, bool readElements)
|
||||
{
|
||||
return FileReader.ReadPolyFile(polyfilename, readElements, false);
|
||||
}
|
||||
|
||||
// Token: 0x0600015D RID: 349 RVA: 0x000174B4 File Offset: 0x000156B4
|
||||
public static InputGeometry ReadPolyFile(string polyfilename, bool readElements, bool readArea)
|
||||
{
|
||||
FileReader.startIndex = 0;
|
||||
int num = 0;
|
||||
int num2 = 0;
|
||||
InputGeometry inputGeometry;
|
||||
using (StreamReader streamReader = new StreamReader(polyfilename))
|
||||
{
|
||||
string[] array;
|
||||
if (!FileReader.TryReadLine(streamReader, out array))
|
||||
{
|
||||
throw new Exception("Can't read input file.");
|
||||
}
|
||||
int num3 = int.Parse(array[0]);
|
||||
if (array.Length > 1 && int.Parse(array[1]) != 2)
|
||||
{
|
||||
throw new Exception("Triangle only works with two-dimensional meshes.");
|
||||
}
|
||||
if (array.Length > 2)
|
||||
{
|
||||
num = int.Parse(array[2]);
|
||||
}
|
||||
if (array.Length > 3)
|
||||
{
|
||||
num2 = int.Parse(array[3]);
|
||||
}
|
||||
if (num3 > 0)
|
||||
{
|
||||
inputGeometry = new InputGeometry(num3);
|
||||
for (int i = 0; i < num3; i++)
|
||||
{
|
||||
if (!FileReader.TryReadLine(streamReader, out array))
|
||||
{
|
||||
throw new Exception("Can't read input file (vertices).");
|
||||
}
|
||||
if (array.Length < 3)
|
||||
{
|
||||
throw new Exception("Invalid vertex.");
|
||||
}
|
||||
if (i == 0)
|
||||
{
|
||||
FileReader.startIndex = int.Parse(array[0], FileReader.nfi);
|
||||
}
|
||||
FileReader.ReadVertex(inputGeometry, i, array, num, num2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
inputGeometry = FileReader.ReadNodeFile(Path.ChangeExtension(polyfilename, ".node"));
|
||||
num3 = inputGeometry.Count;
|
||||
}
|
||||
if (inputGeometry.Points == null)
|
||||
{
|
||||
throw new Exception("No nodes available.");
|
||||
}
|
||||
if (!FileReader.TryReadLine(streamReader, out array))
|
||||
{
|
||||
throw new Exception("Can't read input file (segments).");
|
||||
}
|
||||
int num4 = int.Parse(array[0]);
|
||||
int num5 = 0;
|
||||
if (array.Length > 1)
|
||||
{
|
||||
num5 = int.Parse(array[1]);
|
||||
}
|
||||
for (int j = 0; j < num4; j++)
|
||||
{
|
||||
if (!FileReader.TryReadLine(streamReader, out array))
|
||||
{
|
||||
throw new Exception("Can't read input file (segments).");
|
||||
}
|
||||
if (array.Length < 3)
|
||||
{
|
||||
throw new Exception("Segment has no endpoints.");
|
||||
}
|
||||
int num6 = int.Parse(array[1]) - FileReader.startIndex;
|
||||
int num7 = int.Parse(array[2]) - FileReader.startIndex;
|
||||
int num8 = 0;
|
||||
if (num5 > 0 && array.Length > 3)
|
||||
{
|
||||
num8 = int.Parse(array[3]);
|
||||
}
|
||||
if (num6 < 0 || num6 >= num3)
|
||||
{
|
||||
if (Behavior.Verbose)
|
||||
{
|
||||
SimpleLog.Instance.Warning("Invalid first endpoint of segment.", "MeshReader.ReadPolyfile()");
|
||||
}
|
||||
}
|
||||
else if (num7 < 0 || num7 >= num3)
|
||||
{
|
||||
if (Behavior.Verbose)
|
||||
{
|
||||
SimpleLog.Instance.Warning("Invalid second endpoint of segment.", "MeshReader.ReadPolyfile()");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
inputGeometry.AddSegment(num6, num7, num8);
|
||||
}
|
||||
}
|
||||
if (!FileReader.TryReadLine(streamReader, out array))
|
||||
{
|
||||
throw new Exception("Can't read input file (holes).");
|
||||
}
|
||||
int num9 = int.Parse(array[0]);
|
||||
if (num9 > 0)
|
||||
{
|
||||
for (int k = 0; k < num9; k++)
|
||||
{
|
||||
if (!FileReader.TryReadLine(streamReader, out array))
|
||||
{
|
||||
throw new Exception("Can't read input file (holes).");
|
||||
}
|
||||
if (array.Length < 3)
|
||||
{
|
||||
throw new Exception("Invalid hole.");
|
||||
}
|
||||
inputGeometry.AddHole(double.Parse(array[1], FileReader.nfi), double.Parse(array[2], FileReader.nfi));
|
||||
}
|
||||
}
|
||||
if (FileReader.TryReadLine(streamReader, out array))
|
||||
{
|
||||
int num10 = int.Parse(array[0]);
|
||||
if (num10 > 0)
|
||||
{
|
||||
for (int l = 0; l < num10; l++)
|
||||
{
|
||||
if (!FileReader.TryReadLine(streamReader, out array))
|
||||
{
|
||||
throw new Exception("Can't read input file (region).");
|
||||
}
|
||||
if (array.Length < 4)
|
||||
{
|
||||
throw new Exception("Invalid region attributes.");
|
||||
}
|
||||
inputGeometry.AddRegion(double.Parse(array[1], FileReader.nfi), double.Parse(array[2], FileReader.nfi), int.Parse(array[3]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (readElements)
|
||||
{
|
||||
string text = Path.ChangeExtension(polyfilename, ".ele");
|
||||
if (File.Exists(text))
|
||||
{
|
||||
FileReader.ReadEleFile(text, readArea);
|
||||
}
|
||||
}
|
||||
return inputGeometry;
|
||||
}
|
||||
|
||||
// Token: 0x0600015E RID: 350 RVA: 0x00017808 File Offset: 0x00015A08
|
||||
public static List<ITriangle> ReadEleFile(string elefilename)
|
||||
{
|
||||
return FileReader.ReadEleFile(elefilename, false);
|
||||
}
|
||||
|
||||
// Token: 0x0600015F RID: 351 RVA: 0x00017814 File Offset: 0x00015A14
|
||||
private static List<ITriangle> ReadEleFile(string elefilename, bool readArea)
|
||||
{
|
||||
int num = 0;
|
||||
List<ITriangle> list;
|
||||
using (StreamReader streamReader = new StreamReader(elefilename))
|
||||
{
|
||||
bool flag = false;
|
||||
string[] array;
|
||||
if (!FileReader.TryReadLine(streamReader, out array))
|
||||
{
|
||||
throw new Exception("Can't read input file (elements).");
|
||||
}
|
||||
num = int.Parse(array[0]);
|
||||
int num2 = 0;
|
||||
if (array.Length > 2)
|
||||
{
|
||||
num2 = int.Parse(array[2]);
|
||||
flag = true;
|
||||
}
|
||||
if (num2 > 1)
|
||||
{
|
||||
SimpleLog.Instance.Warning("Triangle attributes not supported.", "FileReader.Read");
|
||||
}
|
||||
list = new List<ITriangle>(num);
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
if (!FileReader.TryReadLine(streamReader, out array))
|
||||
{
|
||||
throw new Exception("Can't read input file (elements).");
|
||||
}
|
||||
if (array.Length < 4)
|
||||
{
|
||||
throw new Exception("Triangle has no nodes.");
|
||||
}
|
||||
InputTriangle inputTriangle = new InputTriangle(int.Parse(array[1]) - FileReader.startIndex, int.Parse(array[2]) - FileReader.startIndex, int.Parse(array[3]) - FileReader.startIndex);
|
||||
if (num2 > 0 && flag)
|
||||
{
|
||||
int num3 = 0;
|
||||
flag = int.TryParse(array[4], out num3);
|
||||
inputTriangle.region = num3;
|
||||
}
|
||||
list.Add(inputTriangle);
|
||||
}
|
||||
}
|
||||
if (readArea)
|
||||
{
|
||||
string text = Path.ChangeExtension(elefilename, ".area");
|
||||
if (File.Exists(text))
|
||||
{
|
||||
FileReader.ReadAreaFile(text, num);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
// Token: 0x06000160 RID: 352 RVA: 0x00017960 File Offset: 0x00015B60
|
||||
private static double[] ReadAreaFile(string areafilename, int intriangles)
|
||||
{
|
||||
double[] array = null;
|
||||
using (StreamReader streamReader = new StreamReader(areafilename))
|
||||
{
|
||||
string[] array2;
|
||||
if (!FileReader.TryReadLine(streamReader, out array2))
|
||||
{
|
||||
throw new Exception("Can't read input file (area).");
|
||||
}
|
||||
if (int.Parse(array2[0]) != intriangles)
|
||||
{
|
||||
SimpleLog.Instance.Warning("Number of area constraints doesn't match number of triangles.", "ReadAreaFile()");
|
||||
return null;
|
||||
}
|
||||
array = new double[intriangles];
|
||||
for (int i = 0; i < intriangles; i++)
|
||||
{
|
||||
if (!FileReader.TryReadLine(streamReader, out array2))
|
||||
{
|
||||
throw new Exception("Can't read input file (area).");
|
||||
}
|
||||
if (array2.Length != 2)
|
||||
{
|
||||
throw new Exception("Triangle has no nodes.");
|
||||
}
|
||||
array[i] = double.Parse(array2[1], FileReader.nfi);
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// Token: 0x06000161 RID: 353 RVA: 0x00017A1C File Offset: 0x00015C1C
|
||||
public static List<Edge> ReadEdgeFile(string edgeFile, int invertices)
|
||||
{
|
||||
List<Edge> list = null;
|
||||
FileReader.startIndex = 0;
|
||||
using (StreamReader streamReader = new StreamReader(edgeFile))
|
||||
{
|
||||
string[] array;
|
||||
if (!FileReader.TryReadLine(streamReader, out array))
|
||||
{
|
||||
throw new Exception("Can't read input file (segments).");
|
||||
}
|
||||
int num = int.Parse(array[0]);
|
||||
int num2 = 0;
|
||||
if (array.Length > 1)
|
||||
{
|
||||
num2 = int.Parse(array[1]);
|
||||
}
|
||||
if (num > 0)
|
||||
{
|
||||
list = new List<Edge>(num);
|
||||
}
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
if (!FileReader.TryReadLine(streamReader, out array))
|
||||
{
|
||||
throw new Exception("Can't read input file (segments).");
|
||||
}
|
||||
if (array.Length < 3)
|
||||
{
|
||||
throw new Exception("Segment has no endpoints.");
|
||||
}
|
||||
int num3 = int.Parse(array[1]) - FileReader.startIndex;
|
||||
int num4 = int.Parse(array[2]) - FileReader.startIndex;
|
||||
int num5 = 0;
|
||||
if (num2 > 0 && array.Length > 3)
|
||||
{
|
||||
num5 = int.Parse(array[3]);
|
||||
}
|
||||
if (num3 < 0 || num3 >= invertices)
|
||||
{
|
||||
if (Behavior.Verbose)
|
||||
{
|
||||
SimpleLog.Instance.Warning("Invalid first endpoint of segment.", "MeshReader.ReadPolyfile()");
|
||||
}
|
||||
}
|
||||
else if (num4 < 0 || num4 >= invertices)
|
||||
{
|
||||
if (Behavior.Verbose)
|
||||
{
|
||||
SimpleLog.Instance.Warning("Invalid second endpoint of segment.", "MeshReader.ReadPolyfile()");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(new Edge(num3, num4, num5));
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
// Token: 0x040000EC RID: 236
|
||||
private static NumberFormatInfo nfi = CultureInfo.InvariantCulture.NumberFormat;
|
||||
|
||||
// Token: 0x040000ED RID: 237
|
||||
private static int startIndex = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,385 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using TriangleNet.Data;
|
||||
using TriangleNet.Geometry;
|
||||
|
||||
namespace TriangleNet.IO
|
||||
{
|
||||
// Token: 0x02000026 RID: 38
|
||||
public static class FileWriter
|
||||
{
|
||||
// Token: 0x06000135 RID: 309 RVA: 0x000160F0 File Offset: 0x000142F0
|
||||
public static void Write(Mesh mesh, string filename)
|
||||
{
|
||||
FileWriter.WritePoly(mesh, Path.ChangeExtension(filename, ".poly"));
|
||||
FileWriter.WriteElements(mesh, Path.ChangeExtension(filename, ".ele"));
|
||||
}
|
||||
|
||||
// Token: 0x06000136 RID: 310 RVA: 0x00016114 File Offset: 0x00014314
|
||||
public static void WriteNodes(Mesh mesh, string filename)
|
||||
{
|
||||
using (StreamWriter streamWriter = new StreamWriter(filename))
|
||||
{
|
||||
FileWriter.WriteNodes(streamWriter, mesh);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000137 RID: 311 RVA: 0x0001614C File Offset: 0x0001434C
|
||||
private static void WriteNodes(StreamWriter writer, Mesh mesh)
|
||||
{
|
||||
int num = mesh.vertices.Count;
|
||||
Behavior behavior = mesh.behavior;
|
||||
if (behavior.Jettison)
|
||||
{
|
||||
num = mesh.vertices.Count - mesh.undeads;
|
||||
}
|
||||
if (writer != null)
|
||||
{
|
||||
writer.WriteLine("{0} {1} {2} {3}", new object[]
|
||||
{
|
||||
num,
|
||||
mesh.mesh_dim,
|
||||
mesh.nextras,
|
||||
behavior.UseBoundaryMarkers ? "1" : "0"
|
||||
});
|
||||
if (mesh.numbering == NodeNumbering.None)
|
||||
{
|
||||
mesh.Renumber();
|
||||
}
|
||||
if (mesh.numbering == NodeNumbering.Linear)
|
||||
{
|
||||
FileWriter.WriteNodes(writer, mesh.vertices.Values, behavior.UseBoundaryMarkers, mesh.nextras, behavior.Jettison);
|
||||
return;
|
||||
}
|
||||
Vertex[] array = new Vertex[mesh.vertices.Count];
|
||||
foreach (Vertex vertex in mesh.vertices.Values)
|
||||
{
|
||||
array[vertex.id] = vertex;
|
||||
}
|
||||
FileWriter.WriteNodes(writer, array, behavior.UseBoundaryMarkers, mesh.nextras, behavior.Jettison);
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000138 RID: 312 RVA: 0x00016290 File Offset: 0x00014490
|
||||
private static void WriteNodes(StreamWriter writer, IEnumerable<Vertex> nodes, bool markers, int attribs, bool jettison)
|
||||
{
|
||||
int num = 0;
|
||||
foreach (Vertex vertex in nodes)
|
||||
{
|
||||
if (!jettison || vertex.type != VertexType.UndeadVertex)
|
||||
{
|
||||
writer.Write("{0} {1} {2}", num, vertex.x.ToString(FileWriter.nfi), vertex.y.ToString(FileWriter.nfi));
|
||||
for (int i = 0; i < attribs; i++)
|
||||
{
|
||||
writer.Write(" {0}", vertex.attributes[i].ToString(FileWriter.nfi));
|
||||
}
|
||||
if (markers)
|
||||
{
|
||||
writer.Write(" {0}", vertex.mark);
|
||||
}
|
||||
writer.WriteLine();
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000139 RID: 313 RVA: 0x0001636C File Offset: 0x0001456C
|
||||
public static void WriteElements(Mesh mesh, string filename)
|
||||
{
|
||||
Otri otri = default(Otri);
|
||||
bool useRegions = mesh.behavior.useRegions;
|
||||
int num = 0;
|
||||
otri.orient = 0;
|
||||
using (StreamWriter streamWriter = new StreamWriter(filename))
|
||||
{
|
||||
streamWriter.WriteLine("{0} 3 {1}", mesh.triangles.Count, useRegions ? 1 : 0);
|
||||
foreach (Triangle triangle in mesh.triangles.Values)
|
||||
{
|
||||
otri.triangle = triangle;
|
||||
Vertex vertex = otri.Org();
|
||||
Vertex vertex2 = otri.Dest();
|
||||
Vertex vertex3 = otri.Apex();
|
||||
streamWriter.Write("{0} {1} {2} {3}", new object[] { num, vertex.id, vertex2.id, vertex3.id });
|
||||
if (useRegions)
|
||||
{
|
||||
streamWriter.Write(" {0}", otri.triangle.region);
|
||||
}
|
||||
streamWriter.WriteLine();
|
||||
triangle.id = num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600013A RID: 314 RVA: 0x000164E4 File Offset: 0x000146E4
|
||||
public static void WritePoly(Mesh mesh, string filename)
|
||||
{
|
||||
FileWriter.WritePoly(mesh, filename, true);
|
||||
}
|
||||
|
||||
// Token: 0x0600013B RID: 315 RVA: 0x000164F0 File Offset: 0x000146F0
|
||||
public static void WritePoly(Mesh mesh, string filename, bool writeNodes)
|
||||
{
|
||||
Osub osub = default(Osub);
|
||||
bool useBoundaryMarkers = mesh.behavior.UseBoundaryMarkers;
|
||||
using (StreamWriter streamWriter = new StreamWriter(filename))
|
||||
{
|
||||
if (writeNodes)
|
||||
{
|
||||
FileWriter.WriteNodes(streamWriter, mesh);
|
||||
}
|
||||
else
|
||||
{
|
||||
streamWriter.WriteLine("0 {0} {1} {2}", mesh.mesh_dim, mesh.nextras, useBoundaryMarkers ? "1" : "0");
|
||||
}
|
||||
streamWriter.WriteLine("{0} {1}", mesh.subsegs.Count, useBoundaryMarkers ? "1" : "0");
|
||||
osub.orient = 0;
|
||||
int num = 0;
|
||||
foreach (Segment segment in mesh.subsegs.Values)
|
||||
{
|
||||
osub.seg = segment;
|
||||
Vertex vertex = osub.Org();
|
||||
Vertex vertex2 = osub.Dest();
|
||||
if (useBoundaryMarkers)
|
||||
{
|
||||
streamWriter.WriteLine("{0} {1} {2} {3}", new object[]
|
||||
{
|
||||
num,
|
||||
vertex.id,
|
||||
vertex2.id,
|
||||
osub.seg.boundary
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
streamWriter.WriteLine("{0} {1} {2}", num, vertex.id, vertex2.id);
|
||||
}
|
||||
num++;
|
||||
}
|
||||
num = 0;
|
||||
streamWriter.WriteLine("{0}", mesh.holes.Count);
|
||||
foreach (Point point in mesh.holes)
|
||||
{
|
||||
streamWriter.WriteLine("{0} {1} {2}", num++, point.X.ToString(FileWriter.nfi), point.Y.ToString(FileWriter.nfi));
|
||||
}
|
||||
if (mesh.regions.Count > 0)
|
||||
{
|
||||
num = 0;
|
||||
streamWriter.WriteLine("{0}", mesh.regions.Count);
|
||||
foreach (RegionPointer regionPointer in mesh.regions)
|
||||
{
|
||||
streamWriter.WriteLine("{0} {1} {2} {3}", new object[]
|
||||
{
|
||||
num,
|
||||
regionPointer.point.X.ToString(FileWriter.nfi),
|
||||
regionPointer.point.Y.ToString(FileWriter.nfi),
|
||||
regionPointer.id
|
||||
});
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600013C RID: 316 RVA: 0x00016834 File Offset: 0x00014A34
|
||||
public static void WriteEdges(Mesh mesh, string filename)
|
||||
{
|
||||
Otri otri = default(Otri);
|
||||
Otri otri2 = default(Otri);
|
||||
Osub osub = default(Osub);
|
||||
Behavior behavior = mesh.behavior;
|
||||
using (StreamWriter streamWriter = new StreamWriter(filename))
|
||||
{
|
||||
streamWriter.WriteLine("{0} {1}", mesh.edges, behavior.UseBoundaryMarkers ? "1" : "0");
|
||||
long num = 0L;
|
||||
foreach (Triangle triangle in mesh.triangles.Values)
|
||||
{
|
||||
otri.triangle = triangle;
|
||||
otri.orient = 0;
|
||||
while (otri.orient < 3)
|
||||
{
|
||||
otri.Sym(ref otri2);
|
||||
if (otri.triangle.id < otri2.triangle.id || otri2.triangle == Mesh.dummytri)
|
||||
{
|
||||
Vertex vertex = otri.Org();
|
||||
Vertex vertex2 = otri.Dest();
|
||||
if (behavior.UseBoundaryMarkers)
|
||||
{
|
||||
if (behavior.useSegments)
|
||||
{
|
||||
otri.SegPivot(ref osub);
|
||||
if (osub.seg == Mesh.dummysub)
|
||||
{
|
||||
streamWriter.WriteLine("{0} {1} {2} {3}", new object[] { num, vertex.id, vertex2.id, 0 });
|
||||
}
|
||||
else
|
||||
{
|
||||
streamWriter.WriteLine("{0} {1} {2} {3}", new object[]
|
||||
{
|
||||
num,
|
||||
vertex.id,
|
||||
vertex2.id,
|
||||
osub.seg.boundary
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
streamWriter.WriteLine("{0} {1} {2} {3}", new object[]
|
||||
{
|
||||
num,
|
||||
vertex.id,
|
||||
vertex2.id,
|
||||
(otri2.triangle == Mesh.dummytri) ? "1" : "0"
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
streamWriter.WriteLine("{0} {1} {2}", num, vertex.id, vertex2.id);
|
||||
}
|
||||
num += 1L;
|
||||
}
|
||||
otri.orient++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600013D RID: 317 RVA: 0x00016AD4 File Offset: 0x00014CD4
|
||||
public static void WriteNeighbors(Mesh mesh, string filename)
|
||||
{
|
||||
Otri otri = default(Otri);
|
||||
Otri otri2 = default(Otri);
|
||||
int num = 0;
|
||||
using (StreamWriter streamWriter = new StreamWriter(filename))
|
||||
{
|
||||
streamWriter.WriteLine("{0} 3", mesh.triangles.Count);
|
||||
Mesh.dummytri.id = -1;
|
||||
foreach (Triangle triangle in mesh.triangles.Values)
|
||||
{
|
||||
otri.triangle = triangle;
|
||||
otri.orient = 1;
|
||||
otri.Sym(ref otri2);
|
||||
int id = otri2.triangle.id;
|
||||
otri.orient = 2;
|
||||
otri.Sym(ref otri2);
|
||||
int id2 = otri2.triangle.id;
|
||||
otri.orient = 0;
|
||||
otri.Sym(ref otri2);
|
||||
int id3 = otri2.triangle.id;
|
||||
streamWriter.WriteLine("{0} {1} {2} {3}", new object[]
|
||||
{
|
||||
num++,
|
||||
id,
|
||||
id2,
|
||||
id3
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600013E RID: 318 RVA: 0x00016C40 File Offset: 0x00014E40
|
||||
public static void WriteVoronoi(Mesh mesh, string filename)
|
||||
{
|
||||
Otri otri = default(Otri);
|
||||
Otri otri2 = default(Otri);
|
||||
double num = 0.0;
|
||||
double num2 = 0.0;
|
||||
int num3 = 0;
|
||||
otri.orient = 0;
|
||||
using (StreamWriter streamWriter = new StreamWriter(filename))
|
||||
{
|
||||
streamWriter.WriteLine("{0} 2 {1} 0", mesh.triangles.Count, mesh.nextras);
|
||||
foreach (Triangle triangle in mesh.triangles.Values)
|
||||
{
|
||||
otri.triangle = triangle;
|
||||
Vertex vertex = otri.Org();
|
||||
Vertex vertex2 = otri.Dest();
|
||||
Vertex vertex3 = otri.Apex();
|
||||
Point point = Primitives.FindCircumcenter(vertex, vertex2, vertex3, ref num, ref num2);
|
||||
streamWriter.Write("{0} {1} {2}", num3, point.X.ToString(FileWriter.nfi), point.Y.ToString(FileWriter.nfi));
|
||||
for (int i = 0; i < mesh.nextras; i++)
|
||||
{
|
||||
streamWriter.Write(" 0");
|
||||
}
|
||||
streamWriter.WriteLine();
|
||||
otri.triangle.id = num3++;
|
||||
}
|
||||
streamWriter.WriteLine("{0} 0", mesh.edges);
|
||||
num3 = 0;
|
||||
foreach (Triangle triangle2 in mesh.triangles.Values)
|
||||
{
|
||||
otri.triangle = triangle2;
|
||||
otri.orient = 0;
|
||||
while (otri.orient < 3)
|
||||
{
|
||||
otri.Sym(ref otri2);
|
||||
if (otri.triangle.id < otri2.triangle.id || otri2.triangle == Mesh.dummytri)
|
||||
{
|
||||
int id = otri.triangle.id;
|
||||
if (otri2.triangle == Mesh.dummytri)
|
||||
{
|
||||
Vertex vertex = otri.Org();
|
||||
Vertex vertex2 = otri.Dest();
|
||||
streamWriter.WriteLine("{0} {1} -1 {2} {3}", new object[]
|
||||
{
|
||||
num3,
|
||||
id,
|
||||
(vertex2[1] - vertex[1]).ToString(FileWriter.nfi),
|
||||
(vertex[0] - vertex2[0]).ToString(FileWriter.nfi)
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
int id2 = otri2.triangle.id;
|
||||
streamWriter.WriteLine("{0} {1} {2}", num3, id, id2);
|
||||
}
|
||||
num3++;
|
||||
}
|
||||
otri.orient++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600013F RID: 319 RVA: 0x00016F64 File Offset: 0x00015164
|
||||
public static void WriteOffFile(Mesh mesh, string filename)
|
||||
{
|
||||
long num = (long)mesh.vertices.Count;
|
||||
if (mesh.behavior.Jettison)
|
||||
{
|
||||
num = (long)(mesh.vertices.Count - mesh.undeads);
|
||||
}
|
||||
int num2 = 0;
|
||||
using (StreamWriter streamWriter = new StreamWriter(filename))
|
||||
{
|
||||
streamWriter.WriteLine("OFF");
|
||||
streamWriter.WriteLine("{0} {1} {2}", num, mesh.triangles.Count, mesh.edges);
|
||||
foreach (Vertex vertex in mesh.vertices.Values)
|
||||
{
|
||||
Vertex vertex;
|
||||
if (!mesh.behavior.Jettison || vertex.type != VertexType.UndeadVertex)
|
||||
{
|
||||
streamWriter.WriteLine(" {0} {1} 0.0", vertex[0].ToString(FileWriter.nfi), vertex[1].ToString(FileWriter.nfi));
|
||||
vertex.id = num2++;
|
||||
}
|
||||
}
|
||||
Otri otri;
|
||||
otri.orient = 0;
|
||||
foreach (Triangle triangle in mesh.triangles.Values)
|
||||
{
|
||||
otri.triangle = triangle;
|
||||
Vertex vertex = otri.Org();
|
||||
Vertex vertex2 = otri.Dest();
|
||||
Vertex vertex3 = otri.Apex();
|
||||
streamWriter.WriteLine(" 3 {0} {1} {2}", vertex.id, vertex2.id, vertex3.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x040000E8 RID: 232
|
||||
private static NumberFormatInfo nfi = CultureInfo.InvariantCulture.NumberFormat;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using TriangleNet.Geometry;
|
||||
|
||||
namespace TriangleNet.IO
|
||||
{
|
||||
// Token: 0x02000027 RID: 39
|
||||
public interface IGeometryFormat
|
||||
{
|
||||
// Token: 0x06000141 RID: 321
|
||||
InputGeometry Read(string filename);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace TriangleNet.IO
|
||||
{
|
||||
// Token: 0x02000028 RID: 40
|
||||
public interface IMeshFormat
|
||||
{
|
||||
// Token: 0x06000142 RID: 322
|
||||
Mesh Import(string filename);
|
||||
|
||||
// Token: 0x06000143 RID: 323
|
||||
void Write(Mesh mesh, string filename);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
using System;
|
||||
using TriangleNet.Data;
|
||||
using TriangleNet.Geometry;
|
||||
|
||||
namespace TriangleNet.IO
|
||||
{
|
||||
// Token: 0x02000029 RID: 41
|
||||
public class InputTriangle : ITriangle
|
||||
{
|
||||
// Token: 0x06000144 RID: 324 RVA: 0x00017169 File Offset: 0x00015369
|
||||
public InputTriangle(int p0, int p1, int p2)
|
||||
{
|
||||
this.vertices = new int[] { p0, p1, p2 };
|
||||
}
|
||||
|
||||
// Token: 0x17000058 RID: 88
|
||||
// (get) Token: 0x06000145 RID: 325 RVA: 0x00017189 File Offset: 0x00015389
|
||||
public int ID
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000059 RID: 89
|
||||
// (get) Token: 0x06000146 RID: 326 RVA: 0x0001718C File Offset: 0x0001538C
|
||||
public int P0
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.vertices[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700005A RID: 90
|
||||
// (get) Token: 0x06000147 RID: 327 RVA: 0x00017196 File Offset: 0x00015396
|
||||
public int P1
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.vertices[1];
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700005B RID: 91
|
||||
// (get) Token: 0x06000148 RID: 328 RVA: 0x000171A0 File Offset: 0x000153A0
|
||||
public int P2
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.vertices[2];
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000149 RID: 329 RVA: 0x000171AA File Offset: 0x000153AA
|
||||
public Vertex GetVertex(int index)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x1700005C RID: 92
|
||||
// (get) Token: 0x0600014A RID: 330 RVA: 0x00017189 File Offset: 0x00015389
|
||||
public bool SupportsNeighbors
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700005D RID: 93
|
||||
// (get) Token: 0x0600014B RID: 331 RVA: 0x000171AD File Offset: 0x000153AD
|
||||
public int N0
|
||||
{
|
||||
get
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700005E RID: 94
|
||||
// (get) Token: 0x0600014C RID: 332 RVA: 0x000171AD File Offset: 0x000153AD
|
||||
public int N1
|
||||
{
|
||||
get
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700005F RID: 95
|
||||
// (get) Token: 0x0600014D RID: 333 RVA: 0x000171AD File Offset: 0x000153AD
|
||||
public int N2
|
||||
{
|
||||
get
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600014E RID: 334 RVA: 0x000171AA File Offset: 0x000153AA
|
||||
public ITriangle GetNeighbor(int index)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x0600014F RID: 335 RVA: 0x000171AA File Offset: 0x000153AA
|
||||
public ISegment GetSegment(int index)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Token: 0x17000060 RID: 96
|
||||
// (get) Token: 0x06000150 RID: 336 RVA: 0x000171B0 File Offset: 0x000153B0
|
||||
// (set) Token: 0x06000151 RID: 337 RVA: 0x000171B8 File Offset: 0x000153B8
|
||||
public double Area
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.area;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.area = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000061 RID: 97
|
||||
// (get) Token: 0x06000152 RID: 338 RVA: 0x000171C1 File Offset: 0x000153C1
|
||||
// (set) Token: 0x06000153 RID: 339 RVA: 0x000171C9 File Offset: 0x000153C9
|
||||
public int Region
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.region;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.region = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x040000E9 RID: 233
|
||||
internal int[] vertices;
|
||||
|
||||
// Token: 0x040000EA RID: 234
|
||||
internal int region;
|
||||
|
||||
// Token: 0x040000EB RID: 235
|
||||
internal double area;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using TriangleNet.Geometry;
|
||||
|
||||
namespace TriangleNet.IO
|
||||
{
|
||||
// Token: 0x0200002B RID: 43
|
||||
public class TriangleFormat : IGeometryFormat, IMeshFormat
|
||||
{
|
||||
// Token: 0x06000163 RID: 355 RVA: 0x00017B88 File Offset: 0x00015D88
|
||||
public Mesh Import(string filename)
|
||||
{
|
||||
string extension = Path.GetExtension(filename);
|
||||
if (extension == ".node" || extension == ".poly" || extension == ".ele")
|
||||
{
|
||||
InputGeometry inputGeometry;
|
||||
List<ITriangle> list;
|
||||
FileReader.Read(filename, out inputGeometry, out list);
|
||||
if (inputGeometry != null && list != null)
|
||||
{
|
||||
Mesh mesh = new Mesh();
|
||||
mesh.Load(inputGeometry, list);
|
||||
return mesh;
|
||||
}
|
||||
}
|
||||
throw new NotSupportedException("Could not load '" + filename + "' file.");
|
||||
}
|
||||
|
||||
// Token: 0x06000164 RID: 356 RVA: 0x00017BF6 File Offset: 0x00015DF6
|
||||
public void Write(Mesh mesh, string filename)
|
||||
{
|
||||
FileWriter.WritePoly(mesh, Path.ChangeExtension(filename, ".poly"));
|
||||
FileWriter.WriteElements(mesh, Path.ChangeExtension(filename, ".ele"));
|
||||
}
|
||||
|
||||
// Token: 0x06000165 RID: 357 RVA: 0x00017C1C File Offset: 0x00015E1C
|
||||
public InputGeometry Read(string filename)
|
||||
{
|
||||
string extension = Path.GetExtension(filename);
|
||||
if (extension == ".node")
|
||||
{
|
||||
return FileReader.ReadNodeFile(filename);
|
||||
}
|
||||
if (extension == ".poly")
|
||||
{
|
||||
return FileReader.ReadPolyFile(filename);
|
||||
}
|
||||
throw new NotSupportedException("File format '" + extension + "' not supported.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user