File size: 5,220 Bytes
2680bd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
import rerun as rr

from ..constant import SKELETON_CHAIN


class RerunVisualizer(object):
    left_mesh_color = [107, 174, 214]
    right_mesh_color = [252, 146, 114]
    left_skeleton_color = [8, 81, 156]
    right_skeleton_color = [203, 24, 29]
    @staticmethod
    def visualize_singlemotion(
        motion:np.ndarray=None, vertices:np.ndarray=None, faces:np.ndarray=None,
        application_id:str="Visualize Single Hand", hand:str="left",
    ):

        rr.log(
            '3D/axis',
            rr.Arrows3D(
                origins=np.zeros((3, 3)),
                vectors=np.eye(3, 3),
                labels=["X", "Y", "Z"],
            ),
            static=True
        )

        motion_frames = motion.shape[0] if motion is not None else 0
        mano_frames = vertices.shape[0] if vertices is not None else 0
        frames = max(motion_frames, mano_frames)
        for frame in range(frames):
            rr.set_time("stable_time", duration=frame / 30)
            rr.log(
                'text',
                rr.TextDocument(
                    text=f'frame {frame}',
                )
            )
            if motion is not None and frame < motion.shape[0]:
                rr.log(
                    '3D/skeleton',
                    rr.LineStrips3D(
                        strips=motion[frame, np.array(SKELETON_CHAIN)],
                        colors=RerunVisualizer.left_skeleton_color if hand == "left" else RerunVisualizer.right_skeleton_color
                    )
                )
            if vertices is not None and faces is not None:
                if frame < len(vertices) and frame < len(faces):
                    rr.log(
                        '3D/mesh',
                        rr.Mesh3D(
                            vertex_positions=vertices[frame],
                            triangle_indices=faces[frame],
                            vertex_colors=RerunVisualizer.left_skeleton_color if hand == "left" else RerunVisualizer.right_skeleton_color,
                            albedo_factor=RerunVisualizer.left_mesh_color if hand == "left" else RerunVisualizer.right_mesh_color
                        )
                    )

    @staticmethod
    def visualize_bihandmotion(
        motion:np.ndarray=None, left_vertices:np.ndarray=None, right_vertices:np.ndarray=None,
        left_faces:np.ndarray=None, right_faces:np.ndarray=None,
    ):
        rr.log(
            '3D/axis',
            rr.Arrows3D(
                origins=np.zeros((3, 3)),
                vectors=np.eye(3, 3),
                labels=["X", "Y", "Z"],
            ),
            static=True
        )

        assert motion is not None or (left_vertices is not None and right_vertices is not None), \
            "Either motion or left/right vertices must be provided."

        print("Visualizing bi-hand motion...")

        motion_frames = motion.shape[0] if motion is not None else 0
        mano_frames = max(
            left_vertices.shape[0] if left_vertices is not None else 0,
            right_vertices.shape[0] if right_vertices is not None else 0
        )
        frames = max(motion_frames, mano_frames)
        for frame in range(frames):
            rr.set_time("stable_time", duration=frame / 30)
            rr.log(
                'text',
                rr.TextDocument(
                    text=f'frame {frame}',
                )
            )
            if motion is not None and frame < motion.shape[0]:
                rr.log(
                    '3D/left_skeleton',
                    rr.LineStrips3D(
                        strips=motion[frame, 0, np.array(SKELETON_CHAIN)],
                        colors=RerunVisualizer.left_skeleton_color
                    )
                )
                rr.log(
                    '3D/right_skeleton',
                    rr.LineStrips3D(
                        strips=motion[frame, 1, np.array(SKELETON_CHAIN)],
                        colors=RerunVisualizer.right_skeleton_color
                    )
                )
            if left_vertices is not None and left_faces is not None:
                if frame < len(left_vertices) and frame < len(left_faces):
                    rr.log(
                        '3D/left_mesh',
                        rr.Mesh3D(
                            vertex_positions=left_vertices[frame],
                            triangle_indices=left_faces[frame],
                            vertex_colors=RerunVisualizer.left_skeleton_color,
                            albedo_factor=RerunVisualizer.left_mesh_color
                        )
                    )
            if right_vertices is not None and right_faces is not None:
                if frame < len(right_vertices) and frame < len(right_faces):
                    rr.log(
                        '3D/right_mesh',
                        rr.Mesh3D(
                            vertex_positions=right_vertices[frame],
                            triangle_indices=right_faces[frame],
                            vertex_colors=RerunVisualizer.right_skeleton_color,
                            albedo_factor=RerunVisualizer.right_mesh_color
                        )
                    )