|
准备一个obj文件,内容如下:
####
# OBJ dataFile simple version. File name: triangles.obj
# Vertices: 4
# Faces: 2
####
# List of Vertices, with (x,y,z) coordinates, w is optional.
v 0.0 0.0 0.0
v 10.0 0.0 0.0
v 10.0 10.0 0.0
v 0.0 10.0 0.0
# 4 vertices
# Face Definitions
f 1 2 3
f 1 3 4
# End of File
加载obj文件代码
#include <pcl/io/vtk_lib_io.h>
pcl::PolygonMesh triangles;
pcl::io::loadPolygonFileOBJ("triangles_test.obj", *triangles);
使用pcl::visualization::PCLVisualizer* viewer显示PolygonMesh代码
viewer->addPolygonMesh(*triangles);
生成TextureMesh模型
//第一个三角形
pcl::TextureMeshPtr nvmMesh_(new pcl::TextureMesh());
nvmMesh_->cloud = triangles_->cloud;
nvmMesh_->header = triangles_->header;
std::vector<pcl::Vertices> polygons;
polygons.push_back(triangles_->polygons[0]);
nvmMesh_->tex_polygons.push_back(polygons);
std::vector< Eigen::Vector2f > texcoord;
texcoord.push_back(Eigen::Vector2f(0.0,0.0));
texcoord.push_back(Eigen::Vector2f(1.0,0.0));
texcoord.push_back(Eigen::Vector2f(1.0,1.0));
texcoord.push_back(Eigen::Vector2f(0.0,1.0));
nvmMesh_->tex_coordinates.push_back(texcoord);
pcl::TexMaterial tex_material;
tex_material.tex_file = std::string("F:\\Develop\\examples\\111.jpg");
tex_material.tex_name = std::string("111.jpg");
nvmMesh_->tex_materials.push_back(tex_material);
//第二个三角形
pcl::TextureMeshPtr nvmMesh(new pcl::TextureMesh());
nvmMesh->cloud = triangles_->cloud;
nvmMesh->header = triangles_->header;
std::vector<pcl::Vertices> polygons2;
polygons2.push_back(triangles_->polygons[1]);
nvmMesh->tex_polygons.push_back(polygons2);
std::vector< Eigen::Vector2f > texcoord2;
texcoord2.push_back(Eigen::Vector2f(0.0,0.0));
texcoord2.push_back(Eigen::Vector2f(-1.0,-1.0));
texcoord2.push_back(Eigen::Vector2f(1.0,1.0));
texcoord2.push_back(Eigen::Vector2f(0.0,1.0));
nvmMesh->tex_coordinates.push_back(texcoord2);
pcl::TexMaterial tex_material2;
tex_material2.tex_file = std::string("F:\\Develop\\examples\\222.jpg");
tex_material2.tex_name = std::string("222.jpg");
nvmMesh->tex_materials.push_back(tex_material2);
使用pcl::visualization::PCLVisualizer* viewer显示TextureMesh代码
viewer->addTextureMesh(*nvmMesh_, tex_material.tex_name);
viewer->addTextureMesh(*nvmMesh, tex_material2.tex_name);
|
|