Skip to content

Commit

Permalink
add a new method for finding the timestamp when the expert was last v…
Browse files Browse the repository at this point in the history
…alid
  • Loading branch information
eugenevinitsky committed Jan 22, 2024
1 parent 8b28348 commit 0804cde
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions nocturne/cpp/include/scenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ class Scenario : public sf::Drawable {
// void removeVehicle(Vehicle* object);
bool RemoveObject(const Object& object);

// Return the last timestamp where the object is valid
int64_t ExpertLastValid(const Object& object) const {
// expert_valid_masks is an array of 0s and 1s
// we want to return the last index where the object is valid
// so we reverse the array and find the first index where the object is valid
// and then subtract that from the size of the array
const auto& valid_mask = expert_valid_masks_.at(object.id());
auto it = std::find(valid_mask.rbegin(), valid_mask.rend(), true);
return valid_mask.size() - std::distance(valid_mask.rbegin(), it);
}

// Returns expert position for obj at timestamp.
geometry::Vector2D ExpertPosition(const Object& obj,
int64_t timestamp) const {
Expand Down
1 change: 1 addition & 0 deletions nocturne/pybind11/src/scenario.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ void DefineScenario(py::module& m) {
.def("expert_pos_shift", &Scenario::ExpertPosShift)
.def("expert_heading_shift", &Scenario::ExpertHeadingShift)
.def("expert_position", &Scenario::ExpertPosition)
.def("expert_last_valid", &Scenario::ExpertLastValid)

// TODO: Deprecate the legacy interfaces below.
.def("getVehicles", &Scenario::vehicles,
Expand Down

0 comments on commit 0804cde

Please sign in to comment.