Skip to content

Commit

Permalink
doc: Update annotation-context.rs to use correct API (#8708)
Browse files Browse the repository at this point in the history
Co-authored-by: Antoine Beyeler <[email protected]>
Co-authored-by: Clement Rey <[email protected]>
  • Loading branch information
3 people authored Jan 17, 2025
1 parent cae7a6a commit fb14c33
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 63 deletions.
2 changes: 1 addition & 1 deletion docs/content/concepts/annotation-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Annotation contexts are logged with:
* Python: 🐍[`rr.AnnotationContext`](https://ref.rerun.io/docs/python/stable/common/archetypes/#rerun.archetypes.AnnotationContext)
* Rust: 🦀[`rerun::AnnotationContext`](https://docs.rs/rerun/latest/rerun/archetypes/struct.AnnotationContext.html#)

snippet: tutorials/annotation-context
snippet: tutorials/annotation_context


## Affected entities
Expand Down
56 changes: 0 additions & 56 deletions docs/snippets/all/tutorials/annotation-context.rs

This file was deleted.

38 changes: 38 additions & 0 deletions docs/snippets/all/tutorials/annotation_context.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <rerun.hpp>

int main() {
const auto rec = rerun::RecordingStream("rerun_example_annotation_context_connections");
rec.spawn().exit_on_failure();

// Annotation context with two classes, using two labeled classes, of which ones defines a
// color.
rec.log_static(
"masks",
rerun::AnnotationContext({
rerun::AnnotationInfo(0, "Background"),
rerun::AnnotationInfo(1, "Person", rerun::Rgba32(255, 0, 0)),
})
);

// Annotation context with simple keypoints & keypoint connections.
std::vector<rerun::AnnotationInfo> keypoint_annotations;
for (uint16_t i = 0; i < 10; ++i) {
keypoint_annotations.push_back(
rerun::AnnotationInfo(i, rerun::Rgba32(0, static_cast<uint8_t>(28 * i), 0))
);
}

std::vector<rerun::KeypointPair> keypoint_connections;
for (uint16_t i = 0; i < 9; ++i) {
keypoint_connections.push_back(rerun::KeypointPair(i, i + 1));
}

rec.log_static(
"detections", // Applies to all entities below "detections".
rerun::AnnotationContext({rerun::ClassDescription(
rerun::AnnotationInfo(0, "Snake"),
keypoint_annotations,
keypoint_connections
)})
);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import rerun as rr

rr.init("rerun_example_annotation_context_connections")

# Annotation context with two classes, using two labeled classes, of which ones defines a color.
rr.log(
"masks", # Applies to all entities below "masks".
Expand All @@ -17,7 +19,7 @@
"detections", # Applies to all entities below "detections".
rr.ClassDescription(
info=rr.AnnotationInfo(0, label="Snake"),
keypoint_annotations=[rr.AnnotationInfo(id=i, color=(0, 255 / 9 * i, 0)) for i in range(10)],
keypoint_annotations=[rr.AnnotationInfo(id=i, color=(0, 28 * i, 0)) for i in range(10)],
keypoint_connections=[(i, i + 1) for i in range(9)],
),
static=True,
Expand Down
40 changes: 40 additions & 0 deletions docs/snippets/all/tutorials/annotation_context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use rerun::{
datatypes::{ClassDescriptionMapElem, KeypointId},
AnnotationContext, AnnotationInfo, ClassDescription, Rgba32,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let rec = rerun::RecordingStreamBuilder::new("rerun_example_annotation_context_connections")
.spawn()?;

// Annotation context with two classes, using two labeled classes, of which ones defines a
// color.
rec.log_static(
"masks", // Applies to all entities below "masks".
&AnnotationContext::new([
ClassDescriptionMapElem::from((0, "Background")),
ClassDescriptionMapElem::from((1, "Person", Rgba32::from_rgb(255, 0, 0))),
]),
)?;

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

Ok(())
}
5 changes: 0 additions & 5 deletions docs/snippets/snippets.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@
"rust",
"py",
]
"tutorials/annotation-context" = [ # Not a complete example
"cpp",
"rust",
"py",
]
"tutorials/any_values" = [ # Not yet implemented
"cpp",
]
Expand Down

0 comments on commit fb14c33

Please sign in to comment.