45 virtual void SimulateLidar(
const float DeltaTime,
bool bLockPhysics =
true);
47 virtual void SendData(
const float DeltaTime);
54 virtual void BeginPlay()
override;
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);
68 void ComputeRawDetection(
const FHitResult &HitInfo,
const FTransform &InverseSensorTransform,
const FVector &SensorLocation,
FSemanticDetection &Detection)
const;
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);
77 virtual void ComputeAndSaveDetections(
const FTransform &SensorTransform);
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,
98 LidarDataT &LidarData,
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);
116 LidarData.ResetMemory(OutPointsPerChannel);
117 for (uint32_t Channel = 0u; Channel < Channels; ++Channel)
119 LidarData.WritePoints(Detections[Channel]);
121 LidarData.WriteChannelCount(OutPointsPerChannel);
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)
152 TArray<
float> LaserAngles;
154 std::vector<
std::vector<
bool>> RayPreprocessCondition;
155 std::vector<uint32_t> PointsPerChannel;
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...
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).