Beispiel #1
0
        /***************************************************/

        private static Point ReferencePoint(IEnumerable <ICurve> hostRegionCurves, IEnumerable <ICurve> openingCurves, ReferencePoint referencePoint)
        {
            if (referencePoint == oM.Spatial.Layouts.ReferencePoint.Centroid)
            {
                return(CentroidWithOpeings(hostRegionCurves.ToList(), openingCurves.ToList()));
            }
            BoundingBox bounds = Geometry.Query.Bounds(hostRegionCurves.Select(x => x.IBounds()).ToList());

            switch (referencePoint)
            {
            case oM.Spatial.Layouts.ReferencePoint.BottomLeft:
                return(new Point {
                    X = bounds.Min.X, Y = bounds.Min.Y
                });

            case oM.Spatial.Layouts.ReferencePoint.BottomCenter:
                return(new Point {
                    X = (bounds.Min.X + bounds.Max.X) / 2, Y = bounds.Min.Y
                });

            case oM.Spatial.Layouts.ReferencePoint.BottomRight:
                return(new Point {
                    X = bounds.Max.X, Y = bounds.Min.Y
                });

            case oM.Spatial.Layouts.ReferencePoint.MiddleLeft:
                return(new Point {
                    X = bounds.Min.X, Y = bounds.Min.Y
                });

            case oM.Spatial.Layouts.ReferencePoint.MiddleCenter:
                return(bounds.Centre());

            case oM.Spatial.Layouts.ReferencePoint.MiddleRight:
                return(new Point {
                    X = bounds.Max.X, Y = (bounds.Min.Y + bounds.Max.Y) / 2
                });

            case oM.Spatial.Layouts.ReferencePoint.TopLeft:
                return(new Point {
                    X = bounds.Min.X, Y = bounds.Max.Y
                });

            case oM.Spatial.Layouts.ReferencePoint.TopCenter:
                return(new Point {
                    X = (bounds.Min.X + bounds.Max.X) / 2, Y = bounds.Max.Y
                });

            case oM.Spatial.Layouts.ReferencePoint.TopRight:
                return(new Point {
                    X = bounds.Max.X, Y = bounds.Max.Y
                });

            default:
                return(CentroidWithOpeings(hostRegionCurves.ToList(), openingCurves.ToList()));
            }
        }
Beispiel #2
0
        public static List <Point> PointLayout(this LinearLayout layout2D, IEnumerable <ICurve> hostRegionCurves, IEnumerable <ICurve> openingCurves = null)
        {
            Point       refPoint = ReferencePoint(hostRegionCurves, openingCurves, layout2D.ReferencePoint);
            BoundingBox bounds   = Geometry.Query.Bounds(hostRegionCurves.Select(x => x.IBounds()).ToList());

            refPoint = refPoint + layout2D.Offset * AlignOffsetVector(Vector.ZAxis.CrossProduct(layout2D.Direction), refPoint, bounds.Centre());
            Line axis = new Line {
                Start = refPoint, End = refPoint + layout2D.Direction, Infinite = true
            };

            List <Line> distributionLines = IntersectionLines(hostRegionCurves, openingCurves, axis);

            if (distributionLines.Count == 0)
            {
                Engine.Reflection.Compute.RecordError("Count not find extents of distribution for the layout.");
                return(new List <Point>());
            }

            return(DivisionPoints(distributionLines, layout2D.NumberOfPoints));
        }
