Exemple #1
0
        internal void RemoveVisGraphVertex(Point p)
        {
            var v = _visGraph.FindVertex(p);

            if (v == null)
            {
                return;
            }
            _visGraph.RemoveVertex(v);
            _visGraphVerticesTree.Remove(new Rectangle(p), v);
        }
Exemple #2
0
        private static void CheckVGOnPoint(Point p, VisibilityGraph vg, List <Point> ps, Point dir)
        {
            var inCone = new List <Point>(ps.Where(q => p != q && InCone(p, q, dir, Math.PI / 6)));


            var v = vg.FindVertex(p);

            Assert.IsTrue(
                (inCone.Count == 0
                 &&
                 (v == null || (v.OutEdges.Count == 0 && v.InEdges.Count() > 0))) ||
                vg.FindVertex(p).OutEdges.Count == 1);
        }
        Point FigureOutHookLocationForClusterOtherPort(Polyline poly, ClusterBoundaryPort otherEdgeEndPort, EdgeGeometry edgeGeom)
        {
            var shapes = shortestPathRouter.MakeTransparentShapesOfEdgeGeometry(edgeGeom);
            //SplineRouter.ShowVisGraph(this.VisibilityGraph, this.LooseHierarchy.GetAllLeaves(),
            //    shapes.Select(sh => sh.BoundaryCurve), new[] { new LineSegment(edgeGeom.SourcePort.Location, edgeGeom.TargetPort.Location) });
            var s = new MultipleSourceMultipleTargetsShortestPathOnVisibilityGraph(otherEdgeEndPort.LoosePolyline.Select(p => VisibilityGraph.FindVertex(p)),
                                                                                   poly.Select(p => VisibilityGraph.FindVertex(p)), VisibilityGraph);
            var path = s.GetPath();

            foreach (var sh in shapes)
            {
                sh.IsTransparent = false;
            }
            return(path.Last().Point);
        }
Exemple #4
0
        private static VisibilityVertex GetCrossingInteriorVertex(VisibilityGraph vg, VisibilityVertex crossingVertex,
                                                                  GroupBoundaryCrossing crossing)
        {
            Point interiorPoint = crossing.GetInteriorVertexPoint(crossingVertex.Point);

            return(vg.FindVertex(interiorPoint) ?? vg.AddVertex(interiorPoint));
        }
Exemple #5
0
 private void LoadEndOverlapVertexIfNeeded(VisibilityGraph vg)
 {
     // See comments in LoadStartOverlapVertexIfNeeded.
     if (NeedEndOverlapVertex)
     {
         VisibilityVertex vertex = vg.FindVertex(End);
         AppendVisibilityVertex(vg, vertex ?? vg.AddVertex(End));
     }
 }
        VisibilityVertex FindVertex(Point p)
        {
            return(VisibilityGraph.FindVertex(p) ?? VisibilityGraph.FindVertex(ApproximateComparer.Round(p)));

            /*  if (r == null) {
             *    SplineRouter.ShowVisGraph(this.VisibilityGraph, this.ObstacleHierarchy.GetAllLeaves(), null,
             *    new[] { new Ellipse(5, 5, p) });
             * }
             * return r;*/
        }
Exemple #7
0
 private void LoadStartOverlapVertexIfNeeded(VisibilityGraph vg)
 {
     // For adjacent segments with different IsOverlapped, we need a vertex that
     // joins the two so a path may be run.  This is paired with the other segment's
     // LoadEndOverlapVertexIfNeeded.
     if (NeedStartOverlapVertex)
     {
         VisibilityVertex vertex = vg.FindVertex(Start);
         AppendVisibilityVertex(vg, vertex ?? vg.AddVertex(Start));
     }
 }
Exemple #8
0
        private bool AppendGroupCrossingsThroughPoint(VisibilityGraph vg, Point lastPoint)
        {
            if (null == GroupBoundaryPointAndCrossingsList)
            {
                return(false);
            }

            bool found = false;

            while (GroupBoundaryPointAndCrossingsList.CurrentIsBeforeOrAt(lastPoint))
            {
                // We will only create crossing Edges that the segment actually crosses, not those it ends before crossing.
                // For those terminal crossings, the adjacent segment creates the interior vertex and crossing edge.
                PointAndCrossings       pac              = GroupBoundaryPointAndCrossingsList.Pop();
                GroupBoundaryCrossing[] lowDirCrossings  = null;
                GroupBoundaryCrossing[] highDirCrossings = null;
                if (PointComparer.Compare(pac.Location, Start) > 0)
                {
                    lowDirCrossings = PointAndCrossingsList.ToCrossingArray(pac.Crossings,
                                                                            ScanDirection.OppositeDirection);
                }
                if (PointComparer.Compare(pac.Location, End) < 0)
                {
                    highDirCrossings = PointAndCrossingsList.ToCrossingArray(pac.Crossings, ScanDirection.Direction);
                }

                found = true;
                VisibilityVertex crossingVertex = vg.FindVertex(pac.Location) ?? vg.AddVertex(pac.Location);

                if ((null != lowDirCrossings) || (null != highDirCrossings))
                {
                    AddLowCrossings(vg, crossingVertex, lowDirCrossings);
                    AddHighCrossings(vg, crossingVertex, highDirCrossings);
                }
                else
                {
                    // This is at this.Start with only lower-direction toward group interior(s), or at this.End with only
                    // higher-direction toward group interior(s).  Therefore an adjacent ScanSegment will create the crossing
                    // edge, so create the crossing vertex here and we'll link to it.
                    if (null == LowestVisibilityVertex)
                    {
                        SetInitialVisibilityVertex(crossingVertex);
                    }
                    else
                    {
                        Debug.Assert(PointComparer.Equal(End, crossingVertex.Point), "Expected this.End crossingVertex");
                        AppendHighestVisibilityVertex(crossingVertex);
                    }
                }
            }
            return(found);
        }
