点云技术相关产学研社区

 找回密码
 立即注册加入PCL中国点云技术相关产学研社区

扫一扫,访问微社区

查看: 9833|回复: 1

PCL多纹理映射实现方法

[复制链接]
发表于 2013-12-23 14:46:00 | 显示全部楼层 |阅读模式
准备一个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);

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册加入PCL中国点云技术相关产学研社区

x
回复

使用道具 举报

发表于 2015-3-3 13:03:30 | 显示全部楼层
你好,我运行这个代码的时候会遇到这样的错误:error C2039: "addTextureMesh" is not the member of the "pcl::visualization::PCLVisualizer",请问这是什么原因呢?

点评

你的pcl啥版本?1.6版本的没有定义addTextureMesh()这个函数  发表于 2015-3-23 14:50
回复 支持 反对

使用道具 举报

本版积分规则

QQ|小黑屋|点云技术相关产学研社区 ( 陕ICP备13001629号 )

GMT+8, 2024-4-29 21:30 , Processed in 2.895872 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表