abreza commited on
Commit
674aded
·
1 Parent(s): 44a5fb8

fix rerun render issue

Browse files
visualization/logger.py CHANGED
@@ -11,12 +11,15 @@ class SimulationLogger:
11
  rr.log("world", rr.ViewCoordinates.RIGHT_HAND_Y_UP, timeless=True)
12
 
13
  def log_metadata(self, instructions: List[Dict[str, Any]]) -> None:
 
 
 
14
  rr.log("metadata/instructions", rr.TextDocument(
15
  "\n".join([
16
  f"Instruction {i+1}:\n" +
17
- f" Movement: {inst['cameraMovement']}\n" +
18
- f" Easing: {inst['movementEasing']}\n" +
19
- f" Frames: {inst['frameCount']}\n" +
20
  f" Camera Angle: {inst.get('initialCameraAngle', 'N/A')}\n" +
21
  f" Shot Type: {inst.get('initialShotType', 'N/A')}\n" +
22
  f" Subject Index: {inst.get('subjectIndex', 'N/A')}"
@@ -24,65 +27,85 @@ class SimulationLogger:
24
  ])
25
  ), timeless=True)
26
 
27
- def log_subjects(self, subjects: List[Dict[str, Any]], selected_subject: int = None) -> None:
 
 
 
28
  for idx, subject in enumerate(subjects):
29
- vertices, faces = create_subject_mesh(subject)
30
- subject_color = [0.8, 0.2, 0.2, 1.0] if idx == selected_subject else [
31
- 0.8, 0.8, 0.8, 1.0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
 
 
 
 
 
 
 
 
33
  rr.log(
34
- f"world/subject_{idx}",
35
- rr.Mesh3D(
36
- vertex_positions=vertices,
37
- indices=faces,
38
- colors=np.tile(subject_color, (len(vertices), 1))
39
  ),
40
  timeless=True
41
  )
42
-
43
- rr.log(f"world/subject_{idx}/class",
44
- rr.TextDocument(subject['objectClass']),
45
- timeless=True)
46
-
47
- def log_camera_trajectory(self, camera_frames: List[Dict[str, Any]]) -> None:
48
- camera_positions = np.array(
49
- [vector3_to_numpy(frame['position']) for frame in camera_frames])
50
- rr.log(
51
- "world/camera_trajectory",
52
- rr.Points3D(
53
- camera_positions,
54
- colors=np.full((len(camera_positions), 4),
55
- [0.0, 0.8, 0.8, 1.0])
56
- ),
57
- timeless=True
58
- )
59
 
60
  def log_camera_frames(self, camera_frames: List[Dict[str, Any]]) -> None:
 
 
 
61
  for frame_idx, camera_frame in enumerate(camera_frames):
62
- rr.set_time_sequence("frame", frame_idx)
 
63
 
64
- position = vector3_to_numpy(camera_frame['position'])
65
- rotation_q = euler_to_quaternion(camera_frame['angle'])
66
 
67
- rr.log(
68
- "world/camera",
69
- rr.Transform3D(
70
- translation=position,
71
- rotation=rr.Quaternion(xyzw=rotation_q)
 
72
  )
73
- )
74
 
75
- rr.log(
76
- "world/camera/view",
77
- rr.Pinhole(
78
- focal_length=camera_frame['focalLength'],
79
- width=1920,
80
- height=1080
 
 
81
  )
82
- )
83
 
84
- rr.log(
85
- "metadata/current_frame",
86
- rr.TextDocument(
87
- f"Frame: {frame_idx + 1}/{len(camera_frames)}"),
88
- )
 
 
 
11
  rr.log("world", rr.ViewCoordinates.RIGHT_HAND_Y_UP, timeless=True)
12
 
13
  def log_metadata(self, instructions: List[Dict[str, Any]]) -> None:
14
+ if not instructions:
15
+ return
16
+
17
  rr.log("metadata/instructions", rr.TextDocument(
18
  "\n".join([
19
  f"Instruction {i+1}:\n" +
20
+ f" Movement: {inst.get('cameraMovement', 'N/A')}\n" +
21
+ f" Easing: {inst.get('movementEasing', 'N/A')}\n" +
22
+ f" Frames: {inst.get('frameCount', 'N/A')}\n" +
23
  f" Camera Angle: {inst.get('initialCameraAngle', 'N/A')}\n" +
24
  f" Shot Type: {inst.get('initialShotType', 'N/A')}\n" +
25
  f" Subject Index: {inst.get('subjectIndex', 'N/A')}"
 
27
  ])
28
  ), timeless=True)
29
 
30
+ def log_subjects(self, subjects: List[Dict[str, Any]], selected_subject: Optional[int] = None) -> None:
31
+ if not subjects:
32
+ return
33
+
34
  for idx, subject in enumerate(subjects):
35
+ try:
36
+ vertices, faces = create_subject_mesh(subject)
37
+ subject_color = [0.8, 0.2, 0.2, 1.0] if idx == selected_subject else [
38
+ 0.8, 0.8, 0.8, 1.0]
39
+
40
+ rr.log(
41
+ f"world/subject_{idx}",
42
+ rr.Mesh3D(
43
+ vertex_positions=vertices,
44
+ vertex_indices=faces, # Changed from indices to vertex_indices
45
+ colors=np.tile(subject_color, (len(vertices), 1))
46
+ ),
47
+ timeless=True
48
+ )
49
+
50
+ rr.log(f"world/subject_{idx}/class",
51
+ rr.TextDocument(subject.get('objectClass', 'Unknown')),
52
+ timeless=True)
53
+ except Exception as e:
54
+ print(f"Error creating mesh for subject {idx}: {str(e)}")
55
 
56
+ def log_camera_trajectory(self, camera_frames: List[Dict[str, Any]]) -> None:
57
+ if not camera_frames:
58
+ return
59
+
60
+ try:
61
+ camera_positions = np.array([
62
+ vector3_to_numpy(frame['position']) for frame in camera_frames
63
+ ])
64
  rr.log(
65
+ "world/camera_trajectory",
66
+ rr.Points3D(
67
+ camera_positions,
68
+ colors=np.full((len(camera_positions), 4),
69
+ [0.0, 0.8, 0.8, 1.0])
70
  ),
71
  timeless=True
72
  )
73
+ except Exception as e:
74
+ print(f"Error logging camera trajectory: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
  def log_camera_frames(self, camera_frames: List[Dict[str, Any]]) -> None:
77
+ if not camera_frames:
78
+ return
79
+
80
  for frame_idx, camera_frame in enumerate(camera_frames):
81
+ try:
82
+ rr.set_time_sequence("frame", frame_idx)
83
 
84
+ position = vector3_to_numpy(camera_frame['position'])
85
+ rotation_q = euler_to_quaternion(camera_frame['angle'])
86
 
87
+ rr.log(
88
+ "world/camera",
89
+ rr.Transform3D(
90
+ translation=position,
91
+ rotation=rr.Quaternion(xyzw=rotation_q)
92
+ )
93
  )
 
94
 
95
+ rr.log(
96
+ "world/camera/view",
97
+ rr.Pinhole(
98
+ focal_length=camera_frame.get(
99
+ 'focalLength', 50), # Added default
100
+ width=1920,
101
+ height=1080
102
+ )
103
  )
 
104
 
105
+ rr.log(
106
+ "metadata/current_frame",
107
+ rr.TextDocument(
108
+ f"Frame: {frame_idx + 1}/{len(camera_frames)}"),
109
+ )
110
+ except Exception as e:
111
+ print(f"Error logging camera frame {frame_idx}: {str(e)}")
visualization/mesh.py CHANGED
@@ -13,7 +13,7 @@ def create_subject_mesh(subject: Dict) -> Tuple[np.ndarray, np.ndarray]:
13
  [-0.5, -0.5, 0.5], [0.5, -0.5, 0.5], [0.5, 0.5, 0.5], [-0.5, 0.5, 0.5]
14
  ]) * size.reshape(1, 3) + position.reshape(1, 3)
