Пример #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<DHr> hours = new List<DHr>();
            List<String> keys = new List<string>();
            if (DA.GetDataList(0, hours) && DA.GetDataList(1, keys)) {
                if ((hours[0].is_surrogate) && ((hours.Count != 1) && (hours.Count != 12) && (hours.Count != 52) && (hours.Count != 365))) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "This component can only plot unmasked surrogate hours for yearly, monthly, weekly, and daily statistics"); }

                Interval ival_y = new Interval();
                bool calc_ival_y = false;
                if (!(DA.GetData(2, ref ival_y))) {
                    ival_y.T0 = hours[0].val(keys[0]);
                    ival_y.T1 = hours[0].val(keys[0]);
                    calc_ival_y = true;
                }
                Dictionary<string, float[]> val_dict = new Dictionary<string, float[]>();
                List<Interval> val_ranges = new List<Interval>();
                foreach (string key in keys) {
                    Interval ival = new Interval();
                    float[] vals = new float[0];
                    DHr.get_domain(key, hours.ToArray(), ref vals, ref ival);
                    vals = new float[hours.Count];
                    for (int h = 0; h < hours.Count; h++) vals[h] = hours[h].val(key);
                    val_dict.Add(key, vals);
                    val_ranges.Add(ival);
                }

                bool force_start_at_zero = true;

                int stack_dir = StackDirection(val_ranges[0]);
                if (stack_dir==0) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The first key returned nothing but zero values.  I can't deal!");
                foreach (Interval ival in val_ranges) {
                    if (StackDirection(ival) != stack_dir) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "A stacked graph can only handle all negative or all positive numbers.");
                    if (calc_ival_y) {
                        if (stack_dir < 1) {
                            if (ival.T1 > ival_y.T0) ival_y.T0 = ival.T1;
                            if (ival.T0 < ival_y.T1) ival_y.T1 = ival.T0;
                        } else {
                            if (ival.T0 < ival_y.T0) ival_y.T0 = ival.T0;
                            if (ival.T1 > ival_y.T1) ival_y.T1 = ival.T1;
                        }
                    }
                }

                if (force_start_at_zero && calc_ival_y) ival_y.T0 = 0;

                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Interval> intervalTreeOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Interval>();
                intervalTreeOut.Append(new Grasshopper.Kernel.Types.GH_Interval(ival_y),new Grasshopper.Kernel.Data.GH_Path(0));
                foreach (Interval ival in val_ranges) intervalTreeOut.Append(new Grasshopper.Kernel.Types.GH_Interval(ival), new Grasshopper.Kernel.Data.GH_Path(1));

                Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1));
                DA.GetData(3, ref plane);

                Grasshopper.Kernel.Types.UVInterval ival2d = new Grasshopper.Kernel.Types.UVInterval();
                if (!DA.GetData(4, ref ival2d)) {
                    ival2d.U0 = 0.0;
                    ival2d.U1 = 12.0;
                    ival2d.V0 = 0.0;
                    ival2d.V1 = 1.0;
                }

                double barWidth = 1.0;
                DA.GetData(5, ref barWidth);

                Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeOut = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Point> pointTreeOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Point>();
                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Rectangle> rectTreeOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Rectangle>();
                List<Point3d> basepoints = new List<Point3d>();
                for (int h = 0; h < hours.Count; h++) {
                    Point3d gpt = GraphPoint(hours[h].hr, 0.0f, plane, ival_y, ival2d);
                    Point3d wpt = plane.PointAt(gpt.X, 0.0);
                    basepoints.Add(wpt);
                }

                for (int k = 0; k < keys.Count; k++) {
                    Grasshopper.Kernel.Data.GH_Path key_path = new Grasshopper.Kernel.Data.GH_Path(k);
                    List<Point3d> points = new List<Point3d>();
                    List<Rectangle3d> rects = new List<Rectangle3d>();

                    for (int h = 0; h < hours.Count; h++) {
                        float val = val_dict[keys[k]][h];
                        for (int kk = 0; kk < k; kk++) val += val_dict[keys[kk]][h]; // add in all previous values
                        Point3d gpt = GraphPoint(hours[h].hr, val, plane, ival_y, ival2d); // returns a point in graph coordinates

                        hours[h].pos = gpt; // the hour records the point in graph coordinates
                        hourTreeOut.Append(new DHr(hours[h]), key_path);

                        Point3d wpt = plane.PointAt(gpt.X, gpt.Y);
                        points.Add(wpt); // adds this point in world coordinates

                        Interval ival_gx; // interval of horz space occupied by this hour in graphic units
                        Interval ival_gy = new Interval(ival2d.V0, gpt.Y); // interval of vertical space occupied by this hour in graphic units
                        if (!hours[h].is_surrogate) {
                            double delta_x2 = (Math.Abs(ival2d.U.Length) / 8760 / 2.0);
                            ival_gx = new Interval(gpt.X - delta_x2, gpt.X + delta_x2); // interval of horz space occupied by this hour in graphic units
                        } else {

                            // if we've been passed surrogate hours, the spacing between bars may not be consistant
                            // we assume we've been given an hour at the start of the range represented
                            double ival_gx_0 = gpt.X;
                            double ival_gx_1;
                            if (h < hours.Count - 1) {
                                Point3d pt_next = GraphPoint(hours[h + 1].hr, val_dict[keys[k]][h + 1], plane, ival_y, ival2d);
                                ival_gx_1 = gpt.X + (pt_next.X - gpt.X) * barWidth;
                            } else { ival_gx_1 = gpt.X + (ival2d.U1 - gpt.X) * barWidth; }
                            ival_gx = new Interval(ival_gx_0, ival_gx_1);
                            if (hours.Count == 1) ival_gx = ival2d.U;

                        }
                        Rectangle3d rect = new Rectangle3d(plane, ival_gx, ival_gy);
                        rects.Add(rect);
                    }

                    List<Grasshopper.Kernel.Types.GH_Point> gh_points = new List<Grasshopper.Kernel.Types.GH_Point>();
                    foreach (Point3d pt in points) gh_points.Add(new Grasshopper.Kernel.Types.GH_Point(pt));
                    pointTreeOut.AppendRange(gh_points, key_path);

                    List<Grasshopper.Kernel.Types.GH_Rectangle> gh_rects = new List<Grasshopper.Kernel.Types.GH_Rectangle>();
                    foreach (Rectangle3d rec in rects) gh_rects.Add(new Grasshopper.Kernel.Types.GH_Rectangle(rec));
                    rectTreeOut.AppendRange(gh_rects, key_path);

                }

                DA.SetDataTree(0, hourTreeOut);
                DA.SetDataTree(1, intervalTreeOut);
                DA.SetDataTree(2, pointTreeOut);
                DA.SetDataList(3, basepoints);
                DA.SetDataTree(4, rectTreeOut);

            }
        }
