コード例 #1
0
        /// <summary>
        /// The TestFunction2 function.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A TestFunction2Outputs instance containing computed results and the model with any new elements.</returns>
        public static TestFunction2Outputs Execute(Dictionary <string, Model> inputModels, TestFunction2Inputs input)
        {
            /// Your code here.
            List <ModelCurve> modelCurves = new List <ModelCurve>();
            List <Curve>      Curves      = new List <Curve>();
            List <Polygon>    Polygons    = new List <Polygon>();

            var bndry     = input.Outline;
            var spine     = bndry.Spine();
            var jig       = bndry.Jigsaw();
            var skel      = bndry.Skeleton();
            var height    = 1.0;
            var volume    = input.Length * input.Width * height;
            var output    = new TestFunction2Outputs(1.0);
            var rectangle = Polygon.Rectangle(input.Length, input.Width);
            var mass      = new Mass(bndry, height);

            Polygons.AddRange(new[] { bndry });
            var bbox = new List <Polygon>();

            foreach (var item in jig)
            {
                bbox.Add(item.AlignedBox());
            }
            var clips = new List <Polygon>();

            for (int i = 0; i < bbox.Count - 1; i++)
            {
                clips.AddRange(Shaper.Differences(bbox[i].ToList(), bbox[i + 1].ToList()));
            }

            var masses = new List <Mass>();

            for (var i = 0; i < clips.Count; i++)
            {
                masses.Add(new Mass(clips[i], 1 + i, name: i.ToString()));
            }

            // Curves.AddRange(spine);
            // Curves.AddRange(jig);
            Curves.AddRange(clips);
            // Curves.AddRange(bbox);

            foreach (var crv in Curves)
            {
                modelCurves.Add(new ModelCurve(crv));
            }

            foreach (var crv in Polygons)
            {
                modelCurves.Add(new ModelCurve(crv));
            }
            // modelCurves[0].
            output.Model.AddElements(modelCurves);
            output.Model.AddElements(masses);
            return(output);
        }
コード例 #2
0
ファイル: ShaperTests.cs プロジェクト: cs-util/GeometryEx
 public void DifferencesTests()
 {
     for (var i = 0; i < 10; i++)
     {
         var ROTATE    = Shaper.RandomDouble(0.0, 360.0);
         var polygon   = Polygon.Rectangle(Vector3.Origin, new Vector3(100.0, 50.0)).Rotate(Vector3.Origin, ROTATE);
         var subtract  = Polygon.Rectangle(Vector3.Origin, new Vector3(1.0, 20.0));
         var subtracts = new List <Polygon>();
         for (var j = 1; j < 99; j++)
         {
             subtracts.Add(subtract.MoveFromTo(Vector3.Origin, new Vector3(j, 0.0)).Rotate(Vector3.Origin, ROTATE));
         }
         subtract = Polygon.Rectangle(new Vector3(0.0, 30.0), new Vector3(1.0, 50.0));
         for (var j = 1; j < 99; j++)
         {
             subtracts.Add(subtract.MoveFromTo(Vector3.Origin, new Vector3(j, 0.0)).Rotate(Vector3.Origin, ROTATE));
         }
         var polygons = Shaper.Differences(polygon.ToList(), subtracts, 0.01);
         var matl     = new Material(Palette.Aqua, 0.0, 0.0, false, null, false, Guid.NewGuid(), "space");
         var model    = new Model();
         var count    = 0;
         foreach (var shape in polygons)
         {
             model.AddElement(new Space(shape, 0.1, BuiltInMaterials.Concrete));
             count++;
         }
         foreach (var shape in subtracts)
         {
             model.AddElement(new Space(shape, 4.0, matl));
             count++;
         }
         Assert.True(count > 196);
         var fileName = "../../../../GeometryExTests/output/Shaper.DifferenceTest" + ROTATE.ToString() + ".glb";
         model.ToGlTF(fileName);
     }
 }
