Skip to content

Commit

Permalink
Added RPC API function for retrieving Instance Segmentation colormap
Browse files Browse the repository at this point in the history
  • Loading branch information
WouterJansen committed Jul 8, 2024
1 parent 52ab777 commit 3d16d77
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 8 deletions.
18 changes: 18 additions & 0 deletions AirLib/include/api/RpcLibAdaptorsBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ namespace airlib_rpclib
{
return msr::airlib::Vector3r(x_val, y_val, z_val);
}
static std::vector<Vector3r> from(
const std::vector<msr::airlib::Vector3r>& vectors
) {
std::vector<Vector3r> vector_adaptor;
for (const auto& item : vectors)
vector_adaptor.push_back(Vector3r(item));

return vector_adaptor;
}
static std::vector<msr::airlib::Vector3r> to(
const std::vector<Vector3r>& vector_adaptor
) {
std::vector<msr::airlib::Vector3r> vectors;
for (const auto& item : vector_adaptor)
vectors.push_back(item.to());

return vectors;
}
};

struct CollisionInfo
Expand Down
1 change: 1 addition & 0 deletions AirLib/include/api/RpcLibClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace airlib

vector<string> simListSceneObjects(const string& name_regex = string(".*")) const;
vector<string> simListInstanceSegmentationObjects() const;
vector<Vector3r> simGetInstanceSegmentationColorMap() const;
vector<Pose> simListInstanceSegmentationPoses(bool ned = true, bool only_visible = false) const;
Pose simGetObjectPose(const std::string& object_name, bool ned = true) const;
bool simLoadLevel(const string& level_name);
Expand Down
1 change: 1 addition & 0 deletions AirLib/include/api/WorldSimApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace airlib

virtual std::vector<std::string> listSceneObjects(const std::string& name_regex) const = 0;
virtual std::vector<std::string> listInstanceSegmentationObjects() const = 0;
virtual std::vector<Vector3r> getInstanceSegmentationColorMap() const = 0;
virtual std::vector<Pose> listInstanceSegmentationPoses(bool ned = true, bool only_visible = false) const = 0;
virtual Pose getObjectPose(const std::string& object_name, bool ned = true) const = 0;
virtual Vector3r getObjectScale(const std::string& object_name) const = 0;
Expand Down
6 changes: 6 additions & 0 deletions AirLib/src/api/RpcLibClientBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,12 @@ __pragma(warning(disable : 4239))
return pimpl_->client.call("simListInstanceSegmentationObjects").as<vector<string>>();
}

vector<msr::airlib::Vector3r> RpcLibClientBase::simGetInstanceSegmentationColorMap() const
{
const auto& response_adaptor = pimpl_->client.call("simGetInstanceSegmentationColorMap").as<vector<RpcLibAdaptorsBase::Vector3r>>();
return RpcLibAdaptorsBase::Vector3r::to(response_adaptor);
}

vector<msr::airlib::Pose> RpcLibClientBase::simListInstanceSegmentationPoses(bool ned, bool only_visible) const
{
const auto& response_adaptor = pimpl_->client.call("simListInstanceSegmentationPoses", ned, only_visible).as<vector<RpcLibAdaptorsBase::Pose>>();
Expand Down
4 changes: 4 additions & 0 deletions AirLib/src/api/RpcLibServerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ namespace airlib
return getWorldSimApi()->listInstanceSegmentationObjects();
});

pimpl_->server.bind("simGetInstanceSegmentationColorMap", [&]() -> std::vector<RpcLibAdaptorsBase::Vector3r> {
return RpcLibAdaptorsBase::Vector3r::from(getWorldSimApi()->getInstanceSegmentationColorMap());
});

pimpl_->server.bind("simListInstanceSegmentationPoses", [&](bool ned, bool only_visible) -> std::vector<RpcLibAdaptorsBase::Pose> {
return RpcLibAdaptorsBase::Pose::from(getWorldSimApi()->listInstanceSegmentationPoses(ned, only_visible));
});
Expand Down
8 changes: 8 additions & 0 deletions Unreal/Plugins/AirSim/Source/Annotation/ObjectAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,10 @@ TMap<FString, float> FObjectAnnotator::GetComponentToValueMap() {
return name_to_value_map_;
}

TArray<FColor> FObjectAnnotator::GetColorMap(){
return ColorGenerator_.GetColorMap();
}


