CARLA
Loading...
Searching...
No Matches
FPixelReader Class Reference

Utils for reading pixels from UTextureRenderTarget2D. More...

#include <PixelReader.h>

Public Types

using Payload = std::function<void(void *, uint32, uint32, uint32)>

Static Public Member Functions

static TUniquePtr< TImagePixelData< FColor > > DumpPixels (UTextureRenderTarget2D &RenderTarget)
 Dump the pixels in RenderTarget.
static TFuture< bool > SavePixelsToDisk (TUniquePtr< TImagePixelData< FColor > > PixelData, const FString &FilePath)
 Asynchronously save the pixels in PixelData to disk.
static TFuture< bool > SavePixelsToDisk (UTextureRenderTarget2D &RenderTarget, const FString &FilePath)
 Asynchronously save the pixels in RenderTarget to disk.
template<typename TSensor, typename TPixel>
static void SendPixelsInRenderThread (TSensor &Sensor, bool use16BitFormat=false, std::function< TArray< TPixel >(void *, uint32)> Conversor={})
 Convenience function to enqueue a render command that sends the pixels down the Sensor's data stream.
static bool WritePixelsToArray (UTextureRenderTarget2D &RenderTarget, TArray< FColor > &BitMap)
 Copy the pixels in RenderTarget into BitMap.
static void WritePixelsToBuffer (UTextureRenderTarget2D &RenderTarget, uint32 Offset, FRHICommandListImmediate &InRHICmdList, FPixelReader::Payload FuncForSending, FRHIGPUReadbackPoolPtr Pool=nullptr)
 Copy the pixels in RenderTarget into Buffer.

Detailed Description

Utils for reading pixels from UTextureRenderTarget2D.

Todo
This class only supports PF_R8G8B8A8 format.

Definition at line 41 of file PixelReader.h.

Member Typedef Documentation

◆ Payload

using FPixelReader::Payload = std::function<void(void *, uint32, uint32, uint32)>

Definition at line 45 of file PixelReader.h.

Member Function Documentation

◆ DumpPixels()

TUniquePtr< TImagePixelData< FColor > > FPixelReader::DumpPixels ( UTextureRenderTarget2D & RenderTarget)
static

Dump the pixels in RenderTarget.

Precondition
To be called from game-thread.

Definition at line 172 of file PixelReader.cpp.

References WritePixelsToArray().

Referenced by SavePixelsToDisk().

◆ SavePixelsToDisk() [1/2]

TFuture< bool > FPixelReader::SavePixelsToDisk ( TUniquePtr< TImagePixelData< FColor > > PixelData,
const FString & FilePath )
static

Asynchronously save the pixels in PixelData to disk.

Precondition
To be called from game-thread.

Definition at line 193 of file PixelReader.cpp.

◆ SavePixelsToDisk() [2/2]

TFuture< bool > FPixelReader::SavePixelsToDisk ( UTextureRenderTarget2D & RenderTarget,
const FString & FilePath )
static

Asynchronously save the pixels in RenderTarget to disk.

Precondition
To be called from game-thread.

Definition at line 186 of file PixelReader.cpp.

References DumpPixels(), and SavePixelsToDisk().

Referenced by ASceneCaptureSensor_WideAngleLens::CaptureSceneExtended(), URoadMap::SaveAsPNG(), ASceneCaptureSensor::SaveCaptureToDisk(), and SavePixelsToDisk().

◆ SendPixelsInRenderThread()

template<typename TSensor, typename TPixel>
void FPixelReader::SendPixelsInRenderThread ( TSensor & Sensor,
bool use16BitFormat = false,
std::function< TArray< TPixel >(void *, uint32)> Conversor = {} )
static

Convenience function to enqueue a render command that sends the pixels down the Sensor's data stream.

It expects a sensor derived from ASceneCaptureSensor or compatible.

Note that the serializer needs to define a "header_offset" that it's allocated in front of the buffer.

Precondition
To be called from game-thread.

Blocks until the render thread has finished all it's tasks.

Todo
Can we make sure the sensor is not going to be destroyed?

Definition at line 104 of file PixelReader.h.

