0
votes

I'm trying to use assimp to load meshes in order to detect Non-Manifold and open (boundary) edges. I'm using the vertex indices that I get out of assimp in order to set up the relationships between vertices, edges, and faces. i have a face class that looks like this

#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;
}

my edge class is basically just a data structure that holds the edge's start index and end index. My mesh class contains a std::vector of faces and std::vector of edges that get populated like this:

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));
   }

my main function has this code:

    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;

I get the right number of edges and faces out of this. How ever the number of boundary edges varies a lot from what I get from meshlab for the same model. and the number of non manifold edges is always 0.

Is their something wrong I'm doing, or is their a better way?

1

1 Answers

1
votes

I think there is an error here:

m_edges2.push_back(Edge2(m_indices[i], m_indices[i]));

I suppose it should be:

m_edges2.push_back(Edge2(m_indices[i], m_indices[i + 1]));

Fixing this might solve your problem

There is also another error in faces creation cycle with the upper iteration bound which may cause UB. It should be:

i < m_indices.size()-2