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

C++ annotation context #2948

Merged
merged 10 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@
"--config",
"rerun_py/pyproject.toml"
],
"cmake.buildDirectory": "${workspaceRoot}/build/",
"C_Cpp.autoAddFileAssociations": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ namespace rerun.archetypes;
/// \rs ```ignore
/// \rs \include:../../../../../docs/code-examples/annotation_context_rects.rs
/// \rs ```
///
/// \cpp ## Example
/// \cpp
/// \cpp ```
// \cpp TODO(#2786): implement Rect2D cpp example and link it here instead.
/// \cpp \include:../../../../../docs/code-examples/annotation_context_arrows_v2.cpp
/// \cpp ```
Wumpf marked this conversation as resolved.
Show resolved Hide resolved
table AnnotationContext (
"attr.rust.derive": "Eq, PartialEq",
order: 100
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.

10 changes: 6 additions & 4 deletions crates/re_types_builder/src/codegen/cpp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,9 +1304,9 @@ fn quote_append_field_to_builder(
quote! {
auto #value_builder = static_cast<arrow::#value_builder_type*>(#builder->value_builder());
#NEWLINE_TOKEN #NEWLINE_TOKEN
ARROW_RETURN_NOT_OK(#builder->AppendValues(num_elements));
static_assert(sizeof(elements[0].#field_name) == sizeof(elements[0]));
ARROW_RETURN_NOT_OK(#value_builder->AppendValues(#field_ptr_accessor, num_elements * #num_items_per_value, nullptr));
ARROW_RETURN_NOT_OK(#builder->AppendValues(num_elements));
}
} else {
let value_reserve_factor = match &field.typ {
Expand Down Expand Up @@ -1348,8 +1348,8 @@ fn quote_append_field_to_builder(
for (auto elem_idx = 0; elem_idx < num_elements; elem_idx += 1) {
const auto& element = elements[elem_idx];
if (element.#field_name.has_value()) {
#append_value
ARROW_RETURN_NOT_OK(#builder->Append());
#append_value
} else {
ARROW_RETURN_NOT_OK(#builder->AppendNull());
}
Expand All @@ -1360,8 +1360,8 @@ fn quote_append_field_to_builder(
#setup
for (auto elem_idx = 0; elem_idx < num_elements; elem_idx += 1) {
const auto& element = elements[elem_idx];
#append_value
ARROW_RETURN_NOT_OK(#builder->Append());
#append_value
}
}
}
Expand Down Expand Up @@ -1477,7 +1477,9 @@ fn quote_append_single_value_to_builder(
let fqname = quote_fqname_as_type_path(includes, fqname);
let field_ptr_accessor = quote_field_ptr_access(typ, value_access);
quote! {
ARROW_RETURN_NOT_OK(#fqname::fill_arrow_array_builder(#value_builder, #field_ptr_accessor, #num_items_per_element));
if (#field_ptr_accessor) {
ARROW_RETURN_NOT_OK(#fqname::fill_arrow_array_builder(#value_builder, #field_ptr_accessor, #num_items_per_element));
}
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions docs/code-examples/annotation_context_arrows_v2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Log an annotation context to assign a label and color to each class

#include <rerun.hpp>

namespace rr = rerun;

int main() {
auto rr_stream = rr::RecordingStream("annotation_context_rects");
rr_stream.connect("127.0.0.1:9876");

// Log an annotation context to assign a label and color to each class
rr_stream.log(
"/",
rr::archetypes::AnnotationContext({
rr::datatypes::AnnotationInfo(1, "red", rr::components::Color(255, 0, 0)),
rr::datatypes::AnnotationInfo(2, "green", rr::components::Color(0, 255, 0)),
})
);

// Log a batch of 2 arrows with different `class_ids`
rr_stream.log(
"arrows",
rr::archetypes::Arrows3D({{1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}}).with_class_ids({1, 2})
);
}
31 changes: 31 additions & 0 deletions rerun_cpp/src/rerun/archetypes/annotation_context.hpp

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

2 changes: 1 addition & 1 deletion rerun_cpp/src/rerun/components/affix_fuzzer11.cpp

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

2 changes: 1 addition & 1 deletion rerun_cpp/src/rerun/components/affix_fuzzer12.cpp

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

2 changes: 1 addition & 1 deletion rerun_cpp/src/rerun/components/affix_fuzzer13.cpp

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

12 changes: 7 additions & 5 deletions rerun_cpp/src/rerun/components/affix_fuzzer16.cpp

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

14 changes: 9 additions & 5 deletions rerun_cpp/src/rerun/components/affix_fuzzer17.cpp

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

14 changes: 9 additions & 5 deletions rerun_cpp/src/rerun/components/affix_fuzzer18.cpp

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

14 changes: 9 additions & 5 deletions rerun_cpp/src/rerun/components/affix_fuzzer7.cpp

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

16 changes: 9 additions & 7 deletions rerun_cpp/src/rerun/components/annotation_context.cpp

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

12 changes: 12 additions & 0 deletions rerun_cpp/src/rerun/components/annotation_context.hpp

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

31 changes: 31 additions & 0 deletions rerun_cpp/src/rerun/components/annotation_context_ext.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <utility>
#include "annotation_context.hpp"

// Uncomment for better auto-complete while editing the extension.
// #define EDIT_EXTENSION

namespace rerun {
namespace components {
#ifdef EDIT_EXTENSION
struct AnnotationContextExt {
std::vector<rerun::datatypes::ClassDescriptionMapElem> class_map;

#define AnnotationContext AnnotationContextExt

// [CODEGEN COPY TO HEADER START]

AnnotationContext(
std::initializer_list<rerun::datatypes::ClassDescription> class_descriptions
) {
class_map.reserve(class_descriptions.size());
for (const auto& class_description : class_descriptions) {
class_map.emplace_back(std::move(class_description));
}
}

// [CODEGEN COPY TO HEADER END]
};
#endif

} // namespace components
} // namespace rerun
12 changes: 7 additions & 5 deletions rerun_cpp/src/rerun/components/line_strip2d.cpp

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

12 changes: 7 additions & 5 deletions rerun_cpp/src/rerun/components/line_strip3d.cpp

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

Loading