private List <HeadingItem> findHeadings(List <Stroke> horizontalLines, ContextNodeCollection contextNodeCollection) { //Group lines together into "Heading Groups" List <HeadingItem> headings = new List <HeadingItem>(); foreach (Stroke node1 in horizontalLines) { List <HeadingItem> intersectHeadings = new List <HeadingItem>(); foreach (HeadingItem heading in headings) { bool intersectsAny = false; foreach (Stroke node2 in heading.lines) { Rect first = node1.GetBounds(); Rect second = node2.GetBounds(); if (Math.Abs(first.Y - second.Y) < Constants.HEADING_LINE_DISTANCE_MAX && Math.Abs(first.X - second.X) < Constants.HEADING_LINE_DISTANCE_MAX) { intersectsAny = true; break; } } if (intersectsAny) { intersectHeadings.Add(heading); } } HeadingItem resultHeading = new HeadingItem(); foreach (HeadingItem heading in intersectHeadings) { resultHeading.lines.AddRange(heading.lines); headings.Remove(heading); } resultHeading.lines.Add(node1); headings.Add(resultHeading); } //Find words that associate to Heading Groups foreach (ContextNode node in contextNodeCollection) { if (node.Strokes.Count == 0) { continue; } Rect underlineBounds = node.Strokes.GetBounds(); if (node is InkWordNode) { if ((node as InkWordNode).GetBaseline() != null && (node as InkWordNode).GetBaseline().Count > 0) { double baseline = (node as InkWordNode).GetBaseline()[0].Y; underlineBounds.Y = baseline; } InkWordNode word = node as InkWordNode; foreach (HeadingItem heading in headings) { if (heading.intersects(underlineBounds)) { heading.text.Add(word); break; } } } } //Remove bad headings List <HeadingItem> actualHeadings = new List <HeadingItem>(); foreach (HeadingItem heading in headings) { if (heading.text.Count > 0) { actualHeadings.Add(heading); } } return(actualHeadings); }
private List<HeadingItem> findHeadings(List<Stroke> horizontalLines, ContextNodeCollection contextNodeCollection) { //Group lines together into "Heading Groups" List<HeadingItem> headings = new List<HeadingItem>(); foreach (Stroke node1 in horizontalLines) { List<HeadingItem> intersectHeadings = new List<HeadingItem>(); foreach (HeadingItem heading in headings) { bool intersectsAny = false; foreach (Stroke node2 in heading.lines) { Rect first = node1.GetBounds(); Rect second = node2.GetBounds(); if (Math.Abs(first.Y - second.Y) < Constants.HEADING_LINE_DISTANCE_MAX && Math.Abs(first.X - second.X) < Constants.HEADING_LINE_DISTANCE_MAX) { intersectsAny = true; break; } } if (intersectsAny) { intersectHeadings.Add(heading); } } HeadingItem resultHeading = new HeadingItem(); foreach (HeadingItem heading in intersectHeadings) { resultHeading.lines.AddRange(heading.lines); headings.Remove(heading); } resultHeading.lines.Add(node1); headings.Add(resultHeading); } //Find words that associate to Heading Groups foreach (ContextNode node in contextNodeCollection) { if (node.Strokes.Count == 0) { continue; } Rect underlineBounds = node.Strokes.GetBounds(); if (node is InkWordNode) { if ((node as InkWordNode).GetBaseline() != null && (node as InkWordNode).GetBaseline().Count > 0) { double baseline = (node as InkWordNode).GetBaseline()[0].Y; underlineBounds.Y = baseline; } InkWordNode word = node as InkWordNode; foreach (HeadingItem heading in headings) { if (heading.intersects(underlineBounds)) { heading.text.Add(word); break; } } } } //Remove bad headings List<HeadingItem> actualHeadings = new List<HeadingItem>(); foreach (HeadingItem heading in headings) { if (heading.text.Count > 0) { actualHeadings.Add(heading); } } return actualHeadings; }