예제 #1
0
        public void GetSeparators()
        {
            var grid = new Grid1d(100);

            grid.DivideByCount(5);
            var pts = grid.GetCellSeparators();

            Assert.Equal(6, pts.Count);
            Assert.Equal(pts[0], new Vector3(0, 0, 0));
            Assert.Equal(pts[1], new Vector3(20, 0, 0));
            Assert.Equal(pts[5], new Vector3(100, 0, 0));

            grid[1].DivideByCount(3);
            var pts2 = grid.GetCellSeparators(true);

            Assert.Equal(8, pts2.Count);
        }
예제 #2
0
        /// <summary>
        /// The BallonaBridge function.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A BallonaBridgeOutputs instance containing computed results and the model with any new elements.</returns>
        public static BallonaBridgeOutputs Execute(Dictionary <string, Model> inputModels, BallonaBridgeInputs input)
        {
            /// Your code here.
            var output = new BallonaBridgeOutputs(1.0);

            Elements.Material brdigeMaterial = null;
            switch (input.Material)
            {
            case Material.Red:
                brdigeMaterial = new Elements.Material("Red", Colors.Red, 0.0f, 0.0f);
                break;

            case Material.Steel:
                brdigeMaterial = BuiltInMaterials.Steel;
                break;

            case Material.Wood:
                brdigeMaterial = BuiltInMaterials.Wood;
                break;
            }
            var beam = new Beam(input.CenterLine, Polygon.Rectangle(input.BridgeWidth, input.BridgeHeight), brdigeMaterial);

            var offsetCrv = input.CenterLine.Offset(5, EndType.Square);

            // output.model.AddElement(offsetCrv);


            var grid = new Grid1d(offsetCrv[0]);

            grid.DivideByApproximateLength(1.0);
            foreach (var pt in grid.GetCellSeparators())
            {
                var column = new Column(pt, 5, Polygon.Rectangle(0.05, 0.05));
                output.model.AddElement(column);
            }

            output.model.AddElement(beam);
            return(output);
        }
예제 #3
0
        /// <summary>
        /// Construct a set of elements from this rule for a given definition.
        /// </summary>
        /// <param name="definition">The definition to instantiate.</param>
        public List <Element> Instantiate(ComponentDefinition definition)
        {
            var arrayElements = new List <Element>();
            var newVertices   = PolylinePlacementRule.TransformPolyline(this, definition);

            var path = IsClosed ? new Polygon(newVertices) : new Polyline(newVertices);

            var grid1d = new Grid1d(path);

            switch (SpacingRule.SpacingMode)
            {
            case SpacingMode.ByLength:
                grid1d.DivideByFixedLength(SpacingRule.Value);
                break;

            case SpacingMode.ByApproximateLength:
                grid1d.DivideByApproximateLength(SpacingRule.Value);
                break;

            case SpacingMode.ByCount:
                grid1d.DivideByCount((int)SpacingRule.Value);
                break;
            }

            var separators = grid1d.GetCellSeparators();

            foreach (var sep in separators)
            {
                ElementDefinition.IsElementDefinition = true;
                var transform = new Transform(definition.OrientationGuide);
                transform.Concatenate(new Transform(sep));
                var instance = ElementDefinition.CreateInstance(transform, Guid.NewGuid().ToString());
                arrayElements.Add(instance);
            }
            return(arrayElements);
        }
