CARLA
InstanceSegmentationCamera.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #include "Carla.h"
10 
12 
13 #include "Components/SceneCaptureComponent2D.h"
14 
16 {
17  return UActorBlueprintFunctionLibrary::MakeCameraDefinition(TEXT("instance_segmentation"));
18 }
19 
21  const FObjectInitializer &ObjectInitializer)
22  : Super(ObjectInitializer)
23 {
24  AddPostProcessingMaterial(TEXT("Material'/Carla/PostProcessingMaterials/PhysicLensDistortion.PhysicLensDistortion'"));
25  // TODO: Setup OnActorSpawnHandler so we can refresh components
26  // World->AddOnActorSpawnedHandler(FOnActorSpawned::FDelegate::CreateRaw(this, &AInstanceSegmentationCamera::OnActorSpawned));
27 }
28 
29 void AInstanceSegmentationCamera::SetUpSceneCaptureComponent(USceneCaptureComponent2D &SceneCapture)
30 {
31  Super::SetUpSceneCaptureComponent(SceneCapture);
32 
33  ApplyViewMode(VMI_Unlit, true, SceneCapture.ShowFlags);
34 
35  SceneCapture.ShowFlags.SetNotDrawTaggedComponents(false); // TaggedComponent detects this and sets view relevance for proxy material
36 
37  SceneCapture.ShowFlags.SetAtmosphere(false);
38 
39  SceneCapture.PrimitiveRenderMode = ESceneCapturePrimitiveRenderMode::PRM_UseShowOnlyList;
40 
41  TArray<UObject *> TaggedComponents;
42  GetObjectsOfClass(UTaggedComponent::StaticClass(), TaggedComponents, false, EObjectFlags::RF_ClassDefaultObject, EInternalObjectFlags::AllFlags);
43 
44  TArray<UPrimitiveComponent *> ShowOnlyComponents;
45  for (UObject *Object : TaggedComponents) {
46  UPrimitiveComponent *Component = Cast<UPrimitiveComponent>(Object);
47  SceneCapture.ShowOnlyComponents.Emplace(Component);
48  }
49 }
50 
51 void AInstanceSegmentationCamera::PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
52 {
53  TRACE_CPUPROFILER_EVENT_SCOPE(AInstanceSegmentationCamera::PostPhysTick);
54 
55  USceneCaptureComponent2D* SceneCapture = GetCaptureComponent2D();
56  TArray<UObject *> TaggedComponents;
57  GetObjectsOfClass(UTaggedComponent::StaticClass(), TaggedComponents, false, EObjectFlags::RF_ClassDefaultObject, EInternalObjectFlags::AllFlags);
58 
59  SceneCapture->ClearShowOnlyComponents();
60  for (UObject *Object : TaggedComponents) {
61  UPrimitiveComponent *Component = Cast<UPrimitiveComponent>(Object);
62  SceneCapture->ShowOnlyComponents.Emplace(Component);
63  }
64 
65  FPixelReader::SendPixelsInRenderThread<AInstanceSegmentationCamera, FColor>(*this);
66 
67 }
AInstanceSegmentationCamera(const FObjectInitializer &ObjectInitializer)
void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds) override
bool AddPostProcessingMaterial(const FString &Path)
Load the UMaterialInstanceDynamic at the given Path and append it to the list of shaders with Weight...
A definition of a Carla Actor with all the variation and attributes.
USceneCaptureComponent2D * GetCaptureComponent2D()
static FActorDefinition GetSensorDefinition()
void SetUpSceneCaptureComponent(USceneCaptureComponent2D &SceneCapture) override
static FActorDefinition MakeCameraDefinition(const FString &Id, bool bEnableModifyingPostProcessEffects=false)