diff --git a/nocturne/cpp/include/scenario.h b/nocturne/cpp/include/scenario.h index 6a428dd2..0eb0373c 100644 --- a/nocturne/cpp/include/scenario.h +++ b/nocturne/cpp/include/scenario.h @@ -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 { diff --git a/nocturne/pybind11/src/scenario.cc b/nocturne/pybind11/src/scenario.cc index 70805e18..fd8fddb1 100644 --- a/nocturne/pybind11/src/scenario.cc +++ b/nocturne/pybind11/src/scenario.cc @@ -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,