Edge of the planar graph.
Ejemplo n.º 1
0
        private bool isLinearEdgeEnabled(PlanarGraphEdge edge, OverlayType operation, Polygon polygon, bool inverseArgs)
        {
            if (isAreaEdgeEnabled(edge, operation, polygon, inverseArgs))
                return false;

            switch (operation)
            {
                case OverlayType.Intersection:
                    return edge.Label.UsedByObject1 && (edge.Label.UsedByObject2 || polygon.ContainsPoint(edge.CenterPoint()));
                case OverlayType.Union:
                    return edge.Label.UsedByObject1 && !polygon.ContainsPoint(edge.CenterPoint());
                case OverlayType.Difference:
                    return inverseArgs ? false : 
                                         edge.Label.UsedByObject1 && 
                                         !polygon.ContainsPoint(edge.CenterPoint()) &&
                                         !edge.Label.UsedByObject2;
                case OverlayType.SymmetricDifference:
                    return edge.Label.UsedByObject1 &&
                           !polygon.ContainsPoint(edge.CenterPoint()) &&
                           !edge.Label.UsedByObject2;
            }

            return false;
        }
Ejemplo n.º 2
0
        private bool isAreaEdgeEnabled(PlanarGraphEdge edge, OverlayType operation, Polygon polygon, bool inverseArgs)
        {
            bool usebyPolyline = edge.Label.UsedByObject1;
            bool usebyPolygon = edge.Label.UsedByObject2;

            switch (operation)
            {
                case OverlayType.Intersection:
                    return false;
                case OverlayType.Union:
                    if (usebyPolygon) return true;
                    break;
                case OverlayType.Difference:
                    return inverseArgs;
                case OverlayType.SymmetricDifference:
                    if (usebyPolygon) return true;
                    break;
            }

            return false;
        }
Ejemplo n.º 3
0
        private bool isAreaEdgeEnabled(PlanarGraphEdge edge, OverlayType operation, Polygon p1, Polygon p2)
        {
            bool usebyPolygon1 = edge.Label.UsedByObject1;
            bool usebyPolygon2 = edge.Label.UsedByObject2;

            switch (operation)
            {
                case OverlayType.Intersection:
                    if (usebyPolygon1 && usebyPolygon2 && edge.OrientationInObject1 == edge.OrientationInObject2)
                        return true;

                    if ((usebyPolygon1 ^ usebyPolygon2))
                        if (usebyPolygon1)
                        {
                            if (p2.ContainsPoint(edge.CenterPoint()))
                                return true;
                        }
                        else
                        {
                            if (p1.ContainsPoint(edge.CenterPoint()))
                                return true;
                        }
                    break;
                case OverlayType.Union:
                    if (usebyPolygon1 && usebyPolygon2 && edge.OrientationInObject1 == edge.OrientationInObject2)
                        return true;

                    if ((usebyPolygon1 ^ usebyPolygon2))
                        if (usebyPolygon1)
                        {
                            if (!p2.ContainsPoint(edge.CenterPoint()))
                                return true;
                        }
                        else
                        {
                            if (!p1.ContainsPoint(edge.CenterPoint()))
                                return true;
                        }
                    break;
                case OverlayType.Difference:
                    if (usebyPolygon1 && usebyPolygon2 && edge.OrientationInObject1 != edge.OrientationInObject2)
                        return true;

                    if ((usebyPolygon1 ^ usebyPolygon2))
                        if (usebyPolygon1)
                        {
                            if (!p2.ContainsPoint(edge.CenterPoint()))
                                return true;
                        }
                        else
                        {
                            if (p1.ContainsPoint(edge.CenterPoint()))
                                return true;
                        }
                    break;
                case OverlayType.SymmetricDifference:
                    if ((usebyPolygon1 ^ usebyPolygon2))
                        return true;
                    break;
            }

            return false;
        }
Ejemplo n.º 4
0
        private bool isLinearEdgeEnabled(PlanarGraphEdge edge, OverlayType operation, Polygon p1, Polygon p2)
        {
            if (isAreaEdgeEnabled(edge, operation, p1, p2))
                return false;

            switch (operation)
            {
                case OverlayType.Intersection:
                    return edge.Label.UsedByObject1 && edge.Label.UsedByObject2;
                case OverlayType.Union:
                    return false;
                case OverlayType.Difference:
                    return false;
                case OverlayType.SymmetricDifference:
                    return false;
            }

            return false;
        }
Ejemplo n.º 5
0
 private void addEdge(PlanarGraphEdge edge)
 {
     _edges.Add(edge);
 }
