Example #1
0
bool ReadPointCloudFromXYZ(const std::string &filename, PointCloud &pointcloud)
{
    FILE *file = fopen(filename.c_str(), "r");
    if (file == NULL) {
        PrintWarning("Read XYZ failed: unable to open file: %s\n", filename.c_str());
        return false;
    }

    char line_buffer[DEFAULT_IO_BUFFER_SIZE];
    double x, y, z;
    pointcloud.Clear();

    while (fgets(line_buffer, DEFAULT_IO_BUFFER_SIZE, file)) {
        if (sscanf(line_buffer, "%lf %lf %lf", &x, &y, &z) == 3) {
            pointcloud.points_.push_back(Eigen::Vector3d(x, y, z));
        }
    }

    fclose(file);
    return true;
}