23 #include "skel_drawer.h"
26 #include <plugins/openni/utils/colors.h>
27 #include <utils/math/angle.h>
33 using namespace fawkes::openni;
46 : users_(users), hands_(hands)
52 SkelGuiSkeletonDrawer::print_string(
void *font,
char *str)
54 const int l = strlen(str);
55 for (
int i = 0; i < l; ++i)
56 glutBitmapCharacter(font, *str++);
60 SkelGuiSkeletonDrawer::draw_limb(
float *proj1,
float conf1,
float *proj2,
float conf2)
62 if (conf1 < 0.5 || conf2 < 0.5)
65 glVertex3i(proj1[0], proj1[1], 0);
66 glVertex3i(proj2[0], proj2[1], 0);
69 #define DRAW_LIMB(user, joint1, joint2) \
70 draw_limb(user.proj_if->proj_##joint1(), \
71 user.skel_if->pos_##joint1##_confidence(), \
72 user.proj_if->proj_##joint2(), \
73 user.skel_if->pos_##joint2##_confidence());
76 SkelGuiSkeletonDrawer::draw_user(
UserInfo &user)
78 if (user.
skel_if->
state() != HumanSkeletonInterface::STATE_TRACKING)
81 DRAW_LIMB(user, head, neck);
83 DRAW_LIMB(user, neck, left_shoulder);
84 DRAW_LIMB(user, left_shoulder, left_elbow);
85 DRAW_LIMB(user, left_elbow, left_hand);
87 DRAW_LIMB(user, neck, right_shoulder);
88 DRAW_LIMB(user, right_shoulder, right_elbow);
89 DRAW_LIMB(user, right_elbow, right_hand);
91 DRAW_LIMB(user, left_shoulder, torso);
92 DRAW_LIMB(user, right_shoulder, torso);
94 DRAW_LIMB(user, torso, left_hip);
95 DRAW_LIMB(user, left_hip, left_knee);
96 DRAW_LIMB(user, left_knee, left_foot);
98 DRAW_LIMB(user, torso, right_hip);
99 DRAW_LIMB(user, right_hip, right_knee);
100 DRAW_LIMB(user, right_knee, right_foot);
102 DRAW_LIMB(user, left_hip, right_hip);
106 SkelGuiSkeletonDrawer::draw_circle(
unsigned int id,
float *proj,
float radius)
108 glBegin(GL_LINE_LOOP);
109 glVertex2f(proj[0], proj[1]);
110 glColor4f(1 - USER_COLORS[
id % NUM_USER_COLORS][0],
111 1 - USER_COLORS[
id % NUM_USER_COLORS][1],
112 1 - USER_COLORS[
id % NUM_USER_COLORS][2],
114 for (
int i = 0; i < 360; ++i) {
117 glVertex2f(proj[0] + cos(rad) * radius, proj[1] + sin(rad) * radius);
119 glColor4f(1, 1, 1, 1);
128 for (UserMap::iterator i = users_.begin(); i != users_.end(); ++i) {
129 if (i->second.skel_if->state() != HumanSkeletonInterface::STATE_INVALID) {
131 memset(label, 0,
sizeof(label));
133 sprintf(label,
"%s", i->first.c_str());
134 }
else if (i->second.skel_if->state() == HumanSkeletonInterface::STATE_TRACKING) {
135 sprintf(label,
"%s - Tracking", i->first.c_str());
136 }
else if (i->second.skel_if->state() == HumanSkeletonInterface::STATE_CALIBRATING) {
137 sprintf(label,
"%s - Calibrating...", i->first.c_str());
139 sprintf(label,
"%s - Looking for pose", i->first.c_str());
142 glColor4f(1 - USER_COLORS[i->second.skel_if->user_id() % NUM_USER_COLORS][0],
143 1 - USER_COLORS[i->second.skel_if->user_id() % NUM_USER_COLORS][1],
144 1 - USER_COLORS[i->second.skel_if->user_id() % NUM_USER_COLORS][2],
147 glRasterPos2i(i->second.proj_if->proj_com(0), i->second.proj_if->proj_com(1));
148 print_string(GLUT_BITMAP_HELVETICA_18, label);
152 glColor4f(1 - USER_COLORS[i->second.skel_if->user_id() % NUM_USER_COLORS][0],
153 1 - USER_COLORS[i->second.skel_if->user_id() % NUM_USER_COLORS][1],
154 1 - USER_COLORS[i->second.skel_if->user_id() % NUM_USER_COLORS][2],
157 draw_user(i->second);
162 glEnable(GL_LINE_SMOOTH);
164 for (HandMap::iterator i = hands_.begin(); i != hands_.end(); ++i) {
165 if (i->second.hand_if->is_visible()) {
166 float proj[2] = {i->second.hand_if->world_x(), i->second.hand_if->world_y()};
167 draw_circle(i->second.hand_if->world_z(), proj, 10);
171 glDisable(GL_LINE_SMOOTH);
181 switch (print_state_) {
194 glBegin(GL_LINE_LOOP);
196 print_state_ = state;
PrintState
Print state enum.
@ PRINT_ID_STATE
Print ID and state.
@ PRINT_NONE
Print neither ID nor state.
void draw()
Draw skeletons.
void set_print_state(PrintState state)
Set print state.
void toggle_print_state()
Toggle the printing state.
SkelGuiSkeletonDrawer(fawkes::openni::UserMap &users, fawkes::openni::HandMap &hands)
Constructor.
State state() const
Get state value.
Fawkes library namespace.
float deg2rad(float deg)
Convert an angle given in degrees to radians.
User info to pass to draw_skeletons().
fawkes::HumanSkeletonInterface * skel_if
Skeleton interface.