Skip to content

Commit

Permalink
determine tuio object state (added, updated, removed)
Browse files Browse the repository at this point in the history
  • Loading branch information
polischouckserg committed Oct 16, 2018
1 parent 716777e commit 3d35fe9
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions RecognitionService/Input/Tuio/TuioObjectController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Collections.Generic;

using RecognitionService.Models;
Expand All @@ -13,6 +14,8 @@ public class TuioObjectController : ITuioInputProvider, IDisposable
private TangibleMarkerController _tangibleMarkerController;
private ITangibleMarkerRecognizer _tangibleMarkerRecognizer = new TangibleMarkerRecognizer();

private Dictionary<int, RecognizedTangibleMarker> previouslyRecognizedTangibles = new Dictionary<int, RecognizedTangibleMarker>();

public event Action<List<TouchPoint>, List<RecognizedTangibleMarker>> OnTuioInput;

public TuioObjectController(IInputProvider inputProvider, TangibleMarkerController tangibleMarkerController)
Expand All @@ -26,12 +29,49 @@ private void ProcessFrame(TouchPointFrame frame)
{
var registredTangibles = _tangibleMarkerController.Config.registredTangibles;
var recognizedTangibles = _tangibleMarkerRecognizer.RecognizeTangibleMarkers(frame.touches, registredTangibles);

// TODO - detect previously recognized tangibles and tangibles that disappeared

var currentRecognizedTangibles = DetermineMarkerState(recognizedTangibles);
previouslyRecognizedTangibles = currentRecognizedTangibles;

// TODO - split touches from objects

OnTuioInput?.Invoke(frame.touches, recognizedTangibles);
OnTuioInput?.Invoke(frame.touches, currentRecognizedTangibles.Values.ToList());
}

private Dictionary<int, RecognizedTangibleMarker> DetermineMarkerState(List<RecognizedTangibleMarker> recognizedTangibles)
{
var currentRecognizedTangibles = new Dictionary<int, RecognizedTangibleMarker>();
foreach (var tangible in recognizedTangibles)
{
if (previouslyRecognizedTangibles.ContainsKey(tangible.Id))
{
// Updated
var tuioObj = previouslyRecognizedTangibles[tangible.Id];
tuioObj.Type = RecognizedTangibleMarker.ActionType.Updated;
currentRecognizedTangibles[tuioObj.Id] = tuioObj;
}
else
{
// Added
var tuioObj = tangible;
tuioObj.Type = RecognizedTangibleMarker.ActionType.Added;
currentRecognizedTangibles[tuioObj.Id] = tuioObj;
}
}

var lookup = recognizedTangibles.ToDictionary(o => o.Id);
foreach (var tangibleId in previouslyRecognizedTangibles.Keys)
{
if (!lookup.ContainsKey(tangibleId))
{
// Removed
var tuioObj = lookup[tangibleId];
tuioObj.Type = RecognizedTangibleMarker.ActionType.Removed;
currentRecognizedTangibles[tuioObj.Id] = tuioObj;
}
}

return currentRecognizedTangibles;
}

public void Dispose()
Expand Down

0 comments on commit 3d35fe9

Please sign in to comment.