以下是计算点云PLY文件内所有点的索引并存入std::vector all 的C++代码示例:

#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
#include <string>

struct Point {
    float x, y, z;
};

std::vector<int> getAllPointIndices(const std::string& filepath) {
    std::vector<int> allIndices;
    std::ifstream file(filepath);
    std::string line;

    // Skip header lines
    while (getline(file, line)) {
        if (line == "end_header")
            break;
    }

    // Read point indices
    int index = 0;
    while (getline(file, line)) {
        std::istringstream iss(line);
        int pointIndex;
        if (iss >> pointIndex) {
            allIndices.push_back(pointIndex);
            index++;
        }
    }

    file.close();
    return allIndices;
}

int main() {
    std::string filePath = "path_to_ply_file.ply";
    std::vector<int> allPointIndices = getAllPointIndices(filePath);

    // Print all point indices
    for (int index : allPointIndices) {
        std::cout << index << std::endl;
    }

    return 0;
}

请注意,该代码假设PLY文件的点索引列位于文件的主体部分,并且没有其他元数据。代码将跳过文件头部分,然后读取点索引直到文件结束。在主函数中,你可以将path_to_ply_file.ply替换为你的PLY文件的实际路径

计算点云ply文件内的所有点的索引并存入stdvectorintall的c++代码

原文地址: https://www.cveoy.top/t/topic/h4kJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录