Skip to content

Commit ee2e721

Browse files
committed
Add logging of Eigen matrix
1 parent 41bbdbe commit ee2e721

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ build/
33

44
# LSP files
55
compile_commands.json
6+
.cache
67

78
# Prerequisites
89
*.d

src/main.cpp

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,46 @@ struct rerun::ComponentBatchAdapter<rerun::components::Position3D, std::vector<E
2525
}
2626
};
2727

28+
template <>
29+
struct rerun::ComponentBatchAdapter<rerun::components::Position3D, Eigen::MatrixX3f> {
30+
// Sanity check that this is binary compatible.
31+
/* static_assert(sizeof(components::Position3D) == sizeof(Eigen::Vector3f)); ?? */
32+
/* static_assert(alignof(components::Position3D) <= alignof(Eigen::Vector3f)); */
33+
34+
ComponentBatch<components::Position3D> operator()(const Eigen::MatrixX3f &matrix
35+
) {
36+
return ComponentBatch<components::Position3D>::borrow(
37+
reinterpret_cast<const components::Position3D *>(matrix.data()),
38+
matrix.rows()
39+
);
40+
}
41+
42+
ComponentBatch<components::Position3D> operator()(std::vector<Eigen::MatrixX3f> &&container) {
43+
throw std::runtime_error("Not implemented for temporaries");
44+
}
45+
};
46+
47+
std::vector<Eigen::Vector3f> generate_random_points_vector(int num_points) {
48+
std::vector<Eigen::Vector3f> points(num_points);
49+
for(auto& point : points) {
50+
point.setRandom();
51+
}
52+
return points;
53+
}
54+
2855
int main() {
29-
auto rec = rerun::RecordingStream("rerun_external_cpp_app");
56+
auto rec = rerun::RecordingStream("rerun_cpp_example_opencv_eigen");
3057
rec.connect("127.0.0.1:9876").throw_on_failure();
3158

59+
const int num_points = 1000;
60+
3261
// 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));
62+
auto points3d_vector = generate_random_points_vector(1000);
63+
rec.log("points_from_vector", rerun::Points3D(points3d_vector));
3564

36-
// Points represented by Nx3 Eigen::Mat...
65+
// Points represented by Eigen::MatX3f (Nx3 matrix)
66+
Eigen::MatrixX3f points3d_matrix = Eigen::MatrixX3f::Random(num_points, 3);
67+
rec.log("points_from_matrix", rerun::Points3D(points3d_matrix));
3768

3869
// Image
3970
std::string image_path = "rerun-logo.png";

0 commit comments

Comments
 (0)