// Fallback
        private static IGeometry GeometricalRepresentation(this IObject obj, RepresentationOptions reprOptions = null)
        {
            IGeometry geometricalRepresentation = null;

            // - Check if the object is a IGeometry, and if it is return itself.
            geometricalRepresentation = obj as IGeometry;
            if (geometricalRepresentation != null)
            {
                return(geometricalRepresentation);
            }

            // - If not, check if the object is a IBHoMObject whose IGeometry can be returned.
            IBHoMObject bHoMObject = obj as IBHoMObject;

            if (bHoMObject != null)
            {
                geometricalRepresentation = BH.Engine.Base.Query.IGeometry(bHoMObject);
            }

            // - Empty CompositeGeometries must not be considered valid.
            if (geometricalRepresentation != null)
            {
                if (geometricalRepresentation is CompositeGeometry && (geometricalRepresentation as CompositeGeometry).Elements.Count < 1)
                {
                    geometricalRepresentation = null;
                }
            }

            return(geometricalRepresentation);
        }
                     "The Geometrical Representation is an IGeometry that can be used to represent the object in another environment.")] //e.g. to 3D-print a point, you want to print a Sphere.
        public static IGeometry IGeometricalRepresentation(this IObject obj, RepresentationOptions reprOptions = null)
        {
            if (obj == null)
            {
                return(null);
            }

            reprOptions = reprOptions ?? new RepresentationOptions();

            IGeometry geometricalRepresentation = null;

            // - Dynamic dispatch
            geometricalRepresentation = GeometricalRepresentation(obj as dynamic, reprOptions);
            if (geometricalRepresentation != null)
            {
                return(geometricalRepresentation);
            }

            // Throw error if not found (but only if the object is not a CustomObject)
            if (geometricalRepresentation == null & !(obj is CustomObject)) // do not throw error for CustomObjects.
            {
                throw new Exception($"Could not compute the Geometrical Representation for the object of type {obj.GetType().Name}.");
            }

            return(geometricalRepresentation);
        }
Ejemplo n.º 3
0
        public static IGeometry GeometricalRepresentation(this Panel panel, RepresentationOptions reprOptions = null)
        {
            if (panel == null)
            {
                BH.Engine.Base.Compute.RecordError("Cannot compute the geometrical representation of a null Structural Panel.");
                return(null);
            }

            reprOptions = reprOptions ?? new RepresentationOptions();

            PlanarSurface centralPlanarSurface = Engine.Geometry.Create.PlanarSurface(
                Engine.Geometry.Compute.IJoin(panel.ExternalEdges.Select(x => x.Curve).ToList()).FirstOrDefault(),
                panel.Openings.SelectMany(x => Engine.Geometry.Compute.IJoin(x.Edges.Select(y => y.Curve).ToList())).Cast <ICurve>().ToList());

            if (!reprOptions.Detailed2DElements) //simple representation
            {
                return(centralPlanarSurface);
            }
            else
            {
                CompositeGeometry compositeGeometry = new CompositeGeometry();

                double thickness     = panel.Property.IAverageThickness();
                Vector translateVect = new Vector()
                {
                    Z = -thickness / 2
                };
                Vector extrudeVect = new Vector()
                {
                    Z = thickness
                };

                Vector upHalf = new Vector()
                {
                    X = 0, Y = 0, Z = thickness / 2
                };
                Vector downHalf = new Vector()
                {
                    X = 0, Y = 0, Z = -thickness / 2
                };

                PlanarSurface topSrf = centralPlanarSurface.ITranslate(upHalf) as PlanarSurface;
                PlanarSurface botSrf = centralPlanarSurface.ITranslate(downHalf) as PlanarSurface;

                IEnumerable <ICurve>    internalEdgesBot        = panel.InternalElementCurves().Select(c => c.ITranslate(translateVect));
                IEnumerable <Extrusion> internalEdgesExtrusions = internalEdgesBot.Select(c => BH.Engine.Geometry.Create.Extrusion(c, extrudeVect));

                IEnumerable <ICurve>    externalEdgesBot        = panel.ExternalEdges.Select(c => c.Curve.ITranslate(translateVect));
                IEnumerable <Extrusion> externalEdgesExtrusions = externalEdgesBot.Select(c => BH.Engine.Geometry.Create.Extrusion(c, extrudeVect));

                compositeGeometry.Elements.Add(topSrf);
                compositeGeometry.Elements.Add(botSrf);
                compositeGeometry.Elements.AddRange(internalEdgesExtrusions);
                compositeGeometry.Elements.AddRange(externalEdgesExtrusions);

                return(compositeGeometry);
            }
        }
Ejemplo n.º 4
0
        public static IGeometry GeometricalRepresentation(this ICurve curve, RepresentationOptions reprOptions = null)
        {
            reprOptions = reprOptions ?? new RepresentationOptions();

            if (!reprOptions.Detailed1DElements)
            {
                return(curve);
            }

            double radius = 0.01 * reprOptions.Element1DScale;
            bool   capped = reprOptions.Cap1DElements;

            return(BH.Engine.Geometry.Create.Pipe(curve, radius, capped));
        }
Ejemplo n.º 5
0
        public static IGeometry GeometricalRepresentation(this Point point, RepresentationOptions reprOptions = null, bool isSubObject = false)
        {
            if (isSubObject) // if it is a property of another object (e.g. a Line) do not display its endpoints.
            {
                return(null);
            }

            reprOptions = reprOptions ?? new RepresentationOptions();

            double radius = 0.15 * reprOptions.Element0DScale;
            Sphere sphere = BH.Engine.Geometry.Create.Sphere(point, radius);

            return(sphere);
        }
