/// @brief get a frame from the leap controller /// /// @param nlhs matlab mex output interface /// @param plhs[] matlab mex output interface void get_frame (int nlhs, mxArray *plhs[]) { // get the frame const matleap::frame &f = fg->get_frame (); // create matlab frame struct const char *frame_field_names[] = { "id", "timestamp", "pointables", "hands" }; int frame_fields = sizeof (frame_field_names) / sizeof (*frame_field_names); plhs[0] = mxCreateStructMatrix (1, 1, frame_fields, frame_field_names); // fill the frame struct mxSetFieldByNumber (plhs[0], 0, 0, mxCreateDoubleScalar (f.id)); mxSetFieldByNumber (plhs[0], 0, 1, mxCreateDoubleScalar (f.timestamp)); // create the pointables structs if (f.pointables.count () > 0) { const char *pointable_field_names[] = { "id", "position", "velocity", "direction", "is_extended", "is_finger", "is_tool", "is_valid", "length", "width", "touch_distance", "time_visible" }; int pointable_fields = sizeof (pointable_field_names) / sizeof (*pointable_field_names); mxArray *p = mxCreateStructMatrix (1, f.pointables.count (), pointable_fields, pointable_field_names); mxSetFieldByNumber (plhs[0], 0, 2, p); // fill the pointables structs for (size_t i = 0; i < f.pointables.count (); ++i) { // set the id mxSetFieldByNumber (p, i, 0, mxCreateDoubleScalar (f.pointables[i].id ())); // create and fill arrays for vectors mxArray *pos = create_and_fill (f.pointables[i].tipPosition ()); mxArray *vel = create_and_fill (f.pointables[i].tipVelocity ()); mxArray *dir = create_and_fill (f.pointables[i].direction ()); // set them in the struct mxSetFieldByNumber (p, i, 1, pos); mxSetFieldByNumber (p, i, 2, vel); mxSetFieldByNumber (p, i, 3, dir); mxSetFieldByNumber (p, i, 4, mxCreateDoubleScalar (f.pointables[i].isExtended ())); mxSetFieldByNumber (p, i, 5, mxCreateDoubleScalar (f.pointables[i].isFinger ())); mxSetFieldByNumber (p, i, 6, mxCreateDoubleScalar (f.pointables[i].isTool ())); mxSetFieldByNumber (p, i, 7, mxCreateDoubleScalar (f.pointables[i].isValid ())); mxSetFieldByNumber (p, i, 8, mxCreateDoubleScalar (f.pointables[i].length ())); mxSetFieldByNumber (p, i, 9, mxCreateDoubleScalar (f.pointables[i].width ())); mxSetFieldByNumber (p, i, 10, mxCreateDoubleScalar (f.pointables[i].touchDistance ())); mxSetFieldByNumber (p, i, 11, mxCreateDoubleScalar (f.pointables[i].timeVisible ())); } } if (f.hands.count () > 0) { const char *hand_field_names[] = { "id", // 0 "basis", // 1 "confidence", // 2 "direction", // 3 "grab_strength", // 4 "is_left", // 5 "is_right", // 6 "is_valid", // 7 "palm_normal", // 8 "palm_position", // 9 "palm_velocity", // 10 "palm_width", // 11 "pinch_strength", // 12 "sphere_center", // 13 "sphere_radius", // 14 "stabilized_palm_position", // 15 "time_visible", // 16 "wrist_position" // 17 }; int hand_fields = sizeof (hand_field_names) / sizeof (*hand_field_names); mxArray *p = mxCreateStructMatrix (1, f.hands.count (), hand_fields, hand_field_names); mxSetFieldByNumber (plhs[0], 0, 3, p); // 3 because hands is the third (fourth) field name in // the overall struct we are creating. for (size_t i = 0; i < f.hands.count (); ++i) { // one by one, get the fields for the hand mxSetFieldByNumber (p, i, 0, mxCreateDoubleScalar (f.hands[i].id ())); mxSetFieldByNumber (p, i, 1, create_and_fill (f.hands[i].basis ())); mxSetFieldByNumber (p, i, 2, mxCreateDoubleScalar (f.hands[i].confidence ())); mxSetFieldByNumber (p, i, 3, create_and_fill (f.hands[i].direction ())); mxSetFieldByNumber (p, i, 4, mxCreateDoubleScalar (f.hands[i].grabStrength ())); mxSetFieldByNumber (p, i, 5, mxCreateDoubleScalar (f.hands[i].isLeft ())); mxSetFieldByNumber (p, i, 6, mxCreateDoubleScalar (f.hands[i].isRight ())); mxSetFieldByNumber (p, i, 7, mxCreateDoubleScalar (f.hands[i].isValid ())); mxSetFieldByNumber (p, i, 8, create_and_fill (f.hands[i].palmNormal ())); mxSetFieldByNumber (p, i, 9, create_and_fill (f.hands[i].palmPosition ())); mxSetFieldByNumber (p, i, 10, create_and_fill (f.hands[i].palmVelocity ())); mxSetFieldByNumber (p, i, 11, mxCreateDoubleScalar (f.hands[i].palmWidth ())); mxSetFieldByNumber (p, i, 12, mxCreateDoubleScalar (f.hands[i].pinchStrength ())); mxSetFieldByNumber (p, i, 13, create_and_fill (f.hands[i].sphereCenter ())); mxSetFieldByNumber (p, i, 14, mxCreateDoubleScalar (f.hands[i].sphereRadius ())); mxSetFieldByNumber (p, i, 15, create_and_fill (f.hands[i].stabilizedPalmPosition ())); mxSetFieldByNumber (p, i, 16, mxCreateDoubleScalar (f.hands[i].timeVisible ())); mxSetFieldByNumber (p, i, 17, create_and_fill (f.hands[i].wristPosition ())); } // re: for f.hands.count() } // re: if f.hands.count() > 0 }
/// @brief get a frame from the leap controller /// /// @param nlhs matlab mex output interface /// @param plhs[] matlab mex output interface void get_frame (int nlhs, mxArray *plhs[]) { // get the frame const matleap::frame &f = fg->get_frame (); // create matlab frame struct const char *frame_field_names[] = { "id", "timestamp", "pointables" }; int frame_fields = sizeof (frame_field_names) / sizeof (*frame_field_names); plhs[0] = mxCreateStructMatrix (1, 1, frame_fields, frame_field_names); // fill the frame struct mxSetFieldByNumber (plhs[0], 0, 0, mxCreateDoubleScalar (f.id)); mxSetFieldByNumber (plhs[0], 0, 1, mxCreateDoubleScalar (f.timestamp)); // create the pointables structs if (f.pointables.count () > 0) { const char *pointable_field_names[] = { "id", "position", "velocity", "direction", "is_extended", "is_finger", "is_tool", "is_valid", "length", "width", "touch_distance", "time_visible" }; int pointable_fields = sizeof (pointable_field_names) / sizeof (*pointable_field_names); mxArray *p = mxCreateStructMatrix (1, f.pointables.count (), pointable_fields, pointable_field_names); mxSetFieldByNumber (plhs[0], 0, 2, p); // fill the pointables structs for (size_t i = 0; i < f.pointables.count (); ++i) { // set the id mxSetFieldByNumber (p, i, 0, mxCreateDoubleScalar (f.pointables[i].id ())); // create and fill arrays for vectors mxArray *pos = create_and_fill (f.pointables[i].tipPosition ()); mxArray *vel = create_and_fill (f.pointables[i].tipVelocity ()); mxArray *dir = create_and_fill (f.pointables[i].direction ()); // set them in the struct mxSetFieldByNumber (p, i, 1, pos); mxSetFieldByNumber (p, i, 2, vel); mxSetFieldByNumber (p, i, 3, dir); mxSetFieldByNumber (p, i, 4, mxCreateDoubleScalar (f.pointables[i].isExtended ())); mxSetFieldByNumber (p, i, 5, mxCreateDoubleScalar (f.pointables[i].isFinger ())); mxSetFieldByNumber (p, i, 6, mxCreateDoubleScalar (f.pointables[i].isTool ())); mxSetFieldByNumber (p, i, 7, mxCreateDoubleScalar (f.pointables[i].isValid ())); mxSetFieldByNumber (p, i, 8, mxCreateDoubleScalar (f.pointables[i].length ())); mxSetFieldByNumber (p, i, 9, mxCreateDoubleScalar (f.pointables[i].width ())); mxSetFieldByNumber (p, i, 10, mxCreateDoubleScalar (f.pointables[i].touchDistance ())); mxSetFieldByNumber (p, i, 11, mxCreateDoubleScalar (f.pointables[i].timeVisible ())); } } }