Skip to content

Commit

Permalink
Merge pull request #814 from aburgm/turn-off-segmentation
Browse files Browse the repository at this point in the history
Allow to unset segmentation object ID
  • Loading branch information
sytelus authored Feb 14, 2018
2 parents c86c341 + 389de38 commit 2e45a50
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
33 changes: 27 additions & 6 deletions Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,45 @@ void UAirBlueprintLib::InitializeObjectStencilID(T* mesh, bool ignore_existing)
template<typename T>
void UAirBlueprintLib::SetObjectStencilID(T* mesh, int object_id)
{
mesh->SetCustomDepthStencilValue(object_id);
mesh->SetRenderCustomDepth(true);
if (object_id < 0)
{
mesh->SetRenderCustomDepth(false);
}
else
{
mesh->SetCustomDepthStencilValue(object_id);
mesh->SetRenderCustomDepth(true);
}
//mesh->SetVisibility(false);
//mesh->SetVisibility(true);
}

void UAirBlueprintLib::SetObjectStencilID(ALandscapeProxy* mesh, int object_id)
{
mesh->CustomDepthStencilValue = object_id;
mesh->bRenderCustomDepth = true;
if (object_id < 0)
{
mesh->bRenderCustomDepth = false;
}
else
{
mesh->CustomDepthStencilValue = object_id;
mesh->bRenderCustomDepth = true;
}

// Explicitly set the custom depth state on the components so the
// render state is marked dirty and the update actually takes effect
// immediately.
for (ULandscapeComponent* comp : mesh->LandscapeComponents)
{
comp->SetCustomDepthStencilValue(object_id);
comp->SetRenderCustomDepth(true);
if (object_id < 0)
{
comp->SetRenderCustomDepth(false);
}
else
{
comp->SetCustomDepthStencilValue(object_id);
comp->SetRenderCustomDepth(true);
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion docs/image_apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ The return value is boolean type that lets you know if the mesh was found.
Notice that typical Unreal environment like Blocks usually have many other meshes that comprises of same object, for example, "Ground_2", "Ground_3" and so on. As it is tedious to set object ID for all of these meshes, AirSim also supports regular expressions. For example, below code sets all meshes which have names starting with "ground" (ignoring case) to 21 with just one line:

```
success = client.simSetSegmentationObjectID("ground[\w]*", 22, True);
success = client.simSetSegmentationObjectID("ground[\w]*", 21, True);
```

The return value is true if at least one mesh was found using regular expression matching.
Expand All @@ -229,6 +229,9 @@ print(np.unique(img_rgba[:,:,2], return_counts=True)) #blue

A complete ready-to-run example can be found in [segmentation.py](https://github.com/Microsoft/AirSim/blob/master/PythonClient/segmentation.py).

#### Unsetting object ID
An object's ID can be set to -1 to make it not show up on the segmentation image.

#### How to Find Mesh Names?
To get desired ground truth segmentation you will need to know names of the meshes in your Unreal environment that you are interested in. To do this, you will need to open up Unreal Environment in Unreal Editor and then inspect the names of the meshes you are interested in the World Outliner. For example, below we see the meshe names for he ground in Blocks environment in right panel in the editor:

Expand Down

0 comments on commit 2e45a50

Please sign in to comment.