Skip to content

Commit 41bbdbe

Browse files
committed
Add minimal cmake project that logs std::vector<Eigen::Vector3f> to Rerun
1 parent 628dd6d commit 41bbdbe

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Build directory
2+
build/
3+
4+
# LSP files
5+
compile_commands.json
6+
17
# Prerequisites
28
*.d
39

CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(rerun_external_cpp_proj LANGUAGES CXX)
4+
5+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
6+
7+
if(NOT DEFINED CMAKE_CXX_STANDARD)
8+
set(CMAKE_CXX_STANDARD 17)
9+
endif()
10+
11+
find_package(Eigen3 REQUIRED)
12+
find_package(OpenCV REQUIRED)
13+
find_package(Arrow REQUIRED)
14+
# find_package(rerun_sdk REQUIRED) # this would be nice (i.e., installable rerun_sdk)
15+
16+
# assume rerun_sdk has been build beforehand
17+
add_library(rerun_sdk INTERFACE)
18+
target_include_directories(rerun_sdk INTERFACE /home/leo/code/rerun/rerun_cpp/src/)
19+
target_link_libraries(rerun_sdk INTERFACE /home/leo/code/rerun/build/rerun_cpp/librerun_sdk.a)
20+
target_link_libraries(rerun_sdk INTERFACE /home/leo/code/rerun/target/release/librerun_c.a)
21+
if(ARROW_LINK_SHARED)
22+
target_link_libraries(rerun_sdk INTERFACE Arrow::arrow_shared)
23+
else()
24+
target_link_libraries(rerun_sdk INTERFACE Arrow::arrow_static)
25+
endif()
26+
27+
28+
add_executable(rerun_ext_example src/main.cpp)
29+
30+
target_link_libraries(rerun_ext_example Eigen3::Eigen ${OpenCV_LIBS} rerun_sdk)

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# C++ Example with OpenCV and Eigen
2+
3+
This is a minimal CMake project that shows how to use [Rerun](https://github.com/rerun-io/rerun) in your code in conjunction with [Eigen](https://eigen.tuxfamily.org/) and [OpenCV](https://opencv.org/).
4+
5+
## Depedencies
6+
7+
TODO
8+
9+
## How to build and run
10+
11+
```bash
12+
mkdir build
13+
cd build
14+
cmake ..
15+
cmake --build .
16+
```

rerun-logo.png

8.25 KB
Loading

src/main.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <eigen3/Eigen/Core>
2+
#include <eigen3/Eigen/Dense>
3+
#include <iostream>
4+
#include <opencv2/core.hpp>
5+
#include <opencv2/highgui.hpp>
6+
#include <opencv2/imgcodecs.hpp>
7+
#include <rerun.hpp>
8+
9+
template <>
10+
struct rerun::ComponentBatchAdapter<rerun::components::Position3D, std::vector<Eigen::Vector3f>> {
11+
// Sanity check that this is binary compatible.
12+
static_assert(sizeof(components::Position3D) == sizeof(Eigen::Vector3f));
13+
static_assert(alignof(components::Position3D) <= alignof(Eigen::Vector3f));
14+
15+
ComponentBatch<components::Position3D> operator()(const std::vector<Eigen::Vector3f> &container
16+
) {
17+
return ComponentBatch<components::Position3D>::borrow(
18+
reinterpret_cast<const components::Position3D *>(container.data()),
19+
container.size()
20+
);
21+
}
22+
23+
ComponentBatch<components::Position3D> operator()(std::vector<Eigen::Vector3f> &&container) {
24+
throw std::runtime_error("Not implemented for temporaries");
25+
}
26+
};
27+
28+
int main() {
29+
auto rec = rerun::RecordingStream("rerun_external_cpp_app");
30+
rec.connect("127.0.0.1:9876").throw_on_failure();
31+
32+
// Points represented by std::vector<Eigen::Vector3f>
33+
std::vector<Eigen::Vector3f> points3d_eigen{{0.1f, 0.1f, 0.1f}};
34+
rec.log("random", rerun::Points3D(points3d_eigen));
35+
36+
// Points represented by Nx3 Eigen::Mat...
37+
38+
// Image
39+
std::string image_path = "rerun-logo.png";
40+
cv::Mat img = imread(image_path, cv::IMREAD_COLOR);
41+
if (img.empty()) {
42+
std::cout << "Could not read the image: " << image_path << std::endl;
43+
return 1;
44+
}
45+
imshow("Display window", img);
46+
cv::waitKey(0);
47+
48+
return 0;
49+
}

0 commit comments

Comments
 (0)