From 25b7b2a1d143adf68152f7d20829287d902e3f12 Mon Sep 17 00:00:00 2001 From: Clement Rey Date: Tue, 4 Jul 2023 15:52:19 +0200 Subject: [PATCH] add roundtrip test for points2d archetype (py) --- .gitignore | 1 + justfile | 2 +- tests/python/roundtrips/points2d/main.py | 54 ++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100755 tests/python/roundtrips/points2d/main.py diff --git a/.gitignore b/.gitignore index 9aa1f538de1a..69b54b688e42 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ screenshot*.png web_demo .nox/ +out.rrd diff --git a/justfile b/justfile index b52c3f489958..e025fd00d667 100644 --- a/justfile +++ b/justfile @@ -18,7 +18,7 @@ lint: toml-lint py-lint rs-lint ### Python -py_folders := "examples rerun_py scripts docs/code-examples" +py_folders := "docs/code-examples examples rerun_py scripts tests" # Set up a Pythonvirtual environment for development py-dev-env: diff --git a/tests/python/roundtrips/points2d/main.py b/tests/python/roundtrips/points2d/main.py new file mode 100755 index 000000000000..2cfe10df13f6 --- /dev/null +++ b/tests/python/roundtrips/points2d/main.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 + +from __future__ import annotations + +import argparse +import itertools + +import numpy as np +import rerun as rr +from rerun._rerun2 import components as rrc + + +def main() -> None: + points = np.array([1, 2, 3, 4], dtype=np.float32) + radii = np.array([0.42, 0.43], dtype=np.float32) + colors = np.array( + [ + 0xAA0000CC, + 0x00BB00DD, + ], + dtype=np.uint32, + ) + labels = ["hello", "friend"] + draw_order = 300 + class_ids = np.array([126, 127], dtype=np.uint64) + keypoint_ids = np.array([2, 3], dtype=np.uint64) + instance_keys = np.array([66, 666], dtype=np.uint64) + + points2d = rr.Points2D( + points, # type: ignore[arg-type] + radii=radii, # type: ignore[arg-type] + colors=colors, # type: ignore[arg-type] + labels=labels, # type: ignore[arg-type] + draw_order=draw_order, # type: ignore[arg-type] + class_ids=class_ids, # type: ignore[arg-type] + keypoint_ids=keypoint_ids, # type: ignore[arg-type] + instance_keys=instance_keys, # type: ignore[arg-type] + ) + + parser = argparse.ArgumentParser(description="Logs rich data using the Rerun SDK.") + rr.script_add_args(parser) + args = parser.parse_args() + + rr.script_setup(args, "roundtrip_points2d") + + rr.log_any("points2d", points2d) + # Hack to establish 2d view bounds + rr.log_rect("rect", [0, 0, 4, 6]) + + rr.script_teardown(args) + + +if __name__ == "__main__": + main()