Skip to content

Commit

Permalink
Add MeshNamingMethod segmentation setting
Browse files Browse the repository at this point in the history
This allows to refer to meshes by their static mesh name instead of the
owner name in the segmentation APIs and the initial object ID assignments.
  • Loading branch information
aburgm committed Feb 21, 2018
1 parent 8554165 commit e08497f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
13 changes: 13 additions & 0 deletions AirLib/include/common/AirSimSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,13 @@ struct AirSimSettings {
None, CommonObjectsRandomIDs
};

enum class MeshNamingMethodType {
OwnerName, StaticMeshName
};

InitMethodType init_method = InitMethodType::CommonObjectsRandomIDs;
bool override_existing = false;
MeshNamingMethodType mesh_naming_method = MeshNamingMethodType::OwnerName;
};

private: //fields
Expand Down Expand Up @@ -398,6 +403,14 @@ struct AirSimSettings {
throw std::invalid_argument(std::string("SegmentationSettings init_method has invalid value in settings ") + init_method);

segmentation_settings.override_existing = json_parent.getBool("OverrideExisting", false);

std::string mesh_naming_method = Utils::toLower(json_parent.getString("MeshNamingMethod", ""));
if (mesh_naming_method == "" || mesh_naming_method == "ownername")
segmentation_settings.mesh_naming_method = SegmentationSettings::MeshNamingMethodType::OwnerName;
else if (mesh_naming_method == "staticmeshname")
segmentation_settings.mesh_naming_method = SegmentationSettings::MeshNamingMethodType::StaticMeshName;
else
throw std::invalid_argument(std::string("SegmentationSettings MeshNamingMethod has invalid value in settings ") + mesh_naming_method);
}
}

Expand Down
22 changes: 18 additions & 4 deletions Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Components/StaticMeshComponent.h"
#include "EngineUtils.h"
#include "Runtime/Landscape/Classes/LandscapeComponent.h"
#include "Runtime/Engine/Classes/Engine/StaticMesh.h"
#include "UObjectIterator.h"
//#include "Runtime/Foliage/Public/FoliageType.h"
#include "Kismet/KismetStringLibrary.h"
Expand All @@ -26,6 +27,8 @@ parameters -> camel_case


bool UAirBlueprintLib::log_messages_hidden = false;
msr::airlib::AirSimSettings::SegmentationSettings::MeshNamingMethodType UAirBlueprintLib::mesh_naming_method =
msr::airlib::AirSimSettings::SegmentationSettings::MeshNamingMethodType::OwnerName;

void UAirBlueprintLib::LogMessageString(const std::string &prefix, const std::string &suffix, LogDebugLevel level, float persist_sec)
{
Expand Down Expand Up @@ -212,10 +215,21 @@ void UAirBlueprintLib::SetObjectStencilID(ALandscapeProxy* mesh, int object_id)
template<class T>
std::string UAirBlueprintLib::GetMeshName(T* mesh)
{
if (mesh->GetOwner())
return std::string(TCHAR_TO_UTF8(*(mesh->GetOwner()->GetName())));
else
return ""; // std::string(TCHAR_TO_UTF8(*(UKismetSystemLibrary::GetDisplayName(mesh))));
switch(mesh_naming_method)
{
case msr::airlib::AirSimSettings::SegmentationSettings::MeshNamingMethodType::OwnerName:
if (mesh->GetOwner())
return std::string(TCHAR_TO_UTF8(*(mesh->GetOwner()->GetName())));
else
return ""; // std::string(TCHAR_TO_UTF8(*(UKismetSystemLibrary::GetDisplayName(mesh))));
case msr::airlib::AirSimSettings::SegmentationSettings::MeshNamingMethodType::StaticMeshName:
if (mesh->GetStaticMesh())
return std::string(TCHAR_TO_UTF8(*(mesh->GetStaticMesh()->GetName())));
else
return "";
default:
return "";
}
}

std::string UAirBlueprintLib::GetMeshName(ALandscapeProxy* mesh)
Expand Down
6 changes: 6 additions & 0 deletions Unreal/Plugins/AirSim/Source/AirBlueprintLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Kismet/KismetMathLibrary.h"
#include "Components/MeshComponent.h"
#include "LandscapeProxy.h"
#include "common/AirSimSettings.hpp"
#include "AirBlueprintLib.generated.h"


Expand Down Expand Up @@ -91,6 +92,10 @@ class UAirBlueprintLib : public UBlueprintFunctionLibrary
{
log_messages_hidden = is_hidden;
}
static void SetMeshNamingMethod(msr::airlib::AirSimSettings::SegmentationSettings::MeshNamingMethodType method)
{
mesh_naming_method = method;
}

private:
template<typename T>
Expand All @@ -108,5 +113,6 @@ class UAirBlueprintLib : public UBlueprintFunctionLibrary

private:
static bool log_messages_hidden;
static msr::airlib::AirSimSettings::SegmentationSettings::MeshNamingMethodType mesh_naming_method;
};

2 changes: 2 additions & 0 deletions Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ void ASimModeBase::BeginPlay()

void ASimModeBase::setStencilIDs()
{
UAirBlueprintLib::SetMeshNamingMethod(getSettings().segmentation_settings.mesh_naming_method);

if (getSettings().segmentation_settings.init_method ==
AirSimSettings::SegmentationSettings::InitMethodType::CommonObjectsRandomIDs) {

Expand Down
2 changes: 2 additions & 0 deletions docs/image_apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ If you don't know how to open Unreal Environment in Unreal Editor then try follo

Once you decide on the meshes you are interested, note down their names and use above API to set their object IDs.

Alternatively, the `MeshNamingMethod` can be switched to "StaticMeshName" in the [settings](settings.md). In this case, the static mesh name as shown in the content browser in the Unreal Editor is used to refer to meshes. Note that it is not possible to tell individual instances of the same static mesh apart this way, but the names are often more intuitive.

#### Changing Colors for Object IDs
At present color for each object ID is fixed as in [this pallet](../Unreal/Plugins/AirSim/Content/HUDAssets/seg_color_pallet.png). We will be adding ability to change colors for object IDs to desired values shortly. In the mean time it might be easier just to open the segmentation image in some image editor and get the RGB values you are interested in.

Expand Down
3 changes: 3 additions & 0 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ Below are complete list of settings available along with their default values. I
},
"ApiServerPort": 41451
},
"SegmentationSettings": {
"MeshNamingMethod": "OwnerName"
},
"PX4": {
"FirmwareName": "PX4",
"LogViewerHostIp": "127.0.0.1",
Expand Down

0 comments on commit e08497f

Please sign in to comment.