예제 #4
0
        /// <summary>
        /// The Testfunction1 function.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A Testfunction1Outputs instance containing computed results and the model with any new elements.</returns>
        public static Testfunction1Outputs Execute(Dictionary <string, Model> inputModels, Testfunction1Inputs input)
        {
            /// Your code here.
            var output = new Testfunction1Outputs(1.0);
            List <ModelCurve> modelCurves = new List <ModelCurve>();
            List <Curve>      Curves      = new List <Curve>();

            Elements.Material brdigeMaterial = null;
            switch (input.Material)
            {
            case Material.Red:
                brdigeMaterial = new Elements.Material("Red", Colors.Red, 0.0f, 0.0f);
                break;

            case Material.Steel:
                brdigeMaterial = BuiltInMaterials.Steel;
                break;

            case Material.Wood:
                brdigeMaterial = BuiltInMaterials.Wood;
                break;
            }
            var            profile          = WideFlangeProfileServer.Instance.GetProfileByType(WideFlangeProfileType.W10x100);
            var            pts              = new List <Vector3>();
            var            centerCrv        = input.CenterLine;
            var            offsetCrv        = input.CenterLine.Offset(input.OffsetWidth, EndType.Square)[0];
            var            offsetCrv2       = input.CenterLine.Offset(input.OffsetWidth / 2, EndType.Square)[0];
            var            rebuildOffsetCrv = new Polygon(offsetCrv.Vertices);
            var            LGon             = Polygon.L(15, 15, 5);
            var            ltransform       = new Transform(15, 0, 0);
            List <Polygon> testPoly         = new List <Polygon>();

            testPoly.AddRange(new[] { rebuildOffsetCrv, Polygon.Rectangle(15, 15), ltransform.OfPolygon(LGon) });

            foreach (var poly in testPoly)
            {
                var beam = new Beam(poly, Polygon.Rectangle(input.BridgeWidth, input.BridgeHeight), brdigeMaterial);
                // var beam = new Beam(poly, profile, brdigeMaterial);
                output.Model.AddElement(beam);
                var grid = new Grid1d(poly);

                grid.DivideByApproximateLength(3);

                foreach (var pt in grid.GetCellSeparators())
                {
                    var column = new Column(pt, 5, Polygon.Rectangle(0.1, 0.1));
                    output.Model.AddElement(column);
                }
            }
            var secLine = new Line(new Vector3(-input.OffsetWidth * 2, 0, 0), new Vector3(input.OffsetWidth * 2, 0, 0));
            // List<Plane> planes = new List<Plane>();
            List <Line> secLines = new List <Line>();


            var crvSegments = centerCrv.Segments();

            foreach (var crv in crvSegments)
            {
                var grid = new Grid1d(crv);

                grid.DivideByApproximateLength(3);

                foreach (var pt in grid.GetCellSeparators())
                {
                    // planes.Add(new Plane(pt, Vector3.XAxis(pt)))
                    // pts.Add(pt);
                    var transform = new Transform(pt, crv.Direction());
                    secLines.Add(transform.OfLine(secLine));
                    // planes.Add(new Plane(pt, crv.Direction()));
                    var column = new Column(pt, 5, Polygon.Rectangle(0.1, 0.1));
                    output.Model.AddElement(column);
                }
            }

            Curves.AddRange(new[] { centerCrv, offsetCrv, (Curve)secLine });
            Curves.AddRange(secLines);
            foreach (var crv in Curves)
            {
                modelCurves.Add(new ModelCurve(crv));
            }
            // var pink = new Elements.Material("pink", Colors.Pink);
            // var modelPoints = new ModelPoints(pts, pink);


            // var crvs = new List<Curve>{Polygon.Rectangle(10,10), offsetCrv[0]};

            // foreach(var crv in crvs) {
            //   modelCurves.Add(new ModelCurve(crv));
            //   var grid = new Grid1d(crv);
            //   grid.DivideByApproximateLength(1.0);
            //   foreach(var pt in grid.GetCellSeparators())
            //   {
            //     var column = new Column(pt, 5, Polygon.Rectangle(0.05, 0.05));
            //     output.Model.AddElement(column);
            //   }

            // }
            // output.Model.AddElements(modelPoints);
            output.Model.AddElements(modelCurves);
            // output.Model.AddElement(beam);
            return(output);
        }
