Commit c1882494 authored by 16이상민's avatar 16이상민

Repair errors

parent a07b33a7
No related merge requests found
...@@ -62,10 +62,7 @@ public class SourceBufferTests ...@@ -62,10 +62,7 @@ public class SourceBufferTests
var obj = new SourceBuffer(); var obj = new SourceBuffer();
obj.UpdateBuffers(frame); obj.UpdateBuffers(frame);
var expected = new byte[KinectConstants.ColorWidth * var expected = frame.LastColorFrame.GetData();
KinectConstants.ColorHeight *
KinectConstants.ColorCount];
frame.LastColorFrame.CopyData(expected);
var actual = obj.ColorBuffer; var actual = obj.ColorBuffer;
...@@ -83,9 +80,7 @@ public class SourceBufferTests ...@@ -83,9 +80,7 @@ public class SourceBufferTests
var obj = new SourceBuffer(); var obj = new SourceBuffer();
obj.UpdateBuffers(frame); obj.UpdateBuffers(frame);
var expected = new byte[KinectConstants.DepthWidth * var expected = frame.LastBodyIndexFrame.GetData();
KinectConstants.DepthHeight];
frame.LastBodyIndexFrame.CopyData(expected);
var actual = obj.BodyIndexBuffer; var actual = obj.BodyIndexBuffer;
...@@ -103,9 +98,7 @@ public class SourceBufferTests ...@@ -103,9 +98,7 @@ public class SourceBufferTests
var obj = new SourceBuffer(); var obj = new SourceBuffer();
obj.UpdateBuffers(frame); obj.UpdateBuffers(frame);
var expected = new ushort[KinectConstants.DepthWidth * var expected = frame.LastDepthFrame.GetData();
KinectConstants.DepthHeight];
frame.LastDepthFrame.CopyData(expected);
var actual = obj.DepthBuffer; var actual = obj.DepthBuffer;
...@@ -123,8 +116,7 @@ public class SourceBufferTests ...@@ -123,8 +116,7 @@ public class SourceBufferTests
var obj = new SourceBuffer(); var obj = new SourceBuffer();
obj.UpdateBuffers(frame); obj.UpdateBuffers(frame);
var expected = new IBody[KinectConstants.BodyCount]; var expected = frame.LastBodyFrame.GetData();
frame.LastBodyFrame.CopyData(expected);
var actual = obj.BodyBuffer; var actual = obj.BodyBuffer;
...@@ -157,74 +149,121 @@ public class MultiSourceFrameStub : IMultiSourceFrame ...@@ -157,74 +149,121 @@ public class MultiSourceFrameStub : IMultiSourceFrame
public class GreenColorFrameStub : IColorFrame public class GreenColorFrameStub : IColorFrame
{ {
private static uint[] data = private static byte[] data = Enumerable.Range(0,
Enumerable.Repeat<uint>(0x00FF00FF, KinectConstants.ColorWidth *
KinectConstants.ColorWidth * KinectConstants.ColorHeight)
KinectConstants.ColorHeight).ToArray(); .Select(x => (byte)((x & 1) == 1 ? 0xFF : 0))
.ToArray();
public void CopyData(byte[] buffer)
public byte[] GetData()
{ {
Buffer.BlockCopy(buffer, 0, data, 0, buffer.Length); return data;
} }
} }
public class Fill1BodyIndexFrameStub : IBodyIndexFrame public class Fill1BodyIndexFrameStub : IBodyIndexFrame
{ {
public void CopyData(byte[] buffer) private static byte[] data = Enumerable.Repeat(0,
KinectConstants.DepthWidth *
KinectConstants.DepthHeight)
.Select(x => (byte)x)
.ToArray();
public byte[] GetData()
{ {
for (int i = 0; i < buffer.Length; ++i) return data;
buffer[i] = 1;
} }
} }
public class Fill8000DepthFrameStub : IDepthFrame public class Fill8000DepthFrameStub : IDepthFrame
{ {
public void CopyData(ushort[] buffer) private static ushort[] data = Enumerable.Repeat(8000,
KinectConstants.DepthWidth *
KinectConstants.DepthHeight)
.Select(x => (ushort)x)
.ToArray();
public ushort[] GetData()
{ {
for (int i = 0; i < buffer.Length; ++i) return data;
buffer[i] = 8000;
} }
} }
public class CleanBodyFrameStub : IBodyFrame public class CleanBodyFrameStub : IBodyFrame
{ {
public void CopyData(IBody[] buffer) private static BodyFake[] data = Enumerable.Range(0, KinectConstants.BodyCount)
.Select(x =>
{
var tmp = new BodyFake();
var joints = tmp.Joints;
for (int j = 0; j < KinectConstants.JointCount; ++j)
joints[joints.ElementAt(j).Key] = new JointStub();
tmp.IsTracked = false;
return tmp;
})
.ToArray();
public IBody[] GetData()
{ {
for (int i = 0; i < buffer.Length; ++i) return data;
{
var tmp = new BodyFake();
var joints = tmp.Joints;
for(int j = 0; j < KinectConstants.JointCount; ++j)
joints[joints.ElementAt(j).Key] = new JointStub();
tmp.IsTracked = false;
buffer[i] = tmp;
}
} }
} }
public class ColorFrameDummy : IColorFrame public class ColorFrameDummy : IColorFrame
{ {
private static byte[] data = new byte[KinectConstants.ColorWidth *
KinectConstants.ColorHeight *
KinectConstants.ColorCount];
public void CopyData(byte[] buffer) public void CopyData(byte[] buffer)
{ } { }
public byte[] GetData()
{
return data;
}
} }
public class BodyIndexFrameDummy : IBodyIndexFrame public class BodyIndexFrameDummy : IBodyIndexFrame
{ {
private static byte[] data = new byte[KinectConstants.DepthWidth *
KinectConstants.DepthHeight];
public void CopyData(byte[] buffer) public void CopyData(byte[] buffer)
{ } { }
public byte[] GetData()
{
return data;
}
} }
public class DepthFrameDummy : IDepthFrame public class DepthFrameDummy : IDepthFrame
{ {
private static ushort[] data = new ushort[KinectConstants.DepthWidth *
KinectConstants.DepthHeight];
public void CopyData(ushort[] buffer) public void CopyData(ushort[] buffer)
{ } { }
public ushort[] GetData()
{
return data;
}
} }
public class BodyFrameDummy : IBodyFrame public class BodyFrameDummy : IBodyFrame
{ {
private static IBody[] data = new IBody[KinectConstants.BodyCount];
public void CopyData(IBody[] buffer) public void CopyData(IBody[] buffer)
{ } { }
public IBody[] GetData()
{
return data;
}
} }
public class BodyFake : IBody public class BodyFake : IBody
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
{ {
public interface IBodyFrame public interface IBodyFrame
{ {
void CopyData(IBody[] buffer); IBody[] GetData();
} }
} }
\ No newline at end of file
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
{ {
public interface IBodyIndexFrame public interface IBodyIndexFrame
{ {
void CopyData(byte[] buffer); byte[] GetData();
} }
} }
\ No newline at end of file
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
{ {
public interface IColorFrame public interface IColorFrame
{ {
void CopyData(byte[] buffer); byte[] GetData();
} }
} }
\ No newline at end of file
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
{ {
public interface IDepthFrame public interface IDepthFrame
{ {
void CopyData(ushort[] buffer); ushort[] GetData();
} }
} }
\ No newline at end of file
...@@ -7,6 +7,7 @@ namespace KinectModule ...@@ -7,6 +7,7 @@ namespace KinectModule
public class RealBody : IBody public class RealBody : IBody
{ {
private Body _Body; private Body _Body;
private Dictionary<JointType, IJoint> _Joints;
public bool IsTracked public bool IsTracked
{ {
...@@ -19,9 +20,7 @@ namespace KinectModule ...@@ -19,9 +20,7 @@ namespace KinectModule
{ {
get get
{ {
return _Body.Joints.Select(x => new KeyValuePair<JointType, IJoint> return _Joints;
(x.Key, new RealJoint(x.Value)))
.ToDictionary(x => x.Key, x => x.Value);
} }
} }
public Body Value public Body Value
...@@ -34,16 +33,25 @@ namespace KinectModule ...@@ -34,16 +33,25 @@ namespace KinectModule
public RealBody(Body body) public RealBody(Body body)
{ {
_Body = body; if (body != null)
{
_Body = body;
_Joints = _Body.Joints.Select(x => new KeyValuePair<JointType, IJoint>
(x.Key, new RealJoint(x.Value)))
.ToDictionary(x => x.Key, x => x.Value);
}
} }
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
return this.Equals(obj as IBody); return Equals(obj as IBody);
} }
public bool Equals(IBody obj) public bool Equals(IBody obj)
{ {
if (_Body == null)
return obj == null;
var keys = Joints.Select(x => x.Key); var keys = Joints.Select(x => x.Key);
foreach (var key in keys) foreach (var key in keys)
{ {
......
...@@ -5,25 +5,22 @@ namespace KinectModule ...@@ -5,25 +5,22 @@ namespace KinectModule
{ {
public class RealBodyFrame : IBodyFrame public class RealBodyFrame : IBodyFrame
{ {
private Body[] _Buffer = new Body[KinectConstants.BodyCount]; private static Body[] _Buffer = new Body[KinectConstants.BodyCount];
private bool IsValid = false;
public RealBodyFrame(BodyFrame frame) public RealBodyFrame(BodyFrame frame)
{ {
if (frame != null) if (frame != null)
{ {
frame.GetAndRefreshBodyData(_Buffer); frame.GetAndRefreshBodyData(_Buffer);
IsValid = true;
} }
} }
public void CopyData(IBody[] buffer) public IBody[] GetData()
{ {
if (IsValid) return Enumerable.Range(0, KinectConstants.BodyCount)
Enumerable.Range(0, KinectConstants.BodyCount) .ToList()
.ToList() .Select(x => new RealBody(_Buffer[x]))
.ForEach(x => buffer[x] = new RealBody(_Buffer[x])); .ToArray();
} }
} }
} }
\ No newline at end of file
using System; using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using Windows.Kinect; using Windows.Kinect;
namespace KinectModule namespace KinectModule
{ {
public class RealBodyIndexFrame : IBodyIndexFrame public class RealBodyIndexFrame : IBodyIndexFrame
{ {
private byte[] _Buffer = new byte[KinectConstants.DepthWidth * private static byte[] _Buffer = new byte[KinectConstants.DepthWidth *
KinectConstants.DepthHeight]; KinectConstants.DepthHeight];
private bool IsValid = false;
public RealBodyIndexFrame(BodyIndexFrame frame) public RealBodyIndexFrame(BodyIndexFrame frame)
{ {
...@@ -17,15 +15,12 @@ namespace KinectModule ...@@ -17,15 +15,12 @@ namespace KinectModule
var BodyIndexData = GCHandle.Alloc(_Buffer, GCHandleType.Pinned); var BodyIndexData = GCHandle.Alloc(_Buffer, GCHandleType.Pinned);
frame.CopyFrameDataToIntPtr(BodyIndexData.AddrOfPinnedObject(), (uint)_Buffer.Length); frame.CopyFrameDataToIntPtr(BodyIndexData.AddrOfPinnedObject(), (uint)_Buffer.Length);
BodyIndexData.Free(); BodyIndexData.Free();
IsValid = true;
} }
} }
public void CopyData(byte[] buffer) public byte[] GetData()
{ {
if (IsValid) return _Buffer;
Array.Copy(_Buffer, buffer, _Buffer.Length);
} }
} }
} }
\ No newline at end of file
using System; using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using Windows.Kinect; using Windows.Kinect;
namespace KinectModule namespace KinectModule
{ {
public class RealColorFrame : IColorFrame public class RealColorFrame : IColorFrame
{ {
private byte[] _Buffer = new byte[KinectConstants.ColorWidth * private static byte[] _Buffer = new byte[KinectConstants.ColorWidth *
KinectConstants.ColorHeight * KinectConstants.ColorHeight *
KinectConstants.ColorCount]; KinectConstants.ColorCount];
private bool IsValid = false;
public RealColorFrame(ColorFrame frame) public RealColorFrame(ColorFrame frame)
{ {
...@@ -18,15 +16,12 @@ namespace KinectModule ...@@ -18,15 +16,12 @@ namespace KinectModule
var ColorData = GCHandle.Alloc(_Buffer, GCHandleType.Pinned); var ColorData = GCHandle.Alloc(_Buffer, GCHandleType.Pinned);
frame.CopyConvertedFrameDataToIntPtr(ColorData.AddrOfPinnedObject(), (uint)_Buffer.Length, ColorImageFormat.Rgba); frame.CopyConvertedFrameDataToIntPtr(ColorData.AddrOfPinnedObject(), (uint)_Buffer.Length, ColorImageFormat.Rgba);
ColorData.Free(); ColorData.Free();
IsValid = true;
} }
} }
public void CopyData(byte[] buffer) public byte[] GetData()
{ {
if (IsValid) return _Buffer;
Array.Copy(_Buffer, buffer, _Buffer.Length);
} }
} }
} }
\ No newline at end of file
using System; using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using Windows.Kinect; using Windows.Kinect;
namespace KinectModule namespace KinectModule
{ {
public class RealDepthFrame : IDepthFrame public class RealDepthFrame : IDepthFrame
{ {
private ushort[] _Buffer = new ushort[KinectConstants.DepthWidth * private static ushort[] _Buffer = new ushort[KinectConstants.DepthWidth *
KinectConstants.DepthHeight]; KinectConstants.DepthHeight];
private bool IsValid = false;
public RealDepthFrame(DepthFrame frame) public RealDepthFrame(DepthFrame frame)
{ {
...@@ -17,15 +15,12 @@ namespace KinectModule ...@@ -17,15 +15,12 @@ namespace KinectModule
var DepthData = GCHandle.Alloc(_Buffer, GCHandleType.Pinned); var DepthData = GCHandle.Alloc(_Buffer, GCHandleType.Pinned);
frame.CopyFrameDataToIntPtr(DepthData.AddrOfPinnedObject(), (uint)_Buffer.Length * sizeof(ushort)); frame.CopyFrameDataToIntPtr(DepthData.AddrOfPinnedObject(), (uint)_Buffer.Length * sizeof(ushort));
DepthData.Free(); DepthData.Free();
IsValid = true;
} }
} }
public void CopyData(ushort[] buffer) public ushort[] GetData()
{ {
if (IsValid) return _Buffer;
Array.Copy(_Buffer, buffer, _Buffer.Length);
} }
} }
} }
\ No newline at end of file
...@@ -4,60 +4,35 @@ namespace KinectModule ...@@ -4,60 +4,35 @@ namespace KinectModule
{ {
public class RealMultiSourceFrame : IMultiSourceFrame public class RealMultiSourceFrame : IMultiSourceFrame
{ {
RealColorFrame _ColorFrame;
RealBodyIndexFrame _BodyIndexFrame;
RealDepthFrame _DepthFrame;
RealBodyFrame _BodyFrame;
public IColorFrame LastColorFrame public IColorFrame LastColorFrame
{ { get; private set; }
get
{
return _ColorFrame;
}
}
public IBodyIndexFrame LastBodyIndexFrame public IBodyIndexFrame LastBodyIndexFrame
{ { get; private set; }
get
{
return _BodyIndexFrame;
}
}
public IDepthFrame LastDepthFrame public IDepthFrame LastDepthFrame
{ { get; private set; }
get
{
return _DepthFrame;
}
}
public IBodyFrame LastBodyFrame public IBodyFrame LastBodyFrame
{ { get; private set; }
get
{
return _BodyFrame;
}
}
public RealMultiSourceFrame(MultiSourceFrame sourceFrame) public RealMultiSourceFrame(MultiSourceFrame sourceFrame)
{ {
if (sourceFrame == null) if (sourceFrame == null)
{ {
_ColorFrame = new RealColorFrame (null); LastColorFrame = new RealColorFrame (null);
_BodyIndexFrame = new RealBodyIndexFrame(null); LastBodyIndexFrame = new RealBodyIndexFrame(null);
_DepthFrame = new RealDepthFrame (null); LastDepthFrame = new RealDepthFrame (null);
_BodyFrame = new RealBodyFrame (null); LastBodyFrame = new RealBodyFrame (null);
return; return;
} }
using (var colorFrame = sourceFrame.ColorFrameReference .AcquireFrame()) using (var colorFrame = sourceFrame.ColorFrameReference .AcquireFrame())
_ColorFrame = new RealColorFrame (colorFrame); LastColorFrame = new RealColorFrame (colorFrame);
using (var bodyIndexFrame = sourceFrame.BodyIndexFrameReference.AcquireFrame()) using (var bodyIndexFrame = sourceFrame.BodyIndexFrameReference.AcquireFrame())
_BodyIndexFrame = new RealBodyIndexFrame(bodyIndexFrame); LastBodyIndexFrame = new RealBodyIndexFrame(bodyIndexFrame);
using (var depthFrame = sourceFrame.DepthFrameReference .AcquireFrame()) using (var depthFrame = sourceFrame.DepthFrameReference .AcquireFrame())
_DepthFrame = new RealDepthFrame (depthFrame); LastDepthFrame = new RealDepthFrame (depthFrame);
using (var bodyFrame = sourceFrame.BodyFrameReference .AcquireFrame()) using (var bodyFrame = sourceFrame.BodyFrameReference .AcquireFrame())
_BodyFrame = new RealBodyFrame (bodyFrame); LastBodyFrame = new RealBodyFrame (bodyFrame);
} }
} }
} }
\ No newline at end of file
...@@ -2,50 +2,33 @@ ...@@ -2,50 +2,33 @@
{ {
public class SourceBuffer public class SourceBuffer
{ {
private byte[] _ColorBuffer = new byte [KinectConstants.ColorWidth * public byte[] ColorBuffer
KinectConstants.ColorHeight * { get; private set; }
KinectConstants.ColorCount], public byte[] BodyIndexBuffer
_BodyIndexBuffer = new byte [KinectConstants.DepthWidth * { get; private set; }
KinectConstants.DepthHeight];
private ushort[] _DepthBuffer = new ushort[KinectConstants.DepthWidth *
KinectConstants.DepthHeight];
private IBody[] _BodyBuffer = new IBody [KinectConstants.BodyCount];
public byte[] ColorBuffer
{
get
{
return _ColorBuffer;
}
}
public byte[] BodyIndexBuffer
{
get
{
return _BodyIndexBuffer;
}
}
public ushort[] DepthBuffer public ushort[] DepthBuffer
{ get; private set; }
public IBody[] BodyBuffer
{ get; private set; }
public SourceBuffer()
{ {
get ColorBuffer = new byte [KinectConstants.ColorWidth *
{ KinectConstants.ColorHeight *
return _DepthBuffer; KinectConstants.ColorCount];
} BodyIndexBuffer = new byte [KinectConstants.DepthWidth *
} KinectConstants.DepthHeight];
public IBody[] BodyBuffer DepthBuffer = new ushort[KinectConstants.DepthWidth *
{ KinectConstants.DepthHeight];
get BodyBuffer = new IBody [KinectConstants.BodyCount];
{
return _BodyBuffer;
}
} }
public void UpdateBuffers(IMultiSourceFrame sourceFrame) public void UpdateBuffers(IMultiSourceFrame sourceFrame)
{ {
sourceFrame.LastColorFrame .CopyData(_ColorBuffer); ColorBuffer = sourceFrame.LastColorFrame .GetData();
sourceFrame.LastBodyIndexFrame.CopyData(_BodyIndexBuffer); BodyIndexBuffer = sourceFrame.LastBodyIndexFrame.GetData();
sourceFrame.LastDepthFrame .CopyData(_DepthBuffer); DepthBuffer = sourceFrame.LastDepthFrame .GetData();
sourceFrame.LastBodyFrame .CopyData(_BodyBuffer); BodyBuffer = sourceFrame.LastBodyFrame .GetData();
} }
} }
} }
\ No newline at end of file
using System.Linq; using KinectModule;
using System.Linq;
using Windows.Kinect; using Windows.Kinect;
namespace MotionAnalysis namespace MotionAnalysis
...@@ -12,7 +13,7 @@ namespace MotionAnalysis ...@@ -12,7 +13,7 @@ namespace MotionAnalysis
public bool IsPreseted public bool IsPreseted
{ get; private set; } { get; private set; }
public void Preset(KinectModule.IBody body) public void Preset(IBody body)
{ {
IsPreseted = false; IsPreseted = false;
...@@ -26,14 +27,15 @@ namespace MotionAnalysis ...@@ -26,14 +27,15 @@ namespace MotionAnalysis
} }
} }
private bool HaveKneeJoint(KinectModule.IBody body) private bool HaveKneeJoint(IBody body)
{ {
return body != null && return body != null &&
body.Joints != null &&
body.Joints.ContainsKey(JointType.KneeLeft) && body.Joints.ContainsKey(JointType.KneeLeft) &&
body.Joints.ContainsKey(JointType.KneeRight); body.Joints.ContainsKey(JointType.KneeRight);
} }
private float ComputeKneeMean(KinectModule.IBody body) private float ComputeKneeMean(IBody body)
{ {
return body.Joints.Where(x => x.Key == JointType.KneeLeft || return body.Joints.Where(x => x.Key == JointType.KneeLeft ||
x.Key == JointType.KneeRight) x.Key == JointType.KneeRight)
...@@ -46,7 +48,7 @@ namespace MotionAnalysis ...@@ -46,7 +48,7 @@ namespace MotionAnalysis
Motion = MotionState.UNKNOWN; Motion = MotionState.UNKNOWN;
} }
public void Update(KinectModule.IBody body) public void Update(IBody body)
{ {
Extractor.Extract(body); Extractor.Extract(body);
......
...@@ -4,7 +4,7 @@ using Windows.Kinect; ...@@ -4,7 +4,7 @@ using Windows.Kinect;
public class CoordinateMapperView : MonoBehaviour public class CoordinateMapperView : MonoBehaviour
{ {
private GameObject manager; private CoordinateMapperManager manager;
private ComputeBuffer DepthBuffer, private ComputeBuffer DepthBuffer,
BodyIndexBuffer; BodyIndexBuffer;
...@@ -14,16 +14,16 @@ public class CoordinateMapperView : MonoBehaviour ...@@ -14,16 +14,16 @@ public class CoordinateMapperView : MonoBehaviour
void Start () void Start ()
{ {
var CoordinateMapperManager = GameObject.Find("InGameManagers").GetComponent<CoordinateMapperManager>(); manager = GameObject.Find("InGameManagers").GetComponent<CoordinateMapperManager>();
var material = GetComponent<Renderer>().material; var material = GetComponent<Renderer>().material;
material.SetTexture("_MainTex", CoordinateMapperManager.ColorTexture); material.SetTexture("_MainTex", manager.ColorTexture);
DepthBuffer = GenerateBuffer("depthCoordinates", sizeof(float) * 2, DepthBuffer = GenerateBuffer("depthCoordinates", sizeof(float) * 2,
(DepthPoints = CoordinateMapperManager.DepthCoordinates), material); manager.DepthCoordinates, material);
BodyIndexBuffer = GenerateBuffer("BodyIndexBuffer", sizeof(float), BodyIndexBuffer = GenerateBuffer("BodyIndexBuffer", sizeof(float),
(BodyIndexPoints = CoordinateMapperManager.BodyIndexBuffer), material); manager.BodyIndexBuffer, material);
} }
ComputeBuffer GenerateBuffer(string name, int stride, Array points, Material material) ComputeBuffer GenerateBuffer(string name, int stride, Array points, Material material)
...@@ -35,12 +35,10 @@ public class CoordinateMapperView : MonoBehaviour ...@@ -35,12 +35,10 @@ public class CoordinateMapperView : MonoBehaviour
void Update() void Update()
{ {
//TODO: fix perf on this call. //TODO: fix perf on this call.
DepthBuffer.SetData(DepthPoints); DepthBuffer.SetData(manager.DepthCoordinates);
BodyIndexBuffer.SetData(Array.ConvertAll(BodyIndexPoints, Convert.ToSingle)); BodyIndexBuffer.SetData(Array.ConvertAll(manager.BodyIndexBuffer, Convert.ToSingle));
} }
void OnDisable() void OnDisable()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment