123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using bbiwarg.Images;
- using bbiwarg.Graphics;
- using bbiwarg.Recognition.Tracking;
- using bbiwarg.Utility;
- using TUIO;
- namespace bbiwarg.Recognition.TouchRecognition
- {
- class TouchTracker : Tracker<TouchEvent>
- {
- public List<TouchEvent> TouchEvents { get { return TrackedObjects; } }
- private TuioServer tuioServer;
- private Dictionary<int, TuioCursor> tuioCursors;
- private TouchEventVisualizer touchEventVisualizer;
- public TouchTracker(TuioServer tuioServer, TouchEventVisualizer touchEventVisualizer)
- : base(Constants.TouchEventNumFramesDetectedUntilTracked, Constants.TouchEventNumFramesLostUntilDeleted, Constants.TouchEventMinSimilarityForTracking)
- {
- this.tuioServer = tuioServer;
- this.tuioCursors = new Dictionary<int, TuioCursor>();
- this.touchEventVisualizer = touchEventVisualizer;
- }
- public new void reset() {
- tuioCursors.Clear();
- touchEventVisualizer.Reset();
- base.reset();
- }
- public new void updateFrame(List<TouchEvent> detectedObjects)
- {
- tuioServer.initFrame();
- base.updateFrame(detectedObjects);
- tuioServer.commitFrame();
- touchEventVisualizer.updateImage();
- }
- protected override void onStateChanged(object sender, TrackingStateChangeEventArgs e)
- {
- TrackableObjectHistory<TouchEvent> history = (TrackableObjectHistory<TouchEvent>)sender;
- TouchEvent currentTouchEvent = history.LastObject;
- if (currentTouchEvent is PalmTouchEvent)
- {
- PalmTouchEvent currentPalmTouchEvent = (PalmTouchEvent)currentTouchEvent;
- Vector2D currentRelativePosition = currentPalmTouchEvent.RelativePalmPosition;
- TuioCursor tuioCursor;
- switch (e.NextState)
- {
- case TrackingState.Tracked:
- if (tuioCursors.TryGetValue(history.ID, out tuioCursor))
- {
- tuioServer.updateTuioCursor(tuioCursor, currentRelativePosition.X, currentRelativePosition.Y);
- touchEventVisualizer.updateTouchEvent(history.ID, currentRelativePosition);
- Logger.log("TouchEvent #" + history.ID.ToString() + " touchMove to (" + currentRelativePosition.X + ", " + currentRelativePosition.Y + ")", LogSubject.TouchTracker);
- }
- else
- {
- TuioCursor newTuioCursor = tuioServer.addTuioCursor(currentRelativePosition.X, currentRelativePosition.Y);
- tuioCursors.Add(history.ID, newTuioCursor);
- touchEventVisualizer.addTouchEvent(history.ID, currentRelativePosition);
- Logger.log("TouchEvent #" + history.ID.ToString() + " touchDown at (" + currentRelativePosition.X + ", " + currentRelativePosition.Y + ")", LogSubject.TouchTracker);
- }
- break;
- case TrackingState.Delete:
- if (tuioCursors.TryGetValue(history.ID, out tuioCursor))
- {
- tuioServer.removeTuioCursor(tuioCursor);
- tuioCursors.Remove(history.ID);
- touchEventVisualizer.removeTouchEvent(history.ID);
- Logger.log("TouchEvent #" + history.ID.ToString() + " touchUp at (" + currentRelativePosition.X + ", " + currentRelativePosition.Y + ")", LogSubject.TouchTracker);
- }
- break;
- }
- }
- }
- }
- }
|