Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slight code cleanup #7

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <iostream>

#include <eigen3/Eigen/Core>
#include <eigen3/Eigen/Dense>
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgcodecs.hpp>
Expand All @@ -9,42 +10,41 @@

// Adapters so we can log eigen vectors as rerun positions:
template <>
struct rerun::ComponentBatchAdapter<rerun::components::Position3D, std::vector<Eigen::Vector3f>> {
struct rerun::ComponentBatchAdapter<rerun::Position3D, std::vector<Eigen::Vector3f>> {
// Sanity check that this is binary compatible.
static_assert(sizeof(components::Position3D) == sizeof(Eigen::Vector3f));
static_assert(alignof(components::Position3D) <= alignof(Eigen::Vector3f));
static_assert(sizeof(rerun::Position3D) == sizeof(Eigen::Vector3f));
static_assert(alignof(rerun::Position3D) <= alignof(Eigen::Vector3f));

ComponentBatch<components::Position3D> operator()(const std::vector<Eigen::Vector3f>& container
) {
return ComponentBatch<components::Position3D>::borrow(
reinterpret_cast<const components::Position3D*>(container.data()),
ComponentBatch<rerun::Position3D> operator()(const std::vector<Eigen::Vector3f>& container) {
return ComponentBatch<rerun::Position3D>::borrow(
reinterpret_cast<const rerun::Position3D*>(container.data()),
container.size()
);
}

ComponentBatch<components::Position3D> operator()(std::vector<Eigen::Vector3f>&& container) {
ComponentBatch<rerun::Position3D> operator()(std::vector<Eigen::Vector3f>&& container) {
throw std::runtime_error("Not implemented for temporaries");
}
};

// Adapters so we can log an eigen matrix as rerun positions:
template <>
struct rerun::ComponentBatchAdapter<rerun::components::Position3D, Eigen::Matrix3Xf> {
struct rerun::ComponentBatchAdapter<rerun::Position3D, Eigen::Matrix3Xf> {
// Sanity check that this is binary compatible.
static_assert(
sizeof(components::Position3D) ==
sizeof(rerun::Position3D) ==
sizeof(Eigen::Matrix3Xf::Scalar) * Eigen::Matrix3Xf::RowsAtCompileTime
);
static_assert(alignof(components::Position3D) <= alignof(Eigen::Matrix3Xf));
static_assert(alignof(rerun::Position3D) <= alignof(Eigen::Matrix3Xf));

ComponentBatch<components::Position3D> operator()(const Eigen::Matrix3Xf& matrix) {
return ComponentBatch<components::Position3D>::borrow(
reinterpret_cast<const components::Position3D*>(matrix.data()),
ComponentBatch<rerun::Position3D> operator()(const Eigen::Matrix3Xf& matrix) {
return ComponentBatch<rerun::Position3D>::borrow(
reinterpret_cast<const rerun::Position3D*>(matrix.data()),
matrix.cols()
);
}

ComponentBatch<components::Position3D> operator()(std::vector<Eigen::Matrix3Xf>&& container) {
ComponentBatch<rerun::Position3D> operator()(std::vector<Eigen::Matrix3Xf>&& container) {
throw std::runtime_error("Not implemented for temporaries");
}
};
Expand Down