forked from SimonBiggsUK/Kinect2UDP_Receiver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recording.pde
74 lines (69 loc) · 2.8 KB
/
recording.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Table table; //this code allows you to record live Kinect data to hard drive for later playback - always make a new unique filename to avoid writing over existing data
String jointID,fileName="data/danceData3.csv"; //remember to set an unique filename if recording - if playing back this is where you identify the file you wish to playback (in a folder called data in the Kinect2UDP_Reciever folder)
float recordedX,recordedY,recordedZ,dancerID;
int recordedTime,rowCounter=0,numberOfRows;
void initialiseRecording() { //lets start the recording by formatting our data
table=new Table();
table.addColumn("time");
table.addColumn("dancer");
table.addColumn("joint");
table.addColumn("x");
table.addColumn("y");
table.addColumn("z");
println("recording Kinect data to RAM...");
}
void upDateRecorded() { //this is for reading and playing back data
if(rowCounter<numberOfRows){ //iterate through the rows of the table
recordedTime=table.getInt(rowCounter,0); //get the timestamp
int currentTime=millis()-theTime; //synch playback speed
if(currentTime>=recordedTime) {
for(int i=0;i<25;i++) { //iterate through the 25 joints of the skeleton
recordedTime=table.getInt(rowCounter,0);
dancerID=table.getInt(rowCounter,1);
jointID=table.getString(rowCounter,2);
recordedX=table.getFloat(rowCounter,3);
recordedY=table.getFloat(rowCounter,4);
recordedZ=table.getFloat(rowCounter,5);
findRecordedSkeleton(); //put all the data together as a skeleton
rowCounter++;
}
}
} else { //if no users then delete them all
user1.deleteUser();
user2.deleteUser();
user3.deleteUser();
user4.deleteUser();
user5.deleteUser();
user6.deleteUser();
rowCounter=0;
theTime=millis();
}
}
void findRecordedSkeleton() { //put the skeleton together
User user=null;
if(dancerID==1) user=user1;
if(dancerID==2) user=user2;
if(dancerID==3) user=user3;
if(dancerID==4) user=user4;
if(dancerID==5) user=user5;
if(dancerID==6) user=user6;
user.addJoint(jointID,new PVector(recordedX,recordedY,recordedZ)); //send the data to the user class to build the skeleton
user.changeState(true);
}
void loadRecording() { //load a recording if playback is true
println("loading recording...");
table=loadTable(fileName, "header");
numberOfRows=table.getRowCount();
println(numberOfRows + " total rows in table");
}
void printRecorded() {
for (TableRow row : table.rows()) {
recordedTime=row.getInt("time");
dancerID=row.getInt("dancer");
jointID=row.getString("joint");
recordedX=row.getFloat("x");
recordedY=row.getFloat("y");
recordedZ=row.getFloat("z");
println("time " + recordedTime + " dancerID " + dancerID + " jointID " + jointID + " x " + recordedX + " y " + recordedY + " z " + recordedZ);
}
}