diff --git a/examples/README.md b/examples/README.md index aa307e3a8139..c9652bae8860 100644 --- a/examples/README.md +++ b/examples/README.md @@ -2,3 +2,7 @@ * [Python](python) * [Rust](rust) + +> Note: Make sure your SDK version matches the code in the examples. +For example, if your SDK version is `0.3.1`, check out the matching tag +for this repository by running `git checkout v0.3.1`. diff --git a/examples/python/README.md b/examples/python/README.md index c23fe221b79d..917985daeff7 100644 --- a/examples/python/README.md +++ b/examples/python/README.md @@ -6,6 +6,10 @@ Read more about our examples at Note: Make sure your SDK version matches the code in the examples. +For example, if your SDK version is `0.3.1`, check out the matching tag +for this repository by running `git checkout v0.3.1`. + ## Dependencies Each example comes with its own set of dependencies listed in a `requirements.txt` file. For example, to install dependencies and run the toy `car` example (which doesn't need to download any data) run: diff --git a/examples/python/api_demo/main.py b/examples/python/api_demo/main.py index d7f06aa362ac..ed950cbb8d25 100755 --- a/examples/python/api_demo/main.py +++ b/examples/python/api_demo/main.py @@ -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 @@ -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") @@ -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) @@ -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`") diff --git a/examples/python/deep_sdf/main.py b/examples/python/deep_sdf/main.py index b9ce2974f356..7bc91a827242 100755 --- a/examples/python/deep_sdf/main.py +++ b/examples/python/deep_sdf/main.py @@ -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" @@ -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}") @@ -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. @@ -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 ) @@ -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) @@ -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" @@ -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: diff --git a/examples/python/mp_pose/main.py b/examples/python/mp_pose/main.py index cd0dd96d02bb..c2d91117c631 100755 --- a/examples/python/mp_pose/main.py +++ b/examples/python/mp_pose/main.py @@ -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" @@ -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) diff --git a/examples/python/multithreading/main.py b/examples/python/multithreading/main.py index 2bc708bbddd0..eeb6f2ed9f49 100755 --- a/examples/python/multithreading/main.py +++ b/examples/python/multithreading/main.py @@ -9,7 +9,6 @@ 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: @@ -17,7 +16,7 @@ def rect_logger(path: str, color: npt.NDArray[np.float32]) -> None: 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: diff --git a/examples/python/objectron/main.py b/examples/python/objectron/main.py index 5e64abfb1391..d7dc5237ddd5 100755 --- a/examples/python/objectron/main.py +++ b/examples/python/objectron/main.py @@ -36,7 +36,6 @@ ObjectType, Sequence, ) -from rerun.log.file import ImageFormat from scipy.spatial.transform import Rotation as R @@ -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) diff --git a/rerun_py/rerun_sdk/rerun/__init__.py b/rerun_py/rerun_sdk/rerun/__init__.py index 93fbcec5c707..00b40749ff25 100644 --- a/rerun_py/rerun_sdk/rerun/__init__.py +++ b/rerun_py/rerun_sdk/rerun/__init__.py @@ -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", @@ -53,7 +56,9 @@ "log_text_entry", "log_unknown_transform", "log_view_coordinates", - "LoggingHandler", + "LogLevel", + "MeshFormat", + "RectFormat", "script_add_args", "script_setup", "script_teardown",