|
7 | 7 | #include <rerun.hpp>
|
8 | 8 |
|
9 | 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)); |
| 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)); |
14 | 15 |
|
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 | + } |
22 | 22 |
|
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 | + } |
26 | 27 | };
|
27 | 28 |
|
28 | 29 | 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)); |
33 | 37 |
|
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 | + } |
41 | 44 |
|
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 | + } |
45 | 49 | };
|
46 | 50 |
|
47 | 51 | 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; |
53 | 57 | }
|
54 | 58 |
|
55 | 59 | 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(); |
58 | 62 |
|
59 |
| - const int num_points = 1000; |
| 63 | + const int num_points = 1000; |
60 | 64 |
|
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)); |
64 | 68 |
|
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)); |
68 | 72 |
|
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); |
78 | 82 |
|
79 |
| - return 0; |
| 83 | + return 0; |
80 | 84 | }
|
0 commit comments