Spaces:
Runtime error
Runtime error
File size: 1,669 Bytes
3c10b34 |
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 |
import numpy as np
class Joint:
def __init__(self, name, parent=None, children=None):
self.name = name
self.parent = parent
self.children = children
class MocapData:
def __init__(self):
self.skeleton = {}
self.values = None
self.channel_names = []
self.framerate = 0.0
self.root_name = ""
self.take_name = ""
def traverse(self, j=None):
stack = [self.root_name]
while stack:
joint = stack.pop()
yield joint
for c in self.skeleton[joint]["children"]:
stack.append(c)
def clone(self):
import copy
new_data = MocapData()
new_data.skeleton = copy.deepcopy(self.skeleton)
new_data.values = copy.deepcopy(self.values)
new_data.channel_names = copy.deepcopy(self.channel_names)
new_data.root_name = copy.deepcopy(self.root_name)
new_data.framerate = copy.deepcopy(self.framerate)
if hasattr(self, "take_name"):
new_data.take_name = copy.deepcopy(self.take_name)
return new_data
def get_all_channels(self):
"""Returns all of the channels parsed from the file as a 2D numpy array"""
frames = [f[1] for f in self.values]
return np.asarray([[channel[2] for channel in frame] for frame in frames])
def get_skeleton_tree(self):
tree = []
root_key = [j for j in self.skeleton if self.skeleton[j]["parent"] == None][0]
root_joint = Joint(root_key)
def get_empty_channels(self):
# TODO
pass
def get_constant_channels(self):
# TODO
pass
|