1717
1818// Global instance pointer
1919matleap::frame_grabber *fg = 0 ;
20+ int version = 3 ; // 1: orig, 2: with arm info, 3: with more hand info
2021
2122// Exit function
2223void matleap_exit ()
@@ -134,7 +135,8 @@ void get_frame (int nlhs, mxArray *plhs[])
134135 " id" ,
135136 " timestamp" ,
136137 " pointables" ,
137- " hands"
138+ " hands" ,
139+ " version"
138140 };
139141 int frame_fields = sizeof (frame_field_names) / sizeof (*frame_field_names);
140142 plhs[0 ] = mxCreateStructMatrix (1 , 1 , frame_fields, frame_field_names);
@@ -221,7 +223,13 @@ void get_frame (int nlhs, mxArray *plhs[])
221223 " stabilized_palm_position" , // 15
222224
223225 " time_visible" , // 16
224- " wrist_position" // 17
226+ " wrist_position" , // 17
227+
228+ " arm_elbowPosition" , // 18
229+ " arm_wristPosition" , // 19
230+ " arm_direction" , // 20
231+
232+ " fingers" // 21
225233 };
226234
227235
@@ -230,8 +238,8 @@ void get_frame (int nlhs, mxArray *plhs[])
230238 mxSetFieldByNumber (plhs[0 ], 0 , 3 , p);
231239 // 3 because hands is the third (fourth) field name in
232240 // the overall struct we are creating.
233-
234- for (size_t i = 0 ; i < f.hands .count (); ++i)
241+
242+ for (int i = 0 ; i < f.hands .count (); ++i)
235243 {
236244 // one by one, get the fields for the hand
237245 mxSetFieldByNumber (p, i, 0 , mxCreateDoubleScalar (f.hands [i].id ()));
@@ -263,8 +271,74 @@ void get_frame (int nlhs, mxArray *plhs[])
263271 mxSetFieldByNumber (p, i, 16 , mxCreateDoubleScalar (f.hands [i].timeVisible ()));
264272
265273 mxSetFieldByNumber (p, i, 17 , create_and_fill (f.hands [i].wristPosition ()));
274+
275+ // get arm position
276+ Leap::Arm arm = f.hands [i].arm ();
277+ mxSetFieldByNumber (p, i, 18 , create_and_fill (arm.elbowPosition ()));
278+ mxSetFieldByNumber (p, i, 19 , create_and_fill (arm.wristPosition ()));
279+ mxSetFieldByNumber (p, i, 20 , create_and_fill (arm.direction ()));
280+
281+ // get bones for all fingers
282+ const char *finger_field_names[] =
283+ {
284+ " finger_type" , // 0
285+ " bones" // 1
286+ };
287+ int finger_fields = sizeof (finger_field_names) / sizeof (*finger_field_names);
288+ Leap::FingerList fingers = f.hands [i].fingers ();
289+ mxArray *f = mxCreateStructMatrix (1 , 5 , finger_fields, finger_field_names);
290+ mxSetFieldByNumber (p, 0 , 21 , f);
291+
292+ int finger_index = 0 ;
293+ for (Leap::FingerList::const_iterator fl = fingers.begin (); fl != fingers.end (); fl++) {
294+
295+ mxSetFieldByNumber (f, 0 , finger_index, mxCreateDoubleScalar ((*fl).type ())); // finger_type
296+
297+ const char *bone_field_names[] =
298+ {
299+ " basis" , // 0
300+ " center" , // 1
301+ " direction" ,// 2
302+
303+ " is_valid" , // 3
304+
305+ " length" , // 4
306+ " width" , // 5
307+ " nextJoint" ,// 6
308+ " prevJoint" ,// 7
309+
310+ " type" // 8
311+ };
312+ int bone_fields = sizeof (bone_field_names) / sizeof (*bone_field_names);
313+ mxArray *bones = mxCreateStructMatrix (1 , 4 , bone_fields, bone_field_names);
314+ mxSetFieldByNumber (f, 0 , finger_index, bones);
315+
316+ Leap::Bone bone;
317+ Leap::Bone::Type boneType;
318+ for (int bi = 0 ; bi < 4 ; bi++)
319+ {
320+ // WATCH OUT: bones can be invalid(?)
321+ boneType = static_cast <Leap::Bone::Type>(bi);
322+ bone = (*fl).bone (boneType);
323+
324+ mxSetFieldByNumber (bones,bi,0 ,create_and_fill (bone.basis ())); // 0
325+ mxSetFieldByNumber (bones,bi,1 ,create_and_fill (bone.center ())); // 1
326+ mxSetFieldByNumber (bones,bi,2 ,create_and_fill (bone.direction ())); // 2
327+ mxSetFieldByNumber (bones,bi,3 ,mxCreateDoubleScalar (bone.isValid ()));
328+ mxSetFieldByNumber (bones,bi,4 ,mxCreateDoubleScalar (bone.length ()));
329+ mxSetFieldByNumber (bones,bi,5 ,mxCreateDoubleScalar (bone.width ()));
330+ mxSetFieldByNumber (bones,bi,5 ,create_and_fill (bone.nextJoint ()));
331+ mxSetFieldByNumber (bones,bi,5 ,create_and_fill (bone.prevJoint ()));
332+ mxSetFieldByNumber (bones,bi,6 ,mxCreateDoubleScalar (boneType));
333+
334+ }
335+ finger_index = finger_index + 1 ;
336+ }
337+
266338 } // re: for f.hands.count()
267339 } // re: if f.hands.count() > 0
340+
341+ mxSetFieldByNumber (plhs[0 ], 0 , 4 , mxCreateDoubleScalar (version));
268342}
269343
270344void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
@@ -280,20 +354,20 @@ void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
280354 {
281355 // turn on debug
282356 case -1 :
283- fg->set_debug (true );
284- return ;
285- // get version
357+ fg->set_debug (true );
358+ return ;
359+ // get version
286360 case 0 :
287- plhs[0 ] = mxCreateNumericMatrix (1 , 2 , mxDOUBLE_CLASS, mxREAL);
288- *(mxGetPr (plhs[0 ]) + 0 ) = MAJOR_REVISION;
289- *(mxGetPr (plhs[0 ]) + 1 ) = MINOR_REVISION;
290- return ;
291- // get frame
361+ plhs[0 ] = mxCreateNumericMatrix (1 , 2 , mxDOUBLE_CLASS, mxREAL);
362+ *(mxGetPr (plhs[0 ]) + 0 ) = MAJOR_REVISION;
363+ *(mxGetPr (plhs[0 ]) + 1 ) = MINOR_REVISION;
364+ return ;
365+ // get frame
292366 case 1 :
293- get_frame (nlhs, plhs);
294- return ;
367+ get_frame (nlhs, plhs);
368+ return ;
295369 default :
296- // this is a logic error
297- mexErrMsgTxt (" unknown error: please contact developer" );
370+ // this is a logic error
371+ mexErrMsgTxt (" unknown error: please contact developer" );
298372 }
299373}
0 commit comments