Add(dev): le mapping implémenter, mais pas testé

pull/22/head
Louis DUFOUR 1 year ago
parent 76ea8f36cc
commit 14a4beb21d

@ -7,31 +7,80 @@ using System.Threading.Tasks;
namespace KinectUtils
{
class BaseMapping<T>
public abstract class BaseMapping<T>
{
public void SubscribeToStartGesture(BaseGesture gesture)
protected bool running = false;
public event EventHandler<OnMappingEventArgs<T>> OnMapping;
protected BaseMapping(BaseGesture startGesture, BaseGesture endGesture)
{
SubscribeToStartGesture(startGesture);
SubscribeToEndGesture(endGesture);
// Assuming GestureManager has an event that provides processed body data
GestureManager.ProcessedBodyFrameArrived += OnProcessedBodyFrameArrived;
}
protected abstract T Mapping(Body body);
protected bool TestMapping(Body body, out T output)
{
output = default(T);
if (running)
{
output = Mapping(body);
return true;
}
return false;
}
protected void SubscribeToStartGesture(BaseGesture gesture)
{
throw new NotImplementedException();
gesture.GestureRecognized += (sender, e) => { if (!running) running = true; };
}
public void SubscribeToEndGesture(BaseGesture gesture)
protected void SubscribeToEndGesture(BaseGesture gesture)
{
throw new NotImplementedException();
gesture.GestureRecognized += (sender, e) => { if (running) running = false; };
}
public void SubscribeToToggleGesture(BaseGesture gesture)
// Assuming your GestureManager provides a similar event
protected void OnProcessedBodyFrameArrived(object sender, ProcessedBodyFrameEventArgs e)
{
throw new NotImplementedException();
foreach (var body in e.Bodies)
{
if (body.IsTracked)
{
T output;
if (TestMapping(body, out output))
{
OnMapping?.Invoke(this, new OnMappingEventArgs<T>(output));
}
}
}
}
}
public class OnMappingEventArgs<T> : EventArgs
{
public T MappedValue { get; private set; }
protected T Mapping(Body body)
public OnMappingEventArgs(T mappedValue)
{
throw new NotImplementedException();
MappedValue = mappedValue;
}
}
// Custom EventArgs to be used within your application logic
// This is not from the Kinect SDK, but rather a custom class to pass along processed body data
public class ProcessedBodyFrameEventArgs : EventArgs
{
public Body[] Bodies { get; private set; }
public Body ClosestBody { get; private set; }
public bool TestMapping(Body body, out T output)
public ProcessedBodyFrameEventArgs(Body[] bodies, Body closestBody)
{
throw new NotImplementedException();
Bodies = bodies;
ClosestBody = closestBody;
}
}
}

@ -14,7 +14,12 @@ namespace KinectUtils
{
private static BodyFrameReader bodyFrameReader;
private static Body[] bodies;
static event EventHandler GestureRecognized;
public static event EventHandler BodyFrameArrived;
public static event EventHandler<ProcessedBodyFrameEventArgs> ProcessedBodyFrameArrived;
static KinectManager KinectManager { get; set; }
static List<BaseGesture> KnownGestures { get; set; } = new List<BaseGesture>();
@ -62,19 +67,24 @@ namespace KinectUtils
bodies = new Body[bodyframe.BodyCount];
}
bodyframe.GetAndRefreshBodyData(bodies);
if (bodies != null)
Body closestBody = bodies.Where(b => b.IsTracked)
.OrderBy(b => b.Joints[JointType.SpineBase].Position.Z)
.FirstOrDefault();
ProcessedBodyFrameArrived?.Invoke(sender, new ProcessedBodyFrameEventArgs(bodies, closestBody));
foreach (var body in bodies)
{
foreach (var body in bodies)
if (body.IsTracked)
{
if (body.IsTracked)
foreach (var gesture in KnownGestures)
{
foreach (var gesture in KnownGestures)
{
gesture.TestGesture(body);
}
gesture.TestGesture(body);
}
}
}
}
}
}

@ -42,6 +42,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="AllGesturesFactory.cs" />

Loading…
Cancel
Save