Ejemplo n.º 6
0
        // Required because of weird behaviour of IGeometry() on CustomObjects. See below.
        private static IGeometry GeometricalRepresentation(this CustomObject obj, RepresentationOptions reprOptions = null)
        {
            IGeometry geometricalRepresentation = null;

            if (obj != null)
            {
                geometricalRepresentation = BH.Engine.Base.Query.IGeometry(obj);
            }

            // Weirdly, by default, IGeometry() on a CustomObject always returns an empty CompositeGeometry.
            // This would generate a lot of needed checks downhill; so instead, return null.
            if (geometricalRepresentation != null && (geometricalRepresentation as CompositeGeometry).Elements.Count < 1)
            {
                geometricalRepresentation = null;
            }

            return(geometricalRepresentation);
        }
Ejemplo n.º 7
0
        public static IGeometry GeometricalRepresentation(this Bar bar, RepresentationOptions reprOptions = null)
        {
            if (bar == null)
            {
                BH.Engine.Base.Compute.RecordError("Cannot compute the geometrical representation of a null bar.");
                return(null);
            }

            reprOptions = reprOptions ?? new RepresentationOptions();

            if (!reprOptions.Detailed1DElements)
            {
                return(bar.Centreline()); //returns the piped centreline.
            }
            else
            {
                // Gets the BH.oM.Geometry.Extrusion out of the Bar. If the profile is made of two curves (e.g. I section), selects only the outermost.
                Extrusion barOutermostExtrusion = bar.Extrude(false).Cast <Extrusion>().OrderBy(extr => extr.Curve.IArea()).First();
                barOutermostExtrusion.Capped = reprOptions.Cap1DElements;

                return(barOutermostExtrusion);
            }
        }
Ejemplo n.º 8
0
        public static IGeometry GeometricalRepresentation(this Node node, RepresentationOptions reprOptions = null, bool isSubObject = false)
        {
            if (node == null)
            {
                BH.Engine.Base.Compute.RecordError("Cannot compute the geometrical representation of a null node.");
                return(null);
            }

            reprOptions = reprOptions ?? new RepresentationOptions();

            if (node.Position == null)
            {
                BH.Engine.Base.Compute.RecordError("Specified Node does not have a position defined.");
                return(null);
            }

            if (node.Support == null || !reprOptions.Detailed0DElements) // If there is no support information, or by choice...
            {
                return(node.Position);                                   // ...just return the representation for the point.
            }
            // -------------------------------------------- //
            // -------- Compute the representation -------- //
            // -------------------------------------------- //

            // Design different representations for different DOF type.

            // For now, all the following DOFTypes are considered "fixed". More, differentiated representations can be added later
            DOFType[] fixedDOFTypes = new[] { DOFType.Fixed, DOFType.FixedNegative, DOFType.FixedPositive, DOFType.Spring, DOFType.Friction, DOFType.Damped, DOFType.SpringPositive, DOFType.SpringNegative };

            bool fixedToTranslation = fixedDOFTypes.Contains(node.Support.TranslationX) || fixedDOFTypes.Contains(node.Support.TranslationY) || fixedDOFTypes.Contains(node.Support.TranslationZ);
            bool fixedToRotation    = fixedDOFTypes.Contains(node.Support.RotationX) || fixedDOFTypes.Contains(node.Support.RotationY) || fixedDOFTypes.Contains(node.Support.RotationZ);

            if (fixedToTranslation && fixedToRotation)
            {
                // Fully fixed: box
                double boxDims = 0.2 * reprOptions.Element0DScale;

                var         centrePoint = node.Position;
                BoundingBox bbox        = BH.Engine.Geometry.Create.BoundingBox(
                    new Point()
                {
                    X = centrePoint.X + 2 * boxDims, Y = centrePoint.Y + 2 * boxDims, Z = centrePoint.Z + boxDims * 1.5
                },
                    new Point()
                {
                    X = centrePoint.X - 2 * boxDims, Y = centrePoint.Y - 2 * boxDims, Z = centrePoint.Z - boxDims * 1.5
                });

                return(bbox);
            }

            if (fixedToTranslation && !fixedToRotation)
            {
                // Pin: cone + sphere
                double radius = 0.15 * reprOptions.Element0DScale;

                CompositeGeometry compositeGeometry = new CompositeGeometry();

                Sphere sphere = BH.Engine.Geometry.Create.Sphere(node.Position, radius);
                compositeGeometry.Elements.Add(sphere);

                double coneHeight = 4 * radius;

                Cone cone = BH.Engine.Geometry.Create.Cone(
                    new Point()
                {
                    X = node.Position.X, Y = node.Position.Y, Z = node.Position.Z - radius / 2 - coneHeight
                },
                    new Vector()
                {
                    X = 0, Y = 0, Z = 1
                },
                    3 * radius,
                    coneHeight
                    );
                compositeGeometry.Elements.Add(cone);

                return(compositeGeometry);
            }

            // Else: we could add more for other DOFs; for now just return the representation for its point.
            if (!isSubObject)
            {
                return(node.Position.GeometricalRepresentation(reprOptions));
            }
            else
            {
                return(null); //do not return representation for point if the Nodes are sub-objects (e.g. of a bar)
            }
        }