Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Mar 11, 2024
1 parent 7d656ec commit ebd0be9
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 7 deletions.
8 changes: 4 additions & 4 deletions docs/code-examples/all/annotation_context_connections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ int main() {
// Log some points with different keypoint IDs
rec.log(
"points",
rerun::Points3D({{0.0f, 0.0f, 0.0f},
{50.0f, 0.0f, 20.0f},
{100.0f, 100.0f, 30.0f},
{0.0f, 50.0f, 40.0f}})
rerun::Points3D(
{{0.0f, 0.0f, 0.0f}, {50.0f, 0.0f, 20.0f}, {100.0f, 100.0f, 30.0f}, {0.0f, 50.0f, 40.0f}
}
)
.with_keypoint_ids({0, 1, 2, 3})
.with_class_ids({0})
);
Expand Down
2 changes: 2 additions & 0 deletions examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ add_subdirectory(clock)
add_subdirectory(custom_collection_adapter)
add_subdirectory(dna)
add_subdirectory(external_data_loader)
add_subdirectory(incremental)
add_subdirectory(log_file)
add_subdirectory(minimal)
add_subdirectory(shared_recording)
Expand All @@ -13,6 +14,7 @@ add_custom_target(examples)
add_dependencies(examples example_clock)
add_dependencies(examples example_custom_collection_adapter)
add_dependencies(examples example_dna)
add_dependencies(examples example_incremental)
add_dependencies(examples example_log_file)
add_dependencies(examples example_minimal)
add_dependencies(examples example_shared_recording)
Expand Down
27 changes: 27 additions & 0 deletions examples/cpp/incremental/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.16...3.27)

# 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_incremental main.cpp)
rerun_strict_warning_settings(example_incremental)
else()
project(example_incremental LANGUAGES CXX)

add_executable(example_incremental main.cpp)

# Set the path to the rerun_c build.
set(RERUN_CPP_URL "https://github.com/rerun-io/rerun/releases/latest/download/rerun_cpp_sdk.zip" CACHE STRING "URL to the rerun_cpp zip.")

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

# Rerun requires at least C++17, but it should be compatible with newer versions.
set_property(TARGET example_incremental PROPERTY CXX_STANDARD 17)
endif()

# Link against rerun_sdk.
target_link_libraries(example_incremental PRIVATE rerun_sdk)
27 changes: 27 additions & 0 deletions examples/cpp/incremental/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--[metadata]
title = "Helix"
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]
channel = "main"
-->


<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_incremental
./examples/cpp/incremental/example_incremental
```
35 changes: 35 additions & 0 deletions examples/cpp/incremental/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <rerun.hpp>

#include <algorithm>
#include <random>

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

// TODO(#5264): just log one once clamp-to-edge semantics land.
std::vector<rerun::Color> colors(10, rerun::Color(255, 0, 0));
std::vector<rerun::Radius> radii(10, rerun::Radius(0.1));

// Only log colors and radii once.
rec.set_time_sequence("frame_nr", 0);
rec.log("points", colors, radii);
// Logging timelessly with `RecordingStream::log_timeless` would also work.
// rec.log_timeless("points", colors, radii);

std::default_random_engine gen;
std::uniform_real_distribution<float> dist_pos(-5.0f, 5.0f);

// Then log only the points themselves each frame.
//
// They will automatically re-use the colors and radii logged at the beginning.
for (int i = 0; i < 10; ++i) {
rec.set_time_sequence("frame_nr", i);

std::vector<rerun::Position3D> points(10);
std::generate(points.begin(), points.end(), [&] {
return rerun::Position3D(dist_pos(gen), dist_pos(gen), dist_pos(gen));
});
rec.log("points", rerun::Points3D(points));
}
}
3 changes: 2 additions & 1 deletion rerun_cpp/src/rerun/third_party/cxxopts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,8 @@ namespace cxxopts {
value->get_implicit_value(),
std::move(arg_help),
value->is_container(),
value->is_boolean()});
value->is_boolean()
});
}

inline void Options::add_one_option(
Expand Down
6 changes: 4 additions & 2 deletions rerun_cpp/tests/mat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ TEST_CASE("Construct Mat4x4 in different ways", TEST_TAG) {
12.0f,
13.0f,
14.f,
15.0f};
15.0f
};
Mat4x4 m4x4(carray);
ctor_checks(m4x4);
}
Expand All @@ -104,7 +105,8 @@ TEST_CASE("Construct Mat4x4 in different ways", TEST_TAG) {
12.0f,
13.0f,
14.f,
15.0f};
15.0f
};
Mat4x4 m4x4(elements.data());
ctor_checks(m4x4);
}
Expand Down

0 comments on commit ebd0be9

Please sign in to comment.