Пример #1
0
 /// <summary>
 /// Update incomplete dirEdge labels from the labelling for the node.
 /// </summary>
 /// <param name="nodeLabel"></param>
 public void UpdateLabelling(Label nodeLabel)
 {
     for (IEnumerator it = GetEnumerator(); it.MoveNext();)
     {
         DirectedEdge de    = (DirectedEdge)it.Current;
         Label        label = de.Label;
         label.SetAllLocationsIfNull(0, nodeLabel.GetLocation(0));
         label.SetAllLocationsIfNull(1, nodeLabel.GetLocation(1));
     }
 }
Пример #2
0
        /// <summary>
        /// Converts a Label to a Line label (that is, one with no side Locations).
        /// </summary>
        /// <param name="label">Label to convert.</param>
        /// <returns>Label as Line label.</returns>
        public static Label ToLineLabel(Label label)
        {
            Label lineLabel = new Label(Locations.Null);

            for (int i = 0; i < 2; i++)
            {
                lineLabel.SetLocation(i, label.GetLocation(i));
            }
            return(lineLabel);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="geomIndex"></param>
        /// <returns></returns>
        private bool CheckAreaLabelsConsistent(int geomIndex)
        {
            // Since edges are stored in CCW order around the node,
            // As we move around the ring we move from the right to the left side of the edge
            IList edges = Edges;

            // if no edges, trivially consistent
            if (edges.Count <= 0)
            {
                return(true);
            }
            // initialize startLoc to location of last Curve side (if any)
            int       lastEdgeIndex = edges.Count - 1;
            Label     startLabel    = ((EdgeEnd)edges[lastEdgeIndex]).Label;
            Locations startLoc      = startLabel.GetLocation(geomIndex, Positions.Left);

            Assert.IsTrue(startLoc != Locations.Null, "Found unlabelled area edge");

            Locations currLoc = startLoc;

            for (IEnumerator it = GetEnumerator(); it.MoveNext();)
            {
                EdgeEnd e     = (EdgeEnd)it.Current;
                Label   label = e.Label;
                // we assume that we are only checking a area
                Assert.IsTrue(label.IsArea(geomIndex), "Found non-area edge");
                Locations leftLoc  = label.GetLocation(geomIndex, Positions.Left);
                Locations rightLoc = label.GetLocation(geomIndex, Positions.Right);
                // check that edge is really a boundary between inside and outside!
                if (leftLoc == rightLoc)
                {
                    return(false);
                }
                // check side location conflict
                if (rightLoc != currLoc)
                {
                    return(false);
                }
                currLoc = leftLoc;
            }
            return(true);
        }
Пример #4
0
 /// <summary>
 /// Updates an IM from the label for an edge.
 /// Handles edges from both L and A geometries.
 /// </summary>
 /// <param name="im"></param>
 /// <param name="label"></param>
 public static void UpdateIM(Label label, IntersectionMatrix im)
 {
     im.SetAtLeastIfValid(label.GetLocation(0, Positions.On), label.GetLocation(1, Positions.On), Dimensions.Curve);
     if (label.IsArea())
     {
         im.SetAtLeastIfValid(label.GetLocation(0, Positions.Left), label.GetLocation(1, Positions.Left), Dimensions.Surface);
         im.SetAtLeastIfValid(label.GetLocation(0, Positions.Right), label.GetLocation(1, Positions.Right), Dimensions.Surface);
     }
 }
Пример #5
0
        /// <summary>
        /// The location for a given eltIndex for a node will be one
        /// of { Null, Interior, Boundary }.
        /// A node may be on both the boundary and the interior of a point;
        /// in this case, the rule is that the node is considered to be in the boundary.
        /// The merged location is the maximum of the two input values.
        /// </summary>
        /// <param name="label2"></param>
        /// <param name="eltIndex"></param>
        public Locations ComputeMergedLocation(Label label2, int eltIndex)
        {
            Locations loc = Locations.Null;

            loc = label.GetLocation(eltIndex);
            if (!label2.IsNull(eltIndex))
            {
                Locations nLoc = label2.GetLocation(eltIndex);
                if (loc != Locations.Boundary)
                {
                    loc = nLoc;
                }
            }
            return(loc);
        }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="geomIndex"></param>
        /// <param name="coord"></param>
        /// <returns></returns>
        public bool IsBoundaryNode(int geomIndex, ICoordinate coord)
        {
            Node node = nodes.Find(coord);

            if (node == null)
            {
                return(false);
            }
            Label label = node.Label;

            if (label != null && label.GetLocation(geomIndex) == Locations.Boundary)
            {
                return(true);
            }
            return(false);
        }
Пример #7
0
        /// <summary>
        /// Merge the RHS label from a DirectedEdge into the label for this EdgeRing.
        /// The DirectedEdge label may be null.  This is acceptable - it results
        /// from a node which is NOT an intersection node between the Geometries
        /// (e.g. the end node of a LinearRing).  In this case the DirectedEdge label
        /// does not contribute any information to the overall labelling, and is simply skipped.
        /// </summary>
        /// <param name="deLabel"></param>
        /// <param name="geomIndex"></param>
        protected void MergeLabel(Label deLabel, int geomIndex)
        {
            Locations loc = deLabel.GetLocation(geomIndex, Positions.Right);

            // no information to be had from this label
            if (loc == Locations.Null)
            {
                return;
            }
            // if there is no current RHS value, set it
            if (label.GetLocation(geomIndex) == Locations.Null)
            {
                label.SetLocation(geomIndex, loc);
                return;
            }
        }
Пример #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="lbl"></param>
 public void Add(Label lbl)
 {
     for (int i = 0; i < 2; i++)
     {
         for (int j = 1; j < 3; j++)
         {
             Locations loc = lbl.GetLocation(i, (Positions)j);
             if (loc == Locations.Exterior || loc == Locations.Interior)
             {
                 // initialize depth if it is null, otherwise add this location value
                 if (IsNull(i, (Positions)j))
                 {
                     depth[i, j] = DepthAtLocation(loc);
                 }
                 else
                 {
                     depth[i, j] += DepthAtLocation(loc);
                 }
             }
         }
     }
 }
Пример #9
0
        /// <summary>
        /// Adds points using the mod-2 rule of SFS.  This is used to add the boundary
        /// points of dim-1 geometries (Curves/MultiCurves).  According to the SFS,
        /// an endpoint of a Curve is on the boundary
        /// if it is in the boundaries of an odd number of Geometries.
        /// </summary>
        /// <param name="argIndex"></param>
        /// <param name="coord"></param>
        private void InsertBoundaryPoint(int argIndex, ICoordinate coord)
        {
            Node  n   = nodes.AddNode((Coordinate)coord);
            Label lbl = n.Label;
            // the new point to insert is on a boundary
            int boundaryCount = 1;
            // determine the current location for the point (if any)
            Locations loc = Locations.Null;

            if (lbl != null)
            {
                loc = lbl.GetLocation(argIndex, Positions.On);
            }
            if (loc == Locations.Boundary)
            {
                boundaryCount++;
            }

            // determine the boundary status of the point according to the Boundary Determination Rule
            Locations newLoc = DetermineBoundary(boundaryCount);

            lbl.SetLocation(argIndex, newLoc);
        }
Пример #10
0
        /// <summary>
        /// Compute the labelling for all dirEdges in this star, as well
        /// as the overall labelling.
        /// </summary>
        /// <param name="geom"></param>
        public override void ComputeLabelling(GeometryGraph[] geom)
        {
            base.ComputeLabelling(geom);

            // determine the overall labelling for this DirectedEdgeStar
            // (i.e. for the node it is based at)
            label = new Label(Locations.Null);
            IEnumerator it = GetEnumerator();

            while (it.MoveNext())
            {
                EdgeEnd ee     = (EdgeEnd)it.Current;
                Edge    e      = ee.Edge;
                Label   eLabel = e.Label;
                for (int i = 0; i < 2; i++)
                {
                    Locations eLoc = eLabel.GetLocation(i);
                    if (eLoc == Locations.Interior || eLoc == Locations.Boundary)
                    {
                        label.SetLocation(i, Locations.Interior);
                    }
                }
            }
        }
Пример #11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="label"></param>
 /// <param name="opCode"></param>
 /// <returns></returns>
 public static bool IsResultOfOp(Label label, SpatialFunctions opCode)
 {
     Locations loc0 = label.GetLocation(0);
     Locations loc1 = label.GetLocation(1);
     return IsResultOfOp(loc0, loc1, opCode);
 }
Пример #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="geom"></param>
        public virtual void ComputeLabelling(GeometryGraph[] geom)
        {
            ComputeEdgeEndLabels();
            // Propagate side labels  around the edges in the star
            // for each parent Geometry
            PropagateSideLabels(0);
            PropagateSideLabels(1);

            /*
             * If there are edges that still have null labels for a point
             * this must be because there are no area edges for that point incident on this node.
             * In this case, to label the edge for that point we must test whether the
             * edge is in the interior of the point.
             * To do this it suffices to determine whether the node for the edge is in the interior of an area.
             * If so, the edge has location Interior for the point.
             * In all other cases (e.g. the node is on a line, on a point, or not on the point at all) the edge
             * has the location Exterior for the point.
             *
             * Note that the edge cannot be on the Boundary of the point, since then
             * there would have been a parallel edge from the Geometry at this node also labelled Boundary
             * and this edge would have been labelled in the previous step.
             *
             * This code causes a problem when dimensional collapses are present, since it may try and
             * determine the location of a node where a dimensional collapse has occurred.
             * The point should be considered to be on the Exterior
             * of the polygon, but locate() will return Interior, since it is passed
             * the original Geometry, not the collapsed version.
             *
             * If there are incident edges which are Line edges labelled Boundary,
             * then they must be edges resulting from dimensional collapses.
             * In this case the other edges can be labelled Exterior for this Geometry.
             *
             * MD 8/11/01 - NOT True!  The collapsed edges may in fact be in the interior of the Geometry,
             * which means the other edges should be labelled Interior for this Geometry.
             * Not sure how solve this...  Possibly labelling needs to be split into several phases:
             * area label propagation, symLabel merging, then finally null label resolution.
             */
            bool[] hasDimensionalCollapseEdge = { false, false };
            for (IEnumerator it = GetEnumerator(); it.MoveNext();)
            {
                EdgeEnd e     = (EdgeEnd)it.Current;
                Label   label = e.Label;
                for (int geomi = 0; geomi < 2; geomi++)
                {
                    if (label.IsLine(geomi) && label.GetLocation(geomi) == Locations.Boundary)
                    {
                        hasDimensionalCollapseEdge[geomi] = true;
                    }
                }
            }
            for (IEnumerator it = GetEnumerator(); it.MoveNext();)
            {
                EdgeEnd e     = (EdgeEnd)it.Current;
                Label   label = e.Label;
                for (int geomi = 0; geomi < 2; geomi++)
                {
                    if (label.IsAnyNull(geomi))
                    {
                        Locations loc = Locations.Null;
                        if (hasDimensionalCollapseEdge[geomi])
                        {
                            loc = Locations.Exterior;
                        }
                        else
                        {
                            ICoordinate p = e.Coordinate;
                            loc = GetLocation(geomi, p, geom);
                        }
                        label.SetAllLocationsIfNull(geomi, loc);
                    }
                }
            }
        }
Пример #13
0
 /// <summary> 
 /// The location for a given eltIndex for a node will be one
 /// of { Null, Interior, Boundary }.
 /// A node may be on both the boundary and the interior of a point;
 /// in this case, the rule is that the node is considered to be in the boundary.
 /// The merged location is the maximum of the two input values.
 /// </summary>
 /// <param name="label2"></param>
 /// <param name="eltIndex"></param>
 public Locations ComputeMergedLocation(Label label2, int eltIndex)
 {
     Locations loc = Locations.Null;
     loc = label.GetLocation(eltIndex);
     if (!label2.IsNull(eltIndex))
     {
         Locations nLoc = label2.GetLocation(eltIndex);
         if (loc != Locations.Boundary)
             loc = nLoc;
     }
     return loc;
 }
Пример #14
0
 /// <summary> 
 /// Updates an IM from the label for an edge.
 /// Handles edges from both L and A geometries.
 /// </summary>
 /// <param name="im"></param>
 /// <param name="label"></param>
 public static void UpdateIM(Label label, IntersectionMatrix im)
 {
     im.SetAtLeastIfValid(label.GetLocation(0, Positions.On), label.GetLocation(1, Positions.On), Dimensions.Curve);
     if (label.IsArea())
     {
         im.SetAtLeastIfValid(label.GetLocation(0, Positions.Left), label.GetLocation(1, Positions.Left), Dimensions.Surface);
         im.SetAtLeastIfValid(label.GetLocation(0, Positions.Right), label.GetLocation(1, Positions.Right), Dimensions.Surface);
     }
 }
Пример #15
0
 /// <summary>
 /// Compute the change in depth as an edge is crossed from R to L.
 /// </summary>
 /// <param name="label"></param>
 private static int DepthDelta(Label label)
 {
     Locations lLoc = label.GetLocation(0, Positions.Left);
     Locations rLoc = label.GetLocation(0, Positions.Right);
     if (lLoc == Locations.Interior && rLoc == Locations.Exterior)
         return 1;
     else if (lLoc == Locations.Exterior && rLoc == Locations.Interior)
         return -1;
     return 0;
 }
Пример #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="geomIndex"></param>
        public void PropagateSideLabels(int geomIndex)
        {
            // Since edges are stored in CCW order around the node,
            // As we move around the ring we move from the right to the left side of the edge
            Locations startLoc = Locations.Null;

            // initialize loc to location of last Curve side (if any)
            for (IEnumerator it = GetEnumerator(); it.MoveNext();)
            {
                EdgeEnd e     = (EdgeEnd)it.Current;
                Label   label = e.Label;
                if (label.IsArea(geomIndex) && label.GetLocation(geomIndex, Positions.Left) != Locations.Null)
                {
                    startLoc = label.GetLocation(geomIndex, Positions.Left);
                }
            }
            // no labelled sides found, so no labels to propagate
            if (startLoc == Locations.Null)
            {
                return;
            }

            Locations currLoc = startLoc;

            for (IEnumerator it = GetEnumerator(); it.MoveNext();)
            {
                EdgeEnd e     = (EdgeEnd)it.Current;
                Label   label = e.Label;
                // set null On values to be in current location
                if (label.GetLocation(geomIndex, Positions.On) == Locations.Null)
                {
                    label.SetLocation(geomIndex, Positions.On, currLoc);
                }
                // set side labels (if any)
                if (label.IsArea(geomIndex))
                {
                    Locations leftLoc  = label.GetLocation(geomIndex, Positions.Left);
                    Locations rightLoc = label.GetLocation(geomIndex, Positions.Right);
                    // if there is a right location, that is the next location to propagate
                    if (rightLoc != Locations.Null)
                    {
                        if (rightLoc != currLoc)
                        {
                            throw new TopologyException("side location conflict", e.Coordinate);
                        }
                        if (leftLoc == Locations.Null)
                        {
                            Assert.ShouldNeverReachHere("found single null side (at " + e.Coordinate + ")");
                        }
                        currLoc = leftLoc;
                    }
                    else
                    {
                        /* RHS is null - LHS must be null too.
                         *  This must be an edge from the other point, which has no location
                         *  labelling for this point.  This edge must lie wholly inside or outside
                         *  the other point (which is determined by the current location).
                         *  Assign both sides to be the current location.
                         */
                        Assert.IsTrue(label.GetLocation(geomIndex, Positions.Left) == Locations.Null, "found single null side");
                        label.SetLocation(geomIndex, Positions.Right, currLoc);
                        label.SetLocation(geomIndex, Positions.Left, currLoc);
                    }
                }
            }
        }
Пример #17
0
 /// <summary> 
 /// Update incomplete dirEdge labels from the labelling for the node.
 /// </summary>
 /// <param name="nodeLabel"></param>
 public void UpdateLabelling(Label nodeLabel)
 {
     for (IEnumerator it = GetEnumerator(); it.MoveNext(); )
     {
         DirectedEdge de = (DirectedEdge)it.Current;
         Label label = de.Label;
         label.SetAllLocationsIfNull(0, nodeLabel.GetLocation(0));
         label.SetAllLocationsIfNull(1, nodeLabel.GetLocation(1));
     }
 }
Пример #18
0
 /// <summary> 
 /// Merge the RHS label from a DirectedEdge into the label for this EdgeRing.
 /// The DirectedEdge label may be null.  This is acceptable - it results
 /// from a node which is NOT an intersection node between the Geometries
 /// (e.g. the end node of a LinearRing).  In this case the DirectedEdge label
 /// does not contribute any information to the overall labelling, and is simply skipped.
 /// </summary>
 /// <param name="deLabel"></param>
 /// <param name="geomIndex"></param>
 protected void MergeLabel(Label deLabel, int geomIndex)
 {
     Locations loc = deLabel.GetLocation(geomIndex, Positions.Right);
     // no information to be had from this label
     if (loc == Locations.Null)
         return;
     // if there is no current RHS value, set it
     if (label.GetLocation(geomIndex) == Locations.Null)
     {
         label.SetLocation(geomIndex, loc);
         return;
     }
 }
Пример #19
0
 /// <summary>
 /// Converts a Label to a Line label (that is, one with no side Locations).
 /// </summary>
 /// <param name="label">Label to convert.</param>
 /// <returns>Label as Line label.</returns>
 public static Label ToLineLabel(Label label)
 {
     Label lineLabel = new Label(Locations.Null);
     for (int i = 0; i < 2; i++)
         lineLabel.SetLocation(i, label.GetLocation(i));
     return lineLabel;
 }
Пример #20
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="lbl"></param>
 public void Add(Label lbl)
 {
     for (int i = 0; i < 2; i++)
     {
         for (int j = 1; j < 3; j++)
         {
             Locations loc = lbl.GetLocation(i, (Positions)j);
             if (loc == Locations.Exterior || loc == Locations.Interior)
             {
                 // initialize depth if it is null, otherwise add this location value
                 if (IsNull(i, (Positions)j))
                      depth[i,j]  = DepthAtLocation(loc);
                 else depth[i,j] += DepthAtLocation(loc);
             }
         }
     }
 }