-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from Ipuch/main
feat: forceplates and floor displayed with c3d
- Loading branch information
Showing
8 changed files
with
303 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,3 +160,5 @@ cython_debug/ | |
#.idea/ | ||
|
||
.idea/ | ||
|
||
sandbox/ |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import os | ||
|
||
import pyorerun as prr | ||
|
||
print(os.getcwd()) | ||
prr.c3d("gait.c3d") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .floor import Floor | ||
from .force_plate import ForcePlate | ||
from .gravity import Gravity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import numpy as np | ||
import rerun as rr | ||
|
||
from ..abstract.abstract_class import TimelessComponent | ||
|
||
|
||
class Floor(TimelessComponent): | ||
|
||
def __init__(self, name, square_width: float, height_offset: float, subsquares: int): | ||
self.name = name + "/floor" | ||
self.vertices, self.faces = floor_mesh( | ||
square_width=square_width, | ||
height_offset=height_offset if height_offset is not None else 0, | ||
subsquares=subsquares if subsquares is not None else 10, | ||
) | ||
|
||
@property | ||
def nb_components(self): | ||
return 1 | ||
|
||
def to_rerun(self) -> None: | ||
rr.log( | ||
"floor", | ||
rr.Mesh3D( | ||
vertex_positions=self.vertices, | ||
vertex_normals=np.tile([0.0, 0.0, 1.0], reps=(self.vertices.shape[0], 1)), | ||
vertex_colors=np.tile([150, 150, 150], reps=(self.vertices.shape[0], 1)), | ||
indices=self.faces, | ||
), | ||
) | ||
|
||
|
||
def floor_mesh(square_width: float, height_offset: float, subsquares: int) -> tuple[np.ndarray, np.ndarray]: | ||
""" | ||
Display a floor in rerun. | ||
Parameters | ||
---------- | ||
square_width: float | ||
The width of the floor in meters centered in zero. | ||
height_offset: float | ||
The height offset of the floor. | ||
subsquares: int | ||
The number of subsquares for each side of the floor. The total number of subsquares is subsquares^2. | ||
Returns | ||
------- | ||
np.ndarray | ||
The vertices of the floor. | ||
np.ndarray | ||
The faces of the floor. | ||
""" | ||
x, y = np.meshgrid( | ||
np.linspace(-square_width, square_width, subsquares), | ||
np.linspace(-square_width, square_width, subsquares), | ||
) | ||
|
||
vertices = [] | ||
faces = [] | ||
base_index = 0 | ||
|
||
for i in range(0, subsquares - 1, 1): | ||
starting_j = 0 if i % 2 == 0 else 1 | ||
for j in range(starting_j, subsquares - 1, 2): | ||
triangle1_vertices = [ | ||
(x[i, j], y[i, j], height_offset), | ||
(x[i + 1, j], y[i + 1, j], height_offset), | ||
(x[i, j + 1], y[i, j + 1], height_offset), | ||
] | ||
triangle2_vertices = [ | ||
(x[i + 1, j + 1], y[i + 1, j + 1], height_offset), | ||
] | ||
|
||
vertices.extend(triangle1_vertices) | ||
vertices.extend(triangle2_vertices) | ||
|
||
triangle1_faces = [(base_index, base_index + 1, base_index + 2)] | ||
triangle2_faces = [(base_index + 3, base_index + 1, base_index + 2)] | ||
|
||
faces.extend(triangle1_faces) | ||
faces.extend(triangle2_faces) | ||
|
||
base_index += 4 | ||
|
||
return np.array(vertices), np.array(faces) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import numpy as np | ||
import rerun as rr | ||
|
||
from ..abstract.abstract_class import TimelessComponent | ||
|
||
|
||
class ForcePlate(TimelessComponent): | ||
|
||
def __init__(self, name, num: int, corners: np.ndarray): | ||
self.entity = f"force_plate{num}" | ||
self.name = name + f"/{self.entity}" | ||
self.vertices, self.faces = rectangle_mesh_from_corners(corners) | ||
|
||
@property | ||
def nb_components(self): | ||
return 1 | ||
|
||
def to_rerun(self) -> None: | ||
rr.log( | ||
self.entity, | ||
rr.Mesh3D( | ||
vertex_positions=self.vertices, | ||
vertex_normals=np.tile([0.0, 0.0, 1.0], reps=(self.vertices.shape[0], 1)), | ||
vertex_colors=np.tile([1, 150, 150], reps=(self.vertices.shape[0], 1)), | ||
indices=self.faces, | ||
), | ||
) | ||
|
||
|
||
def rectangle_mesh_from_corners(corners: np.ndarray) -> tuple[np.ndarray, np.ndarray]: | ||
""" | ||
Create a rectangle mesh from the corners. | ||
Parameters | ||
---------- | ||
corners: np.ndarray | ||
The corners of the rectangle. | ||
Returns | ||
------- | ||
np.ndarray | ||
The vertices of the floor. | ||
np.ndarray | ||
The faces of the floor. | ||
""" | ||
|
||
vertices = corners.T | ||
|
||
triangle1_faces = [0, 1, 2] | ||
triangle2_faces = [2, 3, 0] | ||
|
||
faces = [] | ||
faces.extend(triangle1_faces) | ||
faces.extend(triangle2_faces) | ||
|
||
return vertices, np.array(faces) | ||
|
||
|
||
def rectangle_mesh(length: float, width: float, height: float) -> tuple[np.ndarray, np.ndarray]: | ||
""" | ||
Create a rectangle mesh centered in zero. | ||
Parameters | ||
---------- | ||
length: float | ||
The length of the rectangle in meters (x-axis). | ||
width: float | ||
The width of the rectangle in meters (y-axis). | ||
height: float | ||
The height of the rectangle in meters (z-axis). | ||
Returns | ||
------- | ||
np.ndarray | ||
The vertices of the floor. | ||
np.ndarray | ||
The faces of the floor. | ||
""" | ||
x, y = np.meshgrid( | ||
np.linspace(-length / 2, length / 2, 2), | ||
np.linspace(-width / 2, width / 2, 2), | ||
) | ||
|
||
vertices = [] | ||
faces = [] | ||
base_index = 0 | ||
|
||
for i in range(0, 1, 1): | ||
for j in range(0, 1, 1): | ||
triangle1_vertices = [ | ||
(x[i, j], y[i, j], height), | ||
(x[i + 1, j], y[i + 1, j], height), | ||
(x[i, j + 1], y[i, j + 1], height), | ||
] | ||
triangle2_vertices = [ | ||
(x[i + 1, j + 1], y[i + 1, j + 1], height), | ||
] | ||
|
||
vertices.extend(triangle1_vertices) | ||
vertices.extend(triangle2_vertices) | ||
|
||
triangle1_faces = [(base_index, base_index + 1, base_index + 2)] | ||
triangle2_faces = [(base_index + 3, base_index + 1, base_index + 2)] | ||
|
||
faces.extend(triangle1_faces) | ||
faces.extend(triangle2_faces) | ||
|
||
base_index += 4 | ||
|
||
return np.array(vertices), np.array(faces) |