我想要完成的工作是将.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);
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.
感谢您提前提供任何帮助。
答案 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;
}