示例#1
0
        public DrawsomePic(InkRecognitionRoot root, List <InkRecognizerStroke> inkStrokes, int hookUpDistance)
        {
            this.HookUpDistance = hookUpDistance;
            this.InkRoot        = root;
            if (root.GetShapes().Count() == 0)
            {
                throw new Exception("The Graph is Empty");
            }

            //this.Root = new DrawsomeShape(root.GetShapes().ToList().OrderBy(item => item.BoundingRect.TopY).First());

            // get all recognized shapes and set the text belonged to them
            foreach (var shape in root.GetShapes())
            {
                var shapeToAdd = new DrawsomeShape(shape)
                {
                    Text = root.GetLines().ToList().FindAll(item => shape.Contains(item)).FirstOrDefault()?.RecognizedText
                };
                if (shapeToAdd.Type != ShapeType.Drawing)
                {
                    // add all shapes except line
                    this.AllShapes.Add(shapeToAdd);
                }
            }

            // units include lines and shapes and texts
            foreach (var unit in root.GetUnits())
            {
                var unitToAdd = new DrawsomeObj(unit);
                this.AllUnits.Add(unitToAdd);
            }

            var inkLines = root.GetUnits().Where(item => (item as InkDrawing)?.RecognizedShape == DrawingShapeKind.Drawing).Where(item => item.BoundingRect.Width + item.BoundingRect.Height > 20);



            foreach (var line in inkLines)
            {
                this.AllLines.Add(new DrawsomeLine(line, inkStrokes, 3, HookUpDistance));
            }

            // we iterate each shape to detect the next and previous line
            foreach (var dShape in this.AllShapes)
            {
                var nextLines = this.AllLines.OrderByDescending(item => dShape.OverlapSizeWithLinesBegin(item, item.LittleRects.Count / 10)).Where(item => dShape.OverlapSizeWithLinesBegin(item, item.LittleRects.Count / 10) != 0);
                foreach (var nextLine in nextLines)
                {
                    dShape.Next.Add(nextLine);
                }

                var prevLines = this.AllLines.OrderByDescending(item => dShape.OverlapSizeWithLinesEnd(item, item.LittleRects.Count / 10)).Where(item => dShape.OverlapSizeWithLinesEnd(item, item.LittleRects.Count / 10) != 0);
                foreach (var prevLine in prevLines)
                {
                    prevLine.Next.Add(dShape);
                }
            }

            // reorder the next of each shape to ensure the colored lines behind
            foreach (var dShape in this.AllShapes)
            {
                dShape.Next.Sort((A, B) => (A as DrawsomeLine)?.MainStroke.inkStrokeInternal.DrawingAttributes.Color.R > (B as DrawsomeLine)?.MainStroke.inkStrokeInternal.DrawingAttributes.Color.R ? 1 : -1);
            }

            this.Root = this.AllShapes.OrderBy(item => item.RecogUnit.BoundingRect.TopY).FirstOrDefault();
        }
示例#2
0
 public ComposerStep(DrawsomeObj shape)
 {
     this.RelatedShape = shape as DrawsomeShape;
 }