Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: minor faster ligament #49

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/biorbd/msk_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def main():
# viz.add_animated_model(model, q, display_q=True)
viz.add_animated_model(model, q, display_q=False)
tic = time.time()
viz.rerun("msk_model")
viz.rerun("msk_model with chunks")
toc = time.time()
print(f"Time to run: {toc - tic}")

tic = time.time()
viz.rerun_by_frame("msk_model with chunk")
# viz.rerun_by_frame("msk_model frame by frame")
toc = time.time()
print(f"Time to run with chunks: {toc - tic}")

Expand Down
29 changes: 12 additions & 17 deletions pyorerun/biorbd_components/ligaments.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,20 @@ def compute_strips(self, q: np.ndarray) -> list:

def to_chunk(self, q: np.ndarray) -> dict[str, list]:
nb_frames = q.shape[1]
# partition = [self.nb_strips for _ in range(nb_frames)]

strips_by_frame = self.compute_strips(q)
strips_output = {}
for s in range(self.nb_strips):
strips_output.update(
{
f"{self.name}_{s}": [
rr.LineStrips3D.indicator(),
rr.components.LineStrip3DBatch([strips_by_frame[f][s] for f in range(nb_frames)]),
rr.components.ColorBatch([self.properties.color for _ in range(nb_frames)]),
rr.components.RadiusBatch([self.properties.radius for _ in range(nb_frames)]),
rr.components.TextBatch([self.properties.strip_names[s] for _ in range(nb_frames)]),
]
}
)

return strips_output
colors = [self.properties.color for _ in range(nb_frames)]
radii = [self.properties.radius for _ in range(nb_frames)]
return {
f"{self.name}_{s}": [
rr.LineStrips3D.indicator(),
rr.components.LineStrip3DBatch([strips_by_frame[f][s] for f in range(nb_frames)]),
rr.components.ColorBatch(colors),
rr.components.RadiusBatch(radii),
rr.components.TextBatch([self.properties.strip_names[s] for _ in range(nb_frames)]),
]
for s in range(self.nb_strips)
}


class LigamentsUpdater(LineStripUpdater):
Expand Down Expand Up @@ -122,7 +118,6 @@ def to_chunk(self, q: np.ndarray, markers: np.ndarray) -> dict[str, list]:

strips_output = {}
for s in range(self.nb_strips):
print(self.name, s)
strips_output.update(
{
f"{self.name}_{s}": [
Expand Down
3 changes: 1 addition & 2 deletions pyorerun/rrc3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ def rrc3d(
phase_reruns[-1].add_video(vid_name, np.array(vid, dtype=np.uint8))

multi_phase_rerun = MultiFrameRatePhaseRerun(phase_reruns)
# multi_phase_rerun.rerun(filename, notebook=notebook)
multi_phase_rerun.rerun_with_chunks(filename, notebook=notebook)
multi_phase_rerun.rerun(filename, notebook=notebook)

if show_events:
try:
Expand Down
Loading