// // (C) Copyright 2003-2019 by Autodesk, Inc. All rights reserved. // // Permission to use, copy, modify, and distribute this software in // object code form for any purpose and without fee is hereby granted // provided that the above copyright notice appears in all copies and // that both that copyright notice and the limited warranty and // restricted rights notice below appear in all supporting // documentation. // // AUTODESK PROVIDES THIS PROGRAM 'AS IS' AND WITH ALL ITS FAULTS. // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE // UNINTERRUPTED OR ERROR FREE. // // Use, duplication, or disclosure by the U.S. Government is subject to // restrictions set forth in FAR 52.227-19 (Commercial Computer // Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) // (Rights in Technical Data and Computer Software), as applicable. using System; using System.Collections.Generic; using System.Linq; using System.Text; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Architecture; namespace Revit.SDK.Samples.Site.CS { /// /// Database level utilities for the site editing commands. /// class SiteEditingUtils { /// /// Moves an XYZ point to the elevation specified. /// /// The input. /// The elevation. /// The new point. public static XYZ MoveXYZToElevation(XYZ input, double elevation) { return input + XYZ.BasisZ * (elevation - input.Z); } /// /// Gets the average elevation (z) from a collection of points. /// /// The points. /// The average elevation. public static double GetAverageElevation(IList existingPoints) { if (existingPoints.Count == 0) { return 0; } return existingPoints.Average(xyz => xyz.Z); } /// /// Gets the boundary points for the circular retaining pond surrounding the input point. /// /// The point. The elevation of this point is assumed to be at the bottom of the pond. /// The outer radius for the pond. /// The collection of points representing the pond. public static IList GeneratePondPointsSurrounding(XYZ center, double maxRadius) { if (maxRadius <= 8) throw new Exception("Pond radius must be greater than 8"); List points = new List(); points.Add(center); GenerateCircleSurrounding(points, center, 1, maxRadius - 8); GenerateCircleSurrounding(points, center, 2, maxRadius - 5); GenerateCircleSurrounding(points, center, 3, maxRadius - 1); return points; } /// /// Generates the points representing a circular region around the center. /// /// The collection of points to which the results are added. /// The center. /// The change in elevation relative to the center. /// The radius of the circular region. private static void GenerateCircleSurrounding(IList points, XYZ center, double deltaElevation, double radius) { for (double theta = 0; theta < 2 * Math.PI; theta += Math.PI / 6.0) { XYZ targetPoint = center + new XYZ(radius * Math.Cos(theta), radius * Math.Sin(theta), deltaElevation); points.Add(targetPoint); } } /// /// Gets the center of the element's bounding box. /// /// The element. /// The center of the bounding box. public static XYZ GetCenterOf(Element element) { BoundingBoxXYZ bbox = element.get_BoundingBox(null); return (bbox.Min + bbox.Max) / 2.0; } /// /// Gets the points from a rectangular outline surrounding the subregion bounding box. /// /// The subregion. /// The points. public static IList GetPointsFromSubregionRough(TopographySurface subregion) { BoundingBoxXYZ bbox = subregion.get_BoundingBox(null); // Get toposurface points TopographySurface toposurface = GetTopographySurfaceHost(subregion); Outline outline = new Outline(bbox.Min, bbox.Max); IList points = toposurface.FindPoints(outline); return points; } /// /// Gets the points stored by a subregion. /// /// The subregion. /// The points public static IList GetPointsFromSubregionExact(TopographySurface subregion) { return subregion.GetPoints(); } /// /// Gets the TopographySurface host for a subregion. /// /// The subregion. /// The host TopographySurface. public static TopographySurface GetTopographySurfaceHost(TopographySurface subregion) { TopographySurface toposurface = subregion.Document.GetElement(subregion.AsSiteSubRegion().HostId) as TopographySurface; return toposurface; } /// /// Gets all non-boundary points from a TopographySurface or Subregion. /// /// The TopographySurface or Subregion. /// The non-boundary points. public static IList GetNonBoundaryPoints(TopographySurface toposurface) { return toposurface.GetInteriorPoints(); } } }