internal static void Sweep(IEnumerable<Polyline> obstacles,
                            Point direction, double coneAngle, VisibilityGraph visibilityGraph,
                            IEnumerable<Point> portLocations) {
     var cs = new LineSweeperForPortLocations(obstacles, direction, direction.Rotate(-coneAngle/2),
                                              direction.Rotate(coneAngle/2), visibilityGraph, portLocations);
     cs.Calculate();
 }
 void AddDirection(Point direction) {
     var visibilityGraph = new VisibilityGraph();
     LineSweeperForPortLocations.Sweep(obstacles, direction, coneAngle, visibilityGraph,
                                       PortLocations);
     foreach (var edge in visibilityGraph.Edges)
         VisibilityGraph.AddEdge(edge.SourcePoint, edge.TargetPoint,
                                 ((a, b) => new TollFreeVisibilityEdge(a, b)));
 }
        internal SingleSourceMultipleTargetsShortestPathOnVisibilityGraph(VisibilityVertex sourceVisVertex,
                                                                         IEnumerable<VisibilityVertex> targetVisVertices, VisibilityGraph visibilityGraph) {
            _visGraph = visibilityGraph;
            _visGraph.ClearPrevEdgesTable();
            foreach (var v in visibilityGraph.Vertices())
                v.Distance = Double.PositiveInfinity;

            source = sourceVisVertex;
            targets = new Set<VisibilityVertex>(targetVisVertices);
            source.Distance = 0;
        }
 LineSweeperForPortLocations(IEnumerable<Polyline> obstacles, Point direction, Point coneRsDir, Point coneLsDir,
                             VisibilityGraph visibilityGraph, IEnumerable<Point> portLocations)
     : base(obstacles, direction) {
     this.visibilityGraph = visibilityGraph;
     ConeRightSideDirection = coneRsDir;
     ConeLeftSideDirection = coneLsDir;
     coneSideComparer = new ConeSideComparer(this);
     leftConeSides = new RbTree<ConeSide>(coneSideComparer);
     rightConeSides = new RbTree<ConeSide>(coneSideComparer);
     PortLocations = portLocations;
 }
        internal static void AddTangentVisibilityEdgesToGraph(List<Polygon> holes, VisibilityGraph visibilityGraph) {

            if (holes.Count > 1) {
                TangentVisibilityGraphCalculator calculator = new TangentVisibilityGraphCalculator(holes, visibilityGraph, true);
                calculator.CalculateAndAddEdges();

                //use another family of tangents
                calculator = new TangentVisibilityGraphCalculator(holes, visibilityGraph, false);
                calculator.CalculateAndAddEdges();
            }

        }
 LineSweeper(IEnumerable<Polyline> obstacles, Point direction, Point coneRsDir, Point coneLsDir,
             VisibilityGraph visibilityGraph, Set<Point> ports, Polyline borderPolyline)
     : base(obstacles, direction) {
     this.visibilityGraph = visibilityGraph;
     ConeRightSideDirection = coneRsDir;
     ConeLeftSideDirection = coneLsDir;
     coneSideComparer = new ConeSideComparer(this);
     leftConeSides = new RbTree<ConeSide>(coneSideComparer);
     rightConeSides = new RbTree<ConeSide>(coneSideComparer);
     Ports = ports;
     BorderPolyline = borderPolyline;
     PortEdgesCreator = (a, b) => new TollFreeVisibilityEdge(a, b);
 }
 internal static void CalculatePointVisibilityGraph(IEnumerable<Polyline> listOfHoles,
                                                    VisibilityGraph visibilityGraph, Point point,
                                        VisibilityKind visibilityKind, out VisibilityVertex qVertex) {
     //maybe there is nothing to do
     var qv = visibilityGraph.FindVertex(point);
     if (qv != null){
         qVertex = qv;
         return;
     }
         
     var calculator = new PointVisibilityCalculator(listOfHoles, visibilityGraph, point, visibilityKind);
     calculator.FillGraph();
     qVertex = calculator.QVertex;
     Debug.Assert(qVertex != null);
 }
        internal ConeSpanner(IEnumerable<Polyline> obstacles, VisibilityGraph visibilityGraph, double coneAngle,
                             Set<Point> ports, Polyline borderPolyline)
            : this(obstacles, visibilityGraph) {
            Debug.Assert(borderPolyline == null || obstacles.All(o => Curve.CurveIsInsideOther(o, borderPolyline)));
            Debug.Assert(borderPolyline == null ||
                         ports.All(o => Curve.PointRelativeToCurveLocation(o, borderPolyline) == PointLocation.Inside));

            //Debug.Assert(obstacles.All(o => ports.All(p => Curve.PointRelativeToCurveLocation(p, o) == PointLocation.Outside)));
            //todo: uncomment this assert - it failes on D:\progression\src\ddsuites\src\vs\Progression\ScenarioTests\Grouping\GroupingResources\GroupBySelection2.dgml
            //when dragging
            Debug.Assert(coneAngle > Math.PI/180*2 && coneAngle <= Math.PI/2);

            Ports = ports;
            BorderPolyline = borderPolyline;
            ConeAngle = coneAngle;
        }
