[英]I'm not able to triangulate a regular point cloud
我可以輕松地細分兩個參數化3D曲面(均為凸面)。
這是兩個細分的參數化曲面:
現在,我的意圖是將兩個實體合並為一個實體。 但是我得到這個:
我正在使用Qhull創建Delaunay三角剖分,似乎對第一個凸面效果很好,但不適用於背面。 :(
這是我當前的代碼(部分取自ZivS)
#include "Qhull.h"
using namespace orgQhull;
void myQhull::Qhull::runQhull3D(const pcl::PCLPointCloud2& pointCloud, const char* args)
{
std::cout << "runQhull vertices" << std::endl;
numVertices = 0;
std::stringstream verticesSS;
m_externalPoints = new PointCoordinates(3,""); //3 = dimension
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::fromPCLPointCloud2(pointCloud, *cloud);
std::vector<double> allPoints;
for (unsigned int i = 0; i < cloud->size(); i++) {
allPoints.push_back(cloud->at(i).x);
allPoints.push_back(cloud->at(i).y);
allPoints.push_back(cloud->at(i).z);
verticesSS << cloud->at(i).x << " " << cloud->at(i).y << " " << cloud->at(i).z << "\n";
numVertices++;
}
vertices += verticesSS.str();
m_externalPoints->append(allPoints); //convert to vector<double>
runQhull(*m_externalPoints, args);
}
void myQhull::Qhull::runQhull(const PointCoordinates &points, const char *qhullCommand2)
{
std::string triangles;
std::stringstream ss;
numSimplices = 0;
int numFaces = 0;
std::cout << numVertices << std::endl;
std::cout << "runQhull facets" << std::endl;
orgQhull::Qhull qHull(points.comment().c_str(), points.dimension(), points.count(), &*points.coordinates(), qhullCommand2);
QhullFacetList facets = qHull.facetList();
for (QhullFacetList::iterator it = facets.begin(); it != facets.end(); ++it)
{
if (!(*it).isGood()) continue;
QhullFacet f = *it;
QhullVertexSet vSet = f.vertices();
auto coord = f.hyperplane().coordinates();
numFaces = vSet.size();
ss << numFaces;
for (QhullVertexSet::iterator vIt = vSet.begin(); vIt != vSet.end(); ++vIt)
{
QhullVertex v = *vIt;
QhullPoint p = v.point();
double * coords = p.coordinates();
ss << " " << p.id() << " ";
}
ss << "\n";
numSimplices++;
}
simplices += ss.str();
std::cout << numSimplices << std::endl;
}
void myQhull::Qhull::saveOff(std::string file)
{
std::cout << "Saving qhull.off" << std::endl;
std::ofstream offFile;
offFile.open(file);
offFile << "OFF\n";
offFile << numVertices << " " << numSimplices << " 0";
offFile << vertices;
offFile << simplices;
offFile.close();
}
void myQhull::Qhull::run(const pcl::PCLPointCloud2& pointCloud)
{
Qhull qhull;
qhull.runQhull3D(pointCloud, "Qt");
qhull.saveOff("qhull.off");
}
另外,我使用了OpenCV的greedy_projection
,但沒有成功。 它只能對兩個表面進行細分,而不能將它們結合在一起。
知道為什么會這樣嗎?
終於我找到了解決方案。 向qhull.runQhull3D(pointCloud, "d Qt")
添加“ d”可以為上下表面生成正確的Delaunay三角剖分。 因此,由於它們是常規網格I,因此可以手動從兩個曲面創建連接頂點的邊。 謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.