Skip to content

Commit af1de3a

Browse files
committed
RGB Camera support (reflection-only)
1 parent 80e8ef9 commit af1de3a

File tree

4 files changed

+321
-137
lines changed

4 files changed

+321
-137
lines changed

KinectHandler/KinectHandler.h

Lines changed: 151 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -14,119 +14,155 @@ using namespace Amethyst::Plugins::Contract;
1414

1515
namespace KinectHandler
1616
{
17-
public ref class KinectJoint sealed
18-
{
19-
public:
20-
KinectJoint(const int role)
21-
{
22-
JointRole = role;
23-
}
24-
25-
property Vector3 Position;
26-
property Quaternion Orientation;
27-
28-
property int TrackingState;
29-
property int JointRole;
30-
};
31-
32-
delegate void FunctionToCallDelegate();
33-
34-
public ref class KinectHandler
35-
{
36-
private:
37-
KinectWrapper* kinect_;
38-
FunctionToCallDelegate^ function_;
39-
40-
public:
41-
KinectHandler() : kinect_(new KinectWrapper())
42-
{
43-
function_ = gcnew FunctionToCallDelegate(this, &KinectHandler::StatusChangedHandler);
44-
pin_ptr<FunctionToCallDelegate^> tmp = &function_; // Pin the function delegate
45-
46-
status_changed_event = static_cast<void(__cdecl*)()>(
47-
Marshal::GetFunctionPointerForDelegate(function_).ToPointer());
48-
}
49-
50-
virtual void StatusChangedHandler()
51-
{
52-
// implemented in the c# handler
53-
}
54-
55-
List<KinectJoint^>^ GetTrackedKinectJoints()
56-
{
57-
if (!IsInitialized) return gcnew List<KinectJoint^>;
58-
59-
const auto& positions = kinect_->skeleton_positions();
60-
const auto& orientations = kinect_->bone_orientations();
61-
const auto& states = kinect_->tracking_states();
62-
63-
auto trackedKinectJoints = gcnew List<KinectJoint^>;
64-
for each (auto v in Enum::GetValues<TrackedJointType>())
65-
{
66-
if (v == TrackedJointType::JointHandTipLeft ||
67-
v == TrackedJointType::JointHandTipRight ||
68-
v == TrackedJointType::JointThumbLeft ||
69-
v == TrackedJointType::JointThumbRight ||
70-
v == TrackedJointType::JointNeck ||
71-
v == TrackedJointType::JointManual)
72-
continue; // Skip unsupported joints
73-
74-
auto joint = gcnew KinectJoint(static_cast<int>(v));
75-
76-
joint->TrackingState =
77-
states[kinect_->KinectJointType(static_cast<int>(v))];
78-
79-
joint->Position = Vector3(
80-
positions[kinect_->KinectJointType(static_cast<int>(v))].x,
81-
positions[kinect_->KinectJointType(static_cast<int>(v))].y,
82-
positions[kinect_->KinectJointType(static_cast<int>(v))].z);
83-
84-
joint->Orientation = Quaternion(
85-
orientations[kinect_->KinectJointType(static_cast<int>(v))].absoluteRotation.rotationQuaternion.x,
86-
orientations[kinect_->KinectJointType(static_cast<int>(v))].absoluteRotation.rotationQuaternion.y,
87-
orientations[kinect_->KinectJointType(static_cast<int>(v))].absoluteRotation.rotationQuaternion.z,
88-
orientations[kinect_->KinectJointType(static_cast<int>(v))].absoluteRotation.rotationQuaternion.w);
89-
90-
trackedKinectJoints->Add(joint);
91-
}
92-
93-
return trackedKinectJoints;
94-
}
95-
96-
property bool IsInitialized
97-
{
98-
bool get() { return kinect_->is_initialized(); }
99-
}
100-
101-
property bool IsSkeletonTracked
102-
{
103-
bool get() { return kinect_->skeleton_tracked(); }
104-
}
105-
106-
property int DeviceStatus
107-
{
108-
int get() { return kinect_->status_result(); }
109-
}
110-
111-
property int ElevationAngle
112-
{
113-
int get() { return kinect_->elevation_angle(); }
114-
void set(const int value) { kinect_->elevation_angle(value); }
115-
}
116-
117-
property bool IsSettingsDaemonSupported
118-
{
119-
bool get() { return DeviceStatus == 0; }
120-
}
121-
122-
int InitializeKinect()
123-
{
124-
return kinect_->initialize();
125-
}
126-
127-
int ShutdownKinect()
128-
{
129-
return kinect_->shutdown();
130-
}
131-
};
17+
public ref class KinectJoint sealed
18+
{
19+
public:
20+
KinectJoint(const int role)
21+
{
22+
JointRole = role;
23+
}
24+
25+
property Vector3 Position;
26+
property Quaternion Orientation;
27+
28+
property int TrackingState;
29+
property int JointRole;
30+
};
31+
32+
delegate void FunctionToCallDelegate();
33+
34+
public ref class KinectHandler
35+
{
36+
private:
37+
KinectWrapper* kinect_;
38+
FunctionToCallDelegate^ function_;
39+
40+
public:
41+
KinectHandler() : kinect_(new KinectWrapper())
42+
{
43+
function_ = gcnew FunctionToCallDelegate(this, &KinectHandler::StatusChangedHandler);
44+
pin_ptr<FunctionToCallDelegate^> tmp = &function_; // Pin the function delegate
45+
46+
status_changed_event = static_cast<void(__cdecl*)()>(
47+
Marshal::GetFunctionPointerForDelegate(function_).ToPointer());
48+
}
49+
50+
virtual void StatusChangedHandler()
51+
{
52+
// implemented in the C# handler
53+
}
54+
55+
array<BYTE>^ GetImageBuffer()
56+
{
57+
if (!IsInitialized || !kinect_->camera_enabled()) return __nullptr;
58+
const auto& [unmanagedBuffer, size] = kinect_->color_buffer();
59+
if (size <= 0) return __nullptr;
60+
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
64+
}
65+
66+
List<KinectJoint^>^ GetTrackedKinectJoints()
67+
{
68+
if (!IsInitialized) return gcnew List<KinectJoint^>;
69+
70+
const auto& positions = kinect_->skeleton_positions();
71+
const auto& orientations = kinect_->bone_orientations();
72+
const auto& states = kinect_->tracking_states();
73+
74+
auto trackedKinectJoints = gcnew List<KinectJoint^>;
75+
for each (auto v in Enum::GetValues<TrackedJointType>())
76+
{
77+
if (v == TrackedJointType::JointHandTipLeft ||
78+
v == TrackedJointType::JointHandTipRight ||
79+
v == TrackedJointType::JointThumbLeft ||
80+
v == TrackedJointType::JointThumbRight ||
81+
v == TrackedJointType::JointNeck ||
82+
v == TrackedJointType::JointManual)
83+
continue; // Skip unsupported joints
84+
85+
auto joint = gcnew KinectJoint(static_cast<int>(v));
86+
87+
joint->TrackingState =
88+
states[kinect_->KinectJointType(static_cast<int>(v))];
89+
90+
joint->Position = Vector3(
91+
positions[kinect_->KinectJointType(static_cast<int>(v))].x,
92+
positions[kinect_->KinectJointType(static_cast<int>(v))].y,
93+
positions[kinect_->KinectJointType(static_cast<int>(v))].z);
94+
95+
joint->Orientation = Quaternion(
96+
orientations[kinect_->KinectJointType(static_cast<int>(v))].absoluteRotation.rotationQuaternion.x,
97+
orientations[kinect_->KinectJointType(static_cast<int>(v))].absoluteRotation.rotationQuaternion.y,
98+
orientations[kinect_->KinectJointType(static_cast<int>(v))].absoluteRotation.rotationQuaternion.z,
99+
orientations[kinect_->KinectJointType(static_cast<int>(v))].absoluteRotation.rotationQuaternion.w);
100+
101+
trackedKinectJoints->Add(joint);
102+
}
103+
104+
return trackedKinectJoints;
105+
}
106+
107+
property bool IsInitialized
108+
{
109+
bool get() { return kinect_->is_initialized(); }
110+
}
111+
112+
property bool IsSkeletonTracked
113+
{
114+
bool get() { return kinect_->skeleton_tracked(); }
115+
}
116+
117+
property int DeviceStatus
118+
{
119+
int get() { return kinect_->status_result(); }
120+
}
121+
122+
property int ElevationAngle
123+
{
124+
int get() { return kinect_->elevation_angle(); }
125+
void set(const int value) { kinect_->elevation_angle(value); }
126+
}
127+
128+
property bool IsCameraEnabled
129+
{
130+
bool get() { return kinect_->camera_enabled(); }
131+
void set(const bool value) { kinect_->camera_enabled(value); }
132+
}
133+
134+
property bool IsSettingsDaemonSupported
135+
{
136+
bool get() { return DeviceStatus == 0; }
137+
}
138+
139+
property int CameraImageWidth
140+
{
141+
int get() { return kinect_->CameraImageSize().first; }
142+
}
143+
144+
property int CameraImageHeight
145+
{
146+
int get() { return kinect_->CameraImageSize().second; }
147+
}
148+
149+
Drawing::Size MapCoordinate(Vector3 position)
150+
{
151+
if (!IsInitialized) return Drawing::Size::Empty;
152+
const auto& [width, height] =
153+
kinect_->MapCoordinate(_Vector4{position.X, position.Y, position.Z, 1.0f});
154+
155+
return Drawing::Size(width, height);
156+
}
157+
158+
int InitializeKinect()
159+
{
160+
return kinect_->initialize();
161+
}
162+
163+
int ShutdownKinect()
164+
{
165+
return kinect_->shutdown();
166+
}
167+
};
132168
}

0 commit comments

Comments
 (0)