示例#9
0
        /// <summary>
        /// We suppose that the holes are convex and oriented clockwis and are mutually disjoint
        /// </summary>
        /// <param name="listOfHoles"></param>
        /// <param name="visibilityGraph"></param>
        /// <param name="point">The point can belong to the boundary of one of the holes</param>
        /// <param name="visibilityKind">tangent or regural visibility</param>
        /// <param name="qVertex">the graph vertex corresponding to the pivot</param>
        /// <returns></returns>
        internal static VisibilityVertex CalculatePointVisibilityGraph(
            IEnumerable <Polyline> listOfHoles,
            VisibilityGraph visibilityGraph,
            Point point,
            VisibilityKind visibilityKind)
        {
            //maybe there is nothing to do
            var qv = visibilityGraph.FindVertex(point);

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

            var calculator = new PointVisibilityCalculator(listOfHoles, visibilityGraph, point, visibilityKind);

            calculator.FillGraph();
            return(calculator.QVertex);
        }
        internal static void CalculatePointVisibilityGraph(IEnumerable <Polyline> listOfHoles,
                                                           VisibilityGraph visibilityGraph, Point point,
                                                           VisibilityKind visibilityKind, out VisibilityVertex qVertex)
        {
            //maybe there is nothing to do
            var qv = visibilityGraph.FindVertex(point);

            if (qv != null)
            {
                qVertex = qv;
                return;
            }

            var calculator = new PointVisibilityCalculator(listOfHoles, visibilityGraph, point, visibilityKind);

            calculator.FillGraph();
            qVertex = calculator.QVertex;
            Debug.Assert(qVertex != null);
        }
        internal BundleRouter(GeometryGraph geometryGraph, SdShortestPath shortestPathRouter,
                              VisibilityGraph visibilityGraph, BundlingSettings bundlingSettings, double loosePadding, RectangleNode<Polyline> tightHierarchy,
                              RectangleNode<Polyline> looseHierarchy,
                              Dictionary<EdgeGeometry, Set<Polyline>> edgeLooseEnterable, Dictionary<EdgeGeometry, Set<Polyline>> edgeTightEnterable, Func<Port, Polyline> loosePolylineOfPort) {
            ValidateArg.IsNotNull(geometryGraph, "geometryGraph");
            ValidateArg.IsNotNull(bundlingSettings, "bundlingSettings");

            this.geometryGraph = geometryGraph;
            this.bundlingSettings = bundlingSettings;
            regularEdges = geometryGraph.Edges.Where(e => e.Source != e.Target).ToArray();
            VisibilityGraph = visibilityGraph;
            this.shortestPathRouter = shortestPathRouter;
            LoosePadding = loosePadding;
            LooseHierarchy = looseHierarchy;
            TightHierarchy = tightHierarchy;
            EdgeLooseEnterable = edgeLooseEnterable;
            EdgeTightEnterable = edgeTightEnterable;
            this.loosePolylineOfPort = loosePolylineOfPort;
        }
 public SteinerCdt(VisibilityGraph visGraph, IEnumerable<LgNodeInfo> nodeInfos) {
     _visGraph = visGraph;
     _nodeInfos = nodeInfos;
     MakeSureThatNodeBoundariesAreInVisGraph(nodeInfos);
 }
 void CalculateTangentVisibilityGraph() {
     _visGraph = VisibilityGraph.GetVisibilityGraphForShortestPath(
         SourcePoint, TargetPoint, obstacleCalculator.LooseObstacles, out sourceVisibilityVertex,
         out targetVisibilityVertex);
 }
        internal RectFileReader(string fileName, int fileRoundingDigits)
        {
            comparer = new TestPointComparer(fileRoundingDigits);

            UnpaddedObstacles = new List<Shape>();
            PaddedObstacles = new List<Polyline>();
            RoutingSpecs = new List<EdgeGeometry>();
            HorizontalScanLineSegments = new List<LineSegment>();
            VerticalScanLineSegments = new List<LineSegment>();
            VisibilityGraph = new VisibilityGraph();

            this.FreeRelativePortToShapeMap = new Dictionary<Port, Shape>();

            this.inputFileReader = new StreamReader(fileName);

            this.RandomObstacleArg = RectFileStrings.NullStr;
            this.RandomObstacleDensity = RectFileStrings.NullStr;

            // Input parameters
            ReadHeader();

            // Input detail
            ReadInputObstacles();
            ReadPorts();
            ReadRoutingSpecs();

            // Output detail.
            ReadPaddedObstacles();
            ReadConvexHulls();
            ReadScanSegments();
            ReadVisibilityGraph();
            ReadPaths();

            this.inputFileReader.Close();
            if (0 == this.UnpaddedObstacles.Count)
            {
                Validate.Fail("No obstacles found in file");
            }
        }
        static internal void Test_DumpVisibilityGraph(ObstacleTree obstacleTree, VisibilityGraph vg) {
#if TEST_MSAGL
            var debugCurves = Test_GetObstacleDebugCurves(obstacleTree);
            debugCurves.AddRange(Test_GetVisibilityGraphDebugCurves(vg));
            DebugCurveCollection.WriteToFile(debugCurves, GetDumpFileName("VisibilityGraph"));
#endif // TEST
        }
        /*********************
            A complication arises when we have overlaps. Loose obstacles become large enough to contain several
            ports. We need to avoid a situation when a port has degree more than one. 
            To avoid this situation we redirect to p every edge incoming into cone.Apex. 
            Notice that we create a new graph to keep port edges for ever 
            direction of the sweep and the above procedure just alignes the edges better.
            In the resulting graph, which contains the sum of the graphs passed to AddDirection, of course
            a port can have an incoming and outcoming edge at the same time
            *******************/

        void CreatePortEdge(Cone cone, Point p) {
            if (portEdgesGraph == null) portEdgesGraph = new VisibilityGraph();
            var coneApexVert = portEdgesGraph.FindVertex(cone.Apex);
            //all previous edges adjacent to cone.Apex 
            var edgesToFix = (coneApexVert != null)
                                 ? coneApexVert.InEdges.Concat(coneApexVert.OutEdges).ToArray()
                                 : null;
            if (edgesToFix != null)
                foreach (var edge in edgesToFix) {
                    var otherPort = (edge.Target == coneApexVert ? edge.Source : edge.Target).Point;
                    VisibilityGraph.RemoveEdge(edge);
                    portEdgesGraph.AddEdge(otherPort, p);
                }
            portEdgesGraph.AddEdge(cone.Apex, p);
        }
 TangentVisibilityGraphCalculator(List <Polygon> holes, VisibilityGraph visibilityGraph, bool useLeftPTangents)
 {
     this.polygons         = holes;
     this.visibilityGraph  = visibilityGraph;
     this.useLeftPTangents = useLeftPTangents;
 }
 TangentVisibilityGraphCalculator(List<Polygon> holes, VisibilityGraph visibilityGraph, bool useLeftPTangents) {
     this.polygons = holes;
     this.visibilityGraph = visibilityGraph;
     this.useLeftPTangents = useLeftPTangents;
 }
        // ReSharper disable InconsistentNaming
        protected static void Debug_AssertGraphIsRectilinear(VisibilityGraph graph, ObstacleTree obstacleTree)
        // ReSharper restore InconsistentNaming
        {
#if DEBUG
            if (graph.Edges.Any(edge => !PointComparer.IsPureDirection(PointComparer.GetDirections(edge.SourcePoint, edge.TargetPoint))))
            {
                StaticGraphUtility.Assert(false, "Generated VisibilityGraph contains non-rectilinear lines", obstacleTree, graph);
                return;
            }
#endif
        }
 static internal void Assert(bool condition, string message, ObstacleTree obstacleTree, VisibilityGraph vg) {
     if (!condition) {
         Test_DumpVisibilityGraph(obstacleTree, vg);
         Debug.Assert(condition, message);
     }
 }
 internal ConeSpanner(IEnumerable<Polyline> obstacles, VisibilityGraph visibilityGraph) {
     this._obstacles = VisibilityGraph.OrientHolesClockwise(obstacles);
     this._visibilityGraph = visibilityGraph;
 }
 void AddDirection(Point direction, Polyline borderPolyline, VisibilityGraph visibilityGraph) {
     LineSweeper.Sweep(_obstacles, direction, coneAngle, visibilityGraph, Ports, borderPolyline);
 }
 static internal VisibilityEdge FindNextEdge(VisibilityGraph vg, VisibilityVertex vertex, Directions dir) {
     VisibilityVertex nextVertex = FindNextVertex(vertex, dir);
     return (null == nextVertex) ? null : vg.FindEdge(vertex.Point, nextVertex.Point);
 }
        static internal List<DebugCurve> Test_GetVisibilityGraphDebugCurves(VisibilityGraph vg) {
            return vg.Edges.Select(edge => new DebugCurve(0.1,
                        (edge.Weight == ScanSegment.NormalWeight) ? "Blue"
                                : ((edge.Weight == ScanSegment.ReflectionWeight) ? "DarkCyan" : "LightBlue"),
                        new LineSegment(edge.Source.Point, edge.Target.Point))).ToList();

        }
 public InteractiveTangentVisibilityGraphCalculator(ICollection <Polygon> holes, IEnumerable <Polygon> addedPolygons, VisibilityGraph visibilityGraph)
 {
     this.polygons        = holes;
     this.visibilityGraph = visibilityGraph;
     this.addedPolygons   = addedPolygons;
 }
 private void AddVisibleEdge(Tangent t)
 {
     VisibilityGraph.AddEdge(visibilityGraph.GetVertex(t.Start), visibilityGraph.GetVertex(t.End));
 }
 internal void CreateSparseVerticesAndEdges(VisibilityGraph vg) {
     foreach (var item in this.vector) {
         item.ResetForIntersections();
         for (var segment = item.FirstSegment; segment != null; segment = segment.NextSegment) {
             segment.CreateSparseVerticesAndEdges(vg);
         }
     }
 }
 internal ConeSpannerForPortLocations(IEnumerable<Polyline> obstacles, VisibilityGraph visibilityGraph,
     IEnumerable<Point> portLocationsPointSet) {
     PortLocations = portLocationsPointSet;
     this.obstacles = VisibilityGraph.OrientHolesClockwise(obstacles);
     VisibilityGraph = visibilityGraph;
 }
 public InteractiveTangentVisibilityGraphCalculator(ICollection<Polygon> holes, IEnumerable<Polygon> addedPolygons, VisibilityGraph visibilityGraph) {
     this.polygons = holes;
     this.visibilityGraph = visibilityGraph;
     this.addedPolygons = addedPolygons;
 }
 static internal void ShowVisGraph(VisibilityGraph tmpVisGraph, IEnumerable<Polyline> obstacles, IEnumerable<ICurve> greenCurves, IEnumerable<ICurve> redCurves) {
     var l = new List<DebugCurve>(tmpVisGraph.Edges.Select(e => new DebugCurve(100, 1,
         e.IsPassable != null && e.IsPassable() ? "green" : "black"
         , new LineSegment(e.SourcePoint, e.TargetPoint))));
     if (obstacles != null)
         l.AddRange(obstacles.Select(p => new DebugCurve(100, 1, "brown", p)));
     if (greenCurves != null)
         l.AddRange(greenCurves.Select(p => new DebugCurve(100, 10, "navy", p)));
     if (redCurves != null)
         l.AddRange(redCurves.Select(p => new DebugCurve(100, 10, "red", p)));
     LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(l);
 }
 PointVisibilityCalculator(IEnumerable<Polyline> holes, VisibilityGraph visibilityGraph, Point point,
                           VisibilityKind visibilityKind) {
     this.holes = holes;
     //this.graphOfHoleBoundaries = holeBoundariesGraph;
     this.visibilityGraph = visibilityGraph;
     q = point;
     qPolylinePoint = new PolylinePoint(q);
     QVertex = this.visibilityGraph.AddVertex(qPolylinePoint);
     this.visibilityKind = visibilityKind;
     heapForSorting = new BinaryHeapWithComparer<Stem>(new StemStartPointComparer(q));
 }
        void HandleBideractionalCase() {
            int k = (int)(Math.PI/coneAngle);
            for (int i = 0; i < k; i++) {
                var angle = i*coneAngle;
                var vg0 = new VisibilityGraph();
                AddDirection(new Point(Math.Cos(angle), Math.Sin(angle)), BorderPolyline, vg0);
                var vg1 = new VisibilityGraph();
                AddDirection(new Point(-Math.Cos(angle), -Math.Sin(angle)), BorderPolyline, vg1);
                AddIntersectionOfBothDirectionSweepsToTheResult(vg0, vg1);                
            }

          

        }
// ReSharper disable InconsistentNaming
        static internal void Test_ShowVisibilityGraph(ObstacleTree obstacleTree, VisibilityGraph vg) {
#if TEST_MSAGL
            var debugCurves = Test_GetObstacleDebugCurves(obstacleTree);
            debugCurves.AddRange(Test_GetVisibilityGraphDebugCurves(vg));
            LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(debugCurves);
#endif // TEST
        }
 internal LgPathRouter() {
     _visGraph = new VisibilityGraph();
 }
 void AddIntersectionOfBothDirectionSweepsToTheResult(VisibilityGraph vg0, VisibilityGraph vg1) {
     foreach (var edge in vg0.Edges)
         if (vg1.FindEdge(edge.SourcePoint, edge.TargetPoint) != null)
             _visibilityGraph.AddEdge(edge.SourcePoint, edge.TargetPoint);
 }