Ejemplo n.º 1
0
        public static List <Face3D> ToSAM_Face3Ds(this Mesh mesh)
        {
            List <Triangle3D> triangle3Ds = ToSAM_Triangle3Ds(mesh);

            if (triangle3Ds == null)
            {
                return(null);
            }

            List <Face3D> result = new List <Face3D>();

            foreach (Triangle3D triangle3D in triangle3Ds)
            {
                if (triangle3D == null || !triangle3D.IsValid())
                {
                    continue;
                }

                Face3D face3D = new Face3D(triangle3D);
                if (!face3D.IsValid())
                {
                    continue;
                }

                result.Add(face3D);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static double HydraulicDiameter(this Face3D face3D, double tolerance = Core.Tolerance.Distance)
        {
            Plane plane_Face3D = face3D?.GetPlane();

            if (plane_Face3D == null)
            {
                return(double.NaN);
            }
            Plane plane = Plane.WorldXY;

            if (plane.Perpendicular(plane_Face3D, tolerance))
            {
                return(0);
            }

            Face3D face3D_Project = plane.Project(face3D);

            if (face3D_Project == null || !face3D_Project.IsValid())
            {
                return(0);
            }

            Planar.ISegmentable2D segmentable2D = face3D_Project.ExternalEdge2D as Planar.ISegmentable2D;
            if (segmentable2D == null)
            {
                throw new System.NotImplementedException();
            }

            double area = face3D_Project.GetArea();

            if (area <= tolerance)
            {
                return(0);
            }

            //return (4 * area) / segmentable2D.GetLength();
            return(segmentable2D.GetLength());
        }
Ejemplo n.º 3
0
        public static bool UpdateShading(this AnalyticalModel analyticalModel, TBD.Building building, double tolerance = Core.Tolerance.Distance)
        {
            if (building == null || analyticalModel == null)
            {
                return(false);
            }

            List <TBD.zone> zones = building.Zones();

            if (zones == null)
            {
                return(false);
            }

            List <Tuple <Face3D, BoundingBox3D, TBD.IZoneSurface, int, int> > tuples_ZoneSurfaces = new List <Tuple <Face3D, BoundingBox3D, TBD.IZoneSurface, int, int> >();

            int index_Zone = 0;

            foreach (TBD.zone zone in zones)
            {
                List <TBD.IZoneSurface> zoneSurfaces_Zone = zone?.ZoneSurfaces();
                if (zoneSurfaces_Zone == null)
                {
                    continue;
                }

                int index_Surface = 0;
                foreach (TBD.IZoneSurface zoneSurface in zoneSurfaces_Zone)
                {
                    List <TBD.IRoomSurface> roomSurfaces = zoneSurface.RoomSurfaces();
                    if (roomSurfaces == null)
                    {
                        continue;
                    }

                    foreach (TBD.IRoomSurface roomSurface in roomSurfaces)
                    {
                        Face3D face3D = Geometry.Tas.Convert.ToSAM(roomSurface?.GetPerimeter());
                        if (face3D == null || !face3D.IsValid())
                        {
                            continue;
                        }

                        tuples_ZoneSurfaces.Add(new Tuple <Face3D, BoundingBox3D, TBD.IZoneSurface, int, int>(face3D, face3D.GetBoundingBox(), zoneSurface, index_Zone, index_Surface));
                    }

                    index_Surface++;
                }
                index_Zone++;
            }

            if (tuples_ZoneSurfaces == null || tuples_ZoneSurfaces.Count == 0)
            {
                return(false);
            }

            List <Panel> panels = analyticalModel.GetPanels();

            if (panels == null)
            {
                return(false);
            }

            List <Tuple <Face3D, Point3D, BoundingBox3D, Panel> > tuples_Panel = new List <Tuple <Face3D, Point3D, BoundingBox3D, Panel> >();

            foreach (Panel panel in panels)
            {
                Face3D face3D = panel.Face3D;
                if (face3D == null || !face3D.IsValid())
                {
                    continue;
                }

                BoundingBox3D boundingBox3D = face3D.GetBoundingBox();
                Point3D       point3D       = face3D.GetInternalPoint3D(tolerance);
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 4
0
        public static bool UpdateShading(this TBD.Building building, AnalyticalModel analyticalModel, double tolerance = Core.Tolerance.Distance)
        {
            if (building == null || analyticalModel == null)
            {
                return(false);
            }

            List <TBD.zone> zones = building.Zones();

            if (zones == null)
            {
                return(false);
            }

            List <Tuple <Face3D, BoundingBox3D, TBD.IZoneSurface> > tuples_ZoneSurfaces = new List <Tuple <Face3D, BoundingBox3D, TBD.IZoneSurface> >();

            foreach (TBD.zone zone in zones)
            {
                List <TBD.IZoneSurface> zoneSurfaces_Zone = zone?.ZoneSurfaces();
                if (zoneSurfaces_Zone == null)
                {
                    continue;
                }

                foreach (TBD.IZoneSurface zoneSurface in zoneSurfaces_Zone)
                {
                    List <TBD.IRoomSurface> roomSurfaces = zoneSurface.RoomSurfaces();
                    if (roomSurfaces == null)
                    {
                        continue;
                    }

                    foreach (TBD.IRoomSurface roomSurface in roomSurfaces)
                    {
                        Face3D face3D = Geometry.Tas.Convert.ToSAM(roomSurface?.GetPerimeter());
                        if (face3D == null || !face3D.IsValid())
                        {
                            continue;
                        }

                        tuples_ZoneSurfaces.Add(new Tuple <Face3D, BoundingBox3D, TBD.IZoneSurface>(face3D, face3D.GetBoundingBox(), zoneSurface));
                    }
                }
            }

            if (tuples_ZoneSurfaces == null || tuples_ZoneSurfaces.Count == 0)
            {
                return(false);
            }

            List <Panel> panels = analyticalModel.GetPanels();

            if (panels == null)
            {
                return(false);
            }

            List <Tuple <Face3D, Point3D, BoundingBox3D, Geometry.SolarCalculator.SolarFaceSimulationResult> > tuples_solarFaceSimulationResult = new List <Tuple <Face3D, Point3D, BoundingBox3D, Geometry.SolarCalculator.SolarFaceSimulationResult> >();

            foreach (Panel panel in panels)
            {
                List <Geometry.SolarCalculator.SolarFaceSimulationResult> solarFaceSimulationResults = analyticalModel.GetResults <Geometry.SolarCalculator.SolarFaceSimulationResult>(panel);
                if (solarFaceSimulationResults == null || solarFaceSimulationResults.Count == 0)
                {
                    continue;
                }

                Face3D face3D = panel.Face3D;
                if (face3D == null || !face3D.IsValid())
                {
                    continue;
                }

                BoundingBox3D boundingBox3D = face3D.GetBoundingBox();
                Point3D       point3D       = face3D.GetInternalPoint3D(tolerance);

                foreach (Geometry.SolarCalculator.SolarFaceSimulationResult solarFaceSimulationResult in solarFaceSimulationResults)
                {
                    tuples_solarFaceSimulationResult.Add(new Tuple <Face3D, Point3D, BoundingBox3D, Geometry.SolarCalculator.SolarFaceSimulationResult>(face3D, point3D, boundingBox3D, solarFaceSimulationResult));
                }
            }

            building.ClearShadingData();

            List <TBD.DaysShade> daysShades = new List <TBD.DaysShade>();

            foreach (Tuple <Face3D, Point3D, BoundingBox3D, Geometry.SolarCalculator.SolarFaceSimulationResult> tuple in tuples_solarFaceSimulationResult)
            {
                List <Tuple <Face3D, BoundingBox3D, TBD.IZoneSurface> > tuples_Temp = tuples_ZoneSurfaces.FindAll(x => tuple.Item3.InRange(x.Item2, tolerance));
                tuples_Temp = tuples_Temp.FindAll(x => x.Item1.On(tuple.Item2, tolerance));

                if (tuples_Temp == null || tuples_Temp.Count == 0)
                {
                    continue;
                }

                foreach (Tuple <Face3D, BoundingBox3D, TBD.IZoneSurface> tuple_ZoneSurface in tuples_Temp)
                {
                    UpdateSurfaceShades(building, daysShades, (TBD.zoneSurface)tuple_ZoneSurface.Item3, analyticalModel, tuple.Item4);
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
        public static List <Aperture> ToSAM_Apertures(this FamilyInstance familyInstance, ConvertSettings convertSettings)
        {
            if (familyInstance == null)
            {
                return(null);
            }

            List <Aperture> result = convertSettings?.GetObjects <Aperture>(familyInstance.Id);

            if (result != null)
            {
                return(result);
            }

            if (Core.Revit.Query.Simplified(familyInstance))
            {
                result = Core.Revit.Query.IJSAMObjects <Aperture>(familyInstance);
                if (result != null)
                {
                    convertSettings?.Add(familyInstance.Id, result);
                    return(result);
                }
            }

            Point3D point3D_Location = Geometry.Revit.Query.LocationPoint3D(familyInstance);

            if (point3D_Location == null)
            {
                List <Solid> solids = Core.Revit.Query.Solids(familyInstance, new Options());
                solids?.RemoveAll(x => x.Volume == 0);
                if (solids == null || solids.Count == 0)
                {
                    return(null);
                }

                if (solids.Count > 1)
                {
                    solids.Sort((x, y) => y.Volume.CompareTo(x.Volume));
                }

                point3D_Location = solids[0].ComputeCentroid()?.ToSAM();
            }

            if (point3D_Location == null)
            {
                return(null);
            }

            List <Face3D> face3Ds = null;


            PanelType       panelType_Host       = PanelType.Undefined;
            BuiltInCategory builtInCategory_Host = BuiltInCategory.INVALID;
            HostObject      hostObject           = null;

            if (familyInstance.Host != null)
            {
                hostObject = familyInstance.Host as HostObject;

                if (hostObject != null)
                {
                    builtInCategory_Host = (BuiltInCategory)hostObject.Category.Id.IntegerValue;
                }
            }

            //Method 1 of extracting Geometry
            if (face3Ds == null || face3Ds.Count == 0)
            {
                Vector3D axisX  = null;
                Vector3D normal = null;
                Vector3D axisY  = null;
                if (builtInCategory_Host == BuiltInCategory.OST_Roofs)
                {
                    axisX  = familyInstance.HandOrientation.ToSAM_Vector3D(false);
                    axisY  = familyInstance.FacingOrientation.ToSAM_Vector3D(false);
                    normal = Geometry.Spatial.Query.AxisY(axisY, axisX);
                }
                else
                {
                    axisX  = familyInstance.HandOrientation.ToSAM_Vector3D(false);
                    normal = familyInstance.FacingOrientation.ToSAM_Vector3D(false);
                    axisY  = Geometry.Spatial.Query.AxisY(normal, axisX);
                }

                Geometry.Spatial.Plane plane = Geometry.Spatial.Create.Plane(point3D_Location, axisX, axisY);
                if (!plane.Normal.SameHalf(normal))
                {
                    plane.FlipZ(false);
                }

                List <Shell> shells = Geometry.Revit.Convert.ToSAM_Geometries <Shell>(familyInstance);
                if (shells == null || shells.Count == 0)
                {
                    return(null);
                }

                List <Point2D> point2Ds = new List <Point2D>();
                foreach (Shell shell in shells)
                {
                    List <Face3D> face3Ds_Shell = shell?.Face3Ds;
                    if (face3Ds_Shell == null || face3Ds_Shell.Count == 0)
                    {
                        continue;
                    }

                    foreach (Face3D face3D_Temp in face3Ds_Shell)
                    {
                        ISegmentable3D segmentable3D = face3D_Temp.GetExternalEdge3D() as ISegmentable3D;
                        if (segmentable3D == null)
                        {
                            continue;
                        }

                        segmentable3D?.GetPoints()?.ForEach(x => point2Ds.Add(plane.Convert(x)));
                    }
                }

                Face3D face3D = new Face3D(plane, Geometry.Planar.Create.Rectangle2D(point2Ds));
                if (face3D != null && face3D.IsValid() && face3D.GetArea() > Core.Tolerance.MacroDistance)
                {
                    face3Ds = new List <Face3D>()
                    {
                        face3D
                    };
                }
            }

            //Method 2 of extracting Geometry
            if (hostObject != null)
            {
                builtInCategory_Host = (BuiltInCategory)hostObject.Category.Id.IntegerValue;

                Geometry.Spatial.Plane plane_Host = null;
                if (hostObject is CurtainSystem && familyInstance is Autodesk.Revit.DB.Panel)
                {
                    Autodesk.Revit.DB.Panel panel = (Autodesk.Revit.DB.Panel)familyInstance;
                    ElementId uGridLineElementId  = null;
                    ElementId vGridLineElementId  = null;

                    panel.GetRefGridLines(ref uGridLineElementId, ref vGridLineElementId);

                    CurtainSystem curtainSystem = (CurtainSystem)hostObject;

                    List <Polygon3D> polygon3Ds = curtainSystem.CurtainCell(uGridLineElementId, vGridLineElementId)?.Polygon3Ds();
                    if (polygon3Ds != null && polygon3Ds.Count != 0)
                    {
                        polygon3Ds.Sort((x, y) => y.GetArea().CompareTo(x.GetArea()));
                        plane_Host = polygon3Ds[0].GetPlane();
                    }
                }
                else
                {
                    List <Face3D> face3Ds_Temp = hostObject.Profiles();
                    if (face3Ds_Temp != null && face3Ds_Temp.Count != 0)
                    {
                        plane_Host = face3Ds_Temp.Closest(point3D_Location)?.GetPlane();
                    }
                }

                if (plane_Host != null)
                {
                    face3Ds          = face3Ds?.ConvertAll(x => plane_Host.Project(x));
                    point3D_Location = plane_Host.Project(point3D_Location);
                }


                HostObjAttributes hostObjAttributes = familyInstance.Document.GetElement(hostObject.GetTypeId()) as HostObjAttributes;
                if (hostObjAttributes != null)
                {
                    panelType_Host = hostObjAttributes.PanelType();
                }

                if (panelType_Host == PanelType.Undefined)
                {
                    panelType_Host = hostObject.PanelType();
                }

                List <Face3D> face3Ds_Profiles = hostObject.Profiles(familyInstance.Id);
                face3Ds_Profiles?.RemoveAll(x => x == null || !x.IsValid());
                if (face3Ds_Profiles != null && face3Ds_Profiles.Count > 0)
                {
                    if (face3Ds == null || (face3Ds != null && face3Ds_Profiles.ConvertAll(x => x.GetArea()).Sum() <= face3Ds.ConvertAll(x => x.GetArea()).Sum()))
                    {
                        face3Ds = face3Ds_Profiles;
                    }
                }
            }

            ApertureConstruction apertureConstruction = ToSAM_ApertureConstruction(familyInstance, convertSettings);

            if (apertureConstruction == null && panelType_Host != PanelType.Undefined)
            {
                apertureConstruction = Analytical.Query.DefaultApertureConstruction(panelType_Host, familyInstance.ApertureType()); //Default Aperture Construction
            }
            if (face3Ds == null || face3Ds.Count == 0)
            {
                return(result);
            }

            //TODO: Working on SAM Families (requested by Michal)

            string parameterName_Height = Core.Revit.Query.Name(ActiveSetting.Setting, typeof(Aperture), typeof(FamilyInstance), "GetHeight");
            string parameterName_Width  = Core.Revit.Query.Name(ActiveSetting.Setting, typeof(Aperture), typeof(FamilyInstance), "GetWidth");

            if (!string.IsNullOrWhiteSpace(parameterName_Height) && !string.IsNullOrWhiteSpace(parameterName_Width))
            {
                Parameter parameter_Height = familyInstance.LookupParameter(parameterName_Height);
                Parameter parameter_Width  = familyInstance.LookupParameter(parameterName_Width);
                if (parameter_Height != null && parameter_Width != null && parameter_Height.HasValue && parameter_Width.HasValue && parameter_Height.StorageType == StorageType.Double && parameter_Width.StorageType == StorageType.Double)
                {
#if Revit2017 || Revit2018 || Revit2019 || Revit2020
                    double height = UnitUtils.ConvertFromInternalUnits(parameter_Height.AsDouble(), DisplayUnitType.DUT_METERS);
                    double width  = UnitUtils.ConvertFromInternalUnits(parameter_Width.AsDouble(), DisplayUnitType.DUT_METERS);
#else
                    double height = UnitUtils.ConvertFromInternalUnits(parameter_Height.AsDouble(), UnitTypeId.Meters);
                    double width  = UnitUtils.ConvertFromInternalUnits(parameter_Width.AsDouble(), UnitTypeId.Meters);
#endif
                }
            }

            result = new List <Aperture>();
            foreach (Face3D face3D_Temp in face3Ds)
            {
                Aperture aperture = Analytical.Create.Aperture(apertureConstruction, face3D_Temp);
                if (aperture == null)
                {
                    continue;
                }

                aperture.UpdateParameterSets(familyInstance, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));
                result.Add(aperture);
            }

            convertSettings?.Add(familyInstance.Id, result);

            return(result);
        }