Пример #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeIn = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
            String key = "";
            if (DA.GetDataTree(0, out hourTreeIn) && DA.GetData(1, ref key)) {

                Interval ival_y = new Interval();
                float[] garbage = new float[0];
                if (!(DA.GetData(2, ref ival_y))) DHr.get_domain(key, hourTreeIn.ToArray(), ref garbage, ref ival_y); // vals are no good here, we would need a tree of values

                Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1));
                DA.GetData(3, ref plane);

                Grasshopper.Kernel.Types.UVInterval ival2d = new Grasshopper.Kernel.Types.UVInterval();
                if (!DA.GetData(4, ref ival2d)) {
                    ival2d.U0 = 0.0;
                    ival2d.U1 = 12.0;
                    ival2d.V0 = 0.0;
                    ival2d.V1 = 1.0;
                }

                double barWidth = 1.0;
                DA.GetData(5, ref barWidth);

                Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeOut = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Point> points = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Point>();
                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Rectangle> rects = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Rectangle>();

                double ival2d_u_delta = ival2d.U.Length / hourTreeIn.Branches.Count;

                for (int b = 0; b < hourTreeIn.Branches.Count; b++) {
                    List<DHr> hours = hourTreeIn.Branches[b];
                    Grasshopper.Kernel.Data.GH_Path path = new Grasshopper.Kernel.Data.GH_Path(b);
                    hourTreeOut.EnsurePath(path);
                    points.EnsurePath(path);
                    rects.EnsurePath(path);

                    Grasshopper.Kernel.Types.UVInterval ival2d_sub = new Grasshopper.Kernel.Types.UVInterval(new Interval(b * ival2d_u_delta, (b + 1) * ival2d_u_delta), ival2d.V);
                    double t0_sub = ival2d_sub.U.Mid - (ival2d_sub.U.Mid - ival2d_sub.U.T0) * barWidth;
                    double t1_sub = ival2d_sub.U.Mid + (ival2d_sub.U.T1 - ival2d_sub.U.Mid) * barWidth;
                    ival2d_sub.U = new Interval(t0_sub, t1_sub);

                    for (int h = 0; h < hours.Count; h++) {
                        Point3d gpt = GraphPoint(hours[h].hr % 24, hours[h].val(key), plane, ival_y, ival2d_sub); // returns a point in graph coordinates
                        hours[h].pos = gpt; // the hour records the point in graph coordinates
                        hourTreeOut.Append(hours[h], path);

                        Point3d wpt = plane.PointAt(gpt.X, gpt.Y);
                        points.Append(new Grasshopper.Kernel.Types.GH_Point(wpt), path);  // adds this point in world coordinates

                        double delta_x2 = (Math.Abs(ival2d_sub.U.Length) / 24.0 / 2.0);
                        Interval ival_gx = new Interval(gpt.X - delta_x2, gpt.X + delta_x2); // interval of horz space occupied by this hour in graphic units
                        Interval ival_gy = new Interval(ival2d_sub.V0, gpt.Y); // interval of vertical space occupied by this hour in graphic units

                        Rectangle3d rect = new Rectangle3d(plane, ival_gx, ival_gy);
                        rects.Append(new Grasshopper.Kernel.Types.GH_Rectangle(rect), path);

                    }
                }

                DA.SetDataTree(0, hourTreeOut);
                DA.SetDataTree(1, points);
                DA.SetDataTree(2, rects);

            }
        }