15
 
16
- # Create cube faces
17
  faces = np.array([
18
  [0, 1, 2], [0, 2, 3], # front
19
  [1, 5, 6], [1, 6, 2], # right
 
13
  [-0.5, -0.5, 0.5], [0.5, -0.5, 0.5], [0.5, 0.5, 0.5], [-0.5, 0.5, 0.5]
14
  ]) * size.reshape(1, 3) + position.reshape(1, 3)
15
 
16
+ # Create cube faces (updated to use vertex_indices instead of indices)
17
  faces = np.array([
18
  [0, 1, 2], [0, 2, 3], # front
19
  [1, 5, 6], [1, 6, 2], # right
visualization/visualizer.py CHANGED
@@ -8,13 +8,14 @@ import rerun as rr
8
 
9
 
10
  @spaces.GPU
11
- def visualize_simulation(file, simulation_index: int) -> Optional[str]:
12
- if file is None:
13
  return None
14
 
15
  try:
16
  simulations, _ = load_simulation_data(file)
17
- if simulations is None or simulation_index >= len(simulations):
 
18
  return None
19
 
20
  # Create temporary file for RRD
 
8
 
9
 
10
  @spaces.GPU
11
+ def visualize_simulation(file, simulation_index: Optional[int]) -> Optional[str]:
12
+ if file is None or simulation_index is None:
13
  return None
14
 
15
  try:
16
  simulations, _ = load_simulation_data(file)
17
+ if not simulations or not isinstance(simulation_index, int) or simulation_index < 0 or simulation_index >= len(simulations):
18
+ print(f"Invalid simulation data or index: {simulation_index}")
19
  return None
20
 
21
  # Create temporary file for RRD