Skip to content

Instantly share code, notes, and snippets.

@insaneyilin
Last active January 8, 2020 07:29
Show Gist options
  • Save insaneyilin/9d3ac114c921fa9c57c66b2174016dc1 to your computer and use it in GitHub Desktop.
Save insaneyilin/9d3ac114c921fa9c57c66b2174016dc1 to your computer and use it in GitHub Desktop.
load big binary point cloud (.ply) file
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <sstream>
int main(int argc, char **argv) {
if (argc != 2) {
std::cout << "Usage: ./load_big_ply <filename>\n";
return 1;
}
std::string filename(argv[1]);
std::ifstream ifs(filename, std::ios::in|std::ios::binary);
if (!ifs.is_open()) {
std::cout << "failed to open " << filename << "\n";
return 1;
}
// skip header
std::string line;
while (std::getline(ifs, line, '\n')) {
std::cout << "read: " << line << "\n";
if (line == "end_header") {
break;
}
}
double x = 0.0;
double y = 0.0;
double z = 0.0;
double intensity = 0.0;
int point_cnt = 0;
const double inflate_size = 50.0;
const double xmin = 433233.2 - inflate_size;
const double ymin = 4435156.9 - inflate_size;
const double xmax = 433500.2 + inflate_size;
const double ymax = 4436156.4 + inflate_size;
std::ofstream ofs("out.pcd");
// read point cloud data line by line
while (!ifs.eof()) {
ifs.read((char*)(&x), sizeof(x));
ifs.read((char*)(&y), sizeof(y));
ifs.read((char*)(&z), sizeof(z));
ifs.read((char*)(&intensity), sizeof(intensity));
if (x > xmin && x < xmax && y > ymin && y < ymax) {
++point_cnt;
ofs << std::to_string(x) << " " << std::to_string(y)
<< " " << std::to_string(z) << "\n";
}
}
std::cout << "point_cnt: " << point_cnt << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment