Ejemplo n.º 1
0
        public static Surface IsovistFromPoint(BaseGraph baseGraph, DSPoint point)
        {
            if (baseGraph == null)
            {
                throw new ArgumentNullException("graph");
            }
            if (point == null)
            {
                throw new ArgumentNullException("point");
            }

            Vertex origin = Vertex.ByCoordinates(point.X, point.Y, point.Z);

            List <Vertex>  vertices = Graphical.Graphs.VisibilityGraph.VertexVisibility(origin, baseGraph.graph);
            List <DSPoint> points   = vertices.Select(v => Points.ToPoint(v)).ToList();
            Surface        isovist;

            // TODO: Implement better way of checking if polygon is self intersecting

            Autodesk.DesignScript.Geometry.Polygon polygon = Autodesk.DesignScript.Geometry.Polygon.ByPoints(points);


            //fix back
            //
            // if(Graphical.Geometry.Polygon.Intersection(polygon).Length > 0)
            // {
            //     points.Add(point);
            //     polygon = Polygon.by(points);
            //
            // }

            return(Surface.ByPatch(polygon));
        }
        //ADDED CODE : SUBHAJIT DAS++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


        //makes surface patch for closed polylines
        public static List <Surface> MakeSurfaceForPolygon2d(List <Polygon2d> poly, double height = 3)
        {
            if (poly == null)
            {
                return(null);
            }
            for (int i = 0; i < poly.Count; i++)
            {
                if (poly[i] == null || poly[i].Points == null || poly[i].Points.Count == 0)
                {
                    return(null);
                }
            }
            List <Surface> surfaceList = new List <Surface>();

            for (int i = 0; i < poly.Count; i++)
            {
                if (poly[i] == null)
                {
                    continue;
                }
                //List<Point> ptList = pointFromPoint2dList(poly[i].Points);
                //PolyCurve pCurve = PolyCurve.ByPoints(ptList);
                Polygon pCurve = PolygonByPolygon2d(poly[i], height);
                if (pCurve == null)
                {
                    continue;
                }
                surfaceList.Add(Surface.ByPatch(pCurve));
            }
            return(surfaceList);
        }
Ejemplo n.º 3
0
        private static Surface CreateOneSurface()
        {
            var rect    = Rectangle.ByWidthLength(5, 5);
            var surface = Surface.ByPatch(rect);

            return(surface);
        }
Ejemplo n.º 4
0
        public static void AssertLabelsGoodStartingLocationAndOrientation <K, T>(List <PlanarUnfolder.UnfoldableFaceLabel
                                                                                       <K, T> > labels)
            where K : IUnfoldableEdge
            where T : IUnfoldablePlanarFace <K>
        {
            // get aligned geometry
            var alignedGeo = labels.Select(x => x.AlignedLabelGeometry).ToList();

            // assert that the bounding box of the label at least intersects the face it represents
            for (int i = 0; i < alignedGeo.Count; i++)
            {
                var curveList = alignedGeo[i];

                var curvePoints = curveList.Select(x => x.StartPoint);
                var labelPlane  = Plane.ByBestFitThroughPoints(curvePoints);
                var testsurf    = Surface.ByPatch(Rectangle.ByWidthLength(1, 1).
                                                  Transform(CoordinateSystem.ByPlane(labelPlane)) as Curve);

                //check that the aligned curves intersect the surface they are aligned to
                Assert.IsTrue(curveList.SelectMany(x => labels[i].UnfoldableFace.SurfaceEntities.Select(x.DoesIntersect)).Any());
                Console.WriteLine("This label was in the right spot at the start of the unfold");
                //also assert that the face normal is parallel with the normal of the boundingbox plane

                var face = labels[i].UnfoldableFace.SurfaceEntities;

                UnfoldTestUtils.AssertSurfacesAreCoplanar(testsurf, face.First());
                Console.WriteLine("This label was in the right orientation at the start of the unfold");

                testsurf.Dispose();
                labelPlane.Dispose();
            }
        }
