diff --git a/LibCarla/source/carla/client/World.cpp b/LibCarla/source/carla/client/World.cpp index 2c3c3cabb..90f0d0b87 100644 --- a/LibCarla/source/carla/client/World.cpp +++ b/LibCarla/source/carla/client/World.cpp @@ -174,8 +174,8 @@ namespace client { return _episode.Lock()->GetLevelBBs(queried_tag); } - std::vector World::GetEnvironmentObjects() const { - return _episode.Lock()->GetEnvironmentObjects(); + std::vector World::GetEnvironmentObjects(uint8_t queried_tag) const { + return _episode.Lock()->GetEnvironmentObjects(queried_tag); } void World::EnableEnvironmentObjects( diff --git a/LibCarla/source/carla/client/World.h b/LibCarla/source/carla/client/World.h index 24569d04b..0f9deda88 100644 --- a/LibCarla/source/carla/client/World.h +++ b/LibCarla/source/carla/client/World.h @@ -162,7 +162,7 @@ namespace client { /// Returns all the BBs of all the elements of the level std::vector GetLevelBBs(uint8_t queried_tag) const; - std::vector GetEnvironmentObjects() const; + std::vector GetEnvironmentObjects(uint8_t queried_tag) const; void EnableEnvironmentObjects( std::vector env_objects_ids, diff --git a/LibCarla/source/carla/client/detail/Client.cpp b/LibCarla/source/carla/client/detail/Client.cpp index 55744236d..a05b89b68 100644 --- a/LibCarla/source/carla/client/detail/Client.cpp +++ b/LibCarla/source/carla/client/detail/Client.cpp @@ -460,9 +460,9 @@ namespace detail { return _pimpl->CallAndWait("get_all_level_BBs", queried_tag); } - std::vector Client::GetEnvironmentObjects() const { + std::vector Client::GetEnvironmentObjects(uint8_t queried_tag) const { using return_t = std::vector; - return _pimpl->CallAndWait("get_environment_objects"); + return _pimpl->CallAndWait("get_environment_objects", queried_tag); } void Client::EnableEnvironmentObjects( diff --git a/LibCarla/source/carla/client/detail/Client.h b/LibCarla/source/carla/client/detail/Client.h index 1eff460db..08eb629bb 100644 --- a/LibCarla/source/carla/client/detail/Client.h +++ b/LibCarla/source/carla/client/detail/Client.h @@ -298,7 +298,7 @@ namespace detail { /// Returns all the BBs of all the elements of the level std::vector GetLevelBBs(uint8_t queried_tag) const; - std::vector GetEnvironmentObjects() const; + std::vector GetEnvironmentObjects(uint8_t queried_tag) const; void EnableEnvironmentObjects( std::vector env_objects_ids, diff --git a/LibCarla/source/carla/client/detail/Simulator.h b/LibCarla/source/carla/client/detail/Simulator.h index 90635bc80..3c0e1b034 100644 --- a/LibCarla/source/carla/client/detail/Simulator.h +++ b/LibCarla/source/carla/client/detail/Simulator.h @@ -240,8 +240,8 @@ namespace detail { return _client.GetLevelBBs(queried_tag); } - std::vector GetEnvironmentObjects() const { - return _client.GetEnvironmentObjects(); + std::vector GetEnvironmentObjects(uint8_t queried_tag) const { + return _client.GetEnvironmentObjects(queried_tag); } void EnableEnvironmentObjects( diff --git a/PythonAPI/carla/source/libcarla/World.cpp b/PythonAPI/carla/source/libcarla/World.cpp index 5ad1a1ca4..13b1fe3d3 100644 --- a/PythonAPI/carla/source/libcarla/World.cpp +++ b/PythonAPI/carla/source/libcarla/World.cpp @@ -88,9 +88,9 @@ static auto GetLevelBBs(const carla::client::World &self, uint8_t queried_tag) { return result; } -static auto GetEnvironmentObjects(const carla::client::World &self) { +static auto GetEnvironmentObjects(const carla::client::World &self, uint8_t queried_tag) { boost::python::list result; - for (const auto &object : self.GetEnvironmentObjects()) { + for (const auto &object : self.GetEnvironmentObjects(queried_tag)) { result.append(object); } return result; @@ -270,8 +270,8 @@ void export_world() { .def("reset_all_traffic_lights", &cc::World::ResetAllTrafficLights) .def("get_lightmanager", CONST_CALL_WITHOUT_GIL(cc::World, GetLightManager)) .def("freeze_all_traffic_lights", &cc::World::FreezeAllTrafficLights, (arg("frozen"))) - .def("get_level_bbs", &GetLevelBBs, (arg("actor_type")=cr::CityObjectLabel::None)) - .def("get_environment_objects", &GetEnvironmentObjects) + .def("get_level_bbs", &GetLevelBBs, (arg("bb_type")=cr::CityObjectLabel::None)) + .def("get_environment_objects", &GetEnvironmentObjects, (arg("object_type")=cr::CityObjectLabel::None)) .def("enable_environment_objects", &EnableEnvironmentObjects, (arg("env_objects_ids"), arg("enable"))) .def("cast_ray", CALL_RETURNING_LIST_2(cc::World, CastRay, cg::Location, cg::Location), (arg("initial_location"), arg("final_location"))) .def("project_point", CALL_RETURNING_OPTIONAL_3(cc::World, ProjectPoint, cg::Location, cg::Vector3D, float), (arg("location"), arg("direction"), arg("search_distance")=10000.f)) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h index 37e59b7ad..d48a6d97c 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaGameModeBase.h @@ -57,9 +57,9 @@ public: TArray GetAllBBsOfLevel(uint8 TagQueried = 0); UFUNCTION(Category = "Carla Game Mode", BlueprintCallable, CallInEditor, Exec) - const TArray& GetEnvironmentObjects() const + TArray GetEnvironmentObjects(uint8 QueriedTag = 0) const { - return ObjectRegister->GetEnvironmentObjects(); + return ObjectRegister->GetEnvironmentObjects(QueriedTag); } void EnableEnvironmentObjects(const TSet& EnvObjectIds, bool Enable); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp index 29933b6ec..fe855f02c 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp @@ -369,7 +369,7 @@ void FCarlaServer::FPimpl::BindActions() return MakeVectorFromTArray(Result); }; - BIND_SYNC(get_environment_objects) << [this]() -> R> + BIND_SYNC(get_environment_objects) << [this](uint8 QueriedTag) -> R> { REQUIRE_CARLA_EPISODE(); ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(Episode->GetWorld()); @@ -377,7 +377,7 @@ void FCarlaServer::FPimpl::BindActions() { RESPOND_ERROR("unable to find CARLA game mode"); } - TArray Result = GameMode->GetEnvironmentObjects(); + TArray Result = GameMode->GetEnvironmentObjects(QueriedTag); return MakeVectorFromTArray(Result); }; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/ObjectRegister.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/ObjectRegister.cpp index c61da9a98..1a7386ff9 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/ObjectRegister.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/ObjectRegister.cpp @@ -16,6 +16,24 @@ namespace crp = carla::rpc; +TArray UObjectRegister::GetEnvironmentObjects(uint8 InTagQueried) const +{ + TArray Result; + + crp::CityObjectLabel TagQueried = (crp::CityObjectLabel)InTagQueried; + bool FilterByTagEnabled = (TagQueried != crp::CityObjectLabel::None); + + for(const FEnvironmentObject& It : EnvironmentObjects) + { + if(!FilterByTagEnabled || (It.ObjectLabel == TagQueried)) + { + Result.Emplace(It); + } + } + + return Result; +} + void UObjectRegister::RegisterObjects(TArray Actors) { // Empties the array but doesn't change memory allocations diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/ObjectRegister.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/ObjectRegister.h index 85ec41bcc..b14d0eddc 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/ObjectRegister.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/ObjectRegister.h @@ -25,11 +25,8 @@ public: UObjectRegister() {} ~UObjectRegister() {} - UFUNCTION(Category = "Carla Object Register", BlueprintCallable, CallInEditor, Exec) - const TArray& GetEnvironmentObjects() const - { - return EnvironmentObjects; - } + UFUNCTION(Category = "Carla Object Register", BlueprintCallable, CallInEditor) + TArray GetEnvironmentObjects(uint8 InTagQueried = 0) const; UFUNCTION(Category = "Carla Object Register") void RegisterObjects(TArray Actors);