/// <summary> /// 识别 /// </summary> /// <param name="strokes">笔迹集合</param> /// <returns>候选词数组</returns> public string[] Recognize(StrokeCollection strokes) { if (strokes == null || strokes.Count == 0) { return(Constants.EmptyAlternates); } var analyzer = new InkAnalyzer(); analyzer.AddStrokes(strokes, Constants.ChsLanguageId); analyzer.SetStrokesType(strokes, StrokeType.Writing); var status = analyzer.Analyze(); if (status.Successful) { return(analyzer.GetAlternates() .OfType <AnalysisAlternate>() .Select(x => x.RecognizedString) .ToArray()); } analyzer.Dispose(); return(Constants.EmptyAlternates); }
private void InkWindow_Loaded(object sender, RoutedEventArgs e) { //Initialize analyzer and pipeline inkAnalyzer = new InkAnalyzer(this.Dispatcher); pipeline = new PipelineAnalyzer(inkAnalyzer); //Initialize headings headings = new Headings(); headings.sidebar = SideInkCanvas; headings.scrollViewerContainer = MainScrollView; MainInkCanvas.Strokes.StrokesChanged += Strokes_StrokesChanged; inkAnalyzer.ContextNodeCreated += InkAnalyzer_ContextNodeCreated; pipeline.PipelineComplete += pipeline_PipelineComplete; //DisableDictionary(); insertionBox = new InsertionBox(inserter); insertionBox.TheInsertButton.Click += InsertButton_Click; insertionBox.TheCancelButton.Click += CancelButton_Click; insertReflow = new ReflowProcessor(insertionBox.InkCanvas, false); OverlayCanvas.Children.Add(insertionBox); insertionBox.Visibility = Visibility.Collapsed; inserter = new InsertionProcessor(MainInkCanvas, insertionBox); pipeline.AddProcessor(inserter); pipeline.AddProcessor(new StrikethroughProcessor(MainInkCanvas)); pipeline.AddProcessor(new ReflowProcessor(MainInkCanvas, true)); pipeline.AddProcessor(new NavigationProcessor(headings)); pipeline.AddProcessor(new AutocorrectProcessor(this)); }
/// <summary> /// TODO: 5. Ink Shape Recognition /// </summary> public Collage() { InitializeComponent(); _inkAnalyzer = new InkAnalyzer(); SizeChanged += Collage_SizeChanged; }
protected override void OnContentRendered(EventArgs e) { base.OnContentRendered(e); // Initialize the Analyzer. analyzer = new InkAnalyzer(); analyzer.ResultsUpdated += new ResultsUpdatedEventHandler(analyzer_ResultsUpdated); // Add analysis hints for each form area. // Use the absolute Width and Height of the Grid's // RowDefinition and ColumnDefinition properties defined in XAML, // to calculate the bounds of the AnalysisHintNode objects. hintNodeTitle = analyzer.CreateAnalysisHint( new Rect(100, 0, 740, 100)); hintNodeDirector = analyzer.CreateAnalysisHint( new Rect(100, 100, 740, 100)); hintNodeStarring = analyzer.CreateAnalysisHint( new Rect(100, 200, 740, 100)); hintNodeRating = analyzer.CreateAnalysisHint( new Rect(100, 300, 320, 100)); hintNodeYear = analyzer.CreateAnalysisHint( new Rect(520, 300, 320, 100)); hintNodeGenre = analyzer.CreateAnalysisHint( new Rect(100, 400, 740, 100)); //Set the factoids on the hints. hintNodeTitle.Factoid = "(!IS_DEFAULT)"; hintNodeDirector.Factoid = "(!IS_PERSONALNAME_FULLNAME)"; hintNodeStarring.Factoid = "(!IS_PERSONALNAME_FULLNAME)"; hintNodeRating.Factoid = "(!IS_DEFAULT)"; hintNodeYear.Factoid = "(!IS_DATE_YEAR)"; hintNodeGenre.Factoid = "(!IS_DEFAULT)"; }
private void theInkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e) { var stroke = GetCombinedStore(this.theInkCanvas.Strokes); InkAnalyzer theInkAnalyzer = new InkAnalyzer(); //theInkAnalyzer.AddStrokes(this.theInkCanvas.Strokes, 0x0804); //theInkAnalyzer.SetStrokesType(this.theInkCanvas.Strokes, StrokeType.Writing); theInkAnalyzer.AddStroke(stroke, 0x0804); theInkAnalyzer.SetStrokeType(stroke, StrokeType.Writing); AnalysisStatus status = theInkAnalyzer.Analyze(); if (status.Successful) { List <StrokeWord> slist = new List <StrokeWord>(); //textBox1.Text = theInkAnalyzer.GetRecognizedString(); for (int i = 0; i < theInkAnalyzer.GetAlternates().Count; i++) { StrokeWord sw = new StrokeWord(); sw.StrokeName = theInkAnalyzer.GetAlternates()[i].RecognizedString; slist.Add(sw); } this.StrokeWordList = new List <StrokeWord>(); this.StrokeWordList = slist; } else { MessageBox.Show("识别失败"); } }
public ScannedPaperForm() { // Initialize UI Components InitializeComponent(); // Set the Border style to be non-resizable this.FormBorderStyle = FormBorderStyle.FixedSingle; // Disable the maximize box this.MaximizeBox = false; // Construct an InkOverlay attached to the inkForm's inking panel myInkOverlay = new InkOverlay(this.inkFormInkingPanel); // Create an InkAnalyzer, passing the InkOverlay's Ink Object. analyzer = new InkAnalyzer(myInkOverlay.Ink, this); // Add an event handler that adds Strokes to the InkAnalyzer as they // are collected. myInkOverlay.Stroke += new InkCollectorStrokeEventHandler(MyInkOverlayStroke); // Enable the InkOverlay to begin collection. myInkOverlay.Enabled = true; // Add a paint handler to the inking panel to draw the AnalysisHintNodes // bounds if the "Show Analysis Hint Bounding Boxes" CheckBox is checked. this.inkFormInkingPanel.Paint += new PaintEventHandler(InkFormInkingPanelPaint); // Create the AnalysisHintNode that will be used to give the InkAnalyzer // additional information about how to interpret strokes. Also, initialize the // TextBoxes where the results from each AnalysisHintNode will be stored. this.InitHints(); }
public Scenario2() { this.InitializeComponent(); inkPresenter = inkCanvas.InkPresenter; inkPresenter.StrokesCollected += InkPresenter_StrokesCollected; inkPresenter.StrokesErased += InkPresenter_StrokesErased; inkPresenter.StrokeInput.StrokeStarted += StrokeInput_StrokeStarted; // We exclude CoreInputDeviceTypes.Touch because we use touch to select paragraphs. inkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Mouse; inkCanvas.Tapped += InkCanvas_Tapped; inkCanvas.DoubleTapped += InkCanvas_DoubleTapped; inkAnalyzer = new InkAnalyzer(); paragraphSelected = null; dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += DispatcherTimer_Tick; // We perform analysis when there has been a change to the // ink presenter and the user has been idle for 1 second. dispatcherTimer.Interval = TimeSpan.FromSeconds(1); }
public GraphAnalyzer(MainWindow m) { mainWindow = m; analyzer = new InkAnalyzer(); graphs = new HashSet <Graph>(); strokes = new Dictionary <Stroke, Graph>(); }
/// <summary> /// 识别 /// </summary> /// <param name="strokes">笔迹集合</param> /// <returns>候选词数组</returns> public string[] Recognize(StrokeCollection strokes) { if (strokes == null || strokes.Count == 0) { return(Params.EmptyAlternates); } var stroke = GetCombinedStore(strokes); var analyzer = new InkAnalyzer(); analyzer.AddStroke(stroke, Params.SimplifiedChineseLanguageId); analyzer.SetStrokeType(stroke, StrokeType.Writing); var status = analyzer.Analyze(); if (status.Successful) { var result = analyzer.GetAlternates() .OfType <AnalysisAlternate>() .Select(x => x.RecognizedString) .ToArray(); analyzer.Dispose(); return(result); } analyzer.Dispose(); return(Params.EmptyAlternates); }
public void process(InkAnalyzer inkAnalyzer) { ContextNodeCollection contextNodeCollection = inkAnalyzer.FindLeafNodes(); List<Stroke> horizontalLines = InkUtils.findLines(contextNodeCollection); findAndDeleteStrikethrough(inkAnalyzer, canvas, horizontalLines, contextNodeCollection); }
public void process(InkAnalyzer inkAnalyzer) { ContextNodeCollection contextNodeCollection = inkAnalyzer.FindLeafNodes(); List <Stroke> horizontalLines = InkUtils.findLines(contextNodeCollection); findAndDeleteStrikethrough(inkAnalyzer, canvas, horizontalLines, contextNodeCollection); }
/// <summary> /// 识别(将多个笔画集合成一起识别,提高单字的识别率) /// </summary> /// <param name="strokes">笔迹集合</param> /// <returns>候选词数组</returns> public string[] Recognize(StrokeCollection strokes) { if (strokes == null || strokes.Count == 0) { return(null); } var stroke = GetCombinedStore(strokes); var analyzer = new InkAnalyzer(); analyzer.AddStroke(stroke, 0x0804); analyzer.SetStrokeType(stroke, StrokeType.Writing); var status = analyzer.Analyze(); if (status.Successful) { return(analyzer.GetAlternates() .OfType <AnalysisAlternate>() .Select(x => x.RecognizedString) .ToArray()); } analyzer.Dispose(); return(null); }
private void InkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e) { InkAnalyzer analyser = new InkAnalyzer(); analyser.AddStrokes(_inkCanvas.Strokes); analyser.Analyze(); _inkResults.Text = analyser.GetRecognizedString(); e.Handled = false; }
public MainPage() { this.InitializeComponent(); inkAnalyzer = new InkAnalyzer(); inkPresenter = inkCanvas.InkPresenter; inkPresenter.StrokesCollected += InkPresenter_StrokesCollected; inkPresenter.StrokesErased += InkPresenter_StrokesErased; }
public Graph(IDelegate _del, Stroke b) { del = _del; box = b; bounds = box.GetBounds(); box.StylusPoints = InkUtils.xkcd(InkUtils.box(bounds)); box.DrawingAttributes.Color = Colors.Blue; analyzer = new InkAnalyzer(); analyzer.ContextNodeCreated += ContextNodeCreated; }
private void StrokeToImageButton_Click(object sender, System.Windows.RoutedEventArgs e) { _inkFrame._inkCanvas.StrokeCollected += new InkCanvasStrokeCollectedEventHandler(_inkCanvas_StrokeCollected_StrokeToImage); analyze = new InkAnalyzer(); InkCollector.Mode = InkMode.Ink; _fontChooser.Visibility = Visibility.Hidden; RectangleSlider.Visibility = Visibility.Visible; WidthSlider.Visibility = Visibility.Visible; OpacitySlider.Visibility = Visibility.Visible; this.Height = GlobalValues.ControlPanel_InkModeHeight; }
public void Init(ref InkCanvas inkCanvas) { _presenter = inkCanvas.InkPresenter; _presenter.StrokesCollected += Presenter_StrokesCollected; _presenter.StrokesErased += Presenter_StrokesErased; _presenter.InputDeviceTypes = CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Touch; _analyser = new InkAnalyzer(); }
private void InsertButton_Click(object sender, RoutedEventArgs e) { InkAnalyzer inkAnalyzer = new InkAnalyzer(); inkAnalyzer.AddStrokes(insertionBox.InkCanvas.Strokes); inkAnalyzer.Analyze(); InkUtils.MergeParagraphs(inkAnalyzer); insertReflow.process(inkAnalyzer); insertionBox.Visibility = Visibility.Collapsed; inserter.insertStrokes(this.inkAnalyzer, MainInkCanvas, insertionBox.InkCanvas); }
public void insertStrokes(InkAnalyzer analyzer, InkCanvas mainInkCanvas, InkCanvas insertionCanvas) { double bestY = -10000; ContextNode selectedNode = null; foreach (ContextNode node in analyzer.FindLeafNodes()) { double y1 = strokeToBeReplaced.GetBounds().Y; double y2 = node.Strokes.GetBounds().Y; if (y1 - y2 > 0 && y1 - y2 < y1 - bestY) { bestY = y2; selectedNode = node; } } if (bestY == -10000) { bestY = strokeToBeReplaced.GetBounds().Y; } StrokeCollection strokeCollection = insertionCanvas.Strokes.Clone(); insertionCanvas.Strokes.Clear(); double bestX = strokeToBeReplaced.GetBounds().X; double strokeX = strokeCollection.GetBounds().X; double strokeY = strokeCollection.GetBounds().Y; Matrix inkTransform = new Matrix(); inkTransform.Translate(bestX - strokeX + 20, bestY - strokeY); strokeCollection.Transform(inkTransform, false); double width = strokeCollection.GetBounds().Width + Constants.SPACING; double startX = strokeCollection.GetBounds().X; Matrix transform = new Matrix(); transform.Translate(width, 0); if (selectedNode != null) { for (int i = 0; i < selectedNode.ParentNode.SubNodes.Count; i++) { ContextNode siblingNode = selectedNode.ParentNode.SubNodes[i]; for (int j = 0; j < siblingNode.Strokes.Count; j++) { Stroke stroke = siblingNode.Strokes[j]; double offsetX = stroke.GetBounds().X; if (offsetX > startX) { stroke.Transform(transform, false); } } } } mainInkCanvas.Strokes.Add(strokeCollection); mainInkCanvas.Strokes.Remove(strokeToBeReplaced); }
public InkAnalysisCanvas() { _inkAnalyzer = new InkAnalyzer(this.Dispatcher); // Add a listener to ResultsUpdated event. _inkAnalyzer.ResultsUpdated += OnInkAnalyzerResultsUpdated; // Add a listener to StrokesChanged event of InkAnalysis.Strokes collection. this.Strokes.StrokesChanged += OnStrokesChanged; this.ShowInkAnalysisFeedback = true; }
public void process(InkAnalyzer inkAnalyzer) { ContextNodeCollection contextNodeCollection = inkAnalyzer.FindLeafNodes(); List <Stroke> horizontalLines = InkUtils.findLines(contextNodeCollection); List <HeadingItem> headings = findHeadings(horizontalLines, contextNodeCollection); //Here is the end result of the headings mainHeading.headings = headings; //Invalidate and render the headings to the side panel mainHeading.invalidate(); }
/// <summary> /// Initializes a new instance of the <see cref="InkNote"/> class. /// </summary> public InkNote() { this.InitializeComponent(); inkingCanvas.InkPresenter.IsInputEnabled = true; inkingCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Mouse; inkingCanvas.Tapped += InkCanvas_Tapped; _inkAnalyzer = new InkAnalyzer(); _inkPresenter = inkingCanvas.InkPresenter; _inkPresenter.StrokesCollected += InkPresenter_StrokesCollected; _inkPresenter.StrokesErased += InkPresenter_StrokesErased; _inkPresenter.UnprocessedInput.PointerPressed += UnprocessedInput_PointerPressed; _inkPresenter.InputProcessingConfiguration.RightDragAction = InkInputRightDragAction.LeaveUnprocessed; }
public void process(InkAnalyzer inkAnalyzer) { ContextNodeCollection contextNodeCollection = inkAnalyzer.FindLeafNodes(); List<Stroke> horizontalLines = InkUtils.findLines(contextNodeCollection); List<HeadingItem> headings = findHeadings(horizontalLines, contextNodeCollection); //Here is the end result of the headings mainHeading.headings = headings; //Invalidate and render the headings to the side panel mainHeading.invalidate(); }
public Tinta(InkCanvas inkCanvas, Action <int> solicitudCambioNumero) { this.inkCanvas = inkCanvas; this.solicitudCambioNumero = solicitudCambioNumero; m_analyzer = new InkAnalyzer(); m_analyzer.AnalysisModes = AnalysisModes.AutomaticReconciliationEnabled; m_analyzer.ResultsUpdated += M_analizer_ResultsUpdated; inkCanvas.StrokeCollected += InkCanvas_StrokeCollected; inkCanvas.StrokeErasing += InkCanvas_StrokeErasing; dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += DispatcherTimer_Tick; dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 700); }
// IACore,IAWinFx // C:\Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7 // IALoader // C:\Program Files\Microsoft SDKs\Windows\v6.1\Bin // それぞれのライブラリは「Windows SDK for Windows Server 2008 and .NET Framework 3.5」で取得できる // http://www.microsoft.com/en-us/download/confirmation.aspx?id=11310 private string InkAnalyze( InkCanvas canvas ) { InkAnalyzer theInkAnalyzer = new InkAnalyzer(); // キャンバスに描かれた文字を認識するためにアナライザにストロークをセット theInkAnalyzer.AddStrokes( canvas.Strokes ); theInkAnalyzer.SetStrokesType( canvas.Strokes, StrokeType.Writing ); // 文字を解析 theInkAnalyzer.Analyze(); // 文字を解析した結果の第1候補を返す return theInkAnalyzer.GetRecognizedString(); }
// IACore,IAWinFx // C:\Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7 // IALoader // C:\Program Files\Microsoft SDKs\Windows\v6.1\Bin // それぞれのライブラリは「Windows SDK for Windows Server 2008 and .NET Framework 3.5」で取得できる // http://www.microsoft.com/en-us/download/confirmation.aspx?id=11310 private string InkAnalyze(InkCanvas canvas) { InkAnalyzer theInkAnalyzer = new InkAnalyzer(); // キャンバスに描かれた文字を認識するためにアナライザにストロークをセット theInkAnalyzer.AddStrokes(canvas.Strokes); theInkAnalyzer.SetStrokesType(canvas.Strokes, StrokeType.Writing); // 文字を解析 theInkAnalyzer.Analyze(); // 文字を解析した結果の第1候補を返す return(theInkAnalyzer.GetRecognizedString()); }
public ShapePage() { InitializeComponent(); inkAnalyzer = new InkAnalyzer(); inkCanvas.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Touch; inkCanvas.InkPresenter.StrokesCollected += InkPresenter_StrokesCollected; inkCanvas.InkPresenter.StrokeInput.StrokeStarted += StrokeInput_StrokeStarted; // this timer will allow us to recognize multi-stroke shapes strokeTimer = new DispatcherTimer(); strokeTimer.Interval = TimeSpan.FromMilliseconds(500d); strokeTimer.Tick += StrokeTimer_Tick; this.Loaded += ShapePage_Loaded; }
private void MainWindow_Loaded(object sender, RoutedEventArgs e) { m_analyzer = new InkAnalyzer(); m_analyzer.AnalysisModes = AnalysisModes.AutomaticReconciliationEnabled; m_analyzer.ResultsUpdated += M_analyzer_ResultsUpdated; canvasTinta.StrokeErasing += CanvasTinta_StrokeErasing; canvasTinta.StrokeCollected += CanvasTinta_StrokeCollected; canvasTinta.StylusUp += CanvasTinta_StylusUp; canvasTinta.StylusMove += CanvasTinta_StylusMove; canvasTinta.MouseDown += CanvasTinta_MouseDown; canvasTinta.MouseUp += CanvasTinta_MouseUp; dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += DispatcherTimer_Tick; dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 500); //recognizer = new Recognizer(); }
public static void transposeStrokes(InkAnalyzer inkAnalyzer, StrokeCollection strokes, double offsetX, double offsetY) { if (inkAnalyzer != null) { inkAnalyzer.RemoveStrokes(strokes); } Matrix transform = new Matrix(); transform.Translate(offsetX, offsetY); strokes.Transform(transform, false); if (inkAnalyzer != null) { inkAnalyzer.AddStrokes(strokes); } }
static public bool IsChar(this Stroq stroke, string charset) { System.Windows.Ink.InkAnalyzer ia = new InkAnalyzer(); ia.AddStroke(stroke.BackingStroke); //AnalysisHintNode node = ia.CreateAnalysisHint(); //node.Factoid = "IS_ONECHAR"; //node.CoerceToFactoid = true; //node.Location.MakeInfinite(); AnalysisStatus astat = ia.Analyze(); string reco = ia.GetRecognizedString(); Console.WriteLine("Recognized:<" + reco + ">"); if (astat.Successful && reco != "Other") { return(charset.Contains(reco[0])); } return(false); }
private void reflowAll(InkAnalyzer inkAnalyzer, InkCanvas inkCanvas) { ContextNodeCollection parentList = inkAnalyzer.RootNode.SubNodes; foreach (ContextNode node in parentList) { if (node is WritingRegionNode) { ContextNodeCollection paragraphs = node.SubNodes; foreach (ContextNode paragraph in paragraphs) { if (paragraph is ParagraphNode) { reflowParagraph(paragraph as ParagraphNode, inkAnalyzer, inkCanvas); } } } } }
public void process(InkAnalyzer inkAnalyzer) { ContextNodeCollection nodeCollection = inkAnalyzer.FindLeafNodes(); foreach (ContextNode childNodes in nodeCollection) { foreach (Stroke stroke in childNodes.Strokes) { if (strokeIsCaret(stroke)) { insertionBox.Visibility = Visibility.Visible; Canvas.SetLeft(insertionBox, stroke.StylusPoints[0].X - 140); Canvas.SetTop(insertionBox, stroke.StylusPoints[1].Y); inkAnalyzer.RemoveStroke(stroke); strokeToBeReplaced = stroke; } } } }
public Scenario1() { this.InitializeComponent(); inkPresenter = inkCanvas.InkPresenter; inkPresenter.StrokesCollected += InkPresenter_StrokesCollected; inkPresenter.StrokesErased += InkPresenter_StrokesErased; inkPresenter.StrokeInput.StrokeStarted += StrokeInput_StrokeStarted; inkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Touch; inkAnalyzer = new InkAnalyzer(); dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += DispatcherTimer_Tick; // We perform analysis when there has been a change to the // ink presenter and the user has been idle for 200ms. dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200); }
public String Recognize([FromBody] Results.Stroke stroke) { var strokePointsData = JsonConvert.DeserializeObject<dynamic>(stroke.Json); var strokeCollection = GetStrokeCollectionFromPoints(strokePointsData); var inkAnalyzer = new InkAnalyzer(); inkAnalyzer.AddStrokes(strokeCollection); var analysisStatus = inkAnalyzer.Analyze(); if (analysisStatus.Successful) { var recognizedString = inkAnalyzer.GetRecognizedString(); return recognizedString; } else return "Data not recognized"; }
public HttpResponseMessage<String> Recognize(string strokes) { var strokePointsData = JsonConvert.DeserializeObject<dynamic>(strokes); var strokeCollection = GetStrokeCollectionFromPoints(strokePointsData); var inkAnalyzer = new InkAnalyzer(); inkAnalyzer.AddStrokes(strokeCollection); var analysisStatus = inkAnalyzer.Analyze(); if (analysisStatus.Successful) { var recognizedString = inkAnalyzer.GetRecognizedString(); return new HttpResponseMessage<string>(recognizedString); } else return new HttpResponseMessage<string>("Data not recognized"); }
private static bool strokeIsHorizontalLine(Stroke stroke) { InkAnalyzer temp = new InkAnalyzer(); temp.AddStroke(stroke); temp.Analyze(); ContextNode node = temp.RootNode.SubNodes[0]; if (node is InkDrawingNode) { InkDrawingNode drawing = node as InkDrawingNode; PointCollection boundingBox = drawing.GetRotatedBoundingBox(); double d1 = distSquared(boundingBox[0], boundingBox[1]); double d2 = distSquared(boundingBox[1], boundingBox[2]); return((d2 > 0 && d1 / d2 > 10 * 10 && d1 > 100 && Math.Abs(slope(boundingBox[0], boundingBox[1])) < 0.5) || (d1 > 0 && d2 / d1 > 10 * 10 && d2 > 100 && Math.Abs(slope(boundingBox[1], boundingBox[2])) < 0.5)); } return(false); }
public static void transposeStrokes(InkAnalyzer inkAnalyzer, StrokeCollection strokes, double offsetX, double offsetY) { if(inkAnalyzer != null) { inkAnalyzer.RemoveStrokes(strokes); } Matrix transform = new Matrix(); transform.Translate(offsetX, offsetY); strokes.Transform(transform, false); if(inkAnalyzer != null) { inkAnalyzer.AddStrokes(strokes); } }
public LogicDiagramInkCanvas() { _inkAnalyzer = new InkAnalyzer(this.Dispatcher); this.ShowInkAnalysisFeedback = true; }
void onLoaded(object sender, RoutedEventArgs e) { m_analyzer = new InkAnalyzer(); m_analyzer.AnalysisModes = AnalysisModes.AutomaticReconciliationEnabled; m_analyzer.ResultsUpdated += new ResultsUpdatedEventHandler(m_analyzer_ResultsUpdated); string[] wordListArray = { "+", "-", "x", "/", "=", }; //00D7 = Multiplication X //2217 = Multiplication * //00F7 = Divide Sign //00B2 = ^2 hint = m_analyzer.CreateAnalysisHint(); hint.Location.MakeInfinite(); hint.Factoid = "(NUMBER)"; hint.SetWordlist(wordListArray); hint.Name = "Wordlist"; }
public void InitInkAnalysis() { _inkAnalyzer = new InkAnalyzer(this.Dispatcher); // Add a listener to StrokesChanged event of InkAnalysis.Strokes collection. // Add a listener to ResultsUpdated event. _inkAnalyzer.ResultsUpdated += OnInkAnalyzerResultsUpdated; this.ShowInkAnalysisFeedback = true; }
private void reflowParagraph(ParagraphNode node, InkAnalyzer inkAnalyzer, InkCanvas inkCanvas) { ContextNodeCollection lines = node.SubNodes; Rect bounds = node.Strokes.GetBounds(); List<InkWordNode> resultWords = new List<InkWordNode>(); double lineHeight = 0; double spacing = 30; //Collect all strokes foreach (ContextNode line in lines) { ContextNodeCollection words = line.SubNodes; foreach (ContextNode word in words) { lineHeight += word.Strokes.GetBounds().Height; InkWordNode wordNode = word as InkWordNode; resultWords.Add(wordNode); } } lineHeight /= resultWords.Count; List<List<InkWordNode>> resultLines = new List<List<InkWordNode>>(); List<double> lineMaxBaseline = new List<double>(); //Reflow strokes double x = 0; double maxX = inkCanvas.ActualWidth - bounds.X; resultLines.Add(new List<InkWordNode>()); lineMaxBaseline.Add(0); foreach (InkWordNode word in resultWords) { //Does word fit? Rect wordBound = word.Strokes.GetBounds(); if (x + wordBound.Width + spacing > maxX && multiline) { //Not fitting! Newline x = 0; resultLines.Add(new List<InkWordNode>()); lineMaxBaseline.Add(0); } x += spacing + wordBound.Width; PointCollection baseline = word.GetBaseline(); if (baseline != null && baseline.Count > 0) { double baselineFromTop = baseline[0].Y - wordBound.Y; resultLines[resultLines.Count - 1].Add(word); if (baselineFromTop > lineMaxBaseline[resultLines.Count - 1]) { lineMaxBaseline[resultLines.Count - 1] = baselineFromTop; } } } double y = 0; int lineNumber = 0; foreach (List<InkWordNode> line in resultLines) { double lineBaseline = lineMaxBaseline[lineNumber]; x = 0; foreach (InkWordNode word in line) { Rect wordBound = word.Strokes.GetBounds(); PointCollection baseline = word.GetBaseline(); double baselineFromTop = baseline[0].Y - wordBound.Y; double destX = (x + bounds.X); double dx = destX - (wordBound.X); //Match mid double dy = (y + lineBaseline + bounds.Y) - (wordBound.Y + baselineFromTop); InkUtils.transposeStrokes(inkAnalyzer, word.Strokes, dx, dy); x += spacing + wordBound.Width; } y += lineHeight + spacing; lineNumber++; } }
public GraphAnalyzer(MainWindow m) { mainWindow = m; analyzer = new InkAnalyzer(); graphs = new HashSet<Graph>(); strokes = new Dictionary<Stroke, Graph>(); }
public void process(InkAnalyzer inkAnalyzer) { reflowAll(inkAnalyzer, canvas); }
public static void MergeParagraphs(InkAnalyzer inkAnalyzer) { foreach (ContextNode writingRegion in inkAnalyzer.RootNode.SubNodes) { List<ParagraphAnalysisEntry> paragraphs = new List<ParagraphAnalysisEntry>(); foreach (ContextNode node in writingRegion.SubNodes) { if (node is ParagraphNode) { ParagraphNode paragraph = node as ParagraphNode; ContextNode firstLine = paragraph.SubNodes[0]; Point paragraphReference = firstLine.Strokes.GetBounds().TopLeft; ParagraphAnalysisEntry entry = new ParagraphAnalysisEntry(); entry.paragraph = paragraph; entry.point = paragraphReference; paragraphs.Add(entry); } } paragraphs.Sort(delegate(ParagraphAnalysisEntry a, ParagraphAnalysisEntry b) { return a.point.Y.CompareTo(b.point.Y); }); for (int i = 0; i < paragraphs.Count - 1; i++) { ParagraphAnalysisEntry entry = paragraphs[i]; ParagraphAnalysisEntry next = paragraphs[i + 1]; bool closeto = entry.closeTo(next); if (closeto) { foreach (ContextNode node in next.paragraph.SubNodes) { node.Reparent(entry.paragraph); } writingRegion.DeleteSubNode(next.paragraph); paragraphs[i + 1] = entry; } } } }
private static bool strokeIsHorizontalLine(Stroke stroke) { InkAnalyzer temp = new InkAnalyzer(); temp.AddStroke(stroke); temp.Analyze(); ContextNode node = temp.RootNode.SubNodes[0]; if (node is InkDrawingNode) { InkDrawingNode drawing = node as InkDrawingNode; PointCollection boundingBox = drawing.GetRotatedBoundingBox(); double d1 = distSquared(boundingBox[0], boundingBox[1]); double d2 = distSquared(boundingBox[1], boundingBox[2]); return (d2 > 0 && d1 / d2 > 10 * 10 && d1 > 100 && Math.Abs(slope(boundingBox[0], boundingBox[1])) < 0.5) || (d1 > 0 && d2 / d1 > 10 * 10 && d2 > 100 && Math.Abs(slope(boundingBox[1], boundingBox[2])) < 0.5); } return false; }
private void findAndDeleteStrikethrough(InkAnalyzer inkAnalyzer, InkCanvas canvas, List<Stroke> horizontalLines, ContextNodeCollection contextNodeCollection) { List<ContextNode> deletedNodes = new List<ContextNode>(); List<Stroke> removedHorizontalLines = new List<Stroke>(); //Find things to apply gestures to foreach (ContextNode node in contextNodeCollection) { if (node.Strokes.Count == 0) { continue; } Rect strikethroughBounds = node.Strokes.GetBounds(); strikethroughBounds.Height *= 0.75d; if (node is InkWordNode) { PointCollection bl = (node as InkWordNode).GetBaseline(); if (bl != null && bl.Count() > 0) { double baseline = bl[0].Y; strikethroughBounds.Height = baseline - strikethroughBounds.Y; } } for (int j = 0; j < horizontalLines.Count; j++) { if (node.Strokes[0] == horizontalLines[j]) { break; } Stroke horizontalLine = horizontalLines[j]; Rect horizontalLineBounds = horizontalLine.GetBounds(); double sideBuffer = (1 - Constants.LINE_WORD_OVERLAPSE_RATIO) / 2; double strikethroughBoundLeft = strikethroughBounds.X + strikethroughBounds.Width * sideBuffer; double strikethroughBoundRight = strikethroughBounds.X + strikethroughBounds.Width * (1 - sideBuffer); if (strikethroughBounds.IntersectsWith(horizontalLineBounds) && strikethroughBoundLeft > horizontalLineBounds.X && strikethroughBoundRight < horizontalLineBounds.X + horizontalLineBounds.Width) { //Delete strikethrough deletedNodes.Add(node); removedHorizontalLines.Add(horizontalLine); } } } foreach (Stroke stroke in removedHorizontalLines) { horizontalLines.Remove(stroke); canvas.Strokes.Remove(stroke); inkAnalyzer.RemoveStroke(stroke); } //Final step to apply the gestures, commit changes for (int i = deletedNodes.Count - 1; i >= 0; i--) { ContextNode node = deletedNodes[i]; try { Rect bounds = node.Strokes.GetBounds(); double nodeX = bounds.X; ContextNode parent = node.ParentNode; double closestX = double.MaxValue; foreach (ContextNode sibling in parent.SubNodes) { double siblingX = sibling.Strokes.GetBounds().X; if (siblingX > nodeX && siblingX < closestX) { closestX = siblingX; } } double dx = nodeX - closestX; foreach (ContextNode sibling in parent.SubNodes) { //Nodes right side of current if (sibling.Strokes.GetBounds().X > nodeX) { InkUtils.transposeStrokes(inkAnalyzer, sibling.Strokes, dx, 0d); } } canvas.Strokes.Remove(node.Strokes); inkAnalyzer.RemoveStrokes(node.Strokes); } catch (Exception e) { //Ignore already deleted error } } }
public PipelineAnalyzer(InkAnalyzer inkAnalyzer) { analyzer = this; this.inkAnalyzer = inkAnalyzer; inkAnalyzer.ResultsUpdated += InkAnalyzer_ResultsUpdated; }
public void FuncionalidadTinta() { temp = new System.Timers.Timer(); temp.Elapsed += new ElapsedEventHandler(temp_Elapsed); temp.Interval = 1000; temp.Enabled = false; m_analyzer = new InkAnalyzer(); m_analyzer.AnalysisModes = AnalysisModes.AutomaticReconciliationEnabled; m_analyzer.ResultsUpdated += new ResultsUpdatedEventHandler(m_analyzer_ResultsUpdated); canvasDeTinta.StrokeErasing += new InkCanvasStrokeErasingEventHandler(canvasDeTinta_StrokeErasing); canvasDeTinta.StrokeCollected += new InkCanvasStrokeCollectedEventHandler(canvasDeTinta_StrokeCollected); canvasDeTinta.PreviewMouseDown += new System.Windows.Input.MouseButtonEventHandler(canvasDeTinta_PreviewMouseDown); }
/// <summary> /// Constructor /// </summary> public InkAnalysisFeedbackAdorner(UIElement adornedElement, InkAnalyzer inkAnalyzer) : base(adornedElement) { _inkAnalyzer = inkAnalyzer; }
public void process(InkAnalyzer inkAnalyzer) { window.AutocorrectNewWordNodes(); }