Ejemplo n.º 6
0
        private void addEdges()
        {
            List<SplittedSegment> list;
            if (_splittedSegmentIndex != null)
            {
                list = new List<SplittedSegment>();
                _splittedSegmentIndex.QueryObjectsInRectangle(_splittedSegmentIndex.IndexedSpace, list);
            }
            else
                list = _splittedSegments;

            _edges.Clear();

            foreach (SplittedSegment ss in list)
            {
                //if ((ss.Segment.V1.X == 161.836898803711 &&
                //     ss.Segment.V2.X == 162.26921081543)
                //    ||
                //    (ss.Segment.V2.X == 161.836898803711 &&
                //     ss.Segment.V1.X == 162.26921081543))
                //{
                //    int a = 1;
                //}

                PlanarGraphNode node1 = getNodeAt(ref ss.Segment.V1);
                PlanarGraphNode node2 = getNodeAt(ref ss.Segment.V2);

                if (node1 == null || node2 == null)
                    throw new InvalidOperationException("Internal error");

                if (node1 == node2)
                    throw new TopologyException();
                else
                {
                    PlanarGraphEdge edge = new PlanarGraphEdge(node1, node2);
                    edge.Label.UsedByObject1 = ss.UsedByObject1;
                    edge.Label.UsedByObject2 = ss.UsedByObject2;
                    edge.Label.Object1OccurrencesCount = ss.Object1OccurrencesCount;
                    edge.Label.Object2OccurrencesCount = ss.Object2OccurrencesCount;
                    node1.IncidentEdges.Add(edge);
                    node2.IncidentEdges.Add(edge);
                    addEdge(edge);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Constructs a contour.
        /// </summary>
        private Contour processContour(PlanarGraphEdge startEdge,
                                       bool backward)
        {
            Contour result = new Contour();

            PlanarGraphNode startNode = backward ? startEdge.Node2 : startEdge.Node1;
            result.Vertices.Add(startNode.Point);

            PlanarGraphNode currentNode = backward ? startEdge.Node1 : startEdge.Node2;
            result.Vertices.Add(currentNode.Point);

            // mark first edge
            if ((EdgeUsage)startEdge.Label.Tag != EdgeUsage.None)
            {
                startEdge.Label.Tag = EdgeUsage.Both;
                startEdge.IsVisited = true;
            }
            else
                startEdge.Label.Tag = backward ? EdgeUsage.Backward : EdgeUsage.Forward;

            PlanarGraphEdge currentEdge = startEdge;

            while (true)
            {
                List<PlanarGraphEdge> possibleEdges = new List<PlanarGraphEdge>();
                foreach (PlanarGraphEdge edge in currentNode.IncidentEdges)
                    if (edge.Enabled && edge != currentEdge)
                    {
                        switch ((EdgeUsage)edge.Label.Tag)
                        {
                            case EdgeUsage.Both: break;
                            case EdgeUsage.None:
                                possibleEdges.Add(edge);
                                break;
                            case EdgeUsage.Forward:
                                if (edge.Node2 == currentNode)
                                    possibleEdges.Add(edge);
                                break;
                            case EdgeUsage.Backward:
                                if (edge.Node1 == currentNode)
                                    possibleEdges.Add(edge);
                                break;
                        }
                    }

                double maxAngle = 0; 
                Segment previousEdge = new Segment(currentEdge.Node1.Point, currentEdge.Node2.Point);
                PlanarGraphEdge targetEdge = null;

                if (possibleEdges.Count == 0 && (EdgeUsage)currentEdge.Label.Tag != EdgeUsage.Both)
                    possibleEdges.Add(currentEdge);

                if (possibleEdges.Count == 1)
                    targetEdge = possibleEdges[0];
                else
                    for (int k = 0; k < possibleEdges.Count; k++)
                    {
                        PlanarGraphEdge edge = possibleEdges[k];
                        Segment kEdge = new Segment(edge.Node1.Point, edge.Node2.Point);
                        double angle;
                        try
                        {
                            angle = getAngleBetweenEdges(ref previousEdge, ref kEdge, false);
                        }
                        catch (ArgumentException)
                        {
                            throw new TopologyException();
                        }

                        if (angle >= _twoPi)
                            angle -= _twoPi;

                        if (angle > maxAngle)
                        {
                            maxAngle = angle;
                            targetEdge = edge;
                        }
                    }

                if (targetEdge != null)
                {
                    if (targetEdge.Node1.Point.ExactEquals(currentNode.Point))
                    {
                        if ((EdgeUsage)targetEdge.Label.Tag == EdgeUsage.None)
                            targetEdge.Label.Tag = EdgeUsage.Forward;
                        else
                        {
                            targetEdge.Label.Tag = EdgeUsage.Both;
                            targetEdge.IsVisited = true;
                        }

                        result.Vertices.Add((ICoordinate)targetEdge.Node2.Point.Clone());
                        currentNode = targetEdge.Node2;
                    }
                    else
                    {
                        if ((EdgeUsage)targetEdge.Label.Tag == EdgeUsage.None)
                            targetEdge.Label.Tag = EdgeUsage.Backward;
                        else
                        {
                            targetEdge.Label.Tag = EdgeUsage.Both;
                            targetEdge.IsVisited = true;
                        }

                        result.Vertices.Add((ICoordinate)targetEdge.Node1.Point.Clone());
                        currentNode = targetEdge.Node1;
                    }

                    previousEdge = new Segment(targetEdge.Node1.Point, targetEdge.Node2.Point);
                    currentEdge = targetEdge;

                    if (currentNode == startNode) // пришли, контур сформирован
                    {
                        result.Vertices.RemoveAt(result.Vertices.Count - 1);
                        break;
                    }
                }
                else break;
            }

            return result;
        }