@@ -10,10 +10,39 @@ using namespace Collections::Generic;
1010using namespace ComponentModel ::Composition;
1111using namespace Runtime ::InteropServices;
1212
13- using namespace Amethyst ::Plugins::Contract;
14-
1513namespace KinectHandler
1614{
15+ private enum TrackedJointTypeInternal
16+ {
17+ JointHead,
18+ JointNeck,
19+ JointSpineShoulder,
20+ JointShoulderLeft,
21+ JointElbowLeft,
22+ JointWristLeft,
23+ JointHandLeft,
24+ JointHandTipLeft,
25+ JointThumbLeft,
26+ JointShoulderRight,
27+ JointElbowRight,
28+ JointWristRight,
29+ JointHandRight,
30+ JointHandTipRight,
31+ JointThumbRight,
32+ JointSpineMiddle,
33+ JointSpineWaist,
34+ JointHipLeft,
35+ JointKneeLeft,
36+ JointFootLeft,
37+ JointFootTipLeft,
38+ JointHipRight,
39+ JointKneeRight,
40+ JointFootRight,
41+ JointFootTipRight,
42+ JointManual,
43+ JointCount
44+ };
45+
1746 public ref class KinectJoint sealed
1847 {
1948 public:
@@ -36,12 +65,13 @@ namespace KinectHandler
3665 private:
3766 KinectWrapper* kinect_;
3867 FunctionToCallDelegate^ function_;
68+ array<BYTE>^ managed_buffer_ = nullptr ;
3969
4070 public:
4171 KinectHandler () : kinect_(new KinectWrapper())
4272 {
4373 function_ = gcnew FunctionToCallDelegate (this , &KinectHandler::StatusChangedHandler);
44- pin_ptr<FunctionToCallDelegate^> tmp = &function_; // Pin the function delegate
74+ [[maybe_unused]] pin_ptr<FunctionToCallDelegate^> tmp = &function_; // Pin the function delegate
4575
4676 status_changed_event = static_cast <void (__cdecl*)()>(
4777 Marshal::GetFunctionPointerForDelegate (function_).ToPointer ());
@@ -58,9 +88,11 @@ namespace KinectHandler
5888 const auto & [unmanagedBuffer, size] = kinect_->color_buffer ();
5989 if (!unmanagedBuffer || size <= 0 ) return __nullptr;
6090
61- auto data = gcnew array<byte>(size); // Managed image placeholder
62- Marshal::Copy (IntPtr (unmanagedBuffer), data, 0 , size);
63- return data; // Return managed array of bytes for our camera image
91+ if (managed_buffer_ == nullptr || managed_buffer_->Length != size)
92+ managed_buffer_ = gcnew array<BYTE>(size); // allocate once
93+
94+ Marshal::Copy (IntPtr (unmanagedBuffer), managed_buffer_, 0 , size);
95+ return managed_buffer_;
6496 }
6597
6698 List<KinectJoint^>^ GetTrackedKinectJoints()
@@ -71,26 +103,26 @@ namespace KinectHandler
71103 const auto & orientations = kinect_->bone_orientations ();
72104
73105 auto trackedKinectJoints = gcnew List<KinectJoint^>;
74- for each (auto v in Enum::GetValues<TrackedJointType>() )
106+ for (auto v = 0 ; v < JointCount; v++ )
75107 {
76- if (v == TrackedJointType:: JointManual)
108+ if (v == JointManual)
77109 continue ; // Skip unsupported joints
78110
79- auto joint = gcnew KinectJoint (static_cast < int >(v) );
111+ auto joint = gcnew KinectJoint (v );
80112
81113 joint->TrackingState =
82- positions[kinect_->KinectJointType (static_cast < int >(v) )].TrackingState ;
114+ positions[kinect_->KinectJointType (v )].TrackingState ;
83115
84116 joint->Position = Vector3 (
85- positions[kinect_->KinectJointType (static_cast < int >(v) )].Position .X ,
86- positions[kinect_->KinectJointType (static_cast < int >(v) )].Position .Y ,
87- positions[kinect_->KinectJointType (static_cast < int >(v) )].Position .Z );
117+ positions[kinect_->KinectJointType (v )].Position .X ,
118+ positions[kinect_->KinectJointType (v )].Position .Y ,
119+ positions[kinect_->KinectJointType (v )].Position .Z );
88120
89121 joint->Orientation = Quaternion (
90- orientations[kinect_->KinectJointType (static_cast < int >(v) )].Orientation .x ,
91- orientations[kinect_->KinectJointType (static_cast < int >(v) )].Orientation .y ,
92- orientations[kinect_->KinectJointType (static_cast < int >(v) )].Orientation .z ,
93- orientations[kinect_->KinectJointType (static_cast < int >(v) )].Orientation .w );
122+ orientations[kinect_->KinectJointType (v )].Orientation .x ,
123+ orientations[kinect_->KinectJointType (v )].Orientation .y ,
124+ orientations[kinect_->KinectJointType (v )].Orientation .z ,
125+ orientations[kinect_->KinectJointType (v )].Orientation .w );
94126
95127 trackedKinectJoints->Add (joint);
96128 }
@@ -129,11 +161,6 @@ namespace KinectHandler
129161 void set (const bool value) { kinect_->camera_enabled (value); }
130162 }
131163
132- property bool IsSettingsDaemonSupported
133- {
134- bool get () { return DeviceStatus == 0 ; }
135- }
136-
137164 property int CameraImageWidth
138165 {
139166 int get () { return kinect_->CameraImageSize ().first ; }
0 commit comments