Ejemplo n.º 1
0
        // ------------------------------------------------------------------------------------
        // helpers to generate test data
        public Region GenerateSquareRegion(int squareTop, int squareLeft, int squareBottom, int squareRight)
        {
            // TODO: validate parameters

            var testRegion = new Region();

            Span previousSpan = null;

            for (int currentRow = squareTop; currentRow <= squareBottom; currentRow += 1)
            {
                var newSpan = new Span();

                newSpan.start = squareLeft;
                newSpan.end   = squareRight;
                newSpan.row   = currentRow;

                if (currentRow > squareTop)
                {
                    newSpan.addSpanAbove(previousSpan);
                    previousSpan.addSpanBelow(newSpan);
                }

                previousSpan = newSpan;

                testRegion.AddSpan(newSpan);
            }

            return(testRegion);
        }
Ejemplo n.º 2
0
        // ----------------------------------------------------------------
        // finds region of points that touch specified row,col in topoData that are of same value
        private Region getRegion(int row, int col)
        {
            var newRegion = new Region();

            newRegion.regionValue = _topoData.ValueAt(row, col);

            var seedSpan = getSpan(row, col, newRegion);

            var spansToCheck = new List <Span>();

            spansToCheck.Add(seedSpan);

            while (spansToCheck.Count > 0)
            {
                Span checkSpan = spansToCheck[0];
                spansToCheck.RemoveAt(0);

                // get spans above
                if (checkSpan.row > rectTop)  // 0)
                {
                    var aboveSpans = getOverlappingSpans(checkSpan, checkSpan.row - 1, newRegion);

                    spansToCheck.AddRange(aboveSpans);
                }

                // get spans below
                if (checkSpan.row < rectBottom)  // _topoData.NumRows - 1)
                {
                    var belowSpans = getOverlappingSpans(checkSpan, checkSpan.row + 1, newRegion);

                    spansToCheck.AddRange(belowSpans);
                }

                // done checking, add span to region
                newRegion.AddSpan(checkSpan);
            }

            // connect up above/below spans
            foreach (var currentSpan in newRegion.spanList)
            {
                connectSpanToOverlappingSpansOnAdjacentRows(currentSpan, newRegion);
            }

            // above/below spans must be fully built before sibling discovery
            foreach (var currentSpan in newRegion.spanList)
            {
                connectToSiblingSpans(currentSpan);
            }

            return(newRegion);
        }