"""
BVH 库
"""
import re
class BvhNode:
def __init__(self, value=[], parent=None):
self.value = value
self.children = []
self.parent = parent
if self.parent:
self.parent.add_child(self)
def add_child(self, item):
item.parent = self
self.children.append(item)
def filter(self, key):
for child in self.children:
if child.value[0] == key:
yield child
def __iter__(self):
for child in self.children:
yield child
def __getitem__(self, key):
for child in self.children:
for index, item in enumerate(child.value):
if item == key:
if index + 1 >= len(child.value):
return None
else:
return child.value[index + 1:]
raise IndexError('key {} not found'.format(key))
def __repr__(self):
return str(' '.join(self.value))
@property
def name(self):
return self.value[1]
class Bvh:
def __init__(self, data):
self.data = data
self.root = BvhNode()
self.frames = []
self.tokenize()
def tokenize(self):
first_round = []
accumulator = ''
for char in self.data:
if char not in ('\n', '\r'):
accumulator += char
elif accumulator:
first_round.append(re.split('\\s+', accumulator.strip()))
accumulator = ''
node_stack = [self.root]
frame_time_found = False
node = None
for item in first_round:
if frame_time_found:
self.frames.append(item)
continue
key = item[0]
if key == '{':
node_stack.append(node)
elif key == '}':
node_stack.pop()
else:
node = BvhNode(item)
node_stack[-1].add_child(node)
if item[0] == 'Frame' and item[1] == 'Time:':
frame_time_found = True
def search(self, *items):
found_nodes = []
def check_children(node):
if len(node.value) >= len(items):
failed = False
for index, item in enumerate(items):
if node.value[index] != item:
failed = True
break
if not failed:
found_nodes.append(node)
for child in node:
check_children(child)
check_children(self.root)
return found_nodes
def get_joints(self):
joints = []
def iterate_joints(joint):
joints.append(joint)
for child in joint.filter('JOINT'):
iterate_joints(child)
iterate_joints(next(self.root.filter('ROOT')))
return joints
def get_joints_names(self):
joints = []
def iterate_joints(joint):
joints.append(joint.value[1])
for child in joint.filter('JOINT'):
iterate_joints(child)
iterate_joints(next(self.root.filter('ROOT')))
return joints
def joint_direct_children(self, name):
joint = self.get_joint(name)
return [child for child in joint.filter('JOINT')]
def get_joint_index(self, name):
return self.get_joints().index(self.get_joint(name))
def get_joint(self, name):
found = self.search('ROOT', name)
if not found:
found = self.search('JOINT', name)
if found:
return found[0]
raise LookupError('joint not found')
def joint_offset(self, name):
joint = self.get_joint(name)
offset = joint['OFFSET']
return (float(offset[0]), float(offset[1]), float(offset[2]))
def joint_channels(self, name):
joint = self.get_joint(name)
return joint['CHANNELS'][1:]
def get_joint_channels_index(self, joint_name):
index = 0
for joint in self.get_joints():
if joint.value[1] == joint_name:
return index
index += int(joint['CHANNELS'][0])
raise LookupError('joint not found')
def get_joint_channel_index(self, joint, channel):
channels = self.joint_channels(joint)
if channel in channels:
channel_index = channels.index(channel)
else:
channel_index = -1
return channel_index
def frame_joint_channel(self, frame_index, joint, channel, value=None):
joint_index = self.get_joint_channels_index(joint)
channel_index = self.get_joint_channel_index(joint, channel)
if channel_index == -1 and value is not None:
return value
return float(self.frames[frame_index][joint_index + channel_index])
def frame_joint_channels(self, frame_index, joint, channels, value=None):
values = []
joint_index = self.get_joint_channels_index(joint)
for channel in channels:
channel_index = self.get_joint_channel_index(joint, channel)
if channel_index == -1 and value is not None:
values.append(value)
else:
values.append(
float(
self.frames[frame_index][joint_index + channel_index]
)
)
return values
def frames_joint_channels(self, joint, channels, value=None):
all_frames = []
joint_index = self.get_joint_channels_index(joint)
for frame in self.frames:
values = []
for channel in channels:
channel_index = self.get_joint_channel_index(joint, channel)
if channel_index == -1 and value is not None:
values.append(value)
else:
values.append(
float(frame[joint_index + channel_index]))
all_frames.append(values)
return all_frames
def joint_parent(self, name):
joint = self.get_joint(name)
if joint.parent == self.root:
return None
return joint.parent
def joint_parent_index(self, name):
joint = self.get_joint(name)
if joint.parent == self.root:
return -1
return self.get_joints().index(joint.parent)
@property
def nframes(self):
try:
return int(next(self.root.filter('Frames:')).value[1])
except StopIteration:
raise LookupError('number of frames not found')
@property
def frame_time(self):
try:
return float(next(self.root.filter('Frame')).value[2])
except StopIteration:
raise LookupError('frame time not found')
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 Python开发基于多模态信息融合的上肢康复训练评估系统源码.zipPython开发基于多模态信息融合的上肢康复训练评估系统源码.zipPython开发基于多模态信息融合的上肢康复训练评估系统源码.zipPython开发基于多模态信息融合的上肢康复训练评估系统源码.zipPython开发基于多模态信息融合的上肢康复训练评估系统源码.zipPython开发基于多模态信息融合的上肢康复训练评估系统源码.zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!
资源推荐
资源详情
资源评论
收起资源包目录
Python开发基于多模态信息融合的上肢康复训练评估系统源码.zip (156个子文件)
patient_1.bvh 2.42MB
patient.bvh 2.41MB
patient_3.bvh 2.31MB
patient_2.bvh 2.23MB
normal.bvh 2.11MB
1.bvh 2.07MB
1.bvh 1.91MB
normal_1.bvh 1.9MB
normal_1.bvh 1.87MB
3.bvh 1.8MB
2.bvh 1.76MB
patient_1.bvh 1.73MB
normal_3.bvh 1.7MB
patient_2.bvh 1.68MB
normal_2.bvh 1.65MB
2.bvh 1.65MB
3.bvh 1.61MB
patient_3.bvh 1.61MB
patient_2.bvh 1.6MB
normal_1.bvh 1.58MB
2.bvh 1.53MB
patient_1.bvh 1.51MB
3.bvh 1.5MB
patient_3.bvh 1.49MB
3.bvh 1.48MB
2.bvh 1.42MB
1.bvh 1.4MB
patient_3.bvh 1.4MB
3.bvh 1.39MB
normal_2.bvh 1.38MB
1.bvh 1.37MB
3.bvh 1.36MB
3.bvh 1.35MB
patient_2.bvh 1.34MB
normal_3.bvh 1.33MB
1.bvh 1.32MB
1.bvh 1.31MB
normal_3.bvh 1.31MB
3.bvh 1.29MB
2.bvh 1.25MB
patient_1.bvh 1.24MB
3.bvh 1.22MB
1.bvh 1.21MB
2.bvh 1.2MB
2.bvh 1.2MB
normal_1.bvh 1.19MB
normal_3.bvh 1.19MB
normal_1.bvh 1.18MB
2.bvh 1.17MB
patient_1.bvh 1.17MB
2.bvh 1.14MB
3.bvh 1.13MB
patient_3.bvh 1.13MB
normal_2.bvh 1.1MB
1.bvh 1.1MB
normal_3.bvh 1.09MB
normal_2.bvh 1.06MB
3.bvh 1.06MB
patient_2.bvh 1.05MB
normal_2.bvh 1.05MB
2.bvh 1.03MB
1.bvh 1019KB
2.bvh 1012KB
2.bvh 913KB
1.bvh 873KB
1.bvh 870KB
3.bvh 792KB
1.bvh 766KB
allData.csv 4KB
1.csv 305B
2.csv 304B
normal_1.csv 304B
3.csv 303B
1.csv 303B
patient_3.csv 303B
3.csv 302B
3.csv 301B
2.csv 301B
patient_2.csv 301B
2.csv 300B
2.csv 300B
patient_2.csv 300B
patient_1.csv 300B
patient_1.csv 300B
patient_3.csv 300B
3.csv 299B
1.csv 299B
3.csv 299B
1.csv 299B
normal_1.csv 299B
normal_1.csv 299B
patient_1.csv 299B
1.csv 298B
3.csv 298B
2.csv 298B
normal_3.csv 298B
patient_3.csv 298B
1.csv 297B
1.csv 297B
2.csv 297B
共 156 条
- 1
- 2
资源评论
Make程序设计
- 粉丝: 5632
- 资源: 3568
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- ### 词向量的介绍、使用技巧和优缺点的文章
- 基于STM32F103CBT6单片机GC65+MP2625+CC1101 GPSTrack模块板硬件(原理图+PCB)工程文件
- ### 通道处理过程模拟概念、优缺点和使用技巧
- ### MyBatis动态SQL介绍说明、使用技巧和优缺点
- 上传下载仿163网盘无刷新文件上传 for Jsp-fileupload-jsp.rar
- VMware Workstation业界非常稳定且安全的桌面虚拟机软件-计算机上运行多个操作系统,支持Windows、DOS等
- 基于STM8L101F3P6单片机+LY2508A33P+CC1100遥控器硬件(原理图+PCB)工程文件.zip
- 上传下载WAP图铃下载系统-unimg.rar
- YTX-0.1.0-Win
- 上传下载ExtJS 2.2 开源网络硬盘系统-dogdisk.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功