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); } }
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); } }