Skip to content
Snippets Groups Projects
Commit bb446435 authored by Alexis Iakovenko's avatar Alexis Iakovenko
Browse files

Add temporary gestures and load them to a state class

parent 5962d4d9
No related branches found
No related tags found
No related merge requests found
Showing
with 209 additions and 0 deletions
fileFormatVersion: 2
guid: 2b5090e4d70e187449edf91e8d789dc1
folderAsset: yes
timeCreated: 1511954723
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CompareGestureMean : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
fileFormatVersion: 2
guid: d37d2231777ea564f868e06a19b100d7
timeCreated: 1511954744
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
using System.Collections;
using System.Linq;
public class CSVReader : MonoBehaviour
{
public TextAsset csvFile;
public void Start()
{
string[,] grid = SplitCsvGrid(csvFile.text);
Debug.Log("size = " + (1+ grid.GetUpperBound(0)) + "," + (1 + grid.GetUpperBound(1)));
DebugOutputGrid(grid);
}
// outputs the content of a 2D array, useful for checking the importer
static public void DebugOutputGrid(string[,] grid)
{
string textOutput = "";
for (int y = 0; y < grid.GetUpperBound(1); y++) {
for (int x = 0; x < grid.GetUpperBound(0); x++) {
textOutput += grid[x,y];
textOutput += "|";
}
textOutput += "\n";
}
Debug.Log(textOutput);
}
// splits a CSV file into a 2D string array
static public string[,] SplitCsvGrid(string csvText)
{
string[] lines = csvText.Split("\n"[0]);
// finds the max width of row
int width = 0;
for (int i = 0; i < lines.Length; i++)
{
string[] row = SplitCsvLine( lines[i] );
width = Mathf.Max(width, row.Length);
}
// creates new 2D string grid to output to
string[,] outputGrid = new string[width + 1, lines.Length + 1];
for (int y = 0; y < lines.Length; y++)
{
string[] row = SplitCsvLine( lines[y] );
for (int x = 0; x < row.Length; x++)
{
outputGrid[x,y] = row[x];
// This line was to replace "" with " in my output.
// Include or edit it as you wish.
outputGrid[x,y] = outputGrid[x,y].Replace("\"\"", "\"");
}
}
return outputGrid;
}
// splits a CSV row
static public string[] SplitCsvLine(string line)
{
return (from System.Text.RegularExpressions.Match m in System.Text.RegularExpressions.Regex.Matches(line,
@"(((?<x>(?=[,\r\n]+))|""(?<x>([^""]|"""")+)""|(?<x>[^,\r\n]+)),?)",
System.Text.RegularExpressions.RegexOptions.ExplicitCapture)
select m.Groups[1].Value).ToArray();
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 6102ca539812f7044a75b29f6c152d59
timeCreated: 1511956168
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class LoadTemporaryGestures : MonoBehaviour
{
List<TemporaryGestureState> states = new List<TemporaryGestureState>();
void Start()
{
Load ("Assets/Compare/TemporaryGestures/1.txt");
}
public void Load (string path)
{
StreamReader reader = new StreamReader(path);
string[,] csvStrings = CSVReader.SplitCsvGrid (reader.ReadToEnd ());
Debug.Log("csvStrings length:" + csvStrings.Length);
for (int i = 0; i < 200; i++)
{
if (i < 2) //dont take 2 first lines into account
continue;
//we need timestamp, x, y, z of palm
string[] line = csvStrings[0,i].Split (' ');
TemporaryGestureState state = new TemporaryGestureState ();
state.timestamp = int.Parse(line [2]);
state.x = double.Parse(line [13]);
state.y = double.Parse(line [14]);
state.z = double.Parse(line [15]);
states.Add (state);
Debug.Log(state);
}
reader.Close();
}
}
fileFormatVersion: 2
guid: ee829df398e2f994bb63d985c6e48c7b
timeCreated: 1511955693
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TemporaryGestureState {
public int timestamp = 0;
public double x = 0;
public double y = 0;
public double z = 0;
public override string ToString()
{
return "State timestamp " + timestamp + ", x: " + x + ", y: " + y + ", z: " + z;
}
}
fileFormatVersion: 2
guid: fa855f9ff91cb9444aa07c03f15c1ae3
timeCreated: 1511959669
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment