Skip to content

Commit 828ee6c

Browse files
committed
Add asserts for MatrixX3f adapter
1 parent ee2e721 commit 828ee6c

File tree

1 file changed

+56
-52
lines changed

1 file changed

+56
-52
lines changed

src/main.cpp

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,74 +7,78 @@
77
#include <rerun.hpp>
88

99
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));
10+
struct rerun::ComponentBatchAdapter<rerun::components::Position3D,
11+
std::vector<Eigen::Vector3f>> {
12+
// Sanity check that this is binary compatible.
13+
static_assert(sizeof(components::Position3D) == sizeof(Eigen::Vector3f));
14+
static_assert(alignof(components::Position3D) <= alignof(Eigen::Vector3f));
1415

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-
}
16+
ComponentBatch<components::Position3D>
17+
operator()(const std::vector<Eigen::Vector3f> &container) {
18+
return ComponentBatch<components::Position3D>::borrow(
19+
reinterpret_cast<const components::Position3D *>(container.data()),
20+
container.size());
21+
}
2222

23-
ComponentBatch<components::Position3D> operator()(std::vector<Eigen::Vector3f> &&container) {
24-
throw std::runtime_error("Not implemented for temporaries");
25-
}
23+
ComponentBatch<components::Position3D>
24+
operator()(std::vector<Eigen::Vector3f> &&container) {
25+
throw std::runtime_error("Not implemented for temporaries");
26+
}
2627
};
2728

2829
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)); */
30+
struct rerun::ComponentBatchAdapter<rerun::components::Position3D,
31+
Eigen::MatrixX3f> {
32+
// Sanity check that this is binary compatible.
33+
static_assert(sizeof(components::Position3D) ==
34+
sizeof(Eigen::MatrixX3f::Scalar) *
35+
Eigen::MatrixX3f::ColsAtCompileTime);
36+
static_assert(alignof(components::Position3D) <= alignof(Eigen::MatrixX3f));
3337

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-
}
38+
ComponentBatch<components::Position3D>
39+
operator()(const Eigen::MatrixX3f &matrix) {
40+
return ComponentBatch<components::Position3D>::borrow(
41+
reinterpret_cast<const components::Position3D *>(matrix.data()),
42+
matrix.rows());
43+
}
4144

42-
ComponentBatch<components::Position3D> operator()(std::vector<Eigen::MatrixX3f> &&container) {
43-
throw std::runtime_error("Not implemented for temporaries");
44-
}
45+
ComponentBatch<components::Position3D>
46+
operator()(std::vector<Eigen::MatrixX3f> &&container) {
47+
throw std::runtime_error("Not implemented for temporaries");
48+
}
4549
};
4650

4751
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;
52+
std::vector<Eigen::Vector3f> points(num_points);
53+
for (auto &point : points) {
54+
point.setRandom();
55+
}
56+
return points;
5357
}
5458

5559
int main() {
56-
auto rec = rerun::RecordingStream("rerun_cpp_example_opencv_eigen");
57-
rec.connect("127.0.0.1:9876").throw_on_failure();
60+
auto rec = rerun::RecordingStream("rerun_cpp_example_opencv_eigen");
61+
rec.connect("127.0.0.1:9876").throw_on_failure();
5862

59-
const int num_points = 1000;
63+
const int num_points = 1000;
6064

61-
// Points represented by std::vector<Eigen::Vector3f>
62-
auto points3d_vector = generate_random_points_vector(1000);
63-
rec.log("points_from_vector", rerun::Points3D(points3d_vector));
65+
// Points represented by std::vector<Eigen::Vector3f>
66+
auto points3d_vector = generate_random_points_vector(1000);
67+
rec.log("points_from_vector", rerun::Points3D(points3d_vector));
6468

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));
69+
// Points represented by Eigen::MatX3f (Nx3 matrix)
70+
Eigen::MatrixX3f points3d_matrix = Eigen::MatrixX3f::Random(num_points, 3);
71+
rec.log("points_from_matrix", rerun::Points3D(points3d_matrix));
6872

69-
// Image
70-
std::string image_path = "rerun-logo.png";
71-
cv::Mat img = imread(image_path, cv::IMREAD_COLOR);
72-
if (img.empty()) {
73-
std::cout << "Could not read the image: " << image_path << std::endl;
74-
return 1;
75-
}
76-
imshow("Display window", img);
77-
cv::waitKey(0);
73+
// Image
74+
std::string image_path = "rerun-logo.png";
75+
cv::Mat img = imread(image_path, cv::IMREAD_COLOR);
76+
if (img.empty()) {
77+
std::cout << "Could not read the image: " << image_path << std::endl;
78+
return 1;
79+
}
80+
imshow("Display window", img);
81+
cv::waitKey(0);
7882

79-
return 0;
83+
return 0;
8084
}

0 commit comments

Comments
 (0)