public override bool Recognize(InkStroke inkStroke) { inkStroke = inkStroke.GetResampled(20); _hitScribbables = new List <IScribbable>(); List <int> corners = ShortStraw.IStraw(inkStroke); if (corners.Count >= 5) { ILineString inkStrokeLine = inkStroke.GetLineString(); IList <Vec> convexHull = Convexhull.convexhull(inkStroke.Points); IGeometry convexHullPoly = convexHull.Select(vec => new Point(vec.X, vec.Y)).ToList().GetPolygon(); foreach (IScribbable existingInkStroke in _inkableScene.InkStrokes) { IGeometry geom = existingInkStroke.Geometry; if (geom != null) { if (inkStrokeLine.Intersects(geom)) { _hitScribbables.Add(existingInkStroke); } // Check for small exisiting strokes that are completely covered by the scribble. if (!_hitScribbables.Contains(existingInkStroke) && convexHullPoly.Contains(geom.Buffer(1))) { _hitScribbables.Add(existingInkStroke); } } } List <IScribbable> allScribbables = new List <IScribbable>(); IScribbleHelpers.GetScribbablesRecursive(allScribbables, _inkableScene.Elements.OfType <IScribbable>().ToList()); foreach (IScribbable existingScribbable in allScribbables) { IGeometry geom = existingScribbable.Geometry; if (geom != null) { /*Polygon p = new Polygon(); * PointCollection pc = new PointCollection(existingScribbable.Geometry.Coordinates.Select(c => new System.Windows.Point(c.X, c.Y))); * p.Points = pc; * p.Stroke = Brushes.Blue; * p.StrokeThickness = 5; * _inkableScene.Add(p);*/ if (inkStrokeLine.Intersects(geom)) { _hitScribbables.Add(existingScribbable); } } } } if (_hitScribbables.Count > 0) { return(true); } return(false); }
public bool Consume(InkStroke inkStroke) { GeneralTransform gt = MainViewController.Instance.InkableScene.TransformToVisual(dxSurface); List <Windows.Foundation.Point> selectionPoints = inkStroke.Points.Select(p => gt.TransformPoint(p)). GetLineString().Buffer(1).Coordinates.Select(c => c.GetWindowsPoint()).ToList(); IList <Vec> convexHull = Convexhull.convexhull(selectionPoints); IGeometry convexHullPoly = convexHull.Select(vec => new Windows.Foundation.Point(vec.X, vec.Y)).ToList().GetPolygon(); List <FilterModel> hits = new List <FilterModel>(); foreach (var geom in _plotRendererContentProvider.HitTargets.Keys) { if (convexHullPoly.Intersects(geom)) { hits.Add(_plotRendererContentProvider.HitTargets[geom]); } } if (hits.Count > 0) { foreach (var valueComparison in hits[0].ValueComparisons) { Debug.WriteLine((valueComparison.AttributeTransformationModel.AttributeModel.RawName + " " + valueComparison.Value)); } HistogramOperationModel histogramOperationModel = (HistogramOperationModel)((HistogramOperationViewModel)DataContext).OperationModel; var vcs = hits.SelectMany(h => h.ValueComparisons).ToList(); var xAom = histogramOperationModel.GetAttributeUsageTransformationModel(AttributeUsage.X).First(); var yAom = histogramOperationModel.GetAttributeUsageTransformationModel(AttributeUsage.Y).First(); if (hits.Any(h => histogramOperationModel.FilterModels.Contains(h))) { histogramOperationModel.RemoveFilterModels(hits); } else { histogramOperationModel.AddFilterModels(hits); } } else { var bczhits = new List <BczBinMapModel>(); foreach (var geom in _plotRendererContentProvider.BczHitTargets.Keys) { if (convexHullPoly.Intersects(geom)) { bczhits.Add(_plotRendererContentProvider.BczHitTargets[geom]); } } if (bczhits.Count > 0) { _plotRendererContentProvider.UpdateBinSortings(bczhits); render(); } } return(true); }
public void CalculatePolyConvexEdge(Polygon polyin, ref MyPoint[] ptsout) { int N = polyin.Poly.Count; MyPoint[] pts = polyin.Poly.ToArray(); MyPoint[] chpts = Convexhull.convexhull(pts); ptsout = chpts; }
public override bool EndSelection() { IList <Vec> convexHull = Convexhull.convexhull(_selectionPoints); IGeometry convexHullPoly = convexHull.Select(vec => new Windows.Foundation.Point(vec.X, vec.Y)).ToList().GetPolygon(); List <FilterModel> hits = new List <FilterModel>(); foreach (var geom in _plotRendererContentProvider.HitTargets.Keys) { if (convexHullPoly.Intersects(geom)) { hits.Add(_plotRendererContentProvider.HitTargets[geom]); } } if (hits.Count > 0) { foreach (var valueComparison in hits[0].ValueComparisons) { Debug.WriteLine((valueComparison.AttributeTransformationModel.AttributeModel.RawName + " " + valueComparison.Value)); } HistogramOperationModel histogramOperationModel = (HistogramOperationModel)((HistogramOperationViewModel)DataContext).OperationModel; if (hits.Any(h => histogramOperationModel.FilterModels.Contains(h))) { histogramOperationModel.RemoveFilterModels(hits); } else { histogramOperationModel.AddFilterModels(hits); } return(true); } var bczhits = new List <BczBinMapModel>(); foreach (var geom in _plotRendererContentProvider.BczHitTargets.Keys) { if (convexHullPoly.Intersects(geom)) { bczhits.Add(_plotRendererContentProvider.BczHitTargets[geom]); } } if (bczhits.Count > 0) { _plotRendererContentProvider.UpdateBinSortings(bczhits); render(); return(true); } return(false); }