Exemple #9
0
        public void TwoInAConeLargerOffset()
        {
            var obstacles = new List <Polyline>();

            var direction = new Point(0, 1);
            var vg        = new VisibilityGraph();
            var points    = new List <Point> {
                new Point(0, 0),
                new Point(0.1, 10),
                new Point(-0.1, 20)
            };
            var ports = new Set <Point>();

            ports.Insert(points[0]);
            ports.Insert(points[1]);
            ports.Insert(points[2]);
            Polyline border = null;

            LineSweeper.Sweep(
                obstacles,
                direction,
                Math.PI / 6,
                vg,
                ports,
                border
                );
            Assert.AreEqual(vg.Edges.Count(), 2);
            var orig    = vg.FindVertex(points[0]);
            var outOrig = new List <VisibilityEdge>(orig.OutEdges);

            Assert.AreEqual(outOrig.Count, 1);
            var v10 = vg.FindVertex(points[1]);

            Assert.AreEqual(v10.OutEdges.Count(), 1);
            //Assert.IsTrue(vg.FindEdge(
        }
Exemple #10
0
        internal void CreateSparseVerticesAndEdges(VisibilityGraph vg)
        {
            if (this.sparsePerpendicularCoords == null)
            {
                return;
            }

            AppendGroupCrossingsThroughPoint(vg, Start);
            foreach (var perpCoord in this.sparsePerpendicularCoords.OrderBy(d => d))
            {
                var vertexLocation = this.CreatePointFromPerpCoord(perpCoord);
                Debug.Assert(this.ContainsPoint(vertexLocation), "vertexLocation is not on Segment");
                this.AppendVisibilityVertex(vg, vg.FindVertex(vertexLocation) ?? vg.AddVertex(vertexLocation));
            }
            AppendGroupCrossingsThroughPoint(vg, End);
            GroupBoundaryPointAndCrossingsList = null;

            this.sparsePerpendicularCoords.Clear();
            this.sparsePerpendicularCoords = null;
        }
Exemple #11
0
        /*
         * public void SaveInputToInputGeomtery()
         * {
         *  CheckTopology();
         *
         *  InitPoints();
         *  InitSegments();
         *  InputGeometry inputGeometry = new InputGeometry();
         *  file.WriteLine("# vertices");
         *  file.WriteLine(_pointIndices.Count + " 2 0 0");
         *  foreach (var tuple in _pointIndices)
         *  {
         *      file.WriteLine(tuple.Value + 1 + " " + tuple.Key.X + " " + tuple.Key.Y);
         *  }
         *  file.WriteLine("# segments");
         *  file.WriteLine(_segments.Count + " 0");
         *  int i = 1;
         *  foreach (var seg in _segments)
         *  {
         *      file.WriteLine(i + " " + (seg.Item1 + 1) + " " + (seg.Item2 + 1));
         *      i++;
         *  }
         *
         *  file.WriteLine("# holes");
         *  //file.WriteLine("0");
         *
         *  file.WriteLine(_holes.Count);
         *  for (int j = 0; j < _holes.Count; j++)-
         *  {
         *      file.WriteLine((j + 1) + " " + _holes[j].X + " " + _holes[j].Y);
         *  }
         * }
         */

        public void LoadOutputFileNode(string path)
        {
            int oldPoints = _pointList.Count;

            using (var file = new StreamReader(new FileStream(path, FileMode.Open)))
            {
                string line = file.ReadLine();
                if (line == null)
                {
                    throw new InvalidOperationException("unexpected end of file");
                }
                Regex.Split(line, @"\s{2,}");

                int numVertices = Int32.Parse(line.Split(' ').First());

                for (int i = 0; i < numVertices; i++)
                {
                    line = file.ReadLine();
                    if (line == null)
                    {
                        break;
                    }

                    line = line.TrimStart(' ');
                    var lineParsed = Regex.Split(line, @"\s{2,}");
                    int ind        = Int32.Parse(lineParsed[0]) - 1;
                    if (ind < oldPoints)
                    {
                        _outPoints[ind] = _visGraph.FindVertex(_pointList[ind]);
                    }
                    else
                    {
                        double x = Double.Parse(lineParsed[1]);
                        double y = Double.Parse(lineParsed[2]);
                        _outPoints[ind] = _visGraph.AddVertex(new Point(x, y));
                    }
                }
            }
        }