Example #1
0
        /// <summary>
        /// Sweep2 function that fits a surface through profile curves that define the surface cross-sections
        /// and two curves that defines a surface edge.
        /// </summary>
        /// <param name="rail1">Rail to sweep shapes along</param>
        /// <param name="rail2">Rail to sweep shapes along</param>
        /// <param name="crossSections">Shape curves</param>
        /// <returns>Array of Brep sweep results</returns>
        /// <since>5.0</since>
        public Brep[] PerformSweep(Curve rail1, Curve rail2, IEnumerable <Curve> crossSections)
        {
            // 12-Jun-2019 Dale Fugier, https://mcneel.myjetbrains.com/youtrack/issue/RH-31673
            // Call the new sweep code, used by the Sweep2 command
            //
            //List<double> rail_params1 = new List<double>();
            //List<double> rail_params2 = new List<double>();
            //Interval domain1 = rail1.Domain;
            //Interval domain2 = rail2.Domain;
            //foreach (Curve c in crossSections)
            //{
            //  Point3d point_at_start = c.PointAtStart;
            //  double t;
            //  rail1.ClosestPoint(point_at_start, out t);
            //  if (t == domain1.Max)
            //    t = domain1.Max - RhinoMath.SqrtEpsilon;
            //  rail_params1.Add(t);

            //  rail2.ClosestPoint(point_at_start, out t);
            //  if (t == domain2.Max)
            //    t = domain2.Max - RhinoMath.SqrtEpsilon;
            //  rail_params2.Add(t);
            //}

            //// NOTE: See if we need to do anything special in a rail_params1.Count==1 case
            //// like we do in the Sweep1 counterpart function
            //return PerformSweep(rail1, rail2, crossSections, rail_params1, rail_params2);
            return(Brep.CreateFromSweep(rail1, rail2, crossSections, Point3d.Unset, Point3d.Unset, ClosedSweep, SweepTolerance, SweepRebuild.None, 0, 0.0, MaintainHeight));
        }
Example #2
0
        // ====================================================================

        //---- END CONSTRUCTOR-------------------------------------------------

        // ====================================================================
        // Added by Gene

        public void RunSingleSrf()
        {
            Point3d   pLeft  = curvesLeft.PointAtStart;
            Point3d   pRight = curvesRight.PointAtStart;
            LineCurve rail   = new LineCurve(pLeft, pRight);

            Point3d   pLeft2  = curvesLeft.PointAtEnd;
            Point3d   pRight2 = curvesRight.PointAtEnd;
            LineCurve rail2   = new LineCurve(pLeft2, pRight2);

            loop = Brep.CreateFromSweep(curvesLeft, curvesRight, new List <Curve>()
            {
                rail, rail2
            }, false, documentTolerance)[0];
            //loop = Brep.CreateFromLoftRebuild(new List<Curve>() { curvesLeft, curvesRight }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false, 50)[0];
            //loop = Brep.CreateFromLoft(new List<Curve>() { curvesLeft, curvesRight }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false )[0];

            Brep[] loops;
            double offsetAmount = 0.002;
            //double offsetAmount2 = 0.02;
            Vector3d normal1, normal2;

            normal1 = Vector3d.CrossProduct(cuttingPts[0] - cuttingPts[4], cuttingPts[0] - cuttingPts[2]);
            normal2 = Vector3d.CrossProduct(cuttingPts[1] - cuttingPts[3], cuttingPts[1] - cuttingPts[5]);

            Point3d A_ = cuttingPts[7] + offsetAmount * normal2;
            Point3d B_ = cuttingPts[6] + offsetAmount * normal1;

            //Brep cutter1 = Brep.CreateFromCornerPoints(cuttingPts[0], cuttingPts[1], cuttingPts[2], cuttingPts[3], documentTolerance);
            //Brep cutter2 = Brep.CreateFromCornerPoints(cuttingPts[0], cuttingPts[1], cuttingPts[4], cuttingPts[5], documentTolerance);

            loops = loop.Trim(new Plane(A_, cuttingPts[1], cuttingPts[3]), documentTolerance);
            //loops = loop.Trim(cutter1, documentTolerance);

            if (loops.Length > 0)
            {
                loop = loops[0];
            }
            //else { return; }

            loops = loop.Trim(new Plane(A_, cuttingPts[5], cuttingPts[1]), documentTolerance);

            if (loops.Length > 0)
            {
                loop = loops[0];
            }
            //else { return; }

            loops = loop.Trim(new Plane(B_, cuttingPts[2], cuttingPts[0]), documentTolerance);
            if (loops.Length > 0)
            {
                loop = loops[0];
            }

            loops = loop.Trim(new Plane(B_, cuttingPts[0], cuttingPts[4]), documentTolerance);
            if (loops.Length > 0)
            {
                loop = loops[0];
            }
        }
