c++ - 点云库 - CloudViewer showCloud() - 传递常量指针 - 可视化 STL 文件

标签 c++ pointers point-cloud-library

背景


很抱歉用这么琐碎的问题打扰你。但我似乎做对了。自从我使用任何 C++ 以来已经有一段时间了,所以我可能正在做一些非常基本、非常错误的事情。

我想要完成的是将 .STL 网格文件加载到 PCL 的 cloudViewer。然而,我似乎无法获得可以传递给 showCloud() 的良好变量。

showCloud() 定义如下:

void pcl::visualization::CloudViewer::showCloud(const ColorCloud::ConstPtr & cloud, const std::string & cloudname = "cloud")

这让我相信我需要将一个常量指针传递给该方法。常规指针 (?) 似乎也有效。这是PCL tutorial的方式做到了,那确实奏效了。然而,我需要加载一个网格,而不是直接创建的 PointCloud。以下是本教程中使用常规 PointCloud 完成的方法:

pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile ("my_point_cloud.pcd", *cloud);

pcl::visualization::CloudViewer viewer("Cloud Viewer");

//blocks until the cloud is actually rendered
viewer.showCloud(cloud);

代码


我已将它转换为几乎可以工作的东西,但我似乎无法将正确的变量传递给 showCloud() 方法。

pcl::PolygonMesh mesh;
pcl::io::loadPolygonFile("path/to/mesh.stl", mesh);

pcl::PointCloud<pcl::PointXYZRGB> cloud;
pcl::fromROSMsg(mesh.cloud, cloud);

pcl::visualization::CloudViewer viewer("Cloud Viewer");

//blocks until the cloud is actually rendered
viewer.showCloud(cloud);

错误


我的 IDE (VS2010) 给我的错误信息是:

Error: no instance of overloaded function "pcl::visualization::CloudViewer::showCloud" matches argument list

我尝试了什么


我试过将 cloud 变量转换为指针、常量指针、将其分配给新指针等,但我就是无法理解它。 当我将其更改为指针时,pcl::fromROSMsg() 方法会报同样的错误。因此,当一种方法有效时,另一种方法无效。以下是我尝试过的一些方法(它们可能并不都有意义):

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_ptr;
pcl::PointCloud<pcl::PointXYZRGB> cloud;
pcl::fromROSMsg(mesh.cloud, cloud);
//...
cloud_ptr = cloud*;
//...
viewer.showCloud(cloud_ptr);

//or...
pcl::PointCloud<pcl::PointXYZRGB> cloud;
pcl::fromROSMsg(mesh.cloud, cloud);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_ptr (cloud);

//or...
pcl::PointCloud<pcl::PointXYZRGB> cloud;
pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr cloud_const_pointer = &cloud;
pcl::fromROSMsg(mesh.cloud, cloud);
//...
viewer.showCloud(cloud_const_pointer);

//or...
viewer.showCloud(&cloud);
//etc. etc.

提前感谢您的帮助。

最佳答案

this question 的帮助下,我最终找到了一种不同的方式来可视化我的 .STL 文件:

#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/vtk_lib_io.h>
#include <pcl/io/ply_io.h>

int 
main ()
{
    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>());
    pcl::PolygonMesh triangles;
    pcl::io::loadPolygonFileSTL("C:/Users/bono/Documents/Kinect2/Meshes/MeshedReconstructionAnderson.stl", triangles);
    pcl::fromROSMsg(triangles.cloud, *cloud);

    pcl::visualization::CloudViewer viewer("Cloud Viewer");  
    //blocks until the cloud is actually rendered
    viewer.showCloud(cloud);

    //use the following functions to get access to the underlying more advanced/powerful
    //PCLVisualizer

    //This will only get called once
    viewer.runOnVisualizationThreadOnce (viewerOneOff);

    //This will get called once per visualization iteration
    viewer.runOnVisualizationThread (viewerPsycho);
    while (!viewer.wasStopped ())
    {
        //you can also do cool processing here
        //FIXME: Note that this is running in a separate thread from viewerPsycho
        //and you should guard against race conditions yourself...
        user_data++;
    }

    return 0;
}

关于c++ - 点云库 - CloudViewer showCloud() - 传递常量指针 - 可视化 STL 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30473167/

相关文章:

c++ - Magick++ 的链接库

c++ - 让编译器初始化数组或手动遍历数组进行初始化更快吗?

c - 需要左值作为递增操作数

c++ - 使用指针打印二进制搜索树 C++ 的奇怪方式

c++ - VSCode C++ IntelliSense 工作正常,除了 PCL(点云库)

c++ - 如何在 c++ 中使用 `pcl` (点云库)从 std::vector<int> 创建 pcl::PointIndices?

c++ - 使用指向方法的指针的 MSVC 编译器 fatal error C1001

c++ - 在派生对象到基类的 "this"指针上使用 static_cast 的问题

c++ - 正在打印什么? C++ 指向整数的指针

c++ - 如何检测两个 3D 点云之间的差异?