private SimpleGraph <Point3d> BuildGraph(List <Polyline> Polylines) { List <Polyline> .Enumerator enumerator = new List <Polyline> .Enumerator(); SimpleGraph <Point3d> simpleGraph = new SimpleGraph <Point3d>(null); PointCloud pointCloud = new PointCloud(); pointCloud.Add(Polylines[0][0]); simpleGraph.AddVertex(Polylines[0][0]); int num = 0; try { enumerator = Polylines.GetEnumerator(); while (enumerator.MoveNext()) { Polyline current = enumerator.Current; GraphEdge count = new GraphEdge(); int num1 = pointCloud.ClosestPoint(current[0]); Point3d location = pointCloud[num1].Location; double num2 = location.DistanceTo(current[0]); count.From = num1; if (num2 > Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance) { pointCloud.Add(current[0]); simpleGraph.AddVertex(current[0]); count.From = checked (simpleGraph.Count - 1); } num1 = pointCloud.ClosestPoint(current[checked (current.Count - 1)]); count.To = num1; if (pointCloud[num1].Location.DistanceTo(current[checked (current.Count - 1)]) > Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance) { pointCloud.Add(current[checked (current.Count - 1)]); simpleGraph.AddVertex(current[checked (current.Count - 1)]); count.To = checked (simpleGraph.Count - 1); } count.Orient(); this.SrtThick[count] = this.Thickness[num]; this.SrtFaces[count] = this.FacesCounts[num]; simpleGraph.Edges.Add(count); num = checked (num + 1); } } finally { ((IDisposable)enumerator).Dispose(); } return(simpleGraph); }
/* * private PolyMesh BuildEndStrut(GraphEdge Edge) { * PolyMesh polyMesh = new PolyMesh(); * Circle[] item = this.SrtCircles[Edge]; * int num = this.SrtThick[Edge]; * if (item[0].Radius != 0) { * Point3d[] point3dArray = this.SrtPoints[new Tuple<int, int, int>(Edge.From, Edge.To, 0)]; * Point3d[][] point3dArray1 = this.CreateCirclePoints(item[0], item[1], item[2], num, point3dArray); * polyMesh.Append(this.MeshPoints(point3dArray1[0], point3dArray1[1])); * polyMesh.Append(this.MeshPoints(point3dArray1[1], point3dArray1[2])); * Point3d point3d = this.SrtEnds[Edge.From]; * Point3d item1 = this.SrtEnds[Edge.To]; * Point3d[] point3dArray2 = new Point3d[checked(checked((int)point3dArray1[0].Length - 1) + 1)]; * Line line = new Line(point3d, item1); * Point3d point3d1 = line.ClosestPoint(point3dArray1[2][0], false); * int length = checked((int)point3dArray2.Length - 1); * for (int i = 0; i <= length; i = checked(i + 1)) { * point3dArray2[i] = point3dArray1[2][i] + (item1 - point3d1); * } * polyMesh.Append(this.MeshPoints(point3dArray1[2], point3dArray2)); * } else { * Point3d[] item2 = this.SrtPoints[new Tuple<int, int, int>(Edge.From, Edge.To, 1)]; * Point3d[][] point3dArray3 = this.CreateCirclePoints(item[5], item[4], item[3], num, item2); * polyMesh.Append(this.MeshPoints(point3dArray3[0], point3dArray3[1])); * polyMesh.Append(this.MeshPoints(point3dArray3[1], point3dArray3[2])); * Point3d point3d2 = this.SrtEnds[Edge.From]; * Point3d item3 = this.SrtEnds[Edge.To]; * Point3d[] point3dArray4 = new Point3d[checked(checked((int)point3dArray3[0].Length - 1) + 1)]; * Line line1 = new Line(point3d2, item3); * Point3d point3d3 = line1.ClosestPoint(point3dArray3[2][0], false); * int length1 = checked((int)point3dArray4.Length - 1); * for (int j = 0; j <= length1; j = checked(j + 1)) { * point3dArray4[j] = point3dArray3[2][j] + (point3d2 - point3d3); * } * polyMesh.Append(this.MeshPoints(point3dArray3[2], point3dArray4)); * } * return polyMesh; * } */ private Mesh BuildEndStrut(GraphEdge Edge) { Mesh polyMesh = new Mesh(); Circle[] item = this.SrtCircles[Edge]; int num = this.SrtThick[Edge]; if (item[0].Radius != 0) { Point3d[] point3dArray = this.SrtPoints[new Tuple <int, int, int>(Edge.From, Edge.To, 0)]; Point3d[][] point3dArray1 = this.CreateCirclePoints(item[0], item[1], item[2], num, point3dArray); polyMesh.Append(this.MeshPoints(point3dArray1[0], point3dArray1[1])); polyMesh.Append(this.MeshPoints(point3dArray1[1], point3dArray1[2])); Point3d point3d = this.SrtEnds[Edge.From]; Point3d item1 = this.SrtEnds[Edge.To]; Point3d[] point3dArray2 = new Point3d[checked (checked ((int)point3dArray1[0].Length - 1) + 1)]; Line line = new Line(point3d, item1); Point3d point3d1 = line.ClosestPoint(point3dArray1[2][0], false); int length = checked ((int)point3dArray2.Length - 1); for (int i = 0; i <= length; i = checked (i + 1)) { point3dArray2[i] = point3dArray1[2][i] + (item1 - point3d1); } polyMesh.Append(this.MeshPoints(point3dArray1[2], point3dArray2)); } else { Point3d[] item2 = this.SrtPoints[new Tuple <int, int, int>(Edge.From, Edge.To, 1)]; Point3d[][] point3dArray3 = this.CreateCirclePoints(item[5], item[4], item[3], num, item2); polyMesh.Append(this.MeshPoints(point3dArray3[0], point3dArray3[1])); polyMesh.Append(this.MeshPoints(point3dArray3[1], point3dArray3[2])); Point3d point3d2 = this.SrtEnds[Edge.From]; Point3d item3 = this.SrtEnds[Edge.To]; Point3d[] point3dArray4 = new Point3d[checked (checked ((int)point3dArray3[0].Length - 1) + 1)]; Line line1 = new Line(point3d2, item3); Point3d point3d3 = line1.ClosestPoint(point3dArray3[2][0], false); int length1 = checked ((int)point3dArray4.Length - 1); for (int j = 0; j <= length1; j = checked (j + 1)) { point3dArray4[j] = point3dArray3[2][j] + (point3d2 - point3d3); } polyMesh.Append(this.MeshPoints(point3dArray3[2], point3dArray4)); } return(polyMesh); }
//private PolyMesh BuildStrut(GraphEdge Edge) { // Circle[] item = this.SrtCircles[Edge]; // int num = this.SrtThick[Edge]; // Tuple<int, int, int> tuple = new Tuple<int, int, int>(Edge.From, Edge.To, 0); // Tuple<int, int, int> tuple1 = new Tuple<int, int, int>(Edge.From, Edge.To, 1); // Point3d[][] point3dArray = this.CreateCirclePoints(item[0], item[1], item[2], num, this.SrtPoints[tuple]); // Point3d[][] point3dArray1 = this.CreateCirclePoints(item[5], item[4], item[3], num, this.SrtPoints[tuple1]); // PolyMesh polyMesh = new PolyMesh(); // polyMesh.Append(this.MeshPoints(point3dArray[0], point3dArray[1])); // polyMesh.Append(this.MeshPoints(point3dArray[1], point3dArray[2])); // polyMesh.Append(this.MeshPoints(point3dArray1[0], point3dArray1[1])); // polyMesh.Append(this.MeshPoints(point3dArray1[1], point3dArray1[2])); // Point3d[][] point3dArray2 = PointUtil.InterpolatePointArrays(point3dArray[2], this.FixOrientation(point3dArray[2], point3dArray1[2]), this.SrtFaces[Edge]); // int length = checked((int)point3dArray2.Length - 2); // for (int i = 0; i <= length; i = checked(i + 1)) { // polyMesh.Append(this.MeshPoints(point3dArray2[i], point3dArray2[checked(i + 1)])); // } // return polyMesh; //} private Mesh BuildStrut(GraphEdge Edge) { Circle[] item = this.SrtCircles[Edge]; int num = this.SrtThick[Edge]; Tuple <int, int, int> tuple = new Tuple <int, int, int>(Edge.From, Edge.To, 0); Tuple <int, int, int> tuple1 = new Tuple <int, int, int>(Edge.From, Edge.To, 1); Point3d[][] point3dArray = this.CreateCirclePoints(item[0], item[1], item[2], num, this.SrtPoints[tuple]); Point3d[][] point3dArray1 = this.CreateCirclePoints(item[5], item[4], item[3], num, this.SrtPoints[tuple1]); Mesh polyMesh = new Mesh(); polyMesh.Append(this.MeshPoints(point3dArray[0], point3dArray[1])); polyMesh.Append(this.MeshPoints(point3dArray[1], point3dArray[2])); polyMesh.Append(this.MeshPoints(point3dArray1[0], point3dArray1[1])); polyMesh.Append(this.MeshPoints(point3dArray1[1], point3dArray1[2])); Point3d[][] point3dArray2 = PointUtil.InterpolatePointArrays(point3dArray[2], this.FixOrientation(point3dArray[2], point3dArray1[2]), this.SrtFaces[Edge]); int length = checked ((int)point3dArray2.Length - 2); for (int i = 0; i <= length; i = checked (i + 1)) { polyMesh.Append(this.MeshPoints(point3dArray2[i], point3dArray2[checked (i + 1)])); } return(polyMesh); }
//public PolyMesh BuildMesh(List<Polyline> Polylines, List<int> Strips, List<int> Faces, double Proportion) { // int count; // List<int>.Enumerator enumerator = new List<int>.Enumerator(); // HashSet<GraphEdge>.Enumerator enumerator1 = new HashSet<GraphEdge>.Enumerator(); // PolyMesh polyMesh = new PolyMesh(); // this.Polylines.Clear(); // this.Thickness.Clear(); // this.FacesCounts.Clear(); // this.SrtThick.Clear(); // this.SrtFaces.Clear(); // this.SrtCircles.Clear(); // this.SrtPoints.Clear(); // this.SrtEnds.Clear(); // this.Proportion = Proportion; // this.Polylines.AddRange(Polylines); // this.FacesCounts.AddRange(Faces); // this.Thickness.AddRange(Strips); // int num = checked(this.FacesCounts.Count - 2); // for (int i = 1; i <= num; i = checked(i + 1)) { // List<int> facesCounts = this.FacesCounts; // List<int> nums = facesCounts; // int num1 = i; // count = num1; // facesCounts[num1] = checked(nums[count] - 6); // } // SimpleGraph<Point3d> simpleGraph = this.BuildGraph(Polylines); // this.WrongVertex = new bool[checked(checked(simpleGraph.Count - 1) + 1)]; // List<int>[] connectivityMap = simpleGraph.GetConnectivityMap(); // count = checked(this.SrtThick.Count - 1); // for (int j = 0; j <= count; j = checked(j + 1)) { // Circle[] circleArray = new Circle[6]; // this.SrtCircles[this.SrtThick.Keys[j]] = circleArray; // } // int count1 = checked(simpleGraph.Count - 1); // for (int k = 0; k <= count1; k = checked(k + 1)) { // List<int> vertex = connectivityMap[k]; // if (vertex.Count == 1) { // this.SrtEnds[k] = simpleGraph[k]; // this.SrtEnds[vertex[0]] = simpleGraph[vertex[0]]; // } else if (vertex.Count == 3) { // List<Point3d> point3ds = new List<Point3d>(); // List<Vector3d> vector3ds = new List<Vector3d>(); // List<int> nums1 = new List<int>(); // try { // enumerator = vertex.GetEnumerator(); // while (enumerator.MoveNext()) { // int current = enumerator.Current; // Point3d point3d = simpleGraph[current]; // point3d.Transform(Transform.Scale(simpleGraph[k], Proportion)); // vector3ds.Add(simpleGraph[k] - point3d); // point3ds.Add(point3d); // GraphEdge graphEdge = new GraphEdge(current, k); // graphEdge.Orient(); // nums1.Add(this.SrtThick[graphEdge]); // } // } finally { // ((IDisposable)enumerator).Dispose(); // } // List<Circle> circles = this.ConstructTangentCircles(point3ds, PointUtil.InscribedCircle(point3ds)); // List<Circle> circles1 = this.SecondaryCircles(point3ds, vector3ds, circles); // List<Circle> circles2 = this.TertiaryCircles(point3ds, simpleGraph[k], circles); // int count2 = checked(circles.Count - 1); // for (int l = 0; l <= count2; l = checked(l + 1)) { // GraphEdge item = new GraphEdge(k, vertex[l]); // item.Orient(); // if (k != item.From) { // this.SrtCircles[item][5] = circles[l]; // this.SrtCircles[item][4] = circles1[l]; // this.SrtCircles[item][3] = circles2[l]; // } else { // this.SrtCircles[item][0] = circles[l]; // this.SrtCircles[item][1] = circles1[l]; // this.SrtCircles[item][2] = circles2[l]; // } // } // int[] numArray = null; // List<Circle> circles3 = this.OrientPrimary(circles, nums1, ref numArray); // List<int> nums2 = new List<int>(); // int length = checked((int)numArray.Length - 1); // for (int m = 0; m <= length; m = checked(m + 1)) { // nums2.Add(nums1[numArray[m]]); // int item1 = vertex[numArray[m]]; // GraphEdge graphEdge1 = new GraphEdge(item1, k); // graphEdge1.Orient(); // if (item1 != graphEdge1.From) { // this.SrtCircles[graphEdge1][0] = circles3[m]; // } else { // this.SrtCircles[graphEdge1][5] = circles3[m]; // } // } // List<Point3d> point3ds1 = null; // List<Point3d> point3ds2 = null; // List<Point3d> point3ds3 = null; // PolyMesh polyMesh1 = this.MeshConnector(circles3, nums2, ref point3ds1, ref point3ds2, ref point3ds3); // int length1 = checked((int)numArray.Length - 1); // for (int n = 0; n <= length1; n = checked(n + 1)) { // int item2 = vertex[numArray[n]]; // GraphEdge array = new GraphEdge(item2, k); // array.Orient(); // if (item2 != array.From) { // switch (n) { // case 0: { // this.SrtPoints[new Tuple<int, int, int>(array.From, array.To, 0)] = point3ds3.ToArray(); // break; // } // case 1: { // this.SrtPoints[new Tuple<int, int, int>(array.From, array.To, 0)] = point3ds2.ToArray(); // break; // } // case 2: { // this.SrtPoints[new Tuple<int, int, int>(array.From, array.To, 0)] = point3ds1.ToArray(); // break; // } // } // } else { // switch (n) { // case 0: { // this.SrtPoints[new Tuple<int, int, int>(array.From, array.To, 1)] = point3ds3.ToArray(); // break; // } // case 1: { // this.SrtPoints[new Tuple<int, int, int>(array.From, array.To, 1)] = point3ds2.ToArray(); // break; // } // case 2: { // this.SrtPoints[new Tuple<int, int, int>(array.From, array.To, 1)] = point3ds1.ToArray(); // break; // } // } // } // } // polyMesh.Append(polyMesh1); // } // } // try { // enumerator1 = simpleGraph.Edges.GetEnumerator(); // while (enumerator1.MoveNext()) { // GraphEdge current1 = enumerator1.Current; // if (!(connectivityMap[current1.From].Count == 3 & connectivityMap[current1.To].Count == 3)) { // if (!(connectivityMap[current1.From].Count == 1 & connectivityMap[current1.To].Count == 3 | connectivityMap[current1.From].Count == 3 & connectivityMap[current1.To].Count == 1)) { // continue; // } // polyMesh.Append(this.BuildEndStrut(current1)); // } else { // polyMesh.Append(this.BuildStrut(current1)); // } // } // } finally { // ((IDisposable)enumerator1).Dispose(); // } // polyMesh.Weld(Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, 123); // polyMesh.UnifyFaceNormals(); // return polyMesh; //} public Mesh BuildMesh(List <Polyline> Polylines, List <int> Strips, List <int> Faces, double Proportion) { int count; List <int> .Enumerator enumerator = new List <int> .Enumerator(); HashSet <GraphEdge> .Enumerator enumerator1 = new HashSet <GraphEdge> .Enumerator(); Mesh polyMesh = new Mesh(); this.Polylines.Clear(); this.Thickness.Clear(); this.FacesCounts.Clear(); this.SrtThick.Clear(); this.SrtFaces.Clear(); this.SrtCircles.Clear(); this.SrtPoints.Clear(); this.SrtEnds.Clear(); this.Proportion = Proportion; this.Polylines.AddRange(Polylines); this.FacesCounts.AddRange(Faces); this.Thickness.AddRange(Strips); int num = checked (this.FacesCounts.Count - 2); for (int i = 1; i <= num; i = checked (i + 1)) { List <int> facesCounts = this.FacesCounts; List <int> nums = facesCounts; int num1 = i; count = num1; facesCounts[num1] = checked (nums[count] - 6); } SimpleGraph <Point3d> simpleGraph = this.BuildGraph(Polylines); this.WrongVertex = new bool[checked (checked (simpleGraph.Count - 1) + 1)]; List <int>[] connectivityMap = simpleGraph.GetConnectivityMap(); count = checked (this.SrtThick.Count - 1); for (int j = 0; j <= count; j = checked (j + 1)) { Circle[] circleArray = new Circle[6]; this.SrtCircles[this.SrtThick.Keys[j]] = circleArray; } int count1 = checked (simpleGraph.Count - 1); for (int k = 0; k <= count1; k = checked (k + 1)) { List <int> vertex = connectivityMap[k]; if (vertex.Count == 1) { this.SrtEnds[k] = simpleGraph[k]; this.SrtEnds[vertex[0]] = simpleGraph[vertex[0]]; } else if (vertex.Count == 3) { List <Point3d> point3ds = new List <Point3d>(); List <Vector3d> vector3ds = new List <Vector3d>(); List <int> nums1 = new List <int>(); try { enumerator = vertex.GetEnumerator(); while (enumerator.MoveNext()) { int current = enumerator.Current; Point3d point3d = simpleGraph[current]; point3d.Transform(Transform.Scale(simpleGraph[k], Proportion)); vector3ds.Add(simpleGraph[k] - point3d); point3ds.Add(point3d); GraphEdge graphEdge = new GraphEdge(current, k); graphEdge.Orient(); nums1.Add(this.SrtThick[graphEdge]); } } finally { ((IDisposable)enumerator).Dispose(); } List <Circle> circles = this.ConstructTangentCircles(point3ds, PointUtil.InscribedCircle(point3ds)); List <Circle> circles1 = this.SecondaryCircles(point3ds, vector3ds, circles); List <Circle> circles2 = this.TertiaryCircles(point3ds, simpleGraph[k], circles); int count2 = checked (circles.Count - 1); for (int l = 0; l <= count2; l = checked (l + 1)) { GraphEdge item = new GraphEdge(k, vertex[l]); item.Orient(); if (k != item.From) { this.SrtCircles[item][5] = circles[l]; this.SrtCircles[item][4] = circles1[l]; this.SrtCircles[item][3] = circles2[l]; } else { this.SrtCircles[item][0] = circles[l]; this.SrtCircles[item][1] = circles1[l]; this.SrtCircles[item][2] = circles2[l]; } } int[] numArray = null; List <Circle> circles3 = this.OrientPrimary(circles, nums1, ref numArray); List <int> nums2 = new List <int>(); int length = checked ((int)numArray.Length - 1); for (int m = 0; m <= length; m = checked (m + 1)) { nums2.Add(nums1[numArray[m]]); int item1 = vertex[numArray[m]]; GraphEdge graphEdge1 = new GraphEdge(item1, k); graphEdge1.Orient(); if (item1 != graphEdge1.From) { this.SrtCircles[graphEdge1][0] = circles3[m]; } else { this.SrtCircles[graphEdge1][5] = circles3[m]; } } List <Point3d> point3ds1 = null; List <Point3d> point3ds2 = null; List <Point3d> point3ds3 = null; Mesh polyMesh1 = this.MeshConnector(circles3, nums2, ref point3ds1, ref point3ds2, ref point3ds3); int length1 = checked ((int)numArray.Length - 1); for (int n = 0; n <= length1; n = checked (n + 1)) { int item2 = vertex[numArray[n]]; GraphEdge array = new GraphEdge(item2, k); array.Orient(); if (item2 != array.From) { switch (n) { case 0: { this.SrtPoints[new Tuple <int, int, int>(array.From, array.To, 0)] = point3ds3.ToArray(); break; } case 1: { this.SrtPoints[new Tuple <int, int, int>(array.From, array.To, 0)] = point3ds2.ToArray(); break; } case 2: { this.SrtPoints[new Tuple <int, int, int>(array.From, array.To, 0)] = point3ds1.ToArray(); break; } } } else { switch (n) { case 0: { this.SrtPoints[new Tuple <int, int, int>(array.From, array.To, 1)] = point3ds3.ToArray(); break; } case 1: { this.SrtPoints[new Tuple <int, int, int>(array.From, array.To, 1)] = point3ds2.ToArray(); break; } case 2: { this.SrtPoints[new Tuple <int, int, int>(array.From, array.To, 1)] = point3ds1.ToArray(); break; } } } } polyMesh.Append(polyMesh1); } } try { enumerator1 = simpleGraph.Edges.GetEnumerator(); while (enumerator1.MoveNext()) { GraphEdge current1 = enumerator1.Current; if (!(connectivityMap[current1.From].Count == 3 & connectivityMap[current1.To].Count == 3)) { if (!(connectivityMap[current1.From].Count == 1 & connectivityMap[current1.To].Count == 3 | connectivityMap[current1.From].Count == 3 & connectivityMap[current1.To].Count == 1)) { continue; } polyMesh.Append(this.BuildEndStrut(current1)); } else { polyMesh.Append(this.BuildStrut(current1)); } } } finally { ((IDisposable)enumerator1).Dispose(); } polyMesh.Clean(); //polyMesh.Weld(Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, 123); //polyMesh.UnifyFaceNormals(); return(polyMesh); }