-
Notifications
You must be signed in to change notification settings - Fork 5
/
RTPacket.cs
2036 lines (1856 loc) · 77.7 KB
/
RTPacket.cs
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Realtime SDK for Qualisys Track Manager. Copyright 2015-2018 Qualisys AB
//
using QTMRealTimeSDK.Settings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
namespace QTMRealTimeSDK.Data
{
#region Enumerations related to RTPacket
/// <summary>Type of package sent via RT</summary>
public enum PacketType
{
PacketError = 0,
PacketCommand,
PacketXML,
PacketData,
PacketNoMoreData,
PacketC3DFile,
PacketEvent,
PacketDiscover,
PacketQTMFile,
PacketNone
}
/// <summary>Type of component streamed</summary>
public enum ComponentType
{
// Labeled 3d markers (Get3DMarkerData)
Component3d = 1,
// Unidentified 3d markers (Get3DMarkerNoLabelsData)
Component3dNoLabels = 2,
// Analog data (GetAnalogData)
ComponentAnalog = 3,
// Force data (GetForceData)
ComponentForce = 4,
// 6D data - position and rotation matrix (Get6DOFData)
Component6d = 5,
// 6D data - position and Euler angles (Get6DOFEulerData)
Component6dEuler = 6,
// 2D marker data (Get2DMarkerData)
Component2d = 7,
// Linearized 2D marker data (Get2DLinearizedMarkerDAta)
Component2dLinearized = 8,
// Labeled 3d markers with residual (Get3DMarkerResidualData)
Component3dResidual = 9,
// Unidentified 3d markers with residual (Get3DMarkerNoLabelsResidualData)
Component3dNoLabelsResidual = 10,
// 6D data - position and rotation matrix with residuals with residual (Get6DOFResidualData)
Component6dResidual = 11,
// 6D data - position and Euler angles with residual (Get6DOFEulerResidualData)
Component6dEulerResidual = 12,
// Analog data from available analog devices. Only one sample per channel and camera frame. The latest sample is used if more than one sample is available. (GetAnalogSingleData)
ComponentAnalogSingle = 13,
// Image frame from a specific camera. Image size and format is set with the XML settings, see Image settings. (GetImageData)
ComponentImage = 14,
// Force data from available force plates. Only one sample per plate and camera frame. The latest sample is used if more than one sample is available. (GetForceSingleData)
ComponentForceSingle = 15,
// Gaze vector data from eye tracker (GetGazeVectorData)
ComponentGazeVector = 16,
// Timecode component
ComponentTimecode = 17,
// Skeleton component
ComponentSkeleton = 18,
// Eye tracker component
ComponentEyeTracker = 19,
// Nothing
ComponentNone = 20,
}
/// <summary>Events sent from QTM via RT</summary>
public enum QTMEvent
{
Connected = 1,
ConnectionClosed,
CaptureStarted,
CaptureStopped,
CaptureFetchingFinished,
CalibrationStarted,
CalibrationStopped,
RTFromFileStarted,
RTFromFileStopped,
WaitingForTrigger,
CameraSettingsChanged,
QTMShuttingDown,
CaptureSaved,
ReprocessingStarted,
ReprocessingStopped,
Trigger,
None
}
// <summary>Timecode types available from QTM</summary>
public enum TimecodeType
{
SMPTE = 0,
IRIG,
CameraTime
}
#endregion
#region Data structures related to RTPacket
/// <summary>Data for cameras, includes 2D marker data</summary>
public struct Camera
{
/// <summary>Number of markers</summary>
public uint MarkerCount;
/// <summary>Only first bits is used, too much light enters camera</summary>
public byte StatusFlags;
/// <summary>Marker data for this camera</summary>
public Q2D[] MarkerData2D;
}
/// <summary>Struct for xyz coordinates</summary>
public struct Point
{
[XmlElement("X")]
public float X;
[XmlElement("Y")]
public float Y;
[XmlElement("Z")]
public float Z;
}
/// <summary>Struct for quaterinion </summary>
public struct QuatRotation
{
[XmlElement("A")]
public float X;
[XmlElement("B")]
public float Y;
[XmlElement("C")]
public float Z;
[XmlElement("D")]
public float W;
}
/// <summary>Struct for Euler rotation</summary>
public struct EulerRotation
{
public float First;
public float Second;
public float Third;
}
/// <summary>Data from a force plate, includes samples</summary>
public struct ForcePlate
{
/// <summary>ID of plate</summary>
public int PlateId;
/// <summary>Number of forces in frame</summary>
public int ForceCount;
/// <summary>Force number, increased with the force frequency</summary>
public int ForceNumber;
/// <summary>Samples collected from plate</summary>
public ForceSample[] ForceSamples;
}
/// <summary>samples for a force plat</summary>
public struct ForceSample
{
/// <summary>Coordinate of the force </summary>
public Point Force;
/// <summary>Coordinate of the moment </summary>
public Point Moment;
/// <summary>Coordinate of the force application point </summary>
public Point ApplicationPoint;
}
/// <summary>2D Data for markers from cameras. used by both for non- and linearized marker</summary>
public struct Q2D
{
/// <summary>X coordinate of the marker</summary>
public uint X;
/// <summary>Y coordinate of the marker</summary>
public uint Y;
/// <summary>X diameter of the marker</summary>
public ushort DiameterX;
/// <summary>Y diameter of the marker</summary>
public ushort DiameterY;
}
/// <summary>3D data for marker</summary>
public struct Q3D
{
/// <summary>ID of marker, 0 of marker has label</summary>
public uint Id;
/// <summary>Position data for marker</summary>
public Point Position;
/// <summary>Residual for marker, -1 if residual was not requested</summary>
public float Residual;
}
/// <summary>Data for 6DOF (6 Degrees Of Freedom) Body</summary>
public struct Q6DOF
{
/// <summary>Position data for body</summary>
public Point Position;
/// <summary>Rotation matrix for body</summary>
public float[] Matrix;
/// <summary>Residual for body, -1 if residual was not requested</summary>
public float Residual;
}
/// <summary>Data for 6DOF (6 Degrees Of Freedom) Body, Euler angles instead of matrix</summary>
public struct Q6DOFEuler
{
/// <summary>Position data for body</summary>
public Point Position;
/// <summary>Euler angles for body</summary>
public EulerRotation Rotation;
/// <summary>Residual for body, -1 if residual was not requested</summary>
public float Residual;
}
/// <summary>Data from a analog device, includes samples</summary>
public struct Analog
{
/// <summary>Device ID</summary>
public uint DeviceID;
/// <summary>Number of channels</summary>
public uint ChannelCount;
/// <summary>Samples for all channels</summary>
public AnalogChannelData[] Channels;
/// <summary>Start sample number for analog data packet</summary>
public uint SampleNumber;
}
/// <summary>Channel data from analog device</summary>
public struct AnalogChannelData
{
/// <summary>Sample data for channel</summary>
public float[] Samples;
/// <summary>Sample number</summary>
public uint SampleNumber;
}
/// <summary>Data for camera image</summary>
public struct CameraImage
{
/// <summary>Id of camera image originates from</summary>
public uint CameraID;
/// <summary>Image format</summary>
public ImageFormat ImageFormat;
/// <summary>Width of image</summary>
public uint Width;
/// <summary>Height of image</summary>
public uint Height;
/// <summary>Scaled value of cropping from left</summary>
public float LeftCrop;
/// <summary>Scaled value of cropping from top</summary>
public float TopCrop;
/// <summary>Scaled value of cropping from right</summary>
public float RightCrop;
/// <summary>Scaled value of cropping from bottom</summary>
public float BottomCrop;
/// <summary>Size of image data</summary>
public int ImageSize;
/// <summary>Actual image data</summary>
public byte[] ImageData;
}
/// <summary>Data for Gaze vector.</summary>
public struct GazeVector
{
/// <summary>Sample number</summary>
public uint SampleNumber;
/// <summary>Gaze vector data array</summary>
public GazeVectorSample[] GazeVectorData;
}
public struct GazeVectorSample
{
/// <summary>Gaze vector</summary>
public Point Gaze;
/// <summary>Gaze vector position</summary>
public Point Position;
}
/// <summary>Data for Eye tracker.</summary>
public struct EyeTracker
{
/// <summary>Sample number</summary>
public uint SampleNumber;
/// <summary>Eye tracker data array</summary>
public EyeTrackerSample[] EyeTrackerData;
}
/// <summary>Data for Eye tracker.</summary>
public struct EyeTrackerSample
{
/// <summary>Left Pupil Position</summary>
public float LeftPupilDiameter;
/// <summary>Right Pupil Position</summary>
public float RightPupilDiameter;
}
/// <summary>Data for Timecode.</summary>
public struct Timecode
{
/// <summary>Gaze vector</summary>
public TimecodeType Type;
/// <summary>Gaze vector position</summary>
public uint High;
/// <summary>Sample number</summary>
public uint Low;
public override string ToString()
{
return this.FormatTimestamp();
}
}
/// <summary> IRIG timecode struct </summary>
public struct IRIGTimecode
{
public uint Year;
public uint Day;
public uint Hour;
public uint Minute;
public uint Second;
public uint Tenth;
}
/// <summary> SMPTE timecode struct </summary>
public struct SMPTETimecode
{
public uint Hour;
public uint Minute;
public uint Second;
public uint Frame;
}
/// <summary>Data for Skeleton segment</summary>
public struct SkeletonSegment
{
/// <summary>ID</summary>
public uint ID;
/// <summary>Skeleton position</summary>
public Point Position;
/// <summary>Skeleton rotation</summary>
public QuatRotation Rotation;
}
/// <summary>Data for Skeleton</summary>
public struct Skeleton
{
// <summary>Segment data</summary>
public List<SkeletonSegment> Segments;
/// <summary>Sample number</summary>
public uint SampleNumber;
/// <summary>Number of segments</summary>
public uint SegmentCount;
}
#endregion
public class RTPacket
{
/// <summary>return packet with no data but only type set to error packet</summary>
public static RTPacket ErrorPacket { get { return new RTPacket(PacketType.PacketError); } }
int mMajorVersion;
/// <summary>Major protocol version of packet</summary>
public int MajorVersion { get { return mMajorVersion; } }
int mMinorVersion;
/// <summary>Minor protocol version of packet</summary>
public int MinorVersion { get { return mMinorVersion; } }
int mPacketSize;
/// <summary>size of packet in bytes</summary>
public int PacketSize { get { return mPacketSize; } }
PacketType mPacketType;
/// <summary>what type of packet</summary>
public PacketType PacketType { get { return mPacketType; } }
long mTimestamp;
/// <summary>if the packet is a data packet, this will return the timestamp, otherwise -1</summary>
public long TimeStamp { get { return mTimestamp; } }
int mFrameNumber;
/// <summary>if the packet is a data packet, this will return the frame number, otherwise -1</summary>
public int Frame { get { return mFrameNumber; } }
uint m2DDropRate;
/// <summary>Drop rate from cameras</summary>
public uint DropRate { get { return m2DDropRate; } }
uint m2DOutOfSyncRate;
/// <summary>Out of sync rate from cameras</summary>
public uint OutOfSyncRate { get { return m2DOutOfSyncRate; } }
/// <summary>Number of cameras</summary>
public int CameraCount { get { return (m2DMarkerData != null) ? m2DMarkerData.Count : -1; } }
/// <summary>Number of markers</summary>
public int MarkerCount { get { return (m3DMarkerData != null) ? m3DMarkerData.Count : -1; } }
/// <summary>Number of bodies</summary>
public int BodyCount { get { return (m6DOFData != null) ? m6DOFData.Count : -1; } }
byte[] mData;
internal byte[] Data { get { return mData; } }
List<Camera> m2DMarkerData;
List<Camera> m2DLinearizedMarkerData;
List<Q3D> m3DMarkerData;
List<Q3D> m3DMarkerResidualData;
List<Q3D> m3DMarkerNoLabelData;
List<Q3D> m3DMarkerNoLabelResidualData;
List<Q6DOF> m6DOFData;
List<Q6DOF> m6DOFResidualData;
List<Q6DOFEuler> m6DOFEulerData;
List<Q6DOFEuler> m6DOFEulerResidualData;
List<Analog> mAnalogData;
List<Analog> mAnalogSingleData;
List<ForcePlate> mForcePlateData;
List<ForcePlate> mForceSinglePlateData;
List<CameraImage> mImageData;
List<GazeVector> mGazeVectorData;
List<EyeTracker> mEyeTrackerData;
List<Timecode> mTimecodeData;
List<Skeleton> mSkeletonData;
/// <summary>
/// Private constructor only used for static error packet.
/// </summary>
/// <param name="type"></param>
private RTPacket(PacketType type)
{
mPacketType = type;
}
/// <summary>
/// Constructor for packet.
/// </summary>
/// <param name="majorVersion">Major version of packet, default is latest version.</param>
/// <param name="minorVersion">Minor version of packet, default is latest version.</param>
public RTPacket(int majorVersion = RTProtocol.Constants.MAJOR_VERSION, int minorVersion = RTProtocol.Constants.MINOR_VERSION)
{
mMajorVersion = majorVersion;
mMinorVersion = minorVersion;
m2DMarkerData = new List<Camera>();
m2DLinearizedMarkerData = new List<Camera>();
m3DMarkerData = new List<Q3D>();
m3DMarkerResidualData = new List<Q3D>();
m3DMarkerNoLabelData = new List<Q3D>();
m3DMarkerNoLabelResidualData = new List<Q3D>();
m6DOFData = new List<Q6DOF>();
m6DOFResidualData = new List<Q6DOF>();
m6DOFEulerData = new List<Q6DOFEuler>();
m6DOFEulerResidualData = new List<Q6DOFEuler>();
mAnalogData = new List<Analog>();
mAnalogSingleData = new List<Analog>();
mForcePlateData = new List<ForcePlate>();
mForceSinglePlateData = new List<ForcePlate>();
mImageData = new List<CameraImage>();
mGazeVectorData = new List<GazeVector>();
mEyeTrackerData = new List<EyeTracker>();
mTimecodeData = new List<Timecode>();
mSkeletonData = new List<Skeleton>();
ClearData();
}
/// <summary>
/// Get version of packet.
/// </summary>
/// <param name="majorVersion">Major version of packet.</param>
/// <param name="minorVersion">Minor version of packet.</param>
public void GetVersion(ref int majorVersion, ref int minorVersion)
{
majorVersion = mMajorVersion;
minorVersion = mMinorVersion;
}
/// <summary>
/// Clear packet from data.
/// </summary>
private void ClearData()
{
mData = null;
mPacketSize = -1;
mPacketType = PacketType.PacketNone;
mTimestamp = -1;
mFrameNumber = -1;
m2DMarkerData.Clear();
m2DLinearizedMarkerData.Clear();
m3DMarkerData.Clear();
m3DMarkerResidualData.Clear();
m3DMarkerNoLabelData.Clear();
m3DMarkerNoLabelResidualData.Clear();
m6DOFData.Clear();
m6DOFResidualData.Clear();
m6DOFEulerData.Clear();
m6DOFEulerResidualData.Clear();
mAnalogData.Clear();
mAnalogSingleData.Clear();
mForcePlateData.Clear();
mForceSinglePlateData.Clear();
mImageData.Clear();
mGazeVectorData.Clear();
mEyeTrackerData.Clear();
mTimecodeData.Clear();
mSkeletonData.Clear();
}
private Object packetLock = new Object();
#region Set packet data function
/// <summary>
/// Set the data of packet.
/// </summary>
/// <param name="data">byte data recieved from server</param>
internal void SetData(byte[] data)
{
/* === Data packet setup ===
* Packet size - 4 bytes
* packet type - 4 bytes
* timestamp - 8 bytes
* Component count - 4 bytes
* [for each component]
* Component size - 4 bytes
* Component type - 4 bytes
* Component Data - [Component size] bytes
*/
lock (packetLock)
{
ClearData();
mData = data;
SetPacketHeader(mData);
if (mPacketType == PacketType.PacketData)
{
mTimestamp = BitConverter.ToInt64(mData, RTProtocol.Constants.PACKET_HEADER_SIZE);
mFrameNumber = BitConverter.ToInt32(mData, RTProtocol.Constants.PACKET_HEADER_SIZE + 8);
var components = BitConverter.ToInt32(mData, RTProtocol.Constants.PACKET_HEADER_SIZE + 12);
int position = RTProtocol.Constants.PACKET_HEADER_SIZE + RTProtocol.Constants.DATA_PACKET_HEADER_SIZE;
for (int component = 1; component <= components; component++)
{
ComponentType componentType = GetComponentType(position);
position += RTProtocol.Constants.COMPONENT_HEADER;
if (componentType == ComponentType.Component3d)
{
/* Marker count - 4 bytes
* 2D Drop rate - 2 bytes
* 2D Out of sync rate - 2 bytes
* [Repeated per marker]
* X - 4 bytes
* Y - 4 bytes
* Z - 4 bytes
*/
uint markerCount = BitConvert.GetUInt32(mData, ref position);
m2DDropRate = BitConvert.GetUShort(mData, ref position);
m2DOutOfSyncRate = BitConvert.GetUShort(mData, ref position);
for (int i = 0; i < markerCount; i++)
{
Q3D marker = new Q3D();
marker.Id = 0;
marker.Residual = -1;
marker.Position = BitConvert.GetPoint(mData, ref position);
m3DMarkerData.Add(marker);
}
}
else if (componentType == ComponentType.Component3dNoLabels)
{
/* Marker count - 4 bytes
* 2D Drop rate - 2 bytes
* 2D Out of sync rate - 2 bytes
* [Repeated per marker]
* X - 4 bytes
* Y - 4 bytes
* Z - 4 bytes
* ID - 4 bytes
*/
int markerCount = BitConvert.GetInt32(mData, ref position);
m2DDropRate = BitConvert.GetUShort(mData, ref position);
m2DOutOfSyncRate = BitConvert.GetUShort(mData, ref position);
for (int i = 0; i < markerCount; i++)
{
Q3D marker = new Q3D();
marker.Residual = -1;
marker.Position = BitConvert.GetPoint(mData, ref position);
marker.Id = BitConvert.GetUInt32(mData, ref position);
m3DMarkerNoLabelData.Add(marker);
}
}
else if (componentType == ComponentType.ComponentAnalog)
{
/* Analog Device count - 4 bytes
* [Repeated per device]
* Device id - 4 bytes
* Channel count - 4 bytes
* Sample count - 4 bytes
* Sample number - 4 bytes
* Analog data - 4 * channelcount * sampleCount
*/
uint deviceCount = BitConvert.GetUInt32(mData, ref position);
for (int i = 0; i < deviceCount; i++)
{
Analog analogDeviceData = new Analog();
analogDeviceData.DeviceID = BitConvert.GetUInt32(mData, ref position);
analogDeviceData.ChannelCount = BitConvert.GetUInt32(mData, ref position);
analogDeviceData.Channels = new AnalogChannelData[analogDeviceData.ChannelCount];
uint sampleCount = BitConvert.GetUInt32(mData, ref position);
analogDeviceData.SampleNumber = BitConvert.GetUInt32(mData, ref position);
if (sampleCount > 0)
{
for (uint j = 0; j < analogDeviceData.ChannelCount; j++)
{
AnalogChannelData analogChannelData = new AnalogChannelData();
analogChannelData.Samples = new float[sampleCount];
for (uint k = 0; k < sampleCount; k++)
{
analogChannelData.SampleNumber = analogDeviceData.SampleNumber + k;
analogChannelData.Samples[k] = BitConvert.GetFloat(mData, ref position);
}
analogDeviceData.Channels[j] = analogChannelData;
}
}
else
{
for (uint j = 0; j < analogDeviceData.ChannelCount; j++)
{
AnalogChannelData analogChannelData = new AnalogChannelData();
analogChannelData.Samples = new float[0];
analogChannelData.SampleNumber = 0;
analogDeviceData.Channels[j] = analogChannelData;
}
}
mAnalogData.Add(analogDeviceData);
}
}
else if (componentType == ComponentType.ComponentForce)
{
/* Force plate count - 4 bytes
* [Repeated per plate]
* Force plate ID - 4 bytes
* Force count - 4 bytes
* forceNumber - 4 bytes
* Force data - 36 * force count bytes
*/
int forcePlateCount = BitConvert.GetInt32(mData, ref position);
for (int i = 0; i < forcePlateCount; i++)
{
ForcePlate plate = new ForcePlate();
plate.PlateId = BitConvert.GetInt32(mData, ref position);
plate.ForceCount = BitConvert.GetInt32(mData, ref position);
plate.ForceNumber = BitConvert.GetInt32(mData, ref position);
plate.ForceSamples = new ForceSample[plate.ForceCount];
for (int j = 0; j < plate.ForceCount; j++)
{
ForceSample sample;
sample.Force = BitConvert.GetPoint(mData, ref position);
sample.Moment = BitConvert.GetPoint(mData, ref position);
sample.ApplicationPoint = BitConvert.GetPoint(mData, ref position);
plate.ForceSamples[j] = sample;
}
mForcePlateData.Add(plate);
}
}
else if (componentType == ComponentType.Component6d)
{
/* Body count - 4 bytes
* 2D Drop rate - 2 bytes
* 2D Out of sync rate - 2 bytes
* [Repeated per body]
* X - 4 bytes
* Y - 4 bytes
* Z - 4 bytes
* rotation matrix - 9*4 bytes
*/
int bodyCount = BitConvert.GetInt32(mData, ref position);
m2DDropRate = BitConvert.GetUShort(mData, ref position);
m2DOutOfSyncRate = BitConvert.GetUShort(mData, ref position);
for (int i = 0; i < bodyCount; i++)
{
Q6DOF body = new Q6DOF();
body.Position = BitConvert.GetPoint(mData, ref position);
body.Matrix = new float[9];
for (int j = 0; j < 9; j++)
{
body.Matrix[j] = BitConvert.GetFloat(mData, ref position);
}
body.Residual = -1;
m6DOFData.Add(body);
}
}
else if (componentType == ComponentType.Component6dEuler)
{
/* Body count - 4 bytes
* 2D Drop rate - 2 bytes
* 2D Out of sync rate - 2 bytes
* [Repeated per body]
* X - 4 bytes
* Y - 4 bytes
* Z - 4 bytes
* Euler Angles - 3*4 bytes
*/
int bodyCount = BitConvert.GetInt32(mData, ref position);
m2DDropRate = BitConvert.GetUShort(mData, ref position);
m2DOutOfSyncRate = BitConvert.GetUShort(mData, ref position);
for (int i = 0; i < bodyCount; i++)
{
Q6DOFEuler body = new Q6DOFEuler();
body.Position = BitConvert.GetPoint(mData, ref position);
body.Rotation = BitConvert.GetEulerRotation(mData, ref position);
body.Residual = -1;
m6DOFEulerData.Add(body);
}
}
else if (componentType == ComponentType.Component2d || componentType == ComponentType.Component2dLinearized)
{
/* Camera Count - 4 bytes
* 2D Drop rate - 2 bytes
* 2D Out of sync rate - 2 bytes
* [Repeated per Camera]
* Marker Count - 4 bytes
* Status Flags - 1 byte
* [Repeated per Marker]
* X - 4 Bytes
* Y - 4 Bytes
* Diameter X - 4 bytes
* Diameter Y - 4 bytes
*/
uint cameraCount = BitConvert.GetUInt32(mData, ref position);
m2DDropRate = BitConvert.GetUShort(mData, ref position);
m2DOutOfSyncRate = BitConvert.GetUShort(mData, ref position);
for (int i = 0; i < cameraCount; i++)
{
Camera camera = new Camera();
camera.MarkerCount = BitConvert.GetUInt32(mData, ref position);
camera.StatusFlags = mData[position++];
camera.MarkerData2D = new Q2D[camera.MarkerCount];
for (int j = 0; j < camera.MarkerCount; j++)
{
Q2D marker = new Q2D();
marker.X = BitConvert.GetUInt32(mData, ref position);
marker.Y = BitConvert.GetUInt32(mData, ref position);
marker.DiameterX = BitConvert.GetUShort(mData, ref position);
marker.DiameterY = BitConvert.GetUShort(mData, ref position);
camera.MarkerData2D[j] = marker;
}
if (componentType == ComponentType.Component2d)
m2DMarkerData.Add(camera);
else if (componentType == ComponentType.Component2dLinearized)
m2DLinearizedMarkerData.Add(camera);
}
}
else if (componentType == ComponentType.Component3dResidual)
{
/* Marker count - 4 bytes
* 2D Drop rate - 2 bytes
* 2D Out of sync rate - 2 bytes
* [Repeated per marker]
* X - 4 bytes
* Y - 4 bytes
* Z - 4 bytes
* Residual - 4 bytes
*/
int markerCount = BitConvert.GetInt32(mData, ref position);
m2DDropRate = BitConvert.GetUShort(mData, ref position);
m2DOutOfSyncRate = BitConvert.GetUShort(mData, ref position);
for (int i = 0; i < markerCount; i++)
{
Q3D marker = new Q3D();
marker.Id = 0;
marker.Position = BitConvert.GetPoint(mData, ref position);
marker.Residual = BitConvert.GetFloat(mData, ref position);
m3DMarkerResidualData.Add(marker);
}
}
else if (componentType == ComponentType.Component3dNoLabelsResidual)
{
/* Marker count - 4 bytes
* 2D Drop rate - 2 bytes
* 2D Out of sync rate - 2 bytes
* [Repeated per marker]
* X - 4 bytes
* Y - 4 bytes
* Z - 4 bytes
* ID - 4 bytes
* Residual - 4 bytes
*/
int markerCount = BitConvert.GetInt32(mData, ref position);
m2DDropRate = BitConvert.GetUShort(mData, ref position);
m2DOutOfSyncRate = BitConvert.GetUShort(mData, ref position);
for (int i = 0; i < markerCount; i++)
{
Q3D marker = new Q3D();
marker.Position = BitConvert.GetPoint(mData, ref position);
marker.Id = BitConvert.GetUInt32(mData, ref position);
marker.Residual = BitConvert.GetFloat(mData, ref position);
m3DMarkerNoLabelResidualData.Add(marker);
}
}
else if (componentType == ComponentType.Component6dResidual)
{
/* Body count - 4 bytes
* 2D Drop rate - 2 bytes
* 2D Out of sync rate - 2 bytes
* [Repeated per marker]
* X - 4 bytes
* Y - 4 bytes
* Z - 4 bytes
* rotation matrix - 9*4 bytes
* residual - 9*4 bytes
*/
int bodyCount = BitConvert.GetInt32(mData, ref position);
m2DDropRate = BitConvert.GetUShort(mData, ref position);
m2DOutOfSyncRate = BitConvert.GetUShort(mData, ref position);
for (int i = 0; i < bodyCount; i++)
{
Q6DOF body = new Q6DOF();
body.Position = BitConvert.GetPoint(mData, ref position);
body.Matrix = new float[9];
for (int j = 0; j < 9; j++)
body.Matrix[j] = BitConvert.GetFloat(mData, ref position);
body.Residual = BitConvert.GetFloat(mData, ref position); ;
m6DOFResidualData.Add(body);
}
}
else if (componentType == ComponentType.Component6dEulerResidual)
{
/* Body count - 4 bytes
* 2D Drop rate - 2 bytes
* 2D Out of sync rate - 2 bytes
* [Repeated per marker]
* X - 4 bytes
* Y - 4 bytes
* Z - 4 bytes
* Euler Angles - 3*4 bytes
* residual - 9*4 bytes
*/
int bodyCount = BitConvert.GetInt32(mData, ref position);
m2DDropRate = BitConvert.GetUShort(mData, ref position);
m2DOutOfSyncRate = BitConvert.GetUShort(mData, ref position);
for (int i = 0; i < bodyCount; i++)
{
Q6DOFEuler body = new Q6DOFEuler();
body.Position = BitConvert.GetPoint(mData, ref position);
body.Rotation = BitConvert.GetEulerRotation(mData, ref position);
body.Residual = BitConvert.GetFloat(mData, ref position);
m6DOFEulerResidualData.Add(body);
}
}
else if (componentType == ComponentType.ComponentAnalogSingle)
{
/* Analog Device count - 4 bytes
* [Repeated per device]
* Device id - 4 bytes
* Channel count - 4 bytes
* Analog data - 4 * channelcount
*/
int deviceCount = BitConvert.GetInt32(mData, ref position);
for (int i = 0; i < deviceCount; i++)
{
Analog device = new Analog();
device.DeviceID = BitConvert.GetUInt32(mData, ref position);
device.ChannelCount = BitConvert.GetUInt32(mData, ref position);
device.Channels = new AnalogChannelData[device.ChannelCount];
for (int j = 0; j < device.ChannelCount; j++)
{
AnalogChannelData sample = new AnalogChannelData();
sample.Samples = new float[1];
sample.Samples[0] = BitConvert.GetFloat(mData, ref position);
device.Channels[j] = sample;
}
mAnalogSingleData.Add(device);
}
}
else if (componentType == ComponentType.ComponentImage)
{
/* Camera count - 4 bytes
* [Repeated per marker]
* Camera ID - 4 bytes
* Image Format - 4 bytes
* Width - 4 bytes
* Height- 4 bytes
* Left crop - 4 bytes
* Top crop - 4 bytes
* Right crop - 4 bytes
* Bottom crop - 4 bytes
* Image size- 4 bytes
* Image data - [Image size bytes]
*/
int cameraCount = BitConvert.GetInt32(mData, ref position);
for (int i = 0; i < cameraCount; i++)
{
CameraImage image = new CameraImage();
image.CameraID = BitConvert.GetUInt32(mData, ref position);
image.ImageFormat = (ImageFormat)BitConvert.GetUInt32(mData, ref position);
image.Width = BitConvert.GetUInt32(mData, ref position);
image.Height = BitConvert.GetUInt32(mData, ref position);
image.LeftCrop = BitConvert.GetFloat(mData, ref position);
image.TopCrop = BitConvert.GetFloat(mData, ref position);
image.RightCrop = BitConvert.GetFloat(mData, ref position);
image.BottomCrop = BitConvert.GetFloat(mData, ref position);
image.ImageSize = BitConvert.GetInt32(mData, ref position);
image.ImageData = new byte[image.ImageSize];
Array.Copy(mData, position, image.ImageData, 0, image.ImageSize);
position += image.ImageSize;
mImageData.Add(image);
}
}
else if (componentType == ComponentType.ComponentTimecode)
{
/* Timecode count - 4 bytes
* [Repeated per marker]
* Timecode Type - 4 bytes
* Timecode High - 4 bytes
* Timecode Low - 4 bytes
*/
int timecodeCount = BitConvert.GetInt32(mData, ref position);
for (int i = 0; i < timecodeCount; i++)
{
Timecode timecode = new Timecode();
timecode.Type = (TimecodeType)BitConvert.GetUInt32(mData, ref position);
timecode.High = BitConvert.GetUInt32(mData, ref position);
timecode.Low = BitConvert.GetUInt32(mData, ref position);
mTimecodeData.Add(timecode);
}
}
else if (componentType == ComponentType.ComponentForceSingle)
{
/* Force plate count - 4 bytes
* [Repeated per plate]
* Force plate ID - 4 bytes
* Force data - 36 bytes
*/
int forcePlateCount = BitConvert.GetInt32(mData, ref position);
for (int i = 0; i < forcePlateCount; i++)
{
ForcePlate plate = new ForcePlate();
plate.PlateId = BitConvert.GetInt32(mData, ref position);
plate.ForceCount = 1;
plate.ForceNumber = -1;
plate.ForceSamples = new ForceSample[plate.ForceCount];
plate.ForceSamples[0].Force = BitConvert.GetPoint(mData, ref position);
plate.ForceSamples[0].Moment = BitConvert.GetPoint(mData, ref position);
plate.ForceSamples[0].ApplicationPoint = BitConvert.GetPoint(mData, ref position);
mForceSinglePlateData.Add(plate);
}
}
else if (componentType == ComponentType.ComponentGazeVector)
{
/* Gaze vector count - 4 bytes