/// <summary>
 /// Update incomplete dirEdge labels from the labelling for the node.
 /// </summary>
 /// <param name="nodeLabel"></param>
 public void UpdateLabelling(Label nodeLabel)
 {
     foreach (DirectedEdge de in Edges)
     {
         Label label = de.Label;
         label.SetAllLocationsIfNull(0, nodeLabel.GetLocation(0));
         label.SetAllLocationsIfNull(1, nodeLabel.GetLocation(1));
     }
 }
Beispiel #2
0
        /// <summary>
        /// Updates the label of a node to BOUNDARY,
        /// obeying the mod-2 boundaryDetermination rule.
        /// </summary>
        /// <param name="argIndex"></param>
        public void SetLabelBoundary(int argIndex)
        {
            if (Label == null)
            {
                return;
            }

            // determine the current location for the point (if any)
            Location loc = Location.Null;

            if (Label != null)
            {
                loc = Label.GetLocation(argIndex);
            }
            // flip the loc
            Location newLoc;

            switch (loc)
            {
            case Location.Boundary:
                newLoc = Location.Interior;
                break;

            case Location.Interior:
                newLoc = Location.Boundary;
                break;

            default:
                newLoc = Location.Boundary;
                break;
            }
            Label.SetLocation(argIndex, newLoc);
        }
Beispiel #3
0
        /// <summary>
        /// Converts a Label to a Line label (that is, one with no side Location).
        /// </summary>
        /// <param name="label">Label to convert.</param>
        /// <returns>Label as Line label.</returns>
        public static Label ToLineLabel(Label label)
        {
            Label lineLabel = new Label(Location.Null);

            for (int i = 0; i < 2; i++)
            {
                lineLabel.SetLocation(i, label.GetLocation(i));
            }
            return(lineLabel);
        }
Beispiel #4
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 <EdgeEnd> 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    = edges[lastEdgeIndex].Label;
            Location startLoc      = startLabel.GetLocation(geomIndex, Positions.Left);

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

            Location currLoc = startLoc;

            foreach (EdgeEnd e in Edges)
            {
                Label label = e.Label;
                // we assume that we are only checking a area
                Assert.IsTrue(label.IsArea(geomIndex), "Found non-area edge");
                Location leftLoc  = label.GetLocation(geomIndex, Positions.Left);
                Location 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);
        }
Beispiel #5
0
        public void OLDSetEdgeDepths(Positions position, int depth)
        {
            int       depthDelta    = Edge.DepthDelta;
            Location  loc           = Label.GetLocation(0, position);
            Positions oppositePos   = Position.Opposite(position);
            Location  oppositeLoc   = Label.GetLocation(0, oppositePos);
            int       delta         = Math.Abs(depthDelta) * DepthFactor(loc, oppositeLoc);
            int       oppositeDepth = depth + delta;

            SetDepth(position, depth);
            SetDepth(oppositePos, oppositeDepth);
        }
Beispiel #6
0
 /// <summary>
 /// To merge labels for two nodes,
 /// the merged location for each LabelElement is computed.
 /// The location for the corresponding node LabelElement is set to the result,
 /// as long as the location is non-null.
 /// </summary>
 /// <param name="label2"></param>
 public void MergeLabel(Label label2)
 {
     for (int i = 0; i < 2; i++)
     {
         Location loc     = ComputeMergedLocation(label2, i);
         Location thisLoc = Label.GetLocation(i);
         if (thisLoc == Location.Null)
         {
             Label.SetLocation(i, loc);
         }
     }
 }
Beispiel #7
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), Dimension.Curve);
     if (label.IsArea())
     {
         im.SetAtLeastIfValid(label.GetLocation(0, Positions.Left), label.GetLocation(1, Positions.Left), Dimension.Surface);
         im.SetAtLeastIfValid(label.GetLocation(0, Positions.Right), label.GetLocation(1, Positions.Right), Dimension.Surface);
     }
 }
Beispiel #8
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 Location ComputeMergedLocation(Label label2, int eltIndex)
        {
            /*Location loc = Location.Null*/
            Location loc = Label.GetLocation(eltIndex);

            if (!label2.IsNull(eltIndex))
            {
                Location nLoc = label2.GetLocation(eltIndex);
                if (loc != Location.Boundary)
                {
                    loc = nLoc;
                }
            }
            return(loc);
        }
Beispiel #9
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)
        {
            Location loc = deLabel.GetLocation(geomIndex, Positions.Right);

            // no information to be had from this label
            if (loc == Location.Null)
            {
                return;
            }
            // if there is no current RHS value, set it
            if (_label.GetLocation(geomIndex) == Location.Null)
            {
                _label.SetLocation(geomIndex, loc);
                return;
            }
        }
