Skip to content
Snippets Groups Projects
Commit 8154a235 authored by Víctor Sainz Ubide's avatar Víctor Sainz Ubide
Browse files

New loader for binaries

parent 5c528c49
No related branches found
No related tags found
1 merge request!41Draft: Resolve "New branch laser 3d"
...@@ -40,12 +40,53 @@ typedef pcl::Registration<pcl::PointXYZ, pcl::PointXYZ>::Ptr RegistrationPtr; ...@@ -40,12 +40,53 @@ typedef pcl::Registration<pcl::PointXYZ, pcl::PointXYZ>::Ptr RegistrationPtr;
namespace wolf namespace wolf
{ {
void loadData(std::string fname, pcl::PointCloud<pcl::PointXYZ>& cloud) void loadData(std::string fname, pcl::PointCloud<pcl::PointXYZ> &cloud)
{ {
pcl::io::loadPCDFile(fname, cloud); std::string s_pcd = ".pcd", s_bin = ".bin";
// remove NAN points from the cloud if (fname.compare(fname.size() - 4, 4, s_pcd) == 0)
pcl::Indices indices; {
pcl::removeNaNFromPointCloud(cloud, cloud, indices); pcl::io::loadPCDFile(fname, cloud);
// remove NAN points from the cloud
pcl::Indices indices;
pcl::removeNaNFromPointCloud(cloud, cloud, indices);
}
else if (fname.compare(fname.size() - 4, 4, s_bin) == 0)
{ // file is binary
pcl::PointCloud<pcl::PointXYZ>::Ptr pcl_ptr = pcl::make_shared<pcl::PointCloud<pcl::PointXYZ>>();
FILE *stream;
stream = std::fopen(fname.c_str(), "rb");
int32_t num = std::fread(NULL, sizeof(float), 10000000, stream) / 4; // size of point cloud
float *data = (float *)malloc(num * sizeof(float));
float *px = data + 0;
float *py = data + 1;
float *pz = data + 2;
float *pr = data + 3;
pcl::PointXYZ tPoint;
for (int32_t i = 0; i < num; i++)
{
tPoint.x = *px;
tPoint.y = *py;
tPoint.z = *pz;
pcl_ptr->push_back(tPoint);
// m.cloud -> push_back(*px, *py, *pz, *pr);
// point_cloud.points.push_back(tPoint(*px, *py, *pz, *pr));
px += 4;
py += 4;
pz += 4;
pr += 4;
}
fclose(stream);
// remove NAN points from the cloud
std::vector<int> indices;
pcl::removeNaNFromPointCloud(*pcl_ptr, *pcl_ptr, indices);
}
}; };
// _cloud_ref: first PointCloud // _cloud_ref: first PointCloud
...@@ -86,7 +127,8 @@ inline void pairAlign(const pcl::PointCloud<pcl::PointXYZ>::Ptr _cloud_ref, ...@@ -86,7 +127,8 @@ inline void pairAlign(const pcl::PointCloud<pcl::PointXYZ>::Ptr _cloud_ref,
_transform_final = Eigen::Isometry3d(transform_pcl.cast<double>()); _transform_final = Eigen::Isometry3d(transform_pcl.cast<double>());
// DURATION -------------------------------------------------------- // DURATION --------------------------------------------------------
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - start); auto duration =
std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - start);
WOLF_INFO("Laser3d_tools.h: pairAlign: duration: ", 1e-3 * (duration).count(), " ms"); WOLF_INFO("Laser3d_tools.h: pairAlign: duration: ", 1e-3 * (duration).count(), " ms");
// DURATION -------------------------------------------------------- // DURATION --------------------------------------------------------
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment