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

Expose all Rerun enums and types to main module scope #1598

Merged
merged 6 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 4 additions & 7 deletions examples/python/api_demo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

import numpy as np
import rerun as rr
from rerun.log.annotation import AnnotationInfo
from rerun.log.rects import RectFormat
from rerun.log.text import LoggingHandler, LogLevel
from scipy.spatial.transform import Rotation


Expand Down Expand Up @@ -69,7 +66,7 @@ def run_segmentation() -> None:
rr.set_time_seconds("sim_time", 4)
rr.log_annotation_context(
"seg_demo",
[AnnotationInfo(13, color=(255, 0, 0)), (42, "label2", (0, 255, 0)), AnnotationInfo(99, label="label3")],
[rr.AnnotationInfo(13, color=(255, 0, 0)), (42, "label2", (0, 255, 0)), rr.AnnotationInfo(99, label="label3")],
timeless=False,
)
rr.log_text_entry("logs/seg_demo_log", "label1 disappears and everything with label3 is now default colored again")
Expand Down Expand Up @@ -124,7 +121,7 @@ def run_rects() -> None:
rects_wh = np.random.rand(20, 2) * (1024 - rects_xy + 1)
rects = np.hstack((rects_xy, rects_wh))
colors = np.array([[random.randrange(255) for _ in range(3)] for _ in range(20)])
rr.log_rects("rects_demo/rects", rects, colors=colors, rect_format=RectFormat.XYWH)
rr.log_rects("rects_demo/rects", rects, colors=colors, rect_format=rr.RectFormat.XYWH)

# Clear the rectangles by logging an empty set
rr.set_time_seconds("sim_time", 3)
Expand All @@ -133,9 +130,9 @@ def run_rects() -> None:

def run_text_logs() -> None:
rr.log_text_entry("logs", "Text with explicitly set color", color=[255, 215, 0], timeless=True)
rr.log_text_entry("logs", "this entry has loglevel TRACE", level=LogLevel.TRACE)
rr.log_text_entry("logs", "this entry has loglevel TRACE", level=rr.LogLevel.TRACE)

logging.getLogger().addHandler(LoggingHandler("logs/handler"))
logging.getLogger().addHandler(rr.LoggingHandler("logs/handler"))
logging.getLogger().setLevel(-1)
logging.info("This log got added through a `LoggingHandler`")

Expand Down
28 changes: 13 additions & 15 deletions examples/python/deep_sdf/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import rerun as rr
import trimesh
from download_dataset import AVAILABLE_MESHES, ensure_mesh_downloaded
from rerun.log.file import MeshFormat
from rerun.log.text import LogLevel
from trimesh import Trimesh

CACHE_DIR = Path(os.path.dirname(__file__)) / "cache"
Expand All @@ -64,13 +62,13 @@ def wrapper(*args, **kwargs): # type: ignore[no-untyped-def]


# TODO(cmc): This really should be the job of the SDK.
def get_mesh_format(mesh: Trimesh) -> MeshFormat:
def get_mesh_format(mesh: Trimesh) -> rr.MeshFormat:
ext = Path(mesh.metadata["file_name"]).suffix.lower()
try:
return {
".glb": MeshFormat.GLB,
".glb": rr.MeshFormat.GLB,
# ".gltf": MeshFormat.GLTF,
".obj": MeshFormat.OBJ,
".obj": rr.MeshFormat.OBJ,
}[ext]
except Exception:
raise ValueError(f"unknown file extension: {ext}")
Expand All @@ -82,21 +80,21 @@ def read_mesh(path: Path) -> Trimesh:
return cast(Trimesh, mesh)


@log_timing_decorator("global/voxel_sdf", LogLevel.DEBUG) # type: ignore[misc]
@log_timing_decorator("global/voxel_sdf", rr.LogLevel.DEBUG) # type: ignore[misc]
def compute_voxel_sdf(mesh: Trimesh, resolution: int) -> npt.NDArray[np.float32]:
print("computing voxel-based SDF")
voxvol = np.array(mesh_to_sdf.mesh_to_voxels(mesh, voxel_resolution=resolution), dtype=np.float32)
return voxvol