Пример #3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeIn = new Grasshopper.Kernel.Data.GH_Structure<DHr>();

            if (DA.GetDataTree(0, out hourTreeIn)) {
                Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1));
                DA.GetData(1, ref plane);

                Grasshopper.Kernel.Types.UVInterval ival2d = new Grasshopper.Kernel.Types.UVInterval();
                if (!DA.GetData(2, ref ival2d)) {
                    ival2d.U0 = 0.0;
                    ival2d.U1 = 1.0;
                    ival2d.V0 = 0.0;
                    ival2d.V1 = 2.0;
                }
                if (ival2d.U.IsDecreasing) ival2d.U.Swap();
                if (ival2d.V.IsDecreasing) ival2d.V.Swap();

                double barWidthScale = 1.0;
                DA.GetData(3, ref barWidthScale);

                Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeOut = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Point> points = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Point>();
                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Rectangle> srects = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Rectangle>();
                List<Rectangle3d> rects = new List<Rectangle3d>();
                List<Mesh> meshes = new List<Mesh>();

                int i = 0;//keeps track of which branch we're on... note, this assumes we've been passed a list of lists and nothing 'deeper'
                int maxHourCount = hourTreeIn.Branches[0].Count;
                foreach (List<DHr> hourList in hourTreeIn.Branches) if (hourList.Count > maxHourCount) maxHourCount = hourList.Count;
                Rectangle3d brect = new Rectangle3d(plane, new Interval(0, ival2d.U1), new Interval(0, ival2d.V.ParameterAt((double)hourTreeIn.DataCount / maxHourCount)));
                DA.SetData(5, brect);

                double dx = ival2d.U.Length / hourTreeIn.Branches.Count * barWidthScale;
                double dy = ival2d.V.Length / maxHourCount;
                foreach (List<DHr> hourList in hourTreeIn.Branches) {
                    Grasshopper.Kernel.Data.GH_Path path = new Grasshopper.Kernel.Data.GH_Path(i);
                    hourTreeOut.EnsurePath(path);
                    points.EnsurePath(path);
                    srects.EnsurePath(path);

                    double x = ival2d.U.ParameterAt((i + 0.5) / hourTreeIn.Branches.Count);
                    for (int j = 0; j < hourList.Count; j++) {
                        DHr dhour = hourList[j];

                        double y = ival2d.V.ParameterAt((j + 0.5) / maxHourCount);
                        Point3d pt = plane.PointAt(x, y);
                        dhour.pos = new Point3d(x, y, 0);
                        points.Append(new Grasshopper.Kernel.Types.GH_Point(pt), path);
                        hourTreeOut.Append(dhour, path);

                        Plane pln = new Plane(plane);
                        pln.Origin = plane.PointAt(x - dx / 2, y - dy / 2);
                        Rectangle3d rct = new Rectangle3d(pln, dx, dy);
                        srects.Append(new Grasshopper.Kernel.Types.GH_Rectangle(rct), path);
                    }

                    // make meshes & big rectangles
                    if (hourList.Count > 0) {
                        Mesh mesh = new Mesh();
                        // add bottom pts
                        mesh.Vertices.Add(plane.PointAt(x - dx / 2, 0));
                        mesh.VertexColors.Add(hourList[0].color);
                        mesh.Vertices.Add(plane.PointAt(x + dx / 2, 0));
                        mesh.VertexColors.Add(hourList[0].color);

                        for (int j = 0; j < hourList.Count; j++) {
                            double y = ival2d.V.ParameterAt((j + 0.5) / maxHourCount);
                            mesh.Vertices.Add(plane.PointAt(x - dx / 2, y));
                            mesh.VertexColors.Add(hourList[j].color);
                            mesh.Vertices.Add(plane.PointAt(x + dx / 2, y));
                            mesh.VertexColors.Add(hourList[j].color);
                        }

                        // add top pts
                        double yy = ival2d.V.ParameterAt((float)hourList.Count / maxHourCount);
                        mesh.Vertices.Add(plane.PointAt(x - dx / 2, yy));
                        mesh.VertexColors.Add(hourList[hourList.Count - 1].color);
                        mesh.Vertices.Add(plane.PointAt(x + dx / 2, yy));
                        mesh.VertexColors.Add(hourList[hourList.Count - 1].color);

                        for (int n = 2; n < mesh.Vertices.Count; n = n + 2) mesh.Faces.AddFace(n - 2, n - 1, n + 1, n);
                        meshes.Add(mesh);

                        Plane pln = new Plane(plane);
                        pln.Origin = plane.PointAt(x - dx / 2, 0);
                        Rectangle3d rct = new Rectangle3d(pln, dx, yy);
                        rects.Add(rct);
                    }

                    i++;
                }

                DA.SetDataTree(0, hourTreeOut);
                DA.SetDataTree(1, points);
                DA.SetDataList(2, srects);
                DA.SetDataList(3, rects);
                DA.SetDataList(4, meshes);

            }
        }
