This repository has been archived by the owner on Jan 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathplot.py
131 lines (104 loc) · 3.23 KB
/
plot.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"""
This file uses matplotlib to render a single frame from a CSV file.
The CSV file is just data where every line is a frame. Rig keypoints are assumed to be in the following order:
| Index | Joint |
| -- | -- |
| 0 | pelvis |
| 1 | rHIp |
| 2 | rKnee |
| 3 | rAnkle
| 4 | rToeBase |
| 5 | lHip |
| 6 | lKnee |
| 7 | lAnkle |
| 8 | lToeBase |
| 9 | spine2 |
| 10 | spine3 |
| 11 | spine4 |
| 12 | rShoulder |
| 13 | rElbow |
| 14 | rWrist |
| 15 | lShoulder |
| 16 | lElbow |
| 17 | lWrist |
| 18 | baseNeck |
| 19 | baseHead |
Example file:
x1,y1,z1,x2,y2,z2,...xLastKP,yLastKP,zLastKP
x1,y1,z1,x2,y2,z2,...xLastKP,yLastKP,zLastKP
...
"""
import sys
import os
import numpy # pip3 install numpy
import math
import matplotlib.pyplot as plt # pip3 install matplotlib
from mpl_toolkits import mplot3d # required for matplot versions older than 3.1.1
def addPlot( poseData, ax ):
# Convert the CSV string to a float array
xyzData = [float(numeric_string) for numeric_string in poseData.split( "," )]
# Separate the components
xPoints = xyzData[ 0::3 ]
yPoints = xyzData[ 1::3 ]
zPoints = xyzData[ 2::3 ]
# Normalize positions to the first joint
xPoints = [ x - xPoints[0] for x in xPoints ]
yPoints = [ y - yPoints[0] for y in yPoints ]
zPoints = [ z - zPoints[0] for z in zPoints ]
# Plot individual sections so the lines connect as expected
plot( range(0,5), ax, xPoints, yPoints, zPoints )
plot( [0,5,6,7,8], ax, xPoints, yPoints, zPoints )
plot( [0,9,10,11,18,19], ax, xPoints, yPoints, zPoints )
plot( [18,12,13,14], ax, xPoints, yPoints, zPoints )
plot( [18,15,16,17], ax, xPoints, yPoints, zPoints )
def plot( indices, ax, xPoints, yPoints, zPoints ):
xPointsToPlot = []
yPointsToPlot = []
zPointsToPlot = []
for i in indices:
#ax.text( xPoints[i], yPoints[i], zPoints[i], str(i) )
xPointsToPlot.append( xPoints[i] )
yPointsToPlot.append( yPoints[i] )
zPointsToPlot.append( zPoints[i] )
ax.plot( xPointsToPlot,
yPointsToPlot,
zPointsToPlot,
'-o' )
def main( filenames ):
print( "Plotting the first frame for all characters" )
# Create and layout our subplots
numColumns=1
while math.pow(numColumns,2) < len(filenames):
numColumns = numColumns + 1
numRows = numColumns
if numColumns * (numRows - 1) >= len(filenames):
numRows = numRows - 1
fig = plt.figure()
plt.axis('off')
i = 1
for filename in filenames:
# Read the first line
file = open( filename , 'r' )
line = file.readline().split( '\n' )[0]
file.close()
# Create a new plot
ax = fig.add_subplot( numRows, numColumns, i, projection="3d" )
# Set limits
limit=0.5
ax.set_xlim([-limit,limit])
ax.set_ylim([-limit,limit])
ax.set_zlim([-limit,limit])
ax.axis('off')
ax.set_title( os.path.splitext(filename)[0] )
# Add the plot
addPlot( line, ax )
i+=1
# Show the plot
plt.show()
if __name__ == "__main__":
# Assume all arguments are CSV files
argv = sys.argv[1:]
if len( argv ) < 1:
print( "Usage: <CSV files>" )
exit( 0 )
main( argv )