How to get all mesh faces which share one vertex (c++)

Hi;

Like the picture, now I get the mesh vertex, how cant I all the mesh faces which share the vertex, and delete them?

Hi @suc_kiet,

This function should return the indices of faces that share a specified vertex:

int GetMeshIndexFaces(const ON_Mesh& mesh, int vertex, ON_SimpleArray<int>& faces)
{
  if (vertex <  0 || vertex >= mesh.VertexCount())
    return 0;

  const ON_MeshTopology& top = mesh.Topology();
  if (top.m_topv_map.UnsignedCount() != mesh.m_V.UnsignedCount())
    return 0;

  int topvi = top.m_topv_map[vertex];
  if (topvi < 0 || topvi >= top.m_topv.Count())
    return 0;

  const ON_MeshTopologyVertex& topvert = top.m_topv[topvi];
  for (int i = 0; i < topvert.m_tope_count; i++)
  {
    const ON_MeshTopologyEdge& topedge = top.m_tope[topvert.m_topei[i]];
    for (int j = 0; j < topedge.m_topf_count; j++)
      faces.Append(topedge.m_topfi[j]);
  }

  faces.QuickSort(&ON_CompareIncreasing<int>);

  int fi = -1;
  for (int i = faces.Count() - 1; i >= 0; i--)
  {
    if (faces[i] == fi)
      faces.Remove(i);
    else
      fi = faces[i];
  }

  return faces.Count();
}

– Dale