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

doc: Update annotation-context.rs to use correct API #8708

Merged
merged 4 commits into from
Jan 17, 2025

Conversation

OlivierLDff
Copy link
Contributor

@OlivierLDff OlivierLDff commented Jan 16, 2025

The documentation is outdated, I adapted as I could, since I'm discovering the library.

I didn't take the time to investigate how to run the snippets locally, and hope for the CI to catch my ass.

I tried the code in my main:

    // Annotation context with two classes, using two labeled classes, of which ones defines a
    // color.
    use rerun::{
        AnnotationInfo, ClassDescription, Rgba32,
        components::AnnotationContext,
        datatypes::{ClassDescriptionMapElem, ClassId, KeypointId, Utf8},
    };

// Annotation context with two classes, using two labeled classes, of which ones defines a
// color.
rr.log_static(
    "masks", // Applies to all entities below "masks".
    &AnnotationContext(
        [
            ClassDescription {
                info: AnnotationInfo {
                    id: 0,
                    label: Some(Utf8("Background".into())),
                    color: None,
                },
                ..Default::default()
            },
            ClassDescription {
                info: AnnotationInfo {
                    id: 0,
                    label: Some(Utf8("Person".into())),
                    color: Some(Rgba32(0xFF000000)),
                },
                ..Default::default()
            },
        ]
        .into_iter()
        .map(|class| ClassDescriptionMapElem {
            class_id: ClassId(class.info.id),
            class_description: class,
        })
        .collect(),
    ),
)
.unwrap();

// Annotation context with simple keypoints & keypoint connections.
rr.log_static(
    "detections", // Applies to all entities below "detections".
    &AnnotationContext(
        [ClassDescription {
            info: AnnotationInfo {
                id: 0,
                label: Some(Utf8("Snake".into())),
                color: None,
            },
            keypoint_annotations: (0..10)
                .map(|i| AnnotationInfo {
                    id: i,
                    label: None,
                    color: Some(Rgba32::from_rgb(0, (255 / 9 * i) as u8, 0)),
                })
                .collect(),
            keypoint_connections: (0..9)
                .map(|i| (KeypointId(i), KeypointId(i + 1)))
                .map(Into::into)
                .collect(),
        }]
        .into_iter()
        .map(|class| ClassDescriptionMapElem {
            class_id: ClassId(class.info.id),
            class_description: class,
        })
        .collect(),
    ),
)
.unwrap();

CleanShot 2025-01-16 at 12  39 04@2x

CleanShot 2025-01-16 at 12  38 49@2x

@abey79 abey79 added 📖 documentation Improvements or additions to documentation 🦀 Rust API Rust logging API include in changelog and removed 🦀 Rust API Rust logging API labels Jan 17, 2025
@abey79 abey79 self-requested a review January 17, 2025 08:09
Copy link
Member

@abey79 abey79 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out this wart in our documentation. I'm further cleaning that example and make sure it's actually runs in CI.

Copy link
Member

@abey79 abey79 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for this. This snippet is now ported to C++ and fully round-tripped by CI.

@abey79 abey79 merged commit fb14c33 into rerun-io:main Jan 17, 2025
5 checks passed
@abey79 abey79 mentioned this pull request Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📖 documentation Improvements or additions to documentation include in changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants