以下是基于pcl库遍历result的C++代码:

#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/visualization/cloud_viewer.h>

struct Edge {
    int src;
    int tgt;
    float weight;
    bool isRead;
};

int main() {
    pcl::PointCloud<pcl::PointXYZ>::Ptr result(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::PointCloud<pcl::PointXYZ>::Ptr yr(new pcl::PointCloud<pcl::PointXYZ>);

    std::vector<Edge> edges;
    // Populate the edges vector with your data

    // Iterate over the result point cloud
    for (size_t i = 0; i < result->size(); ++i) {
        pcl::PointXYZ point = result->at(i);

        // Check if the point is equal to src or tgt in any edge
        for (size_t j = 0; j < edges.size(); ++j) {
            if (point.x == edges[j].src || point.x == edges[j].tgt) {
                // Add the point to yr
                yr->push_back(point);

                // Mark the edge as read
                edges[j].isRead = true;
                break; // Exit the loop since the point is found
            }
        }
    }

    // Re-iterate over the result point cloud
    for (size_t i = 0; i < result->size(); ++i) {
        pcl::PointXYZ point = result->at(i);

        // Check if the point is equal to src or tgt in any edge
        for (size_t j = 0; j < edges.size(); ++j) {
            if ((point.x == edges[j].src || point.x == edges[j].tgt) && !edges[j].isRead) {
                // Add the point to yr
                yr->push_back(point);

                // Mark the edge as read
                edges[j].isRead = true;
                break; // Exit the loop since the point is found
            }
        }
    }

    // Visualize yr point cloud
    pcl::visualization::CloudViewer viewer("YR Point Cloud Viewer");
    viewer.showCloud(yr);
    while (!viewer.wasStopped()) {}

    return 0;
}

请根据您的具体需求调整代码中的数据类型和变量名称。此代码遍历result点云,并根据src和tgt的值将对应的点添加到yr点云中,同时标记edges容器中的边为已读。然后重新遍历result点云,将未读的边对应的点也添加到yr点云中。最后,使用pcl库的CloudViewer可视化yr点云。

基于pcl库遍历resultresult里的存储边边容器包括srctgtweight三个变量当遍历result时若存在一点p等于src或tgt则将该点加入指针yr同时将容器内该点标记为已读重新遍历result的c++代码

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

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