Example #1
0
File: Eco.cs Project: tsvilans/tas
        public override bool Evaluate()
        {
            Glulam g = GlulamParam.Value as Glulam;

            bool is_ok_x = false, is_ok_y = false;

            Glulam gdup = g.Duplicate();

            gdup.Data.LamHeight = (double)LHParam.Value;
            gdup.Data.LamWidth  = (double)LWParam.Value;

            bool res = gdup.InKLimitsComponent(out is_ok_x, out is_ok_y);

            if (res)
            {
                return(res);
            }
            else
            {
                if (!LHParam.Locked && !LWParam.Locked)
                {
                    //GlulamData gdata = GlulamData.FromCurveLimits(g.Centreline, g.GetAllPlanes());
                    GlulamData gdata = GlulamData.Default;
                    LHParam.Value = gdata.LamHeight;
                    LWParam.Value = gdata.LamWidth;
                    return(true);
                }
                else
                {
                    // TODO: Propose new relaxed curve
                    return(false);
                }
            }
        }
Example #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Curve crv = null;

            if (!DA.GetData("Curve", ref crv))
            {
                return;
            }

            crv.Domain.MakeIncreasing();

            List <object> r_orientation = new List <object>();

            DA.GetDataList("Orientation", r_orientation);

            object r_data = null;

            DA.GetData("Data", ref r_data);

            CrossSectionOrientation orientation = ParseGlulamOrientation(r_orientation, crv);

            AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, orientation.ToString());

            GlulamData data = ParseGlulamData(r_data);

            AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, data.ToString());

            data.Samples = (int)Math.Ceiling(crv.GetLength() / GlulamData.DefaultSampleDistance);

            Glulam glulam = Glulam.CreateGlulam(crv, orientation, data);


            DA.SetData("Glulam", new GH_Glulam(glulam));
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Curve crv  = null;
            Brep  brep = null;
            //double lw = 0, lh = 0;
            double       w = 0, h = 0;
            int          samples = 0;
            List <Plane> planes  = new List <Plane>();

            if (!DA.GetData("Curve", ref crv))
            {
                return;
            }
            if (!DA.GetData("Brep", ref brep))
            {
                return;
            }

            //DA.GetData("LamWidth", ref lw);
            //DA.GetData("LamHeight", ref lh);
            DA.GetData("Width", ref w);
            DA.GetData("Height", ref h);
            DA.GetData("Samples", ref samples);
            samples = Math.Max(samples, 2);

            Plane[] frames = tas.Core.Util.Misc.FramesNormalToSurface(crv, brep);

            GlulamData data = null;

            if (calculate_data)
            {
                data = Lam.GlulamData.FromCurveLimits(crv, w, h, frames);
            }
            else
            {
                data = new Lam.GlulamData(1, 1, w, h, samples);
            }
            //data.LamHeight = lh > 0.001 ? lh : 20.0;
            //data.LamWidth = lw > 0.001 ? lw : 20.0;
            //data.NumHeight = h > 0 ? (int)Math.Ceiling(h / lh) : 4;
            //data.NumWidth = w > 0 ? (int)Math.Ceiling(w / lw) : 4;

            data.InterpolationType = GlulamData.Interpolation.HERMITE;
            Glulam blank = Glulam.CreateGlulam(crv, frames, data);

            //Lam.Glulam blank = Lam.Glulam.CreateGlulamNormalToSurface(crv, brep, 20, null);
            DA.SetData("Glulam", new GH_Glulam(blank));
        }
Example #4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            double lw = 0, lh = 0;
            int    nw = 0, nh = 0;

            int samples       = 0;
            int interpolation = 2;

            DA.GetData("LamW", ref lw);
            DA.GetData("LamH", ref lh);
            DA.GetData("NumW", ref nw);
            DA.GetData("NumH", ref nh);
            DA.GetData("Samples", ref samples);
            DA.GetData("Interpolation", ref interpolation);

            GlulamData data = new GlulamData(Math.Max(nw, 1), Math.Max(nh, 1), lw, lh, samples);

            data.InterpolationType = (GlulamData.Interpolation)interpolation;

            DA.SetData("GlulamData", new GH_GlulamData(data));
        }
Example #5
0
        public override bool Read(GH_IReader reader)
        {
            if (!reader.ItemExists("guide"))
            {
                Value = null;
                throw new Exception("Couldn't retrieve 'guide'.");
            }

            Curve guide = GH_Convert.ByteArrayToCommonObject <Curve>(reader.GetByteArray("guide"));

            if (guide == null)
            {
                throw new Exception("Failed to convert 'guide'.");
            }

            CrossSectionOrientation ori = GH_Glulam.ReadCrossSectionOrientation(reader);
            GlulamData data             = GH_GlulamData.ReadGlulamData(reader);

            Value = Glulam.CreateGlulam(guide, ori, data);

            return(base.Read(reader));
        }
