Fix bug in lidar point count

This commit is contained in:
Daniel Santos-Oliván 2021-04-08 13:14:54 +02:00 committed by bernat
parent f295d1eebf
commit 2eddbbcb39
5 changed files with 17 additions and 11 deletions

View File

@ -79,13 +79,10 @@ namespace data {
~LidarData() = default;
virtual void ResetSerPoints(std::vector<uint32_t> points_per_channel) {
virtual void ResetMemory(std::vector<uint32_t> 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<uint32_t>(
std::accumulate(points_per_channel.begin(), points_per_channel.end(), 0));

View File

@ -110,13 +110,10 @@ namespace data {
return _header[Index::ChannelCount];
}
virtual void ResetSerPoints(std::vector<uint32_t> points_per_channel) {
virtual void ResetMemory(std::vector<uint32_t> 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<uint32_t>(
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<uint32_t> 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);
}

View File

@ -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);
}

View File

@ -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

View File

@ -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;