diff --git a/LibCarla/source/carla/sensor/data/LidarData.h b/LibCarla/source/carla/sensor/data/LidarData.h index 73d325047..cc5e3a89f 100644 --- a/LibCarla/source/carla/sensor/data/LidarData.h +++ b/LibCarla/source/carla/sensor/data/LidarData.h @@ -79,13 +79,10 @@ namespace data { ~LidarData() = default; - virtual void ResetSerPoints(std::vector points_per_channel) { + virtual void ResetMemory(std::vector points_per_channel) { DEBUG_ASSERT(GetChannelCount() > points_per_channel.size()); std::memset(_header.data() + Index::SIZE, 0, sizeof(uint32_t) * GetChannelCount()); - for (auto idxChannel = 0u; idxChannel < GetChannelCount(); ++idxChannel) - _header[Index::SIZE + idxChannel] = points_per_channel[idxChannel]; - uint32_t total_points = static_cast( std::accumulate(points_per_channel.begin(), points_per_channel.end(), 0)); diff --git a/LibCarla/source/carla/sensor/data/SemanticLidarData.h b/LibCarla/source/carla/sensor/data/SemanticLidarData.h index 30d711d05..ef0e6f0a6 100644 --- a/LibCarla/source/carla/sensor/data/SemanticLidarData.h +++ b/LibCarla/source/carla/sensor/data/SemanticLidarData.h @@ -110,13 +110,10 @@ namespace data { return _header[Index::ChannelCount]; } - virtual void ResetSerPoints(std::vector points_per_channel) { + virtual void ResetMemory(std::vector points_per_channel) { DEBUG_ASSERT(GetChannelCount() > points_per_channel.size()); std::memset(_header.data() + Index::SIZE, 0, sizeof(uint32_t) * GetChannelCount()); - for (auto idxChannel = 0u; idxChannel < GetChannelCount(); ++idxChannel) - _header[Index::SIZE + idxChannel] = points_per_channel[idxChannel]; - uint32_t total_points = static_cast( std::accumulate(points_per_channel.begin(), points_per_channel.end(), 0)); @@ -124,6 +121,11 @@ namespace data { _ser_points.reserve(total_points); } + virtual void WriteChannelCount(std::vector points_per_channel) { + for (auto idxChannel = 0u; idxChannel < GetChannelCount(); ++idxChannel) + _header[Index::SIZE + idxChannel] = points_per_channel[idxChannel]; + } + virtual void WritePointSync(SemanticLidarDetection &detection) { _ser_points.emplace_back(detection); } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/RayCastLidar.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/RayCastLidar.cpp index e0214dc01..beac45e3e 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/RayCastLidar.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/RayCastLidar.cpp @@ -125,13 +125,18 @@ ARayCastLidar::FDetection ARayCastLidar::ComputeDetection(const FHitResult& HitI void ARayCastLidar::ComputeAndSaveDetections(const FTransform& SensorTransform) { for (auto idxChannel = 0u; idxChannel < Description.Channels; ++idxChannel) PointsPerChannel[idxChannel] = RecordedHits[idxChannel].size(); - LidarData.ResetSerPoints(PointsPerChannel); + + LidarData.ResetMemory(PointsPerChannel); for (auto idxChannel = 0u; idxChannel < Description.Channels; ++idxChannel) { for (auto& hit : RecordedHits[idxChannel]) { FDetection Detection = ComputeDetection(hit, SensorTransform); if (PostprocessDetection(Detection)) LidarData.WritePointSync(Detection); + else + PointsPerChannel[idxChannel]--; } } + + LidarData.WriteChannelCount(PointsPerChannel); } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/RayCastSemanticLidar.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/RayCastSemanticLidar.cpp index b3da64ac9..c69911d82 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/RayCastSemanticLidar.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/RayCastSemanticLidar.cpp @@ -160,7 +160,7 @@ void ARayCastSemanticLidar::WritePointAsync(uint32_t channel, FHitResult &detect void ARayCastSemanticLidar::ComputeAndSaveDetections(const FTransform& SensorTransform) { for (auto idxChannel = 0u; idxChannel < Description.Channels; ++idxChannel) PointsPerChannel[idxChannel] = RecordedHits[idxChannel].size(); - SemanticLidarData.ResetSerPoints(PointsPerChannel); + SemanticLidarData.ResetMemory(PointsPerChannel); for (auto idxChannel = 0u; idxChannel < Description.Channels; ++idxChannel) { for (auto& hit : RecordedHits[idxChannel]) { @@ -169,6 +169,8 @@ void ARayCastSemanticLidar::ComputeAndSaveDetections(const FTransform& SensorTra SemanticLidarData.WritePointSync(detection); } } + + SemanticLidarData.WriteChannelCount(PointsPerChannel); } void ARayCastSemanticLidar::ComputeRawDetection(const FHitResult& HitInfo, const FTransform& SensorTransf, FSemanticDetection& Detection) const diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/RayCastSemanticLidar.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/RayCastSemanticLidar.h index 7269c8297..51da54951 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/RayCastSemanticLidar.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/RayCastSemanticLidar.h @@ -46,7 +46,7 @@ protected: void CreateLasers(); /// Updates LidarMeasurement with the points read in DeltaTime. - void SimulateLidar(float DeltaTime); + void SimulateLidar(const float DeltaTime); /// Shoot a laser ray-trace, return whether the laser hit something. bool ShootLaser(const float VerticalAngle, float HorizontalAngle, FHitResult &HitResult) const;