Spaces:
Running
on
Zero
Running
on
Zero
Update visualization/logger.py
Browse files- visualization/logger.py +13 -10
visualization/logger.py
CHANGED
@@ -4,9 +4,9 @@ from typing import Dict, Any, List
|
|
4 |
from utils.geometry import vector3_to_numpy, euler_to_quaternion
|
5 |
|
6 |
|
7 |
-
def create_subject_box(
|
8 |
-
position = vector3_to_numpy(
|
9 |
-
size =
|
10 |
|
11 |
return {
|
12 |
'center': position,
|
@@ -42,7 +42,7 @@ class SimulationLogger:
|
|
42 |
])
|
43 |
), timeless=True)
|
44 |
|
45 |
-
def log_subjects(self, subjects: List[Dict[str, Any]]) -> None:
|
46 |
if not subjects:
|
47 |
return
|
48 |
|
@@ -53,7 +53,9 @@ class SimulationLogger:
|
|
53 |
|
54 |
for subject in subjects:
|
55 |
try:
|
56 |
-
|
|
|
|
|
57 |
centers.append(box_params['center'])
|
58 |
half_sizes.append(box_params['half_size'])
|
59 |
colors.append([0.8, 0.2, 0.2, 1.0])
|
@@ -71,8 +73,7 @@ class SimulationLogger:
|
|
71 |
colors=np.array(colors),
|
72 |
show_labels=False,
|
73 |
fill_mode="solid"
|
74 |
-
)
|
75 |
-
timeless=True
|
76 |
)
|
77 |
|
78 |
def log_camera_trajectory(self, camera_frames: List[Dict[str, Any]]) -> None:
|
@@ -108,7 +109,7 @@ class SimulationLogger:
|
|
108 |
except Exception as e:
|
109 |
print(f"Error logging camera trajectory: {str(e)}")
|
110 |
|
111 |
-
def log_camera_frames(self, camera_frames: List[Dict[str, Any]]) -> None:
|
112 |
if not camera_frames:
|
113 |
return
|
114 |
|
@@ -136,6 +137,9 @@ class SimulationLogger:
|
|
136 |
)
|
137 |
)
|
138 |
|
|
|
|
|
|
|
139 |
except Exception as e:
|
140 |
print(f"Error logging camera frame {frame_idx}: {str(e)}")
|
141 |
|
@@ -143,7 +147,6 @@ class SimulationLogger:
|
|
143 |
if not helper_keyframes:
|
144 |
return
|
145 |
|
146 |
-
|
147 |
helper_positions = np.array([
|
148 |
vector3_to_numpy(frame['position']) for frame in helper_keyframes
|
149 |
])
|
@@ -183,4 +186,4 @@ class SimulationLogger:
|
|
183 |
|
184 |
except Exception as e:
|
185 |
print(
|
186 |
-
f"Error logging helper keyframe {keyframe_idx}: {str(e)}")
|
|
|
4 |
from utils.geometry import vector3_to_numpy, euler_to_quaternion
|
5 |
|
6 |
|
7 |
+
def create_subject_box(frame: Dict, dimensions: Dict) -> Dict[str, np.ndarray]:
|
8 |
+
position = vector3_to_numpy(frame['position'])
|
9 |
+
size = np.array([dimensions['width'], dimensions['height'], dimensions['depth']])
|
10 |
|
11 |
return {
|
12 |
'center': position,
|
|
|
42 |
])
|
43 |
), timeless=True)
|
44 |
|
45 |
+
def log_subjects(self, subjects: List[Dict[str, Any]], frame_idx: int = 0) -> None:
|
46 |
if not subjects:
|
47 |
return
|
48 |
|
|
|
53 |
|
54 |
for subject in subjects:
|
55 |
try:
|
56 |
+
# Use the frame at frame_idx, or the first frame if frame_idx is out of range
|
57 |
+
frame = subject['frames'][min(frame_idx, len(subject['frames']) - 1)]
|
58 |
+
box_params = create_subject_box(frame, subject['dimensions'])
|
59 |
centers.append(box_params['center'])
|
60 |
half_sizes.append(box_params['half_size'])
|
61 |
colors.append([0.8, 0.2, 0.2, 1.0])
|
|
|
73 |
colors=np.array(colors),
|
74 |
show_labels=False,
|
75 |
fill_mode="solid"
|
76 |
+
)
|
|
|
77 |
)
|
78 |
|
79 |
def log_camera_trajectory(self, camera_frames: List[Dict[str, Any]]) -> None:
|
|
|
109 |
except Exception as e:
|
110 |
print(f"Error logging camera trajectory: {str(e)}")
|
111 |
|
112 |
+
def log_camera_frames(self, camera_frames: List[Dict[str, Any]], subjects: List[Dict[str, Any]]) -> None:
|
113 |
if not camera_frames:
|
114 |
return
|
115 |
|
|
|
137 |
)
|
138 |
)
|
139 |
|
140 |
+
# Log subjects for this frame
|
141 |
+
self.log_subjects(subjects, frame_idx)
|
142 |
+
|
143 |
except Exception as e:
|
144 |
print(f"Error logging camera frame {frame_idx}: {str(e)}")
|
145 |
|
|
|
147 |
if not helper_keyframes:
|
148 |
return
|
149 |
|
|
|
150 |
helper_positions = np.array([
|
151 |
vector3_to_numpy(frame['position']) for frame in helper_keyframes
|
152 |
])
|
|
|
186 |
|
187 |
except Exception as e:
|
188 |
print(
|
189 |
+
f"Error logging helper keyframe {keyframe_idx}: {str(e)}")
|