From 37e40c85229313ff233aaf11c1a503965222b55e Mon Sep 17 00:00:00 2001
From: Alexis Iakovenko <alexis.iakovenko@gmail.com>
Date: Mon, 29 Jan 2018 17:40:00 +0100
Subject: [PATCH] Revert "Added all fingers and switched format to list of
 JSON"

This reverts commit 6e9d0a33403aedc6c1998084f856dc270e238363.
---
 Assets/Record/Recorder.cs | 93 ++++++++-------------------------------
 1 file changed, 19 insertions(+), 74 deletions(-)

diff --git a/Assets/Record/Recorder.cs b/Assets/Record/Recorder.cs
index aba7378..cd62112 100644
--- a/Assets/Record/Recorder.cs
+++ b/Assets/Record/Recorder.cs
@@ -3,7 +3,6 @@ using Leap.Unity;
 using System.Collections;
 using System.Collections.Generic;
 using System.IO;
-using System.Text;
 using UnityEngine;
 using UnityEngine.UI;
 
@@ -20,14 +19,8 @@ public class Recorder : MonoBehaviour
 
 	private string path = "Assets/Record/Recorded/";
 	private StreamWriter mStreamWriter;
+	private string date;
 
-	// Finger bones from base to tip
-	private Bone.BoneType[] bones = new Bone.BoneType[] {
-		Bone.BoneType.TYPE_METACARPAL,
-		Bone.BoneType.TYPE_PROXIMAL,
-		Bone.BoneType.TYPE_INTERMEDIATE,
-		Bone.BoneType.TYPE_DISTAL
-	};
 
 	public void ToggleRecording()
 	{
@@ -41,7 +34,8 @@ public class Recorder : MonoBehaviour
 	{
 		Directory.CreateDirectory (path + gestureName);
 		mStreamWriter = new StreamWriter(path + gestureName + "/" + recordingNumber.ToString() + ".txt");
-		mStreamWriter.WriteLine("Gesture: " + gestureName + "; Author: " + userName);
+		mStreamWriter.WriteLine("Gesture: " + gestureName + "; Author: " + userName + "; Recorded: " + date);
+		mStreamWriter.WriteLine("timestamp l_palm_pos_x l_palm_pos_y l_palm_pos_z r_palm_pos_x r_palm_pos_y r_palm_pos_z");
 
 		//UI
 		recordingLabel.SetActive (true);
@@ -65,91 +59,42 @@ public class Recorder : MonoBehaviour
 	{
 		if (mStreamWriter != null)
 		{
-			Dictionary<string, float> hands = new Dictionary<string, float>();
+			Vector3 leftPalmPosition = Vector3.zero, rightPalmPosition = Vector3.zero;
+			Vector4 leftPalmRotation = Vector3.zero, rightPalmRotation = Vector3.zero;
 
             Frame frame = LeapService.CurrentFrame;
             foreach (Hand hand in frame.Hands)
             {
 				if (hand.IsLeft)
 				{
-					handToDict ("l", hand, hands);
+					leftPalmPosition = hand.PalmPosition.ToVector3 ();
+					leftPalmRotation = new Vector4(hand.Rotation.x, hand.Rotation.y, hand.Rotation.z, hand.Rotation.w);
 				}
 				else
 				{
-					handToDict ("r", hand, hands);
+					rightPalmPosition = hand.PalmPosition.ToVector3();
+					rightPalmRotation = new Vector4(hand.Rotation.x, hand.Rotation.y, hand.Rotation.z, hand.Rotation.w);
 				}
             }
 
-			hands ["timestamp"] = Time.unscaledTime;
-
-			mStreamWriter.WriteLine(JsonUtility.ToJson(hands));
+			mStreamWriter.WriteLine(DataToString(VecToData(leftPalmPosition), VecToData(leftPalmRotation), VecToData(rightPalmPosition), VecToData(rightPalmRotation)));
         }
 	}
 
-	private void handToDict(string prefix, Hand hand, Dictionary<string, float> result) {
-		// Iterate over each finger and bone
-		foreach (Finger finger in hand.Fingers) {
-			foreach (var boneType in bones) {
-				// Load the bone
-				var bone = finger.Bone (boneType);
-				var boneID = string.Join ("_", new string[]{prefix, FingerName (finger.Type), BoneName (boneType)});
-
-				// Store the center of the bone
-				result [boneID + "_cen_x"] = bone.Center.x;
-				result [boneID + "_cen_y"] = bone.Center.y;
-				result [boneID + "_cen_z"] = bone.Center.z;
-
-				// Store the direction of the bone
-				result [boneID + "_dir_x"] = bone.Direction.x;
-				result [boneID + "_dir_y"] = bone.Direction.y;
-				result [boneID + "_dir_z"] = bone.Direction.z;
-
-				// Store the length of the bone
-				result [boneID + "_len"] = bone.Length;
-			}
-		}
-
-		// Store the palm of the hand
-		var palmID = string.Join("_", new string[]{ prefix, "palm" });
-		result [palmID + "_pos_x"] = hand.PalmPosition.x;
-		result [palmID + "_pos_y"] = hand.PalmPosition.y;
-		result [palmID + "_pos_z"] = hand.PalmPosition.z;
-		result [palmID + "_rot_x"] = hand.Rotation.x;
-		result [palmID + "_rot_y"] = hand.Rotation.y;
-		result [palmID + "_rot_z"] = hand.Rotation.z;
-		result [palmID + "_rot_w"] = hand.Rotation.w;
-	}
-
-	private string FingerName(Finger.FingerType fingerType)
+	private static string VecToData(Vector3 vec)
 	{
-		switch (fingerType) {
-		case Finger.FingerType.TYPE_INDEX:
-			return "index";
-		case Finger.FingerType.TYPE_MIDDLE:
-			return "middle";
-		case Finger.FingerType.TYPE_PINKY:
-			return "pinky";
-		case Finger.FingerType.TYPE_RING:
-			return "ring";
-		case Finger.FingerType.TYPE_THUMB:
-			return "thumb";
-		}
-		return "unknown";
+		return string.Format("{0} {1} {2}", vec.x, vec.y, vec.z);
 	}
 
-	private string BoneName(Bone.BoneType boneType)
+	private static string DataToString(params object[] list)
 	{
-		switch (boneType) {
-		case Bone.BoneType.TYPE_DISTAL:
-			return "distral";
-		case Bone.BoneType.TYPE_INTERMEDIATE:
-			return "intermediate";
-		case Bone.BoneType.TYPE_METACARPAL:
-			return "metacarpal";
-		case Bone.BoneType.TYPE_PROXIMAL:
-			return "proximal";
+		string[] strs = new string[list.Length];
+
+		for (int i = 0; i < list.Length; i++) {
+			strs [i] = list [i].ToString ();
 		}
-		return "unknown";
+
+		return string.Join (" ", strs);
 	}
 
 	public void UpdateGestureName(string name)
-- 
GitLab