//构造函数用于给以上声明的两个列表初始化 public Construction_TIN(PointList points) { this.pointlist = points; this.triangles = new TriangleList(); }
private void but_run_Click(object sender, EventArgs e) { if (txtFile == "" && demFile == "" && domFile == "" && yuzhi == null) { MessageBox.Show("请指定必要数据!"); return; } using (System.IO.StreamWriter log = new System.IO.StreamWriter("a", false)) { log.WriteLine(domFile); log.WriteLine(demFile); log.WriteLine(txtFile); log.WriteLine(yuzhi); log.Close(); } string outMap = txtFile.Substring(0, txtFile.LastIndexOf(".")) + "_map.tif"; if (File.Exists(outMap)) { File.Delete(outMap); } //get三角形 GetPointGroup afeat = new GetPointGroup(txtFile, demFile, yuzhi, domFile, outMap); points.pointList.AddRange(afeat.mapP); Construction_TIN delaunay = new Construction_TIN(this.points); triangles = delaunay.Triangle_const(); // delaunay.getUsefulTriangles(afeat.geom); //输出脚本 string outPath = txtFile.Substring(0, txtFile.LastIndexOf(".")) + "_res.txt"; if (File.Exists(outPath)) { File.Delete(outPath); } //输出所有点坐标 //StreamWriter第二个参数为false覆盖现有文件,为true则把文本追加到文件末尾 using (System.IO.StreamWriter file = new System.IO.StreamWriter(outPath, true)) { string vertices = "mesh vertices:#("; file.Write(vertices); for (int i = 0; i < afeat.mapP.Count; i++) { string x = afeat.mapP[i].X.ToString(); string y = afeat.mapP[i].Y.ToString(); string z = afeat.mapP[i].Z.ToString(); string coor = x + "," + y + "," + z; vertices = "[" + coor + "],"; if (i == (afeat.mapP.Count - 1)) { vertices = "[" + coor + "]) "; } file.Write(vertices); } string faces = "faces:#("; file.Write(faces); for (int i = 0; i < triangles.Count; i++) { string a = triangles[i].A.ids.ToString(); string b = triangles[i].B.ids.ToString(); string c = triangles[i].C.ids.ToString(); string ids = c + "," + b + "," + a; faces = "[" + ids + "],"; if (i == (triangles.Count - 1)) { faces = "[" + ids + "]) isSelected:on"; } file.Write(faces); } file.Close(); } MessageBox.Show("OK"); }