24#include "RayCastSemanticLidar.generated.h"
45 virtual void SimulateLidar(
const float DeltaTime,
bool bLockPhysics =
true);
47 virtual void SendData(
const float DeltaTime);
55 virtual void EndPlay(EEndPlayReason::Type EndPlayReason)
override;
61 bool ShootLaser(
const float VerticalAngle,
float HorizontalAngle, FHitResult &HitResult, FCollisionQueryParams& TraceParams,
62 const FVector &LidarBodyLocation,
const FRotator &LidarBodyRotation)
const;
65 virtual void PreprocessRays(uint32_t Channels, uint32_t MaxPointsPerChannel);
71 virtual void WriteDetectionAsync(uint32_t Channel,
const FHitResult &HitInfo,
const FTransform &InverseSensorTransform,
const FVector &SensorLocation);
74 virtual void ResetDetections(uint32_t Channels, uint32_t MaxPointsPerChannel);
80 template <
typename DetectionT>
81 static void ResetChannelDetections(std::vector<std::vector<DetectionT>> &Detections, uint32_t Channels, uint32_t MaxPointsPerChannel)
83 Detections.resize(Channels);
84 for (
auto &ChannelDetections : Detections)
86 ChannelDetections.clear();
87 ChannelDetections.reserve(MaxPointsPerChannel);
93 template <
typename DetectionT,
typename L
idarDataT,
typename PostprocessT>
95 std::vector<std::vector<DetectionT>> &Detections,
96 std::vector<uint32_t> &OutPointsPerChannel,
99 PostprocessT &&Postprocess)
101 for (uint32_t Channel = 0u; Channel < Channels; ++Channel)
103 auto &ChannelDetections = Detections[Channel];
105 for (DetectionT &Detection : ChannelDetections)
107 if (Postprocess(Detection))
109 ChannelDetections[Kept++] = Detection;
112 ChannelDetections.resize(Kept);
113 OutPointsPerChannel[Channel] =
static_cast<uint32_t
>(Kept);
117 for (uint32_t Channel = 0u; Channel < Channels; ++Channel)
125 template <
typename DetectionT>
127 const std::vector<std::vector<DetectionT>> &Detections,
128 const std::vector<uint32_t> &InPointsPerChannel,
129 TArray<float> &PointCloud)
131 static_assert(
sizeof(DetectionT) ==
sizeof(float) * 4,
"Detection must be 4 packed floats");
132 static_assert(std::is_trivially_copyable_v<DetectionT>,
"Detection must be trivially copyable");
134 const uint32_t TotalPoints = std::accumulate(InPointsPerChannel.begin(), InPointsPerChannel.end(), 0u);
135 PointCloud.SetNumUninitialized(
static_cast<int32
>(TotalPoints * 4));
137 float *Dest = PointCloud.GetData();
138 for (
const auto &ChannelDetections : Detections)
140 if (ChannelDetections.empty())
144 FMemory::Memcpy(Dest, ChannelDetections.data(), ChannelDetections.size() *
sizeof(DetectionT));
145 Dest += ChannelDetections.size() * 4;
149 UPROPERTY(EditAnywhere)
carla::sensor::data::SemanticLidarData FSemanticLidarData
void GetMirrorState(carla::multigpu::SensorState &State) const override
Multi-GPU: the runtime state this sensor starts its next tick from (noise generator,...
static FActorDefinition GetSensorDefinition()
std::vector< uint32_t > PointsPerChannel
void SetMirrorState(const carla::multigpu::SensorState &State) override
virtual void SendData(const float DeltaTime)
virtual void BeginPlay() override
virtual void ComputeAndSaveDetections(const FTransform &SensorTransform)
Copies the per-channel detections into the LidarData structure.
static void CompactAndWriteDetections(std::vector< std::vector< DetectionT > > &Detections, std::vector< uint32_t > &OutPointsPerChannel, uint32_t Channels, LidarDataT &LidarData, PostprocessT &&Postprocess)
Post-processes the detections channel by channel, drops the rejected ones and writes the rest to Lida...
virtual void PreprocessRays(uint32_t Channels, uint32_t MaxPointsPerChannel)
Method that allow to preprocess if the rays will be traced.
virtual void SimulateLidar(const float DeltaTime, bool bLockPhysics=true)
void CreateLasers()
Creates a Laser for each channel.
void ComputeRawDetection(const FHitResult &HitInfo, const FTransform &InverseSensorTransform, const FVector &SensorLocation, FSemanticDetection &Detection) const
Compute all raw detection information.
static void ResetChannelDetections(std::vector< std::vector< DetectionT > > &Detections, uint32_t Channels, uint32_t MaxPointsPerChannel)
Clears every channel buffer and reserves room for a full scan.
TArray< float > LaserAngles
carla::sensor::data::SemanticLidarDetection FSemanticDetection
virtual void WriteDetectionAsync(uint32_t Channel, const FHitResult &HitInfo, const FTransform &InverseSensorTransform, const FVector &SensorLocation)
Computes the detection of a hit inside the raycast ParallelFor.
virtual void EndPlay(EEndPlayReason::Type EndPlayReason) override
static void CopyDetectionsToPointCloud(const std::vector< std::vector< DetectionT > > &Detections, const std::vector< uint32_t > &InPointsPerChannel, TArray< float > &PointCloud)
Copies the kept detections into a flat x, y, z, intensity array (editor debug point cloud).
virtual void Set(const FActorDescription &Description) override
ARayCastSemanticLidar(const FObjectInitializer &ObjectInitializer)
std::vector< std::vector< bool > > RayPreprocessCondition
virtual void ResetDetections(uint32_t Channels, uint32_t MaxPointsPerChannel)
Clear the per-channel detection buffers.
FLidarDescription Description
std::vector< std::vector< FSemanticDetection > > SemanticDetections
bool ShootLaser(const float VerticalAngle, float HorizontalAngle, FHitResult &HitResult, FCollisionQueryParams &TraceParams, const FVector &LidarBodyLocation, const FRotator &LidarBodyRotation) const
Shoot a laser ray-trace, return whether the laser hit something.
FSemanticLidarData SemanticLidarData
ASensor(const FObjectInitializer &ObjectInitializer)
void WritePoints(const std::vector< LidarDetection > &detections)
virtual void ResetMemory(std::vector< uint32_t > points_per_channel)
virtual void WriteChannelCount(std::vector< uint32_t > points_per_channel)
Helper class to store and serialize the data generated by a RawLidar.
A definition of a Carla Actor with all the variation and attributes.
A description of a Carla Actor with all its variation.
One record of frame data packet 27: the runtime state a sensor of the primary starts this frame's tic...