Beispiel #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="geomIndex"></param>
        /// <param name="coord"></param>
        /// <returns></returns>
        public bool IsBoundaryNode(int geomIndex, Coordinate coord)
        {
            Node node = _nodes.Find(coord);

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

            if (label != null && label.GetLocation(geomIndex) == Location.Boundary)
            {
                return(true);
            }
            return(false);
        }
Beispiel #11
0
        /// <summary>
        /// Adds candidate boundary points using the current <see cref="IBoundaryNodeRule"/>.
        /// This is used to add the boundary
        /// points of dim-1 geometries (Curves/MultiCurves).
        /// </summary>
        /// <param name="argIndex"></param>
        /// <param name="coord"></param>
        private void InsertBoundaryPoint(int argIndex, Coordinate coord)
        {
            var n = NodeMap.AddNode(coord);
            // nodes always have labels
            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)
            //Location loc = Location.Null;
            var loc = lbl.GetLocation(argIndex, Positions.On);

            if (loc == Location.Boundary)
            {
                boundaryCount++;
            }

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

            lbl.SetLocation(argIndex, newLoc);
        }
Beispiel #12
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++)
         {
             Location loc = lbl.GetLocation(i, (Positions)j);
             if (loc == Location.Exterior || loc == Location.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);
                 }
             }
         }
     }
 }
Beispiel #13
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(Location.Null);
            IEnumerator <EdgeEnd> it = GetEnumerator();

            while (it.MoveNext())
            {
                EdgeEnd ee     = it.Current;
                Edge    e      = ee.Edge;
                Label   eLabel = e.Label;
                for (int i = 0; i < 2; i++)
                {
                    Location eLoc = eLabel.GetLocation(i);
                    if (eLoc == Location.Interior || eLoc == Location.Boundary)
                    {
                        _label.SetLocation(i, Location.Interior);
                    }
                }
            }
        }
Beispiel #14
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
            Location startLoc = Location.Null;

            // initialize loc to location of last Curve side (if any)
            foreach (EdgeEnd e in Edges)
            {
                Label label = e.Label;
                if (label.IsArea(geomIndex) && label.GetLocation(geomIndex, Positions.Left) != Location.Null)
                {
                    startLoc = label.GetLocation(geomIndex, Positions.Left);
                }
            }
            // no labelled sides found, so no labels to propagate
            if (startLoc == Location.Null)
            {
                return;
            }

            Location currLoc = startLoc;

            foreach (EdgeEnd e in Edges)
            {
                Label label = e.Label;
                // set null On values to be in current location
                if (label.GetLocation(geomIndex, Positions.On) == Location.Null)
                {
                    label.SetLocation(geomIndex, Positions.On, currLoc);
                }
                // set side labels (if any)
                if (label.IsArea(geomIndex))
                {
                    Location leftLoc  = label.GetLocation(geomIndex, Positions.Left);
                    Location rightLoc = label.GetLocation(geomIndex, Positions.Right);
                    // if there is a right location, that is the next location to propagate
                    if (rightLoc != Location.Null)
                    {
                        if (rightLoc != currLoc)
                        {
                            throw new TopologyException("side location conflict", e.Coordinate);
                        }
                        if (leftLoc == Location.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) == Location.Null, "found single null side");
                        label.SetLocation(geomIndex, Positions.Right, currLoc);
                        label.SetLocation(geomIndex, Positions.Left, currLoc);
                    }
                }
            }
        }
Beispiel #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="geomGraph"></param>
        public virtual void ComputeLabelling(GeometryGraph[] geomGraph)
        {
            ComputeEdgeEndLabels(geomGraph[0].BoundaryNodeRule);
            // 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 };
            foreach (var e in Edges)
            {
                Label label = e.Label;
                for (int geomi = 0; geomi < 2; geomi++)
                {
                    if (label.IsLine(geomi) && label.GetLocation(geomi) == Location.Boundary)
                    {
                        hasDimensionalCollapseEdge[geomi] = true;
                    }
                }
            }
            foreach (var e in Edges)
            {
                Label label = e.Label;
                for (int geomi = 0; geomi < 2; geomi++)
                {
                    if (label.IsAnyNull(geomi))
                    {
                        Location loc;
                        if (hasDimensionalCollapseEdge[geomi])
                        {
                            loc = Location.Exterior;
                        }
                        else
                        {
                            Coordinate p = e.Coordinate;
                            loc = GetLocation(geomi, p, geomGraph);
                        }
                        label.SetAllLocationsIfNull(geomi, loc);
                    }
                }
            }
        }