Spaces:
Running
on
Zero
Running
on
Zero
Update visualization/logger.py
Browse files- visualization/logger.py +62 -6
visualization/logger.py
CHANGED
@@ -56,14 +56,13 @@ class SimulationLogger:
|
|
56 |
|
57 |
def log_subjects(self, subjects: List[Dict[str, Any]]) -> None:
|
58 |
"""
|
59 |
-
|
60 |
- Each subject has multiple frames (position, rotation).
|
61 |
- Subject dimensions (width, height, depth) remain constant across frames.
|
62 |
"""
|
63 |
if not subjects:
|
64 |
return
|
65 |
|
66 |
-
# For each subject, log each frame at a different time index.
|
67 |
for subject_idx, subject in enumerate(subjects):
|
68 |
dimensions = subject.get("dimensions", {})
|
69 |
frames = subject.get("frames", [])
|
@@ -80,7 +79,7 @@ class SimulationLogger:
|
|
80 |
# Convert Euler angles to quaternion for rotation
|
81 |
rotation_q = euler_to_quaternion(frame['rotation'])
|
82 |
|
83 |
-
# 1) Log a transform for
|
84 |
rr.log(
|
85 |
f"world/subjects/subject_{subject_idx}",
|
86 |
rr.Transform3D(
|
@@ -101,19 +100,73 @@ class SimulationLogger:
|
|
101 |
fill_mode="solid"
|
102 |
)
|
103 |
)
|
|
|
104 |
except Exception as e:
|
105 |
print(f"Error creating box parameters for subject {subject_idx}, frame {frame_idx}: {str(e)}")
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
def log_camera_trajectory(self, camera_frames: List[Dict[str, Any]]) -> None:
|
|
|
|
|
|
|
|
|
108 |
if not camera_frames:
|
109 |
return
|
110 |
|
111 |
try:
|
112 |
camera_positions = np.array([
|
113 |
vector3_to_numpy(frame['position']) for frame in camera_frames
|
114 |
-
])
|
|
|
115 |
rr.log(
|
116 |
-
"world/
|
117 |
rr.Points3D(
|
118 |
camera_positions,
|
119 |
colors=np.full((len(camera_positions), 4), [0.0, 0.8, 0.8, 1.0])
|
@@ -124,7 +177,7 @@ class SimulationLogger:
|
|
124 |
if len(camera_positions) > 1:
|
125 |
lines = np.stack([camera_positions[:-1], camera_positions[1:]], axis=1)
|
126 |
rr.log(
|
127 |
-
"world/
|
128 |
rr.LineStrips3D(
|
129 |
lines,
|
130 |
colors=[(0.0, 0.8, 0.8, 1.0)]
|
@@ -136,6 +189,9 @@ class SimulationLogger:
|
|
136 |
print(f"Error logging camera trajectory: {str(e)}")
|
137 |
|
138 |
def log_camera_frames(self, camera_frames: List[Dict[str, Any]]) -> None:
|
|
|
|
|
|
|
139 |
if not camera_frames:
|
140 |
return
|
141 |
|
|
|
56 |
|
57 |
def log_subjects(self, subjects: List[Dict[str, Any]]) -> None:
|
58 |
"""
|
59 |
+
Handles dynamic subjects:
|
60 |
- Each subject has multiple frames (position, rotation).
|
61 |
- Subject dimensions (width, height, depth) remain constant across frames.
|
62 |
"""
|
63 |
if not subjects:
|
64 |
return
|
65 |
|
|
|
66 |
for subject_idx, subject in enumerate(subjects):
|
67 |
dimensions = subject.get("dimensions", {})
|
68 |
frames = subject.get("frames", [])
|
|
|
79 |
# Convert Euler angles to quaternion for rotation
|
80 |
rotation_q = euler_to_quaternion(frame['rotation'])
|
81 |
|
82 |
+
# 1) Log a transform for this subject so the box is placed at 'center' with correct rotation
|
83 |
rr.log(
|
84 |
f"world/subjects/subject_{subject_idx}",
|
85 |
rr.Transform3D(
|
|
|
100 |
fill_mode="solid"
|
101 |
)
|
102 |
)
|
103 |
+
|
104 |
except Exception as e:
|
105 |
print(f"Error creating box parameters for subject {subject_idx}, frame {frame_idx}: {str(e)}")
|
106 |
|
107 |
+
def log_subject_trajectories(self, subjects: List[Dict[str, Any]]) -> None:
|
108 |
+
"""
|
109 |
+
For each subject, collect all frame centers and log them as:
|
110 |
+
- A set of 3D points (subject center positions).
|
111 |
+
- A line strip connecting them (showing the subject's center path).
|
112 |
+
This is done timelessly so the full trajectory is always visible.
|
113 |
+
"""
|
114 |
+
if not subjects:
|
115 |
+
return
|
116 |
+
|
117 |
+
for subject_idx, subject in enumerate(subjects):
|
118 |
+
dimensions = subject.get("dimensions", {})
|
119 |
+
frames = subject.get("frames", [])
|
120 |
+
label = subject.get('objectClass', f"Subject_{subject_idx}")
|
121 |
+
|
122 |
+
if not frames:
|
123 |
+
continue
|
124 |
+
|
125 |
+
# Gather center positions
|
126 |
+
center_positions = []
|
127 |
+
for frame in frames:
|
128 |
+
pos = vector3_to_numpy(frame['position'])
|
129 |
+
center_positions.append(pos)
|
130 |
+
|
131 |
+
center_positions = np.array(center_positions, dtype=np.float32)
|
132 |
+
|
133 |
+
# Log the points
|
134 |
+
rr.log(
|
135 |
+
f"world/subjects/subject_{subject_idx}/center_trajectory_points",
|
136 |
+
rr.Points3D(
|
137 |
+
center_positions,
|
138 |
+
colors=np.full((len(center_positions), 4), [0.8, 0.6, 0.2, 1.0])
|
139 |
+
),
|
140 |
+
timeless=True
|
141 |
+
)
|
142 |
+
|
143 |
+
# Log a line strip
|
144 |
+
if len(center_positions) > 1:
|
145 |
+
lines = np.stack([center_positions[:-1], center_positions[1:]], axis=1)
|
146 |
+
rr.log(
|
147 |
+
f"world/subjects/subject_{subject_idx}/center_trajectory_line",
|
148 |
+
rr.LineStrips3D(
|
149 |
+
lines,
|
150 |
+
colors=[(0.8, 0.6, 0.2, 1.0)],
|
151 |
+
),
|
152 |
+
timeless=True
|
153 |
+
)
|
154 |
+
|
155 |
def log_camera_trajectory(self, camera_frames: List[Dict[str, Any]]) -> None:
|
156 |
+
"""
|
157 |
+
Logs the entire camera trajectory as a set of 3D points and a connecting line strip.
|
158 |
+
This is typically done timelessly to show the full path at once.
|
159 |
+
"""
|
160 |
if not camera_frames:
|
161 |
return
|
162 |
|
163 |
try:
|
164 |
camera_positions = np.array([
|
165 |
vector3_to_numpy(frame['position']) for frame in camera_frames
|
166 |
+
], dtype=np.float32)
|
167 |
+
|
168 |
rr.log(
|
169 |
+
"world/camera_trajectory_points",
|
170 |
rr.Points3D(
|
171 |
camera_positions,
|
172 |
colors=np.full((len(camera_positions), 4), [0.0, 0.8, 0.8, 1.0])
|
|
|
177 |
if len(camera_positions) > 1:
|
178 |
lines = np.stack([camera_positions[:-1], camera_positions[1:]], axis=1)
|
179 |
rr.log(
|
180 |
+
"world/camera_trajectory_line",
|
181 |
rr.LineStrips3D(
|
182 |
lines,
|
183 |
colors=[(0.0, 0.8, 0.8, 1.0)]
|
|
|
189 |
print(f"Error logging camera trajectory: {str(e)}")
|
190 |
|
191 |
def log_camera_frames(self, camera_frames: List[Dict[str, Any]]) -> None:
|
192 |
+
"""
|
193 |
+
Logs each camera frame at a given time sequence, so you can watch it update over time.
|
194 |
+
"""
|
195 |
if not camera_frames:
|
196 |
return
|
197 |
|