static int compare (const void * a, const void * b) { sortable_pointValue *x = (sortable_pointValue*)a; sortable_pointValue *y = (sortable_pointValue*)b; return (x->value - y->value); } void nodeEvent ( VuoInputData(VuoList_VuoLeapPointable) pointables, VuoInputData(VuoPoint3d, {"default":{"x":0, "y":0, "z":0}}) target, VuoOutputData(VuoList_VuoLeapPointable) sortedPointables ) { *sortedPointables = VuoListCreate_VuoLeapPointable(); int count = VuoListGetCount_VuoLeapPointable(pointables); sortable_pointValue pointValues[count]; for(int i = 0; i < count; i++) pointValues[i] = (sortable_pointValue){i, fabs(VuoListGetValue_VuoLeapPointable(pointables, i+1).tipPosition.z - target.z)}; qsort (pointValues, count, sizeof(sortable_pointValue), compare); for(int i = 0; i < count; i++) VuoListAppendValue_VuoLeapPointable(*sortedPointables, VuoListGetValue_VuoLeapPointable(pointables, pointValues[i].index+1) ); }
/** * @ingroup VuoLeapHand * Decodes the JSON object @c js to create a new value. * * @eg{ * /// @todo write VuoLeapHand json example * } */ VuoLeapHand VuoLeapHand_makeFromJson(json_object * js) { VuoLeapHand hand = VuoLeapHand_make( 0, // id (VuoPoint4d){0,0,0,0}, // rotation (VuoPoint3d){0,0,0}, // palmPosition (VuoPoint3d){0,0,0}, // palmVelocity 0., // sphereRadius (VuoPoint3d){0,0,0}, // sphereCenter 0., // palmWidth (VuoPoint3d){0,0,0}, // wristPosition 0., // pinchAmount 0., // grabAmount 0., // timeVisible false, // isLeftHand 0., // confidence VuoListCreate_VuoLeapPointable() // fingers ); json_object *o = NULL; if (json_object_object_get_ex(js, "id", &o)) hand.id = VuoInteger_makeFromJson(o); if (json_object_object_get_ex(js, "rotation", &o)) hand.rotation = VuoPoint4d_makeFromJson(o); if (json_object_object_get_ex(js, "palmPosition", &o)) hand.palmPosition = VuoPoint3d_makeFromJson(o); if (json_object_object_get_ex(js, "palmVelocity", &o)) hand.palmVelocity = VuoPoint3d_makeFromJson(o); if (json_object_object_get_ex(js, "sphereRadius", &o)) hand.sphereRadius = VuoReal_makeFromJson(o); if (json_object_object_get_ex(js, "sphereCenter", &o)) hand.sphereCenter = VuoPoint3d_makeFromJson(o); if (json_object_object_get_ex(js, "palmWidth", &o)) hand.palmWidth = VuoReal_makeFromJson(o); if (json_object_object_get_ex(js, "wristPosition", &o)) hand.wristPosition = VuoPoint3d_makeFromJson(o); if (json_object_object_get_ex(js, "pinchAmount", &o)) hand.pinchAmount = VuoReal_makeFromJson(o); if (json_object_object_get_ex(js, "grabAmount", &o)) hand.grabAmount = VuoReal_makeFromJson(o); if (json_object_object_get_ex(js, "timeVisible", &o)) hand.timeVisible = VuoReal_makeFromJson(o); if (json_object_object_get_ex(js, "isLeftHand", &o)) hand.isLeftHand = VuoBoolean_makeFromJson(o); if (json_object_object_get_ex(js, "confidence", &o)) hand.confidence = VuoReal_makeFromJson(o); if (json_object_object_get_ex(js, "fingers", &o)) hand.fingers = VuoList_VuoLeapPointable_makeFromJson(o); return hand; }
VuoOutputData(VuoTransform) transform, VuoOutputData(VuoPoint3d) palmVelocity, VuoOutputData(VuoPoint3d) wristPosition, VuoOutputData(VuoReal) sphereRadius, VuoOutputData(VuoPoint3d) sphereCenter, VuoOutputData(VuoReal) pinchAmount, VuoOutputData(VuoReal) grabAmount, VuoOutputData(VuoBoolean) isLeftHand, VuoOutputData(VuoReal) timeVisible, VuoOutputData(VuoReal) confidence, VuoOutputData(VuoList_VuoLeapPointable) fingers ) { *id = hand.id; VuoPoint3d scale = VuoPoint3d_make(hand.palmWidth, hand.palmWidth, hand.palmWidth); *transform = VuoTransform_makeQuaternion(hand.palmPosition, hand.rotation, scale); *palmVelocity = hand.palmVelocity; *wristPosition = hand.wristPosition; *sphereRadius = hand.sphereRadius; *sphereCenter = hand.sphereCenter; *pinchAmount = hand.pinchAmount; *grabAmount = hand.grabAmount; *isLeftHand = hand.isLeftHand; *timeVisible = hand.timeVisible; *confidence = hand.confidence; *fingers = hand.fingers ? hand.fingers : VuoListCreate_VuoLeapPointable(); }
*/ #include "node.h" #include "VuoLeapFrame.h" #include "VuoLeapHand.h" #include "VuoLeapPointable.h" #include "VuoList_VuoLeapHand.h" #include "VuoList_VuoLeapPointable.h" VuoModuleMetadata({ "title" : "Get Frame Values", "keywords" : [ "gesture", "controller", "motion", "hand", "palm", "pointable", "finger", "tool" ], "version" : "1.0.0", "node": { "exampleCompositions" : [ "DisplayLeapHand.vuo", "HighlightExtendedFingers.vuo", "TwirlImageWithLeap.vuo" ] } }); void nodeEvent ( VuoInputData(VuoLeapFrame) frame, VuoOutputData(VuoInteger, {"name":"ID"}) id, VuoOutputData(VuoList_VuoLeapHand) hands, VuoOutputData(VuoList_VuoLeapPointable) pointables ) { *id = frame.id; *hands = frame.hands ? frame.hands : VuoListCreate_VuoLeapHand(); *pointables = frame.pointables ? frame.pointables : VuoListCreate_VuoLeapPointable(); }
#include "VuoLeapPointableType.h" #include "VuoList_VuoLeapPointable.h" VuoModuleMetadata({ "title" : "Find Pointables by Type", "keywords" : [ "filter", "finger", "tool" ], "version" : "2.0.0", "node": { "exampleCompositions" : [ ] } }); void nodeEvent ( VuoInputData(VuoList_VuoLeapPointable) pointables, VuoInputData(VuoLeapPointableType, {"default":"finger"}) type, VuoOutputData(VuoList_VuoLeapPointable) foundPointables ) { *foundPointables = VuoListCreate_VuoLeapPointable(); unsigned long count = VuoListGetCount_VuoLeapPointable(pointables); for(unsigned long i = 1; i <= count; i++) { VuoLeapPointable pointable = VuoListGetValue_VuoLeapPointable(pointables, i); if (pointable.type == type) VuoListAppendValue_VuoLeapPointable(*foundPointables, pointable); } }
#include "VuoLeapPointableType.h" #include "VuoList_VuoLeapPointable.h" VuoModuleMetadata({ "title" : "Filter Pointables by Type", "keywords" : [ ], "version" : "1.0.0", "node": { "isInterface" : false } }); void nodeEvent ( VuoInputData(VuoList_VuoLeapPointable) pointables, VuoInputData(VuoLeapPointableType, {"default":"finger"}) type, VuoOutputData(VuoList_VuoLeapPointable) filteredPointables ) { *filteredPointables = VuoListCreate_VuoLeapPointable(); unsigned long count = VuoListGetCount_VuoLeapPointable(pointables); for(unsigned long i = 1; i <= count; i++) { VuoLeapPointable pointable = VuoListGetValueAtIndex_VuoLeapPointable(pointables, i); if (pointable.type == type) VuoListAppendValue_VuoLeapPointable(*filteredPointables, pointable); } }