Пример #4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<DHr> hours = new List<DHr>();

            if (DA.GetDataList(0, hours)) {

                Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1));
                DA.GetData(1, ref plane);

                Grasshopper.Kernel.Types.UVInterval ival2d = new Grasshopper.Kernel.Types.UVInterval();
                if (!DA.GetData(2, ref ival2d)) {
                    ival2d.U0 = 0.0;
                    ival2d.U1 = 12.0;
                    ival2d.V0 = 1.0;
                    ival2d.V1 = 0.0;
                } else {
                    // swap v-interval so that hours start at top left of defined area
                    ival2d.V.Swap();
                }

                List<Point3d> points = new List<Point3d>();
                List<Rectangle3d> rects = new List<Rectangle3d>();
                double delta_x = Math.Abs(ival2d.U.Length) / 365.0;
                double delta_y = Math.Abs(ival2d.V.Length) / 24.0;
                double delta_x2 = delta_x / 2.0;
                double delta_y2 = delta_y / 2.0;

                // only produce a mesh if given a full year worth of hours
                bool doMesh = false;
                Rhino.Geometry.Mesh mesh = new Mesh();
                if (hours.Count == 8760) doMesh = true;

                for (int h = 0; h < hours.Count; h++) {
                    //x = (math.floor(hr_out.hr/24)/365.0)
                    //y = ((hr_out.hr % 24)/24.0)
                    float x = (float)((ival2d.U.ParameterAt(Math.Floor(hours[h].hr / 24.0) / 365.0)) + delta_x2);
                    float y = (float)((ival2d.V.ParameterAt((hours[h].hr % 24) / 24.0)) + delta_y2);
                    Point3d pt = plane.PointAt(x, y, 0);
                    points.Add(pt);
                    hours[h].pos = new Point3d(x, y, 0);

                    if (doMesh) {
                        mesh.Vertices.Add(pt);
                        mesh.VertexColors.Add(hours[h].color);
                    }

                    Rectangle3d rect = new Rectangle3d(new Plane(new Point3d(pt.X - delta_x2, pt.Y - delta_y2, 0), new Vector3d(0, 0, 1)), delta_x, delta_y);
                    rects.Add(rect);
                }

                if (doMesh) {
                    for (int h = 0; h < 8760 - 24; h++) {
                        if (h % 24 != 0) mesh.Faces.AddFace(h, h - 1, h + 23, h + 24);
                    }
                    mesh.Normals.ComputeNormals();
                    mesh.Compact();
                }

                DA.SetDataList(0, hours);
                DA.SetDataList(1, points);
                DA.SetDataList(2, rects);
                DA.SetData(3, mesh);

            }
        }
