Skip to content

Commit

Permalink
Merge pull request #28 from Ipuch/multiframerate
Browse files Browse the repository at this point in the history
fix: q viz without ranges
  • Loading branch information
Ipuch authored May 24, 2024
2 parents ddf8c1a + 63f2836 commit bc35f7d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pyorerun/abstract/q.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class QProperties:
def __init__(
self,
joint_names: list[str, ...] | tuple[str, ...],
ranges: tuple[tuple[float, float], ...],
ranges: tuple[tuple[float, float], ...] = None,
width: float = None,
):
"""
Expand Down
4 changes: 4 additions & 0 deletions pyorerun/biorbd_components/model_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ def q_ranges(self) -> tuple[tuple[float, float], ...]:
def gravity(self) -> np.ndarray:
return self.model.getGravity().to_array()

@property
def has_mesh(self) -> bool:
return any([s.has_mesh for s in self.segments])


class BiorbdModel(BiorbdModelNoMesh):
"""
Expand Down
9 changes: 6 additions & 3 deletions pyorerun/biorbd_components/model_updapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np

from .mesh import TransformableMeshUpdater
from .model_interface import BiorbdModel
from .model_interface import BiorbdModel, BiorbdModelNoMesh
from .model_markers import MarkersUpdater
from .segment import SegmentUpdater
from ..abstract.abstract_class import Components
Expand All @@ -15,7 +15,7 @@


class ModelUpdater(Components):
def __init__(self, name, model: BiorbdModel):
def __init__(self, name, model: BiorbdModelNoMesh):
self.name = name
self.model = model
self.markers = self.create_markers_updater()
Expand Down Expand Up @@ -54,7 +54,10 @@ def from_file(cls, model_path: str):
"""
model = BiorbdModel(model_path)
return cls(model.name, model)
if model.has_mesh:
return cls(model.name, model)

return cls(model.name, BiorbdModelNoMesh(model_path))

def create_markers_updater(self):
if self.model.nb_markers == 0:
Expand Down
10 changes: 7 additions & 3 deletions pyorerun/phase_rerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ def add_xp_markers(self, name, markers: PyoMarkers) -> None:
self.xp_data.add_data(MarkersXp(name=f"{self.name}/{name}", markers=markers))

def add_q(
self, name: str, q: np.ndarray, ranges: tuple[tuple[float, float], ...], dof_names: tuple[str, ...]
self,
name: str,
q: np.ndarray,
dof_names: tuple[str, ...],
ranges: tuple[tuple[float, float], ...] = None,
) -> None:
"""
Add the generalized coordinates to be displqyed.
Expand All @@ -140,10 +144,10 @@ def add_q(
The name of the q set.
q: np.ndarray
The generalized coordinates to display of shape (nb_q, nb_frames).
ranges: tuple[tuple[float, float], ...]
The ranges of the q values, min and max.
dof_names: tuple[str, ...]
The names of the degrees of freedom.
ranges: tuple[tuple[float, float], ...]
The ranges of the q values, min and max.
"""
if q.shape[1] != self.t_span.shape[0]:
raise ValueError(
Expand Down
40 changes: 26 additions & 14 deletions pyorerun/xp_components/timeseries_q.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,32 @@ def nb_components(self):
return 1

def to_rerun(self, frame: int) -> None:
for joint_idx in range(self.nb_q):
name = f"{self.properties.displayed_joint_names[joint_idx]}"
qmin, qmax = self.properties.ranges[joint_idx]
# todo: this log calls should be done once for all somewhere in the properties of Q
rr.log(
f"{name}/min", rr.SeriesLine(color=self.properties.min_color, name="min", width=self.properties.width)
)
rr.log(
f"{name}/max", rr.SeriesLine(color=self.properties.max_color, name="max", width=self.properties.width)
)
rr.log(
f"{name}/value", rr.SeriesLine(color=self.properties.value_color, name="q", width=self.properties.width)
)
self.to_serie_line(name=name, min=qmin, max=qmax, val=self.q[joint_idx, frame])
if self.properties.ranges is None:
for joint_idx in range(self.nb_q):
name = f"{self.properties.displayed_joint_names[joint_idx]}"
rr.log(
f"{name}/value",
rr.SeriesLine(color=self.properties.value_color, name="q", width=self.properties.width),
)
rr.log(f"{name}/value", rr.Scalar(self.q[joint_idx, frame]))
else:
for joint_idx in range(self.nb_q):
name = f"{self.properties.displayed_joint_names[joint_idx]}"
qmin, qmax = self.properties.ranges[joint_idx]
# todo: this log calls should be done once for all somewhere in the properties of Q
rr.log(
f"{name}/min",
rr.SeriesLine(color=self.properties.min_color, name="min", width=self.properties.width),
)
rr.log(
f"{name}/max",
rr.SeriesLine(color=self.properties.max_color, name="max", width=self.properties.width),
)
rr.log(
f"{name}/value",
rr.SeriesLine(color=self.properties.value_color, name="q", width=self.properties.width),
)
self.to_serie_line(name=name, min=qmin, max=qmax, val=self.q[joint_idx, frame])

@staticmethod
def to_serie_line(name: str, min: float, max: float, val: float):
Expand Down

0 comments on commit bc35f7d

Please sign in to comment.