8#include <RobotsIO/Utils/DatasetDataStream.h>
9#include <RobotsIO/Utils/FileToEigen.h>
12using namespace RobotsIO::Utils;
15DatasetDataStream::DatasetDataStream(
const std::string& file_path,
const std::size_t& skip_rows,
const std::size_t& skip_cols,
const std::size_t& expected_cols,
const int rx_time_index,
const int tx_time_index)
19 std::tie(valid_file, data_all) = file_to_eigen(file_path, 0, skip_cols, expected_cols);
22 throw(std::runtime_error(log_name_ +
"::ctor. Error cannot read data from file " + file_path +
"."));
24 if (rx_time_index >= data_all.cols())
25 throw(std::runtime_error(log_name_ +
"::ctor. Specified rx time index " + std::to_string(rx_time_index) +
" is out of range."));
27 if (tx_time_index >= data_all.cols())
28 throw(std::runtime_error(log_name_ +
"::ctor. Specified tx time index " + std::to_string(tx_time_index) +
" is out of range."));
30 std::size_t data_time_rows = 0;
31 if (rx_time_index != -1)
33 data_rx_time_ = data_all.row(rx_time_index);
37 if (tx_time_index != -1)
39 data_tx_time_ = data_all.row(tx_time_index);
43 data_.resize(data_all.rows() - data_time_rows, data_all.cols());
45 for (std::size_t i = 0; i < data_all.rows(); i++)
47 if ((i == rx_time_index) || (i == tx_time_index))
49 data_.row(j) = data_all.row(i);
56DatasetDataStream::~DatasetDataStream()
60double DatasetDataStream::rx_time()
62 if (data_rx_time_.size() != 0)
63 return data_rx_time_(get_head());
69double DatasetDataStream::tx_time()
71 if (data_tx_time_.size() != 0)
72 return data_tx_time_(get_head());
78VectorXd DatasetDataStream::data()
80 return data_.col(get_head());
84bool DatasetDataStream::freeze()
86 return set_head(get_head() + 1);
90int DatasetDataStream::get_head()
96bool DatasetDataStream::set_head(
const int& value)
98 if (value >= data_.cols())
107VectorXd DatasetDataStream::data(
const int& index)
109 if (index < 0 || index >= data_.cols())
110 throw(std::runtime_error(log_name_ +
"::data(const int& index). Error: invalid index provided (index = " + std::to_string(index) +
")."));
112 return data_.col(index);