Пример #5
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<DHr> hours = new List<DHr>();
            String key = "";
            if (DA.GetDataList(0, hours) && DA.GetData(1, ref key)) {
                if ((hours[0].is_surrogate) && ((hours.Count != 1) && (hours.Count != 12) && (hours.Count != 52) && (hours.Count != 365))) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "This component can only plot unmasked surrogate hours for yearly, monthly, weekly, and daily statistics"); }

                Interval ival_y = new Interval();
                float[] vals = new float[0];
                if (!(DA.GetData(2, ref ival_y))) DHr.get_domain(key, hours.ToArray(), ref vals, ref ival_y);
                else {
                    vals = new float[hours.Count];
                    for (int h = 0; h < hours.Count; h++) vals[h] = hours[h].val(key);
                }

                Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1));
                DA.GetData(3, ref plane);

                Grasshopper.Kernel.Types.UVInterval ival2d = new Grasshopper.Kernel.Types.UVInterval();
                if (!DA.GetData(4, ref ival2d)) {
                    ival2d.U0 = 0.0;
                    ival2d.U1 = 12.0;
                    ival2d.V0 = 0.0;
                    ival2d.V1 = 1.0;
                }

                double barWidth = 1.0;
                DA.GetData(5, ref barWidth);

                List<Point3d> points = new List<Point3d>();
                List<Rectangle3d> rects = new List<Rectangle3d>();
                //double delta_x = Math.Abs(ival2d.U.Length) / hours.Count;
                //double delta_x2 = delta_x / 2.0;

                for (int h = 0; h < hours.Count; h++) {
                    Point3d gpt = GraphPoint(hours[h].hr, vals[h], plane, ival_y, ival2d); // returns 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

                    Interval ival_gx; // interval of horz space occupied by this hour in graphic units
                    Interval ival_gy = new Interval(ival2d.V0, gpt.Y); // interval of vertical space occupied by this hour in graphic units
                    if (!hours[h].is_surrogate) {
                        double delta_x2 = (Math.Abs(ival2d.U.Length) / 8760 / 2.0);
                        ival_gx = new Interval(gpt.X - delta_x2, gpt.X + delta_x2); // interval of horz space occupied by this hour in graphic units
                    } else {
                        // if we've been passed surrogate hours, the spacing between bars may not be consistant
                        // we assume we've been given an hour at the start of the range represented
                        double ival_gx_0 = gpt.X;
                        //if (h > 0) {
                        //    Point3d pt_prev = GraphPoint(hours[h - 1].hr, vals[h - 1], plane, ival_y, ival2d);
                        //    ival_gx_0 = gpt.X - (gpt.X - pt_prev.X) * barWidth;
                        //} else { ival_gx_0 = gpt.X - (gpt.X - ival2d.U0) * barWidth; }
                        double ival_gx_1;
                        if (h < hours.Count - 1) {
                            Point3d pt_next = GraphPoint(hours[h + 1].hr, vals[h + 1], plane, ival_y, ival2d);
                            ival_gx_1 = gpt.X + (pt_next.X - gpt.X) * barWidth;
                        } else { ival_gx_1 = gpt.X + (ival2d.U1 - gpt.X) * barWidth; }
                        ival_gx = new Interval(ival_gx_0, ival_gx_1);
                        if (hours.Count == 1) ival_gx = ival2d.U;
                    }
                    Rectangle3d rect = new Rectangle3d(plane, ival_gx, ival_gy);
                    rects.Add(rect);
                }

                DA.SetDataList(0, hours);
                DA.SetDataList(1, points);
                DA.SetDataList(2, rects);
                //DA.SetData(3, mesh);

            }
        }