Ejemplo n.º 5
0
        public static Surface IsovistFromPoint(BaseGraph baseGraph, DSPoint point)
        {
            if (baseGraph == null)
            {
                throw new ArgumentNullException("graph");
            }
            if (point == null)
            {
                throw new ArgumentNullException("point");
            }

            gVertex origin = gVertex.ByCoordinates(point.X, point.Y, point.Z);

            List <gVertex> vertices = Graphical.Graphs.VisibilityGraph.VertexVisibility(origin, baseGraph.graph);
            List <DSPoint> points   = vertices.Select(v => Points.ToPoint(v)).ToList();
            Surface        isovist;
            // TODO: Implement better way of checking if polygon is self intersectingç

            Polygon polygon = Polygon.ByPoints(points);

            if (polygon.SelfIntersections().Length > 0)
            {
                points.Add(point);
                polygon = Polygon.ByPoints(points);
            }

            return(Surface.ByPatch(polygon));
        }
Ejemplo n.º 6
0
        public void IsovistFromPointReturnsCorrectSurfaceAreaTest()
        {
            // Create origin point
            Point originPoint = layoutPolygon.Center();

            // Create isovist form the origin point
            Surface isovist = Isovist.FromPoint(new List <Polygon> {
                layoutPolygon
            }, new List <Polygon> {
                layoutPolygon
            }, originPoint);

            // Checks if the area of the isovist is equal to the area of the layout
            // as there are no obstructions the entire layout should be visible from the origin point
            Assert.AreEqual(isovist.Area, Surface.ByPatch(layoutPolygon).Area);
        }
        public static List <Polygon2d> Trim(this Polygon2d polygon, Polygon2d other)
        {
            if (other == null)
            {
                return(null);
            }

            Geometry[] dTrimmed = null;
            {
                Polygon dPolyThis    = DynamoGeometry.PolygonByPolygon2d(polygon, 0);
                Surface dSurfaceThis = Surface.ByPatch(dPolyThis);

                Polygon dPolyOther    = DynamoGeometry.PolygonByPolygon2d(other, 0);
                Surface dSurfaceOther = Surface.ByPatch(dPolyOther);
                Solid   dSolidOther   = dSurfaceOther.Thicken(1.0, true);

                dTrimmed = dSurfaceThis.SubtractFrom(dSolidOther);

                dPolyThis.Dispose();
                dSurfaceThis.Dispose();
                dPolyOther.Dispose();
                dSurfaceOther.Dispose();
                dSolidOther.Dispose();
            }

            List <Polygon2d> polygons = new List <Polygon2d>();

            foreach (Geometry dGeometry in dTrimmed)
            {
                List <Point2d> points  = new List <Point2d>();
                Curve[]        dCurves = ((Surface)dGeometry).PerimeterCurves();
                foreach (Curve dCurve in dCurves)
                {
                    Point dPoint = dCurve.StartPoint;
                    points.Add(new Point2d(dPoint.X, dPoint.Y));
                    dPoint.Dispose();

                    dCurve.Dispose();
                }

                polygons.Add(new Polygon2d(points));

                dGeometry.Dispose();
            }

            return(polygons);
        }
Ejemplo n.º 8
0
        public void BeforeTest()
        {
            surface = Surface.ByPatch(PolyCurve.ByPoints(new List <Point>
            {
                Point.ByCoordinates(0, 0, 0),
                Point.ByCoordinates(27.129, 25.08, 0),
                Point.ByCoordinates(10.318, 36.351, 0),
                Point.ByCoordinates(-7.419, 16.573, 0)
            }, true));

            List <double> newRange = DSCore.Math.RemapRange(new List <double> {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9
            }, 0, 1) as List <double>;

            uParams = newRange;
            vParams = newRange;
        }
Ejemplo n.º 9
0
        public void RightObstacleTest()
        {
            // Create a rectangle object with 4 equal sides to check openess score
            var origin  = Point.ByCoordinates(10, 0);
            var surface = Surface.ByPatch(Rectangle.ByWidthLength(CoordinateSystem.ByOrigin(origin), 10, 10));

            // Calculate openess score
            var openessScore = Openess.FromSurface(surface, 0, new List <Polygon> {
            }, new List <Polygon> {
                obstacle
            });

            // Check of score equals 75%, as the entire right side is blocked by the obstacle
            Assert.AreEqual(75d, openessScore);

            // Dispose unused geometry
            obstacle.Dispose();
            origin.Dispose();
        }
Ejemplo n.º 10
0
        public void BottomObstacleTest()
        {
            // Create a rectangle object with 4 equal sides to check openess score
            Point   origin  = Point.ByCoordinates(0, -10);
            Surface surface = Surface.ByPatch(Rectangle.ByWidthLength(CoordinateSystem.ByOrigin(origin), 10, 10));

            // Calculate openess score
            double openessScore = Openess.FromSurface(surface, 0, new List <Polygon> {
            }, new List <Polygon> {
                obstacle
            });

            // Check of score equals 0.25, as the entire bottom is blocked by the obstacle
            Assert.AreEqual(0.25, openessScore);

            // Dispose unused geometry
            obstacle.Dispose();
            origin.Dispose();
        }
Ejemplo n.º 11
0
        public void IsovistFromPointDetectsObstructionsInLayoutTest()
        {
            // Create obstruction
            Polygon internals = Rectangle.ByWidthLength(5, 5) as Polygon;

            // Create origin point
            Point originPoint = Point.ByCoordinates(3, 3);

            // Create isovist form the origin point
            Surface isovist = Isovist.FromPoint(new List <Polygon> {
                layoutPolygon
            }, new List <Polygon> {
                internals
            }, originPoint);

            // Checks that the area returned by the isovist is not equal to the area of the layout
            // and that the isovist does not intersect the midpoint of the obstacle.
            Assert.AreNotEqual(Surface.ByPatch(layoutPolygon).Area, isovist.Area);
            Assert.False(isovist.DoesIntersect(internals.Center()));
        }
Ejemplo n.º 12
0
        public void ObstacleOnBothSides()
        {
            List <Polygon> obstaclePolygons = new List <Polygon>()
            {
                obstacle.Translate(-10) as Polygon,
                obstacle.Translate(10) as Polygon
            };

            // Create a rectangle object with 4 equal sides to check openess score
            Surface surface = Surface.ByPatch(Rectangle.ByWidthLength(10, 10));

            // Calculate openess score
            double openessScore = Openess.FromSurface(surface, 0, new List <Polygon> {
            }, obstaclePolygons);

            // Check if score equals 0.50, as the entire right and left side is blocked by the obstacles
            Assert.AreEqual(0.50, openessScore);

            // Dispose unused geometry
            obstaclePolygons.ForEach(poly => poly.Dispose());
        }
Ejemplo n.º 13
0
        public static Surface IsovistFromPoint(
            Point point,
            List <Polygon> boundary,
            [DefaultArgument("[]")] List <Polygon> obstructions)
        {
            var baseGraph = BaseGraph.ByBoundaryAndInternalPolygons(boundary, obstructions);

            if (baseGraph == null)
            {
                throw new ArgumentNullException("graph");
            }
            if (point == null)
            {
                throw new ArgumentNullException("point");
            }

            GTGeom.Vertex origin = GTGeom.Vertex.ByCoordinates(point.X, point.Y, point.Z);

            List <GTGeom.Vertex> vertices = VisibilityGraph.VertexVisibility(origin, baseGraph.graph);
            var points = vertices.Select(v => GTGeom.Points.ToPoint(v)).ToList();

            var polygon = Polygon.ByPoints(points);

            // if polygon is self intersecting, make new polygon
            if (polygon.SelfIntersections().Length > 0)
            {
                points.Add(point);
                polygon = Polygon.ByPoints(points);
            }

            var surface = Surface.ByPatch(polygon);

            polygon.Dispose();
            points.ForEach(p => p.Dispose());

            return(surface);
        }
