Skip to content

Commit a4e7bbc

Browse files
committed
fix: use correct head in get_edge_RT_as_rtmat and get_translation
1 parent 518f3f0 commit a4e7bbc

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

api/dsr_rt_api.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ std::optional<Mat::RTMat> RT_API::get_edge_RT_as_rtmat(const Edge &edge, std::u
5555
const auto &r = r_o.value().get();
5656
if (timestamp == 0) // return with the first 3 elements of the arrays
5757
{
58-
if (head_o.has_value() and tstamps_o.has_value())
58+
if (head_o.has_value())
5959
{
60-
const auto &head = head_o.value();
60+
const auto &head = prev(head_o.value(), t.size(), 3);
6161
//qInfo() << __FUNCTION__ << " ZERO " << static_cast<int64_t>(timestamp) << static_cast<int64_t>(tstamps_o.value().get()[(int)(head/BLOCK_SIZE)]);
6262
return Mat::RTMat(Eigen::Translation3d(t[head], t[head+1], t[head+2]) *
6363
Eigen::AngleAxisd(r[head], Eigen::Vector3d::UnitX()) *
@@ -117,9 +117,10 @@ std::optional<Eigen::Vector3d> RT_API::get_translation(const Node &n, uint64_t t
117117
const auto &t = t_o.value().get();
118118
if (timestamp == 0)
119119
{
120-
if (head_o.has_value() and tstamps_o.has_value())
121-
return Eigen::Vector3d(t[head_o.value()], t[head_o.value() + 1], t[head_o.value() + 2]);
122-
else
120+
if (head_o.has_value() and tstamps_o.has_value()){
121+
auto h = prev(head_o.value(), t.size(), 3);
122+
return Eigen::Vector3d(t[h], t[h + 1], t[h + 2]);
123+
} else
123124
return Eigen::Vector3d(t[0], t[1], t[2]);
124125
}
125126
else // timestamp not 0
@@ -216,8 +217,6 @@ void RT_API::insert_or_assign_edge_RT(Node &n, uint64_t to, const std::vector<fl
216217
std::chrono::system_clock::now().time_since_epoch()).count());
217218

218219

219-
constexpr auto next = [](auto v, auto size) { return (v + 1) % size; };
220-
constexpr auto prev = [](auto v, auto size) { return (v > 0) ? v - 1 : size - 1; };
221220

222221
if (timestamp_v < time_stamps[prev(timestamp_index, HISTORY_SIZE)]) {
223222
std::vector<int64_t> diffs;
@@ -405,8 +404,6 @@ void RT_API::insert_or_assign_edge_RT(Node &n, uint64_t to, std::vector<float> &
405404
std::chrono::duration_cast<std::chrono::milliseconds>(
406405
std::chrono::system_clock::now().time_since_epoch()).count());
407406

408-
constexpr auto next = [](auto v, auto size) { return (v + 1) % size; };
409-
constexpr auto prev = [](auto v, auto size) { return (v > 0) ? v - 1 : size - 1; };
410407

411408
if (timestamp_v < time_stamps[prev(timestamp_index, HISTORY_SIZE)]) {
412409
std::vector<int64_t> diffs;

api/include/dsr/api/dsr_rt_api.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ namespace DSR
3939
// void del_edge_slot(const std::int32_t from, const std::int32_t to, const std::string &edge_type);
4040
private:
4141
DSR::DSRGraph *G;
42+
static constexpr auto next = [](auto v, int size, int decr = 1) { return (v + decr) % size; };
43+
static constexpr auto prev = [](auto v, int size, int inc = 1) { return (v > 0) ? v - inc : size - inc; };
44+
4245
};
4346
}
4447

0 commit comments

Comments
 (0)