// compute plate and output polyline public void ComputePlates() { // set up second type of plate for (int i = 0; i < oSpringMesh.Vertices.Count; i++) { Point3d vertexPosition = oSpringMesh.Vertices[i].Position; Point3d closeVertice = Point3dList.ClosestPointInList(iClosedPanelPts, vertexPosition); if (ICD.Utils.Distance(closeVertice, vertexPosition) < iClosePanelDist) { oVertexPanel2[i] = true; } } // attractor thickness for (int i = 0; i < oSpringMesh.Vertices.Count; i++) { Point3d vertexPosition = oSpringMesh.Vertices[i].Position; // different thickness Point3d closestPt = Point3dList.ClosestPointInList(iAttrThicknessPts, vertexPosition); double distValue = ICD.Utils.Distance(vertexPosition, closestPt); if (iHeightThickness) // adding z coordinate as account { double k = vertexPosition.Z * 0.125; distValue *= k * iMinThickness + (0.5 - k) * iMaxThickness; } othickness.Add(distValue); } // fix the second type plate area thickness for (int i = 0; i < oSpringMesh.Vertices.Count; i++) { Vertex vt = oSpringMesh.Vertices[i]; //List<int> Neighbours = v.NeighborVertexIndices; oInfo += "i = " + i.ToString() + ", value = " + oVertexPanel2[i] + "\n"; foreach (int n in vt.NeighborVertexIndices) { if (oVertexPanel2[n] == true) { oInfo += "n = " + n.ToString() + ", value = " + oVertexPanel2[n] + "\n"; oInfo += n.ToString() + " get it \n"; double temp = othickness[n]; othickness[i] = temp; } } oInfo += "==============================\n"; } // remap double max = othickness.Max(); double min = othickness.Min(); // map(value, low1, high1, low2, high2) = > low2 + (value - low1) * (high2 - low2) / (high1 - low1) for (int i = 0; i < othickness.Count; i++) { othickness[i] = iMinThickness + (othickness[i] - min) * (iMaxThickness - iMinThickness) / (max - min); } // ------------------------- end attractors -------------------------------------------------------------------------- // test foreach (int id in iID) { Circle c = new Circle(oSpringMesh.Vertices[id].Position, 0.2); oDebugList.Add(NurbsCurve.CreateFromCircle(c)); } // create plate using TPI DualTPI(false); DualTPI(true); }
private void storePlatesTPI() { // initial // 3 for polygon id, 3 for 3 tri side id. use the number to compare if polygon is clockwise. int[] triIndex = new int[6] { -1, -1, -1, -1, -1, -1 }; // construct center pt for (int i = 0; i < iSpringMesh.Triangles.Count; i++) { topCenterPts.Add(iSpringMesh.ComputeTriangleCentroid(i)); bottomCenterPts.Add(iSpringMesh.ComputeTriangleCentroid(i)); topCenterPolygonOccupied.Add(false); // to see if triangle be occupied by polygon int[] copy = (int[])triIndex.Clone(); // have to copy array otherwise it's reference type it will change all indexSortPolygon.Add(copy); } // compare center pt with TPI // get discontinuity points for (int i = 0; i < iPolyLine.Count; i++) { Curve c = iPolyLine[i]; double t; double start = c.Domain.Min; int counter = 0; while (c.GetNextDiscontinuity(Continuity.C1_locus_continuous, start, c.Domain.Max, out t)) { //oInfo += "outsider i = " + i.ToString() + "\n"; start = t; Point3d pt = c.PointAt(t); if (i < iPolyLine.Count / 2) { Point3d closestPt = Point3dList.ClosestPointInList(topCenterPts, pt); int index = topCenterPts.IndexOf(closestPt); topCenterPts[index] = pt; topCenterPolygonOccupied[index] = true; // set occupied status // sort triangle id /////////////////////////////////////// //oInfo += "index = " + index.ToString() + "\n"; for (int j = 0; j < 3; j++) { //oInfo += "in for loop \n"; if (indexSortPolygon[index][j] == -1) { //oInfo += "indexP " + indexSortPolygon[index][j] + "\n"; //oInfo += "indexP " + indexSortPolygon[index][j + 3] + "\n"; //oInfo += "j = " + j.ToString() + "\n"; //oInfo += "i = " + i.ToString() + "\n"; indexSortPolygon[index][j] = i; indexSortPolygon[index][j + 3] = counter; //oInfo += "indexP " + indexSortPolygon[index][j] + "\n"; //oInfo += "indexP " + indexSortPolygon[index][j + 3] + "\n"; break; } } counter++; //oInfo += "counter = " + counter.ToString() + "\n"; //oInfo += "================= \n"; ///////////////////////////////////////////////////////////// } else { Point3d closestPt = Point3dList.ClosestPointInList(bottomCenterPts, pt); int index = bottomCenterPts.IndexOf(closestPt); bottomCenterPts[index] = pt; } } } foreach (Point3d p in topCenterPts) { oDebugList.Add(p); } foreach (Point3d p in bottomCenterPts) { oDebugList.Add(p); } // debug /* * foreach (int[] ip in indexSortPolygon) * oInfo += ip[0].ToString() + ", " + * ip[1].ToString() + ", " + * ip[2].ToString() + ", " + * ip[3].ToString() + ", " + * ip[4].ToString() + ", " + * ip[5].ToString() + "\n";*/ }
protected override void GroundHogSolveInstance(IGH_DataAccess DA) { // Create holder variables for input parameters var ALL_CONTOURS = new List <Curve>(); var BOUNDARY = default(Curve); var MAXIMUM_GAP = default(double); // Access and extract data from the input parameters individually if (!DA.GetDataList(0, ALL_CONTOURS)) { return; } if (!DA.GetData(1, ref BOUNDARY)) { return; } if (!DA.GetData(2, ref MAXIMUM_GAP)) { return; } // Input Validation int preCullSize = ALL_CONTOURS.Count; ALL_CONTOURS.RemoveAll(item => item == null); if (ALL_CONTOURS.Count == 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No valid contour curves were provided."); return; } else if (ALL_CONTOURS.Count < preCullSize) { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, String.Format("{0} contours were removed because they were null items — perhaps because they are no longer present in the Rhino model.", preCullSize - ALL_CONTOURS.Count)); } // Ensure the maximum gap is a positive number (won't crash if not; but just does nothing) if (MAXIMUM_GAP <= 0.0) { DA.SetDataList(0, ALL_CONTOURS); DA.SetDataList(1, null); AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Maximum Distance was set at or below 0 so no changes were made to the contours."); return; } // Create holder variables for ouput parameters var fixedContours = new List <Curve>(); var connections = new List <Curve>(); // For each contour, get start and end points that arent outside or on the boundaries var possibleSplitPoints = new List <Point3d>(); foreach (var contour in ALL_CONTOURS) { fixedContours.Add(contour); if (contour.IsClosed == false) { var pointContainmentS = BOUNDARY.Contains(contour.PointAtStart); if (pointContainmentS.ToString() == "Inside") { possibleSplitPoints.Add(contour.PointAtStart); } var pointContainmentE = BOUNDARY.Contains(contour.PointAtEnd); if (pointContainmentE.ToString() == "Inside") { possibleSplitPoints.Add(contour.PointAtEnd); } } } if (possibleSplitPoints != null && possibleSplitPoints.Count > 0) { // For each point that needs to be connected, find the closest non-self point, and creating a joining line var joinedPoints = new List <Point3d>(); foreach (var point in possibleSplitPoints) { if (joinedPoints.Contains(point) == false) { var possibleSplitPointsWithoutSelf = new List <Point3d>(possibleSplitPoints); // clone the current list possibleSplitPointsWithoutSelf.Remove(point); // remove the item we are searching from if (possibleSplitPointsWithoutSelf.Count == 0) { continue; } // Get the closest point on the boundary and check we aren't extending to a boundary gap var closestPoint = Point3dList.ClosestPointInList(possibleSplitPointsWithoutSelf, point); BOUNDARY.ClosestPoint(point, out double closestBoundaryPtParamater); var closestBoundaryPt = BOUNDARY.PointAt(closestBoundaryPtParamater); closestBoundaryPt.Z = point.Z; // Set the Z's to be the same as the boundary is assumed to be 3D // Don't proceed if the closest point has already been joined if (joinedPoints.Contains(closestPoint) == false) { if (point.DistanceTo(closestPoint) < point.DistanceTo(closestBoundaryPt)) { if (point.DistanceTo(closestPoint) <= MAXIMUM_GAP) { Curve connection = new LineCurve(point, closestPoint); connections.Add(connection); fixedContours.Add(connection); joinedPoints.Add(point); joinedPoints.Add(closestPoint); } } } } } } // Assign variables to output parameters DA.SetDataList(0, Curve.JoinCurves(fixedContours)); DA.SetDataList(1, connections); }