Beispiel #1
0
        /// <summary>
        /// Classifies a span with regard to already processed spans
        /// </summary>
        /// <param name="currentSpan"></param>
        /// <param name="currentComponentSet"></param>
        static void PlaceSpan(Span currentSpan, ConnectedComponentSet currentComponentSet)
        {
            if (currentSpan.Y == 0)
            {
                // for the first row, just accumulate the spans in the Generation 0
                currentComponentSet.AddNewComponentFromSpan(currentSpan);
                return;
            }

            // find all spans from Generation 1 that "touch" this span
            ConnectedComponentSet componentsToJoin = new ConnectedComponentSet();

            componentsToJoin.AddRange(
                currentComponentSet.Where(
                    component => component.FrontalSpans.IntersectsWith(currentSpan)));

            // if we "touch" 0 existing components, create a new one
            if (componentsToJoin.Count == 0)
            {
                currentComponentSet.AddNewComponentFromSpan(currentSpan);
            }
            // if we touch one component, append the current span to its bottom
            else if (componentsToJoin.Count == 1)
            {
                componentsToJoin[0].NewFrontalSpans.Add(currentSpan);
            }
            // if we touch more than one component, it means they all belong together.
            // Now we unite all of these components into one.
            else
            {
                for (int i = 1; i < componentsToJoin.Count; i++)
                {
                    componentsToJoin[0].NewFrontalSpans.Add(currentSpan);
                    componentsToJoin[0].UnionWith(componentsToJoin[i]);
                    currentComponentSet.Remove(componentsToJoin[i]);
                }
            }
        }