PCL 在添加到查看器之前变换纹理网格

问题描述 投票:0回答:1

使用 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
吗?

提前谢谢您!!

graphics 3d textures mesh point-cloud-library
1个回答
0
投票

在多边形网格中,每个多边形都通过顶点索引与顶点相连。当顶点坐标发生变化时(PCL 中的

mesh.cloud
),网格也会发生变化。

但是,

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;
}


以下是可视化结果:

转换前可视化

变形后可视化

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.