/** * @ingroup VuoPoint2d * Decodes the JSON object @c js to create a new value. * * @eg{ * { * "x" : 0.5, * "y" : 1 * } * } */ VuoPoint2d VuoPoint2d_makeFromJson(json_object * js) { VuoPoint2d point = {0,0}; json_object *o = NULL; if (json_object_object_get_ex(js, "x", &o)) point.x = VuoReal_makeFromJson(o); if (json_object_object_get_ex(js, "y", &o)) point.y = VuoReal_makeFromJson(o); return point; }
/** * Decodes the JSON object @c js to create a new value. * * @eg{ * { * "samples" : [ -0.014525, 0.015363, 0.013679 ], * "samplesPerSecond" : 44100.000000 * } * } */ VuoAudioSamples VuoAudioSamples_makeFromJson(json_object * js) { VuoAudioSamples value = {0, NULL, 0}; json_object *o = NULL; if (json_object_object_get_ex(js, "samples", &o)) { int sampleCount = json_object_array_length(o); if (sampleCount) { value = VuoAudioSamples_alloc(sampleCount); for (VuoInteger i = 0; i < sampleCount; ++i) value.samples[i] = json_object_get_double(json_object_array_get_idx(o, i)); } else { value.sampleCount = 0; value.samples = NULL; } } if (json_object_object_get_ex(js, "samplesPerSecond", &o)) value.samplesPerSecond = VuoReal_makeFromJson(o); return value; }
/** * @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; }