void SetSource(TouchMouseSensorEventArgs e)
    {
      //Send for recording
      Recorder.Append(e.Status, e.Image);

      // Convert bitmap from memory to graphic form.
      BitmapSource source =
          BitmapSource.Create(e.Status.m_dwImageWidth, e.Status.m_dwImageHeight,
          96, 96,
          PixelFormats.Gray8, null, e.Image, e.Status.m_dwImageWidth);

      // Show bitmap in user interface.
      SensorImage.Source = source;
    }
Esempio n. 2
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;
        }
 /// <summary>
 /// Handle callback from mouse.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The event arguments.</param>
 void TouchMouseSensorHandler(object sender, TouchMouseSensorEventArgs e)
 {
   // We're in a thread belonging to the mouse, not the user interface 
   // thread. Need to dispatch to the user interface thread.
   Dispatcher.Invoke((Action<TouchMouseSensorEventArgs>)SetSource, e);
 }
Esempio n. 4
0
 void TouchMouseSensorHandler(object sender, TouchMouseSensorEventArgs e)
 {
     // We're in a thread belonging to the mouse, not the user interface
     // thread. Need to dispatch to the user interface thread.
     _args = e;
 }