1.现象描述
利用pcl::GreedyProjectionTriangulation对点云进行三角面片得到的mesh,假如直接在pcl::visualization::PCLVisualizer显示是没有问题的:
// Create a PCLVisualizer object
pcl::visualization::PCLVisualizer viewer("PCL Viewer");
// Define the color of the point cloud
viewer.setBackgroundColor(0.5, 0.6, 0.0);
// Add the point cloud and its normals to the viewer
viewer.addPointCloudNormals<pcl::PointXYZRGBNormal>(cloud_with_normals, 2); // 显示点云以及法线
viewer.addPolygonMesh(mesh); // 显示mesh
// Set the camera position and orientation
viewer.setCameraPosition(0.0, 0.0, -2.0, 0.0, -1.0, 0.0);
// Start the viewer
while(!viewer.wasStopped())
{
viewer.spin();
// viewer.spinOnce();
}
可以看到,法线都是在同一侧的,表示方向是正确的。
但是,利用pcl::io::saveOBJFile将mesh保存为obj后,再用别第三方软件打开就出现很调皮的效果了:
pcl::PolygonMesh mesh;
ret = MyUtil::pointCloudToMesh(pclCloud, mesh);
if(ret != 0)
{
return;
}
QString fileName = QString("mesh_%1.obj").arg(QTime::currentTime().toString("hhmmss_zzz"));
//保存网格图名
pcl::io::saveOBJFile(fileName.toStdString(), mesh);
可以看到,黑一片、灰一片的。打开法线看看:
好家伙,一半是正向的,一半是反向的。难怪看起来不对劲了。打开方向着色看也可以看到一部分面片的法线方向是有问题的
2.解决方法
还不知道。
先用ply格式吧,虽然法线好像还是有问题,但是基本能看。
不知道为啥都是法线有问题,obj显示不行,但是ply格式显示还可以。