使用PCL,我将把一个纹理化的OBJ文件加载到pcl::TextureMesh
中,并使用viewer->addTextureMesh()
函数在pcl查看器中可视化它。在可视化网格之前,我需要对其进行转换。对于实际的点云格式,比如pcl::PointCloud<pcl::PointXYZ>
转换,使用pcl::transformPointCloud()
函数非常简单。我如何转换一个pcl::TextureMesh
到目前为止,我试图将它转换为pcl::PointCloud<pcl::TextureMesh>
(这样我就可以使用pcl::transformPointCloud()
函数),但是我的PCL程序员的技能非常有限,所以我不知道如何做到这一点。要在转换之后通过viewer->addTextureMesh()
函数将其添加到查看器中,我需要再次从pcl::PointCloud<pcl::textureMesh>
中提取它,在这里,它仍然不知道如何实现。
有人能帮我如何转换pcl::TextureMesh
吗?
提前谢谢你!!
发布于 2022-08-20 10:48:51
在多边形网格中,每个多边形都通过顶点索引与顶点相连。当顶点坐标发生变化(mesh.cloud
在PCL中)时,网格也会发生变化。
但是,mesh.cloud
的数据类型是pcl::PointCloud2
,pcl::transformPointCloud
不支持这种数据类型。因此,我们需要在转换之前将pcl::PointCloud2
转换为pcl::PointCloud<PointT>
。
下面是我在PCL中转换网格的解决方案的一个例子。它使用pcl::PolygonMesh
(因为我没有带有纹理的OBJ文件),但是我认为它在pcl::TextureMesh
中工作得很好!
#include <string>
#include <iostream>
#include <Eigen/Dense>
#include <pcl/io/vtk_lib_io.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/point_cloud.h>
#include <pcl/io/obj_io.h>
#include <pcl/common/transforms.h>
using namespace std;
using namespace Eigen;
int main(){
string filepath = "test.obj";
//// read mesh
pcl::PolygonMesh mesh;
if (pcl::io::loadPolygonFile(filepath, mesh)==-1) {
fprintf(stderr, " [ERROE] Could not read mesh from file %s\n", filepath.c_str());
exit(1);
}
//// visualize before transformation
pcl::visualization::PCLVisualizer::Ptr viewer_(new pcl::visualization::PCLVisualizer("results"));
viewer_->setBackgroundColor(0,0,0);
viewer_->addCoordinateSystem(1.0);
viewer_->initCameraParameters();
viewer_->addPolygonMesh(mesh, "mesh");
viewer_->spin();
//// convert to pcl::PointCloud<PointT>
pcl::PointCloud<pcl::PointXYZ> cloud;
pcl::fromPCLPointCloud2(mesh.cloud, cloud);
//// transformation
Matrix4f T = Matrix4f::Identity();
T.block<3, 3>(0, 0) = AngleAxisf(M_PI/4, Vector3f(0,0,1)).toRotationMatrix(); // Rotate 45 degrees around the z-axis
pcl::transformPointCloud(cloud, cloud, T);
pcl::toPCLPointCloud2(cloud, mesh.cloud);
//// visualize after transformation
viewer_->updatePolygonMesh(mesh, "mesh");
viewer_->spin();
return 0;
}
以下是可视化结果:
https://stackoverflow.com/questions/71186153
复制相似问题