Beispiel #3
0
        public static List <Point> PointLayout(this MultiLinearLayout layout2D, IEnumerable <ICurve> hostRegionCurves, IEnumerable <ICurve> openingCurves = null)
        {
            Point       refPoint  = ReferencePoint(hostRegionCurves, openingCurves, layout2D.ReferencePoint);
            BoundingBox bounds    = Geometry.Query.Bounds(hostRegionCurves.Select(x => x.IBounds()).ToList());
            Vector      offsetDir = AlignOffsetVector(Vector.ZAxis.CrossProduct(layout2D.Direction), refPoint, bounds.Centre());

            refPoint = refPoint + layout2D.Offset * offsetDir;
            int remainingPoints = layout2D.NumberOfPoints;

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


            offsetDir = offsetDir.Normalise() * layout2D.PerpendicularMinimumSpacing;

            while (remainingPoints > 0)
            {
                Line axis = new Line {
                    Start = refPoint, End = refPoint + layout2D.Direction, Infinite = true
                };
                List <Line> distributionLines = IntersectionLines(hostRegionCurves, openingCurves, axis, layout2D.ParallelMinimumSpacing);

                if (distributionLines.Count == 0)
                {
                    //No lines found and axis is within boundingbox of the curve, try next layer
                    if (axis.IsInRange(bounds) && offsetDir.SquareLength() != 0)
                    {
                        Engine.Reflection.Compute.RecordNote("Could not find distribution lines for one or more layer.");
                        refPoint += offsetDir;
                        continue;
                    }
                    else
                    {
                        //No more lines can be found
                        Engine.Reflection.Compute.RecordError("Could not generate distribution lines for the reinforcement. The number of points might not fit in the region curve. The resulting number of points might be different from the number requested.");
                        remainingPoints = 0;
                    }
                }

                int layerDivs = 0;
                for (int i = 0; i < distributionLines.Count; i++)
                {
                    int divs = (int)Math.Ceiling(distributionLines[i].ILength() / layout2D.ParallelMinimumSpacing);
                    layerDivs += divs;
                }

                layerDivs = Math.Min(layerDivs, remainingPoints);

                //SamplePoints adds extra point at start/ end.Hence subtracting count here to make sure correct number is extracted.
                result.AddRange(DivisionPoints(distributionLines, layerDivs));
                remainingPoints -= layerDivs;

                //Find next layer by moving the centre of the axis
                refPoint += offsetDir;
            }

            return(result);
        }
Beispiel #4
0
        /***************************************************/
        /**** Private Methods                           ****/
        /***************************************************/

        public static bool IsContaining(IGeometry container, IObject iObj, ContainmentRules containmentRule = ContainmentRules.Geometry, bool acceptOnEdge = true, double tolerance = Tolerance.Distance)
        {
            bool passed = false;

            if (iObj == null)
            {
                return(passed);
            }

            IGeometry geom = null;

            if (containmentRule == ContainmentRules.AtLeastOneGeometryPoint)
            {
                geom = BH.Engine.CIH.Query.IGeometry(iObj);
                List <Point> points = BH.Engine.CIH.Query.IPoints(geom);
                foreach (Point pt in points)
                {
                    if (container.IIsContaining(pt))
                    {
                        passed = true;
                        break;
                    }
                }
            }
            else if (containmentRule == ContainmentRules.Geometry3D)
            {
                geom = BH.Engine.Base.Query.IGeometry3D(iObj);
                BoundingBox bb = BH.Engine.Geometry.Query.IBounds(geom);

                if (container.IIsContaining(bb))
                {
                    passed = true;
                }
            }
            else if (containmentRule == ContainmentRules.BoundingBoxCentre)
            {
                geom = BH.Engine.Base.Query.IGeometry3D(iObj);
                BoundingBox bb = BH.Engine.Geometry.Query.IBounds(geom);

                if (container.IIsContaining(bb.Centre()))
                {
                    passed = true;
                }
            }
            else
            {
                // Fall back on ContainmentRule = "Geometry"
                geom = BH.Engine.CIH.Query.IGeometry(iObj);

                BoundingBox bb = BH.Engine.Geometry.Query.IBounds(geom);

                //BoundingBox containerBB = container as BoundingBox;

                ////containerBB.Max += new Vector() { X = 1, Y = 1, Z = 1 };
                ////containerBB.Min += new Vector() { X = -1, Y = -1, Z = -1 };

                if (container.IIsContaining(bb))
                {
                    passed = true;
                }
            }

            return(passed);
        }