1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- public static class CSVWriter
- {
- private static readonly string path = Application.dataPath + "/demo_and_body_positions.csv";
- public static void WriteCSV(List<List<Vector3>> posJointsDemos, List<List<Vector3>> posJointsBodys, List<float> csvTimes)
- {
- string[] jointsName = { "SpineBase", "SpineMid", "Neck", "ShoulderLeft", "ElbowLeft", "WristLeft", "ShoulderRight",
- "ElbowRight", "WristRight", "HipLeft", "KneeLeft", "AnkleLeft", "FootLeft", "HipRight", "KneeRight", "AnkleRight",
- "FootRight", "SpineShoulder" };
- string demos = "";
- string bodys = "";
- foreach(string name in jointsName)
- {
- demos += "Demo_" + name + ",";
- bodys += "Body_" + name + ",";
- }
- StreamWriter sw = new StreamWriter(path);
- sw.WriteLine(demos + bodys + "time");
- for (int i = 0; i < posJointsDemos.Count; i++)
- {
- List<Vector3> demo = posJointsDemos[i];
- List<Vector3> body = posJointsBodys[i];
- string d = "";
- string b = "";
- for(int j = 0; j < demo.Count; j++)
- {
- d += Vector3ToString(demo[j]) + ",";
- b += Vector3ToString(body[j]) + ",";
- }
- sw.WriteLine(b + d + csvTimes[i]);
- }
- sw.Close();
- }
- private static string Vector3ToString(Vector3 vector)
- {
- return vector.x.ToString() + ";" + vector.y.ToString() + ";" + vector.z.ToString();
- }
- }
|