def parse_asf()

in fairmotion/data/asfamc.py [0:0]


def parse_asf(file_path):
    """read joint data only"""
    with open(file_path) as f:
        content = f.read().splitlines()

    for idx, line in enumerate(content):
        # meta infomation is ignored
        if line == ":bonedata":
            content = content[idx + 1 :]
            break

    # read joints
    joints = {
        "root": Joint(
            "root",
            direction=np.zeros(3),
            length=0,
            axis=np.zeros(3),
            dof=[],
            limits=[],
        )
    }

    idx = 0
    while True:
        # the order of each section is hard-coded

        line, idx = read_line(content, idx)

        if line[0] == ":hierarchy":
            break

        assert line[0] == "begin"

        line, idx = read_line(content, idx)
        assert line[0] == "id"

        line, idx = read_line(content, idx)
        assert line[0] == "name"
        name = line[1]

        line, idx = read_line(content, idx)
        assert line[0] == "direction"
        direction = np.array([float(axis) for axis in line[1:]])

        # skip length
        line, idx = read_line(content, idx)
        assert line[0] == "length"
        length = float(line[1])

        line, idx = read_line(content, idx)
        assert line[0] == "axis"
        assert line[4] == "XYZ"

        axis = np.array([float(axis) for axis in line[1:-1]])

        dof = []
        limits = []

        line, idx = read_line(content, idx)
        if line[0] == "dof":
            dof = line[1:]
            for i in range(len(dof)):
                line, idx = read_line(content, idx)
                if i == 0:
                    assert line[0] == "limits"
                    line = line[1:]
                assert len(line) == 2
                mini = float(line[0][1:])
                maxi = float(line[1][:-1])
                limits.append((mini, maxi))

            line, idx = read_line(content, idx)

        assert line[0] == "end"
        joints[name] = Joint(
            name,
            direction=direction,
            length=length,
            axis=axis,
            dof=dof,
            limits=limits,
        )

    # read hierarchy
    assert line[0] == ":hierarchy"

    line, idx = read_line(content, idx)

    assert line[0] == "begin"

    while True:
        line, idx = read_line(content, idx)
        if line[0] == "end":
            break
        assert len(line) >= 2
        for joint_name in line[1:]:
            joints[line[0]].child_joints.append(joints[joint_name])
        for nm in line[1:]:
            joints[nm].parent_joint = joints[line[0]]

    return joints