Ejemplo n.º 14
0
        public static Dictionary <string, object> ConvertSiteOutlineToPolygon2d(List <Geometry> geomList, double inset = 5)// Geometry
        {
            string         type      = geomList[0].GetType().ToString();
            List <Point2d> pointList = new List <Point2d>();
            //Trace.WriteLine("list found is + " + type);
            List <NurbsCurve> nurbList = new List <NurbsCurve>();

            if (type.IndexOf("Line") != -1)
            {
                List <Line> lineList = new List <Line>();
                for (int i = 0; i < geomList.Count; i++)
                {
                    lineList.Add((Line)geomList[i]);
                }
                for (int i = 0; i < lineList.Count; i++)
                {
                    Point2d pointPerCurve = Point2d.ByCoordinates(lineList[i].StartPoint.X, lineList[i].StartPoint.Y);
                    pointList.Add(pointPerCurve);
                    if (i == lineList.Count)
                    {
                        pointList.Add(Point2d.ByCoordinates(lineList[i].EndPoint.X, lineList[i].EndPoint.Y));
                    }
                }
            }
            else if (type.IndexOf("NurbsCurve") != -1)
            {
                nurbList = new List <NurbsCurve>();
                for (int i = 0; i < geomList.Count; i++)
                {
                    nurbList.Add((NurbsCurve)geomList[i]);
                }

                /*
                 * for (int i = 0; i < nurbList.Count; i++)
                 * {
                 *  Point2d pointPerCurve = Point2d.ByCoordinates(nurbList[i].StartPoint.X, nurbList[i].StartPoint.Y);
                 *  pointList.Add(pointPerCurve);
                 *  if (i == nurbList.Count) pointList.Add(Point2d.ByCoordinates(nurbList[i].EndPoint.X, nurbList[i].EndPoint.Y));
                 * }
                 */
            }
            else
            {
                return(null);
            }

            PolyCurve pCrv = PolyCurve.ByJoinedCurves((Curve[])nurbList.ToArray());


            Curve   cInsetA = pCrv.Offset(inset);
            Curve   cInsetB = pCrv.Offset(inset * -1);
            Curve   cInset;
            Surface srfA = Surface.ByPatch(cInsetA), srfB = Surface.ByPatch(cInsetB);

            if (srfA.Area > srfB.Area)
            {
                cInset = cInsetB;
            }
            else
            {
                cInset = cInsetA;
            }

            srfA.Dispose(); srfB.Dispose();
            List <Curve> curvList = new List <Curve>();

            geomList = cInset.Explode().ToList();
            for (int i = 0; i < geomList.Count; i++)
            {
                curvList.Add((Curve)geomList[i]);
            }
            for (int i = 0; i < curvList.Count; i++)
            {
                Point2d pointPerCurve = Point2d.ByCoordinates(curvList[i].StartPoint.X, curvList[i].StartPoint.Y);
                pointList.Add(pointPerCurve);
                if (i == curvList.Count)
                {
                    pointList.Add(Point2d.ByCoordinates(curvList[i].EndPoint.X, curvList[i].EndPoint.Y));
                }
            }
            //return new Polygon2d(pointList);
            return(new Dictionary <string, object>
            {
                { "InsetSiteOutline", (new Polygon2d(pointList)) }
            });
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        public void BeforeTest()
        {
            Rectangle layoutPolygon = Rectangle.ByWidthLength(500, 500);

            surface = Surface.ByPatch(layoutPolygon);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Gets a list of closed polycurve edges of surface. First list item is outside boundary.
        /// </summary>
        /// <param name="surface">The surface.</param>
        /// <returns name="edgeCrvList">Edges of surface.</returns>
        /// <exception cref="ArgumentNullException">Surface</exception>
        public static PolyCurve[] GetSurfaceLoops(Surface surface)
        {
            if (surface == null)
            {
                throw new ArgumentNullException(nameof(surface));
            }

            var curves = surface.PerimeterCurves();

            var loops = new List <PolyCurve>();

            foreach (var curve in curves)
            {
                var added = false;

                for (var i = 0; i < loops.Count; i++)
                {
                    var loop = loops[i];

                    if (loop.IsClosed)
                    {
                        continue;
                    }

                    if (loop.StartPoint.IsAlmostEqualTo(curve.StartPoint) ||
                        loop.StartPoint.IsAlmostEqualTo(curve.EndPoint) ||
                        loop.EndPoint.IsAlmostEqualTo(curve.StartPoint) ||
                        loop.EndPoint.IsAlmostEqualTo(curve.EndPoint))
                    {
                        try
                        {
                            loops[i] = loop.Join(new[] { curve });

                            added = true;
                            break;
                        }
                        catch (ApplicationException)
                        {
                            continue;
                        }
                    }
                }

                if (!added)
                {
                    loops.Add(PolyCurve.ByJoinedCurves(new[] { curve }));
                }

                curve.Dispose();
            }

            if (loops.Any(loop => !loop.IsClosed))
            {
                throw new ArgumentException("Created non-closed polycurve.");
            }

            return(loops.OrderByDescending(c =>
            {
                using (var s = Surface.ByPatch(c))
                {
                    return s.Area;
                }
            }).ToArray());
        }
Ejemplo n.º 18
0
        public static Dictionary <string, Autodesk.DesignScript.Geometry.Surface> Create(
            Autodesk.DesignScript.Geometry.Surface surface,
            double offset,
            double depth)
        {
            // offset perimeter curves by the specified offset and create new surface.
            // makes sure there are space between outer perimeter and the amenity space
            List <Curve> inCrvs = surface.OffsetPerimeterCurves(offset)["insetCrvs"].ToList();
            Surface      inSrf  = Surface.ByPatch(PolyCurve.ByJoinedCurves(inCrvs));

            // get longest curve of the inSrf
            Curve        max;
            List <Curve> others;
            Dictionary <string, dynamic> dict = inCrvs.MaximumLength();

            if (dict["maxCrv"].Count < 1)
            {
                max = dict["otherCrvs"][0] as Curve;
                int          count = dict["otherCrvs"].Count;
                List <Curve> rest  = dict["otherCrvs"];
                others = rest.GetRange(1, (count - 1));
            }
            else
            {
                max    = dict["maxCrv"][0] as Curve;
                others = dict["otherCrvs"];
            }

            // get perimeter curves of input surface
            List <Curve> perimCrvs = surface.PerimeterCurves().ToList();
            List <Curve> matchCrvs = max.FindMatchingVectorCurves(perimCrvs);

            // get longest curve
            Curve max2;
            Dictionary <string, dynamic> dict2 = matchCrvs.MaximumLength();

            if (dict2["maxCrv"].Count < 1)
            {
                max2 = dict2["otherCrvs"][0] as Curve;
            }
            else
            {
                max2 = dict2["maxCrv"][0] as Curve;
            }

            Vector vec = max2.ByTwoCurves(max);

            Curve transLine  = max.Translate(vec, depth) as Curve;
            Line  extendLine = transLine.ExtendAtBothEnds(1);


            List <Curve> crvList = new List <Curve>()
            {
                max, extendLine
            };
            Surface loftSrf = Surface.ByLoft(crvList);

            List <bool> boolLst = new List <bool>();

            foreach (var crv in others)
            {
                bool b = max.DoesIntersect(crv);
                boolLst.Add(b);
            }

            List <Curve> intersectingCurves = others
                                              .Zip(boolLst, (name, filter) => new { name, filter, })
                                              .Where(item => item.filter == true)
                                              .Select(item => item.name)
                                              .ToList();
            List <Curve> extendCurves = new List <Curve>();

            foreach (Curve crv in intersectingCurves)
            {
                var l = crv.ExtendAtBothEnds(1);
                extendCurves.Add(l);
            }

            List <Surface> split = loftSrf
                                   .SplitPlanarSurfaceByMultipleCurves(extendCurves)
                                   .OfType <Surface>()
                                   .ToList();

            Surface amenitySurf = split.MaximumArea()["maxSrf"] as Surface;

            Surface remainSurf = inSrf.Split(amenitySurf)[0] as Surface;

            Dictionary <string, Surface> newOutput;

            newOutput = new Dictionary <string, Surface>
            {
                { amenitySurfaceOutputPort, amenitySurf },
                { remainingSurfaceOutputPort, remainSurf }
            };

            //Dispose redundant geometry
            inCrvs.ForEach(crv => crv.Dispose());
            inSrf.Dispose();
            max.Dispose();
            perimCrvs.ForEach(crv => crv.Dispose());
            matchCrvs.ForEach(crv => crv.Dispose());
            max2.Dispose();
            vec.Dispose();
            transLine.Dispose();
            extendLine.Dispose();
            crvList.ForEach(crv => crv.Dispose());
            loftSrf.Dispose();
            intersectingCurves.ForEach(crv => crv.Dispose());
            extendCurves.ForEach(crv => crv.Dispose());

            return(newOutput);
        }