void FObjectAnnotator::EndPlay() {

Expand Down Expand Up @@ -1341,6 +1345,10 @@ int FColorGenerator::GetGammaCorrectedColor(int color_index) {
return GammaCorrectionTable_[color_index];
}

static TArray<FColor> FColorGenerator::GetColorMap(){
return color_map_;
}

int32 FColorGenerator::GammaCorrectionTable_[256] =
{
0,
Expand Down
3 changes: 3 additions & 0 deletions Unreal/Plugins/AirSim/Source/Annotation/ObjectAnnotator.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class FColorGenerator
FColor GetColorFromColorMap(int32 ObjectIndex);
int GetIndexForColor(FColor color);
int GetGammaCorrectedColor(int color_index);
static TArray<FColor> GetColorMap();

private:
int32 GetChannelValue(uint32 Index);
Expand Down Expand Up @@ -71,6 +72,8 @@ class AIRSIM_API FObjectAnnotator

static void SetViewForAnnotationRender(FEngineShowFlags& show_flags);

TArray<FColor> GetColorMap();

bool IsDirect();
FObjectAnnotator::AnnotatorType GetType();

Expand Down
9 changes: 9 additions & 0 deletions Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,15 @@ std::vector<std::string> ASimModeBase::GetAllInstanceSegmentationMeshIDs() {
return instance_segmentation_annotator_.GetAllComponentNames();
}

TArray<msr::airlib::Vector3r> ASimModeBase::GetInstanceSegmentationColorMap() {
TArray<FColor> color_map = instance_segmentation_annotator_.GetColorMap();
TArray<msr::airlib::Vector3r> color_map_vector;
for (FColor color : color_map) {
color_map_vector.Add(msr::airlib::Vector3r(color.R, color.G, color.B));
}
return color_map_vector;
}

TMap<UMeshComponent*, FString> ASimModeBase::GetInstanceSegmentationComponentToNameMap() {
return instance_segmentation_annotator_.GetComponentToNameMap();
}
Expand Down
3 changes: 2 additions & 1 deletion Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,15 @@ class AIRSIM_API ASimModeBase : public AActor
const PawnSimApi* getVehicleSimApi(const std::string& vehicle_name = "") const
{
return static_cast<PawnSimApi*>(api_provider_->getVehicleSimApi(vehicle_name));
}
}W
PawnSimApi* getVehicleSimApi(const std::string& vehicle_name = "")
{
return static_cast<PawnSimApi*>(api_provider_->getVehicleSimApi(vehicle_name));
}
std::vector<std::string> GetAllInstanceSegmentationMeshIDs();
std::vector<msr::airlib::Pose> GetAllInstanceSegmentationMeshPoses(bool ned = true, bool only_visible = false);
TMap<UMeshComponent*, FString> GetInstanceSegmentationComponentToNameMap();
TArray<msr::airlib::Vector3r> GetInstanceSegmentationColorMap();

bool SetMeshInstanceSegmentationID(const std::string& mesh_name, int object_id, bool is_name_regex, bool update_annotation = true);
int GetMeshInstanceSegmentationID(const std::string& mesh_name);
Expand Down
6 changes: 6 additions & 0 deletions Unreal/Plugins/AirSim/Source/WorldSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,17 @@ bool WorldSimApi::runConsoleCommand(const std::string& command)
true);
return succeeded;
}

std::vector<std::string> WorldSimApi::listInstanceSegmentationObjects() const
{
return simmode_->GetAllInstanceSegmentationMeshIDs();
}

std::vector<msr::airlib::Vector3r> WorldSimApi::getInstanceSegmentationColorMap() const
{
return simmode_->GetInstanceSegmentationColorMap();
}

std::vector <msr::airlib::Pose> WorldSimApi::listInstanceSegmentationPoses(bool ned, bool only_visible) const
{
return simmode_->GetAllInstanceSegmentationMeshPoses(ned, only_visible);
Expand Down
1 change: 1 addition & 0 deletions Unreal/Plugins/AirSim/Source/WorldSimApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class WorldSimApi : public msr::airlib::WorldSimApiBase
virtual void setWeatherParameter(WeatherParameter param, float val);

virtual std::vector<std::string> listInstanceSegmentationObjects() const override;
virtual std::vector<Vector3r> getInstanceSegmentationColorMap() const override;
virtual std::vector<Pose> listInstanceSegmentationPoses(bool ned = true, bool only_visible = false) const override;

virtual bool setSegmentationObjectID(const std::string& mesh_name, int object_id, bool is_name_regex = false) override;
Expand Down
8 changes: 4 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ set +x

echo ""
echo ""
echo "=================================================================="
echo " AirSim plugin is built! Here's how to build Unreal project."
echo "=================================================================="
echo "==============================="
echo " Cosys-AirSim plugin is built!."
echo "==============================="
echo ""
echo "For further info see:"
echo "For further info see for installation see:"
echo "https://cosysgit.uantwerpen.be/sensorsimulation/airsim/-/tree/mastermaster/docs/install_linux.md"
echo "=================================================================="

Expand Down
6 changes: 3 additions & 3 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,6 @@ popd >/dev/null

set +x
echo ""
echo "************************************"
echo "AirSim setup completed successfully!"
echo "************************************"
echo "******************************************"
echo "Cosys-AirSim setup completed successfully!"
echo "******************************************"

0 comments on commit 3d16d77

Please sign in to comment.