protected override void SolveInstance(IGH_DataAccess DA) { var curves = new List <Curve>(); var lines = new List <Line>(); if (DA.GetDataList(0, curves) && DA.GetDataList(1, lines)) { curves.RemoveAll(_removeNullAndInvalidDelegate); lines.RemoveAll(_removeInvalidDelegate); if (curves.Count < 1) { return; } CurvesTopology top = new CurvesTopology(curves, GH_Component.DocumentTolerance()); var distances = top.MeasureAllEdgeLengths(); List <Curve> result = new List <Curve>(); for (int i = 0; i < lines.Count; i++) { var line = lines[i]; int fromIndex = top.GetClosestNode(line.From); int toIndex = top.GetClosestNode(line.To); if (fromIndex == toIndex) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The start and end positions are equal"); result.Add(null); continue; } var pathSearch = new AStar(top, distances); var current = pathSearch.Cross(fromIndex, toIndex); if (current == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, string.Format("No walk found for line at position {0}. Are end points isolated?", i.ToString())); } result.Add(current); } DA.SetDataList(0, result); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Plane plane = new Plane(); string text = ""; double size = 5; int justify = 0; string font = ""; bool bold = false; double offsetDis = 0; DA.GetData("Location", ref plane); DA.GetData("Text", ref text); DA.GetData("Size", ref size); DA.GetData("Justification", ref justify); DA.GetData("Font", ref font); DA.GetData("Bold", ref bold); DA.GetData("OffsetDistance", ref offsetDis); if (justify < 0 || justify > 8) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid Justification.Only 0-8 are allowed."); justify = 4; } TextJustification justification = TextJustification.MiddleCenter; if (justify == 0) { Message = "BottomLeft"; justification = TextJustification.BottomLeft; } else if (justify == 1) { Message = "BottomCenter"; justification = TextJustification.BottomCenter; } else if (justify == 2) { Message = "BottomRight"; justification = TextJustification.BottomRight; } else if (justify == 3) { Message = "MiddleLeft"; justification = TextJustification.MiddleLeft; } else if (justify == 4) { Message = "MiddleCenter"; justification = TextJustification.MiddleCenter; } else if (justify == 5) { Message = "MiddleRight"; justification = TextJustification.MiddleRight; } else if (justify == 6) { Message = "TopLeft"; justification = TextJustification.TopLeft; } else if (justify == 7) { Message = "TopCenter"; justification = TextJustification.TopCenter; } else if (justify == 8) { Message = "TopRight"; justification = TextJustification.TopRight; } TextEntity t = new TextEntity(); t.Plane = plane; t.PlainText = text; t.DimensionScale = size; t.Font = Rhino.DocObjects.Font.InstalledFonts(font)[0]; t.Justification = justification; t.SetBold(bold); List <Curve> curves = new List <Curve>(t.Explode()); List <Point3d> boxCorner = new List <Point3d>(); foreach (Curve crv in curves) { foreach (Point3d pt in crv.GetBoundingBox(plane).GetCorners()) { boxCorner.Add(pt); } } Box box = new Box(plane, new BoundingBox(boxCorner)); Point3d[] corners = box.GetCorners(); Point3d[] pts = new Point3d[5] { corners[0], corners[1], corners[2], corners[3], corners[0] }; PolylineCurve polyCrv = new PolylineCurve(pts); Curve bound; if (offsetDis == 0) { bound = polyCrv; } else { bound = polyCrv.Offset(plane, offsetDis, GH_Component.DocumentTolerance(), CurveOffsetCornerStyle.Round)[0]; } DA.SetDataList("Curve", curves); DA.SetData("Bound", bound); }
public Curve[] AfterOffset(Curve destination, double naN, Plane unset, int num2) { if (!RhinoMath.IsValidDouble(naN)) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "不是有效的数字"); return(new Curve[] {}); } else if (!unset.IsValid) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "不是有效的平面"); return(new Curve[] { }); } else { double num3 = Math.Abs(naN); double tolerance = Math.Min(GH_Component.DocumentTolerance(), 0.1 * num3); GH_Component.DocumentAngleTolerance(); num2 = Math.Max(Math.Min(num2, 4), 0); if (naN == 0.0) { return(new Curve[] { destination }); } else { CurveOffsetCornerStyle none = CurveOffsetCornerStyle.None; switch (num2) { case 0: none = CurveOffsetCornerStyle.None; break; case 1: none = CurveOffsetCornerStyle.Sharp; break; case 2: none = CurveOffsetCornerStyle.Round; break; case 3: none = CurveOffsetCornerStyle.Smooth; break; case 4: none = CurveOffsetCornerStyle.Chamfer; break; } Curve[] inputCurves = null; inputCurves = destination.Offset(unset, naN, tolerance, none); if (inputCurves == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "不能偏移该曲线"); return(new Curve[] { }); } else { Curve[] data = Curve.JoinCurves(inputCurves); if (data == null) { return(inputCurves); } else { return(data); } } } } }
private bool ProcessCurveArrArray(HbCurveArrArray hbCurveArrArray) // various kinds of lines, vertical wall, or planar floor { try { double brepTolerence = GH_Component.DocumentTolerance(); // Not sure what this is but suggested by McNeel if (brepTolerence <= 0.0) { brepTolerence = 0.001; // Since we are not sure what the effect would be } List <Point3d> pointsInnerLoop; Curve curveInnerLoop; List <Point3d> points = new List <Point3d>(); List <Curve> curves = new List <Curve>(); PolyCurve polyCurve; foreach (HbCurveArray hbCurveArray in hbCurveArrArray) { //List<Curve> curvesInnerLoop = new List<Curve>(); polyCurve = new PolyCurve(); foreach (HbCurve hbCurve in hbCurveArray) { HbTypes hbType; if (hbTypeDictionary.TryGetValue(hbCurve.GetType(), out hbType)) { HbToRhino(hbCurve, out pointsInnerLoop, out curveInnerLoop); if (pointsInnerLoop != null) { foreach (Point3d point3d in pointsInnerLoop) { points.Add(point3d); } } if (curveInnerLoop != null) { polyCurve.Append(curveInnerLoop); } } } if (polyCurve.SegmentCount > 0) { curves.Add(polyCurve); } } // Obsolete w Revit 6 // Brep brep = Brep.CreatePlanarBreps(curves)[0]; Brep brep = Brep.CreatePlanarBreps(curves, brepTolerence)[0]; // Add to outputs this.dataTreePoints.AddRange(points, new GH_Path(indexPoints)); indexPoints++; this.dataTreeCurves.AddRange(curves, new GH_Path(indexCurves)); indexCurves++; this.dataTreeBreps.AddRange(new List <Brep> { brep }, new GH_Path(indexBreps)); indexBreps++; // Create Geometry if (createGeometryPoints) { foreach (Point3d point3d in points) { Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(point3d); } } if (createGeometryCurves) { foreach (Curve curveItem in curves) { Rhino.RhinoDoc.ActiveDoc.Objects.AddCurve(curveItem); } } if (createGeometrySurfaces) { if (brep.Faces.Count > 0) { Rhino.RhinoDoc.ActiveDoc.Objects.AddBrep(brep); } } return(true); } catch { return(false); } }
private bool ProcessPointsToBrep(HbXYZ hbXYZ1, HbXYZ hbXYZ2, HbXYZ hbXYZ3, HbXYZ hbXYZ4) // planar floor { try { double brepTolerence = GH_Component.DocumentTolerance(); // Not sure what this is but suggested by McNeel if (brepTolerence <= 0.0) { brepTolerence = 0.001; // Since we are not sure what the effect would be } if (hbXYZ1 == null || hbXYZ2 == null || hbXYZ3 == null || hbXYZ4 == null) { return(true); // Don't process bad data } List <Point3d> points = new List <Point3d> { new Point3d(hbXYZ1.X, hbXYZ1.Y, hbXYZ1.Z), new Point3d(hbXYZ2.X, hbXYZ2.Y, hbXYZ2.Z), new Point3d(hbXYZ3.X, hbXYZ3.Y, hbXYZ3.Z), new Point3d(hbXYZ4.X, hbXYZ4.Y, hbXYZ4.Z) }; List <Curve> curves = new List <Curve>() { new LineCurve(points[0], points[1]), new LineCurve(points[1], points[2]), new LineCurve(points[2], points[3]), new LineCurve(points[3], points[0]) }; PolyCurve polyCurve = new PolyCurve(); foreach (LineCurve curve in curves) { polyCurve.Append(curve); } // Obsolete w Revit 6 // Brep brep = Brep.CreatePlanarBreps(curves)[0]; Brep brep = Brep.CreatePlanarBreps(curves, brepTolerence)[0]; // Add to outputs this.dataTreePoints.AddRange(points, new GH_Path(indexPoints)); indexPoints++; this.dataTreeCurves.AddRange(curves, new GH_Path(indexCurves)); indexCurves++; this.dataTreeBreps.AddRange(new List <Brep> { brep }, new GH_Path(indexBreps)); indexBreps++; // Create Geometry if (createGeometryPoints) { foreach (Point3d point3d in points) { Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(point3d); } } if (createGeometryCurves) { foreach (Curve curveItem in curves) { Rhino.RhinoDoc.ActiveDoc.Objects.AddCurve(curveItem); } } if (createGeometrySurfaces) { Rhino.RhinoDoc.ActiveDoc.Objects.AddBrep(brep); } return(true); } catch { return(false); } }
/// <summary> /// 計算部分 /// </summary> /// <param name="DA">インプットパラメータからデータを取得し、出力用のデータを保持するオブジェクト</param> protected override void SolveInstance(IGH_DataAccess DA) { int nFL = 0; double FH = 0, Angle = 0, R = 0; IGH_GeometricGoo FL = null; Brep Floor = null; // 入力設定============================ if (!DA.GetData(0, ref nFL)) { return; } if (!DA.GetData(1, ref FH)) { return; } if (!DA.GetData(2, ref Angle)) { return; } if (!DA.GetData(3, ref R)) { return; } if (!DA.GetData(4, ref FL)) { return; } if (!DA.GetData(4, ref Floor)) { return; } // 床の作成 List <IGH_GeometricGoo> list = new List <IGH_GeometricGoo>(nFL); Vector3d DirectionVector = new Vector3d(0, 0, FH); Point3d Center = new Point3d(0, 0, 0); for (int i = 0; i < nFL; i++) { ITransform transform = new Translation(DirectionVector * (double)i); ITransform transform2 = new Rotation(Center, DirectionVector, Angle * (double)i); if (FL != null) { IGH_GeometricGoo FL2 = FL.DuplicateGeometry(); FL2 = FL2.Transform(transform.ToMatrix()); FL2 = FL2.Transform(transform2.ToMatrix()); list.Add(FL2); } else { list.Add(null); } } // 柱の作成 List <Brep> collist = new List <Brep>(nFL); Point3d[] CornerPoints = Floor.DuplicateVertices(); // 内柱 Point3d Point1in = new Point3d(CornerPoints[0].X / 2.0, CornerPoints[0].Y / 2.0, CornerPoints[0].Z / 2.0); Point3d Point2in = new Point3d(CornerPoints[1].X / 2.0, CornerPoints[1].Y / 2.0, CornerPoints[1].Z / 2.0); Point3d Point3in = new Point3d(CornerPoints[2].X / 2.0, CornerPoints[2].Y / 2.0, CornerPoints[2].Z / 2.0); Point3d Point4in = new Point3d(CornerPoints[3].X / 2.0, CornerPoints[3].Y / 2.0, CornerPoints[3].Z / 2.0); // 外柱 Point3d Point1outS = new Point3d(CornerPoints[0].X, CornerPoints[0].Y, CornerPoints[0].Z); Point3d Point2outS = new Point3d(CornerPoints[1].X, CornerPoints[1].Y, CornerPoints[1].Z); Point3d Point3outS = new Point3d(CornerPoints[2].X, CornerPoints[2].Y, CornerPoints[2].Z); Point3d Point4outS = new Point3d(CornerPoints[3].X, CornerPoints[3].Y, CornerPoints[3].Z); Point3d Point1outE = Point1outS; Point3d Point2outE = Point2outS; Point3d Point3outE = Point3outS; Point3d Point4outE = Point4outS; double num1 = GH_Component.DocumentTolerance(); double num2 = GH_Component.DocumentAngleTolerance(); for (int i = 0; i < nFL - 1; i++) { if (FL != null) { if (i != 0) { // 内柱 Point1in = new Point3d(Point1in.X, Point1in.Y, Point1in.Z + FH); Point2in = new Point3d(Point2in.X, Point2in.Y, Point2in.Z + FH); Point3in = new Point3d(Point3in.X, Point3in.Y, Point3in.Z + FH); Point4in = new Point3d(Point4in.X, Point4in.Y, Point4in.Z + FH); // 外柱 Point1outS = new Point3d(Point1outE.X, Point1outE.Y, Point1outE.Z); Point2outS = new Point3d(Point2outE.X, Point2outE.Y, Point2outE.Z); Point3outS = new Point3d(Point3outE.X, Point3outE.Y, Point3outE.Z); Point4outS = new Point3d(Point4outE.X, Point4outE.Y, Point4outE.Z); } // 外柱 終点 Point1outE = new Point3d( Point1outS.X * Math.Cos(Angle) - Point1outS.Y * Math.Sin(Angle), Point1outS.X * Math.Sin(Angle) + Point1outS.Y * Math.Cos(Angle), Point1outS.Z + FH); Point2outE = new Point3d( Point2outS.X * Math.Cos(Angle) - Point2outS.Y * Math.Sin(Angle), Point2outS.X * Math.Sin(Angle) + Point2outS.Y * Math.Cos(Angle), Point2outS.Z + FH); Point3outE = new Point3d( Point3outS.X * Math.Cos(Angle) - Point3outS.Y * Math.Sin(Angle), Point3outS.X * Math.Sin(Angle) + Point3outS.Y * Math.Cos(Angle), Point3outS.Z + FH); Point4outE = new Point3d( Point4outS.X * Math.Cos(Angle) - Point4outS.Y * Math.Sin(Angle), Point4outS.X * Math.Sin(Angle) + Point4outS.Y * Math.Cos(Angle), Point4outS.Z + FH); LineCurve LineCurve1in = new LineCurve(new Line(Point1in, DirectionVector)); LineCurve LineCurve2in = new LineCurve(new Line(Point2in, DirectionVector)); LineCurve LineCurve3in = new LineCurve(new Line(Point3in, DirectionVector)); LineCurve LineCurve4in = new LineCurve(new Line(Point4in, DirectionVector)); // LineCurve LineCurve1out = new LineCurve(new Line(Point1outS, Point1outE)); LineCurve LineCurve2out = new LineCurve(new Line(Point2outS, Point2outE)); LineCurve LineCurve3out = new LineCurve(new Line(Point3outS, Point3outE)); LineCurve LineCurve4out = new LineCurve(new Line(Point4outS, Point4outE)); Brep[] col1in = Brep.CreatePipe(LineCurve1in, R, true, 0, false, num1, num2); Brep[] col2in = Brep.CreatePipe(LineCurve2in, R, true, 0, false, num1, num2); Brep[] col3in = Brep.CreatePipe(LineCurve3in, R, true, 0, false, num1, num2); Brep[] col4in = Brep.CreatePipe(LineCurve4in, R, true, 0, false, num1, num2); // Brep[] col1out = Brep.CreatePipe(LineCurve1out, R, true, 0, false, num1, num2); Brep[] col2out = Brep.CreatePipe(LineCurve2out, R, true, 0, false, num1, num2); Brep[] col3out = Brep.CreatePipe(LineCurve3out, R, true, 0, false, num1, num2); Brep[] col4out = Brep.CreatePipe(LineCurve4out, R, true, 0, false, num1, num2); collist.AddRange(col1in); collist.AddRange(col2in); collist.AddRange(col3in); collist.AddRange(col4in); collist.AddRange(col1out); collist.AddRange(col2out); collist.AddRange(col3out); collist.AddRange(col4out); } } // 出力設定============================ DA.SetDataList(0, list); DA.SetDataList(1, collist); }
protected override void GroundHogSolveInstance(IGH_DataAccess DA) { var CURVES = new List <Curve>(); var STARTS = new List <Point3d>(); var ENDS = new List <Point3d>(); var LENGTHS = new List <double>(); // Access and extract data from the input parameters individually if (!DA.GetDataList(0, CURVES)) { return; } if (!DA.GetDataList(1, STARTS)) { return; } if (!DA.GetDataList(2, ENDS)) { return; } DA.GetDataList(3, LENGTHS); // Input validation int negativeIndex = LENGTHS.FindIndex(_isNegative); if (negativeIndex != -1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Distances cannot be negative. At least one negative value found at index {0}.", negativeIndex)); return; } CURVES.RemoveAll(_removeNullAndInvalidDelegate); if (CURVES.Count < 1) { return; } STARTS.RemoveAll(_removeInvalidDelegate); ENDS.RemoveAll(_removeInvalidDelegate); if (STARTS.Count != ENDS.Count) { if (ENDS.Count == 1 && STARTS.Count > 1) { // Assume multiple starts going to single end; populate ends to match for (int i = 1; i < STARTS.Count; i++) { ENDS.Add(ENDS[0]); } } else if (STARTS.Count == 1 && ENDS.Count > 1) { // Assume single start going to multiple ends; populate starts to match for (int i = 1; i < ENDS.Count; i++) { STARTS.Add(STARTS[0]); } } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The quantity of start points does not match the quantity of end points"); return; } } if (LENGTHS.Count > 0 && LENGTHS.Count != CURVES.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "If lengths are provided they must match the number of curves"); return; } // Construct topology CurvesTopology top = new CurvesTopology(CURVES, GH_Component.DocumentTolerance()); //CurvesTopologyPreview.Mark(top, Color.BurlyWood, Color.Bisque); PathMethod pathSearch; if (LENGTHS.Count == 0) { IList <double> distances = top.MeasureAllEdgeLengths(); pathSearch = new AStar(top, distances); } else if (LENGTHS.Count == 1) { pathSearch = new Dijkstra(top, LENGTHS[0]); } else { IList <double> interfLengths = LENGTHS; if (interfLengths.Count < top.EdgeLength) { interfLengths = new ListByPattern <double>(interfLengths, top.EdgeLength); } bool isAlwaysShorterOrEqual = true; for (int i = 0; i < top.EdgeLength; i++) { if (top.LinearDistanceAt(i) > interfLengths[i]) { isAlwaysShorterOrEqual = false; break; } } if (isAlwaysShorterOrEqual) { pathSearch = new AStar(top, interfLengths); } else { pathSearch = new Dijkstra(top, interfLengths); } } var resultCurves = new List <Curve>(); var resultLinks = new GH_Structure <GH_Integer>(); var resultDirs = new GH_Structure <GH_Boolean>(); var resultLengths = new List <double>(); for (int i = 0; i < STARTS.Count; i++) { int fromIndex = top.GetClosestNode(STARTS[i]); int toIndex = top.GetClosestNode(ENDS[i]); if (fromIndex == toIndex) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The start and end positions are equal; perhaps because they are not close enough to one of the curves in the network."); resultCurves.Add(null); continue; } var current = pathSearch.Cross(fromIndex, toIndex, out int[] nodes, out int[] edges, out bool[] dir, out double tot); if (current == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, string.Format("No walk found for start point at position {0}. Are end points isolated?", i.ToString())); } else { var pathLinks = DA.ParameterTargetPath(1).AppendElement(i); resultLinks.AppendRange(GhWrapTypeArray <int, GH_Integer>(edges), pathLinks); resultDirs.AppendRange(GhWrapTypeArray <bool, GH_Boolean>(dir), pathLinks); resultLengths.Add(tot); } resultCurves.Add(current); } DA.SetDataList(0, resultCurves); DA.SetDataTree(1, resultLinks); DA.SetDataTree(2, resultDirs); DA.SetDataList(3, resultLengths); }
protected override void SolveInstance(IGH_DataAccess DA) { var curves = new List <Curve>(); var lengths = new List <double>(); var lines = new List <Line>(); if (DA.GetDataList(0, curves) && DA.GetDataList(2, lines)) { DA.GetDataList(1, lengths); int negativeIndex = lengths.FindIndex(_isNegative); if (negativeIndex != -1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Distances cannot be negative. At least one negative value encounter at index {0}.", negativeIndex)); return; } curves.RemoveAll(_removeNullAndInvalidDelegate); lines.RemoveAll(_removeInvalidDelegate); if (curves.Count < 1) { return; } CurvesTopology top = new CurvesTopology(curves, GH_Component.DocumentTolerance()); //CurvesTopologyPreview.Mark(top, Color.BurlyWood, Color.Bisque); PathMethod pathSearch; if (lengths.Count == 0) { IList <double> distances = top.MeasureAllEdgeLengths(); pathSearch = new AStar(top, distances); } else if (lengths.Count == 1) { pathSearch = new Dijkstra(top, lengths[0]); } else { IList <double> interfLengths = lengths; if (interfLengths.Count < top.EdgeLength) { interfLengths = new ListByPattern <double>(interfLengths, top.EdgeLength); } bool isAlwaysShorterOrEqual = true; for (int i = 0; i < top.EdgeLength; i++) { if (top.LinearDistanceAt(i) > interfLengths[i]) { isAlwaysShorterOrEqual = false; break; } } if (isAlwaysShorterOrEqual) { pathSearch = new AStar(top, interfLengths); } else { pathSearch = new Dijkstra(top, interfLengths); } } var resultCurves = new List <Curve>(); var resultLinks = new GH_Structure <GH_Integer>(); var resultDirs = new GH_Structure <GH_Boolean>(); var resultLengths = new List <double>(); for (int i = 0; i < lines.Count; i++) { var line = lines[i]; int fromIndex = top.GetClosestNode(line.From); int toIndex = top.GetClosestNode(line.To); if (fromIndex == toIndex) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The start and end positions are equal"); resultCurves.Add(null); continue; } int[] nodes, edges; bool[] dir; double tot; var current = pathSearch.Cross(fromIndex, toIndex, out nodes, out edges, out dir, out tot); if (current == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, string.Format("No walk found for line at position {0}. Are end points isolated?", i.ToString())); } else { var pathLinks = DA.get_ParameterTargetPath(1).AppendElement(i); resultLinks.AppendRange(GhWrapTypeArray <int, GH_Integer>(edges), pathLinks); resultDirs.AppendRange(GhWrapTypeArray <bool, GH_Boolean>(dir), pathLinks); resultLengths.Add(tot); } resultCurves.Add(current); } DA.SetDataList(0, resultCurves); DA.SetDataTree(1, resultLinks); DA.SetDataTree(2, resultDirs); DA.SetDataList(3, resultLengths); } }