Skip to content

Commit

Permalink
sanity checks on pointcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacharyTaylor committed Nov 16, 2018
1 parent df2d05c commit 67443b1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/lidar_align/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class Lidar {

const size_t getNumberOfScans() const;

const size_t getTotalPoints() const;

// note points are appended so any points in *pointcloud are preserved
void getCombinedPointcloud(Pointcloud* pointcloud) const;

Expand Down
16 changes: 16 additions & 0 deletions src/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ void Loader::parsePointcloudMsg(const sensor_msgs::PointCloud2 msg,
point.z = raw_point.z;
point.intensity = raw_point.intensity;

if (!std::isfinite(point.x) || !std::isfinite(point.y) ||
!std::isfinite(point.z) || !std::isfinite(point.intensity)) {
continue;
}

pointcloud->push_back(point);
}
pointcloud->header = raw_pointcloud.header;
Expand All @@ -54,6 +59,11 @@ void Loader::parsePointcloudMsg(const sensor_msgs::PointCloud2 msg,
point.y = raw_point.y;
point.z = raw_point.z;

if (!std::isfinite(point.x) || !std::isfinite(point.y) ||
!std::isfinite(point.z)) {
continue;
}

pointcloud->push_back(point);
}
pointcloud->header = raw_pointcloud.header;
Expand Down Expand Up @@ -90,6 +100,12 @@ bool Loader::loadPointcloudFromROSBag(const std::string& bag_path,
break;
}
}
if (lidar->getTotalPoints() == 0) {
ROS_ERROR_STREAM(
"No points were loaded, verify that the bag contains populated "
"messages of type sensor_msgs/PointCloud2");
return false;
}

return true;
}
Expand Down
8 changes: 8 additions & 0 deletions src/sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ Lidar::Lidar(const LidarId& lidar_id) : lidar_id_(lidar_id){};

const size_t Lidar::getNumberOfScans() const { return scans_.size(); }

const size_t Lidar::getTotalPoints() const {
size_t num_points = 0;
for (const Scan& scan : scans_) {
num_points += scan.getRawPointcloud().size();
}
return num_points;
}

const LidarId& Lidar::getId() const { return lidar_id_; }

void Lidar::addPointcloud(const LoaderPointcloud& pointcloud,
Expand Down

0 comments on commit 67443b1

Please sign in to comment.