예제 #5
0
        /// <summary>
        /// The PhoneBoothLayout function.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A PhoneBoothLayoutOutputs instance containing computed results and the model with any new elements.</returns>
        public static PhoneBoothLayoutOutputs Execute(Dictionary <string, Model> inputModels, PhoneBoothLayoutInputs input)
        {
            var spacePlanningZones = inputModels["Space Planning Zones"];
            var levelsModel        = inputModels["Levels"];
            var levels             = spacePlanningZones.AllElementsOfType <LevelElements>();
            var levelVolumes       = levelsModel.AllElementsOfType <LevelVolume>();
            var output             = new PhoneBoothLayoutOutputs();
            var configJson         = File.ReadAllText("./PhoneBoothConfigurations.json");
            var configs            = JsonConvert.DeserializeObject <SpaceConfiguration>(configJson);

            var wallMat    = new Material("Drywall", new Color(0.9, 0.9, 0.9, 1.0), 0.01, 0.01);
            var glassMat   = new Material("Glass", new Color(0.7, 0.7, 0.7, 0.3), 0.3, 0.6);
            var mullionMat = new Material("Storefront Mullions", new Color(0.5, 0.5, 0.5, 1.0));

            foreach (var lvl in levels)
            {
                var corridors           = lvl.Elements.OfType <Floor>();
                var corridorSegments    = corridors.SelectMany(p => p.Profile.Segments());
                var meetingRmBoundaries = lvl.Elements.OfType <SpaceBoundary>().Where(z => z.Name == "Phone Booth");
                var levelVolume         = levelVolumes.First(l => l.Name == lvl.Name);
                var wallCandidateLines  = new List <(Line line, string type)>();
                foreach (var room in meetingRmBoundaries)
                {
                    var  spaceBoundary        = room.Boundary;
                    Line orientationGuideEdge = FindEdgeAdjacentToSegments(spaceBoundary.Perimeter.Segments(), corridorSegments, out var wallCandidates);
                    var  exteriorWalls        = FindEdgeAdjacentToSegments(wallCandidates, levelVolume.Profile.Segments(), out var solidWalls, 0.6);
                    wallCandidateLines.AddRange(solidWalls.Select(s => (s, "Solid")));
                    var orientationTransform = new Transform(Vector3.Origin, orientationGuideEdge.Direction(), Vector3.ZAxis);
                    var boundaryCurves       = new List <Polygon>();
                    boundaryCurves.Add(spaceBoundary.Perimeter);
                    boundaryCurves.AddRange(spaceBoundary.Voids ?? new List <Polygon>());

                    var grid = new Grid2d(boundaryCurves, orientationTransform);
                    grid.U.DivideByApproximateLength(input.MinimumSize, EvenDivisionMode.RoundDown);
                    foreach (var cell in grid.GetCells())
                    {
                        var  rect       = cell.GetCellGeometry() as Polygon;
                        var  segs       = rect.Segments();
                        var  width      = segs[0].Length();
                        var  depth      = segs[1].Length();
                        Line glassWall  = null;
                        var  trimmedGeo = cell.GetTrimmedCellGeometry();
                        if (!cell.IsTrimmed() && trimmedGeo.Count() > 0)
                        {
                            glassWall = segs[0];
                            output.Model.AddElement(InstantiateLayout(configs, width, depth, rect, room.Transform));
                        }
                        else if (trimmedGeo.Count() > 0)
                        {
                            var largestTrimmedShape = trimmedGeo.OfType <Polygon>().OrderBy(s => s.Area()).Last();
                            glassWall = largestTrimmedShape.Segments().OrderBy(s => s.PointAt(0.5).DistanceTo(segs[0].PointAt(0.5))).FirstOrDefault();

                            var cinchedVertices = rect.Vertices.Select(v => largestTrimmedShape.Vertices.OrderBy(v2 => v2.DistanceTo(v)).First()).ToList();
                            var cinchedPoly     = new Polygon(cinchedVertices);
                            output.Model.AddElement(InstantiateLayout(configs, width, depth, cinchedPoly, room.Transform));
                        }
                        if (glassWall != null)
                        {
                            wallCandidateLines.Add((glassWall, "Glass"));
                        }
                    }
                    var cellSeparators = grid.GetCellSeparators(GridDirection.V, true);
                    wallCandidateLines.AddRange(grid.GetCellSeparators(GridDirection.V, true).OfType <Curve>().Select(c => (new Line(c.PointAt(0), c.PointAt(1)), "Partition")));
                }
                var mullionSize           = 0.07;
                var doorWidth             = 0.9;
                var doorHeight            = 2.1;
                var sideLightWidth        = 0.4;
                var totalStorefrontHeight = Math.Min(2.7, levelVolume.Height);
                var mullion = new StandardWall(new Line(new Vector3(-mullionSize / 2, 0, 0), new Vector3(mullionSize / 2, 0, 0)), mullionSize, totalStorefrontHeight, mullionMat);
                mullion.IsElementDefinition = true;
                if (input.CreateWalls)
                {
                    foreach (var wallCandidate in wallCandidateLines)
                    {
                        if (wallCandidate.type == "Solid")
                        {
                            output.Model.AddElement(new StandardWall(wallCandidate.line, 0.2, levelVolume.Height, wallMat, levelVolume.Transform));
                        }
                        else if (wallCandidate.type == "Partition")
                        {
                            output.Model.AddElement(new StandardWall(wallCandidate.line, 0.1, levelVolume.Height, wallMat, levelVolume.Transform));
                        }
                        else if (wallCandidate.type == "Glass")
                        {
                            var grid = new Grid1d(wallCandidate.line);
                            grid.SplitAtOffsets(new[] { sideLightWidth, sideLightWidth + doorWidth });
                            grid[2].DivideByApproximateLength(2);
                            var separators = grid.GetCellSeparators(true);
                            var beam       = new Beam(wallCandidate.line, Polygon.Rectangle(mullionSize, mullionSize), mullionMat, 0, 0, 0, isElementDefinition: true);
                            output.Model.AddElement(beam.CreateInstance(levelVolume.Transform, "Base Mullion"));
                            output.Model.AddElement(beam.CreateInstance(levelVolume.Transform.Concatenated(new Transform(0, 0, doorHeight)), "Base Mullion"));
                            output.Model.AddElement(beam.CreateInstance(levelVolume.Transform.Concatenated(new Transform(0, 0, totalStorefrontHeight)), "Base Mullion"));
                            foreach (var separator in separators)
                            {
                                // var line = new Line(separator, separator + new Vector3(0, 0, levelVolume.Height));
                                // output.Model.AddElement(new ModelCurve(line, BuiltInMaterials.XAxis, levelVolume.Transform));
                                var instance = mullion.CreateInstance(new Transform(separator, wallCandidate.line.Direction(), Vector3.ZAxis, 0).Concatenated(levelVolume.Transform), "Mullion");
                                output.Model.AddElement(instance);
                            }
                            output.Model.AddElement(new StandardWall(wallCandidate.line, 0.05, totalStorefrontHeight, glassMat, levelVolume.Transform));
                            var headerHeight = levelVolume.Height - totalStorefrontHeight;
                            if (headerHeight > 0.01)
                            {
                                output.Model.AddElement(new StandardWall(wallCandidate.line, 0.2, headerHeight, wallMat, levelVolume.Transform.Concatenated(new Transform(0, 0, totalStorefrontHeight))));
                            }
                        }
                    }
                }
            }
            InstancePositionOverrides(input.Overrides, output.Model);
            return(output);
        }