Пример #6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<DHr> hours = new List<DHr>();
            string alt_key = "solar_altitude";
            Interval alt_ival = new Interval(0, Math.PI / 2);
            string azm_key = "solar_azimuth";
            Interval azm_ival = new Interval(0, Math.PI * 2);
            bool cull_night = true;

            if (DA.GetDataList(0, hours)) {

                this.plot_type = PType.Invalid;
                String p_type_string = "";
                DA.GetData(4, ref p_type_string);
                p_type_string = p_type_string.ToLowerInvariant().Trim();
                if (p_type_string.Contains("stereo")) { this.plot_type = PType.Stereo; }
                if (p_type_string.Contains("ortho")) { this.plot_type = PType.Ortho; }
                if (this.plot_type == PType.Invalid) {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Plot type not recognized. Choose 'Ortho' or 'Stereo'.");
                    return;
                }

                Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1));
                DA.GetData(1, ref plane);

                Grasshopper.Kernel.Types.UVInterval ival2d = new Grasshopper.Kernel.Types.UVInterval();
                if (!DA.GetData(2, ref ival2d)) {
                    ival2d.U0 = 0.0;
                    ival2d.U1 = 1.0;
                    ival2d.V0 = 0.0;
                    ival2d.V1 = 1.0;
                }
                double radius_gr = 3.0;
                DA.GetData(3, ref radius_gr);

                DA.GetData(5, ref alt_key);
                DA.GetData(6, ref azm_key);
                DA.GetData(7, ref cull_night);

                List<Point3d> points = new List<Point3d>();

                Plane drawPlane = new Plane(plane);

                if (this.plot_type == PType.Ortho) DA.SetData(5, new Rectangle3d(drawPlane, ival2d.U, ival2d.V)); // set the trimming boundary
                if (this.plot_type == PType.Stereo)
                {
                    drawPlane.Origin = new Point3d(plane.Origin.X, plane.Origin.Y + ival2d.V.Mid, plane.Origin.Z);
                    drawPlane.Rotate(-Math.PI / 2, drawPlane.ZAxis);
                    ival2d.V0 = radius_gr; // sets the radius of stereographic plots
                    ival2d.V1 = 0.0;

                    Circle circ = new Circle(drawPlane, Math.Abs(ival2d.V.Length));
                    DA.SetData(5, circ); // set the trimming boundary
                }

                for (int h = 0; h < hours.Count; h++) {
                    double x = 0;
                    double y = 0;
                    switch (this.plot_type) {
                        case PType.Ortho:
                            x = ival2d.U.ParameterAt(azm_ival.NormalizedParameterAt(hours[h].val(azm_key)));
                            y = ival2d.V.ParameterAt(alt_ival.NormalizedParameterAt(hours[h].val(alt_key)));
                            break;

                        case PType.Stereo:
                            double radius = ival2d.V.ParameterAt(alt_ival.NormalizedParameterAt(hours[h].val(alt_key)));
                            double theta = -hours[h].val(azm_key); // reversed theta to ensure clockwise direction
                            x = radius * Math.Cos(theta);
                            y = radius * Math.Sin(theta);
                            break;
                    }
                    Point3d pt = drawPlane.PointAt(x, y);
                    points.Add(pt);
                    hours[h].pos = pt; // TODO: solar plots currently record the point in world space, switch to graph space
                }

                List<Polyline> plines = new List<Polyline>();
                List<Color> colors = new List<Color>();
                for (int h = 0; h < points.Count; h++)
                {
                    List<Point3d> pts = new List<Point3d>();
                    DHr prev_hr; if (h > 0) prev_hr = hours[h - 1]; else prev_hr = hours[hours.Count - 1];
                    DHr this_hr = hours[h];
                    DHr next_hr; if (h < hours.Count - 1) next_hr = hours[h + 1]; else next_hr = hours[0];

                    switch (this.plot_type) {
                        case PType.Ortho:
                            if ((this_hr.hr - 1 == prev_hr.hr) && (this_hr.pos_x > prev_hr.pos_x)) pts.Add(interp(this_hr.pos, prev_hr.pos, 0.5));
                            pts.Add(this_hr.pos);
                            if ((this_hr.hr + 1 == next_hr.hr) && (this_hr.pos_x < next_hr.pos_x)) pts.Add(interp(this_hr.pos, next_hr.pos, 0.5));
                            break;

                        case PType.Stereo:
                            pts.Add(interp(this_hr.pos, prev_hr.pos, 0.5));
                            pts.Add(this_hr.pos);
                            pts.Add(interp(this_hr.pos, next_hr.pos, 0.5));
                            break;
                    }

                    plines.Add(new Polyline(pts));
                    colors.Add(hours[h].color);
                }

                Mesh mesh = CreateColoredMesh(hours, points, plines, cull_night, alt_key);
                mesh.Compact();
                mesh.Weld(0.1);

                if (cull_night) {
                    List<DHr> day_hours = new List<DHr>();
                    List<Point3d> day_points = new List<Point3d>();
                    List<Polyline> day_plines = new List<Polyline>();

                    List<Color> day_colors = new List<Color>();
                    for (int h = 1; h < hours.Count - 1; h++)
                    {
                        if (hour_contains_day(hours, h, alt_key))
                        {
                            day_hours.Add(hours[h]);
                            day_points.Add(points[h]);
                            day_plines.Add(plines[h]);
                            day_colors.Add(colors[h]);
                        }
                    }
                    hours = day_hours;
                    points = day_points;
                    plines = day_plines;
                    colors = day_colors;

                    #region failed attempt to trim mesh
                    //trim mesh
                    /*
                    Plane trimPlane = new Plane(plane);
                    trimPlane.Rotate(Math.PI/2,plane.XAxis);
                    Mesh trimMesh = Mesh.CreateFromPlane(trimPlane, ival2d.U, new Interval(-0.1, 0.1), 10, 10);
                    //Mesh[] result = Mesh.CreateBooleanSplit(new Mesh[] { mesh }, new Mesh[] { trimMesh });
                    Mesh[] result = mesh.Split(trimPlane);
                    if (result.Length == 1) mesh = result[0];
                    else if (result.Length == 2) {
                        Point3d pt = plane.PointAt(0, 1);
                        Point3d p0 = result[0].ClosestPoint(pt);
                        Point3d p1 = result[1].ClosestPoint(pt);

                        if (p0.DistanceTo(pt) < p1.DistanceTo(pt)) mesh = result[0];
                        else mesh = result[1];
                    }
                     */

                    #endregion

                }

                DA.SetDataList(0, new List<DHr>(hours));
                DA.SetDataList(1, points);
                DA.SetDataList(2, plines);
                DA.SetDataList(3, colors);
                DA.SetData(4, mesh);
            }
        }
