Add debugging methods to scene capture sensor

This commit is contained in:
nsubiron 2018-09-29 14:24:15 +02:00
parent 5e18418e14
commit bf88697374
2 changed files with 53 additions and 2 deletions

View File

@ -7,6 +7,12 @@
#include "Carla.h"
#include "Carla/Sensor/SceneCaptureSensor.h"
#include "Components/DrawFrustumComponent.h"
#include "Components/SceneCaptureComponent2D.h"
#include "Components/StaticMeshComponent.h"
#include "Engine/TextureRenderTarget2D.h"
#include "HighResScreenshot.h"
static auto SCENE_CAPTURE_COUNTER = 0u;
// =============================================================================
@ -87,6 +93,41 @@ float ASceneCaptureSensor::GetFOVAngle() const
return CaptureComponent2D->FOVAngle;
}
bool ASceneCaptureSensor::ReadPixels_GameThread(TArray<FColor> &BitMap) const
{
check(IsInGameThread());
if (!CaptureRenderTarget)
{
UE_LOG(LogCarla, Error, TEXT("SceneCaptureCamera: Missing render target"));
return false;
}
FTextureRenderTargetResource *RTResource =
CaptureRenderTarget->GameThread_GetRenderTargetResource();
if (RTResource == nullptr)
{
UE_LOG(LogCarla, Error, TEXT("SceneCaptureCamera: Missing render target"));
return false;
}
FReadSurfaceDataFlags ReadPixelFlags(RCM_UNorm);
ReadPixelFlags.SetLinearToGamma(true);
return RTResource->ReadPixels(BitMap, ReadPixelFlags);
}
bool ASceneCaptureSensor::SaveCaptureToDisk(const FString &FilePath) const
{
TArray<FColor> OutBMP;
if (!ReadPixels_GameThread(OutBMP)) {
return false;
}
for (FColor &color : OutBMP) {
color.A = 255u;
}
const FIntPoint DestSize(GetImageWidth(), GetImageHeight());
FString ResultPath;
FHighResScreenshotConfig &HighResScreenshotConfig = GetHighResScreenshotConfig();
return HighResScreenshotConfig.SaveImage(FilePath, OutBMP, DestSize, &ResultPath);
}
void ASceneCaptureSensor::PostActorCreated()
{
Super::PostActorCreated();

View File

@ -22,14 +22,14 @@ class UTextureRenderTarget2D;
/// SetUpSceneCaptureComponent function.
///
/// @warning All the setters should be called before BeginPlay.
UCLASS()
UCLASS(Abstract)
class CARLA_API ASceneCaptureSensor : public ASensor
{
GENERATED_BODY()
public:
ASceneCaptureSensor(const FObjectInitializer& ObjectInitializer);
ASceneCaptureSensor(const FObjectInitializer &ObjectInitializer);
void SetImageSize(uint32 Width, uint32 Height);
@ -43,11 +43,15 @@ public:
return ImageHeight;
}
protected:
void EnablePostProcessingEffects(bool Enable = true)
{
bEnablePostProcessingEffects = Enable;
}
public:
bool ArePostProcessingEffectsEnabled() const
{
return bEnablePostProcessingEffects;
@ -57,6 +61,12 @@ public:
float GetFOVAngle() const;
/// Use only for debugging purposes.
bool ReadPixels_GameThread(TArray<FColor> &BitMap) const;
/// Use only for debugging purposes.
bool SaveCaptureToDisk(const FString &FilePath) const;
protected:
virtual void PostActorCreated() override;