2 #include "visualization_msgs/Marker.h" 3 #include "visualization_msgs/MarkerArray.h" 5 #include "leap_motion/Human.h" 6 #include "leap_motion/Hand.h" 7 #include "leap_motion/Finger.h" 8 #include "leap_motion/Bone.h" 14 const std::string
fingerNames[] = {
"Thumb",
"Index",
"Middle",
"Ring",
"Pinky"};
28 std::string hand_ns, std::string finger_ns,
unsigned int id, geometry_msgs::Pose location ){
30 visualization_msgs::Marker joint_marker;
32 joint_marker.header.frame_id = human->header.frame_id;
33 joint_marker.header.stamp = human->header.stamp;
34 joint_marker.ns = hand_ns+
"_"+finger_ns;
36 joint_marker.type = visualization_msgs::Marker::SPHERE;
37 joint_marker.action = visualization_msgs::Marker::ADD;
40 joint_marker.pose.position.x = location.position.x;
41 joint_marker.pose.position.y = location.position.y;
42 joint_marker.pose.position.z = location.position.z;
44 joint_marker.scale.x = 0.015;
45 joint_marker.scale.y = 0.015;
46 joint_marker.scale.z = 0.015;
48 joint_marker.color.r = 1.0f;
49 joint_marker.color.g = 0.0f;
50 joint_marker.color.b = 0.0f;
51 joint_marker.color.a = 1.0f;
69 std::string hand_ns, std::string finger_ns,
unsigned int id, leap_motion::Bone current_bone){
71 visualization_msgs::Marker line_list;
72 line_list.header.frame_id = human -> header.frame_id;
73 line_list.header.stamp = human -> header.stamp;
74 line_list.ns = hand_ns +
"_" + finger_ns;
75 line_list.type = visualization_msgs::Marker::LINE_LIST;
76 line_list.action = visualization_msgs::Marker::ADD;
79 line_list.scale.x = 0.0075;
82 line_list.color.r = 1.0f;
83 line_list.color.g = 1.0f;
84 line_list.color.b = 1.0f;
85 line_list.color.a = 1.0f;
88 geometry_msgs::Point p;
89 p.x = current_bone.bone_start.position.x;
90 p.y = current_bone.bone_start.position.y;
91 p.z = current_bone.bone_start.position.z;
92 line_list.points.push_back(p);
94 p.x = current_bone.bone_end.position.x;
95 p.y = current_bone.bone_end.position.y;
96 p.z = current_bone.bone_end.position.z;
97 line_list.points.push_back(p);
114 std::string hand_ns,
unsigned int id, leap_motion::Hand current_hand){
116 visualization_msgs::Marker line_list;
117 line_list.header.frame_id = human -> header.frame_id;
118 line_list.header.stamp = human -> header.stamp;
119 line_list.ns = hand_ns;
122 line_list.type = visualization_msgs::Marker::LINE_LIST;
123 line_list.action = visualization_msgs::Marker::ADD;
125 line_list.scale.x = 0.0075;
128 line_list.color.r = 1.0f;
129 line_list.color.g = 1.0f;
130 line_list.color.b = 1.0f;
131 line_list.color.a = 1.0f;
134 for(
unsigned int j = 0; j < current_hand.finger_list.size(); j++){
136 geometry_msgs::Point p;
138 leap_motion::Finger finger = current_hand.finger_list[j];
139 leap_motion::Bone bone = finger.bone_list[0];
142 if(finger.type == Leap::Finger::Type::TYPE_THUMB)
144 p.x = bone.bone_start.position.x;
145 p.y = bone.bone_start.position.y;
146 p.z = bone.bone_start.position.z;
147 line_list.points.push_back(p);
151 finger = current_hand.finger_list[1];
152 bone = finger.bone_list[1];
153 p.x = bone.bone_start.position.x;
154 p.y = bone.bone_start.position.y;
155 p.z = bone.bone_start.position.z;
156 line_list.points.push_back(p);
159 else if(finger.type == Leap::Finger::Type::TYPE_PINKY)
161 p.x = bone.bone_start.position.x;
162 p.y = bone.bone_start.position.y;
163 p.z = bone.bone_start.position.z;
164 line_list.points.push_back(p);
166 p.x = bone.bone_end.position.x;
167 p.y = bone.bone_end.position.y;
168 p.z = bone.bone_end.position.z;
169 line_list.points.push_back(p);
172 p.x = bone.bone_start.position.x;
173 p.y = bone.bone_start.position.y;
174 p.z = bone.bone_start.position.z;
175 line_list.points.push_back(p);
177 finger = current_hand.finger_list[0];
178 bone = finger.bone_list[0];
179 p.x = bone.bone_start.position.x;
180 p.y = bone.bone_start.position.y;
181 p.z = bone.bone_start.position.z;
182 line_list.points.push_back(p);
187 leap_motion::Bone bone = finger.bone_list[1];
188 p.x = bone.bone_start.position.x;
189 p.y = bone.bone_start.position.y;
190 p.z = bone.bone_start.position.z;
191 line_list.points.push_back(p);
193 leap_motion::Finger temp_finger = current_hand.finger_list[j+1];
194 bone = temp_finger.bone_list[1];
195 p.x = bone.bone_start.position.x;
196 p.y = bone.bone_start.position.y;
197 p.z = bone.bone_start.position.z;
198 line_list.points.push_back(p);
201 geometry_msgs::Point p;
202 p.x = current_hand.arm.elbow.position.x;
203 p.y = current_hand.arm.elbow.position.y;
204 p.z = current_hand.arm.elbow.position.z;
205 line_list.points.push_back(p);
206 p.x = current_hand.arm.wrist.position.x;
207 p.y = current_hand.arm.wrist.position.y;
208 p.z = current_hand.arm.wrist.position.z;
209 line_list.points.push_back(p);
226 std::string hand_ns,
unsigned int id, geometry_msgs::Point centre_point){
228 visualization_msgs::Marker palm_centre;
229 palm_centre.header.frame_id = human -> header.frame_id;
230 palm_centre.header.stamp = human -> header.stamp;
232 palm_centre.ns = hand_ns;
234 palm_centre.type = visualization_msgs::Marker::SPHERE;
235 palm_centre.action = visualization_msgs::Marker::ADD;
238 palm_centre.pose.position.x = centre_point.x;
239 palm_centre.pose.position.y = centre_point.y;
240 palm_centre.pose.position.z = centre_point.z;
242 palm_centre.scale.x = 0.025;
243 palm_centre.scale.y = 0.025;
244 palm_centre.scale.z = 0.025;
246 palm_centre.color.r = 0.0f;
247 palm_centre.color.g = 0.0f;
248 palm_centre.color.b = 1.0f;
249 palm_centre.color.a = 1.0f;
268 void createVisualization(visualization_msgs::MarkerArray* marker_array,
const leap_motion::Human::ConstPtr& human,
269 leap_motion::Hand hand, std::string hand_ns, uint8_t hand_id){
271 marker_array->markers.push_back(
createPalmPosition(human, hand_ns, 55, hand.palm_center));
272 marker_array->markers.push_back(
createHandOutline(human, hand_ns, hand_id, hand) );
274 leap_motion::Finger finger;
275 for(
unsigned int j = 0; j < hand.finger_list.size(); j++)
277 finger = hand.finger_list[j];
279 unsigned int id_offset = finger.bone_list.size();
281 leap_motion::Bone bone;
282 for(
unsigned int k = 1; k < finger.bone_list.size(); k++)
284 bone = finger.bone_list[k];
285 marker_array->markers.push_back(
createFingerLines(human, hand_ns, ns_finger, k, bone));
286 marker_array->markers.push_back(
createJointMarker(human, hand_ns, ns_finger, k + id_offset, bone.bone_start));
289 if(finger.type == Leap::Finger::Type::TYPE_PINKY)
291 leap_motion::Bone temp_bone = finger.bone_list[0];
293 k + id_offset+1, temp_bone.bone_start));
296 if(k == Leap::Bone::Type::TYPE_DISTAL)
299 k + id_offset + 2, bone.bone_end));
312 visualization_msgs::MarkerArray marker_array;
313 leap_motion::Hand hand;
315 if( human -> right_hand.is_present )
317 hand = human -> right_hand;
321 if( human -> left_hand.is_present )
323 hand = human -> left_hand;
327 marker_pub->
publish(marker_array);
330 int main(
int argc,
char** argv) {
335 nh.
getParam(
"/enable_filter", enable_filter);
344 ROS_INFO(
"enable_filter: %s", enable_filter ?
"true" :
"false");
visualization_msgs::Marker createJointMarker(const leap_motion::Human::ConstPtr &human, std::string hand_ns, std::string finger_ns, unsigned int id, geometry_msgs::Pose location)
Adds circles at the intersection of bones.
static ros::Publisher * marker_pub
void publish(const boost::shared_ptr< M > &message) const
visualization_msgs::Marker createPalmPosition(const leap_motion::Human::ConstPtr &human, std::string hand_ns, unsigned int id, geometry_msgs::Point centre_point)
Represents the midpoint of the palm.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char **argv)
ROSCPP_DECL void spin(Spinner &spinner)
visualization_msgs::Marker createFingerLines(const leap_motion::Human::ConstPtr &human, std::string hand_ns, std::string finger_ns, unsigned int id, leap_motion::Bone current_bone)
Adds lines between the tips of the bones.
void frameCallback(const leap_motion::Human::ConstPtr &human)
Called when a new Human.msg is received.
const std::string fingerNames[]
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void createVisualization(visualization_msgs::MarkerArray *marker_array, const leap_motion::Human::ConstPtr &human, leap_motion::Hand hand, std::string hand_ns, uint8_t hand_id)
Creates a visualization of an entire hand from he wrist up.
bool getParam(const std::string &key, std::string &s) const
visualization_msgs::Marker createHandOutline(const leap_motion::Human::ConstPtr &human, std::string hand_ns, unsigned int id, leap_motion::Hand current_hand)
Creates a representation of palm.