@log_timing_decorator("global/sample_sdf", LogLevel.DEBUG) # type: ignore[misc]
@log_timing_decorator("global/sample_sdf", rr.LogLevel.DEBUG) # type: ignore[misc]
def compute_sample_sdf(mesh: Trimesh, num_points: int) -> Tuple[npt.NDArray[np.float32], npt.NDArray[np.float32]]:
print("computing sample-based SDF")
points, sdf, _ = mesh_to_sdf.sample_sdf_near_surface(mesh, number_of_points=num_points, return_gradients=True)
return (points, sdf)


@log_timing_decorator("global/log_mesh", LogLevel.DEBUG) # type: ignore[misc]
@log_timing_decorator("global/log_mesh", rr.LogLevel.DEBUG) # type: ignore[misc]
def log_mesh(path: Path, mesh: Trimesh) -> None:
# Internally, `mesh_to_sdf` will normalize everything to a unit sphere centered around the
# center of mass.
Expand Down Expand Up @@ -126,10 +124,10 @@ def log_sampled_sdf(points: npt.NDArray[np.float32], sdf: npt.NDArray[np.float32
rr.log_text_entry(
"world/sdf/inside/logs",
f"{len(points) - len(outside)} points inside ({len(points)} total)",
level=LogLevel.TRACE,
level=rr.LogLevel.TRACE,
)
rr.log_text_entry(
"world/sdf/outside/logs", f"{len(outside)} points outside ({len(points)} total)", level=LogLevel.TRACE
"world/sdf/outside/logs", f"{len(outside)} points outside ({len(points)} total)", level=rr.LogLevel.TRACE
)


Expand All @@ -138,7 +136,7 @@ def log_volumetric_sdf(voxvol: npt.NDArray[np.float32]) -> None:
rr.log_tensor("tensor", voxvol, names=names)


@log_timing_decorator("global/log_mesh", LogLevel.DEBUG) # type: ignore[misc]
@log_timing_decorator("global/log_mesh", rr.LogLevel.DEBUG) # type: ignore[misc]
def compute_and_log_volumetric_sdf(mesh_path: Path, mesh: Trimesh, resolution: int) -> None:
os.makedirs(CACHE_DIR, exist_ok=True)
basename = os.path.basename(mesh_path)
Expand All @@ -154,10 +152,10 @@ def compute_and_log_volumetric_sdf(mesh_path: Path, mesh: Trimesh, resolution: i

with open(voxvol_path, "wb+") as f:
np.save(f, voxvol)
rr.log_text_entry("global", "writing volumetric SDF to cache", level=LogLevel.DEBUG)
rr.log_text_entry("global", "writing volumetric SDF to cache", level=rr.LogLevel.DEBUG)


@log_timing_decorator("global/log_mesh", LogLevel.DEBUG) # type: ignore[misc]
@log_timing_decorator("global/log_mesh", rr.LogLevel.DEBUG) # type: ignore[misc]
def compute_and_log_sample_sdf(mesh_path: Path, mesh: Trimesh, num_points: int) -> None:
basename = os.path.basename(mesh_path)
points_path = f"{CACHE_DIR}/{basename}.points.{num_points}.npy"
Expand All @@ -179,10 +177,10 @@ def compute_and_log_sample_sdf(mesh_path: Path, mesh: Trimesh, num_points: int)

with open(points_path, "wb+") as f:
np.save(f, points)
rr.log_text_entry("global", "writing sampled SDF to cache", level=LogLevel.DEBUG)
rr.log_text_entry("global", "writing sampled SDF to cache", level=rr.LogLevel.DEBUG)
with open(sdf_path, "wb+") as f:
np.save(f, sdf)
rr.log_text_entry("global", "writing point cloud to cache", level=LogLevel.DEBUG)
rr.log_text_entry("global", "writing point cloud to cache", level=rr.LogLevel.DEBUG)


def main() -> None:
Expand Down
10 changes: 5 additions & 5 deletions examples/python/mp_pose/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import numpy.typing as npt
import requests
import rerun as rr
from rerun.log.annotation import AnnotationInfo, ClassDescription

EXAMPLE_DIR: Final = Path(os.path.dirname(__file__))
DATASET_DIR: Final = EXAMPLE_DIR / "dataset" / "pose_movement"
Expand All @@ -26,15 +25,16 @@ def track_pose(video_path: str, segment: bool) -> None:

rr.log_annotation_context(
"/",
ClassDescription(
info=AnnotationInfo(label="Person"),
keypoint_annotations=[AnnotationInfo(id=lm.value, label=lm.name) for lm in mp_pose.PoseLandmark],
rr.ClassDescription(
info=rr.AnnotationInfo(label="Person"),
keypoint_annotations=[rr.AnnotationInfo(id=lm.value, label=lm.name) for lm in mp_pose.PoseLandmark],
keypoint_connections=mp_pose.POSE_CONNECTIONS,
),
)
# Use a separate annotation context for the segmentation mask.
rr.log_annotation_context(
"video/mask", [AnnotationInfo(id=0, label="Background"), AnnotationInfo(id=1, label="Person", color=(0, 0, 0))]
"video/mask",
[rr.AnnotationInfo(id=0, label="Background"), rr.AnnotationInfo(id=1, label="Person", color=(0, 0, 0))],
)
rr.log_view_coordinates("person", up="-Y", timeless=True)

Expand Down
3 changes: 1 addition & 2 deletions examples/python/multithreading/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
import numpy as np
import numpy.typing as npt
import rerun as rr
from rerun.log.rects import RectFormat


def rect_logger(path: str, color: npt.NDArray[np.float32]) -> None:
for _ in range(1000):
rects_xy = np.random.rand(5, 2) * 1024
rects_wh = np.random.rand(5, 2) * (1024 - rects_xy + 1)
rects = np.hstack((rects_xy, rects_wh))
rr.log_rects(path, rects, colors=color, rect_format=RectFormat.XYWH)
rr.log_rects(path, rects, colors=color, rect_format=rr.RectFormat.XYWH)


def main() -> None:
Expand Down
3 changes: 1 addition & 2 deletions examples/python/objectron/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
ObjectType,
Sequence,
)
from rerun.log.file import ImageFormat
from scipy.spatial.transform import Rotation as R


Expand Down Expand Up @@ -125,7 +124,7 @@ def log_ar_frames(samples: Iterable[SampleARFrame], seq: Sequence) -> None:
rr.set_time_seconds("time", sample.timestamp)
frame_times.append(sample.timestamp)

rr.log_image_file("world/camera/video", img_path=sample.image_path, img_format=ImageFormat.JPEG)
rr.log_image_file("world/camera/video", img_path=sample.image_path, img_format=rr.ImageFormat.JPEG)
log_camera(sample.frame.camera)
log_point_cloud(sample.frame.raw_feature_points)

Expand Down
15 changes: 10 additions & 5 deletions rerun_py/rerun_sdk/rerun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,30 @@
import rerun_bindings as bindings # type: ignore[attr-defined]

from rerun.log import log_cleared
from rerun.log.annotation import log_annotation_context
from rerun.log.annotation import AnnotationInfo, ClassDescription, log_annotation_context
from rerun.log.arrow import log_arrow
from rerun.log.bounding_box import log_obb
from rerun.log.camera import log_pinhole
from rerun.log.extension_components import log_extension_components
from rerun.log.file import log_image_file, log_mesh_file
from rerun.log.file import ImageFormat, MeshFormat, log_image_file, log_mesh_file
from rerun.log.image import log_depth_image, log_image, log_segmentation_image
from rerun.log.lines import log_line_segments, log_line_strip, log_path
from rerun.log.mesh import log_mesh, log_meshes
from rerun.log.points import log_point, log_points
from rerun.log.rects import log_rect, log_rects
from rerun.log.rects import RectFormat, log_rect, log_rects
from rerun.log.scalar import log_scalar
from rerun.log.tensor import log_tensor
from rerun.log.text import log_text_entry
from rerun.log.text import LoggingHandler, LogLevel, log_text_entry
from rerun.log.transform import log_rigid3, log_unknown_transform, log_view_coordinates
from rerun.script_helpers import script_add_args, script_setup, script_teardown

__all__ = [
"AnnotationInfo",
"ClassDescription",
"LoggingHandler",
"bindings",
"components",
"ImageFormat",
"log_annotation_context",
"log_arrow",
"log_cleared",
Expand All @@ -53,7 +56,9 @@
"log_text_entry",
"log_unknown_transform",
"log_view_coordinates",
"LoggingHandler",
emilk marked this conversation as resolved.
Show resolved Hide resolved
"LogLevel",
"MeshFormat",
"RectFormat",
"script_add_args",
"script_setup",
"script_teardown",
Expand Down