コード例 #3
0
        /// <summary>
        /// Generates Rooms of a supplied area on each incoming Level deployed along the Level's straight skeleton spine which is used as a central corridor path.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A RoomsByLevelsOutputs instance containing computed results and the model with any new elements.</returns>
        public static RoomsByLevelsOutputs Execute(Dictionary <string, Model> inputModels, RoomsByLevelsInputs input)
        {
            var levels = new List <LevelPerimeter>();

            inputModels.TryGetValue("Levels", out var lvlModel);
            if (lvlModel != null)
            {
                levels.AddRange(lvlModel.AllElementsOfType <LevelPerimeter>());
            }
            if (levels.Count == 0)
            {
                throw new ArgumentException("No LevelPerimeters found.");
            }
            levels = levels.OrderBy(l => l.Elevation).ToList();
            var stories = new List <Story>();

            for (var i = 0; i < levels.Count - 1; i++)
            {
                var perimeter = levels[i].Perimeter;
                var elevation = levels[i].Elevation;
                var height    = (levels[i + 1].Elevation - levels[i].Elevation) - 0.5; // replace this number with a plenum height
                var spine     = levels[i].Perimeter.Spine();
                var sections  = levels[i].Perimeter.Jigsaw();
                var endSects  = new List <Polygon>();
                var midSects  = new List <Polygon>();
                var corridors = new List <Polygon>();
                var story     =
                    new Story(perimeter)
                {
                    Elevation = elevation
                };
                foreach (var line in spine)
                {
                    corridors.Add(line.ToPolyline().Offset(input.CorridorWidth * 0.5, EndType.Square).First());
                }
                corridors = Shaper.Merge(corridors);
                foreach (var corridor in corridors)
                {
                    story.AddCorridor(new RoomKit.Room(corridor.Straighten(input.CorridorWidth * 0.1).Simplify(input.CorridorWidth * 0.9), height), false);
                }
                foreach (var polygon in sections)
                {
                    if (polygon.Vertices.Count == 3)
                    {
                        endSects.Add(polygon.AlignedBox());
                        continue;
                    }
                    midSects.Add(polygon);
                }
                var scaffolds = new List <Polygon>(endSects);
                foreach (var midSect in midSects)
                {
                    scaffolds.AddRange(Shaper.Differences(midSect.ToList(), endSects));
                }
                var roomRows = new List <RoomRow>();
                foreach (var polygon in scaffolds)
                {
                    roomRows.Add(new RoomRow(polygon));
                }
                foreach (var row in roomRows)
                {
                    var result = row.AddRoomByArea(row.Area * 0.5, height, elevation);
                    result = row.AddRoomByArea(row.Area * 0.5, height, elevation);
                    row.Infill(height, true);
                }
                var rowRooms = new List <RoomKit.Room>();
                foreach (var row in roomRows)
                {
                    rowRooms.AddRange(row.Rooms);
                }
                foreach (var room in rowRooms)
                {
                    story.AddRoom(room);
                }
                stories.Add(story);
            }
            var rooms = new List <Elements.Room>();

            foreach (var story in stories)
            {
                foreach (var room in story.Rooms)
                {
                    room.Color = Palette.Aqua;
                    var solid   = new Elements.Geometry.Solids.Extrude(room.Perimeter, room.Height, Vector3.ZAxis, false);
                    var geomRep = new Representation(new List <Elements.Geometry.Solids.SolidOperation>()
                    {
                        solid
                    });
                    rooms.Add(new Elements.Room(room.Perimeter,
                                                Vector3.ZAxis,
                                                "", "", "", "",
                                                input.RoomArea,
                                                room.Ratio,
                                                0.0,
                                                room.Elevation,
                                                room.Height,
                                                room.Area,
                                                null,
                                                room.ColorAsMaterial,
                                                geomRep,
                                                false,
                                                Guid.NewGuid(),
                                                room.Name));
                }
                foreach (var room in story.Corridors)
                {
                    room.Color = Palette.White;
                    var solid   = new Elements.Geometry.Solids.Extrude(room.Perimeter, room.Height, Vector3.ZAxis, false);
                    var geomRep = new Representation(new List <Elements.Geometry.Solids.SolidOperation>()
                    {
                        solid
                    });
                    rooms.Add(new Elements.Room(room.Perimeter,
                                                Vector3.ZAxis,
                                                "", "", "", "",
                                                input.RoomArea,
                                                room.Ratio,
                                                0.0,
                                                room.Elevation,
                                                room.Height,
                                                room.Area,
                                                null,
                                                room.ColorAsMaterial,
                                                geomRep,
                                                false,
                                                Guid.NewGuid(),
                                                room.Name));
                }
            }
            var output = new RoomsByLevelsOutputs(rooms.Count / levels.Count, rooms.Count);

            foreach (var room in rooms)
            {
                output.Model.AddElement(room);
            }
            return(output);
        }