Example #6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Curve crv = null;
            //double lw = 0, lh = 0;
            double       w = 0, h = 0;
            int          flags  = 0;
            List <Plane> planes = new List <Plane>();

            Plane[] plane_array = null;

            if (!DA.GetData("Curve", ref crv))
            {
                return;
            }

            //DA.GetData("LamWidth", ref lw);
            //DA.GetData("LamHeight", ref lh);
            DA.GetData("Width", ref w);
            DA.GetData("Height", ref h);
            //DA.GetData("Samples", ref samples);
            DA.GetData("Flags", ref flags);

            if (!DA.GetDataList("Frames", planes))
            {
                //Plane p;
                //crv.PerpendicularFrameAt(crv.Domain.Min, out p);
                //plane_array = new Plane[] { p };
            }
            else
            {
                plane_array = planes.ToArray();
            }

            /*
             * Lam.GlulamData data = new Lam.GlulamData();
             * data.LamHeight = lh > 0.1 ? lh : 20.0;
             * data.LamWidth = lw > 0.1 ? lw : 20.0;
             * data.NumHeight = h > 0 ? (int)Math.Ceiling(h / lh) : 4;
             * data.NumWidth = w > 0 ? (int)Math.Ceiling(w / lw) : 4;
             * data.Samples = samples > 1 ? samples : 2;
             */
            Lam.GlulamData data = null;
            data = new GlulamData(crv, w, h, plane_array, (int)Math.Ceiling(crv.GetLength() / GlulamData.DefaultSampleDistance));

            /*
             * if (calculate_data)
             *  data = Lam.GlulamData.FromCurveLimits(crv, w, h, plane_array);
             * else
             *  data = new Lam.GlulamData(1, 1, w, h);
             */

            Lam.Glulam blank = Lam.Glulam.CreateGlulam(crv, plane_array, data);
            //blank.CalculateLamellaSizes(w, h);

            List <object> output = new List <object>();

            if ((flags & 1) > 0)
            {
                output.Add(blank.GetBoundingMesh(0, blank.Data.InterpolationType));
            }
            if ((flags & (1 << 1)) > 0)
            {
                output.Add(blank.GetBoundingBrep());
            }
            if ((flags & (1 << 2)) > 0)
            {
                output.AddRange(blank.GetLamellaCurves());
            }
            if ((flags & (1 << 3)) > 0)
            {
                output.AddRange(blank.GetLamellaMeshes());
            }
            if ((flags & (1 << 4)) > 0)
            {
                output.AddRange(blank.GetLamellaBreps());
            }

            DA.SetDataList("Geometry", output);
            DA.SetData("Glulam", new GH.GH_Glulam(blank));
        }
Example #7
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Curve        crv    = null;
            List <Curve> guides = new List <Curve>();

            //double lw = 0, lh = 0;
            double       w = 0, h = 0;
            int          samples = 0;
            List <Plane> planes  = new List <Plane>();

            if (!DA.GetData("Curve", ref crv))
            {
                return;
            }
            if (!DA.GetDataList("Guides", guides))
            {
                return;
            }

            for (int i = 0; i < guides.Count; ++i)
            {
                Point3d  pt  = guides[i].PointAtStart;
                Vector3d vec = guides[i].TangentAtStart;

                double t;
                crv.ClosestPoint(pt, out t);

                //Plane nor_plane = new Plane(crv.PointAt(t), crv.TangentAt(t));

                //vec = vec.ProjectToPlane(nor_plane);

                //Plane frame = new Plane(nor_plane.Origin, Vector3d.CrossProduct(crv.TangentAt(t), vec), vec);

                var origin = crv.PointAt(t);
                var x_axis = Vector3d.CrossProduct(vec, crv.TangentAt(t));
                var y_axis = Vector3d.CrossProduct(crv.TangentAt(t), x_axis);

                Plane frame = new Plane(origin, x_axis, y_axis);

                planes.Add(frame);
            }

            //DA.GetData("LamWidth", ref lw);
            //DA.GetData("LamHeight", ref lh);
            DA.GetData("Width", ref w);
            DA.GetData("Height", ref h);
            DA.GetData("Samples", ref samples);


            Lam.GlulamData data = null;

            data = new GlulamData(crv, w, h, planes.ToArray(), (int)Math.Ceiling(crv.GetLength() / GlulamData.DefaultSampleDistance));

            /*
             * if (calculate_data)
             *  data = Lam.GlulamData.FromCurveLimits(crv, w, h);
             * else
             *  data = new Lam.GlulamData(1, 1, w, h);
             * //data.LamHeight = lh > 0.001 ? lh : 20.0;
             * //data.LamWidth = lw > 0.001 ? lw : 20.0;
             * //data.NumHeight = h > 0 ? (int)Math.Ceiling(h / lh) : 4;
             * //data.NumWidth = w > 0 ? (int)Math.Ceiling(w / lw) : 4;
             */
            data.Samples = samples > 1 ? samples : 2;


            Lam.Glulam blank = Lam.Glulam.CreateGlulam(crv, planes.ToArray(), data);
            //blank.RemoveDuplicateFrames();
            DA.SetData("Glulam", new GH.GH_Glulam(blank));
        }
