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