Example #3
0
        public ProfileToElements(string name, Profile elementProfile, List <Line> insertLines, double angle, Material material, int type)
        {
            Name         = name;
            Material     = material;
            Profile      = elementProfile;
            ElementLines = insertLines;
            Amount       = insertLines.Count;
            ElementType  = IfcTools.IntToType(type);

            double surfaceArea = elementProfile.BoundarySurfaces[0].GetArea();

            Volume = insertLines.Sum(line => surfaceArea * line.Length);

            Mass = Volume * material.Density;
            SectionInsertPlanes = new List <Plane>();
            Breps = new List <Brep>();

            foreach (var line in insertLines)
            {
                Curve    lineCurve           = line.ToNurbsCurve();
                double[] divisionParameters  = lineCurve.DivideByCount(1, true);
                Plane[]  perpendicularPlanes = lineCurve.GetPerpendicularFrames(divisionParameters);
                Plane    sectionInsertPlane  = perpendicularPlanes[0].Clone();
                sectionInsertPlane.Rotate(angle, sectionInsertPlane.ZAxis);
                SectionInsertPlanes.Add(sectionInsertPlane);

                Transform planeToPlane   = Transform.PlaneToPlane(Plane.WorldXY, sectionInsertPlane);
                Curve     duplicateCurve = elementProfile.ProfileCurve.DuplicateCurve();
                duplicateCurve.Transform(planeToPlane);

                Breps.Add(Brep.CreateFromSweep(line.ToNurbsCurve(), duplicateCurve, true, elementProfile.Tolerance)[0]);
            }
        }
        /// <summary>
        /// Rhino calls the virtual ReplayHistory functions to to remake an objects when inputs have changed.
        /// </summary>
        protected override bool ReplayHistory(ReplayHistoryData replay)
        {
            ObjRef rail_objref  = null;
            ObjRef shape_objref = null;
            double tolerance    = RhinoMath.UnsetValue;

            if (!ReadHistory(replay, ref rail_objref, ref shape_objref, ref tolerance))
            {
                return(false);
            }

            Rhino.Geometry.Curve rail_curve = rail_objref.Curve();
            if (null == rail_curve)
            {
                return(false);
            }

            Rhino.Geometry.Curve shape_curve = shape_objref.Curve();
            if (null == shape_curve)
            {
                return(false);
            }

            if (!Rhino.RhinoMath.IsValidDouble(tolerance))
            {
                tolerance = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;
            }

            Brep[] brep = Brep.CreateFromSweep(rail_curve, shape_curve, false, tolerance);
            if (null == brep || 0 == brep.Length)
            {
                return(false);
            }

            for (int i = 0; i < brep.Length; i++)
            {
                if (null != replay.Results[i])
                {
                    replay.Results[i].UpdateToBrep(brep[i], null);
                }
                else
                {
                    break;
                }
            }

            return(true);
        }
Example #5
0
 /// <summary>
 /// Sweep2 function that fits a surface through profile curves that define the surface cross-sections
 /// and two curves that defines a surface edge.
 /// </summary>
 /// <param name="rail1">Rail to sweep shapes along</param>
 /// <param name="rail2">Rail to sweep shapes along</param>
 /// <param name="crossSections">Shape curves</param>
 /// <param name="rebuildCount">Rebuild point count</param>
 /// <returns>Array of Brep sweep results</returns>
 /// <since>5.0</since>
 public Brep[] PerformSweepRebuild(Curve rail1, Curve rail2, IEnumerable <Curve> crossSections, int rebuildCount)
 {
     // 12-Jun-2019 Dale Fugier, https://mcneel.myjetbrains.com/youtrack/issue/RH-31673
     // Call the new sweep code, used by the Sweep2 command
     //
     //List<double> rail_params1 = new List<double>();
     //List<double> rail_params2 = new List<double>();
     //foreach (Curve c in crossSections)
     //{
     //  Point3d point_at_start = c.PointAtStart;
     //  double t;
     //  rail1.ClosestPoint(point_at_start, out t);
     //  rail_params1.Add(t);
     //  rail2.ClosestPoint(point_at_start, out t);
     //  rail_params2.Add(t);
     //}
     //return PerformSweepRebuild(rail1, rail2, crossSections, rail_params1, rail_params2, rebuildCount);
     return(Brep.CreateFromSweep(rail1, rail2, crossSections, Point3d.Unset, Point3d.Unset, ClosedSweep, SweepTolerance, SweepRebuild.Rebuild, rebuildCount, 0.0, MaintainHeight));
 }
        private bool CreateSectionSweeps(List <ResultElement> res, string loadComb, bool showDeformed, double sFac)
        {
            // Clear lists
            ResetDrawingData();

            List <Point3d> pts     = new List <Point3d>();      // Points to create curve from
            List <Brep>    sSweeps = new List <Brep>(res.Count);

            foreach (ResultElement re in res)
            {
                List <Curve> crvs;
                List <Curve> sweepCrvs = new List <Curve>();

                // Start and end caps
                List <Curve> sCap = new List <Curve>();
                List <Curve> eCap = new List <Curve>();

                if (CrossSectionCasts.GetSectionPropertyCrvs(re.SectionPropertyString, out crvs))
                {
                    pts.Clear();

                    // Create rail
                    Curve rail;
                    if (showDeformed)
                    {
                        for (int i = 0; i < re.pos.Count; i++)
                        {
                            Point3d pt = CalcDeformedPosition(re, i, loadComb, sFac);

                            // Add points to list
                            pts.Add(pt);
                        }

                        rail = Curve.CreateInterpolatedCurve(pts, 3);
                    }
                    else
                    {
                        // Add points to list for transform of curves to positions
                        for (int i = 0; i < re.pos.Count; i++)
                        {
                            pts.Add(CalcUndeformedPosition(re, i));
                        }

                        rail = (Curve) new Line(re.sPos, re.ePos).ToNurbsCurve();
                    }

                    foreach (Curve crv in crvs)
                    {
                        // Rotation to local coordinates
                        Transform rotTrans = Transform.Rotation(Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, re.LocalX, re.LocalY, re.elNormal);
                        crv.Transform(rotTrans);

                        sweepCrvs.Clear();

                        for (int i = 0; i < re.pos.Count; i++)
                        {
                            Curve c = (Curve)crv.Duplicate();

                            Transform defTrans;
                            if (showDeformed)
                            {
                                // Rotation to deformed shape
                                Vector3d defTan = CalcDeformedTangent(rail, pts[i]);
                                defTrans = GetDeformationTransform(re, defTan, i, loadComb, sFac);
                            }
                            else
                            {
                                defTrans = Transform.Identity;
                            }

                            // Calculate move to element positions
                            Transform tTrans = Transform.Translation((Vector3d)pts[i]);

                            // Perform transformation
                            c.Transform(defTrans);
                            c.Transform(tTrans);

                            // Add curves
                            _secCrvs.Add(c);
                            sweepCrvs.Add(c);
                        }

                        //Add curves to cap curves
                        if (sweepCrvs.Count > 0)
                        {
                            sCap.Add(sweepCrvs[0]);
                            eCap.Add(sweepCrvs[sweepCrvs.Count - 1]);
                        }

                        //Create sweep
                        Brep[] b = Brep.CreateFromSweep(rail, sweepCrvs, true, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
                        _breps.AddRange(b);
                    }

                    // Cap sections
                    _breps.Add(Utilities.CapSections(sCap));
                    _breps.Add(Utilities.CapSections(eCap));
                }
            }

            _bb = new BoundingBox(pts);

            return(true);
        }
Example #7
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //inputs
            Brep   brep = new Brep();
            string type = "";

            DA.GetData(0, ref brep);
            DA.GetData(1, ref type);

            //parameters
            Wall w = new Wall("straight wall");

            //variables
            List <string> infos  = new List <string>();
            List <Brep>   srfs   = new List <Brep>();
            List <Curve>  ibcrvs = new List <Curve>(); //internal boundaries
            List <Curve>  bcvs   = new List <Curve>(); //bottom boundaries
            List <Curve>  tcvs   = new List <Curve>(); //top boundaries

            //methods
            infos.Add("Creting Multiconsult wall");
            w.brep = brep;
            var cpts = Methods.Geometry.findBottomAndTopCenterPoints(brep);  //find bottom and top central points
            var pls  = Methods.Geometry.findWallHorizontalPlanes(brep);
            var crvs = Methods.Geometry.findWallBottomAndTop(brep);

            //find central plane
            w.planeHorizontal = pls[0]; //XY plane in the middle of the wall height
            //find bottom and top planes
            w.planeBottom = pls[1];
            w.planeTop    = pls[2];

            //create master surface and bottom and top curves
            srfs.Add(Brep.CreatePlanarBreps(crvs[0], 0.00001)[0]);
            bcvs.Add(crvs[1]);
            //tcvs.Add(crvs[2]);

            //find the longest curve and midle curve
            Line[] constructionLines = Methods.Geometry.findWallConstructionLines(crvs.ToArray(), cpts);
            w.constructionLines = constructionLines;

            Line heightLine = new Line(cpts[0], cpts[1]);

            w.bottomAxis = constructionLines[0].ToNurbsCurve();
            Point3d  wallOrigin = constructionLines[2].PointAt(0.5);
            Vector3d wallX      = Point3d.Subtract(constructionLines[0].From, constructionLines[0].To);
            Vector3d wallY      = Point3d.Subtract(constructionLines[2].From, constructionLines[2].To);

            w.plane = new Plane(wallOrigin, wallX, wallY);

            //assign section
            w.section = new Wall_Section("straight wall", Math.Round(constructionLines[0].Length));
            //assign material
            w.material = Methods.Revit.getRevitMaterialFromString(type);

            Brep masterSurface = Brep.CreateFromSweep(w.constructionLines[2].ToNurbsCurve(), w.constructionLines[0].ToNurbsCurve(), true, 0.000001)[0];

            w.surface = masterSurface;

            //validate the information about analysis
            infos.Add("Revit Material= " + w.material.RevitMaterialName);
            infos.Add("Section = " + w.section.name);

            //outputs
            DA.SetData(0, w);
            DA.SetDataList(1, infos);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const ObjectType geometryFilter = ObjectType.Curve;

            GetObject get_rail = new GetObject();

            get_rail.SetCommandPrompt("Select rail curve");
            get_rail.GeometryFilter = geometryFilter;
            //get_rail.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
            get_rail.SubObjectSelect = false;
            get_rail.Get();
            if (get_rail.CommandResult() != Result.Success)
            {
                return(get_rail.CommandResult());
            }

            ObjRef rail_objref = get_rail.Object(0);
            Curve  rail_curve  = rail_objref.Curve();

            if (null == rail_curve)
            {
                return(Result.Failure);
            }

            GetObject get_shape = new GetObject();

            get_shape.SetCommandPrompt("Select cross section curve");
            get_shape.GeometryFilter = geometryFilter;
            //get_shape.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
            get_shape.SubObjectSelect = false;
            get_shape.EnablePreSelect(false, false);
            get_shape.DeselectAllBeforePostSelect = false;
            get_shape.Get();
            if (get_shape.CommandResult() != Result.Success)
            {
                return(get_shape.CommandResult());
            }

            ObjRef shape_objref = get_shape.Object(0);
            Curve  shape_curve  = shape_objref.Curve();

            if (null == shape_curve)
            {
                return(Result.Failure);
            }

            double tolerance = doc.ModelAbsoluteTolerance;

            Brep[] brep = Brep.CreateFromSweep(rail_curve, shape_curve, false, tolerance);
            if (null == brep || 0 == brep.Length)
            {
                return(Result.Failure);
            }

            // Create a history record
            HistoryRecord history = new HistoryRecord(this, HISTORY_VERSION);

            WriteHistory(history, rail_objref, shape_objref, tolerance);

            for (int i = 0; i < brep.Length; i++)
            {
                doc.Objects.AddBrep(brep[i], null, history, false);
            }

            doc.Views.Redraw();

            return(Result.Success);
        }