References carla::BufferView::CreateFrom(), carla::streaming::detail::token_type::get_stream_id(), FCarlaEngine::GetFrameCounter(), carla::ros2::ROS2::GetInstance(), SendPixelsInRenderThread(), carla::sensor::CompositeSerializer< std::pair< ACollisionSensor *, s11n::CollisionEventSerializer >, std::pair< ADepthCamera *, s11n::ImageSerializer >, std::pair< ANormalsCamera *, s11n::NormalsImageSerializer >, std::pair< ADVSCamera *, s11n::DVSEventArraySerializer >, std::pair< AGnssSensor *, s11n::GnssSerializer >, std::pair< AInertialMeasurementUnit *, s11n::IMUSerializer >, std::pair< ALaneInvasionSensor *, s11n::NoopSerializer >, std::pair< AObstacleDetectionSensor *, s11n::ObstacleDetectionEventSerializer >, std::pair< AOpticalFlowCamera *, s11n::OpticalFlowImageSerializer >, std::pair< ARadar *, s11n::RadarSerializer >, std::pair< ARayCastSemanticLidar *, s11n::SemanticLidarSerializer >, std::pair< ARayCastLidar *, s11n::LidarSerializer >, std::pair< ARssSensor *, s11n::NoopSerializer >, std::pair< ASceneCaptureCamera *, s11n::ImageSerializer >, std::pair< ASceneCaptureCamera_RayTracedLens *, s11n::ImageSerializer >, std::pair< ASemanticSegmentationCamera *, s11n::ImageSerializer >, std::pair< AInstanceSegmentationCamera *, s11n::ImageSerializer >, std::pair< FWorldObserver *, s11n::EpisodeStateSerializer >, std::pair< ASceneCaptureCamera_WideAngleLens *, s11n::ImageSerializer >, std::pair< ADepthCamera_WideAngleLens *, s11n::ImageSerializer >, std::pair< AInstanceSegmentationCamera_WideAngleLens *, s11n::ImageSerializer >, std::pair< ASemanticSegmentationCamera_WideAngleLens *, s11n::ImageSerializer >, std::pair< FCameraGBufferUint8 *, s11n::GBufferUint8Serializer >, std::pair< FCameraGBufferFloat *, s11n::GBufferFloatSerializer >, std::pair< AHSSLidar *, s11n::LidarSerializer >, std::pair< AV2XSensor *, s11n::CAMDataSerializer >, std::pair< ACustomV2XSensor *, s11n::CustomV2XDataSerializer >, std::pair< AVehicleStatusSensor *, s11n::VehicleStatusSerializer >, std::pair< AAutowareGnssSensor *, s11n::GnssSerializer >, std::pair< ASceneCaptureCamera_RayTracedLensDistance *, s11n::DistanceImageSerializer >, std::pair< ASceneCaptureCamera_RayTracedLensInstance *, s11n::ImageSerializer > >::Serialize(), and WritePixelsToBuffer().

Referenced by SendPixelsInRenderThread().

◆ WritePixelsToArray()

bool FPixelReader::WritePixelsToArray ( UTextureRenderTarget2D & RenderTarget,
TArray< FColor > & BitMap )
static

Copy the pixels in RenderTarget into BitMap.

Precondition
To be called from game-thread.

Definition at line 155 of file PixelReader.cpp.

Referenced by DumpPixels(), and ASceneCaptureSensor::ReadPixels().

◆ WritePixelsToBuffer()

void FPixelReader::WritePixelsToBuffer ( UTextureRenderTarget2D & RenderTarget,
uint32 Offset,
FRHICommandListImmediate & InRHICmdList,
FPixelReader::Payload FuncForSending,
FRHIGPUReadbackPoolPtr Pool = nullptr )
static

Copy the pixels in RenderTarget into Buffer.

Precondition
To be called from render-thread.
Parameters
PoolOptional per-sensor readback pool; when null falls back to a per-call alloc.

Definition at line 36 of file PixelReader.cpp.

References CVarPixelReaderLegacyVulkanFenceFlush().

Referenced by SendPixelsInRenderThread().


The documentation for this class was generated from the following files: