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

fixed loadData()

parent 74263d35
No related branches found
No related tags found
1 merge request!41Draft: Resolve "New branch laser 3d"
...@@ -36,53 +36,47 @@ ...@@ -36,53 +36,47 @@
#include <pcl/registration/icp_nl.h> #include <pcl/registration/icp_nl.h>
#include <pcl/registration/transforms.h> #include <pcl/registration/transforms.h>
#include <iostream>
#include <fstream>
typedef pcl::Registration<pcl::PointXYZ, pcl::PointXYZ>::Ptr RegistrationPtr; 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)
{ {
std::string s_pcd = ".pcd", s_bin = ".bin"; //std::string s_pcd = ".pcd", s_bin = ".bin";
if (fname.compare(fname.size() - 4, 4, s_pcd) == 0) if (fname.compare(fname.size() - 4, 4, ".pcd") == 0)
{ {
pcl::io::loadPCDFile(fname, cloud); 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"); else if (fname.compare(fname.size() - 4, 4, ".bin") == 0)
{ // file is binary
//pcl::PointCloud<pcl::PointXYZ>::Ptr pcl_ptr = pcl::make_shared<pcl::PointCloud<pcl::PointXYZ>>();
std::ifstream stream_input;
stream_input.open(fname, std::ios::in);
for (int i = 0; stream_input.good() && !stream_input.eof(); i++)
{
pcl::PointXYZI point_raw;
stream_input.read((char *)&point_raw.x, 3 * sizeof(float));
stream_input.read((char *)&point_raw.intensity, sizeof(float));
pcl::PointXYZ tPoint;
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; tPoint.x = point_raw.x;
float *py = data + 1; tPoint.y = point_raw.y;
float *pz = data + 2; tPoint.z = point_raw.z;
float *pr = data + 3;
pcl::PointXYZ tPoint; cloud.push_back(tPoint);
for (int32_t i = 0; i < num; i++)
{
tPoint.x = *px;
tPoint.y = *py;
tPoint.z = *pz;
pcl_ptr->push_back(tPoint);
px += 4;
py += 4;
pz += 4;
pr += 4;
} }
fclose(stream); stream_input.close();
std::vector<int> indices; // remove NAN points from the cloud
pcl::removeNaNFromPointCloud(*pcl_ptr, *pcl_ptr, indices); pcl::Indices indices;
pcl::removeNaNFromPointCloud(cloud, cloud, indices);
} }
}; };
...@@ -109,7 +103,7 @@ inline void pairAlign(const pcl::PointCloud<pcl::PointXYZ>::Ptr _cloud_ref, ...@@ -109,7 +103,7 @@ inline void pairAlign(const pcl::PointCloud<pcl::PointXYZ>::Ptr _cloud_ref,
Eigen::Matrix4f transform_guess = _transform_guess.matrix().cast<float>(); Eigen::Matrix4f transform_guess = _transform_guess.matrix().cast<float>();
// Alignment // Alignment
pcl::PointCloud<pcl::PointXYZ>cloud_out; pcl::PointCloud<pcl::PointXYZ> cloud_out;
_registration_solver->align(cloud_out, transform_guess); _registration_solver->align(cloud_out, transform_guess);
transform_pcl = _registration_solver->getFinalTransformation(); transform_pcl = _registration_solver->getFinalTransformation();
......
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