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

Port DNA (getting started) example to C++ #3963

Merged
merged 8 commits into from
Oct 24, 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: 1 addition & 1 deletion crates/re_sdk/src/demo_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ pub fn color_spiral(
.map(move |i| {
let angle = i as f32 * angular_step * TAU + angular_offset;
glam::Vec3::new(
angle.sin() * radius,
angle.cos() * radius,
angle.sin() * radius,
i as f32 * z_step,
)
})
Expand Down
25 changes: 25 additions & 0 deletions crates/re_types_builder/src/codegen/cpp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,31 @@ impl QuotedObject {
));
};

// If we're a component with a single datatype field, add an implicit casting operator for convenience.
if obj.kind == ObjectKind::Component
&& obj.fields.len() == 1
&& matches!(obj.fields[0].typ, Type::Object { .. })
{
if let Type::Object(datatype_fqname) = &obj.fields[0].typ {
let data_type = quote_field_type(&mut hpp_includes, &obj.fields[0]);
let type_name = datatype_fqname.split('.').last().unwrap();
let field_name = format_ident!("{}", obj.fields[0].name);

methods.push(Method {
docs: format!("Cast to the underlying {type_name} datatype").into(),
declaration: MethodDeclaration {
name_and_parameters: quote! { operator #data_type() const },
is_static: false,
return_type: quote! {},
},
definition_body: quote! {
return #field_name;
},
inline: true,
});
}
}

// Arrow serialization methods.
// TODO(andreas): These are just utilities for to_data_cell. How do we hide them best from the public header?
methods.push(arrow_data_type_method(
Expand Down
2 changes: 2 additions & 0 deletions examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
add_subdirectory(clock)
add_subdirectory(minimal)
add_subdirectory(dna)

add_custom_target(examples)
add_dependencies(examples example_minimal)
add_dependencies(examples example_clock)
add_dependencies(examples example_dna)
2 changes: 2 additions & 0 deletions examples/cpp/clock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: Clock
python: https://github.com/rerun-io/rerun/tree/latest/examples/python/clock/main.py
rust: https://github.com/rerun-io/rerun/tree/latest/examples/rust/clock/src/main.rs
# TODO(#3962): Update Link
cpp: https://github.com/rerun-io/rerun/tree/main/examples/cpp/clock/main.cpp
thumbnail: https://static.rerun.io/clock/ae4b8970edba8480431cb71e57b8cddd9e1769c7/480w.png
---

Expand Down
27 changes: 27 additions & 0 deletions examples/cpp/dna/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.16)

# If you use the example outside of the Rerun SDK you need to specify
# where the rerun_c build is to be found by setting the `RERUN_CPP_URL` variable.
# This can be done by passing `-DRERUN_CPP_URL=<path to rerun_sdk_cpp zip>` to cmake.
if(DEFINED RERUN_REPOSITORY)
add_executable(example_dna main.cpp)
set_default_warning_settings(example_dna)
else()
project(example_dna LANGUAGES CXX)

add_executable(example_dna main.cpp)

# Set the path to the rerun_c build.
set(RERUN_CPP_URL CACHE STRING "URL to the rerun_cpp zip.")

# Download the rerun_sdk
include(FetchContent)
FetchContent_Declare(rerun_sdk DOWNLOAD_EXTRACT_TIMESTAMP YES URL ${RERUN_CPP_URL})
FetchContent_MakeAvailable(rerun_sdk)

# Rerun requires at least C++17, but you can use an evern newer version.
set_property(TARGET example_dna PROPERTY CXX_STANDARD 17)
endif()

# Link against rerun_sdk.
target_link_libraries(example_dna PRIVATE rerun_sdk)
30 changes: 30 additions & 0 deletions examples/cpp/dna/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: Helix
Copy link
Member

Choose a reason for hiding this comment

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

not new in this PR, but it's a bit confusing that the example is called both dna and Helix

Copy link
Member Author

Choose a reason for hiding this comment

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

helix is the better name imho. DNA sounds like we're doing actual medical visualization

python: https://github.com/rerun-io/rerun/tree/latest/examples/python/dna/main.py
rust: https://github.com/rerun-io/rerun/tree/latest/examples/rust/dna/src/main.rs
# TODO(#3962): Update Link
cpp: https://github.com/rerun-io/rerun/tree/main/examples/cpp/dna/main.cpp
tags: [3d, api-example]
description: "Simple example of logging point and line primitives to draw a 3D helix."
thumbnail: https://static.rerun.io/helix/f4c375546fa9d24f7cd3a1a715ebf75b2978817a/480w.png
thumbnail_dimensions: [480, 285]
demo: true
---

<picture>
<source media="(max-width: 480px)" srcset="https://static.rerun.io/helix/f4c375546fa9d24f7cd3a1a715ebf75b2978817a/480w.png">
<source media="(max-width: 768px)" srcset="https://static.rerun.io/helix/f4c375546fa9d24f7cd3a1a715ebf75b2978817a/768w.png">
<source media="(max-width: 1024px)" srcset="https://static.rerun.io/helix/f4c375546fa9d24f7cd3a1a715ebf75b2978817a/1024w.png">
<source media="(max-width: 1200px)" srcset="https://static.rerun.io/helix/f4c375546fa9d24f7cd3a1a715ebf75b2978817a/1200w.png">
<img src="https://static.rerun.io/helix/f4c375546fa9d24f7cd3a1a715ebf75b2978817a/full.png" alt="">
</picture>

Simple example of logging point and line primitives to draw a 3D helix.


To build it from a checkout of the repository (requires a Rust toolchain):
```bash
cmake .
cmake --build . --target example_dna
./examples/cpp/dna/dna
```
2 changes: 1 addition & 1 deletion examples/cpp/dna/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int main() {

std::vector<rerun::LineStrip3D> lines;
for (size_t i = 0; i < points1.size(); ++i) {
lines.emplace_back(points1[i], points2[i]);
lines.emplace_back(rerun::LineStrip3D({points1[i].xyz, points2[i].xyz}));
}

rec.log(
Expand Down
3 changes: 3 additions & 0 deletions examples/python/dna/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
title: Helix
python: https://github.com/rerun-io/rerun/tree/latest/examples/python/dna/main.py
rust: https://github.com/rerun-io/rerun/tree/latest/examples/rust/dna/src/main.rs
# TODO(#3962): Update Link
cpp: https://github.com/rerun-io/rerun/tree/main/examples/cpp/dna/main.cpp
tags: [3d, api-example]
description: "Simple example of logging point and line primitives to draw a 3D helix."
thumbnail: https://static.rerun.io/helix/f4c375546fa9d24f7cd3a1a715ebf75b2978817a/480w.png
Expand Down
2 changes: 2 additions & 0 deletions examples/rust/clock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: Clock
python: https://github.com/rerun-io/rerun/tree/latest/examples/python/clock/main.py
rust: https://github.com/rerun-io/rerun/tree/latest/examples/rust/clock/src/main.rs
# TODO(#3962): Update Link
cpp: https://github.com/rerun-io/rerun/tree/main/examples/cpp/clock/main.cpp
thumbnail: https://static.rerun.io/clock/ae4b8970edba8480431cb71e57b8cddd9e1769c7/480w.png
---

Expand Down
26 changes: 26 additions & 0 deletions examples/rust/dna/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: Helix
python: https://github.com/rerun-io/rerun/tree/latest/examples/python/dna/main.py
rust: https://github.com/rerun-io/rerun/tree/latest/examples/rust/dna/src/main.rs
# TODO(#3962): Update Link
cpp: https://github.com/rerun-io/rerun/tree/main/examples/cpp/dna/main.cpp
tags: [3d, api-example]
description: "Simple example of logging point and line primitives to draw a 3D helix."
thumbnail: https://static.rerun.io/helix/f4c375546fa9d24f7cd3a1a715ebf75b2978817a/480w.png
thumbnail_dimensions: [480, 285]
demo: true
---

<picture>
<source media="(max-width: 480px)" srcset="https://static.rerun.io/helix/f4c375546fa9d24f7cd3a1a715ebf75b2978817a/480w.png">
<source media="(max-width: 768px)" srcset="https://static.rerun.io/helix/f4c375546fa9d24f7cd3a1a715ebf75b2978817a/768w.png">
<source media="(max-width: 1024px)" srcset="https://static.rerun.io/helix/f4c375546fa9d24f7cd3a1a715ebf75b2978817a/1024w.png">
<source media="(max-width: 1200px)" srcset="https://static.rerun.io/helix/f4c375546fa9d24f7cd3a1a715ebf75b2978817a/1200w.png">
<img src="https://static.rerun.io/helix/f4c375546fa9d24f7cd3a1a715ebf75b2978817a/full.png" alt="">
</picture>

Simple example of logging point and line primitives to draw a 3D helix.

```bash
cargo run --release
```
5 changes: 5 additions & 0 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ py-test = { cmd = "python -m pytest -vv rerun_py/tests/unit", depends_on = [
"py-build",
] }

cpp-build-all = { depends_on = [
"cpp-build-tests",
"cpp-build-examples",
"cpp-build-doc-examples",
] }
cpp-prepare = "cmake -G Ninja -B build -S . -DCMAKE_BUILD_TYPE=Debug"
cpp-build-tests = { cmd = "cmake --build build --config Debug --target rerun_sdk_tests", depends_on = [
"cpp-prepare",
Expand Down
1 change: 1 addition & 0 deletions rerun_cpp/src/rerun.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace rerun {
using components::HalfSizes2D;
using components::HalfSizes3D;
using components::InstanceKey;
using components::LineStrip3D;
using components::Material;
using components::MediaType;
using components::MeshProperties;
Expand Down
4 changes: 2 additions & 2 deletions rerun_cpp/src/rerun/component_batch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ namespace rerun {
template <typename... Ts>
struct NoAdapterFor : std::false_type {};

// `NoAdapterFor` always evaluates to false, but in a way that requires template instantiation.
static_assert(
NoAdapterFor<TComponent, TInput>::value, // Always evaluate to false, but in a way that
// requires template instantiation.
NoAdapterFor<TComponent, TInput>::value,
"ComponentBatchAdapter is not implemented for this type. "
"It is implemented for for single components as well as std::vector, std::array, and "
"c-arrays of components. "
Expand Down
5 changes: 5 additions & 0 deletions rerun_cpp/src/rerun/components/class_id.hpp

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

5 changes: 5 additions & 0 deletions rerun_cpp/src/rerun/components/color.hpp

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

5 changes: 5 additions & 0 deletions rerun_cpp/src/rerun/components/half_sizes2d.hpp

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

5 changes: 5 additions & 0 deletions rerun_cpp/src/rerun/components/half_sizes3d.hpp

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

5 changes: 5 additions & 0 deletions rerun_cpp/src/rerun/components/keypoint_id.hpp

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

5 changes: 5 additions & 0 deletions rerun_cpp/src/rerun/components/material.hpp

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

5 changes: 5 additions & 0 deletions rerun_cpp/src/rerun/components/media_type.hpp

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

5 changes: 5 additions & 0 deletions rerun_cpp/src/rerun/components/mesh_properties.hpp

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

5 changes: 5 additions & 0 deletions rerun_cpp/src/rerun/components/out_of_tree_transform3d.hpp

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

5 changes: 5 additions & 0 deletions rerun_cpp/src/rerun/components/pinhole_projection.hpp

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

5 changes: 5 additions & 0 deletions rerun_cpp/src/rerun/components/position2d.hpp

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

5 changes: 5 additions & 0 deletions rerun_cpp/src/rerun/components/position3d.hpp

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

5 changes: 5 additions & 0 deletions rerun_cpp/src/rerun/components/resolution.hpp

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

5 changes: 5 additions & 0 deletions rerun_cpp/src/rerun/components/rotation3d.hpp

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

5 changes: 5 additions & 0 deletions rerun_cpp/src/rerun/components/tensor_data.hpp

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

5 changes: 5 additions & 0 deletions rerun_cpp/src/rerun/components/text.hpp

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

Loading