Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
ButtonPusher
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Button Pusher
ButtonPusher
Commits
857647e9
Commit
857647e9
authored
Jan 09, 2018
by
16이상민
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Edit test: SourceBufferTests, I wrote the test in a completely incorrect way :(
parent
f21dfc57
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
430 additions
and
173 deletions
+430
-173
KinectAccessManagerTests.cs
Assets/Editor/KinectAccessManagerTests.cs
+0
-10
SourceBufferTests.cs
Assets/Editor/SourceBufferTests.cs
+92
-61
CoordinateMapperManager.cs
Assets/Script/CoordinateMapperManager.cs
+208
-76
CoordinateMapperView.cs
Assets/Script/CoordinateMapperView.cs
+9
-18
MotionView.cs
Assets/Script/MotionView.cs
+7
-7
Tests.meta
Assets/Script/Tests.meta
+10
-0
CoordinateMapperManagerTests.cs
Assets/Script/Tests/CoordinateMapperManagerTests.cs
+30
-0
CoordinateMapperManagerTests.cs.meta
Assets/Script/Tests/CoordinateMapperManagerTests.cs.meta
+13
-0
CoordinateMapperViewTests.cs
Assets/Script/Tests/CoordinateMapperViewTests.cs
+47
-0
CoordinateMapperViewTests.cs.meta
Assets/Script/Tests/CoordinateMapperViewTests.cs.meta
+13
-0
ProjectSettings.asset
ProjectSettings/ProjectSettings.asset
+1
-1
No files found.
Assets/Editor/KinectAccessManagerTests.cs
View file @
857647e9
...
@@ -18,14 +18,4 @@ public class KinectAccessManagerTests
...
@@ -18,14 +18,4 @@ public class KinectAccessManagerTests
_KinectAccessManager
.
Dispose
();
_KinectAccessManager
.
Dispose
();
Assert
.
IsFalse
(
_KinectAccessManager
.
IsAccess
,
"Kinect Dispose Error."
);
Assert
.
IsFalse
(
_KinectAccessManager
.
IsAccess
,
"Kinect Dispose Error."
);
}
}
// A UnityTest behaves like a coroutine in PlayMode
// and allows you to yield null to skip a frame in EditMode
[
UnityTest
]
public
IEnumerator
KinectAccessManagerTestsWithEnumeratorPasses
()
{
// Use the Assert class to test conditions.
// yield to skip a frame
yield
return
null
;
}
}
}
Assets/Editor/SourceBufferTests.cs
View file @
857647e9
...
@@ -4,90 +4,121 @@ using System.Collections;
...
@@ -4,90 +4,121 @@ using System.Collections;
using
Windows.Kinect
;
using
Windows.Kinect
;
using
System.Runtime.InteropServices
;
using
System.Runtime.InteropServices
;
using
KinectModule
;
using
KinectModule
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System
;
// To test the update function and the updated buffer, you need a stub for the source frame class.
public
class
SourceBufferTests
public
class
SourceBufferTests
{
{
KinectAccessManager
_KinectAccessManager
=
new
KinectAccessManager
();
[
Test
]
SourceBuffer
_SourceBuffer
=
new
SourceBuffer
();
public
void
ColorBuffer_NotEqual_Null
()
{
var
obj
=
new
SourceBuffer
();
var
expected
=
null
as
byte
[];
var
actual
=
obj
.
ColorBuffer
;
Assert
.
AreNotEqual
(
expected
,
actual
,
"ColorBuffer should not be null value."
);
}
[
Test
]
[
Test
]
public
void
SourceBufferTestsSimplePasses
()
public
void
BodyIndexBuffer_NotEqual_Null
()
{
{
// Use the Assert class to test conditions.
var
obj
=
new
SourceBuffer
();
var
expected
=
null
as
byte
[];
var
actual
=
obj
.
BodyIndexBuffer
;
_KinectAccessManager
.
Access
(
);
Assert
.
AreNotEqual
(
expected
,
actual
,
"BodyIndexBuffer should not be null value."
);
Assert
.
IsTrue
(
_KinectAccessManager
.
IsAccess
,
"Kinect Access Error."
);
}
var
sourceFrame
=
_KinectAccessManager
.
SourceFrame
;
[
Test
]
_SourceBuffer
.
UpdateBuffers
(
sourceFrame
);
public
void
DepthBuffer_NotEqual_Null
()
{
var
obj
=
new
SourceBuffer
();
ColorBufferTest
(
sourceFrame
);
var
expected
=
null
as
ushort
[];
BodyIndexBufferTest
(
sourceFrame
);
var
actual
=
obj
.
DepthBuffer
;
DepthBufferTest
(
sourceFrame
);
BodyBufferTest
(
sourceFrame
);
_KinectAccessManager
.
Dispose
(
);
Assert
.
AreNotEqual
(
expected
,
actual
,
"DepthBuffer should not be null value."
);
}
}
private
void
ColorBufferTest
(
MultiSourceFrame
sourceFrame
)
[
Test
]
public
void
BodyBuffer_NotEqual_Null
()
{
{
var
colorBuffer
=
new
byte
[
SourceBuffer
.
ColorWidth
*
SourceBuffer
.
ColorHeight
*
4
];
var
obj
=
new
SourceBuffer
();
using
(
var
colorFrame
=
sourceFrame
.
ColorFrameReference
.
AcquireFrame
())
if
(
colorFrame
!=
null
)
var
expected
=
null
as
Body
[];
{
var
actual
=
obj
.
BodyBuffer
;
var
ColorData
=
GCHandle
.
Alloc
(
colorBuffer
,
GCHandleType
.
Pinned
);
colorFrame
.
CopyConvertedFrameDataToIntPtr
(
ColorData
.
AddrOfPinnedObject
(),
(
uint
)
colorBuffer
.
Length
,
ColorImageFormat
.
Rgba
);
Assert
.
AreNotEqual
(
expected
,
actual
,
"BodyBuffer should not be null value."
);
ColorData
.
Free
();
}
Assert
.
AreEqual
(
colorBuffer
,
_SourceBuffer
.
ColorBuffer
,
"ColorBufferTest failed."
);
}
}
private
void
BodyIndexBufferTest
(
MultiSourceFrame
sourceFrame
)
[
Test
]
public
void
ColorBuffer_Equal_Green
()
{
{
var
bodyIndexBuffer
=
new
byte
[
SourceBuffer
.
DepthWidth
*
SourceBuffer
.
DepthHeight
];
var
frame
=
new
GreenFrameStub
();
using
(
var
bodyIndexFrame
=
sourceFrame
.
BodyIndexFrameReference
.
AcquireFrame
())
if
(
bodyIndexFrame
!=
null
)
var
obj
=
new
SourceBuffer
();
{
obj
.
UpdateBuffers
(
frame
);
var
BodyIndexData
=
GCHandle
.
Alloc
(
bodyIndexBuffer
,
GCHandleType
.
Pinned
);
bodyIndexFrame
.
CopyFrameDataToIntPtr
(
BodyIndexData
.
AddrOfPinnedObject
(),
(
uint
)
bodyIndexBuffer
.
Length
);
var
expected
=
new
byte
[
KinectConstants
.
ColorWidth
*
BodyIndexData
.
Free
();
KinectConstants
.
ColorHeight
*
}
KinectConstants
.
ColorCount
];
frame
.
LastColorFrame
.
CopyData
(
expected
);
Assert
.
AreEqual
(
bodyIndexBuffer
,
_SourceBuffer
.
BodyIndexBuffer
,
"BodyIndexBufferTest failed."
);
var
actual
=
obj
.
ColorBuffer
;
Assert
.
AreEqual
(
expected
,
actual
,
"Colorbuffer should be filled with green."
);
}
}
}
public
class
GreenFrameStub
:
IMultiSourceFrame
{
private
GreenColorFrameStub
_ColorFrame
=
new
GreenColorFrameStub
();
private
BodyIndexFrameDummy
_BodyIndexFrame
=
new
BodyIndexFrameDummy
();
private
DepthFrameDummy
_DepthFrame
=
new
DepthFrameDummy
();
private
BodyFrameDummy
_BodyFrame
=
new
BodyFrameDummy
();
private
void
DepthBufferTest
(
MultiSourceFrame
sourceFrame
)
public
IColorFrame
LastColorFrame
{
get
{
return
_ColorFrame
;
}
}
public
IBodyIndexFrame
LastBodyIndexFrame
{
get
{
return
_BodyIndexFrame
;
}
}
public
IDepthFrame
LastDepthFrame
{
get
{
return
_DepthFrame
;
}
}
public
IBodyFrame
LastBodyFrame
{
get
{
return
_BodyFrame
;
}
}
private
class
GreenColorFrameStub
:
IColorFrame
{
{
var
depthBuffer
=
new
ushort
[
SourceBuffer
.
DepthWidth
*
SourceBuffer
.
DepthHeight
];
private
static
uint
[]
data
=
using
(
var
depthFrame
=
sourceFrame
.
DepthFrameReference
.
AcquireFrame
())
Enumerable
.
Repeat
<
uint
>(
0x00FF00FF
,
if
(
depthFrame
!=
null
)
KinectConstants
.
ColorWidth
*
{
KinectConstants
.
ColorHeight
).
ToArray
<
uint
>();
var
DepthData
=
GCHandle
.
Alloc
(
depthBuffer
,
GCHandleType
.
Pinned
);
depthFrame
.
CopyFrameDataToIntPtr
(
DepthData
.
AddrOfPinnedObject
(),
(
uint
)
depthBuffer
.
Length
*
sizeof
(
ushort
));
public
void
CopyData
(
byte
[]
buffer
)
DepthData
.
Free
();
{
}
Buffer
.
BlockCopy
(
buffer
,
0
,
data
,
0
,
buffer
.
Length
);
}
Assert
.
AreEqual
(
depthBuffer
,
_SourceBuffer
.
DepthBuffer
,
"DepthBufferTest failed."
);
}
}
private
void
BodyBufferTest
(
MultiSourceFrame
sourceFrame
)
private
class
BodyIndexFrameDummy
:
IBodyIndexFrame
{
{
var
bodyBuffer
=
new
Body
[
SourceBuffer
.
BodyCount
];
public
void
CopyData
(
byte
[]
buffer
)
using
(
var
bodyFrame
=
sourceFrame
.
BodyFrameReference
.
AcquireFrame
())
{
}
if
(
bodyFrame
!=
null
)
}
bodyFrame
.
GetAndRefreshBodyData
(
bodyBuffer
);
Assert
.
AreEqual
(
bodyBuffer
,
_SourceBuffer
.
BodyBuffer
,
"BodyBufferTest failed."
);
private
class
DepthFrameDummy
:
IDepthFrame
{
public
void
CopyData
(
ushort
[]
buffer
)
{
}
}
}
// A UnityTest behaves like a coroutine in PlayMode
private
class
BodyFrameDummy
:
IBodyFrame
// and allows you to yield null to skip a frame in EditMode
[
UnityTest
]
public
IEnumerator
SourceBufferTestsWithEnumeratorPasses
()
{
{
// Use the Assert class to test conditions.
public
void
CopyData
(
Body
[]
buffer
)
// yield to skip a frame
{
}
yield
return
null
;
}
}
}
}
\ No newline at end of file
Assets/Script/CoordinateMapperManager.cs
View file @
857647e9
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
using
Windows.Kinect
;
using
Windows.Kinect
;
using
System.Runtime.InteropServices
;
using
System.Runtime.InteropServices
;
using
System
;
using
System
;
using
System.Collections
;
using
System.Linq
;
using
System.Collections.Generic
;
public
class
CoordinateMapperManager
:
MonoBehaviour
public
class
CoordinateMapperManager
:
MonoBehaviour
{
{
...
@@ -17,8 +20,6 @@ public class CoordinateMapperManager : MonoBehaviour
...
@@ -17,8 +20,6 @@ public class CoordinateMapperManager : MonoBehaviour
Texture2D
_ColorRGBX
;
Texture2D
_ColorRGBX
;
bool
nullFrame
=
false
;
public
Texture2D
ColorTexture
public
Texture2D
ColorTexture
{
get
{
return
_ColorRGBX
;
}
}
{
get
{
return
_ColorRGBX
;
}
}
public
byte
[]
BodyIndexBuffer
public
byte
[]
BodyIndexBuffer
...
@@ -30,9 +31,12 @@ public class CoordinateMapperManager : MonoBehaviour
...
@@ -30,9 +31,12 @@ public class CoordinateMapperManager : MonoBehaviour
void
Awake
()
void
Awake
()
{
{
_ColorRGBX
=
new
Texture2D
(
KinectModule
.
SourceBuffer
.
ColorWidth
,
KinectModule
.
SourceBuffer
.
ColorHeight
,
TextureFormat
.
RGBA32
,
false
);
_ColorRGBX
=
new
Texture2D
(
KinectModule
.
KinectConstants
.
ColorWidth
,
KinectModule
.
KinectConstants
.
ColorHeight
,
TextureFormat
.
RGBA32
,
false
);
_DepthCoordinates
=
new
DepthSpacePoint
[
KinectModule
.
SourceBuffer
.
ColorWidth
*
KinectModule
.
SourceBuffer
.
ColorHeight
];
_DepthCoordinates
=
new
DepthSpacePoint
[
KinectModule
.
KinectConstants
.
ColorWidth
*
KinectModule
.
KinectConstants
.
ColorHeight
];
_KinectAccessManager
.
Access
();
_KinectAccessManager
.
Access
();
}
}
...
@@ -41,27 +45,30 @@ public class CoordinateMapperManager : MonoBehaviour
...
@@ -41,27 +45,30 @@ public class CoordinateMapperManager : MonoBehaviour
{
{
GUI
.
Box
(
new
Rect
(
10
,
10
,
200
,
30
),
"FPS: "
+
fps
.
ToString
(
"0.00"
));
GUI
.
Box
(
new
Rect
(
10
,
10
,
200
,
30
),
"FPS: "
+
fps
.
ToString
(
"0.00"
));
if
(
n
ullFrame
)
if
(
_KinectAccessManager
.
N
ullFrame
)
GUI
.
Box
(
new
Rect
(
10
,
50
,
200
,
30
),
"NULL MSFR Frame"
);
GUI
.
Box
(
new
Rect
(
10
,
50
,
200
,
30
),
"NULL MSFR Frame"
);
}
}
void
ProcessFrame
()
void
MapColorToDepth
()
{
{
var
DepthData
=
GCHandle
.
Alloc
(
_SourceBuffer
.
DepthBuffer
,
GCHandleType
.
Pinned
);
var
DepthData
=
GCHandle
.
Alloc
(
_SourceBuffer
.
DepthBuffer
,
GCHandleType
.
Pinned
);
var
p
DepthCoordinatesData
=
GCHandle
.
Alloc
(
_DepthCoordinates
,
GCHandleType
.
Pinned
);
var
DepthCoordinatesData
=
GCHandle
.
Alloc
(
_DepthCoordinates
,
GCHandleType
.
Pinned
);
_KinectAccessManager
.
CoordinateMapper
.
MapColorFrameToDepthSpaceUsingIntPtr
(
_KinectAccessManager
.
CoordinateMapper
.
MapColorFrameToDepthSpaceUsingIntPtr
(
DepthData
.
AddrOfPinnedObject
(),
DepthData
.
AddrOfPinnedObject
(),
(
uint
)
_SourceBuffer
.
DepthBuffer
.
Length
*
sizeof
(
ushort
),
(
uint
)
_SourceBuffer
.
DepthBuffer
.
Length
*
sizeof
(
ushort
),
pDepthCoordinatesData
.
AddrOfPinnedObject
(),
DepthCoordinatesData
.
AddrOfPinnedObject
(),
(
uint
)
_DepthCoordinates
.
Length
);
(
uint
)
_DepthCoordinates
.
Length
);
pDepthCoordinatesData
.
Free
();
DepthCoordinatesData
.
Free
();
DepthData
.
Free
();
DepthData
.
Free
();
}
_ColorRGBX
.
LoadRawTextureData
(
_SourceBuffer
.
ColorBuffer
);
void
UpdateTexture
()
_ColorRGBX
.
Apply
();
{
}
_ColorRGBX
.
LoadRawTextureData
(
_SourceBuffer
.
ColorBuffer
);
_ColorRGBX
.
Apply
();
}
void
GetFPS
()
void
GetFPS
()
{
{
...
@@ -79,37 +86,49 @@ public class CoordinateMapperManager : MonoBehaviour
...
@@ -79,37 +86,49 @@ public class CoordinateMapperManager : MonoBehaviour
{
{
GetFPS
();
GetFPS
();
var
sourceFrame
=
_KinectAccessManager
.
SourceFrame
;
var
sourceFrame
=
new
KinectModule
.
RealMultiSourceFrame
(
_KinectAccessManager
.
SourceFrame
);
;
if
((
nullFrame
=
sourceFrame
==
null
))
return
;
if
(!
_KinectAccessManager
.
NullFrame
)
{
_SourceBuffer
.
UpdateBuffers
(
sourceFrame
);
_SourceBuffer
.
UpdateBuffers
(
sourceFrame
);
MapColorToDepth
(
);
ProcessFrame
();
UpdateTexture
();
}
}
}
void
OnApplicationQuit
()
void
OnApplicationQuit
()
{
{
_DepthCoordinates
=
null
;
_KinectAccessManager
.
Dispose
();
_KinectAccessManager
.
Dispose
();
}
}
}
}
namespace
KinectModule
namespace
KinectModule
{
{
public
class
SourceBuffer
public
class
KinectConstants
{
{
public
const
int
DepthWidth
=
512
;
public
const
int
DepthWidth
=
512
;
public
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
;
public
const
int
BodyCount
=
6
;
public
const
int
ColorCount
=
4
;
}
private
byte
[]
_ColorBuffer
=
new
byte
[
ColorWidth
*
ColorHeight
*
4
],
public
class
SourceBuffer
_BodyIndexBuffer
=
new
byte
[
DepthWidth
*
DepthHeight
];
{
private
ushort
[]
_DepthBuffer
=
new
ushort
[
DepthWidth
*
DepthHeight
];
private
byte
[]
_ColorBuffer
=
new
byte
[
KinectConstants
.
ColorWidth
*
private
Body
[]
_BodyBuffer
=
new
Body
[
BodyCount
];
KinectConstants
.
ColorHeight
*
KinectConstants
.
ColorCount
],
_BodyIndexBuffer
=
new
byte
[
KinectConstants
.
DepthWidth
*
KinectConstants
.
DepthHeight
];
private
ushort
[]
_DepthBuffer
=
new
ushort
[
KinectConstants
.
DepthWidth
*
KinectConstants
.
DepthHeight
];
private
Body
[]
_BodyBuffer
=
new
Body
[
KinectConstants
.
BodyCount
];
// 1. Do not return null values.
// 2. The updated value should reflect the data of the source frame.
public
byte
[]
ColorBuffer
public
byte
[]
ColorBuffer
{
get
{
return
_ColorBuffer
;
}
}
{
get
{
return
_ColorBuffer
;
}
}
...
@@ -120,52 +139,14 @@ namespace KinectModule
...
@@ -120,52 +139,14 @@ namespace KinectModule
public
Body
[]
BodyBuffer
public
Body
[]
BodyBuffer
{
get
{
return
_BodyBuffer
;
}
}
{
get
{
return
_BodyBuffer
;
}
}
public
void
UpdateBuffers
(
MultiSourceFrame
sourceFrame
)
// 1. The data of the source frame must be reflected in the buffer.
{
UpdateColorBuffer
(
sourceFrame
);
UpdateBodyIndexBuffer
(
sourceFrame
);
UpdateDepthBuffer
(
sourceFrame
);
UpdateBodyBuffer
(
sourceFrame
);
}
p
rivate
void
UpdateColorBuffer
(
MultiSourceFrame
sourceFrame
)
p
ublic
void
UpdateBuffers
(
I
MultiSourceFrame
sourceFrame
)
{
{
using
(
var
colorFrame
=
sourceFrame
.
ColorFrameReference
.
AcquireFrame
())
sourceFrame
.
LastColorFrame
.
CopyData
(
_ColorBuffer
);
if
(
colorFrame
!=
null
)
sourceFrame
.
LastBodyIndexFrame
.
CopyData
(
_BodyIndexBuffer
);
{
sourceFrame
.
LastDepthFrame
.
CopyData
(
_DepthBuffer
);
var
ColorData
=
GCHandle
.
Alloc
(
_ColorBuffer
,
GCHandleType
.
Pinned
);
sourceFrame
.
LastBodyFrame
.
CopyData
(
_BodyBuffer
);
colorFrame
.
CopyConvertedFrameDataToIntPtr
(
ColorData
.
AddrOfPinnedObject
(),
(
uint
)
_ColorBuffer
.
Length
,
ColorImageFormat
.
Rgba
);
ColorData
.
Free
();
}
}
private
void
UpdateBodyIndexBuffer
(
MultiSourceFrame
sourceFrame
)
{
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
();
}
}
private
void
UpdateDepthBuffer
(
MultiSourceFrame
sourceFrame
)
{
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
();
}
}
private
void
UpdateBodyBuffer
(
MultiSourceFrame
sourceFrame
)
{
using
(
var
bodyFrame
=
sourceFrame
.
BodyFrameReference
.
AcquireFrame
())
if
(
bodyFrame
!=
null
)
bodyFrame
.
GetAndRefreshBodyData
(
_BodyBuffer
);
}
}
}
}
...
@@ -177,13 +158,29 @@ namespace KinectModule
...
@@ -177,13 +158,29 @@ namespace KinectModule
private
bool
_IsSensorOpen
=
false
;
private
bool
_IsSensorOpen
=
false
;
private
bool
_IsFrameReaderOpen
=
false
;
private
bool
_IsFrameReaderOpen
=
false
;
private
bool
_NullFrame
=
false
;
public
bool
IsAccess
public
bool
IsAccess
{
get
{
return
_IsSensorOpen
&&
_IsFrameReaderOpen
;
}
}
{
get
{
return
_IsSensorOpen
&&
_IsFrameReaderOpen
;
}
}
public
CoordinateMapper
CoordinateMapper
public
CoordinateMapper
CoordinateMapper
{
get
{
return
IsAccess
?
_CoordinateMapper
:
null
;
}
}
{
get
{
return
IsAccess
?
_CoordinateMapper
:
null
;
}
}
public
MultiSourceFrame
SourceFrame
public
MultiSourceFrame
SourceFrame
{
get
{
return
IsAccess
?
_SourceFrameReader
.
AcquireLatestFrame
()
:
null
;
}
}
{
get
{
if
(
IsAccess
)
{
var
val
=
_SourceFrameReader
.
AcquireLatestFrame
();
_NullFrame
=
(
val
==
null
);
return
val
;
}
_NullFrame
=
true
;
return
null
;
}
}
public
bool
NullFrame
{
get
{
return
_NullFrame
;
}
}
public
void
Access
()
public
void
Access
()
{
{
...
@@ -256,4 +253,139 @@ namespace KinectModule
...
@@ -256,4 +253,139 @@ namespace KinectModule
}
}
}
}
}
}
public
interface
IMultiSourceFrame
{
IColorFrame
LastColorFrame
{
get
;
}
IBodyIndexFrame
LastBodyIndexFrame
{
get
;
}
IDepthFrame
LastDepthFrame
{
get
;
}
IBodyFrame
LastBodyFrame
{
get
;
}
}
public
interface
IColorFrame
{
void
CopyData
(
byte
[]
buffer
);
}
public
interface
IBodyIndexFrame
{
void
CopyData
(
byte
[]
buffer
);
}
public
interface
IDepthFrame
{
void
CopyData
(
ushort
[]
buffer
);
}
public
interface
IBodyFrame
{
void
CopyData
(
Body
[]
buffer
);
}
public
class
RealMultiSourceFrame
:
IMultiSourceFrame
{
MultiSourceFrame
_SourceFrame
;
RealColorFrame
_ColorFrame
;
RealBodyIndexFrame
_BodyIndexFrame
;
RealDepthFrame
_DepthFrame
;
RealBodyFrame
_BodyFrame
;
public
IColorFrame
LastColorFrame
{
get
{
return
_ColorFrame
;
}
}
public
IBodyIndexFrame
LastBodyIndexFrame
{
get
{
return
_BodyIndexFrame
;
}
}
public
IDepthFrame
LastDepthFrame
{
get
{
return
_DepthFrame
;
}
}
public
IBodyFrame
LastBodyFrame
{
get
{
return
_BodyFrame
;
}
}
public
RealMultiSourceFrame
(
MultiSourceFrame
sourceFrame
)
{
_SourceFrame
=
sourceFrame
;
_ColorFrame
=
new
RealColorFrame
(
sourceFrame
.
ColorFrameReference
.
AcquireFrame
());
_BodyIndexFrame
=
new
RealBodyIndexFrame
(
sourceFrame
.
BodyIndexFrameReference
.
AcquireFrame
());
_DepthFrame
=
new
RealDepthFrame
(
sourceFrame
.
DepthFrameReference
.
AcquireFrame
());
_BodyFrame
=
new
RealBodyFrame
(
sourceFrame
.
BodyFrameReference
.
AcquireFrame
());
}
private
class
RealColorFrame
:
IColorFrame
{
private
ColorFrame
_Frame
;
public
RealColorFrame
(
ColorFrame
frame
)
{
_Frame
=
frame
;
}
public
void
CopyData
(
byte
[]
buffer
)
{
if
(
_Frame
!=
null
)
{
var
ColorData
=
GCHandle
.
Alloc
(
buffer
,
GCHandleType
.
Pinned
);
_Frame
.
CopyConvertedFrameDataToIntPtr
(
ColorData
.
AddrOfPinnedObject
(),
(
uint
)
buffer
.
Length
,
ColorImageFormat
.
Rgba
);
ColorData
.
Free
();
}
}
}
private
class
RealBodyIndexFrame
:
IBodyIndexFrame
{
private
BodyIndexFrame
_Frame
;
public
RealBodyIndexFrame
(
BodyIndexFrame
frame
)
{
_Frame
=
frame
;
}
public
void
CopyData
(
byte
[]
buffer
)
{
if
(
_Frame
!=
null
)
{
var
BodyIndexData
=
GCHandle
.
Alloc
(
buffer
,
GCHandleType
.
Pinned
);
_Frame
.
CopyFrameDataToIntPtr
(
BodyIndexData
.
AddrOfPinnedObject
(),
(
uint
)
buffer
.
Length
);
BodyIndexData
.
Free
();
}
}
}
private
class
RealDepthFrame
:
IDepthFrame
{
private
DepthFrame
_Frame
;
public
RealDepthFrame
(
DepthFrame
frame
)
{
_Frame
=
frame
;
}
public
void
CopyData
(
ushort
[]
buffer
)
{
if
(
_Frame
!=
null
)
{
var
DepthData
=
GCHandle
.
Alloc
(
buffer
,
GCHandleType
.
Pinned
);
_Frame
.
CopyFrameDataToIntPtr
(
DepthData
.
AddrOfPinnedObject
(),
(
uint
)
buffer
.
Length
*
sizeof
(
ushort
));
DepthData
.
Free
();
}
}
}
private
class
RealBodyFrame
:
IBodyFrame
{
private
BodyFrame
_Frame
;
public
RealBodyFrame
(
BodyFrame
frame
)
{
_Frame
=
frame
;
}
public
void
CopyData
(
Body
[]
buffer
)
{
if
(
_Frame
!=
null
)
_Frame
.
GetAndRefreshBodyData
(
buffer
);
}
}
}
}
}
Assets/Script/CoordinateMapperView.cs
View file @
857647e9
...
@@ -15,22 +15,16 @@ public class CoordinateMapperView : MonoBehaviour
...
@@ -15,22 +15,16 @@ public class CoordinateMapperView : MonoBehaviour
CoordinateMapperManager
CoordinateMapperManager
=
GameObject
.
Find
(
"Managers"
).
GetComponent
<
CoordinateMapperManager
>();
CoordinateMapperManager
CoordinateMapperManager
=
GameObject
.
Find
(
"Managers"
).
GetComponent
<
CoordinateMapperManager
>();
GetComponent
<
Renderer
>().
material
.
SetTexture
(
"_MainTex"
,
CoordinateMapperManager
.
ColorTexture
);
GetComponent
<
Renderer
>().
material
.
SetTexture
(
"_MainTex"
,
CoordinateMapperManager
.
ColorTexture
);
DepthBuffer
=
GenerateBuffer
(
"depthCoordinates"
,
sizeof
(
float
)
*
2
,
(
DepthPoints
=
CoordinateMapperManager
.
DepthCoordinates
));
BodyIndexBuffer
=
GenerateBuffer
(
"BodyIndexBuffer"
,
sizeof
(
float
),
(
BodyIndexPoints
=
CoordinateMapperManager
.
BodyIndexBuffer
));
}
Func
<
Array
,
Array
,
Action
<
string
,
ComputeBuffer
,
int
>>
setBuffer
=
(
srcPoints
,
dstPoints
)
=>
ComputeBuffer
GenerateBuffer
(
string
name
,
int
stride
,
Array
points
)
{
{
dstPoints
=
srcPoints
;
var
buffer
=
new
ComputeBuffer
(
points
.
Length
,
stride
);
return
(
name
,
buffer
,
stride
)
=>
GetComponent
<
Renderer
>().
material
.
SetBuffer
(
name
,
buffer
);
{
return
buffer
;
buffer
=
new
ComputeBuffer
(
dstPoints
.
Length
,
stride
);
GetComponent
<
Renderer
>().
material
.
SetBuffer
(
name
,
buffer
);
};
};
setBuffer
(
CoordinateMapperManager
.
DepthCoordinates
,
DepthPoints
)
(
"depthCoordinates"
,
DepthBuffer
,
sizeof
(
float
)
*
2
);
setBuffer
(
CoordinateMapperManager
.
BodyIndexBuffer
,
BodyIndexPoints
)
(
"BodyIndexBuffer"
,
BodyIndexBuffer
,
sizeof
(
float
));
}
}
void
Update
()
void
Update
()
...
@@ -45,8 +39,5 @@ public class CoordinateMapperView : MonoBehaviour
...
@@ -45,8 +39,5 @@ public class CoordinateMapperView : MonoBehaviour
{
{
DepthBuffer
.
Release
();
DepthBuffer
.
Release
();
BodyIndexBuffer
.
Release
();
BodyIndexBuffer
.
Release
();
DepthPoints
=
null
;
BodyIndexPoints
=
null
;
}
}
}
}
Assets/Script/MotionView.cs
View file @
857647e9
...
@@ -6,7 +6,7 @@ using UnityEngine.UI;
...
@@ -6,7 +6,7 @@ using UnityEngine.UI;
using
Windows.Kinect
;
using
Windows.Kinect
;
public
class
MotionView
:
MonoBehaviour
{
public
class
MotionView
:
MonoBehaviour
{
Pair
<
float
,
MotionState
>
r
ecent
;
Pair
<
float
,
MotionState
>
_R
ecent
;
public
GameObject
CoordinateMapperManager
;
public
GameObject
CoordinateMapperManager
;
CoordinateMapperManager
_coordinateMapperManager
;
CoordinateMapperManager
_coordinateMapperManager
;
Body
[]
body
;
Body
[]
body
;
...
@@ -17,13 +17,13 @@ public class MotionView : MonoBehaviour {
...
@@ -17,13 +17,13 @@ public class MotionView : MonoBehaviour {
kneeRightBase
;
kneeRightBase
;
bool
IsInitialized
;
bool
IsInitialized
;
public
Pair
<
float
,
MotionState
>
Recent
State
public
Pair
<
float
,
MotionState
>
Recent
{
get
{
return
r
ecent
;
}
}
{
get
{
return
_R
ecent
;
}
}
// Use this for initialization
// Use this for initialization
void
Start
()
void
Start
()
{
{
r
ecent
=
new
Pair
<
float
,
MotionState
>
_R
ecent
=
new
Pair
<
float
,
MotionState
>
{
{
first
=
0
,
first
=
0
,
second
=
MotionState
.
UNKNOWN
second
=
MotionState
.
UNKNOWN
...
@@ -42,10 +42,10 @@ public class MotionView : MonoBehaviour {
...
@@ -42,10 +42,10 @@ public class MotionView : MonoBehaviour {
// Update is called once per frame
// Update is called once per frame
void
Update
()
void
Update
()
{
{
r
ecent
.
first
+=
Time
.
deltaTime
;
_R
ecent
.
first
+=
Time
.
deltaTime
;
r
ecent
.
second
=
DetermineState
();
_R
ecent
.
second
=
DetermineState
();
InputManager
.
Instance
.
CurrentMotionState
=
r
ecent
.
second
;
InputManager
.
Instance
.
CurrentMotionState
=
_R
ecent
.
second
;
}
}
MotionState
DetermineState
()
MotionState
DetermineState
()
...
...
Assets/Script/Tests.meta
0 → 100644
View file @
857647e9
fileFormatVersion: 2
guid: c28398155b106d94db55ece60bf7890b
folderAsset: yes
timeCreated: 1515375347
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Assets/Script/Tests/CoordinateMapperManagerTests.cs
0 → 100644
View file @
857647e9
using
UnityEngine
;
using
UnityEngine.TestTools
;
using
NUnit.Framework
;
using
System.Collections
;
using
Windows.Kinect
;
using
System.Runtime.InteropServices
;
using
System
;
public
class
CoordinateMapperManagerTests
{
[
Test
]
public
void
CoordinateMapperManagerTestsSimplePasses
()
{
// Use the Assert class to test conditions.
}
// A UnityTest behaves like a coroutine in PlayMode
// and allows you to yield null to skip a frame in EditMode
[
UnityTest
]
public
IEnumerator
InterfaceTest
()
{
// Use the Assert class to test conditions.
// yield to skip a frame
yield
return
null
;
}
[
UnityTest
]
public
IEnumerator
FPSTest
()
{
yield
return
null
;
}
}
Assets/Script/Tests/CoordinateMapperManagerTests.cs.meta
0 → 100644
View file @
857647e9
fileFormatVersion: 2
guid: b1d6a9e0d1a234f4292f6a346b18d2ec
timeCreated: 1515375333
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Script/Tests/CoordinateMapperViewTests.cs
0 → 100644
View file @
857647e9
using
UnityEngine
;
using
UnityEngine.TestTools
;
using
NUnit.Framework
;
using
System.Collections
;
using
Windows.Kinect
;
using
System.Runtime.InteropServices
;
using
System
;
namespace
Assets.Script.Tests
{
class
CoordinateMapperViewTests
{
[
Test
]
public
void
CoordinateMapperViewTestsSimplePasses
()
{
// Use the Assert class to test conditions.
}
// A UnityTest behaves like a coroutine in PlayMode
// and allows you to yield null to skip a frame in EditMode
[
UnityTest
]
public
IEnumerator
CoordinateMapperViewTestsWithEnumeratorPasses
()
{
var
CoordinateMapperManager
=
GameObject
.
Find
(
"Managers"
).
GetComponent
<
CoordinateMapperManager
>();
var
tmpObj
=
GameObject
.
CreatePrimitive
(
PrimitiveType
.
Plane
);
tmpObj
.
GetComponent
<
Renderer
>().
material
=
Resources
.
Load
(
"GreenScreen/GreenScreen.mat"
,
typeof
(
Material
))
as
Material
;
tmpObj
.
GetComponent
<
Renderer
>().
material
.
SetTexture
(
"_MainTex"
,
CoordinateMapperManager
.
ColorTexture
);
var
DepthPoints
=
CoordinateMapperManager
.
DepthCoordinates
;
var
DepthBuffer
=
new
ComputeBuffer
(
DepthPoints
.
Length
,
sizeof
(
float
)
*
2
);
tmpObj
.
GetComponent
<
Renderer
>().
material
.
SetBuffer
(
"depthCoordinates"
,
DepthBuffer
);
var
BodyIndexPoints
=
CoordinateMapperManager
.
BodyIndexBuffer
;
var
BodyIndexBuffer
=
new
ComputeBuffer
(
BodyIndexPoints
.
Length
,
sizeof
(
float
));
tmpObj
.
GetComponent
<
Renderer
>().
material
.
SetBuffer
(
"bodyIndexBuffer"
,
BodyIndexBuffer
);
var
CoordinateMapperView
=
GameObject
.
Find
(
"CoordinateMapView"
);
// Use the Assert class to test conditions.
// yield to skip a frame
yield
return
null
;
Assert
.
AreEqual
(
tmpObj
.
GetComponent
<
Renderer
>().
material
.
mainTexture
,
CoordinateMapperView
.
GetComponent
<
Renderer
>().
material
.
mainTexture
,
"CoordinateMapperViewTest Failed."
);
}
}
}
Assets/Script/Tests/CoordinateMapperViewTests.cs.meta
0 → 100644
View file @
857647e9
fileFormatVersion: 2
guid: 623524eedad81b24c9da54ab55e5e468
timeCreated: 1515385568
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
ProjectSettings/ProjectSettings.asset
View file @
857647e9
...
@@ -295,7 +295,7 @@ PlayerSettings:
...
@@ -295,7 +295,7 @@ PlayerSettings:
wiiUGamePadStartupScreen
:
{
fileID
:
0
}
wiiUGamePadStartupScreen
:
{
fileID
:
0
}
wiiUDrcBufferDisabled
:
0
wiiUDrcBufferDisabled
:
0
wiiUProfilerLibPath
:
wiiUProfilerLibPath
:
playModeTestRunnerEnabled
:
0
playModeTestRunnerEnabled
:
1
actionOnDotNetUnhandledException
:
1
actionOnDotNetUnhandledException
:
1
enableInternalProfiler
:
0
enableInternalProfiler
:
0
logObjCUncaughtExceptions
:
1
logObjCUncaughtExceptions
:
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment