/// <summary> /// Number the vertices and write them to a .node file. /// </summary> /// <param name="mesh"></param> /// <param name="filename"></param> public static void WriteNodes(Mesh mesh, string filename) { using (StreamWriter writer = new StreamWriter(filename)) { FileWriter.WriteNodes(writer, mesh); } }
private static void WriteNodes(StreamWriter writer, Mesh mesh) { int count = mesh.vertices.Count; Behavior behavior = mesh.behavior; if (behavior.Jettison) { count = mesh.vertices.Count - mesh.undeads; } if (writer != null) { StreamWriter streamWriter = writer; object[] meshDim = new object[] { count, mesh.mesh_dim, mesh.nextras, null }; meshDim[3] = (behavior.UseBoundaryMarkers ? "1" : "0"); streamWriter.WriteLine("{0} {1} {2} {3}", meshDim); 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[] vertexArray = new Vertex[mesh.vertices.Count]; foreach (Vertex value in mesh.vertices.Values) { vertexArray[value.id] = value; } FileWriter.WriteNodes(writer, vertexArray, behavior.UseBoundaryMarkers, mesh.nextras, behavior.Jettison); } }
public static void WriteNodes(Mesh mesh, string filename) { using (StreamWriter streamWriter = new StreamWriter(new FileStream(filename, FileMode.Create))) { FileWriter.WriteNodes(streamWriter, mesh); } }
/// <summary> /// Number the vertices and write them to a .node file. /// </summary> /// <param name="mesh"></param> /// <param name="filename"></param> public static void WriteNodes(Mesh mesh, string filename) { using (Stream outputStream = File.Create(filename)) { using (StreamWriter writer = new StreamWriter(outputStream)) { FileWriter.WriteNodes(writer, mesh); } } }
/// <summary> /// Write the segments and holes to a .poly file. /// </summary> /// <param name="mesh">Data source.</param> /// <param name="filename">File name.</param> /// <param name="writeNodes">Write nodes into this file.</param> /// <remarks>If the nodes should not be written into this file, /// make sure a .node file was written before, so that the nodes /// are numbered right.</remarks> public static void WritePoly(Mesh mesh, string filename, bool writeNodes) { Osub subseg = default(Osub); Vertex pt1, pt2; bool useBoundaryMarkers = mesh.behavior.UseBoundaryMarkers; using (StreamWriter writer = new StreamWriter(filename)) { if (writeNodes) { // Write nodes to this file. FileWriter.WriteNodes(writer, mesh); } else { // The zero indicates that the vertices are in a separate .node file. // Followed by number of dimensions, number of vertex attributes, // and number of boundary markers (zero or one). writer.WriteLine("0 {0} {1} {2}", mesh.mesh_dim, mesh.nextras, useBoundaryMarkers ? "1" : "0"); } // Number of segments, number of boundary markers (zero or one). writer.WriteLine("{0} {1}", mesh.subsegs.Count, useBoundaryMarkers ? "1" : "0"); subseg.orient = 0; int j = 0; foreach (var item in mesh.subsegs.Values) { subseg.seg = item; pt1 = subseg.Org(); pt2 = subseg.Dest(); // Segment number, indices of its two endpoints, and possibly a marker. if (useBoundaryMarkers) { writer.WriteLine("{0} {1} {2} {3}", j, pt1.id, pt2.id, subseg.seg.boundary); } else { writer.WriteLine("{0} {1} {2}", j, pt1.id, pt2.id); } j++; } // Holes j = 0; writer.WriteLine("{0}", mesh.holes.Count); foreach (var hole in mesh.holes) { writer.WriteLine("{0} {1} {2}", j++, hole.X.ToString(nfi), hole.Y.ToString(nfi)); } // Regions if (mesh.regions.Count > 0) { j = 0; writer.WriteLine("{0}", mesh.regions.Count); foreach (var region in mesh.regions) { writer.WriteLine("{0} {1} {2} {3}", j, region.point.X.ToString(nfi), region.point.Y.ToString(nfi), region.id); j++; } } } }
public static void WritePoly(Mesh mesh, string filename, bool writeNodes) { double x; Osub osub = new Osub(); bool useBoundaryMarkers = mesh.behavior.UseBoundaryMarkers; using (StreamWriter streamWriter = new StreamWriter(new FileStream(filename, FileMode.Create))) { if (!writeNodes) { streamWriter.WriteLine("0 {0} {1} {2}", mesh.mesh_dim, mesh.nextras, (useBoundaryMarkers ? "1" : "0")); } else { FileWriter.WriteNodes(streamWriter, mesh); } streamWriter.WriteLine("{0} {1}", mesh.subsegs.Count, (useBoundaryMarkers ? "1" : "0")); osub.orient = 0; int num = 0; foreach (Segment value in mesh.subsegs.Values) { osub.seg = value; Vertex vertex = osub.Org(); Vertex vertex1 = osub.Dest(); if (!useBoundaryMarkers) { streamWriter.WriteLine("{0} {1} {2}", num, vertex.id, vertex1.id); } else { streamWriter.WriteLine("{0} {1} {2} {3}", new object[] { num, vertex.id, vertex1.id, osub.seg.boundary }); } num++; } num = 0; streamWriter.WriteLine("{0}", mesh.holes.Count); foreach (Point hole in mesh.holes) { int num1 = num; num = num1 + 1; object obj = num1; x = hole.X; string str = x.ToString(FileWriter.nfi); x = hole.Y; streamWriter.WriteLine("{0} {1} {2}", obj, str, x.ToString(FileWriter.nfi)); } if (mesh.regions.Count > 0) { num = 0; streamWriter.WriteLine("{0}", mesh.regions.Count); foreach (RegionPointer region in mesh.regions) { object[] objArray = new object[] { num, null, null, null }; x = region.point.X; objArray[1] = x.ToString(FileWriter.nfi); x = region.point.Y; objArray[2] = x.ToString(FileWriter.nfi); objArray[3] = region.id; streamWriter.WriteLine("{0} {1} {2} {3}", objArray); num++; } } } }