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

时间:2015-05-27 04:26:26

标签: 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.

感谢您提前提供任何帮助。

1 个答案:

答案 0 :(得分:0)

我最终找到了一种在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;
}