Skip to content

Commit

Permalink
Add default value for info argument of ClassDescription (#3017)
Browse files Browse the repository at this point in the history
* Closes #2924

Two changes:
* You can now easily specify the `info` without having to also specify
label and color, using `info=0`.
* The default info is one with `id=0`, matching 0.7.0 behavior and how
`log_points` work


(This took me over an hour to figure out 😭)

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3017) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/3017)
- [Docs
preview](https://rerun.io/preview/pr%3Aemilk%2Ffix-annotation-context-default/docs)
- [Examples
preview](https://rerun.io/preview/pr%3Aemilk%2Ffix-annotation-context-default/examples)
  • Loading branch information
emilk authored Aug 17, 2023
1 parent d023720 commit e78fc1c
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace rerun.datatypes;
/// Color and label will be used to annotate entities/keypoints which reference the id.
/// The id refers either to a class or key-point id
table AnnotationInfo (
"attr.python.aliases": "Tuple[int, str], Tuple[int, str, datatypes.ColorLike]",
"attr.python.aliases": "int, Tuple[int, str], Tuple[int, str, datatypes.ColorLike]",
"attr.rust.derive": "Default, Eq, PartialEq",
order: 500
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace rerun.datatypes;
/// defined, and both keypoints exist within the instance of the class, then the
/// keypoints should be connected with an edge. The edge should be labeled and
/// colored as described by the class's `AnnotationInfo`.
///
/// The default `info` is an `id=0` with no label or color.
table ClassDescription (
"attr.python.aliases": "datatypes.AnnotationInfoLike",
"attr.rust.derive": "Default, Eq, PartialEq",
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/source_hash.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/re_types/src/datatypes/class_description.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rerun_cpp/src/rerun/datatypes/class_description.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@

def classdescription_init(
self: ClassDescription,
info: AnnotationInfoLike,
info: AnnotationInfoLike = 0,
*,
keypoint_annotations: Sequence[AnnotationInfoLike] = [],
keypoint_connections: Sequence[KeypointPairLike] = [],
) -> None:
Expand Down Expand Up @@ -89,6 +90,8 @@ def classdescription_info_converter(

if isinstance(data, AnnotationInfo):
return data
elif isinstance(data, int):
return AnnotationInfo(id=data)
else:
return AnnotationInfo(*data)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/python/roundtrips/annotation_context/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def main() -> None:
[
(1, "hello"),
rrd.ClassDescription(
(2, "world", [3, 4, 5]),
info=(2, "world", [3, 4, 5]),
keypoint_annotations=[(17, "head"), (42, "shoulders")],
keypoint_connections=[(1, 2), (3, 4)],
),
Expand Down

0 comments on commit e78fc1c

Please sign in to comment.