diff --git a/CMakeLists.txt b/CMakeLists.txt index b905980..f853180 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,6 @@ FetchContent_MakeAvailable(vrslib) find_package(fmt REQUIRED) -add_executable(rerun_vrs_example src/main.cpp src/FramePlayer.cpp src/IMUPlayer.cpp) +add_executable(rerun_vrs_example src/main.cpp src/frame_player.cpp src/imu_player.cpp) target_link_libraries(rerun_vrs_example rerun_sdk vrslib vrs_utils fmt) target_include_directories(rerun_vrs_example PRIVATE src) diff --git a/src/FramePlayer.cpp b/src/frame_player.cpp similarity index 73% rename from src/FramePlayer.cpp rename to src/frame_player.cpp index a3e3103..571a067 100644 --- a/src/FramePlayer.cpp +++ b/src/frame_player.cpp @@ -21,7 +21,7 @@ #include #include -#include "FramePlayer.h" +#include "frame_player.hpp" namespace rerun_vrs { @@ -32,12 +32,12 @@ namespace rerun_vrs { }; FramePlayer::FramePlayer(vrs::StreamId id, std::shared_ptr rec) - : id_{id}, rec_{rec}, entityPath_{rerun::new_entity_path({id.getName()})} {} + : _id{id}, _rec{rec}, _entity_path{rerun::new_entity_path({id.getName()})} {} bool FramePlayer::onDataLayoutRead( - const vrs::CurrentRecord& record, size_t blockIndex, vrs::DataLayout& layout + const vrs::CurrentRecord& record, size_t block_index, vrs::DataLayout& layout ) { - if (!enabled_) { + if (!_enabled) { return false; } @@ -45,42 +45,42 @@ namespace rerun_vrs { layout.printLayoutCompact(buffer); const auto& layout_str = buffer.str(); - rec_->set_time_seconds("timestamp", record.timestamp); + _rec->set_time_seconds("timestamp", record.timestamp); if (record.recordType == vrs::Record::Type::CONFIGURATION) { // NOTE this is meta data from the sensor that doesn't change over time and only comes // in once in the beginning - rec_->log_timeless(entityPath_ + "/configuration", rerun::TextDocument(layout_str)); + _rec->log_timeless(_entity_path + "/configuration", rerun::TextDocument(layout_str)); } if (record.recordType == vrs::Record::Type::DATA) { - auto& config = getExpectedLayout(layout, blockIndex); + auto& config = getExpectedLayout(layout, block_index); uint64_t frame_number; if (config.frameNumber.get(frame_number)) { - rec_->set_time_sequence("frame_number", frame_number); + _rec->set_time_sequence("frame_number", frame_number); } // this is meta data per record and changes over time - rec_->log(entityPath_ + "/data", rerun::TextDocument(layout_str)); + _rec->log(_entity_path + "/data", rerun::TextDocument(layout_str)); } return true; } bool FramePlayer::onImageRead( - const vrs::CurrentRecord& record, size_t /*blockIndex*/, - const vrs::ContentBlock& contentBlock + const vrs::CurrentRecord& record, size_t /*block_index*/, + const vrs::ContentBlock& content_block ) { std::shared_ptr frame; - bool frameValid = vrs::utils::PixelFrame::readFrame(frame, record.reader, contentBlock); + bool frame_valid = vrs::utils::PixelFrame::readFrame(frame, record.reader, content_block); - if (frameValid) { + if (frame_valid) { // Log image to Rerun // NOTE Rerun assumes row major ordering for Images (i.e., TensorData) without any stride. // Right now we don't check this properly, and just assume that there is no extra padding // per pixel and / or per row. - rec_->log( - entityPath_, + _rec->log( + _entity_path, rerun::Image( {frame->getHeight(), frame->getWidth(), @@ -90,9 +90,9 @@ namespace rerun_vrs { ); } else { std::cout << "Failed reading image with format \"" - << contentBlock.image().getImageFormatAsString() << "\". Disabling player." + << content_block.image().getImageFormatAsString() << "\". Disabling player." << std::endl; - enabled_ = false; + _enabled = false; } return true; } diff --git a/src/FramePlayer.h b/src/frame_player.hpp similarity index 85% rename from src/FramePlayer.h rename to src/frame_player.hpp index b6c305e..9220941 100644 --- a/src/FramePlayer.h +++ b/src/frame_player.hpp @@ -30,16 +30,16 @@ namespace rerun_vrs { public: explicit FramePlayer(vrs::StreamId id, std::shared_ptr rec); - bool onDataLayoutRead(const vrs::CurrentRecord& r, size_t blockIndex, vrs::DataLayout&) + bool onDataLayoutRead(const vrs::CurrentRecord& r, size_t block_index, vrs::DataLayout&) override; - bool onImageRead(const vrs::CurrentRecord& r, size_t blockIndex, const vrs::ContentBlock&) + bool onImageRead(const vrs::CurrentRecord& r, size_t block_index, const vrs::ContentBlock&) override; private: - std::shared_ptr rec_; - vrs::StreamId id_; - std::string entityPath_; - bool enabled_{true}; + std::shared_ptr _rec; + vrs::StreamId _id; + std::string _entity_path; + bool _enabled{true}; }; } // namespace rerun_vrs diff --git a/src/IMUPlayer.cpp b/src/imu_player.cpp similarity index 57% rename from src/IMUPlayer.cpp rename to src/imu_player.cpp index 18d86b0..2ed8bba 100644 --- a/src/IMUPlayer.cpp +++ b/src/imu_player.cpp @@ -23,14 +23,14 @@ #include #include -#include "IMUPlayer.h" +#include "imu_player.hpp" namespace rerun_vrs { struct IMUConfigurationDataLayout : public vrs::AutoDataLayout { - vrs::DataPieceValue hasAccelerometer_{"has_accelerometer"}; - vrs::DataPieceValue hasGyroscope_{"has_gyroscope"}; - vrs::DataPieceValue hasMagnetometer_{"has_magnetometer"}; + vrs::DataPieceValue _has_accelerometer{"has_accelerometer"}; + vrs::DataPieceValue _has_gyroscope{"has_gyroscope"}; + vrs::DataPieceValue _has_magnetometer{"has_magnetometer"}; vrs::AutoDataLayoutEnd endLayout; }; @@ -44,12 +44,12 @@ namespace rerun_vrs { }; IMUPlayer::IMUPlayer(vrs::StreamId id, std::shared_ptr rec) - : id_{id}, rec_{rec}, entityPath_{rerun::new_entity_path({id.getName()})} {} + : _id{id}, _rec{rec}, _entity_path{rerun::new_entity_path({id.getName()})} {} bool IMUPlayer::onDataLayoutRead( const vrs::CurrentRecord& record, size_t blockIndex, vrs::DataLayout& layout ) { - if (!enabled_) { + if (!_enabled) { return false; } @@ -57,39 +57,39 @@ namespace rerun_vrs { layout.printLayoutCompact(buffer); const auto& layout_str = buffer.str(); - rec_->set_time_seconds("timestamp", record.timestamp); + _rec->set_time_seconds("timestamp", record.timestamp); if (record.recordType == vrs::Record::Type::CONFIGURATION) { // NOTE this is meta data from the sensor that doesn't change over time and only comes // in once in the beginning - rec_->log_timeless(entityPath_ + "/configuration", rerun::TextDocument(layout_str)); + _rec->log_timeless(_entity_path + "/configuration", rerun::TextDocument(layout_str)); // read properties required for logging auto& config = getExpectedLayout(layout, blockIndex); - hasAccelerometer_ = config.hasAccelerometer_.get(); - hasGyroscope_ = config.hasGyroscope_.get(); - hasMagnetometer_ = config.hasMagnetometer_.get(); + _has_accelerometer = config._has_accelerometer.get(); + _has_gyroscope = config._has_gyroscope.get(); + _has_magnetometer = config._has_magnetometer.get(); } if (record.recordType == vrs::Record::Type::DATA) { auto& data = getExpectedLayout(layout, blockIndex); - if (hasAccelerometer_) { + if (_has_accelerometer) { std::array accelMSec2; if (data.accelMSec2.get(accelMSec2.data(), accelMSec2.size())) { - logAccelerometer(accelMSec2); + log_accelerometer(accelMSec2); } } - if (hasGyroscope_) { + if (_has_gyroscope) { std::array gyroRadSec; if (data.gyroRadSec.get(gyroRadSec.data(), gyroRadSec.size())) { - logGyroscope(gyroRadSec); + log_gyroscope(gyroRadSec); } } - if (hasMagnetometer_) { + if (_has_magnetometer) { std::array magTesla; if (data.magTesla.get(magTesla.data(), magTesla.size())) { - logMagnetometer(magTesla); + log_magnetometer(magTesla); } } } @@ -97,26 +97,26 @@ namespace rerun_vrs { return false; } - void IMUPlayer::logAccelerometer(const std::array& accelMSec2) { - rec_->log(entityPath_ + "/accelerometer", rerun::Arrows3D::from_vectors({accelMSec2})); - rec_->log(entityPath_ + "/accelerometer/x", rerun::TimeSeriesScalar(accelMSec2[0])); - rec_->log(entityPath_ + "/accelerometer/y", rerun::TimeSeriesScalar(accelMSec2[1])); - rec_->log(entityPath_ + "/accelerometer/z", rerun::TimeSeriesScalar(accelMSec2[2])); + void IMUPlayer::log_accelerometer(const std::array& accelMSec2) { + _rec->log(_entity_path + "/accelerometer", rerun::Arrows3D::from_vectors({accelMSec2})); + _rec->log(_entity_path + "/accelerometer/x", rerun::TimeSeriesScalar(accelMSec2[0])); + _rec->log(_entity_path + "/accelerometer/y", rerun::TimeSeriesScalar(accelMSec2[1])); + _rec->log(_entity_path + "/accelerometer/z", rerun::TimeSeriesScalar(accelMSec2[2])); } - void IMUPlayer::logGyroscope(const std::array& gyroRadSec) { - rec_->log(entityPath_ + "/gyroscope/x", rerun::TimeSeriesScalar(gyroRadSec[0])); - rec_->log(entityPath_ + "/gyroscope/y", rerun::TimeSeriesScalar(gyroRadSec[1])); - rec_->log(entityPath_ + "/gyroscope/z", rerun::TimeSeriesScalar(gyroRadSec[2])); + void IMUPlayer::log_gyroscope(const std::array& gyroRadSec) { + _rec->log(_entity_path + "/gyroscope/x", rerun::TimeSeriesScalar(gyroRadSec[0])); + _rec->log(_entity_path + "/gyroscope/y", rerun::TimeSeriesScalar(gyroRadSec[1])); + _rec->log(_entity_path + "/gyroscope/z", rerun::TimeSeriesScalar(gyroRadSec[2])); } - void IMUPlayer::logMagnetometer(const std::array& magTesla) { - rec_->log(entityPath_ + "/magnetometer/x", rerun::TimeSeriesScalar(magTesla[0])); - rec_->log(entityPath_ + "/magnetometer/y", rerun::TimeSeriesScalar(magTesla[1])); - rec_->log(entityPath_ + "/magnetometer/z", rerun::TimeSeriesScalar(magTesla[2])); + void IMUPlayer::log_magnetometer(const std::array& magTesla) { + _rec->log(_entity_path + "/magnetometer/x", rerun::TimeSeriesScalar(magTesla[0])); + _rec->log(_entity_path + "/magnetometer/y", rerun::TimeSeriesScalar(magTesla[1])); + _rec->log(_entity_path + "/magnetometer/z", rerun::TimeSeriesScalar(magTesla[2])); } - bool mightContainIMUData(const vrs::StreamId& id) { + bool might_contain_imu_data(const vrs::StreamId& id) { return id.getTypeId() == vrs::RecordableTypeId::SlamImuData || id.getTypeId() == vrs::RecordableTypeId::SlamMagnetometerData || id.getTypeId() == vrs::RecordableTypeId::ImuRecordableClass; diff --git a/src/IMUPlayer.h b/src/imu_player.hpp similarity index 71% rename from src/IMUPlayer.h rename to src/imu_player.hpp index a994c8e..1433cc0 100644 --- a/src/IMUPlayer.h +++ b/src/imu_player.hpp @@ -34,19 +34,19 @@ namespace rerun_vrs { override; private: - void logAccelerometer(const std::array& accelMSec2); - void logGyroscope(const std::array& gyroRadSec); - void logMagnetometer(const std::array& magTesla); - - std::shared_ptr rec_; - vrs::StreamId id_; - std::string entityPath_; - bool enabled_{true}; - bool hasAccelerometer_; - bool hasGyroscope_; - bool hasMagnetometer_; + void log_accelerometer(const std::array& accelMSec2); + void log_gyroscope(const std::array& gyroRadSec); + void log_magnetometer(const std::array& magTesla); + + std::shared_ptr _rec; + vrs::StreamId _id; + std::string _entity_path; + bool _enabled{true}; + bool _has_accelerometer; + bool _has_gyroscope; + bool _has_magnetometer; }; - bool mightContainIMUData(const vrs::StreamId& id); + bool might_contain_imu_data(const vrs::StreamId& id); } // namespace rerun_vrs diff --git a/src/main.cpp b/src/main.cpp index 203941f..ef96777 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,8 +7,8 @@ #include #include -#include "FramePlayer.h" -#include "IMUPlayer.h" +#include "frame_player.hpp" +#include "imu_player.hpp" int main(int argc, const char* argv[]) { std::cout << "Rerun SDK Version:" << rerun::version_string() << std::endl; @@ -21,13 +21,13 @@ int main(int argc, const char* argv[]) { return 0; } - std::string vrsPath(argv[1]); + std::string vrs_path(argv[1]); vrs::RecordFileReader reader; - if (reader.openFile(vrsPath) == 0) { + if (reader.openFile(vrs_path) == 0) { // for each type of stream there is one player that logs the read data to // Rerun - std::vector> streamPlayers; + std::vector> stream_players; const std::set& streamIds = reader.getStreams(); for (auto id : streamIds) { @@ -35,12 +35,12 @@ int main(int argc, const char* argv[]) { << ": "; if (reader.mightContainImages(id)) { std::cout << "Handled by FramePlayer" << std::endl; - streamPlayers.emplace_back(std::make_unique(id, rec)); - reader.setStreamPlayer(id, streamPlayers.back().get()); - } else if (rerun_vrs::mightContainIMUData(id)) { + stream_players.emplace_back(std::make_unique(id, rec)); + reader.setStreamPlayer(id, stream_players.back().get()); + } else if (rerun_vrs::might_contain_imu_data(id)) { std::cout << "Handled by IMUPlayer" << std::endl; - streamPlayers.emplace_back(std::make_unique(id, rec)); - reader.setStreamPlayer(id, streamPlayers.back().get()); + stream_players.emplace_back(std::make_unique(id, rec)); + reader.setStreamPlayer(id, stream_players.back().get()); } else { std::cout << "No player available. Skipped." << std::endl; }