예제 #6
0
파일: Joist.cs 프로젝트: jmerlan/Elements
        private Representation ConstructRepresentation()
        {
            if (CellCount == 0)
            {
                return(null);
            }

            JoistPoints.Clear();

            var ll = Construct2LProfile(TopChordProfile, true);

            var topSweepR = new Sweep(ll[0],
                                      Curve,
                                      StartSetback,
                                      EndSetback,
                                      Rotation,
                                      false);
            var topSweepL = new Sweep(ll[1],
                                      Curve,
                                      StartSetback,
                                      EndSetback,
                                      Rotation,
                                      false);

            var  startT = Curve.TransformAt(0);
            Line line   = (Line)Curve;

            var topStart = line.Start - startT.ZAxis * DistanceToFirstPanel;
            var topEnd   = line.End + startT.ZAxis * DistanceToFirstPanel;

            var bottomStart = line.Start - startT.YAxis * Depth - startT.ZAxis * DistanceToFirstPanel;
            var bottomEnd   = line.End - startT.YAxis * Depth + startT.ZAxis * DistanceToFirstPanel;

            ll = Construct2LProfile(BottomChordProfile);

            var bottomChord  = new Line(bottomStart, bottomEnd);
            var bottomSweepR = new Sweep(ll[0],
                                         bottomChord,
                                         0,
                                         0,
                                         Rotation,
                                         false);
            var bottomSweepL = new Sweep(ll[1],
                                         bottomChord,
                                         0,
                                         0,
                                         Rotation,
                                         false);

            // Use a line that is shorter than the curve length.
            var topGrid = new Grid1d(new Line(topStart, topEnd));

            topGrid.DivideByCount(CellCount);

            var bottomGrid = new Grid1d(bottomChord);

            bottomGrid.DivideByCount(CellCount);

            var topPts    = topGrid.GetCellSeparators();
            var bottomPts = bottomGrid.GetCellSeparators();

            var solidOperations = new List <SolidOperation>()
            {
                topSweepL, topSweepR, bottomSweepL, bottomSweepR
            };

            Vector3 prevTop    = default;
            Vector3 prevBottom = default;

            var wll = Construct2LProfile(WebProfile);

            for (var i = 0; i < topPts.Count; i++)
            {
                var topPt    = topPts[i];
                var bottomPt = bottomPts[i];
                if (i % 2 == 0)
                {
                    prevTop = topPt;

                    // Vertical web
                    if (i != 0 && i != topPts.Count - 1)
                    {
                        var v1 = new Sweep(wll[0],
                                           new Line(topPt, bottomPt),
                                           0,
                                           0,
                                           0,
                                           false);
                        solidOperations.Add(v1);
                        var v2 = new Sweep(wll[1],
                                           new Line(topPt, bottomPt),
                                           0,
                                           0,
                                           0,
                                           false);
                        solidOperations.Add(v2);

                        JoistPoints.Add(topPt);
                    }

                    // Forward leaning web
                    if (i > 0)
                    {
                        var fl1 = new Sweep(wll[0],
                                            new Line(prevBottom, topPt),
                                            0,
                                            0,
                                            0,
                                            false);
                        solidOperations.Add(fl1);
                        var fl2 = new Sweep(wll[1],
                                            new Line(prevBottom, topPt),
                                            0,
                                            0,
                                            0,
                                            false);
                        solidOperations.Add(fl2);
                    }
                }
                else
                {
                    // Backward leaning web
                    var bl1 = new Sweep(wll[0],
                                        new Line(bottomPt, prevTop),
                                        0,
                                        0,
                                        0,
                                        false);
                    solidOperations.Add(bl1);
                    var bl2 = new Sweep(wll[1],
                                        new Line(bottomPt, prevTop),
                                        0,
                                        0,
                                        0,
                                        false);
                    solidOperations.Add(bl2);

                    prevBottom = bottomPt;
                }
            }

            var rep = new Representation(solidOperations);

            return(rep);
        }