public static (List <Polygon> polygons, List <string> colors) MakeBuilding(Polygon footprint, double fromZ, double height, BuildingStyle buildingStyle)
        {
            var result = new List <Polygon>();
            var colors = new List <string>();

            var floor = Tesselate(footprint, fromZ);
            var roof  = Tesselate(footprint, fromZ + height);

            colors.AddRange(GetColors(floor, buildingStyle.FloorColor));
            colors.AddRange(GetColors(roof, buildingStyle.RoofColor));

            result.AddRange(floor);
            result.AddRange(roof);

            if (buildingStyle.Storeys == null)
            {
                var walls = MakeWalls(footprint, fromZ, height - fromZ);
                colors.AddRange(GetColors(walls, buildingStyle.WallsColor));
                result.AddRange(walls);
            }
            else
            {
                foreach (var storey in buildingStyle.Storeys)
                {
                    var walls = MakeWalls(footprint, fromZ + storey.From, storey.To - storey.From);
                    colors.AddRange(GetColors(walls, storey.Color));
                    result.AddRange(walls);
                }
            }

            return(result, colors);
        }
Example #2
0
        public static (PolyhedralSurface polyhedral, List <string> colors) MakeBuilding(Polygon footprint, double fromZ, double height, BuildingStyle buildingStyle)
        {
            var colors     = new List <string>();
            var polyhedral = new PolyhedralSurface();

            polyhedral.Dimension = Dimension.Xyz;

            polyhedral.Geometries.Add(GetPolygonZ(footprint, fromZ));
            polyhedral.Geometries.Add(GetPolygonZ(footprint, fromZ + height));
            if (buildingStyle.Storeys == null)
            {
                var walls = MakeWalls(footprint, fromZ, height - fromZ);
                polyhedral.Geometries.AddRange(walls);
            }
            else
            {
                {
                    foreach (var storey in buildingStyle.Storeys)
                    {
                        var walls = MakeWalls(footprint, fromZ + storey.From, storey.To - storey.From);
                        polyhedral.Geometries.AddRange(walls);
                    }
                }
            }

            var stream = new MemoryStream();

            polyhedral.Serialize <WkbSerializer>(stream);
            var wkb             = stream.ToArray();
            var triangulatedWkb = Triangulator.Triangulate(wkb);
            var polyhedralNew   = (PolyhedralSurface)Geometry.Deserialize <WkbSerializer>(triangulatedWkb);

            foreach (var polygon in polyhedralNew.Geometries)
            {
                var normal = polygon.GetNormal();

                if (Math.Abs(normal.X) > Math.Abs(normal.Y) && Math.Abs(normal.X) > Math.Abs(normal.Z) ||
                    (Math.Abs(normal.Y) > Math.Abs(normal.Z)))
                {
                    //  (yz) projection
                    if (buildingStyle.WallsColor == null)
                    {
                        // use storeys
                        var storeyColor = GetStoreyColor(polygon, buildingStyle.Storeys);
                        colors.Add(storeyColor);
                    }
                    else
                    {
                        colors.Add(buildingStyle.WallsColor);
                    }
                }
                else
                {
                    // (xy) projextion
                    if (polygon.ExteriorRing.Points[0].Z == fromZ)
                    {
                        // floor
                        colors.Add(buildingStyle.FloorColor);
                    }
                    else
                    {
                        // roof
                        colors.Add(buildingStyle.RoofColor);
                    }
                }
            }
            return(polyhedralNew, colors);
        }
        public static (PolyhedralSurface polyhedral, List <string> colors) MakePolyHedral(Polygon footprint, double fromZ, double height, BuildingStyle buildingStyle)
        {
            var polyhedral = new PolyhedralSurface();

            var res = MakeBuilding(footprint, fromZ, height, buildingStyle);

            foreach (var t in res.polygons)
            {
                polyhedral.Geometries.Add(t);
            }

            return(polyhedral, res.colors);
        }