/// <summary> /// Constructs a polyline from this rectangle. /// </summary> /// <returns>A polyline with the same shape as this rectangle.</returns> public Polyline ToPolyline() { Polyline rc = new Polyline(5); rc.Add(Corner(0)); rc.Add(Corner(1)); rc.Add(Corner(2)); rc.Add(Corner(3)); rc.Add(Corner(0)); return rc; }
/// <summary> /// Creates a Geometry object from a List of Rhino Curves. /// </summary> /// <param name="c">The c.</param> /// <param name="scale">The scale.</param> /// <param name="rebox">if set to <c>true</c> [rebox].</param> /// <returns></returns> public static Geometry pathGeomFromCrvs(List <Curve> c, double scale, bool rebox) { string crvString = ""; //adapt curve location/positioning rebaseGeometry(c.OfType <GeometryBase>(), scale, rebox); //for all the curves foreach (Curve crv in c) { //try to convert to a polylineCurve and then get the polyline from that PolylineCurve p = new PolylineCurve(); Rhino.Geometry.Polyline pl = new Rhino.Geometry.Polyline(); if (!crv.TryGetPolyline(out pl)) { p = crv.ToPolyline(0, 0, 0.1, 2.0, 0, 0, crv.GetLength() / 50, 0, true); p.TryGetPolyline(out pl); } crvString += "M "; //Start structuring the notation syntax into a string - M starts a shape foreach (Point3d pt in pl) //for all the points in the polyline { // Add each vertex of the polyline. Closed polylines naturally have duplicate vertices at beginning and end // so no special accounting is necessary. crvString += String.Format("{0:0.000},{1:0.000} ", pt.X, pt.Y); } } return(Geometry.Parse(crvString)); //parses the curve string into a geometry object }
public KdTree(List<Point3d> Points) { this.points = new List<Point3d>(); double x1, x2, y1, y2, z1, z2; Points.Sort(CompareDinos_X); x1 = Points[0].X; x2 = Points[Points.Count - 1].X; Points.Sort(CompareDinos_Y); y1 = Points[0].Y; y2 = Points[Points.Count - 1].Y; Points.Sort(CompareDinos_Z); z1 = Points[0].Z; z2 = Points[Points.Count - 1].Z; if ((x2 - x1) > (y2 - y1)) { side = 1; } else { side = 2; } for (int i = 0; i < Points.Count; i++) { Point3d p = Points[i]; if (p.X != x1 && p.X != x2 && p.Y != y1 && p.Y != y2) { this.points.Add(p); } } Point3d p1, p2, p3, p4; p1 = new Point3d(x1, y1, 0); p2 = new Point3d(x2, y1, 0); p3 = new Point3d(x2, y2, 0); p4 = new Point3d(x1, y2, 0); this.Counter = new Polyline(); this.Counter.Add(p1); this.Counter.Add(p2); this.Counter.Add(p3); this.Counter.Add(p4); this.Counter.Add(p1); }
public Mesh ClosedBridge(Polyline pl1, Polyline pl2) { if (pl1.Count != pl2.Count) return null; if (pl1.Count < 2 || pl2.Count < 2) return null; if (pl1[0].DistanceTo(pl1[pl1.Count - 1]) < 0.01) { pl1.RemoveAt(pl1.Count - 1); } if (pl2[0].DistanceTo(pl2[pl2.Count - 1]) < 0.01) { pl2.RemoveAt(pl2.Count - 1); } Polyline pl3 = new Polyline(); int sign = 0; double min = double.MaxValue; for (int i = 0; i < pl2.Count; i++) { double Length = 0; for (int j = 0; j < pl2.Count; j++) { int index = i + j; if (index > pl2.Count - 1) index -= pl2.Count; Length += pl2[index].DistanceTo(pl1[j]); } if (Length < min) { min = Length; sign = i; } } for (int j = 0; j < pl2.Count; j++) { int index = sign + j; if (index > pl2.Count - 1) index -= pl2.Count; pl3.Add(pl2[index]); } return MeshLoft(pl1, pl3, true, false); }
private void SetCurveType(Rg.Curve curve) { Rg.Circle R = new Rg.Circle(); Rg.Arc A = new Rg.Arc(); Rg.Ellipse S = new Rg.Ellipse(); Rg.Polyline P = new Rg.Polyline(); if (curve.TryGetCircle(out R)) { curveType = CurveTypes.Circle; } else if (curve.TryGetArc(out A)) { curveType = CurveTypes.Arc; } else if (curve.TryGetEllipse(out S)) { curveType = CurveTypes.Ellipse; } else if (curve.IsLinear()) { curveType = CurveTypes.Line; } else if (curve.TryGetPolyline(out P)) { curveType = CurveTypes.Polyline; } else { curveType = CurveTypes.Spline; } }
public void FitEdge(ref Mesh mesh, Polyline pts, double tol) { MeshCreation mc = new MeshCreation(); List<int> index = mc.MeshEdgeVerticeIndex(mesh); for (int i = 0; i < index.Count; i++) { Point3d pt = mesh.Vertices[index[i]]; int sign = 0; double dist = double.MaxValue; for (int j = 0; j < pts.Count; j++) { double t = pts[j].DistanceTo(pt); if (t < dist) { dist = t; sign = j; } } mesh.Vertices.SetVertex(index[i], pts[sign]); } for (int i = 0; i < mesh.Vertices.Count; i++) { Point3d pt = mesh.Vertices[i]; int sign = 0; double dist = double.MaxValue; for (int j = 0; j < pts.Count; j++) { double t = pts[j].DistanceTo(pt); if (t < dist) { dist = t; sign = j; } } if (dist < tol) mesh.Vertices.SetVertex(i, pts[sign]); } }
public static Profile ToProfile(this rg.Polyline pl) { var polygon = pl.ToPolygon(); var profile = new Profile(polygon); return(profile); }
public SimpleTrail(Program program, double maxLength, int mechanicalGroup = 0) { this.program = program; this.Length = maxLength; this.mechanicalGroup = mechanicalGroup; Polyline = new Polyline(); time = program.CurrentSimulationTime; }
/// <summary> /// Verifies a Polyline is a rectangle /// </summary> public static bool IsRectangle(Polyline polyline) { if (polyline == null) return false; var curve = new PolylineCurve(polyline); return curve.IsValid && IsRectangle(curve); }
/// <summary> /// Returns a Windows Shapes Path from a Rhinocommon Polyline /// </summary> /// <param name="input">Rhinocommon Polyline</param> /// <returns>System Windows Shapes Path</returns> public static Sh.Path ToPath(this Rg.Polyline input) { Sh.Path path = new Sh.Path(); path.Data = input.ToGeometry(); return(path); }
private Polyline[] calculateOffsetEdges() { Polyline[] insetLines = new Polyline[refMesh.faces.Count]; for (int i = 0; i < refMesh.faces.Count; i++) { insetLines[i] = refMesh.faces[i].convertFaceToOffsetPolyline(offsetEdgeValues); } return insetLines; }
public static Rg.Polyline ToPolyline(this List <Rg.Point3d> input, bool isClosed = false) { Rg.Polyline polyline = new Rg.Polyline(input); if (isClosed) { polyline.Add(input[0]); } return(polyline); }
public List<Line> breakPoly(Polyline pl) { List<Line> ls = new List<Line>(); if (pl.Count < 1) return ls; for (int i = 1; i < pl.Count; i++) { ls.Add(new Line(pl[i], pl[i - 1])); } return ls; }
public static Polyline cc_Subdivide(Polyline ptlist, int level) { if (level >= 1) { for (int i = 0; i < level; i++) { ptlist = cc_Subdivide(ptlist); } } return ptlist; }
/***************************************************/ public static BHG.Polyline FromRhino(this RHG.Polyline polyline) { if (polyline == null) { return(null); } return(new BHG.Polyline { ControlPoints = polyline.Select(x => x.FromRhino()).ToList() }); }
public static NXOpen.Point3d[] AsPolyLine(Polyline value) { int count = value.Count; var points = new NXOpen.Point3d[count]; for (int p = 0; p < count; ++p) { points[p] = AsXYZ(value[p]); } return(points); }
public static string ToSVG(this Rg.Polyline input) { Rg.Curve curve = input.ToNurbsCurve(); string output = "M " + input[0].ToSVG(); for (int i = 1; i < input.Count; i++) { output += input[i].ToSVG(); } output += " "; return(output); }
/***************************************************/ public static BHG.ICurve FromRhino(this RHG.Curve rCurve) { if (rCurve == null) { return(null); } Type curveType = rCurve.GetType(); if (rCurve.IsLinear() && rCurve.SpanCount < 2) { return(new BHG.Line { Start = rCurve.PointAtStart.FromRhino(), End = rCurve.PointAtEnd.FromRhino(), Infinite = false }); } if (rCurve.IsCircle()) { RHG.Circle circle = new RHG.Circle(); rCurve.TryGetCircle(out circle); return(circle.FromRhino()); } else if (rCurve.IsArc() || typeof(RHG.ArcCurve).IsAssignableFrom(curveType)) { RHG.Arc arc = new RHG.Arc(); rCurve.TryGetArc(out arc); return(arc.FromRhino()); } else if (rCurve.IsPolyline() || typeof(RHG.PolylineCurve).IsAssignableFrom(curveType)) { RHG.Polyline polyline = new RHG.Polyline(); rCurve.TryGetPolyline(out polyline); return(polyline.FromRhino()); } else if (rCurve.IsClosed && rCurve.IsEllipse()) { RHG.Ellipse ellipse = new RHG.Ellipse(); rCurve.TryGetEllipse(out ellipse); return(ellipse.FromRhino()); } else if (rCurve is RHG.NurbsCurve) { return(((RHG.NurbsCurve)rCurve).FromRhino()); } else if (rCurve is RHG.PolyCurve) { return(((RHG.PolyCurve)rCurve).FromRhino()); //The test of IsPolyline above is very important to make sure we can cast to PolyCurve here } else { return((rCurve.ToNurbsCurve()).FromRhino()); } }
public static List <Rg.Polyline> TraceToRhino(this Bitmap input, double threshold, double alpha, double tolerance, int size, bool optimize, TurnModes mode) { List <List <Pt.Curve> > crvs = new List <List <Pt.Curve> >(); List <Rg.Polyline> polylines = new List <Rg.Polyline>(); int height = input.Height; Pt.Potrace.Clear(); Pt.Potrace.turnpolicy = (Pt.TurnPolicy)mode; Pt.Potrace.curveoptimizing = optimize; Pt.Potrace.opttolerance = tolerance; Pt.Potrace.Treshold = threshold; Pt.Potrace.alphamax = alpha * 1.3334; Pt.Potrace.turdsize = size; Pt.Potrace.Potrace_Trace(input, crvs); foreach (var crvList in crvs) { Rg.Polyline polyline = new Rg.Polyline(); polyline.Add(crvList[0].A.ToRhPoint(height)); foreach (Pt.Curve curve in crvList) { Rg.Point3d a = curve.ControlPointA.ToRhPoint(height); Rg.Point3d b = curve.ControlPointB.ToRhPoint(height); Rg.Point3d c = curve.B.ToRhPoint(height); if (a != polyline[polyline.Count - 1]) { polyline.Add(a); } if (b != a) { polyline.Add(b); } if (c != b) { polyline.Add(c); } } if (!polyline.IsClosed) { polyline.Add(crvList[0].A.ToRhPoint(height)); } polylines.Add(polyline); } return(polylines); }
//David: I just copied this function from Point3dList... internal static Polyline PolyLineFromNativeArray(Runtime.InteropWrappers.SimpleArrayPoint3d pts) { if (null == pts) return null; int count = pts.Count; Polyline list = new Polyline(count); if (count > 0) { IntPtr pNativeArray = pts.ConstPointer(); UnsafeNativeMethods.ON_3dPointArray_CopyValues(pNativeArray, list.m_items); list.m_size = count; } return list; }
public static Polyline cc_Subdivide(Polyline ptlist) { List<Point3d> ps2 = new List<Point3d>(); if (ptlist.Count < 3) { return ptlist; } if (ptlist[0].DistanceTo(ptlist[ptlist.Count - 1]) > 0.001) { ps2.Add(ptlist[0]); Point3d pt = (ptlist[0] + ptlist[1]) / 2; ps2.Add(pt); for (int i = 1; i < ptlist.Count - 1; i++) { Point3d p1 = new Point3d(ptlist[i - 1]); Point3d p2 = new Point3d(ptlist[i]); Point3d p3 = new Point3d(ptlist[i + 1]); Point3d p4 = (p2 + p3) / 2; ps2.Add(p1 * (1 / 6.0) + p2 * (2 / 3.0) + p3 * (1 / 6.0)); ps2.Add(p4); } ps2.Add(ptlist[ptlist.Count - 1]); } else { if (ptlist.Count < 4) { return ptlist; } Point3d p1 = new Point3d(ptlist[ptlist.Count - 2]); Point3d p2 = new Point3d(ptlist[0]); Point3d p3 = new Point3d(ptlist[0 + 1]); Point3d p4 = (p2 + p3) / 2; ps2.Add(p1 * (1 / 6.0) + p2 * (2 / 3.0) + p3 * (1 / 6.0)); ps2.Add(p4); for (int i = 1; i < ptlist.Count - 1; i++) { p1 = new Point3d(ptlist[i - 1]); p2 = new Point3d(ptlist[i]); p3 = new Point3d(ptlist[i + 1]); p4 = (p2 + p3) / 2; ps2.Add(p1 * (1 / 6.0) + p2 * (2 / 3.0) + p3 * (1 / 6.0)); ps2.Add(p4); } ps2.Add(ps2[0]); } Polyline pl2 = new Polyline(ps2); return pl2; }
public static Polyline ToPolyline(this rg.Polyline pl) { var vertices = new List <Vector3>(); var lastVertex = rg.Point3d.Unset; foreach (var vertex in pl) { if (lastVertex == rg.Point3d.Unset || lastVertex.DistanceTo(vertex) > 0.0001) { vertices.Add(vertex.ToVector3()); } lastVertex = vertex; } return(new Polyline(vertices)); }
public override void InitializeAgent() { // layoutAcademy = GameObject.FindObjectOfType<Academy>().GetComponent<LayoutAcademy>(); layoutArea = transform.parent.GetComponent <LayoutArea>(); //transform.position = layoutAcademy.agentPosition[agentNumber]; transform.position = layoutArea.agentPosition[agentNumber]; //gridSize = layoutAcademy.gridSize; gridSize = layoutArea.gridSize; x_Ex = layoutArea.x_Ex; y_Ex = layoutArea.y_Ex; shape = layoutArea.shape; offsetShape = layoutArea.offsetShape; }
public static string ToSVG(this Hp.Geometry input) { string path = string.Empty; switch (input.CurveType) { case Geometry.CurveTypes.Arc: Rg.Arc arc = new Rg.Arc(); input.Curve.TryGetArc(out arc); path = arc.ToSVG(); break; case Geometry.CurveTypes.Circle: Rg.Circle circle = new Rg.Circle(); input.Curve.TryGetCircle(out circle); path = circle.ToSVG(); break; case Geometry.CurveTypes.Ellipse: Rg.Ellipse ellipse = new Rg.Ellipse(); input.Curve.TryGetEllipse(out ellipse); path = ellipse.ToSVG(); break; case Geometry.CurveTypes.Line: Rg.Line line = new Rg.Line(input.Curve.PointAtStart, input.Curve.PointAtEnd); path = line.ToSVG(); break; case Geometry.CurveTypes.Polyline: Rg.Polyline polyline = new Rg.Polyline(); input.Curve.TryGetPolyline(out polyline); path = polyline.ToSVG(); break; case Geometry.CurveTypes.Rectangle: Rg.Polyline pline = new Rg.Polyline(); input.Curve.TryGetPolyline(out pline); path = pline.ToSVG(); break; default: path = input.Curve.ToSVG(); break; } return(path); }
/// <summary> /// Convert a Rhino polyline to a Nucleus one /// </summary> /// <param name="polyline"></param> /// <returns></returns> public static PolyLine Convert(RC.Polyline polyline) { if (polyline != null && polyline.IsValid) { var points = new List <Vector>(); foreach (RC.Point3d pt in polyline) { points.Add(Convert(pt)); } return(new PolyLine(points)); } else { return(null); } }
public static Sm.Geometry ToGeometry(this Geometry input) { Sm.Geometry geometry = null; switch (input.CurveType) { case Geometry.CurveTypes.Arc: Rg.Arc arc = new Rg.Arc(); input.Curve.TryGetArc(out arc); geometry = arc.ToGeometry(); break; case Geometry.CurveTypes.Circle: Rg.Circle circle = new Rg.Circle(); input.Curve.TryGetCircle(out circle); geometry = circle.ToGeometry(); break; case Geometry.CurveTypes.Ellipse: Rg.Ellipse ellipse = new Rg.Ellipse(); input.Curve.TryGetEllipse(out ellipse); geometry = ellipse.ToGeometry(); break; case Geometry.CurveTypes.Line: Rg.Line line = new Rg.Line(input.Curve.PointAtStart, input.Curve.PointAtEnd); geometry = line.ToGeometry(); break; case Geometry.CurveTypes.Polyline: Rg.Polyline polyline = new Rg.Polyline(); input.Curve.TryGetPolyline(out polyline); geometry = polyline.ToGeometry(); break; case Geometry.CurveTypes.Rectangle: Rg.Polyline pline = new Rg.Polyline(); input.Curve.TryGetPolyline(out pline); Rg.Rectangle3d rectangle = new Rg.Rectangle3d(Rg.Plane.WorldXY, pline[0], pline[2]); geometry = rectangle.ToGeometry(); break; default: geometry = input.Curve.ToGeometry(); break; } return(geometry); }
public SuperPolyline(Polyline p, bool isClosed) { data.uvs = ""; data.normals = ""; data.faces = ""; data.isClosed = isClosed; data.vertices = new List<double>(); Point3d[] pts = p.ToArray(); foreach (Point3d myPoint in pts) { data.vertices.Add(Math.Round(myPoint.Y * 1, 3)); data.vertices.Add(Math.Round(myPoint.Z * 1, 3)); data.vertices.Add(Math.Round(myPoint.X * 1, 3)); } }
/***************************************************/ public static bool IsEqual(this BHG.Polyline bhPolyline, RHG.Polyline rhPolyline, double tolerance = BHG.Tolerance.Distance) { if (bhPolyline == null & rhPolyline == null) { return(true); } RHG.Point3d[] rhPoints = rhPolyline.ToArray(); List <BHG.Point> bhPoints = bhPolyline.ControlPoints; bool pointsEqual = false; for (int i = 0; i < bhPoints.Count; i++) { pointsEqual = bhPoints[i].IsEqual(rhPoints[i], tolerance); } return(pointsEqual); }
/// <summary> /// Returns a Windows Media Path Geometry from a Rhinocommon Polyline /// </summary> /// <param name="input">Rhinocommon Polyline</param> /// <returns>System Windows Media Path Geometry</returns> public static Sm.PathGeometry ToGeometry(this Rg.Polyline input) { Sm.PathFigure figure = new Sm.PathFigure(); Sm.PathGeometry geometry = new Sm.PathGeometry(); Sm.PathFigureCollection figureCollection = new Sm.PathFigureCollection(); Sm.PathSegmentCollection segmentCollection = new Sm.PathSegmentCollection(); figure.StartPoint = input[0].ToWindowsPoint(); for (int i = 1; i < input.Count; i++) { Sm.LineSegment line = new Sm.LineSegment(input[i].ToWindowsPoint(), true); segmentCollection.Add(line); } figure.Segments = segmentCollection; figureCollection.Add(figure); geometry.Figures = figureCollection; return(geometry); }
public static Polyline[] ExportRhinoPolylines(ITurtleMesh ngons) { var polylines = new Polyline[ngons.FaceCount]; for (int i = 0; i < ngons.FaceCount; i++) { var f = ngons.FaceAt(i); Polyline p = new Polyline(f.EdgesVerticesCount + 1); for (int j = 0; j < f.EdgesVerticesCount; j++) { var v = ngons.VertexAt(f[j]); p.Add(v.X, v.Y, v.Z); } var closure = ngons.VertexAt(f[0]); p.Add(closure.X, closure.Y, closure.Z); polylines[i] = p; } return polylines; }
/// <summary> /// Converts dxf lwpolyline into rhino polyline. This method will approximate arcs to small lines. /// TODO: check magic numbers (int precision=36, double lengthTolerance=.001) /// </summary> /// <param name="precision"></param> /// <param name="lengthTolerance"></param> /// <returns></returns> private Polyline GetApproxRhinoPolyline(int precision = 16, double lengthTolerance = .001) { if (DxfLwPolyline != null) { IList <Vector2> vertexes = DxfLwPolyline.PolygonalVertexes(precision, lengthTolerance, .001); List <Point3d> RhPlVertexes = new List <Point3d>(); Polyline pl = new Rhino.Geometry.Polyline(); foreach (var item in vertexes) { RhPlVertexes.Add(new Point3d(item.X, item.Y, 0)); } pl = new Polyline(RhPlVertexes); return(pl); } else { return(null); } }
// Start is called before the first frame update void Start() { var render = obj.GetComponent <LineRenderer>(); var vetx = new List <Point3d>(); for (int i = 0; i < render.positionCount; i++) { vetx.Add(render.GetPosition(i).ToRhino()); } var shapeCrv = new Rhino.Geometry.Polyline(vetx).ToPolylineCurve(); shapeCrv.MakeClosed(1); var plane = new Rhino.Geometry.Plane(AreaMassProperties.Compute(shapeCrv).Centroid, Vector3d.ZAxis); shapeCrv.Offset(plane, (-gridSize * minGridNum) / 2.0 * 0.001f, 1, CurveOffsetCornerStyle.Sharp)[0].TryGetPolyline(out Polyline offsetShapeCrv); Debug.Log(shapeCrv.Offset(plane, (-gridSize * minGridNum) / 2.0 * 0.001f, 1, CurveOffsetCornerStyle.Sharp).Length); RhinoPreview.PolyLineShow(offsetShapeCrv, Color.red, 0.3f, "offset", false); RhinoPreview.PolyLineShow(new Rhino.Geometry.Polyline(vetx), Color.green, 0.3f, "offset", false); }
// polyline public static Model3D RhinoToHelixPolyline(Rhino.Geometry.Polyline poly, double diameter, int resolutiontube, System.Windows.Media.Media3D.Material mat) { var modelGroup = new Model3DGroup(); var meshBuilder = new MeshBuilder(false, false); Line[] lines = poly.GetSegments(); List <Point3D> path = new List <Point3D>(); foreach (Line l in lines) { path.Add(RhinoToHelixPoint(l.To)); } path.Add(RhinoToHelixPoint(lines[0].From)); meshBuilder.AddTube(path, diameter, resolutiontube, true); var meshHelix = meshBuilder.ToMesh(true); modelGroup.Children.Add(new GeometryModel3D { Geometry = meshHelix, Material = mat, BackMaterial = mat }); return(modelGroup); }
public static bool getPolyLines(List <Rhino.Geometry.Polyline> rhino_polylines, IntPtr pPolylines, bool flipYZ = true) { if (isNull(pPolylines) == 0) { int nPolyLines = getNPolyLines(pPolylines); for (int id = 0; id < nPolyLines; id++) { int nPolyLineI = getNPolyLineI(pPolylines, id); IntPtr pPoints = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(float)) * nPolyLineI * 3); copyPolyLineI(pPolylines, id, pPoints); float[] points = new float[3 * nPolyLineI]; Marshal.Copy(pPoints, points, 0, 3 * nPolyLineI); Marshal.FreeHGlobal(pPoints); //use points to construct polylines List <Rhino.Geometry.Point3d> rhino_points = new List <Rhino.Geometry.Point3d>(nPolyLineI); for (int jd = 0; jd < nPolyLineI; jd++) { Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(); if (flipYZ) { pt = new Rhino.Geometry.Point3d(points[jd * 3], -points[jd * 3 + 2], points[jd * 3 + 1]); } else { pt = new Rhino.Geometry.Point3d(points[jd * 3], points[jd * 3 + 1], points[jd * 3 + 2]); } rhino_points.Add(pt); } Rhino.Geometry.Polyline polyline = new Rhino.Geometry.Polyline(rhino_points); rhino_polylines.Add(polyline); } return(true); } return(false); }
public static Polygon ToPolygon(this rg.Polyline pl) { if (pl.IsClosed) { pl.RemoveAt(pl.Count - 1); } var vertices = new List <Vector3>(); var lastVertex = rg.Point3d.Unset; foreach (var vertex in pl) { if (lastVertex == rg.Point3d.Unset || lastVertex.DistanceTo(vertex) > 0.0001) { vertices.Add(vertex.ToVector3()); } lastVertex = vertex; } var polygon = new Polygon(vertices); return(polygon); }
public void CreateMeshRoad(Polyline x, Mesh y, double[] inputdata, out Mesh road, out List<Mesh> bank, out List<Polyline> Ploutput) { road = new Mesh(); bank = new List<Mesh>(); Ploutput = new List<Polyline>(); Polyline pl1 = Project(x, y); //pl1 = MeshClassLibrary.PolylineSmooth.cc_Subdivide(pl1); pl1.Transform(Transform.Translation(0, 0, inputdata[0])); Polyline pl1a = OffsetPolyline(pl1, -inputdata[1]); Polyline pl1b = OffsetPolyline(pl1, inputdata[2]); pl1a = MeshClassLibrary.PolylineSmooth.cc_Subdivide(pl1a, (int)inputdata[3]); pl1b = MeshClassLibrary.PolylineSmooth.cc_Subdivide(pl1b, (int)inputdata[3]); Polyline pl1af = Project(pl1a, y); Polyline pl1bf = Project(pl1b, y); FitPoly(ref pl1af, pl1a); FitPoly(ref pl1bf, pl1b); bank.AddRange(MeshRoadWall(pl1a, pl1af)); bank.AddRange(MeshRoadWall(pl1bf, pl1b)); road = MeshUVRoad(pl1a, pl1b, 60); Ploutput.Add(pl1af); Ploutput.Add(pl1bf); }
public static GameObject PolyLineShow(Rhino.Geometry.Polyline polyLine, Color color, float width, string name = "PolyLine", bool convertM = true) { var polyLineObj = new GameObject(name); var lineRender = polyLineObj.AddComponent <LineRenderer>(); var vtxs = polyLine.ToList(); lineRender.positionCount = vtxs.Count; for (int i = 0; i < vtxs.Count; i++) { var position = convertM ? new Vector3((float)vtxs[i].X, (float)vtxs[i].Y, (float)vtxs[i].Z) * 0.001f : new Vector3((float)vtxs[i].X, (float)vtxs[i].Y, (float)vtxs[i].Z); lineRender.SetPosition(i, position); } lineRender.startColor = color; lineRender.endColor = color; lineRender.startWidth = width; lineRender.endWidth = width; lineRender.receiveShadows = false; lineRender.material = new Material(Shader.Find("UI/Default")); return(polyLineObj); }
/// <summary> /// Adds a polygon to the drawing list. Polygons are not like Hatches, when you supply a concave /// polygon, the shading probably won't work. /// </summary> /// <param name="polygon">Points that define the corners of the polygon.</param> /// <param name="fillColor">Fill color of polygon.</param> /// <param name="edgeColor">Edge color of polygon.</param> /// <param name="drawFill">If true, the polygon contents will be drawn.</param> /// <param name="drawEdge">If true, the polygon edge will be drawn.</param> public void AddPolygon(IEnumerable<Point3d> polygon, Color fillColor, Color edgeColor, bool drawFill, bool drawEdge) { if (m_disposed) { throw new ObjectDisposedException("This CustomDisplay instance has been disposed and cannot be modified"); } if (polygon == null) { return; } Polyline pgon = new Polyline(polygon); CDU_Polygon cdu = new CDU_Polygon(); cdu.m_polygon = pgon; cdu.m_color_fill = fillColor; cdu.m_color_edge = edgeColor; cdu.m_draw_fill = drawFill; cdu.m_draw_edge = drawEdge; m_polygons.Add(cdu); m_clip.Union(pgon.BoundingBox); }
/// <summary> /// Several types of Curve can have the form of a polyline /// including a degree 1 NurbsCurve, a PolylineCurve, /// and a PolyCurve all of whose segments are some form of /// polyline. IsPolyline tests a curve to see if it can be /// represented as a polyline. /// </summary> /// <param name="polyline"> /// If true is returned, then the polyline form is returned here. /// </param> /// <param name="parameters"> /// if true is returned, then the parameters of the polyline /// points are returned here. /// </param> /// <returns>true if this curve can be represented as a polyline; otherwise, false.</returns> public bool TryGetPolyline(out Polyline polyline, out double[] parameters) { polyline = null; parameters = null; SimpleArrayPoint3d outputPts = new SimpleArrayPoint3d(); int pointCount = 0; IntPtr pCurve = ConstPointer(); IntPtr outputPointsPointer = outputPts.NonConstPointer(); Rhino.Runtime.InteropWrappers.SimpleArrayDouble tparams = new SimpleArrayDouble(); IntPtr ptparams = tparams.NonConstPointer(); UnsafeNativeMethods.ON_Curve_IsPolyline2(pCurve, outputPointsPointer, ref pointCount, ptparams); if (pointCount > 0) { polyline = Polyline.PolyLineFromNativeArray(outputPts); parameters = tparams.ToArray(); } tparams.Dispose(); outputPts.Dispose(); return (pointCount != 0); }
/// <summary> /// unstable method, the level is 10 /// </summary> public Mesh ComputeMeshTree(List<Line> x, Point3d y,double firstEnergy,double EnergyDecrease) { Vertice1.CreateCollection(x, out this.id, out this.vs); for (int i = 0; i < vs.Count; i++) { if (vs[i].equalTo(y)) { vs[i].energy = firstEnergy; break; } } for (int i = 0; i < 40; i++) { vs.ForEach(delegate(Vertice1 v) { v.transferenergy(EnergyDecrease, ref vs); }); } for (int i = 0; i < vs.Count; i++) { vs[i].CrateEdges(vs); //Print(vs[i].edges.Count.ToString()); } //////////////// Mesh mesh = new Mesh(); for (int i = 0; i < id.Count; i++) { Polyline pl1 = new Polyline(); Polyline pl2 = new Polyline(); if (vs[id[i].J].refer.Count == 3) { for (int j = 0; j < 3; j++) { if (vs[id[i].J].refer[j] == id[i].I) { pl1 = vs[id[i].J].edges[j]; break; } } } if (vs[id[i].I].refer.Count == 3) { for (int j = 0; j < 3; j++) { if (vs[id[i].I].refer[j] == id[i].J) { pl2 = vs[id[i].I].edges[j]; break; } } } //Print(pl1.Count.ToString()); if (pl1.Count == 4 && pl2.Count == 0) { Plane p = new Plane(vs[id[i].I].pos, vs[vs[id[i].I].refer[0]].pos - vs[id[i].I].pos); pl2.AddRange(pl1); pl2.Transform(Transform.PlanarProjection(p)); } if (pl1.Count == 0 && pl2.Count == 4) { Plane p = new Plane(vs[id[i].J].pos, vs[vs[id[i].J].refer[0]].pos - vs[id[i].J].pos); pl1.AddRange(pl2); pl1.Transform(Transform.PlanarProjection(p)); } if (pl1.Count == 4 && pl2.Count == 4) { Plane p1 = new Plane(pl1[0], pl1[1], pl1[2]); Plane p2 = new Plane(pl2[0], pl2[1], pl2[2]); if (Vector3d.VectorAngle(p1.Normal, p2.Normal) > Math.PI / 2) pl2.Reverse(); mesh.Append(mc.ClosedBridge(pl1, pl2)); } } return mesh; }
public void SetInputs(List <DataTree <ResthopperObject> > values) { foreach (var tree in values) { if (!_input.TryGetValue(tree.ParamName, out var inputGroup)) { continue; } if (inputGroup.AlreadySet(tree)) { LogDebug("Skipping input tree... same input"); continue; } inputGroup.CacheTree(tree); IGH_ContextualParameter contextualParameter = inputGroup.Param as IGH_ContextualParameter; if (contextualParameter != null) { switch (ParamTypeName(inputGroup.Param)) { case "Number": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { double[] doubles = new double[entree.Value.Count]; for (int i = 0; i < doubles.Length; i++) { ResthopperObject restobj = entree.Value[i]; doubles[i] = JsonConvert.DeserializeObject <double>(restobj.Data); } contextualParameter.AssignContextualData(doubles); break; } } break; case "Integer": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { int[] integers = new int[entree.Value.Count]; for (int i = 0; i < integers.Length; i++) { ResthopperObject restobj = entree.Value[i]; integers[i] = JsonConvert.DeserializeObject <int>(restobj.Data); } contextualParameter.AssignContextualData(integers); break; } } break; case "Point": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { Point3d[] points = new Point3d[entree.Value.Count]; for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; points[i] = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data); } contextualParameter.AssignContextualData(points); break; } } break; case "Line": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { Line[] lines = new Line[entree.Value.Count]; for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; lines[i] = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data); } contextualParameter.AssignContextualData(lines); break; } } break; case "Text": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { string[] strings = new string[entree.Value.Count]; for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; strings[i] = restobj.Data.Trim(new char[] { '"' }); } contextualParameter.AssignContextualData(strings); break; } } break; case "Geometry": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GeometryBase[] geometries = new GeometryBase[entree.Value.Count]; for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(restobj.Data); geometries[i] = Rhino.Runtime.CommonObject.FromJSON(dict) as GeometryBase; } contextualParameter.AssignContextualData(geometries); break; } } break; } continue; } inputGroup.Param.VolatileData.Clear(); inputGroup.Param.ExpireSolution(false); // mark param as expired but don't recompute just yet! if (inputGroup.Param is Param_Point) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Point3d rPt = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data); GH_Point data = new GH_Point(rPt); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Vector) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Vector3d rhVector = JsonConvert.DeserializeObject <Rhino.Geometry.Vector3d>(restobj.Data); GH_Vector data = new GH_Vector(rhVector); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Integer) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; int rhinoInt = JsonConvert.DeserializeObject <int>(restobj.Data); GH_Integer data = new GH_Integer(rhinoInt); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Number) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_String) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = restobj.Data; GH_String data = new GH_String(rhString); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Line) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Line rhLine = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data); GH_Line data = new GH_Line(rhLine); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Curve) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; GH_Curve ghCurve; try { Rhino.Geometry.Polyline data = JsonConvert.DeserializeObject <Rhino.Geometry.Polyline>(restobj.Data); Rhino.Geometry.Curve c = new Rhino.Geometry.PolylineCurve(data); ghCurve = new GH_Curve(c); } catch { var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(restobj.Data); var c = (Rhino.Geometry.Curve)Rhino.Runtime.CommonObject.FromJSON(dict); ghCurve = new GH_Curve(c); } inputGroup.Param.AddVolatileData(path, i, ghCurve); } } continue; } if (inputGroup.Param is Param_Circle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Circle rhCircle = JsonConvert.DeserializeObject <Rhino.Geometry.Circle>(restobj.Data); GH_Circle data = new GH_Circle(rhCircle); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Plane) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Plane rhPlane = JsonConvert.DeserializeObject <Rhino.Geometry.Plane>(restobj.Data); GH_Plane data = new GH_Plane(rhPlane); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Rectangle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Rectangle3d rhRectangle = JsonConvert.DeserializeObject <Rhino.Geometry.Rectangle3d>(restobj.Data); GH_Rectangle data = new GH_Rectangle(rhRectangle); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Box) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Box rhBox = JsonConvert.DeserializeObject <Rhino.Geometry.Box>(restobj.Data); GH_Box data = new GH_Box(rhBox); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Surface) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Surface rhSurface = JsonConvert.DeserializeObject <Rhino.Geometry.Surface>(restobj.Data); GH_Surface data = new GH_Surface(rhSurface); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Brep) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Brep rhBrep = JsonConvert.DeserializeObject <Rhino.Geometry.Brep>(restobj.Data); GH_Brep data = new GH_Brep(rhBrep); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Mesh) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Mesh rhMesh = JsonConvert.DeserializeObject <Rhino.Geometry.Mesh>(restobj.Data); GH_Mesh data = new GH_Mesh(rhMesh); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is GH_NumberSlider) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Boolean || inputGroup.Param is GH_BooleanToggle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; bool boolean = JsonConvert.DeserializeObject <bool>(restobj.Data); GH_Boolean data = new GH_Boolean(boolean); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is GH_Panel) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = JsonConvert.DeserializeObject <string>(restobj.Data); GH_String data = new GH_String(rhString); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } } }
private static bool GetRectangleCurve(string section, out List<Curve> crvs) { crvs = new List<Curve>(); double height, width; if (!GetDimensionsRectangle(section, out height, out width)) return false; height /= Utilities.GetScalingFactorFromRhino(); width /= Utilities.GetScalingFactorFromRhino(); List<Point3d> pts = new List<Point3d>(); pts.Add((Point3d)(Vector3d.ZAxis * height / 2 + Vector3d.YAxis * width / 2)); pts.Add((Point3d)(Vector3d.ZAxis * height / 2 - Vector3d.YAxis * width / 2)); pts.Add((Point3d)(-Vector3d.ZAxis * height / 2 - Vector3d.YAxis * width / 2)); pts.Add((Point3d)(-Vector3d.ZAxis * height / 2 + Vector3d.YAxis * width / 2)); pts.Add((Point3d)(Vector3d.ZAxis * height / 2 + Vector3d.YAxis * width / 2)); // Add first pt again to get closed curve Polyline p = new Polyline(pts); crvs.Add(p.ToNurbsCurve()); return true; }
private static bool GetRHSCurve(string section, out List<Curve> crvs) { crvs = new List<Curve>(); double height, width, thickness; if (!GetDimensionsRHS(section, out height, out width, out thickness)) return false; height /= Utilities.GetScalingFactorFromRhino(); width /= Utilities.GetScalingFactorFromRhino(); thickness /= Utilities.GetScalingFactorFromRhino(); // Outer curve List<Point3d> pts = new List<Point3d>(); pts.Add((Point3d)(Vector3d.ZAxis * height / 2 + Vector3d.YAxis * width / 2)); pts.Add((Point3d)(Vector3d.ZAxis * height / 2 - Vector3d.YAxis * width / 2)); pts.Add((Point3d)(-Vector3d.ZAxis * height / 2 - Vector3d.YAxis * width / 2)); pts.Add((Point3d)(-Vector3d.ZAxis * height / 2 + Vector3d.YAxis * width / 2)); pts.Add((Point3d)(Vector3d.ZAxis * height / 2 + Vector3d.YAxis * width / 2)); // Add first pt again to get closed curve Polyline p1 = new Polyline(pts); crvs.Add(p1.ToNurbsCurve()); // Inner curve pts.Clear(); pts.Add((Point3d)(Vector3d.ZAxis * ((height / 2) - thickness) + Vector3d.YAxis * ((width / 2) - thickness))); pts.Add((Point3d)(Vector3d.ZAxis * ((height / 2) - thickness) - Vector3d.YAxis * ((width / 2) - thickness))); pts.Add((Point3d)(-Vector3d.ZAxis * ((height / 2) - thickness) - Vector3d.YAxis * ((width / 2) - thickness))); pts.Add((Point3d)(-Vector3d.ZAxis * ((height / 2) - thickness) + Vector3d.YAxis * ((width / 2) - thickness))); pts.Add((Point3d)(Vector3d.ZAxis * ((height / 2) - thickness) + Vector3d.YAxis * ((width / 2) - thickness))); // Add first pt again to get closed curve Polyline p2 = new Polyline(pts); crvs.Add(p2.ToNurbsCurve()); return true; }
/// <summary> /// Breaks this polyline into sections at sharp kinks. /// Closed polylines will also be broken at the first and last vertex. /// </summary> /// <param name="angle">Angle (in radians) between adjacent segments for a break to occur.</param> /// <returns>An array of polyline segments, or null on error.</returns> public Polyline[] BreakAtAngles(double angle) { int count = Count; if (count == 0) { return null; } if (count <= 2) { return new Polyline[] { new Polyline(this) }; } bool[] frac = new bool[count]; for (int i = 1; i < (count - 1); i++) { Point3d p0 = this[i - 1]; Point3d p1 = this[i]; Point3d p2 = this[i + 1]; Vector3d t0 = p0 - p1; Vector3d t1 = p2 - p1; if (!t0.IsZero && !t1.IsZero) { frac[i] = (Vector3d.VectorAngle(t0, t1) <= angle); } } List<Polyline> segments = new List<Polyline>(); Polyline segment = new Polyline(); for (int i = 0; i < count; i++) { segment.Add(this[i]); if (i == (count - 1)) { segments.Add(segment); segment = null; break; } else { if (frac[i]) { segments.Add(segment); segment = new Polyline {this[i]}; } } } return segments.ToArray(); }
public static Response Grasshopper(NancyContext ctx) { // load grasshopper file var archive = new GH_Archive(); // TODO: stream to string var body = ctx.Request.Body.ToString(); string json = string.Empty; using (var reader = new StreamReader(ctx.Request.Body)) { json = reader.ReadToEnd(); } //GrasshopperInput input = Newtonsoft.Json.JsonConvert.DeserializeObject<GrasshopperInput>(json); //JsonSerializerSettings settings = new JsonSerializerSettings(); //settings.ContractResolver = new DictionaryAsArrayResolver(); Schema input = JsonConvert.DeserializeObject <Schema>(json); string grasshopperXml = string.Empty; if (input.Algo != null) { // If request contains markup byte[] byteArray = Convert.FromBase64String(input.Algo); grasshopperXml = System.Text.Encoding.UTF8.GetString(byteArray); } else { // If request contains pointer string pointer = input.Pointer; grasshopperXml = GetGhxFromPointer(pointer); } if (!archive.Deserialize_Xml(grasshopperXml)) { throw new Exception(); } var definition = new GH_Document(); if (!archive.ExtractObject(definition, "Definition")) { throw new Exception(); } // Set input params foreach (var obj in definition.Objects) { var group = obj as GH_Group; if (group == null) { continue; } if (group.NickName.Contains("RH_IN")) { // It is a RestHopper input group! GHTypeCodes code = (GHTypeCodes)Int32.Parse(group.NickName.Split(':')[1]); var param = group.Objects()[0]; //GH_Param<IGH_Goo> goo = obj as GH_Param<IGH_Goo>; // SetData foreach (Resthopper.IO.DataTree <ResthopperObject> tree in input.Values) { string paramname = tree.ParamName; if (group.NickName == paramname) { switch (code) { case GHTypeCodes.Boolean: //PopulateParam<GH_Boolean>(goo, tree); Param_Boolean boolParam = param as Param_Boolean; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Boolean> objectList = new List <GH_Boolean>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; bool boolean = JsonConvert.DeserializeObject <bool>(restobj.Data); GH_Boolean data = new GH_Boolean(boolean); boolParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Point: //PopulateParam<GH_Point>(goo, tree); Param_Point ptParam = param as Param_Point; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Point> objectList = new List <GH_Point>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Point3d rPt = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data); GH_Point data = new GH_Point(rPt); ptParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Vector: //PopulateParam<GH_Vector>(goo, tree); Param_Vector vectorParam = param as Param_Vector; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Vector> objectList = new List <GH_Vector>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Vector3d rhVector = JsonConvert.DeserializeObject <Rhino.Geometry.Vector3d>(restobj.Data); GH_Vector data = new GH_Vector(rhVector); vectorParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Integer: //PopulateParam<GH_Integer>(goo, tree); Param_Integer integerParam = param as Param_Integer; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Integer> objectList = new List <GH_Integer>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; int rhinoInt = JsonConvert.DeserializeObject <int>(restobj.Data); GH_Integer data = new GH_Integer(rhinoInt); integerParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Number: //PopulateParam<GH_Number>(goo, tree); Param_Number numberParam = param as Param_Number; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Number> objectList = new List <GH_Number>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); numberParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Text: //PopulateParam<GH_String>(goo, tree); Param_String stringParam = param as Param_String; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_String> objectList = new List <GH_String>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = JsonConvert.DeserializeObject <string>(restobj.Data); GH_String data = new GH_String(rhString); stringParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Line: //PopulateParam<GH_Line>(goo, tree); Param_Line lineParam = param as Param_Line; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Line> objectList = new List <GH_Line>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Line rhLine = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data); GH_Line data = new GH_Line(rhLine); lineParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Curve: //PopulateParam<GH_Curve>(goo, tree); Param_Curve curveParam = param as Param_Curve; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Curve> objectList = new List <GH_Curve>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; GH_Curve ghCurve; try { Rhino.Geometry.Polyline data = JsonConvert.DeserializeObject <Rhino.Geometry.Polyline>(restobj.Data); Rhino.Geometry.Curve c = new Rhino.Geometry.PolylineCurve(data); ghCurve = new GH_Curve(c); } catch { Rhino.Geometry.NurbsCurve data = JsonConvert.DeserializeObject <Rhino.Geometry.NurbsCurve>(restobj.Data); Rhino.Geometry.Curve c = new Rhino.Geometry.NurbsCurve(data); ghCurve = new GH_Curve(c); } curveParam.AddVolatileData(path, i, ghCurve); } } break; case GHTypeCodes.Circle: //PopulateParam<GH_Circle>(goo, tree); Param_Circle circleParam = param as Param_Circle; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Circle> objectList = new List <GH_Circle>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Circle rhCircle = JsonConvert.DeserializeObject <Rhino.Geometry.Circle>(restobj.Data); GH_Circle data = new GH_Circle(rhCircle); circleParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.PLane: //PopulateParam<GH_Plane>(goo, tree); Param_Plane planeParam = param as Param_Plane; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Plane> objectList = new List <GH_Plane>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Plane rhPlane = JsonConvert.DeserializeObject <Rhino.Geometry.Plane>(restobj.Data); GH_Plane data = new GH_Plane(rhPlane); planeParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Rectangle: //PopulateParam<GH_Rectangle>(goo, tree); Param_Rectangle rectangleParam = param as Param_Rectangle; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Rectangle> objectList = new List <GH_Rectangle>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Rectangle3d rhRectangle = JsonConvert.DeserializeObject <Rhino.Geometry.Rectangle3d>(restobj.Data); GH_Rectangle data = new GH_Rectangle(rhRectangle); rectangleParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Box: //PopulateParam<GH_Box>(goo, tree); Param_Box boxParam = param as Param_Box; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Box> objectList = new List <GH_Box>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Box rhBox = JsonConvert.DeserializeObject <Rhino.Geometry.Box>(restobj.Data); GH_Box data = new GH_Box(rhBox); boxParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Surface: //PopulateParam<GH_Surface>(goo, tree); Param_Surface surfaceParam = param as Param_Surface; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Surface> objectList = new List <GH_Surface>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Surface rhSurface = JsonConvert.DeserializeObject <Rhino.Geometry.Surface>(restobj.Data); GH_Surface data = new GH_Surface(rhSurface); surfaceParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Brep: //PopulateParam<GH_Brep>(goo, tree); Param_Brep brepParam = param as Param_Brep; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Brep> objectList = new List <GH_Brep>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Brep rhBrep = JsonConvert.DeserializeObject <Rhino.Geometry.Brep>(restobj.Data); GH_Brep data = new GH_Brep(rhBrep); brepParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Mesh: //PopulateParam<GH_Mesh>(goo, tree); Param_Mesh meshParam = param as Param_Mesh; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Mesh> objectList = new List <GH_Mesh>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Mesh rhMesh = JsonConvert.DeserializeObject <Rhino.Geometry.Mesh>(restobj.Data); GH_Mesh data = new GH_Mesh(rhMesh); meshParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Slider: //PopulateParam<GH_Number>(goo, tree); GH_NumberSlider sliderParam = param as GH_NumberSlider; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Number> objectList = new List <GH_Number>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); sliderParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.BooleanToggle: //PopulateParam<GH_Boolean>(goo, tree); GH_BooleanToggle toggleParam = param as GH_BooleanToggle; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Boolean> objectList = new List <GH_Boolean>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; bool rhBoolean = JsonConvert.DeserializeObject <bool>(restobj.Data); GH_Boolean data = new GH_Boolean(rhBoolean); toggleParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Panel: //PopulateParam<GH_String>(goo, tree); GH_Panel panelParam = param as GH_Panel; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Panel> objectList = new List <GH_Panel>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = JsonConvert.DeserializeObject <string>(restobj.Data); GH_String data = new GH_String(rhString); panelParam.AddVolatileData(path, i, data); } } break; } } } } } Schema OutputSchema = new Schema(); OutputSchema.Algo = Utils.Base64Encode(string.Empty); // Parse output params foreach (var obj in definition.Objects) { var group = obj as GH_Group; if (group == null) { continue; } if (group.NickName.Contains("RH_OUT")) { // It is a RestHopper output group! GHTypeCodes code = (GHTypeCodes)Int32.Parse(group.NickName.Split(':')[1]); var param = group.Objects()[0] as IGH_Param; if (param == null) { continue; } try { param.CollectData(); param.ComputeData(); } catch (Exception) { param.Phase = GH_SolutionPhase.Failed; // TODO: throw something better throw; } // Get data Resthopper.IO.DataTree <ResthopperObject> OutputTree = new Resthopper.IO.DataTree <ResthopperObject>(); OutputTree.ParamName = group.NickName; var volatileData = param.VolatileData; for (int p = 0; p < volatileData.PathCount; p++) { List <ResthopperObject> ResthopperObjectList = new List <ResthopperObject>(); foreach (var goo in volatileData.get_Branch(p)) { if (goo == null) { continue; } else if (goo.GetType() == typeof(GH_Boolean)) { GH_Boolean ghValue = goo as GH_Boolean; bool rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <bool>(rhValue)); } else if (goo.GetType() == typeof(GH_Point)) { GH_Point ghValue = goo as GH_Point; Point3d rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Point3d>(rhValue)); } else if (goo.GetType() == typeof(GH_Vector)) { GH_Vector ghValue = goo as GH_Vector; Vector3d rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Vector3d>(rhValue)); } else if (goo.GetType() == typeof(GH_Integer)) { GH_Integer ghValue = goo as GH_Integer; int rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <int>(rhValue)); } else if (goo.GetType() == typeof(GH_Number)) { GH_Number ghValue = goo as GH_Number; double rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <double>(rhValue)); } else if (goo.GetType() == typeof(GH_String)) { GH_String ghValue = goo as GH_String; string rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <string>(rhValue)); } else if (goo.GetType() == typeof(GH_Line)) { GH_Line ghValue = goo as GH_Line; Line rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Line>(rhValue)); } else if (goo.GetType() == typeof(GH_Curve)) { GH_Curve ghValue = goo as GH_Curve; Curve rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Curve>(rhValue)); } else if (goo.GetType() == typeof(GH_Circle)) { GH_Circle ghValue = goo as GH_Circle; Circle rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Circle>(rhValue)); } else if (goo.GetType() == typeof(GH_Plane)) { GH_Plane ghValue = goo as GH_Plane; Plane rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Plane>(rhValue)); } else if (goo.GetType() == typeof(GH_Rectangle)) { GH_Rectangle ghValue = goo as GH_Rectangle; Rectangle3d rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Rectangle3d>(rhValue)); } else if (goo.GetType() == typeof(GH_Box)) { GH_Box ghValue = goo as GH_Box; Box rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Box>(rhValue)); } else if (goo.GetType() == typeof(GH_Surface)) { GH_Surface ghValue = goo as GH_Surface; Brep rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Brep>(rhValue)); } else if (goo.GetType() == typeof(GH_Brep)) { GH_Brep ghValue = goo as GH_Brep; Brep rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Brep>(rhValue)); } else if (goo.GetType() == typeof(GH_Mesh)) { GH_Mesh ghValue = goo as GH_Mesh; Mesh rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Mesh>(rhValue)); } } GhPath path = new GhPath(new int[] { p }); OutputTree.Add(path.ToString(), ResthopperObjectList); } OutputSchema.Values.Add(OutputTree); } } if (OutputSchema.Values.Count < 1) { throw new System.Exceptions.PayAttentionException("Looks like you've missed something..."); // TODO } string returnJson = JsonConvert.SerializeObject(OutputSchema); return(returnJson); }
/// <summary> /// Constructs a polyline out of a parameter subdomain in this curve. /// </summary> /// <param name="domain">The subdomain of the polyline. /// The integer part of the domain parameters indicate the index of the segment.</param> /// <returns>The polyline as defined by the subdomain, or null on failure.</returns> public Polyline Trim(Interval domain) { int count = Count; int N = count - 1; // Polyline parameters double t0 = domain.Min; double t1 = domain.Max; // Segment indices int si0 = (int)Math.Floor(t0); int si1 = (int)Math.Floor(t1); // Segment parameters double st0 = t0 - si0; double st1 = t1 - si1; if (st0 < 0.0) { st0 = 0.0; } if (st0 >= 1.0) { si0++; st0 = 0.0; } if (st1 < 0.0) { st1 = 0.0; } if (st1 >= 1.0) { si1++; st1 = 0.0; } // Limit to polyline domain. if (si0 < 0) { si0 = 0; st0 = 0.0; } if (si0 >= N) { si0 = N; st0 = 0.0; } if (si1 < 0) { si1 = 0; st1 = 0.0; } if (si1 >= N) { si1 = N; st1 = 0.0; } // Build trimmed polyline. Polyline rc = new Polyline {PointAt(t0)}; for (int i = si0 + 1; i <= si1; i++) { rc.Add(m_items[i]); } if (st1 > 0.0) { rc.Add(PointAt(t1)); } return rc; }
private void create3DViewPort(List <Mesh> meshes, List <PolylineCurve> polys, bool hasViewcube) { hVp3D = new HelixViewport3D(); //hVp3D = new HelixToolkit.Wpf.SharpDX.Viewport3DX(); //Settings hVp3D.ShowFrameRate = false; //hVp3D.ViewCubeOpacity = 0.1; hVp3D.ViewCubeTopText = "T"; hVp3D.ViewCubeBottomText = "B"; hVp3D.ViewCubeFrontText = "E"; hVp3D.ViewCubeRightText = "N"; hVp3D.ViewCubeLeftText = "S"; hVp3D.ViewCubeBackText = "W"; hVp3D.ViewCubeHeight = 40; hVp3D.ViewCubeWidth = 40; hVp3D.ShowViewCube = hasViewcube; DefaultLights lights = new DefaultLights(); hVp3D.Children.Add(lights); hVp3D.IsInertiaEnabled = true; hVp3D.ZoomExtentsWhenLoaded = true; List <ModelVisual3D> vis = new List <ModelVisual3D>(); for (int i = 0; i < meshes.Count; i++) { if (meshes[i] != null) { MeshGeometry3D wMesh = new MeshGeometry3D(); DiffuseMaterial material = new DiffuseMaterial(); Friends.ConvertRhinotoWpfMesh(meshes[i], wMesh, material); GeometryModel3D model = new GeometryModel3D(wMesh, material); model.BackMaterial = material; ModelVisual3D v = new ModelVisual3D(); v.Content = model; vis.Add(v); } } for (int i = 0; i < polys.Count; i++) { if (polys[i] != null) { LinesVisual3D line = new LinesVisual3D(); line.Color = Colors.Black; line.Thickness = 1; Rhino.Geometry.Polyline result = new Rhino.Geometry.Polyline(); polys[i].TryGetPolyline(out result); for (int j = 0; j < result.Count - 1; j++) { line.Points.Add(new Point3D(result[j].X, result[j].Y, result[j].Z)); line.Points.Add(new Point3D(result[j + 1].X, result[j + 1].Y, result[j + 1].Z)); } vis.Add(line); } } for (int i = 0; i < vis.Count; i++) { hVp3D.Children.Add(vis[i]); } //Add viewport to user control this.AddChild(hVp3D); /* * ContextMenu myMenu = new ContextMenu(); * * MenuItem item1 = new MenuItem(); * MenuItem item2 = new MenuItem(); * * item1.Header = "item1"; * //item1.Click += new RoutedEventHandler(item1_Click); * myMenu.Items.Add(item1); * * item2.Header = "item2"; * //item2.Click += new RoutedEventHandler(item2_Click); * myMenu.Items.Add(item2); * * //this.ContextMenu = myMenu; * //myMenu.IsOpen = true; * hVp3D.ContextMenu = myMenu; */ }
protected override void SolveInstance(IGH_DataAccess DA) { List<double> values = new List<double>(); if (DA.GetDataList(0, values)) { bool has_colors = false; List<Color> colors = new List<Color>(); has_colors = DA.GetDataList(1, colors); if ((has_colors) && (colors.Count != values.Count)) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "If you're going to pass in colors, please pass in a list of colors that is the same length as the list of values you gave me."); return; } Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1)); DA.GetData(2, ref plane); Interval ival_gr = new Interval(); //Interval ival_ga = new Interval(0, Math.PI * 2); DA.GetData(3, ref ival_gr); this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "You've set your inner or outer radius to 0. Invalid curves will result."); //Interval ival_va = new Interval(0, values.Sum()); double sum = values.Sum(); int segments_in_whole_circle = 36; Interval ival_angle = new Interval(0, 0); List<Grasshopper.Kernel.Types.GH_Curve> regions = new List<Grasshopper.Kernel.Types.GH_Curve>(); List<Color> colors_out = new List<Color>(); List<Mesh> meshes = new List<Mesh>(); for (int n = 0; n < values.Count; n++) { if (values[n] == 0) continue; ival_angle.T1 = ival_angle.T0 + (Math.PI * 2 / sum * values[n]); int cnt = Math.Max(4, (int)Math.Ceiling(segments_in_whole_circle * ival_angle.Length / Math.PI * 2)); Polyline pcrv = new Polyline(); pcrv.AddRange(FakeArc(plane, ival_gr.T0, ival_angle.T0, ival_angle.T1, cnt)); pcrv.AddRange(FakeArc(plane, ival_gr.T1, ival_angle.T1, ival_angle.T0, cnt)); pcrv.Add(pcrv[0]); Grasshopper.Kernel.Types.GH_Curve gh_curve = new Grasshopper.Kernel.Types.GH_Curve(); Grasshopper.Kernel.GH_Convert.ToGHCurve(pcrv, GH_Conversion.Both, ref gh_curve); regions.Add(gh_curve); colors_out.Add(colors[n]); Rhino.Geometry.Mesh mesh = new Mesh(); foreach (Point3d pt in FakeArc(plane, ival_gr.T0, ival_angle.T0, ival_angle.T1, cnt)) { mesh.Vertices.Add(pt); if (has_colors) mesh.VertexColors.Add(colors[n]); } foreach (Point3d pt in FakeArc(plane, ival_gr.T1, ival_angle.T0, ival_angle.T1, cnt)) { mesh.Vertices.Add(pt); if (has_colors) mesh.VertexColors.Add(colors[n]); } for (int i = 0; i < cnt - 1; i++) { mesh.Faces.AddFace(i, i + 1, i + cnt); mesh.Faces.AddFace(i + 1, i + cnt + 1, i + cnt); } mesh.Normals.ComputeNormals(); mesh.Compact(); meshes.Add(mesh); ival_angle.T0 = ival_angle.T1; } DA.SetDataList(0, regions); DA.SetDataList(1, meshes); DA.SetDataList(2, colors_out); } }
public Mesh Mesh2DMinimalBox(Mesh mesh) { List<Point3d> x = new List<Point3d>(); Rhino.Geometry.Collections.MeshTopologyVertexList vs = mesh.TopologyVertices; for (int i = 0; i < vs.Count; i++) { x.Add(new Point3d(vs[i])); } Grasshopper.Kernel.Geometry.Node2List list = new Grasshopper.Kernel.Geometry.Node2List(x); Polyline pl = Grasshopper.Kernel.Geometry.ConvexHull.Solver.ComputeHull(list); double t = double.MaxValue; Transform xform = new Transform(); for (int i = 0; i < pl.Count - 1; i++) { Vector3d Xaxis = pl[i + 1] - pl[i]; Vector3d Yaxis = Vector3d.CrossProduct(Xaxis, Vector3d.ZAxis); Plane p = new Plane(pl[i], Xaxis, Yaxis); Polyline pl2 = new Polyline(pl); pl2.Transform(Transform.PlaneToPlane(p, Plane.WorldXY)); Rhino.Geometry.BoundingBox box = pl2.BoundingBox; double area = (box.Max.X - box.Min.X) * (box.Max.Y - box.Min.Y); if (area < t) { t = area; xform = Transform.PlaneToPlane(p, Plane.WorldXY); } } mesh.Transform(xform); return mesh; }
public Polyline getPolyline(Point3d p) { Polyline L = new Polyline(); L.Add(p); L.Add(new Point3d(p.X - XEdge, p.Y, p.Z)); L.Add(new Point3d(p.X - XEdge, p.Y - YEdge, p.Z)); L.Add(new Point3d(p.X, p.Y - YEdge, p.Z)); L.Add(p); return L; }
protected override void SolveInstance(IGH_DataAccess DA) { List<DHr> hours = new List<DHr>(); String key_r = ""; String key_a = ""; if (DA.GetDataList(0, hours) && DA.GetData(1, ref key_r) && DA.GetData(2, ref key_a)) { Interval ival_r = new Interval(); Interval ival_a = new Interval(); float[] vals_r = new float[0]; float[] vals_a = new float[0]; if (!(DA.GetData(3, ref ival_r))) DHr.get_domain(key_r, hours.ToArray(), ref vals_r, ref ival_r); else { ival_r = new Interval(hours[0].val(key_r), hours[0].val(key_r)); vals_r = new float[hours.Count]; for (int h = 0; h < hours.Count; h++) { vals_r[h] = hours[h].val(key_r); if (vals_r[h] < ival_r.T0) ival_r.T0 = vals_r[h]; if (vals_r[h] > ival_r.T1) ival_r.T1 = vals_r[h]; } } DHr.get_domain(key_a, hours.ToArray(), ref vals_a, ref ival_a); DA.GetData(4, ref ival_a); Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1)); DA.GetData(5, ref plane); Interval ival_gr = new Interval(); Interval ival_ga = new Interval(0, Math.PI * 2); DA.GetData(6, ref ival_gr); Interval subdivs = new Interval(); DA.GetData(7, ref subdivs); int subdivs_r = (int)Math.Floor(subdivs.T0); int subdivs_a = (int)Math.Floor(subdivs.T1); List<Point3d> points = new List<Point3d>(); for (int h = 0; h < hours.Count; h++) { double radius = ival_gr.ParameterAt(ival_r.NormalizedParameterAt(vals_r[h])); double theta = ival_a.NormalizedParameterAt(vals_a[h]) * Math.PI * 2; Point3d gpt = PointByCylCoords(radius, theta); // a point in graph coordinates hours[h].pos = gpt; // the hour records the point in graph coordinates Point3d wpt = plane.PointAt(gpt.X, gpt.Y); points.Add(wpt); // adds this point in world coordinates } Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Curve> regions = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Curve>(); int segments_in_whole_circle = 36; //double step_r = ival_r.Length / subdivs_r; //double step_a = Math.PI*2 / subdivs_a; for (int r = 0; r < subdivs_r; r++) for (int a = 0; a < subdivs_a; a++) { Interval rad = new Interval(ival_gr.ParameterAt(r / (float)subdivs_r), ival_gr.ParameterAt((r + 1) / (float)subdivs_r)); Interval ang = new Interval(ival_ga.ParameterAt(a / (float)subdivs_a), ival_ga.ParameterAt((a + 1) / (float)subdivs_a)); int cnt = (int)Math.Ceiling(segments_in_whole_circle * ang.Length / Math.PI * 2); Polyline pcrv = new Polyline(); pcrv.AddRange(FakeArc(plane, rad.T0, ang.T0, ang.T1, cnt)); pcrv.AddRange(FakeArc(plane, rad.T1, ang.T1, ang.T0, cnt)); pcrv.Add(pcrv[0]); Grasshopper.Kernel.Types.GH_Curve gh_curve = new Grasshopper.Kernel.Types.GH_Curve(); Grasshopper.Kernel.GH_Convert.ToGHCurve(pcrv, GH_Conversion.Both, ref gh_curve); regions.Append(gh_curve, new Grasshopper.Kernel.Data.GH_Path(new int[] { r, a })); } DA.SetDataList(0, hours); DA.SetDataList(1, points); DA.SetDataTree(2, regions); } }
/// <summary> /// Constructs a new surface of revolution from a generatrix polyline and an axis. /// </summary> /// <param name="revolutePolyline">A generatrix.</param> /// <param name="axisOfRevolution">An axis.</param> /// <returns>A new surface of revolution, or null if any of the inputs is invalid or on error.</returns> public static RevSurface Create(Polyline revolutePolyline, Line axisOfRevolution) { return Create(revolutePolyline, axisOfRevolution, 0, 2.0 * Math.PI); }
/// <summary> /// Generates curve bundling /// </summary> /// <param name="particleList"></param> /// <param name="particleSet">The empty datatree which will be populated with the new post bundled curve positions per path </param> /// <param name="crvList">The list of curves to bundle</param> /// <param name="thresh">The search distance for each point on each curve</param> /// <param name="ratio">The amount to move per iteration</param> /// <param name="weldCount">The number of points you would like to weld from the existing curve</param> /// <param name="rebuild">Rebuilds the curve pre simulation</param> /// <param name="ptCount">The number of points to rebuilt the curve to</param> /// <param name="colorMesh">The color mesh to use for input mapping</param> /// <param name="useColor">Use the color data or not</param> /// <returns>The list of bundled curves</returns> public List <Curve> Bundling(List <Point3d> particleList, DataTree <Point3d> particleSet, List <Curve> crvList, double thresh, double ratio, int weldCount, bool rebuild, int ptCount, Mesh colorMesh = null, bool useColor = false) { bool color_Override = false; double multiplier = new double(); //-----------SelfOrg--------------------- for (int j = 0; j < crvList.Count; j++) { //go through each curve GH_Path path = new GH_Path(j); List <Point3d> arrNewPos = new List <Point3d>(); if (rebuild || (!rebuild && crvList[j].Degree == 3)) { //rebuild curve crvList[j] = crvList[j].Rebuild(ptCount, 1, false); } Polyline pline = new Rhino.Geometry.Polyline(); bool conv = crvList[j].TryGetPolyline(out pline); //get polyline from curve if (!conv) { throw new Exception("Could not convert to a polyline, had to abort"); } List <Point3d> ptList = new List <Point3d>(); for (int z = 0; z < pline.SegmentCount + 1; z++) { ptList.Add(pline.PointAt((float)z)); } //-----------Weld Points Setup--------------------- List <Point3d> subList = new List <Point3d>(); subList = ptList.GetRange(weldCount, (ptList.Count) - ((weldCount) * 2)); List <Point3d> frontList = new List <Point3d>(); frontList = ptList.GetRange(0, weldCount); List <Point3d> endList = new List <Point3d>(); endList = ptList.GetRange((weldCount) + subList.Count, weldCount); //-----------Go through each point of the current curve--------------------- for (int k = 0; k < subList.Count; k++) { //-----------Color--------------------- if (useColor) { multiplier = Utilities.ColorUtility.GetHueSatLum(subList[k], colorMesh).L; if (multiplier == 0) { color_Override = true; } else { color_Override = false; multiplier *= thresh; } } else { color_Override = false; multiplier = thresh; } if (!color_Override) { List <Point3d> arrCrvPts = new List <Point3d>(); //-----------Go through each other curve and get the closest point on each curve--------------------- for (int m = 0; m < crvList.Count; m++) { if (j != m) { double tVal = new double(); crvList[m].ClosestPoint(subList[k], out tVal, thresh); arrCrvPts.Add(crvList[m].PointAt(tVal)); } } Point3d newcrvPt = arrCrvPts[Rhino.Collections.Point3dList.ClosestIndexInList(arrCrvPts, subList[k])]; //get the closest point of the closest points from each curve arrCrvPts.Clear(); double dist = newcrvPt.DistanceTo(subList[k]); if (dist < multiplier) { Vector3d subVec = Rhino.Geometry.Vector3d.Subtract(new Vector3d(newcrvPt), new Vector3d(subList[k])); Vector3d newVec = Rhino.Geometry.Vector3d.Multiply(subVec, ratio); arrNewPos.Add(Rhino.Geometry.Point3d.Add(newVec, subList[k])); } else { arrNewPos.Add(subList[k]); } } else { arrNewPos.Add(subList[k]); } } //-----------Re insert the og weld point positions and create the new curve--------------------- arrNewPos.InsertRange(0, frontList); arrNewPos.InsertRange(arrNewPos.Count, endList); crvList[j] = Curve.CreateInterpolatedCurve(arrNewPos, 1); particleSet.AddRange(arrNewPos, path); particleList.AddRange(arrNewPos); arrNewPos.Clear(); ptList.Clear(); subList.Clear(); frontList.Clear(); endList.Clear(); } return(crvList); }
/// <summary> /// Constructs a new surface of revolution from a generatrix polyline and an axis. /// <para>This overload accepts a slice start and end angles.</para> /// </summary> /// <param name="revolutePolyline">A generatrix.</param> /// <param name="axisOfRevolution">An axis.</param> /// <param name="startAngleRadians">An angle in radias for the start.</param> /// <param name="endAngleRadians">An angle in radias for the end.</param> /// <returns>A new surface of revolution, or null if any of the inputs is invalid or on error.</returns> public static RevSurface Create(Polyline revolutePolyline, Line axisOfRevolution, double startAngleRadians, double endAngleRadians) { using (PolylineCurve plc = new PolylineCurve(revolutePolyline)) { return Create(plc, axisOfRevolution, startAngleRadians, endAngleRadians); } }
public void SetInputs(List <DataTree <ResthopperObject> > values) { foreach (var tree in values) { if (!_input.TryGetValue(tree.ParamName, out var inputGroup)) { continue; } if (inputGroup.AlreadySet(tree)) { Console.WriteLine("Skipping input tree... same input"); continue; } inputGroup.CacheTree(tree); inputGroup.Param.VolatileData.Clear(); inputGroup.Param.ExpireSolution(true); if (inputGroup.Param is Param_Point) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Point3d rPt = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data); GH_Point data = new GH_Point(rPt); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Vector) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Vector3d rhVector = JsonConvert.DeserializeObject <Rhino.Geometry.Vector3d>(restobj.Data); GH_Vector data = new GH_Vector(rhVector); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Integer) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; int rhinoInt = JsonConvert.DeserializeObject <int>(restobj.Data); GH_Integer data = new GH_Integer(rhinoInt); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Number) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_String) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = restobj.Data; GH_String data = new GH_String(rhString); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Line) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Line rhLine = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data); GH_Line data = new GH_Line(rhLine); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Curve) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; GH_Curve ghCurve; try { Rhino.Geometry.Polyline data = JsonConvert.DeserializeObject <Rhino.Geometry.Polyline>(restobj.Data); Rhino.Geometry.Curve c = new Rhino.Geometry.PolylineCurve(data); ghCurve = new GH_Curve(c); } catch { var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(restobj.Data); var c = (Rhino.Geometry.Curve)Rhino.Runtime.CommonObject.FromJSON(dict); ghCurve = new GH_Curve(c); } inputGroup.Param.AddVolatileData(path, i, ghCurve); } } continue; } if (inputGroup.Param is Param_Circle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Circle rhCircle = JsonConvert.DeserializeObject <Rhino.Geometry.Circle>(restobj.Data); GH_Circle data = new GH_Circle(rhCircle); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Plane) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Plane rhPlane = JsonConvert.DeserializeObject <Rhino.Geometry.Plane>(restobj.Data); GH_Plane data = new GH_Plane(rhPlane); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Rectangle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Rectangle3d rhRectangle = JsonConvert.DeserializeObject <Rhino.Geometry.Rectangle3d>(restobj.Data); GH_Rectangle data = new GH_Rectangle(rhRectangle); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Box) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Box rhBox = JsonConvert.DeserializeObject <Rhino.Geometry.Box>(restobj.Data); GH_Box data = new GH_Box(rhBox); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Surface) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Surface rhSurface = JsonConvert.DeserializeObject <Rhino.Geometry.Surface>(restobj.Data); GH_Surface data = new GH_Surface(rhSurface); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Brep) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Brep rhBrep = JsonConvert.DeserializeObject <Rhino.Geometry.Brep>(restobj.Data); GH_Brep data = new GH_Brep(rhBrep); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Mesh) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Mesh rhMesh = JsonConvert.DeserializeObject <Rhino.Geometry.Mesh>(restobj.Data); GH_Mesh data = new GH_Mesh(rhMesh); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is GH_NumberSlider) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Boolean || inputGroup.Param is GH_BooleanToggle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; bool boolean = JsonConvert.DeserializeObject <bool>(restobj.Data); GH_Boolean data = new GH_Boolean(boolean); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is GH_Panel) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = JsonConvert.DeserializeObject <string>(restobj.Data); GH_String data = new GH_String(rhString); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } } }
/// <summary> /// Creates a simple viewport without helix /// </summary> /// <param name="chromo"></param> /// <param name="owner"></param> public ViewportBasic(Chromosome chromo, BiomorpherWindow owner) { InitializeComponent(); Owner = owner; thisDesign = chromo; this.ToolTip = "double click to display in main viewport"; myViewport = new HelixViewport3D(); myViewport.ZoomExtentsWhenLoaded = true; myViewport.ShowViewCube = false; DefaultLights lights = new DefaultLights(); myViewport.Children.Add(lights); List <Mesh> rMesh = thisDesign.phenoMesh; List <PolylineCurve> polys = thisDesign.phenoPoly; List <ModelVisual3D> vis = new List <ModelVisual3D>(); for (int i = 0; i < rMesh.Count; i++) { if (rMesh[i] != null) { MeshGeometry3D wMesh = new MeshGeometry3D(); DiffuseMaterial material = new DiffuseMaterial(); Friends.ConvertRhinotoWpfMesh(rMesh[i], wMesh, material); GeometryModel3D model = new GeometryModel3D(wMesh, material); model.BackMaterial = material; // DirectionalLight myLight = new DirectionalLight(Colors.White, new Vector3D(-0.5, -1, -1)); Model3DGroup modelGroup = new Model3DGroup(); modelGroup.Children.Add(model); //modelGroup.Children.Add(myLight); ModelVisual3D v = new ModelVisual3D(); v.Content = modelGroup; vis.Add(v); } } for (int i = 0; i < polys.Count; i++) { if (polys[i] != null) { LinesVisual3D line = new LinesVisual3D(); line.Color = Colors.Black; line.Thickness = 1; Rhino.Geometry.Polyline result = new Rhino.Geometry.Polyline(); polys[i].TryGetPolyline(out result); for (int j = 0; j < result.Count - 1; j++) { line.Points.Add(new Point3D(result[j].X, result[j].Y, result[j].Z)); line.Points.Add(new Point3D(result[j + 1].X, result[j + 1].Y, result[j + 1].Z)); } vis.Add(line); } } for (int i = 0; i < vis.Count; i++) { myViewport.Children.Add(vis[i]); } myViewport.IsEnabled = false; //Add viewport to user control this.AddChild(myViewport); }
/// <summary> /// Several types of Curve can have the form of a polyline /// including a degree 1 NurbsCurve, a PolylineCurve, /// and a PolyCurve all of whose segments are some form of /// polyline. IsPolyline tests a curve to see if it can be /// represented as a polyline. /// </summary> /// <param name="polyline"> /// If true is returned, then the polyline form is returned here. /// </param> /// <returns>true if this curve can be represented as a polyline; otherwise, false.</returns> public bool TryGetPolyline(out Polyline polyline) { polyline = null; SimpleArrayPoint3d outputPts = new SimpleArrayPoint3d(); int pointCount = 0; IntPtr pCurve = ConstPointer(); IntPtr outputPointsPointer = outputPts.NonConstPointer(); UnsafeNativeMethods.ON_Curve_IsPolyline2(pCurve, outputPointsPointer, ref pointCount, IntPtr.Zero); if (pointCount > 0) { polyline = Polyline.PolyLineFromNativeArray(outputPts); } outputPts.Dispose(); return (pointCount != 0); }
public Mesh MeshPipe(Line l, double t) { Mesh mesh = new Mesh(); List<Point3d> ls = new List<Point3d>(); ls.Add(new Point3d(1, 0, 0)); ls.Add(new Point3d(0.707, 0.707, 0)); ls.Add(new Point3d(0, 1, 0)); ls.Add(new Point3d(-0.707, 0.707, 0)); ls.Add(new Point3d(-1, 0, 0)); ls.Add(new Point3d(-0.707, -0.707, 0)); ls.Add(new Point3d(0, -1, 0)); ls.Add(new Point3d(0.707, -0.707, 0)); Polyline l1 = new Polyline(ls); Polyline l2 = new Polyline(ls); l1.Transform(Transform.Scale(new Point3d(0, 0, 0), t)); l2.Transform(Transform.Scale(new Point3d(0, 0, 0), t)); Vector3d v = l.To - l.From; l1.Transform(Transform.PlaneToPlane(Plane.WorldXY, new Plane(l.From, v))); l2.Transform(Transform.PlaneToPlane(Plane.WorldXY, new Plane(l.To, v))); mesh.Append(MeshLoft(l1, l2, true, false)); return mesh; }
public Polyline MinimalBox2D(List<Point3d> x) { Grasshopper.Kernel.Geometry.Node2List list = new Grasshopper.Kernel.Geometry.Node2List(x); Polyline pl = Grasshopper.Kernel.Geometry.ConvexHull.Solver.ComputeHull(list); // List<Polyline> boxes = new List<Polyline>(); Polyline output = new Polyline(); double t = double.MaxValue; for(int i = 0;i < pl.Count - 1;i++){ Vector3d Xaxis = pl[i + 1] - pl[i]; Vector3d Yaxis = Vector3d.CrossProduct(Xaxis, Vector3d.ZAxis); Plane p = new Plane(pl[i], Xaxis, Yaxis); Polyline pl2 = new Polyline(pl); pl2.Transform(Transform.PlaneToPlane(p, Plane.WorldXY)); Rhino.Geometry.BoundingBox box = pl2.BoundingBox; Polyline pl3 = new Polyline(); pl3.Add(box.Corner(false, false, false)); pl3.Add(box.Corner(false, true, false)); pl3.Add(box.Corner(true, true, false)); pl3.Add(box.Corner(true, false, false)); pl3.Add(box.Corner(false, false, false)); double area = pl3[1].DistanceTo(pl3[0]) * pl3[1].DistanceTo(pl3[2]); if(area < t){t = area; pl3.Transform(Transform.PlaneToPlane(Plane.WorldXY, p));output = pl3;} // boxes.Add(pl3); } return output; }
/***************************************************/ public static void RenderRhinoWires(RHG.Polyline polyline, Rhino.Display.DisplayPipeline pipeline, Color bhColour, int thickness) { pipeline.DrawPolyline(polyline, bhColour, thickness); }