diff --git a/Docs/python_api.md b/Docs/python_api.md index 8e67ca2ae..60d87ca78 100644 --- a/Docs/python_api.md +++ b/Docs/python_api.md @@ -78,6 +78,7 @@ ## `carla.ActorList` +- `find(id)` - `filter(wildcard_pattern)` - `__getitem__(pos)` - `__len__()` diff --git a/LibCarla/source/carla/client/ActorList.cpp b/LibCarla/source/carla/client/ActorList.cpp index 98091b313..4faecd019 100644 --- a/LibCarla/source/carla/client/ActorList.cpp +++ b/LibCarla/source/carla/client/ActorList.cpp @@ -20,12 +20,9 @@ namespace client { : _episode(std::move(episode)), _actors(std::make_move_iterator(actors.begin()), std::make_move_iterator(actors.end())) {} - SharedPtr ActorList::GetActor(actor_id_type const actor_id) const - { - for (auto &actor: _actors) - { - if (actor_id == actor.GetId()) - { + SharedPtr ActorList::Find(actor_id_type const actor_id) const { + for (auto &actor : _actors) { + if (actor_id == actor.GetId()) { return actor.Get(_episode, shared_from_this()); } } diff --git a/LibCarla/source/carla/client/ActorList.h b/LibCarla/source/carla/client/ActorList.h index 445823816..1a20ca507 100644 --- a/LibCarla/source/carla/client/ActorList.h +++ b/LibCarla/source/carla/client/ActorList.h @@ -27,6 +27,9 @@ namespace client { public: + /// Find an actor by id. + SharedPtr Find(actor_id_type actor_id) const; + /// Filters a list of Actor with type id matching @a wildcard_pattern. ActorList Filter(const std::string &wildcard_pattern) const; @@ -54,8 +57,6 @@ namespace client { return _actors.size(); } - SharedPtr GetActor(actor_id_type const actor_id) const; - private: friend class World; diff --git a/LibCarla/source/carla/client/detail/ActorVariant.cpp b/LibCarla/source/carla/client/detail/ActorVariant.cpp index ee1959ef1..1865bb916 100644 --- a/LibCarla/source/carla/client/detail/ActorVariant.cpp +++ b/LibCarla/source/carla/client/detail/ActorVariant.cpp @@ -16,10 +16,10 @@ namespace detail { void ActorVariant::MakeActor(EpisodeProxy episode, SharedPtr actor_list) const { auto const parent_id = GetParentId(); SharedPtr parent = nullptr; - if ( (actor_list != nullptr) && (parent_id != 0) ) - { - // in case we have an actor list as context, we are able to actually create the parent actor - parent = actor_list->GetActor(parent_id); + if ((actor_list != nullptr) && (parent_id != 0)) { + // In case we have an actor list as context, we are able to actually + // create the parent actor. + parent = actor_list->Find(parent_id); } _value = detail::ActorFactory::MakeActor( episode, diff --git a/PythonAPI/source/libcarla/Blueprint.cpp b/PythonAPI/source/libcarla/Blueprint.cpp index 79af45a6f..1903723ff 100644 --- a/PythonAPI/source/libcarla/Blueprint.cpp +++ b/PythonAPI/source/libcarla/Blueprint.cpp @@ -148,8 +148,8 @@ void export_blueprint() { class_>("BlueprintLibrary", no_init) .def("find", +[](const cc::BlueprintLibrary &self, const std::string &key) -> cc::ActorBlueprint { return self.at(key); - }) - .def("filter", &cc::BlueprintLibrary::Filter) + }, (arg("id"))) + .def("filter", &cc::BlueprintLibrary::Filter, (arg("wildcard_pattern"))) .def("__getitem__", +[](const cc::BlueprintLibrary &self, size_t pos) -> cc::ActorBlueprint { return self.at(pos); }) diff --git a/PythonAPI/source/libcarla/World.cpp b/PythonAPI/source/libcarla/World.cpp index b2ead0362..93bb52373 100644 --- a/PythonAPI/source/libcarla/World.cpp +++ b/PythonAPI/source/libcarla/World.cpp @@ -64,7 +64,8 @@ void export_world() { ; class_>("ActorList", no_init) - .def("filter", &cc::ActorList::Filter) + .def("find", &cc::ActorList::Find, (arg("id"))) + .def("filter", &cc::ActorList::Filter, (arg("wildcard_pattern"))) .def("__getitem__", &cc::ActorList::at) .def("__len__", &cc::ActorList::size) .def("__iter__", range(&cc::ActorList::begin, &cc::ActorList::end))