Skip to content

Commit 0d355d2

Browse files
authored
Merge pull request #83 from Ipuch/main
update rerun 0.24.1
2 parents 70d3085 + da8ecf6 commit 0d355d2

File tree

14 files changed

+61
-45
lines changed

14 files changed

+61
-45
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
We can rerun c3d files and display their original content.
55
And also animate biorbd models from the pyomeca organization.
66

7-
``` conda install -c conda-forge pyorerun rerun-sdk=0.22.1```
8-
7+
``` conda install -c conda-forge pyorerun rerun-sdk=0.24.1```
98
``` conda install opensim-org::opensim # not a mandatory dependency```
109

1110
# Rerun .c3d - As simple as that

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ channels:
55
- opensim-org
66
dependencies:
77
- ezc3d
8-
- rerun-sdk=0.22.1
8+
- rerun-sdk=0.24.1
99
- numpy
1010
- matplotlib
1111
- biorbd>=1.10.5

examples/biorbd/no_mesh.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ def main():
2424
rerun_biorbd = PhaseRerun(t_span)
2525
q = np.zeros((biorbd_model.model.nbQ(), nb_frames)) # no movement
2626
rerun_biorbd.add_animated_model(biorbd_model, q)
27+
2728
markers = PyoMarkers(data=noisy_markers, channels=[f"marker_{i}" for i in range(1, nb_random_markers + 1)])
29+
markers.show_labels = False
30+
2831
rerun_biorbd.add_xp_markers(
2932
name="noisy_markers",
3033
markers=markers,

pyorerun/abstract/markers.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from abc import abstractmethod
2+
from functools import cached_property
23

34
import numpy as np
45

@@ -52,15 +53,19 @@ def __init__(
5253
radius : float | tuple[float, ...]
5354
the radius of the markers
5455
color : np.ndarray
55-
the color of the markers
56+
the color of the markers in RGB format from 0 to 255, e.g. [0, 0, 255] for blue
5657
show_labels : bool
5758
whether to show the labels of the markers (this can be changed by checking the appropriate box in the GUI)
5859
"""
5960
self.marker_names = marker_names
6061
self.radius = radius
61-
self.color = color
62+
self._color = color
6263
self.show_labels = show_labels
6364

65+
@cached_property
66+
def color(self):
67+
return rgb255_to_hex_rgba(self._color)
68+
6469
@property
6570
def nb_markers(self):
6671
"""
@@ -107,3 +112,10 @@ def show_labels_to_rerun(self) -> list[bool]:
107112
return self.show_labels
108113
else:
109114
raise ValueError("The show_labels attribute must be a boolean or a list of booleans.")
115+
116+
117+
def rgb255_to_hex_rgba(color_rgb, alpha=255) -> int:
118+
# color_rgb: np.ndarray ou list \[R, G, B] en 0–255
119+
r, g, b = [int(np.clip(c, 0, 255)) for c in color_rgb[:3]]
120+
a = int(np.clip(alpha, 0, 255))
121+
return (r << 24) | (g << 16) | (b << 8) | a

pyorerun/live_animation.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def update_rerun_components(self, the_dof_idx: int, the_value: float):
7878
self.q[the_dof_idx] = the_value
7979
# update counter
8080
self.counter += 1
81-
rr.set_time_sequence(timeline="step", sequence=self.counter)
81+
rr.set_time(timeline="step", sequence=self.counter)
8282
# Update the model
8383
self.update_model(self.q)
8484
# Update the q trajectories
@@ -93,17 +93,17 @@ def update_trajectories(self, q: np.ndarray):
9393
dof_names = self.model.dof_names
9494
for joint_idx in range(self.biorbd_model.nbQ()):
9595
name = f"q{joint_idx} - {dof_names[joint_idx]}"
96-
rr.log(f"{name}/min", rr.SeriesLine(color=[255, 0, 0], name="min", width=0.5))
97-
rr.log(f"{name}/max", rr.SeriesLine(color=[255, 0, 0], name="max", width=0.5))
98-
rr.log(f"{name}/value", rr.SeriesLine(color=[0, 255, 0], name="q", width=0.5))
96+
rr.log(f"{name}/min", rr.SeriesLines(colors=[255, 0, 0], names="min", widths=0.5))
97+
rr.log(f"{name}/max", rr.SeriesLines(colors=[255, 0, 0], names="max", widths=0.5))
98+
rr.log(f"{name}/value", rr.SeriesLines(colors=[0, 255, 0], names="q", widths=0.5))
9999

100100
q_range = q_ranges[joint_idx]
101101
self.to_serie_line(name=name, min=q_range.min(), max=q_range.max(), val=q[joint_idx])
102102

103103
def to_serie_line(self, name: str, min: float, max: float, val: float):
104-
rr.log(f"{name}/min", rr.Scalar(min))
105-
rr.log(f"{name}/max", rr.Scalar(max))
106-
rr.log(f"{name}/value", rr.Scalar(val))
104+
rr.log(f"{name}/min", rr.Scalars(min))
105+
rr.log(f"{name}/max", rr.Scalars(max))
106+
rr.log(f"{name}/value", rr.Scalars(val))
107107

108108
def rerun(self, name: str = None):
109109
# update manually here

pyorerun/model_components/model_markers.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,15 @@ def to_chunk(self, q: np.ndarray) -> dict[str, list]:
134134

135135
return {
136136
self.name: [
137-
rr.Points3D.indicator(),
138-
rr.components.Position3DBatch(markers).partition(partition),
139-
rr.components.ColorBatch([self.marker_properties.color for _ in range(nb_frames_trials)]),
140-
rr.components.RadiusBatch([self.marker_properties.radius for _ in range(nb_frames_trials)]),
141-
rr.components.TextBatch(partition_marker_names).partition(partition),
142-
rr.components.ShowLabelsBatch([self.marker_properties.show_labels for _ in range(nb_frames_trials)]),
137+
*rr.Points3D.columns(
138+
positions=markers,
139+
labels=partition_marker_names,
140+
).partition(partition),
141+
*rr.Points3D.columns(
142+
colors=[self.persistent_options.color for _ in range(nb_frames_trials)],
143+
radii=[self.persistent_options.radius for _ in range(nb_frames_trials)],
144+
show_labels=[self.persistent_options.show_labels for _ in range(nb_frames_trials)],
145+
),
143146
]
144147
}
145148

pyorerun/multi_frame_rate_phase_rerun.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ def rerun_by_frame(
8585

8686
for phase_rerun in self.phase_reruns:
8787
frame = 0
88-
rr.set_time_seconds("stable_time", phase_rerun.t_span[frame])
88+
rr.set_time("stable_time", duration=phase_rerun.t_span[frame])
8989
phase_rerun.timeless_components.to_rerun()
9090
phase_rerun.biorbd_models.to_rerun(frame)
9191
phase_rerun.xp_data.to_rerun(frame)
9292

9393
cumulative_frames_in_merged_t_span = self.cumulative_frames_in_merged_t_span
9494
for frame, (t, idx) in enumerate(zip(self.merged_t_span[1:], self.frame_t_span_idx[1:])):
95-
rr.set_time_seconds("stable_time", t)
95+
rr.set_time("stable_time", duration=t)
9696
for i in idx:
9797
frame_i = cumulative_frames_in_merged_t_span[i][frame + 1]
9898
self.phase_reruns[i].biorbd_models.to_rerun(frame_i)
@@ -119,12 +119,12 @@ def rerun(
119119

120120
for phase_rerun in self.phase_reruns:
121121
frame = 0
122-
rr.set_time_seconds("stable_time", phase_rerun.t_span[frame])
122+
rr.set_time("stable_time", duration=phase_rerun.t_span[frame])
123123
phase_rerun.timeless_components.to_rerun()
124124
phase_rerun.models.initialize()
125125
phase_rerun.xp_data.initialize()
126126

127-
times = [rr.TimeSecondsColumn("stable_time", phase_rerun.t_span)]
127+
times = [rr.TimeColumn("stable_time", duration=phase_rerun.t_span)]
128128

129129
for name, chunk in phase_rerun.xp_data.to_chunk().items():
130130
rr.send_columns(

pyorerun/phase_rerun.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,13 @@ def rerun_by_frame(
240240
rr.init(f"{name}_{self.phase}", spawn=True if not notebook else False)
241241

242242
frame = 0
243-
rr.set_time_seconds("stable_time", self.t_span[frame])
243+
rr.set_time("stable_time", duration=self.t_span[frame])
244244
self.timeless_components.to_rerun()
245245
self.models.to_rerun(frame)
246246
self.xp_data.to_rerun(frame)
247247

248248
for frame, t in enumerate(self.t_span[1:]):
249-
rr.set_time_seconds("stable_time", t)
249+
rr.set_time("stable_time", duration=t)
250250
self.models.to_rerun(frame + 1)
251251
self.xp_data.to_rerun(frame + 1)
252252

@@ -265,12 +265,12 @@ def rerun(
265265
rr.init(f"{name}_{self.phase}", spawn=True if not notebook else False)
266266

267267
frame = 0
268-
rr.set_time_seconds("stable_time", self.t_span[frame])
268+
rr.set_time("stable_time", duration=self.t_span[frame])
269269
self.timeless_components.to_rerun()
270270
self.models.initialize()
271271
self.xp_data.initialize()
272272

273-
times = [rr.TimeSecondsColumn("stable_time", self.t_span)]
273+
times = [rr.TimeColumn("stable_time", duration=self.t_span)]
274274

275275
for name, chunk in self.xp_data.to_chunk().items():
276276
rr.send_columns(
@@ -287,7 +287,7 @@ def rerun(
287287
)
288288

289289
if clear_last_node:
290-
rr.set_time_seconds("stable_time", self.t_span[-1])
290+
rr.set_time("stable_time", duration=self.t_span[-1])
291291
for component in [
292292
*self.models.component_names,
293293
*self.xp_data.component_names,

pyorerun/rrc3d.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ def rrc3d(
136136
for j, axis in enumerate(["X", "Y", "Z"]):
137137
rr.send_columns(
138138
f"markers_graphs/{m}/{axis}",
139-
indexes=[rr.TimeSecondsColumn("stable_time", t_span)],
139+
indexes=[rr.TimeColumn("stable_time", duration=t_span)],
140140
columns=[
141-
*rr.Scalar.columns(
142-
scalar=phase_rerun.xp_data.xp_data[0].markers_numpy[j, marker_names.index(m), :]
141+
*rr.Scalars.columns(
142+
scalars=phase_rerun.xp_data.xp_data[0].markers_numpy[j, marker_names.index(m), :]
143143
)
144144
],
145145
)
@@ -153,7 +153,7 @@ def set_event_as_log(c3d_file: str) -> None:
153153
context = c3d_file["parameters"]["EVENT"]["CONTEXTS"]["value"]
154154

155155
for i, (time, label, description, context) in enumerate(zip(times, labels, descriptions, context)):
156-
rr.set_time_seconds("stable_time", time)
156+
rr.set_time("stable_time", duration=time)
157157
rr.log(
158158
f"events",
159159
rr.TextLog(

pyorerun/xp_components/force_vector.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import rerun as rr
55

66
from ..abstract.abstract_class import ExperimentalData
7+
from ..abstract.markers import rgb255_to_hex_rgba
8+
9+
VECTOR_COLOR = rgb255_to_hex_rgba(np.array([201, 219, 227]))
710

811

912
class Vector(ExperimentalData, ABC):
@@ -27,7 +30,7 @@ def to_component(self, frame: int) -> np.ndarray:
2730
return rr.Arrows3D(
2831
origins=self.vector_origins[:, frame],
2932
vectors=self.vector_magnitude[:, frame],
30-
colors=np.array([201, 219, 227]),
33+
colors=VECTOR_COLOR,
3134
)
3235

3336
def initialize(self):
@@ -41,20 +44,12 @@ def to_rerun(self, frame) -> None:
4144

4245
def to_chunk(self, **kwargs) -> dict[str, list]:
4346

44-
# return {
45-
# self.name: [
46-
# rr.Arrows3D.indicator(),
47-
# rr.components.Position3DBatch(self.vector_origins.T),
48-
# rr.components.Vector3DBatch(self.vector_magnitude.T),
49-
# rr.components.ColorBatch([np.array([201, 219, 227]) for _ in range(self.nb_frames)]),
50-
# ]
51-
# }
5247
return {
5348
self.name: [
5449
*rr.Arrows3D.columns(
5550
origins=self.vector_origins.T.tolist(),
5651
vectors=self.vector_magnitude.T.tolist(),
57-
colors=[np.array([201, 219, 227]) for _ in range(self.nb_frames)],
52+
colors=[VECTOR_COLOR for _ in range(self.nb_frames)],
5853
)
5954
]
6055
}

0 commit comments

Comments
 (0)