System for setting sensor attributes
This commit is contained in:
parent
8cfee9696d
commit
fb68143559
|
@ -7,6 +7,7 @@
|
|||
#include "Carla.h"
|
||||
#include "Carla/Actor/ActorBlueprintFunctionLibrary.h"
|
||||
|
||||
#include "Carla/Sensor/SceneCaptureSensor.h"
|
||||
#include "Carla/Util/ScopedStack.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -186,17 +187,19 @@ bool UActorBlueprintFunctionLibrary::CheckActorDefinitions(const TArray<FActorDe
|
|||
/// ============================================================================
|
||||
|
||||
FActorDefinition UActorBlueprintFunctionLibrary::MakeCameraDefinition(
|
||||
const FString &Id)
|
||||
const FString &Id,
|
||||
const bool bEnableModifyingPostProcessEffects)
|
||||
{
|
||||
FActorDefinition Definition;
|
||||
bool Success;
|
||||
MakeCameraDefinition(Id, Success, Definition);
|
||||
MakeCameraDefinition(Id, bEnableModifyingPostProcessEffects, Success, Definition);
|
||||
check(Success);
|
||||
return Definition;
|
||||
}
|
||||
|
||||
void UActorBlueprintFunctionLibrary::MakeCameraDefinition(
|
||||
const FString &Id,
|
||||
const bool bEnableModifyingPostProcessEffects,
|
||||
bool &Success,
|
||||
FActorDefinition &Definition)
|
||||
{
|
||||
|
@ -221,6 +224,17 @@ void UActorBlueprintFunctionLibrary::MakeCameraDefinition(
|
|||
ResY.bRestrictToRecommended = false;
|
||||
|
||||
Definition.Variations = {ResX, ResY, FOV};
|
||||
|
||||
if (bEnableModifyingPostProcessEffects)
|
||||
{
|
||||
FActorVariation PostProccess;
|
||||
PostProccess.Id = TEXT("enable_postprocess_effects");
|
||||
PostProccess.Type = EActorAttributeType::Bool;
|
||||
PostProccess.RecommendedValues = { TEXT("true") };
|
||||
PostProccess.bRestrictToRecommended = false;
|
||||
Definition.Variations.Add(PostProccess);
|
||||
}
|
||||
|
||||
Success = CheckActorDefinition(Definition);
|
||||
}
|
||||
|
||||
|
@ -410,3 +424,42 @@ FColor UActorBlueprintFunctionLibrary::RetrieveActorAttributeToColor(
|
|||
ActorAttributeToColor(Attributes[Id], Default) :
|
||||
Default;
|
||||
}
|
||||
|
||||
/// ============================================================================
|
||||
/// -- Helpers to set Actors ---------------------------------------------------
|
||||
/// ============================================================================
|
||||
|
||||
// Here we do different checks when we are in editor, because we don't want the
|
||||
// editor crashing while people is testing new actor definitions.
|
||||
#if WITH_EDITOR
|
||||
# define CARLA_ABFL_CHECK_ACTOR(ActorPtr) \
|
||||
if ((ActorPtr == nullptr) || ActorPtr->IsPendingKill()) \
|
||||
{ \
|
||||
UE_LOG(LogCarla, Error, TEXT("Cannot set empty actor!")); \
|
||||
return; \
|
||||
}
|
||||
#else
|
||||
# define CARLA_ABFL_CHECK_ACTOR(ActorPtr) \
|
||||
check((ActorPtr != nullptr) && !ActorPtr->IsPendingKill());
|
||||
#endif // WITH_EDITOR
|
||||
|
||||
void UActorBlueprintFunctionLibrary::SetActor(
|
||||
const FActorDescription &Description,
|
||||
ASceneCaptureSensor *Camera)
|
||||
{
|
||||
CARLA_ABFL_CHECK_ACTOR(Camera);
|
||||
Camera->SetImageSize(
|
||||
RetrieveActorAttributeToInt("image_size_x", Description.Variations, 800),
|
||||
RetrieveActorAttributeToInt("image_size_y", Description.Variations, 600));
|
||||
Camera->SetFOVAngle(
|
||||
RetrieveActorAttributeToFloat("fov", Description.Variations, 90.0f));
|
||||
if (Description.Variations.Contains("enable_postprocess_effects"))
|
||||
{
|
||||
Camera->EnablePostProcessingEffects(
|
||||
ActorAttributeToBool(
|
||||
Description.Variations["enable_postprocess_effects"],
|
||||
true));
|
||||
}
|
||||
}
|
||||
|
||||
#undef CARLA_ABFL_CHECK_ACTOR
|
||||
|
|
|
@ -7,12 +7,15 @@
|
|||
#pragma once
|
||||
|
||||
#include "Carla/Actor/ActorDefinition.h"
|
||||
#include "Carla/Actor/ActorDescription.h"
|
||||
#include "Carla/Vehicle/CarlaWheeledVehicle.h"
|
||||
|
||||
#include "Kismet/BlueprintFunctionLibrary.h"
|
||||
|
||||
#include "ActorBlueprintFunctionLibrary.generated.h"
|
||||
|
||||
class ASceneCaptureSensor;
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct CARLA_API FVehicleParameters
|
||||
{
|
||||
|
@ -61,11 +64,14 @@ public:
|
|||
/// ==========================================================================
|
||||
/// @{
|
||||
|
||||
static FActorDefinition MakeCameraDefinition(const FString &Id);
|
||||
static FActorDefinition MakeCameraDefinition(
|
||||
const FString &Id,
|
||||
bool bEnableModifyingPostProcessEffects = false);
|
||||
|
||||
UFUNCTION(Category = "Carla Actor", BlueprintCallable)
|
||||
static void MakeCameraDefinition(
|
||||
const FString &Id,
|
||||
bool bEnableModifyingPostProcessEffects,
|
||||
bool &Success,
|
||||
FActorDefinition &Definition);
|
||||
|
||||
|
@ -131,6 +137,15 @@ public:
|
|||
const TMap<FString, FActorAttribute> &Attributes,
|
||||
const FColor &Default);
|
||||
|
||||
/// @}
|
||||
/// ==========================================================================
|
||||
/// @name Helpers to set Actors
|
||||
/// ==========================================================================
|
||||
/// @{
|
||||
|
||||
UFUNCTION(Category = "Carla Actor", BlueprintCallable)
|
||||
static void SetActor(const FActorDescription &Description, ASceneCaptureSensor *Camera);
|
||||
|
||||
/// @}
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#include "Carla.h"
|
||||
#include "Carla/Sensor/DepthCamera.h"
|
||||
|
||||
#include "Carla/Sensor/PixelReader.h"
|
||||
|
||||
FActorDefinition ADepthCamera::GetSensorDefinition()
|
||||
{
|
||||
return UActorBlueprintFunctionLibrary::MakeCameraDefinition(TEXT("depth_camera"));
|
||||
}
|
||||
|
||||
ADepthCamera::ADepthCamera(const FObjectInitializer &ObjectInitializer)
|
||||
: Super(ObjectInitializer)
|
||||
{
|
||||
LoadPostProcessingMaterial(
|
||||
#if PLATFORM_LINUX
|
||||
TEXT("Material'/Carla/PostProcessingMaterials/DepthEffectMaterial_GLSL.DepthEffectMaterial_GLSL'")
|
||||
#else
|
||||
TEXT("Material'/Carla/PostProcessingMaterials/DepthEffectMaterial.DepthEffectMaterial'")
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
void ADepthCamera::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
FPixelReader::SendPixelsInRenderThread(*this);
|
||||
}
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Carla/Sensor/PixelReader.h"
|
||||
#include "Carla/Sensor/ShaderBasedSensor.h"
|
||||
|
||||
#include "DepthCamera.generated.h"
|
||||
|
@ -18,28 +17,11 @@ class CARLA_API ADepthCamera : public AShaderBasedSensor
|
|||
|
||||
public:
|
||||
|
||||
static FActorDefinition GetSensorDefinition()
|
||||
{
|
||||
return UActorBlueprintFunctionLibrary::MakeCameraDefinition(TEXT("depth_camera"));
|
||||
}
|
||||
static FActorDefinition GetSensorDefinition();
|
||||
|
||||
ADepthCamera(const FObjectInitializer &ObjectInitializer)
|
||||
: Super(ObjectInitializer)
|
||||
{
|
||||
LoadPostProcessingMaterial(
|
||||
#if PLATFORM_LINUX
|
||||
TEXT("Material'/Carla/PostProcessingMaterials/DepthEffectMaterial_GLSL.DepthEffectMaterial_GLSL'")
|
||||
#else
|
||||
TEXT("Material'/Carla/PostProcessingMaterials/DepthEffectMaterial.DepthEffectMaterial'")
|
||||
#endif
|
||||
);
|
||||
}
|
||||
ADepthCamera(const FObjectInitializer &ObjectInitializer);
|
||||
|
||||
protected:
|
||||
|
||||
void Tick(float DeltaTime) override
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
FPixelReader::SendPixelsInRenderThread(*this);
|
||||
}
|
||||
void Tick(float DeltaTime) override;
|
||||
};
|
||||
|
|
|
@ -25,7 +25,7 @@ ARayTraceLidar::ARayTraceLidar(const FObjectInitializer& ObjectInitializer)
|
|||
RootComponent = MeshComp;
|
||||
}
|
||||
|
||||
void ARayTraceLidar::Set(const FLidarDescription &LidarDescription)
|
||||
void ARayTraceLidar::SetLidar(const FLidarDescription &LidarDescription)
|
||||
{
|
||||
Description = LidarDescription;
|
||||
LidarMeasurement = FLidarMeasurement(Description.Channels);
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
|
||||
ARayTraceLidar(const FObjectInitializer &ObjectInitializer);
|
||||
|
||||
void Set(const FLidarDescription &LidarDescription);
|
||||
void SetLidar(const FLidarDescription &LidarDescription);
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#include "Carla.h"
|
||||
#include "Carla/Sensor/SceneCaptureCamera.h"
|
||||
|
||||
FActorDefinition ASceneCaptureCamera::GetSensorDefinition()
|
||||
{
|
||||
constexpr bool bEnableModifyingPostProcessEffects = true;
|
||||
return UActorBlueprintFunctionLibrary::MakeCameraDefinition(
|
||||
TEXT("camera"),
|
||||
bEnableModifyingPostProcessEffects);
|
||||
}
|
||||
|
||||
void ASceneCaptureCamera::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
FPixelReader::SendPixelsInRenderThread(*this);
|
||||
}
|
|
@ -18,18 +18,9 @@ class CARLA_API ASceneCaptureCamera : public ASceneCaptureSensor
|
|||
|
||||
public:
|
||||
|
||||
static FActorDefinition GetSensorDefinition()
|
||||
{
|
||||
return UActorBlueprintFunctionLibrary::MakeCameraDefinition(TEXT("camera"));
|
||||
}
|
||||
|
||||
using ASceneCaptureSensor::EnablePostProcessingEffects;
|
||||
static FActorDefinition GetSensorDefinition();
|
||||
|
||||
protected:
|
||||
|
||||
void Tick(float DeltaTime) override
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
FPixelReader::SendPixelsInRenderThread(*this);
|
||||
}
|
||||
void Tick(float DeltaTime) override;
|
||||
};
|
||||
|
|
|
@ -75,6 +75,12 @@ ASceneCaptureSensor::ASceneCaptureSensor(const FObjectInitializer& ObjectInitial
|
|||
++SCENE_CAPTURE_COUNTER;
|
||||
}
|
||||
|
||||
void ASceneCaptureSensor::Set(const FActorDescription &Description)
|
||||
{
|
||||
Super::Set(Description);
|
||||
UActorBlueprintFunctionLibrary::SetActor(Description, this);
|
||||
}
|
||||
|
||||
void ASceneCaptureSensor::SetImageSize(uint32 InWidth, uint32 InHeight)
|
||||
{
|
||||
ImageWidth = InWidth;
|
||||
|
|
|
@ -34,6 +34,8 @@ public:
|
|||
|
||||
ASceneCaptureSensor(const FObjectInitializer &ObjectInitializer);
|
||||
|
||||
void Set(const FActorDescription &ActorDescription) override;
|
||||
|
||||
void SetImageSize(uint32 Width, uint32 Height);
|
||||
|
||||
uint32 GetImageWidth() const
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#include "Carla.h"
|
||||
#include "Carla/Sensor/SemanticSegmentationCamera.h"
|
||||
|
||||
#include "Carla/Sensor/PixelReader.h"
|
||||
|
||||
FActorDefinition ASemanticSegmentationCamera::GetSensorDefinition()
|
||||
{
|
||||
return UActorBlueprintFunctionLibrary::MakeCameraDefinition(TEXT("semseg_camera"));
|
||||
}
|
||||
|
||||
ASemanticSegmentationCamera::ASemanticSegmentationCamera(
|
||||
const FObjectInitializer &ObjectInitializer)
|
||||
: Super(ObjectInitializer)
|
||||
{
|
||||
LoadPostProcessingMaterial(
|
||||
TEXT("Material'/Carla/PostProcessingMaterials/GTMaterial.GTMaterial'"));
|
||||
}
|
||||
|
||||
void ASemanticSegmentationCamera::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
FPixelReader::SendPixelsInRenderThread(*this);
|
||||
}
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Carla/Sensor/PixelReader.h"
|
||||
#include "Carla/Sensor/ShaderBasedSensor.h"
|
||||
|
||||
#include "SemanticSegmentationCamera.generated.h"
|
||||
|
@ -18,22 +17,11 @@ class CARLA_API ASemanticSegmentationCamera : public AShaderBasedSensor
|
|||
|
||||
public:
|
||||
|
||||
static FActorDefinition GetSensorDefinition()
|
||||
{
|
||||
return UActorBlueprintFunctionLibrary::MakeCameraDefinition(TEXT("semseg_camera"));
|
||||
}
|
||||
static FActorDefinition GetSensorDefinition();
|
||||
|
||||
ASemanticSegmentationCamera(const FObjectInitializer &ObjectInitializer)
|
||||
: Super(ObjectInitializer)
|
||||
{
|
||||
LoadPostProcessingMaterial(TEXT("Material'/Carla/PostProcessingMaterials/GTMaterial.GTMaterial'"));
|
||||
}
|
||||
ASemanticSegmentationCamera(const FObjectInitializer &ObjectInitializer);
|
||||
|
||||
protected:
|
||||
|
||||
void Tick(float DeltaTime) override
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
FPixelReader::SendPixelsInRenderThread(*this);
|
||||
}
|
||||
void Tick(float DeltaTime) override;
|
||||
};
|
||||
|
|
|
@ -20,6 +20,8 @@ class CARLA_API ASensor : public AActor
|
|||
|
||||
public:
|
||||
|
||||
virtual void Set(const FActorDescription &) {}
|
||||
|
||||
/// @warning Do not change the stream after BeginPlay. It is not thread-safe.
|
||||
void SetDataStream(FDataStream InStream)
|
||||
{
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
#include "Carla.h"
|
||||
#include "Carla/Sensor/SensorFactory.h"
|
||||
|
||||
#include "Carla/Actor/ActorBlueprintFunctionLibrary.h"
|
||||
#include "Carla/Sensor/SceneCaptureCamera.h"
|
||||
#include "Carla/Sensor/Sensor.h"
|
||||
|
||||
#include <compiler/disable-ue4-macros.h>
|
||||
#include <carla/sensor/SensorRegistry.h>
|
||||
|
@ -59,27 +58,25 @@ FActorSpawnResult ASensorFactory::SpawnActor(
|
|||
const FTransform &Transform,
|
||||
const FActorDescription &Description)
|
||||
{
|
||||
FActorSpawnParameters Params;
|
||||
auto *World = GetWorld();
|
||||
if (World == nullptr)
|
||||
{
|
||||
UE_LOG(LogCarla, Error, TEXT("ASensorFactory: cannot spawn sensor into empty world."));
|
||||
return {};
|
||||
}
|
||||
/// @todo Here we may spawn something else than a scene capture.
|
||||
auto *Sensor = World->SpawnActorDeferred<ASceneCaptureSensor>(
|
||||
auto *Sensor = World->SpawnActorDeferred<ASensor>(
|
||||
Description.Class,
|
||||
Transform,
|
||||
this,
|
||||
nullptr,
|
||||
ESpawnActorCollisionHandlingMethod::AlwaysSpawn);
|
||||
if (Sensor != nullptr)
|
||||
if (Sensor == nullptr)
|
||||
{
|
||||
using ABFL = UActorBlueprintFunctionLibrary;
|
||||
Sensor->SetImageSize(
|
||||
ABFL::RetrieveActorAttributeToInt("image_size_x", Description.Variations, 800),
|
||||
ABFL::RetrieveActorAttributeToInt("image_size_y", Description.Variations, 600));
|
||||
Sensor->SetFOVAngle(
|
||||
ABFL::RetrieveActorAttributeToFloat("fov", Description.Variations, 90.0f));
|
||||
UE_LOG(LogCarla, Error, TEXT("ASensorFactory: spawn sensor failed."));
|
||||
}
|
||||
else
|
||||
{
|
||||
Sensor->Set(Description);
|
||||
}
|
||||
UGameplayStatics::FinishSpawningActor(Sensor, Transform);
|
||||
return FActorSpawnResult{Sensor};
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
|
||||
#include "SensorFactory.generated.h"
|
||||
|
||||
/// Object in charge of spawning sensors.
|
||||
/// Object in charge of spawning sensors. Automatically looks for all the
|
||||
/// sensors registered in carla::sensor::SensorRegistry.
|
||||
UCLASS()
|
||||
class CARLA_API ASensorFactory : public ACarlaActorFactory
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue