Пример #1
0
        /// <summary>
        /// Get surface points inside a closed boundary
        /// </summary>
        /// <param name="boundary">A closed curve</param>
        /// <param name="tolerance">A value between 0 and 1 to define the precision of the tessellation along non-straight curves.</param>
        /// <returns>
        /// The List of Points
        /// </returns>
        public List <Point> GetPointsInBoundary(Curve boundary, double tolerance = 0.1)
        {
            Utils.Log(string.Format("CivilSurface.GetPointsInBoundary started...", ""));

            if (!boundary.IsClosed)
            {
                string message = "The Curve provided is not closed.";

                Utils.Log(string.Format("ERROR: CivilSurface.GetPointsInBoundary {0}", message));

                throw new Exception(message);
            }

            Plane xy = Plane.XY();

            Curve boundaryXY = boundary.PullOntoPlane(xy);

            Surface surf = null;

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

            Polygon polygon = null;

            try
            {
                surf = Surface.ByPatch(boundaryXY);
            }
            catch
            {
                string message = "Unable to create surface form boundary.";

                Utils.Log(string.Format("ERROR: CivilSurface.GetPointsInBoundary {0}", message));
            }

            if (surf != null)
            {
                pointsInside = this.GetSurfacePoints().Where(p => Point.ByCoordinates(p.X, p.Y).DoesIntersect(surf)).ToList();
            }
            else
            {
                if (tolerance <= 0 || tolerance > 1)
                {
                    tolerance = 1;
                }

                if (boundary is PolyCurve)
                {
                    PolyCurve pc = boundary as PolyCurve;

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

                    for (int i = 0; i < pc.NumberOfCurves; ++i)
                    {
                        Curve c = pc.CurveAtIndex(i);

                        try
                        {
                            Line line = c as Line;
                            points.Add(c.StartPoint);
                        }
                        catch
                        {
                            for (double j = 0; j < 1; j = j + tolerance)
                            {
                                points.Add(c.PointAtParameter(j));
                            }
                        }

                        c.Dispose();
                    }

                    polygon = Polygon.ByPoints(points.Select(p => Point.ByCoordinates(p.X, p.Y)));

                    foreach (var item in points)
                    {
                        if (item != null)
                        {
                            item.Dispose();
                        }
                    }

                    points.Clear();
                }
                else if (boundary is Circle)
                {
                    List <Point> points = new List <Point>();

                    for (double j = 0; j < 1; j = j + tolerance)
                    {
                        points.Add(boundary.PointAtParameter(j));
                    }

                    polygon = Polygon.ByPoints(points.Select(p => Point.ByCoordinates(p.X, p.Y)));

                    foreach (var item in points)
                    {
                        if (item != null)
                        {
                            item.Dispose();
                        }
                    }

                    points.Clear();
                }
                else if (boundary is Rectangle)
                {
                    polygon = Polygon.ByPoints(((Rectangle)boundary).Curves().Select(c => c.StartPoint).Select(p => Point.ByCoordinates(p.X, p.Y)));
                }
                else if (boundary is Polygon)
                {
                    polygon = boundary as Polygon;
                }

                pointsInside = this.GetSurfacePoints().Where(p => polygon.ContainmentTest(Point.ByCoordinates(p.X, p.Y))).ToList();
            }

            if (polygon != null)
            {
                polygon.Dispose();
            }

            xy.Dispose();

            if (boundaryXY != null)
            {
                boundaryXY.Dispose();
            }

            if (surf != null)
            {
                surf.Dispose();
            }

            Utils.Log(string.Format("CivilSurface.GetPointsInBoundary completed.", ""));

            return(pointsInside);
        }
Пример #2
0
        /// <summary>
        /// Get surface points inside a closed boundary
        /// </summary>
        /// <param name="boundary">A closed curve</param>
        /// <param name="tolerance">A value between 0 and 1 to define the precision of the tessellation along non-straight curves.</param>
        /// <returns>
        /// The List of Points
        /// </returns>
        public List <Point> GetPointsInBoundary(Curve boundary, double tolerance = 0.1)
        {
            Utils.Log(string.Format("CivilSurface.GetPointsInBoundary started...", ""));

            if (!boundary.IsClosed)
            {
                string message = "The Curve provided is not closed.";

                Utils.Log(string.Format("ERROR: CivilSurface.GetPointsInBoundary {0}", message));

                throw new Exception(message);
            }

            if (tolerance <= 0 || tolerance > 1)
            {
                tolerance = 1;
            }

            Polygon polygon = null;

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

            if (boundary is PolyCurve)
            {
                // polygon = Polygon.ByPoints(((PolyCurve)boundary).Curves().Select(c => c.StartPoint).Select(p => Point.ByCoordinates(p.X, p.Y)));

                PolyCurve pc = boundary as PolyCurve;

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

                for (int i = 0; i < pc.NumberOfCurves; ++i)
                {
                    Curve c = pc.CurveAtIndex(i);

                    try
                    {
                        Line line = c as Line;
                        points.Add(c.StartPoint);
                    }
                    catch
                    {
                        for (double j = 0; j < 1; j = j + tolerance)
                        {
                            points.Add(c.PointAtParameter(j));
                        }
                    }
                }

                polygon = Polygon.ByPoints(points.Select(p => Point.ByCoordinates(p.X, p.Y)));

                points.Clear();
            }
            else if (boundary is Circle)
            {
                List <Point> points = new List <Point>();

                for (double j = 0; j < 1; j = j + tolerance)
                {
                    points.Add(boundary.PointAtParameter(j));
                }

                polygon = Polygon.ByPoints(points.Select(p => Point.ByCoordinates(p.X, p.Y)));

                points.Clear();
            }
            else if (boundary is Rectangle)
            {
                polygon = Polygon.ByPoints(((Rectangle)boundary).Curves().Select(c => c.StartPoint).Select(p => Point.ByCoordinates(p.X, p.Y)));
            }
            else if (boundary is Polygon)
            {
                polygon = boundary as Polygon;
            }

            pointsInside = this.GetSurfacePoints().Where(p => polygon.ContainmentTest(Point.ByCoordinates(p.X, p.Y))).ToList();

            polygon.Dispose();

            Utils.Log(string.Format("CivilSurface.GetPointsInBoundary completed.", ""));

            return(pointsInside);
        }