Пример #7
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<DHr> dhrs = new List<DHr>();
            string key_u = "";
            string key_v = "";
            Interval subdivs = new Interval();
            if ((DA.GetDataList(0, dhrs)) && (DA.GetData(1, ref key_u)) && (DA.GetData(2, ref key_v)) && (DA.GetData(4, ref subdivs)))
            {
                int subdivs_u = (int) Math.Floor(subdivs.T0);
                int subdivs_v = (int) Math.Floor(subdivs.T1);

                Grasshopper.Kernel.Types.UVInterval ival_overall = new Grasshopper.Kernel.Types.UVInterval();
                if (!DA.GetData(3, ref ival_overall)) {
                    // go thru the given hours and find the max and min value for the given key
                    Interval ival_temp_u = new Interval(MDHr.INVALID_VAL, MDHr.INVALID_VAL);
                    Interval ival_temp_v = new Interval(MDHr.INVALID_VAL, MDHr.INVALID_VAL);
                    foreach (DHr dhr in dhrs) {
                        float val_u = dhr.val(key_u);
                        float val_v = dhr.val(key_v);
                        if ((ival_temp_u.T0 == MDHr.INVALID_VAL) || (val_u < ival_temp_u.T0)) ival_temp_u.T0 = val_u;
                        if ((ival_temp_u.T1 == MDHr.INVALID_VAL) || (val_u > ival_temp_u.T1)) ival_temp_u.T1 = val_u;
                        if ((ival_temp_v.T0 == MDHr.INVALID_VAL) || (val_v < ival_temp_v.T0)) ival_temp_v.T0 = val_v;
                        if ((ival_temp_v.T1 == MDHr.INVALID_VAL) || (val_v > ival_temp_v.T1)) ival_temp_v.T1 = val_v;
                    }
                }

                bool cull_outliers = false;
                DA.GetData(5, ref cull_outliers);

                Grasshopper.Kernel.Data.GH_Structure<DHr> hrsOut = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Integer> freqOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Integer>();
                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Interval2D> ivalsOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Interval2D>();

                if (ival_overall.U.IsDecreasing) ival_overall.U.Swap();
                if (ival_overall.V.IsDecreasing) ival_overall.V.Swap();
                double delta_u = ival_overall.U.Length / subdivs_u;
                double delta_v = ival_overall.V.Length / subdivs_v;
                for (int u = 0; u < subdivs_u; u++) {
                    for (int v = 0; v < subdivs_v; v++) {
                        Grasshopper.Kernel.Data.GH_Path path = new Grasshopper.Kernel.Data.GH_Path(new int[] { u, v });
                        ivalsOut.EnsurePath(path);
                        hrsOut.EnsurePath(path);

                        Interval sub_u = new Interval(ival_overall.U.T0 + u * delta_u, ival_overall.U.T0 + ((u + 1) * delta_u));
                        Interval sub_v = new Interval(ival_overall.V.T0 + v * delta_v, ival_overall.V.T0 + ((v + 1) * delta_v));
                        Grasshopper.Kernel.Types.UVInterval sub_uv = new Grasshopper.Kernel.Types.UVInterval(sub_u, sub_v);
                        Grasshopper.Kernel.Types.GH_Interval2D i2d = new Grasshopper.Kernel.Types.GH_Interval2D();
                        i2d.Value = sub_uv;
                        ivalsOut.Append(i2d, path);
                    }
                }

                foreach (DHr dhr in dhrs) {
                    int[] address = new int[] { -1 , -1};
                    for (int u = 0; u < subdivs_u; u++)
                    {
                        Grasshopper.Kernel.Data.GH_Path path_u = new Grasshopper.Kernel.Data.GH_Path(new int[] { u, 0 });
                        Interval sub_u = ivalsOut.get_DataItem(path_u, 0).Value.U;
                        double val = dhr.val(key_u);
                        if ((sub_u.IncludesParameter(val)) || ((!cull_outliers) && (u == 0) && (val <= sub_u.Min)) || ((!cull_outliers) && (u == subdivs_u - 1) && (val >= sub_u.Max)))
                        {
                            address[0] = u;
                            break;
                        }
                    }

                    for (int v = 0; v < subdivs_v; v++)
                    {
                        Grasshopper.Kernel.Data.GH_Path path_v = new Grasshopper.Kernel.Data.GH_Path(new int[] { 0, v });
                        Interval sub_v = ivalsOut.get_DataItem(path_v, 0).Value.V;
                        double val = dhr.val(key_v);
                        if ((sub_v.IncludesParameter(val)) || ((!cull_outliers) && (v == 0) && (val <= sub_v.Min)) || ((!cull_outliers) && (v == subdivs_v - 1) && (val >= sub_v.Max)))
                        {
                            address[1] = v;
                            break;
                        }
                    }
                    if ((address[0] < 0) || (address[1] < 0))
                    {
                        if (!cull_outliers) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Crud. Could not place an outlier into any intervals.  What gives?!");
                    }
                    else
                    {
                        Grasshopper.Kernel.Data.GH_Path path = new Grasshopper.Kernel.Data.GH_Path(address);
                        hrsOut.Append(dhr, path);
                    }
                }

                foreach (Grasshopper.Kernel.Data.GH_Path path in hrsOut.Paths)
                {
                    int n = hrsOut.get_Branch(path).Count;
                    freqOut.Append(new Grasshopper.Kernel.Types.GH_Integer(n), path);
                }

                DA.SetDataTree(0, freqOut);
                DA.SetDataTree(1, ivalsOut);
                DA.SetDataTree(2, hrsOut);
            }
        }
Пример #8
0
 public static GH_Interval2D ToIO(this Grasshopper.Kernel.Types.UVInterval d)
 {
     return(new GH_Interval2D(d.U0, d.U1, d.V0, d.V1));
 }