Esempio n. 1
0
 internal void FindMovements(TouchImage previousImage)
 {
     if (this.CenterOfGravity != null && previousImage != null)
     {
         this.CenterOfGravity.CreateMovement(previousImage.CenterOfGravity);
     }
     foreach (var point in TouchPoints)
     {
         point.CreateMovement(previousImage);
     }
 }
Esempio n. 2
0
        internal static TouchPoint Create(TouchImage touchImage, int i)
        {
            int x = i % touchImage.Width;
            int y = i / touchImage.Width;
            TouchPoint touchPoint = Create(x, y);

            touchPoint.FocalPointValue = touchImage[x, y];
            touchPoint.FindAdjacentPoints(touchImage, x, y);
            touchPoint.FindType(touchImage.Width);

            return touchPoint;
        }
Esempio n. 3
0
        private void FindAdjacentPoints(TouchImage image, int x, int y)
        {
            // Look right
            if (x + 1 < image.Width && image[x + 1, y] > 0)
            {
                AddValidPoint(image, x + 1, y);
            }

            // Look left
            if (x == Left && x > 0 && image[x - 1, y] > 0)
            {
                AddValidPoint(image, x - 1, y);
            }

            // Look diagonal left-down if it hasn't been checked yet
            //if (x == Left && x > 0 && y + 1 < image.Height && image[x - 1, y + 1] > 0)
            //{
            //    AddValidPoint(image, x - 1, y + 1);
            //}

            // Look down
            if (y + 1 < image.Height && image[x, y + 1] > 0)
            {
                AddValidPoint(image, x, y + 1);
            }

            // Look down and right
            //if (x + 1 < image.Width && y + 1 < image.Height && image[x + 1, y + 1] > 0)
            //{
            //    AddValidPoint(image, x + 1, y + 1);
            //}
        }
Esempio n. 4
0
        private void AddValidPoint(TouchImage image, int x, int y)
        {
            Mass += image[x, y];

            if (FocalPointValue < image[x, y])
            {
                FocalPointValue = image[x, y];
                FocalPointX = x;
                FocalPointY = y;
            }

            if (x > Right)
            {
                Right = x;
            }

            if (x < Left)
            {
                Left = x;
            }

            if (y > Bottom)
            {
                Bottom = y;
            }

            if (y < Top)
            {
                System.Diagnostics.Trace.WriteLine("Y:" + y + "should not be less than Top:" + Top);
            }

            FindAdjacentPoints(image, x, y);
            System.Diagnostics.Debug.Assert(y >= Top, "Y:" + y + "should be >= than Top:" + Top);
        }
Esempio n. 5
0
        internal void CreateMovement(TouchImage previousImage)
        {
            TouchPoint previousPoint = null;
            if (previousImage != null)
            {
                //previousPoint = previousImage.TouchPoints.Where(x => x.TouchPointType == this.TouchPointType).OrderBy(x => this.DistanceTo(x)).FirstOrDefault();
                previousPoint = previousImage.TouchPoints.FirstOrDefault(x => x.TouchPointType == this.TouchPointType && !x.HasBeenFollowed);
                // Try checking points from button region if this point is a button
                if (previousPoint == null && (this.IsButton()))
                {
                    //previousPoint = previousImage.TouchPoints.Where(x => x.IsButton()).OrderBy(x => this.DistanceTo(x)).FirstOrDefault();
                    previousPoint = previousImage.TouchPoints.FirstOrDefault(x => !x.HasBeenFollowed && x.IsButton());
                }
            }

            CreateMovement(previousPoint);
        }
Esempio n. 6
0
        private void TimerTick(object state, EventArgs e)
        {
            _frameNumber++;

            if (_args == null)
            {
                MainWindow.SetSensorImage(TouchImage.GetEmptyImage());
                return;
            }

            //Stopwatch sw = new Stopwatch();
            //sw.Start();

            TouchImage currentImage = new TouchImage()
            {
                Height = (byte)_args.Status.m_dwImageHeight,
                Width = (byte)_args.Status.m_dwImageWidth,
                Image = _args.Image,
                FrameNumber = _frameNumber,
            };

            currentImage.FindTouchPoints();

            if (currentImage.TouchPoints.Count > 0)
            {
                currentImage.FindMovements(_previousImage);
            }

            // Check touchpoints that were not continued for gestures
            if (_previousImage != null)
            {
                _previousImage.CheckGesture();
            }

            _previousImage = currentImage;

            //sw.Stop();
            //Trace.WriteLine("Elapsed: " + sw.ElapsedMilliseconds);
            //MainWindow.SetMessage("Elapsed: " + sw.ElapsedMilliseconds);

            bool hasPrinted = false;

            if (currentImage.CenterOfGravity != null && currentImage.CenterOfGravity.Movement != null
                && currentImage.CenterOfGravity.Movement.Magnitude > Movement.MOVEMENT_THRESHOLD)
            {
                Trace.WriteLine(string.Format("{0}, {1}: {2}, {3}: {4}: {5}", currentImage.CenterOfGravity.FocalPointX,
                    currentImage.CenterOfGravity.FocalPointY, currentImage.CenterOfGravity.Movement.XMovement,
                    currentImage.CenterOfGravity.Movement.YMovement, currentImage.CenterOfGravity.Movement.Magnitude,
                    currentImage.CenterOfGravity.TouchPointType));
                Trace.WriteLine(string.Join<Movement>(", ", currentImage.CenterOfGravity.Movements));
                Trace.WriteLine("*********************");
                hasPrinted = true;
            }

            if (currentImage.TouchPoints.Count(x => x.Movement.Magnitude > Movement.MOVEMENT_THRESHOLD) > 0)
            {
                int movementCount = 0;
                foreach (var point in currentImage.TouchPoints)
                {
                    movementCount += point.Movements.Count;
                    //if (point.Gesture != null && point.Movement.Magnitude > Movement.MOVEMENT_THRESHOLD)//point.Gesture.LastOrDefault() == point.Movement)
                    //{
                    Trace.WriteLine(string.Format("{0}, {1}: {2}, {3}: {4}: {5}: {6}", point.FocalPointX, point.FocalPointY, point.Movement.XMovement, point.Movement.YMovement, point.Movement.Magnitude, point.Movement.Direction, point.TouchPointType));
                    Trace.WriteLine(string.Join<Movement>(", ", currentImage.CenterOfGravity.Movements));
                    Trace.WriteLine("*********************");
                    hasPrinted = true;
                }
            }

            if (hasPrinted)
            {
                System.Diagnostics.Trace.WriteLine("------------------- End Frame " + _frameNumber + " --------------------");
            }

            //SensorImage.Source = ti.GetSensorImage();
            //SensorImage.Source = ti.GetTouchPointImage();
            MainWindow.SetSensorImage(currentImage.GetTouchPointImageColored());

            _args = null;
        }