Commit 36e20b59 authored by 16이상민's avatar 16이상민

Change the class extraction method: Extract Module -> Extract Class

Complete tests for class 'SourceBuffer'
parent c6acafe4
using UnityEngine; using UnityEngine.TestTools;
using UnityEditor;
using UnityEngine.TestTools;
using NUnit.Framework; using NUnit.Framework;
using System.Collections; using System.Collections;
using Windows.Kinect; using Windows.Kinect;
...@@ -8,10 +6,7 @@ using System.Runtime.InteropServices; ...@@ -8,10 +6,7 @@ using System.Runtime.InteropServices;
public class SourceBufferTests public class SourceBufferTests
{ {
const int DepthWidth = 512, SourceBuffer _SourceBuffer = new SourceBuffer();
DepthHeight = 424,
ColorWidth = 1920,
ColorHeight = 1080;
[Test] [Test]
public void SourceBufferTestsSimplePasses() public void SourceBufferTestsSimplePasses()
...@@ -34,9 +29,10 @@ public class SourceBufferTests ...@@ -34,9 +29,10 @@ public class SourceBufferTests
var sourceFrame = sourceFrameReader.AcquireLatestFrame(); var sourceFrame = sourceFrameReader.AcquireLatestFrame();
SourceBuffer.UpdateBuffers(sourceFrame); _SourceBuffer.UpdateBuffers(sourceFrame);
ColorBufferTest(sourceFrame); ColorBufferTest(sourceFrame);
BodyIndexBufferTest(sourceFrame);
} }
sensor.Close(); sensor.Close();
...@@ -44,7 +40,7 @@ public class SourceBufferTests ...@@ -44,7 +40,7 @@ public class SourceBufferTests
private void ColorBufferTest(MultiSourceFrame sourceFrame) private void ColorBufferTest(MultiSourceFrame sourceFrame)
{ {
var colorBuffer = new byte[ColorWidth * ColorHeight * 4]; var colorBuffer = new byte[SourceBuffer.ColorWidth * SourceBuffer.ColorHeight * 4];
using (var colorFrame = sourceFrame.ColorFrameReference.AcquireFrame()) using (var colorFrame = sourceFrame.ColorFrameReference.AcquireFrame())
if (colorFrame != null) if (colorFrame != null)
{ {
...@@ -53,7 +49,45 @@ public class SourceBufferTests ...@@ -53,7 +49,45 @@ public class SourceBufferTests
ColorData.Free(); ColorData.Free();
} }
Assert.AreEqual(colorBuffer, SourceBuffer.ColorBuffer, "ColorBufferTest failed."); Assert.AreEqual(colorBuffer, _SourceBuffer.ColorBuffer, "ColorBufferTest failed.");
}
private void BodyIndexBufferTest(MultiSourceFrame sourceFrame)
{
var bodyIndexBuffer = new byte[SourceBuffer.DepthWidth * SourceBuffer.DepthHeight];
using (var bodyIndexFrame = sourceFrame.BodyIndexFrameReference.AcquireFrame())
if (bodyIndexFrame != null)
{
var BodyIndexData = GCHandle.Alloc(bodyIndexBuffer, GCHandleType.Pinned);
bodyIndexFrame.CopyFrameDataToIntPtr(BodyIndexData.AddrOfPinnedObject(), (uint)bodyIndexBuffer.Length);
BodyIndexData.Free();
}
Assert.AreEqual(bodyIndexBuffer, _SourceBuffer.BodyIndexBuffer, "BodyIndexBufferTest failed.");
}
private void UpdateDepthBuffer(MultiSourceFrame sourceFrame)
{
var depthBuffer = new ushort[SourceBuffer.DepthWidth * SourceBuffer.DepthHeight];
using (var depthFrame = sourceFrame.DepthFrameReference.AcquireFrame())
if (depthFrame != null)
{
var DepthData = GCHandle.Alloc(depthBuffer, GCHandleType.Pinned);
depthFrame.CopyFrameDataToIntPtr(DepthData.AddrOfPinnedObject(), (uint)depthBuffer.Length * sizeof(ushort));
DepthData.Free();
}
Assert.AreEqual(depthBuffer, _SourceBuffer.DepthBuffer, "DepthBufferTest failed.");
}
private void UpdateBodyBuffer(MultiSourceFrame sourceFrame)
{
var bodyBuffer = new Body[SourceBuffer.BodyCount];
using (var bodyFrame = sourceFrame.BodyFrameReference.AcquireFrame())
if (bodyFrame != null)
bodyFrame.GetAndRefreshBodyData(bodyBuffer);
Assert.AreEqual(bodyBuffer, _SourceBuffer.BodyBuffer, "BodyBufferTest failed.");
} }
// A UnityTest behaves like a coroutine in PlayMode // A UnityTest behaves like a coroutine in PlayMode
......
fileFormatVersion: 2 fileFormatVersion: 2
guid: 85bafbe9b14b18b45b445b304b1f3efc guid: 85bafbe9b14b18b45b445b304b1f3efc
PluginImporter: PluginImporter:
externalObjects: {}
serializedVersion: 2 serializedVersion: 2
iconMap: {} iconMap: {}
executionOrder: {} executionOrder: {}
isPreloaded: 0 isPreloaded: 0
isOverridable: 0 isOverridable: 0
platformData: platformData:
data: - first:
first: '': Any
Any:
second: second:
enabled: 0 enabled: 0
settings:
Exclude Editor: 1
Exclude Linux: 1
Exclude Linux64: 1
Exclude LinuxUniversal: 1
Exclude OSXUniversal: 1
Exclude Win: 1
Exclude Win64: 1
- first:
Any:
second:
enabled: 1
settings: {} settings: {}
data: - first:
first:
Editor: Editor Editor: Editor
second: second:
enabled: 0 enabled: 0
settings: settings:
CPU: AnyCPU
DefaultValueInitialized: true DefaultValueInitialized: true
data: OS: AnyOS
first: - first:
Facebook: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Facebook: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Linux
second:
enabled: 0
settings:
CPU: x86
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: x86_64
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Windows Store Apps: WindowsStoreApps Windows Store Apps: WindowsStoreApps
second: second:
enabled: 1 enabled: 1
......
fileFormatVersion: 2 fileFormatVersion: 2
guid: 40e0d3de9df769b42b6ae91ec22df21e guid: 40e0d3de9df769b42b6ae91ec22df21e
folderAsset: yes folderAsset: yes
timeCreated: 1503553766 timeCreated: 1515256762
licenseType: Free licenseType: Free
DefaultImporter: DefaultImporter:
externalObjects: {}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
fileFormatVersion: 2 fileFormatVersion: 2
guid: 82e143d16729051459ae6a54b37e9eab guid: 82e143d16729051459ae6a54b37e9eab
timeCreated: 1515256762
licenseType: Free
PluginImporter: PluginImporter:
externalObjects: {}
serializedVersion: 2 serializedVersion: 2
iconMap: {} iconMap: {}
executionOrder: {} executionOrder: {}
isPreloaded: 0 isPreloaded: 0
isOverridable: 0 isOverridable: 0
platformData: platformData:
data: - first:
first: '': OSXIntel
second:
enabled: 0
settings:
CPU: None
- first:
'': OSXIntel64
second:
enabled: 1
settings:
CPU: AnyCPU
- first:
Any: Any:
second: second:
enabled: 1 enabled: 1
settings: {} settings: {}
data: - first:
first:
Editor: Editor Editor: Editor
second: second:
enabled: 0 enabled: 0
settings: settings:
CPU: x86_64 CPU: x86_64
DefaultValueInitialized: true DefaultValueInitialized: true
data: - first:
first:
Facebook: Win Facebook: Win
second: second:
enabled: 0 enabled: 0
settings: settings:
CPU: None CPU: None
data: - first:
first:
Facebook: Win64 Facebook: Win64
second: second:
enabled: 1 enabled: 1
settings: settings:
CPU: AnyCPU CPU: AnyCPU
data: - first:
first:
Standalone: Linux Standalone: Linux
second: second:
enabled: 0 enabled: 0
settings: settings:
CPU: None CPU: None
data: - first:
first:
Standalone: Linux64 Standalone: Linux64
second: second:
enabled: 1 enabled: 1
settings: settings:
CPU: x86_64 CPU: x86_64
data: - first:
first:
Standalone: LinuxUniversal Standalone: LinuxUniversal
second: second:
enabled: 1 enabled: 1
settings: settings:
CPU: x86_64 CPU: x86_64
data: - first:
first:
Standalone: OSXIntel
second:
enabled: 0
settings:
CPU: None
data:
first:
Standalone: OSXIntel64
second:
enabled: 1
settings:
CPU: AnyCPU
data:
first:
Standalone: OSXUniversal Standalone: OSXUniversal
second: second:
enabled: 0 enabled: 0
settings: settings:
CPU: x86_64 CPU: x86_64
data: - first:
first:
Standalone: Win Standalone: Win
second: second:
enabled: 0 enabled: 0
settings: settings:
CPU: None CPU: None
data: - first:
first:
Standalone: Win64 Standalone: Win64
second: second:
enabled: 1 enabled: 1
......
...@@ -9,8 +9,7 @@ public class CoordinateMapperManager : MonoBehaviour ...@@ -9,8 +9,7 @@ public class CoordinateMapperManager : MonoBehaviour
private MultiSourceFrameReader _SourceFrameReader; private MultiSourceFrameReader _SourceFrameReader;
private DepthSpacePoint[] _DepthCoordinates; private DepthSpacePoint[] _DepthCoordinates;
const int ColorWidth = 1920; private SourceBuffer _SourceBuffer;
const int ColorHeight = 1080;
long frameCount = 0; long frameCount = 0;
...@@ -24,17 +23,17 @@ public class CoordinateMapperManager : MonoBehaviour ...@@ -24,17 +23,17 @@ public class CoordinateMapperManager : MonoBehaviour
public Texture2D ColorTexture public Texture2D ColorTexture
{ get { return _ColorRGBX; } } { get { return _ColorRGBX; } }
public byte[] BodyIndexBuffer public byte[] BodyIndexBuffer
{ get { return SourceBuffer.BodyIndexBuffer; } } { get { return _SourceBuffer.BodyIndexBuffer; } }
public DepthSpacePoint[] DepthCoordinates public DepthSpacePoint[] DepthCoordinates
{ get { return _DepthCoordinates; } } { get { return _DepthCoordinates; } }
public Body[] BodyBuffer public Body[] BodyBuffer
{ get { return SourceBuffer.BodyBuffer; } } { get { return _SourceBuffer.BodyBuffer; } }
void Awake() void Awake()
{ {
_ColorRGBX = new Texture2D (ColorWidth, ColorHeight, TextureFormat.RGBA32, false); _ColorRGBX = new Texture2D (SourceBuffer.ColorWidth, SourceBuffer.ColorHeight, TextureFormat.RGBA32, false);
_DepthCoordinates = new DepthSpacePoint[ColorWidth * ColorHeight]; _DepthCoordinates = new DepthSpacePoint[SourceBuffer.ColorWidth * SourceBuffer.ColorHeight];
InitializeDefaultSensor (); InitializeDefaultSensor ();
} }
...@@ -76,19 +75,19 @@ public class CoordinateMapperManager : MonoBehaviour ...@@ -76,19 +75,19 @@ public class CoordinateMapperManager : MonoBehaviour
void ProcessFrame() void ProcessFrame()
{ {
var DepthData = GCHandle.Alloc(SourceBuffer.DepthBuffer, GCHandleType.Pinned); var DepthData = GCHandle.Alloc(_SourceBuffer.DepthBuffer, GCHandleType.Pinned);
var pDepthCoordinatesData = GCHandle.Alloc(_DepthCoordinates, GCHandleType.Pinned); var pDepthCoordinatesData = GCHandle.Alloc(_DepthCoordinates, GCHandleType.Pinned);
_CoordinateMapper.MapColorFrameToDepthSpaceUsingIntPtr( _CoordinateMapper.MapColorFrameToDepthSpaceUsingIntPtr(
DepthData.AddrOfPinnedObject(), DepthData.AddrOfPinnedObject(),
(uint)SourceBuffer.DepthBuffer.Length * sizeof(ushort), (uint)_SourceBuffer.DepthBuffer.Length * sizeof(ushort),
pDepthCoordinatesData.AddrOfPinnedObject(), pDepthCoordinatesData.AddrOfPinnedObject(),
(uint)_DepthCoordinates.Length); (uint)_DepthCoordinates.Length);
pDepthCoordinatesData.Free(); pDepthCoordinatesData.Free();
DepthData.Free(); DepthData.Free();
_ColorRGBX.LoadRawTextureData(SourceBuffer.ColorBuffer); _ColorRGBX.LoadRawTextureData(_SourceBuffer.ColorBuffer);
_ColorRGBX.Apply(); _ColorRGBX.Apply();
} }
...@@ -115,7 +114,7 @@ public class CoordinateMapperManager : MonoBehaviour ...@@ -115,7 +114,7 @@ public class CoordinateMapperManager : MonoBehaviour
if ((nullFrame = sourceFrame == null)) if ((nullFrame = sourceFrame == null))
return; return;
SourceBuffer.UpdateBuffers(sourceFrame); _SourceBuffer.UpdateBuffers(sourceFrame);
ProcessFrame(); ProcessFrame();
} }
...@@ -138,28 +137,29 @@ public class CoordinateMapperManager : MonoBehaviour ...@@ -138,28 +137,29 @@ public class CoordinateMapperManager : MonoBehaviour
} }
} }
public static class SourceBuffer public class SourceBuffer
{ {
private const int DepthWidth = 512; public const int DepthWidth = 512;
private const int DepthHeight = 424; public const int DepthHeight = 424;
public const int ColorWidth = 1920; public const int ColorWidth = 1920;
public const int ColorHeight = 1080; public const int ColorHeight = 1080;
public const int BodyCount = 6;
static private byte[] _ColorBuffer = new byte[ColorWidth * ColorHeight * 4], private byte[] _ColorBuffer = new byte[ColorWidth * ColorHeight * 4],
_BodyIndexBuffer = new byte[DepthWidth * DepthHeight]; _BodyIndexBuffer = new byte[DepthWidth * DepthHeight];
static private ushort[] _DepthBuffer = new ushort[DepthWidth * DepthHeight]; private ushort[] _DepthBuffer = new ushort[DepthWidth * DepthHeight];
private static Body[] _BodyBuffer = new Body[6]; private Body[] _BodyBuffer = new Body[BodyCount];
public static byte[] ColorBuffer public byte[] ColorBuffer
{ get { return _ColorBuffer; } } { get { return _ColorBuffer; } }
public static byte[] BodyIndexBuffer public byte[] BodyIndexBuffer
{ get { return _BodyIndexBuffer; } } { get { return _BodyIndexBuffer; } }
public static ushort[] DepthBuffer public ushort[] DepthBuffer
{ get { return _DepthBuffer; } } { get { return _DepthBuffer; } }
public static Body[] BodyBuffer public Body[] BodyBuffer
{ get { return _BodyBuffer; } } { get { return _BodyBuffer; } }
public static void UpdateBuffers(MultiSourceFrame sourceFrame) public void UpdateBuffers(MultiSourceFrame sourceFrame)
{ {
UpdateColorBuffer (sourceFrame); UpdateColorBuffer (sourceFrame);
UpdateBodyIndexBuffer(sourceFrame); UpdateBodyIndexBuffer(sourceFrame);
...@@ -167,7 +167,7 @@ public static class SourceBuffer ...@@ -167,7 +167,7 @@ public static class SourceBuffer
UpdateBodyBuffer (sourceFrame); UpdateBodyBuffer (sourceFrame);
} }
private static void UpdateColorBuffer(MultiSourceFrame sourceFrame) private void UpdateColorBuffer(MultiSourceFrame sourceFrame)
{ {
using (var colorFrame = sourceFrame.ColorFrameReference.AcquireFrame()) using (var colorFrame = sourceFrame.ColorFrameReference.AcquireFrame())
if (colorFrame != null) if (colorFrame != null)
...@@ -178,7 +178,7 @@ public static class SourceBuffer ...@@ -178,7 +178,7 @@ public static class SourceBuffer
} }
} }
private static void UpdateBodyIndexBuffer(MultiSourceFrame sourceFrame) private void UpdateBodyIndexBuffer(MultiSourceFrame sourceFrame)
{ {
using (var bodyIndexFrame = sourceFrame.BodyIndexFrameReference.AcquireFrame()) using (var bodyIndexFrame = sourceFrame.BodyIndexFrameReference.AcquireFrame())
if (bodyIndexFrame != null) if (bodyIndexFrame != null)
...@@ -189,7 +189,7 @@ public static class SourceBuffer ...@@ -189,7 +189,7 @@ public static class SourceBuffer
} }
} }
private static void UpdateDepthBuffer(MultiSourceFrame sourceFrame) private void UpdateDepthBuffer(MultiSourceFrame sourceFrame)
{ {
using (var depthFrame = sourceFrame.DepthFrameReference.AcquireFrame()) using (var depthFrame = sourceFrame.DepthFrameReference.AcquireFrame())
if (depthFrame != null) if (depthFrame != null)
...@@ -200,7 +200,7 @@ public static class SourceBuffer ...@@ -200,7 +200,7 @@ public static class SourceBuffer
} }
} }
private static void UpdateBodyBuffer(MultiSourceFrame sourceFrame) private void UpdateBodyBuffer(MultiSourceFrame sourceFrame)
{ {
using (var bodyFrame = sourceFrame.BodyFrameReference.AcquireFrame()) using (var bodyFrame = sourceFrame.BodyFrameReference.AcquireFrame())
if (bodyFrame != null) if (bodyFrame != null)
......
...@@ -258,7 +258,10 @@ PlayerSettings: ...@@ -258,7 +258,10 @@ PlayerSettings:
resolutionDialogBanner: {fileID: 0} resolutionDialogBanner: {fileID: 0}
m_BuildTargetIcons: [] m_BuildTargetIcons: []
m_BuildTargetBatching: [] m_BuildTargetBatching: []
m_BuildTargetGraphicsAPIs: [] m_BuildTargetGraphicsAPIs:
- m_BuildTarget: WindowsStandaloneSupport
m_APIs: 02000000
m_Automatic: 1
m_BuildTargetVRSettings: [] m_BuildTargetVRSettings: []
m_BuildTargetEnableVuforiaSettings: [] m_BuildTargetEnableVuforiaSettings: []
openGLRequireES31: 0 openGLRequireES31: 0
......
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