Пример #1
0
 public IList<IGesture> Recognize(Stroq stroq)
 {
     var result = new List<IGesture>();
     foreach (IGesture gesture in _gestures)
     {
         if (gesture.Recognize(stroq))
         {
             result.Add(gesture);
             return result;
         }
     }
     return result;
 }
Пример #2
0
        public bool Recognize(Stroq stroq)
        {
            // stroq = stroq.GetResampled(20);
            _hitStroqs = new List<Stroq>();

            bool isScribble = false;

            foreach (Stroq existingStroq in _inqCanvas.GetStrokes().Where(s => s != stroq))
            {
                IList<Vector2> intersections = new List<Vector2>();
                IList<LineSegment> existingStroqSegs = existingStroq.ToLineSegments();
                IList<LineSegment> scribbleSegs = stroq.ToLineSegments();

                foreach (LineSegment stroqResampledSeg in existingStroqSegs)
                {
                    foreach (LineSegment stroqSeg in scribbleSegs)
                    {
                        var intersection = new Vector2();
                        if (stroqSeg.Intersects(stroqResampledSeg, out intersection))
                        {
                            intersections.Add(intersection);
                        }
                    }
                }

                var intersectionStroq = new Stroq(intersections);
                if (intersectionStroq.Points.Count > 2 && intersectionStroq.GetAveragePointDistance() < 20)
                {
                    isScribble = true;
                    _hitStroqs.Add(existingStroq);
                }

                // Check for small exisiting strokes that are completely covered by the scribble.

                // TODO: add back in
                /*
                if (stroq.BoundingRect.Contains(existingStroq.BoundingRect))
                {
                    isScribble = true;
                    _hitStroqs.Add(existingStroq);
                }
                */
            }

            return isScribble;
        }
Пример #3
0
        private void OnStrokeAdded(object sender, Stroq stroq)
        {
            Debug.WriteLine("Stroke addded");

            var gestures = _gesturizer.Recognize(stroq);
            foreach (var gesture in gestures)
            {
                if (gesture is XyAxisGesture)
                {
                    DrawXyAxis();
                    xInqCanvas.RemoveStroke(stroq);
                } else if (gesture is ScribbleGesture)
                {
                    var scribble = (ScribbleGesture) gesture;
                    foreach (var hitStroq in scribble.HitStroqs.ToList())
                    {
                        xInqCanvas.RemoveStroke(hitStroq);
                    }
                    xInqCanvas.RemoveStroke(stroq);
                    QueryStroqs.Remove(stroq);
                }
            }

            if (gestures.Count == 0)
            {
                if (stroq.Points.Count > 30 && _axisDrawn)
                    QueryStroqs.Add(stroq);
                else
                    xInqCanvas.RemoveStroke(stroq);
            }
        }
Пример #4
0
 public void RemoveStroke(Stroq stroq)
 {
     var pl = _strokes[stroq];
     Children.Remove(pl);
     _strokes.Remove(stroq);
 }
Пример #5
0
 public void AddStroke(Polyline pl, Stroq stroq)
 {
     _strokes.Add(stroq, pl);
     StrokeAdded?.Invoke(this, stroq);
 }
Пример #6
0
        public void SplitTrBl(out Stroq left, out Stroq right)
        {
            left = new Stroq();
            right = new Stroq();
            var rect = BoundingRect;
            var tr = new Vector2(rect.X + rect.Width, rect.Y);
            var bl = new Vector2(rect.X, rect.Y + rect.Height);
            var bltr = tr - bl;

            foreach (var point in Points)
            {
                var blToP = point - bl;
                if (bltr.Cross(blToP) < 0)
                    left.Points.Add(point);
                else
                    right.Points.Add(point);
            }

            var rightLine = MathUtil.ApproximateLine(right.Points);
        }
Пример #7
0
 public Stroq GetDerivate()
 {
     var d = new Stroq();
     for (var i = 0; i < Points.Count - 1; i++)
     {
         var x = Points[i].X;
         var dy = Points[i + 1].Y - Points[i].Y;
         d.Points.Add(new Point(x, dy));
     }
     return d;
 }
Пример #8
0
        public Stroq Clone()
        {
            var s = new Stroq();
            foreach (var point in Points)
            {
                s.Points.Add(new Point(point.X, point.Y));
            }

            if (BackingStroke != null)
                s.BackingStroke = BackingStroke.Clone();
            return s;
        }
Пример #9
0
 public Stroq GetDerivate()
 {
     var d = new Stroq();
     for (int i = 0; i < _points.Count - 1; i++)
     {
         double x = _points[i].X;
         double dy = _points[i + 1].Y - _points[i].Y;
         d.Points.Add(new Point(x, dy));
     }
     return d;
 }
Пример #10
0
        private void OnStrokeAdded(object sender, Stroq stroke)
        {
            Rect bb = stroke.BoundingRect;
            double w = MathUtil.Clamp(0,1,bb.Width / xInqCanvas.ActualWidth);
            double x = bb.X / xInqCanvas.ActualWidth;
            var end = MathUtil.Clamp(0,1,x + w);
            OnSelectionChange?.Invoke(x, end);

            var lvm = (LineGraphViewModel) DataContext;
            var ts = lvm.TimeSeries.First().Clone();
            ts.Trim(x, x+w);

            var transform = (CompositeTransform)RenderTransform;
            var tg = new TransformGroup();

            tg.Children.Add(Controller.Instance.MainCanvas.RenderTransform);
            //  tg.Children.Add(transform);

            var sp = tg.TransformPoint(new Point(transform.TranslateX, transform.TranslateY));
            var qb = Controller.Instance.AddQueryBox(sp.X, sp.Y, ts.GetNormalized());
               Anim.To(qb, "X", transform.TranslateX + 500, 300);
            var ty = transform.TranslateY -150;
            Anim.To(qb, "Y", ty, 300);
        }