我正在尝试使用assimp加载网格以检测非流形和开放(边界)边缘。我正在使用我从assimp中获得的顶点索引,以便设置顶点,边和面之间的关系。我有一个看起来像这样的面部课
#include "Face2.h"
Face2::Face2()
{
}
Face2::Face2(std::vector<unsigned int> indices)
{
m_indices = indices;
}
bool Face2::containsEdge(const Edge2 &edge)
{
// for(unsigned int i = 0; i < m_indices.size(); i++)
// {
// if(edge.getStartIndex() == m_indices[i]){
// for(unsigned int i = 0; i < m_indices.size(); i++)
// {
// edge.getEndIndex() == m_indices[i]
// }
// }
// }
for(unsigned int i = 0; i < m_indices.size(); i++)
{
if(edge.getStartIndex() == m_indices[i])
{
for(unsigned int j = 0; j < m_indices.size(); j++)
{
if(edge.getEndIndex() == m_indices[j]) return true;
}
}
}
return false;
}
std::vector<unsigned int> Face2::getIndices() const
{
return m_indices;
}
void Face2::setIndices(const std::vector<unsigned int> &indices)
{
m_indices = indices;
}
我的边缘类基本上只是一个包含边的起始索引和结束索引的数据结构。 我的网格类包含一个std :: faces of faces和std :: vector of edges,它们填充如下:
for(unsigned int i = 0; i < m_indices.size()-1; i+=2)
{
m_edges2.push_back(Edge2(m_indices[i], m_indices[i]));
}
for(unsigned int i = 0; i < m_indices.size()-1; i+=3)
{
std::vector<unsigned int> faceData;
faceData.push_back(m_indices[i]);
faceData.push_back(m_indices[i+1]);
faceData.push_back(m_indices[i+2]);
m_faces2.push_back(Face2(faceData));
}
我的main函数有这段代码:
std::cout << "Number of edges2: " << m->getEdges2().size() << std::endl;
std::cout << "Number of faces2: " << m->getFaces2().size() << std::endl;
std::cout << "finished " << std::endl;
unsigned int nonManif = 0;
unsigned int boundary = 0;
for(unsigned int i = 0; i < m->getEdges2().size(); i++)
{
unsigned int edgeCount = 0;
for(unsigned int j = 0; j < m->getFaces2().size(); j++)
{
if(m->getFaces2().at(j).containsEdge(m->getEdges2().at(i)))
{
edgeCount++;
}
}
std::cout << "Edge#" << i << " occurences: " << edgeCount << std::endl;
if(edgeCount > 2) nonManif++;
else if(edgeCount < 2) boundary++;
}
std::cout << "Non-Manifold: " << nonManif << std::endl;
std::cout << "Boundary: " << boundary << std::endl;
我得到了正确数量的边和面。 然而,对于相同的模型,边界边的数量与我从meshlab获得的数量变化很大。并且非流形边的数量始终为0.
他们做错了什么,或者他们是更好的方式?
答案 0 :(得分:1)
我认为这里有一个错误:
m_edges2.push_back(Edge2(m_indices[i], m_indices[i]));
我想它应该是:
m_edges2.push_back(Edge2(m_indices[i], m_indices[i + 1]));
修复此问题可能会解决您的问题
面部创建周期中还有另一个错误,上面的迭代绑定可能会导致UB。它应该是:
i < m_indices.size()-2