Example #8
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            int samples = 0, m_alignment = 4;

            //int interpolation = 2;

            DA.GetData("Samples", ref samples);
            DA.GetData("Alignment", ref m_alignment);

            //DA.GetData("Interpolation", ref interpolation);
            GlulamData data = null;

            if (DataMethod == GlulamDataMethod.Lamella)
            {
                double lamella_x = 20, lamella_y = 20;
                int    num_x = 4, num_y = 4;

                DA.GetData("LamellaX", ref lamella_x);
                DA.GetData("LamellaY", ref lamella_y);
                DA.GetData("NumX", ref num_x);
                DA.GetData("NumY", ref num_y);

                data = new GlulamData(Math.Max(num_x, 1), Math.Max(num_y, 1), lamella_x, lamella_y, samples);
                data.SectionAlignment = (GlulamData.CrossSectionPosition)m_alignment;

                //data.InterpolationType = (GlulamData.Interpolation)interpolation;
            }
            else if (DataMethod == GlulamDataMethod.Section)
            {
                double m_width = 80.0, m_height = 80.0;
                double kx = 0, ky = 0;
                DA.GetData("Width (X)", ref m_width);
                DA.GetData("Height (Y)", ref m_height);

                DA.GetData("Curvature (X)", ref kx);
                DA.GetData("Curvature (Y)", ref ky);

                if (m_width < 0)
                {
                    m_width = -m_width;
                }
                if (m_height < 0)
                {
                    m_height = -m_height;
                }

                if (m_width == 0.0)
                {
                    m_width = 80.0;
                }
                if (m_height == 0.0)
                {
                    m_height = 80.0;
                }

                double l_width, l_height;
                if (kx > 0)
                {
                    l_width = GluLamb.Standards.NoStandard.Instance.CalculateLaminationThickness(kx);
                    // l_width = 1 / (Glulam.RadiusMultiplier * kx);
                }
                else
                {
                    l_width = m_width;
                }

                if (ky > 0)
                {
                    l_height = GluLamb.Standards.NoStandard.Instance.CalculateLaminationThickness(ky);
                    // l_height = 1 / (Glulam.RadiusMultiplier * ky);
                }
                else
                {
                    l_height = m_height;
                }

                int n_width  = Math.Max((int)Math.Ceiling(m_width / l_width), 1);
                int n_height = Math.Max((int)Math.Ceiling(m_height / l_height), 1);

                l_width  = m_width / n_width;
                l_height = m_height / n_height;

                data = new GlulamData(n_width, n_height, l_width, l_height, GlulamData.DefaultCurvatureSamples);
                data.SectionAlignment = (GlulamData.CrossSectionPosition)m_alignment;
                //data.InterpolationType = (GlulamData.Interpolation)interpolation;
            }

            DA.SetData("GlulamData", new GH_GlulamData(data));
        }
Example #9
0
        public Glulam GlulamFromCurveMesh(Curve crv, Mesh mesh, GlulamType type = GlulamType.DoubleCurved, Standards.Standard standard = Standards.Standard.None, double tolerance = 10.0)
        {
            double     width, height;
            GlulamData data;
            Plane      xform = new Plane(crv.PointAtStart, crv.PointAtEnd - crv.PointAtStart);
            Polyline   convex_hull;

            if (crv.IsLinear())
            {
                type = GlulamType.Straight;
            }
            else if (crv.IsPlanar())
            {
                type = GlulamType.SingleCurved;
            }

            Beam beam;

            switch (type)
            {
            case GlulamType.Straight:
                var   line_curve = new Line(crv.PointAtStart, crv.PointAtEnd);
                Plane plane      = xform;
                mesh.FitToAxes(plane, out convex_hull, ref xform);

                height = convex_hull.BoundingBox.Max.Y - convex_hull.BoundingBox.Min.Y;
                width  = convex_hull.BoundingBox.Max.X - convex_hull.BoundingBox.Min.X;

                data = new GlulamData(1, 1, width, height);

                var orientation = new VectorOrientation(xform.YAxis);

                return(Glulam.CreateGlulam(line_curve.ToNurbsCurve(), orientation, data));

            case GlulamType.SingleCurved:
                crv.TryGetPlane(out Plane project, tolerance);
                mesh.FitToAxes(project, out convex_hull, ref xform);

                var cbb = crv.GetBoundingBox(project);
                height = (convex_hull.BoundingBox.Max.Y - convex_hull.BoundingBox.Min.Y) - (cbb.Max.Y - cbb.Min.Y);
                width  = (convex_hull.BoundingBox.Max.X - convex_hull.BoundingBox.Min.X) - (cbb.Max.X - cbb.Min.X);

                beam = new Beam {
                    Centreline = crv, Orientation = new PlanarOrientation(project), Width = width, Height = height
                };
                return(Glulam.CreateGlulam(beam, beam.Orientation, standard));

            case GlulamType.DoubleCurved:
            default:
                beam = new Beam {
                    Centreline = crv, Orientation = new RmfOrientation()
                };
                var gmesh = beam.ToBeamSpace(mesh);

                var bb = gmesh.GetBoundingBox(true);
                beam.Height = bb.Max.Y - bb.Min.Y;
                beam.Width  = bb.Max.X - bb.Min.X;

                return(Glulam.CreateGlulam(beam, beam.Orientation, standard));
            }
        }
