-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStruct.cs
More file actions
296 lines (281 loc) · 8.48 KB
/
Copy pathStruct.cs
File metadata and controls
296 lines (281 loc) · 8.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace OpenNUI.CSharp.Library
{
public enum EventType : int
{
HandStatusChange,
HandPositionChange,
FaceDataChange,
PatternDataChange,
GestureDetected,
SensorCreated,
SensorStatusChanged,
UserCustom,
}
public enum SensorState : int
{
UNLOADED = 0, //DLL은 물려있는데 센서가 열리지 않음.
UNKNOWN, //뽑힘 (제거)
OPENED, //정상
SUSPENDED //센서 정지.
}
public enum HandStatus : short
{
Unknown = 0,
NotTracked = 1,
Open = 2,
Closed = 3,
Point = 4,
}
public enum TrackingState : int
{
NotTracked = 0,
Inferred = 1,
Tracked = 2,
}
public enum JointType : int
{
NULL = -1,
SpineBase = 0,
SpineMid = 1,
Neck = 2,
Head = 3,
ShoulderLeft = 4,
ElbowLeft = 5,
WristLeft = 6,
HandLeft = 7,
ShoulderRight = 8,
ElbowRight = 9,
WristRight = 10,
HandRight = 11,
HipLeft = 12,
KneeLeft = 13,
AnkleLeft = 14,
FootLeft = 15,
HipRight = 16,
KneeRight = 17,
AnkleRight = 18,
FootRight = 19,
SpineShoulder = 20,
HandTipLeft = 21,
ThumbLeft = 22,
HandTipRight = 23,
ThumbRight = 24,
}
public static class SensorSupport
{
public const int DEPTH = 0x01;
public const int COLOR = 0x02;
public const int BODY = 0x04;
public const int HAND = 0x08;
}
public struct Vector3
{
public double x;
public double y;
public double z;
public Vector3(double x, double y, double z)
{
this.x = x;
this.y = y;
this.z = z;
}
public override string ToString()
{
return "(" + x.ToString() + "," + y.ToString() + "," + z.ToString() + ")";
}
}
public struct Vector2
{
public double x;
public double y;
public Vector2(double x, double y)
{
this.x = x;
this.y = y;
}
public override string ToString()
{
return "(" + x.ToString() + "," + y.ToString() + ")";
}
public static Vector2 operator +(Vector2 op1, Vector2 op2)
{
return new Vector2(op1.x + op2.x, op1.y + op2.y);
}
public static Vector2 operator -(Vector2 op1, Vector2 op2)
{
return new Vector2(op1.x - op2.x, op1.y - op2.y);
}
}
public struct Joint
{
public readonly Vector3 position;
public readonly JointType type;
public readonly TrackingState state;
internal Joint(double x, double y, double z, JointType type, TrackingState state)
{
position = new Vector3(x, y, z);
this.type = type;
this.state = state;
}
}
public struct JointOrientation
{
public JointType type;
public readonly float x;
public readonly float y;
public readonly float z;
public readonly float w;
internal JointOrientation(JointType type, float x, float y, float z, float w)
{
this.type = type;
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
public override string ToString()
{
return "(" + x.ToString() + "," + y.ToString() + "," + z.ToString() + "," + w.ToString() + ")";
}
}
public struct ColorInfo
{
public int Width;
public int Height;
public int BytePerPixel;
public int Size { get { return Width * Height * BytePerPixel; } }
public ColorInfo(int width, int height, int bpp)
{
Width = width;
Height = height;
BytePerPixel = bpp;
}
}
public struct DepthInfo
{
public readonly bool EnableCoordinate;
internal readonly double JointDepthXMult;
internal readonly double JointDepthXFix;
internal readonly double JointDepthYMult;
internal readonly double JointDepthYFix;
internal readonly double DepthToJointZMult;
public readonly int Width;
public readonly int Height;
public readonly int BytePerPixel;
public readonly short MinValue;
public readonly short MaxValue;
public int Size { get { return Width * Height * BytePerPixel; } }
public DepthInfo(int width, int height, short MinValue, short MaxValue, int bpp,
bool EnableCoordinate = false,
double JointDepthXMult = 0, double JointDepthXFix = 0,
double JointDepthYMult = 0, double JointDepthYFix = 0,
double DepthToJointZMult = 0)
{
Width = width;
Height = height;
BytePerPixel = bpp;
this.MinValue = MinValue;
this.MaxValue = MaxValue;
//Coordinate
this.EnableCoordinate = EnableCoordinate;
this.JointDepthXMult = JointDepthXMult;
this.JointDepthXFix = JointDepthXFix;
this.JointDepthYMult = JointDepthYMult;
this.JointDepthYFix = JointDepthYFix;
this.DepthToJointZMult = DepthToJointZMult;
}
}
public struct BodyInfo
{
public int MaxTrackingNumber;
public BodyInfo(int maxTrackingNumber)
{
MaxTrackingNumber = maxTrackingNumber;
}
}
public class ImageData
{
public byte[] FrameData { get; private set; }
public ColorInfo Description { get; private set; }
internal ImageData(byte[] data, ColorInfo info)
{
FrameData = data;
Description = info;
}
}
public class DepthData
{
public ushort[] FrameData { get; private set; }
public DepthInfo Description { get; private set; }
internal DepthData(short[] data, DepthInfo info)
{
this.FrameData = new ushort[data.Length];
int index = 0;
foreach (short value in data)
{
this.FrameData[index] = (ushort)value;
index++;
}
this.Description = info;
}
}
public struct BodyData
{
public readonly Dictionary<JointType, Joint> Joints;
public readonly Dictionary<JointType, JointOrientation> Orientations;
public readonly int Id;
public readonly bool Valid;
public readonly HandStatus LeftHand;
public readonly HandStatus RightHand;
public readonly NuiSensor Sensor;
internal BodyData(Dictionary<JointType, Joint> joints, Dictionary<JointType, JointOrientation> orientations, bool valid, int id, NuiSensor sensor, HandStatus leftHand, HandStatus rightHand)
{
this.Joints = joints;
this.Orientations = orientations;
this.Id = id;
this.Valid = valid;
this.Sensor = sensor;
this.LeftHand = leftHand;
this.RightHand = rightHand;
}
}
public class EventData
{
public const int EVENT_DATA_SIZE = 260;
public EventType EventType { get; private set; }
public byte[] Data { get; set; }
public EventData(EventType type)
{
EventType = type;
Data = new byte[256];
}
// 쓰기 함수 만들어야돠ㅣㅁ
public static EventData ToEvent(byte[] data, int offset = 0)
{
if (data.Length >= EventData.EVENT_DATA_SIZE + offset)
{
EventData e = new EventData((EventType)BitConverter.ToInt32(data, 0));
Array.Copy(data, sizeof(Int32), e.Data, 0, 256);
return e;
}
return null; // [에러임 이건]
}
public byte[] GetBytes()
{
byte[] buffer = new byte[EVENT_DATA_SIZE];
MemoryStream stream = new MemoryStream(buffer.Length);
BinaryWriter writer = new BinaryWriter(stream);
writer.Write((int)EventType);
writer.Write(Data);
buffer = stream.GetBuffer();
writer.Close();
stream.Close();
return buffer;
}
}
}