refactor body tracking manager
This commit is contained in:
parent
be8a4dd1c0
commit
646ac34143
8 changed files with 43 additions and 107 deletions
|
@ -66,7 +66,6 @@
|
||||||
<Compile Include="Assets\Editor\SpectrumGeneratorEditMode.cs" />
|
<Compile Include="Assets\Editor\SpectrumGeneratorEditMode.cs" />
|
||||||
<Compile Include="Assets\Editor\StateManagerEditor.cs" />
|
<Compile Include="Assets\Editor\StateManagerEditor.cs" />
|
||||||
<Compile Include="Assets\Editor\UnitTest\UnitTest_ChangeObserver.cs" />
|
<Compile Include="Assets\Editor\UnitTest\UnitTest_ChangeObserver.cs" />
|
||||||
<Compile Include="Assets\Editor\UnitTest\UnitTest_Holder.cs" />
|
|
||||||
<Compile Include="Assets\Editor\UnitTest\UnitTest_RectangularSelection.cs" />
|
<Compile Include="Assets\Editor\UnitTest\UnitTest_RectangularSelection.cs" />
|
||||||
<Compile Include="Assets\Editor\UnitTest\UnitTest_SpectrumGeneratorEditMode.cs" />
|
<Compile Include="Assets\Editor\UnitTest\UnitTest_SpectrumGeneratorEditMode.cs" />
|
||||||
<Compile Include="Assets\Editor\UnitTest\UnitTest_SpectrumGeneratorPlayMode.cs" />
|
<Compile Include="Assets\Editor\UnitTest\UnitTest_SpectrumGeneratorPlayMode.cs" />
|
||||||
|
|
|
@ -74,7 +74,7 @@
|
||||||
<Compile Include="Assets\Scenes\Examples\TimbreID\script\IdToText.cs" />
|
<Compile Include="Assets\Scenes\Examples\TimbreID\script\IdToText.cs" />
|
||||||
<Compile Include="Assets\Scenes\Examples\VisualEffectGraph\script\FlareBind.cs" />
|
<Compile Include="Assets\Scenes\Examples\VisualEffectGraph\script\FlareBind.cs" />
|
||||||
<Compile Include="Assets\Scenes\Examples\VisualEffectGraph\script\SmokeBind.cs" />
|
<Compile Include="Assets\Scenes\Examples\VisualEffectGraph\script\SmokeBind.cs" />
|
||||||
<Compile Include="Assets\Scripts\Math\Holder.cs" />
|
<Compile Include="Assets\Scripts\Math\BodyHolder.cs" />
|
||||||
<Compile Include="Assets\Scripts\Math\Smoother.cs" />
|
<Compile Include="Assets\Scripts\Math\Smoother.cs" />
|
||||||
<Compile Include="Assets\Scripts\Math\Threshold.cs" />
|
<Compile Include="Assets\Scripts\Math\Threshold.cs" />
|
||||||
<Compile Include="Assets\Scripts\PdConnection\DspController.cs" />
|
<Compile Include="Assets\Scripts\PdConnection\DspController.cs" />
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
using NUnit.Framework;
|
|
||||||
|
|
||||||
namespace cylvester
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
public class UnitTest_Holder
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void Construction_capacity()
|
|
||||||
{
|
|
||||||
var holder = new Holder<int>(2);
|
|
||||||
|
|
||||||
holder.Add(1);
|
|
||||||
holder.Add(2);
|
|
||||||
holder.Add(3);
|
|
||||||
|
|
||||||
Assert.AreEqual(0, holder.IndexOf(1));
|
|
||||||
Assert.AreEqual(1, holder.IndexOf(2));
|
|
||||||
Assert.IsNull(holder.IndexOf(3));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Add()
|
|
||||||
{
|
|
||||||
var holder = new Holder<int>(2);
|
|
||||||
holder.Add(102);
|
|
||||||
|
|
||||||
Assert.AreEqual(0, holder.IndexOf(102));
|
|
||||||
Assert.IsNull(holder.IndexOf(103));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Add_return()
|
|
||||||
{
|
|
||||||
var holder = new Holder<int>(2);
|
|
||||||
Assert.IsTrue(holder.Add(102));
|
|
||||||
Assert.IsTrue(holder.Add(103));
|
|
||||||
Assert.IsFalse(holder.Add(103));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Add_unique()
|
|
||||||
{
|
|
||||||
var holder = new Holder<int>(2);
|
|
||||||
holder.Add(102);
|
|
||||||
holder.Add(102); // doesn't affect
|
|
||||||
holder.Add(103);
|
|
||||||
|
|
||||||
Assert.IsNull(holder.IndexOf(103));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Remove()
|
|
||||||
{
|
|
||||||
var holder = new Holder<int>(2);
|
|
||||||
holder.Add(102);
|
|
||||||
holder.Remove(102);
|
|
||||||
|
|
||||||
Assert.IsNull(holder.IndexOf(102));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: e41847d6d84d439e858e4eadb0232998
|
|
||||||
timeCreated: 1572778377
|
|
|
@ -20,26 +20,20 @@ namespace cylvester
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnSkeletonFrameReceived(Body[] bodies)
|
public void OnSkeletonFrameReceived(Body body, int id)
|
||||||
{
|
{
|
||||||
foreach (var body in bodies)
|
var i = 0;
|
||||||
|
foreach(var pair in body.Joints)
|
||||||
{
|
{
|
||||||
if(!body.IsTracked)
|
var joint = pair.Value;
|
||||||
continue;
|
if(joint.TrackingState == TrackingState.NotTracked)
|
||||||
|
balls_[i].SetActive(false);
|
||||||
var i = 0;
|
else
|
||||||
foreach(var pair in body.Joints)
|
|
||||||
{
|
{
|
||||||
var joint = pair.Value;
|
balls_[i].SetActive(true);
|
||||||
if(joint.TrackingState == TrackingState.NotTracked)
|
balls_[i].transform.position = new Vector3(joint.Position.X * 10f , joint.Position.Y * 10f, 0f);
|
||||||
balls_[i].SetActive(false);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
balls_[i].SetActive(true);
|
|
||||||
balls_[i].transform.position = new Vector3(joint.Position.X * 10f , joint.Position.Y * 10f, 0f);
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,43 +1,43 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Windows.Kinect;
|
||||||
|
|
||||||
namespace cylvester
|
namespace cylvester
|
||||||
{
|
{
|
||||||
public class Holder<T> where T : IEquatable<T>
|
public class BodyHolder
|
||||||
{
|
{
|
||||||
private readonly List<T> elements_;
|
private readonly List<Body> elements_;
|
||||||
private readonly int capacity_;
|
private readonly int capacity_;
|
||||||
|
|
||||||
public Holder(int capacity)
|
public BodyHolder(int capacity)
|
||||||
{
|
{
|
||||||
capacity_ = capacity;
|
capacity_ = capacity;
|
||||||
elements_ = new List<T>();
|
elements_ = new List<Body>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Add(T newElement)
|
public bool Add(Body newBody)
|
||||||
{
|
{
|
||||||
if (elements_.Count == capacity_)
|
if (elements_.Count == capacity_)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (elements_.Contains(newElement))
|
if (elements_.Contains(newBody))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
elements_.Add(newElement);
|
elements_.Add(newBody);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Exist(T element)
|
public bool Exist(Body element)
|
||||||
{
|
{
|
||||||
return elements_.Contains(element);
|
return elements_.Contains(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int? IndexOf(T element)
|
public int? IndexOf(Body element)
|
||||||
{
|
{
|
||||||
var index = elements_.FindIndex(e => e.Equals(element));
|
var index = elements_.FindIndex(e => e.Equals(element));
|
||||||
return (index < 0) ? (int?) null : index;
|
return (index < 0) ? (int?) null : index;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(T element)
|
public void Remove(Body element)
|
||||||
{
|
{
|
||||||
elements_.Remove(element);
|
elements_.Remove(element);
|
||||||
}
|
}
|
|
@ -32,7 +32,7 @@ namespace cylvester
|
||||||
private EventHandler<InfraredFrameArrivedEventArgs> onInfraredFrameArrived_;
|
private EventHandler<InfraredFrameArrivedEventArgs> onInfraredFrameArrived_;
|
||||||
private EventHandler<BodyFrameArrivedEventArgs> onBodyFrameArrived_;
|
private EventHandler<BodyFrameArrivedEventArgs> onBodyFrameArrived_;
|
||||||
private EventHandler<BodyIndexFrameArrivedEventArgs> onBodyIndexFrameArrived_;
|
private EventHandler<BodyIndexFrameArrivedEventArgs> onBodyIndexFrameArrived_;
|
||||||
private Holder<ulong> trackedIds_;
|
private BodyHolder trackedBodies_;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
@ -86,7 +86,7 @@ namespace cylvester
|
||||||
private void InitSkeletonTracking()
|
private void InitSkeletonTracking()
|
||||||
{
|
{
|
||||||
bodies_ = new Body[6];
|
bodies_ = new Body[6];
|
||||||
trackedIds_ = new Holder<ulong>(numberOfBodiesTobeTracked);
|
trackedBodies_ = new BodyHolder(numberOfBodiesTobeTracked);
|
||||||
InitBodyFrameReader();
|
InitBodyFrameReader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,24 +104,32 @@ namespace cylvester
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bodyFrame.GetAndRefreshBodyData(bodies_);
|
bodyFrame.GetAndRefreshBodyData(bodies_);
|
||||||
foreach (var body in bodies_.Where(body => body.IsTracked))
|
foreach (var body in bodies_.Where(t => t.IsTracked))
|
||||||
{
|
{
|
||||||
if (trackedIds_.Exist(body.TrackingId))
|
if (body.IsTracked)
|
||||||
{
|
{
|
||||||
var idNumber = trackedIds_.IndexOf(body.TrackingId);
|
if (trackedBodies_.Exist(body))
|
||||||
if(idNumber.HasValue)
|
|
||||||
skeletonDataReceived.Invoke(body, idNumber.Value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (trackedIds_.Add(body.TrackingId))
|
|
||||||
{
|
{
|
||||||
var idNumber = trackedIds_.IndexOf(body.TrackingId);
|
var idNumber = trackedBodies_.IndexOf(body);
|
||||||
if (idNumber.HasValue)
|
if (idNumber.HasValue)
|
||||||
skeletonDataReceived.Invoke(body, idNumber.Value);
|
skeletonDataReceived.Invoke(body, idNumber.Value);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (trackedBodies_.Add(body))
|
||||||
|
{
|
||||||
|
var idNumber = trackedBodies_.IndexOf(body);
|
||||||
|
if (idNumber.HasValue)
|
||||||
|
skeletonDataReceived.Invoke(body, idNumber.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var body in bodies_.Where(t => !t.IsTracked && trackedBodies_.Exist(t)))
|
||||||
|
{
|
||||||
|
trackedBodies_.Remove(body);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
bodyFrameReader_.FrameArrived += onBodyFrameArrived_;
|
bodyFrameReader_.FrameArrived += onBodyFrameArrived_;
|
||||||
|
|
Loading…
Reference in a new issue