Example #10
0
        public override bool Read(GH_IReader reader)
        {
            if (!reader.ItemExists("guide"))
            {
                Value = null;
                throw new Exception("Couldn't retrieve 'guide'.");
            }

            byte[] rawGuide = reader.GetByteArray("guide");

            Curve guide = GH_Convert.ByteArrayToCommonObject <Curve>(rawGuide);

            if (guide == null)
            {
                throw new Exception("Failed to convert 'guide'.");
            }

            int N = reader.GetInt32("num_frames");

            Plane[] frames = new Plane[N];

            for (int i = 0; i < N; ++i)
            {
                var gp = reader.GetPlane("frames", i);
                frames[i] = new Plane(
                    new Point3d(
                        gp.Origin.x,
                        gp.Origin.y,
                        gp.Origin.z),
                    new Vector3d(
                        gp.XAxis.x,
                        gp.XAxis.y,
                        gp.XAxis.z),
                    new Vector3d(
                        gp.YAxis.x,
                        gp.YAxis.y,
                        gp.YAxis.z)
                    );
            }

            int    lcx           = reader.GetInt32("lcx");
            int    lcy           = reader.GetInt32("lcy");
            double lsx           = reader.GetDouble("lsx");
            double lsy           = reader.GetDouble("lsy");
            int    interpolation = reader.GetInt32("interpolation");
            int    samples       = reader.GetInt32("samples");

            GlulamData data = new GlulamData(lcx, lcy, lsx, lsy, samples);

            data.InterpolationType = (GlulamData.Interpolation)interpolation;

            Value = Glulam.CreateGlulam(guide, frames, data);

            if (Value == null)
            {
                throw new Exception("What in the Lord's name...");
            }
            //DisplayMesh = Value.GetBoundingMesh();

            return(true);
        }
Example #11
0
 protected string GlulamDataToString(GlulamData data)
 {
     return($"GlulamData [ lw {data.LamWidth} lh {data.LamHeight} nw {data.NumHeight} nh {data.NumHeight} s {data.Samples} sa {data.SectionAlignment} ]");
 }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            double k_mult = 200.0;

            double m_width = 80.0, m_height = 80, m_kwidth = 0.0, m_kheight = 0.0;

            int m_alignment     = 4;
            int m_interpolation = 2;

            DA.GetData("Width", ref m_width);
            DA.GetData("Height", ref m_height);

            DA.GetData("Alignment", ref m_alignment);
            DA.GetData("Interpolation", ref m_interpolation);
            DA.GetData("KWidth", ref m_kwidth);
            DA.GetData("KHeight", ref m_kheight);

            if (m_width < 0)
            {
                m_width = -m_width;
            }
            if (m_height < 0)
            {
                m_height = -m_height;
            }

            if (m_width == 0.0)
            {
                m_width = 80.0;
            }
            if (m_height == 0.0)
            {
                m_height = 80.0;
            }

            double l_width, l_height;

            if (m_kwidth > 0)
            {
                l_width = 1 / (k_mult * m_kwidth);
            }
            else
            {
                l_width = m_width;
            }

            if (m_kheight > 0)
            {
                l_height = 1 / (k_mult * m_kheight);
            }
            else
            {
                l_height = m_height;
            }

            int n_width  = Math.Max((int)Math.Ceiling(m_width / l_width), 1);
            int n_height = Math.Max((int)Math.Ceiling(m_height / l_height), 1);

            l_width  = m_width / n_width;
            l_height = m_height / n_height;

            GlulamData data = new GlulamData(n_width, n_height, l_width, l_height, GlulamData.DefaultCurvatureSamples);

            data.InterpolationType = (GlulamData.Interpolation)m_interpolation;
            data.SectionAlignment  = (GlulamData.CrossSectionPosition)m_alignment;

            DA.SetData("GlulamData", new GH_GlulamData(data));
        }