How to find adjacent faces of a face?

Can someone give me a hint on how I can find adjacent faces of a known face on a mesh. Basically, I know a face on a mesh based on a “m_face_index”. Now, is it possible to base on that information to find any adjacent faces?

Thanks in advance.

Brian.

Use the topological information of the mesh to find adjacent faces.
ON_MeshTopology, ON_MeshFaceTopology etc. See opennurbs_mesh.h for more information.

Just googled adjacent. Tommorow I’m gonna go back to pronouns.

I found a function in the PCL lib that does just that. If anyone is interested, just drop a line. I will post the function.

Brian.

I am thinking something like this would work, although it doesn’t take welded edges into account.

static int FindAdjacentFaces(
        const ON_Mesh* mesh, 
        int face_index, 
        ON_SimpleArray<int>& adjacent_faces
        )
{
  if (mesh && mesh->IsValid())
  {
    if (face_index >= 0 && face_index < mesh->FaceCount())
    {
      const ON_MeshTopology& top = mesh->Topology();
      if (top.IsValid())
      {
        ON_COMPONENT_INDEX ci(ON_COMPONENT_INDEX::mesh_face, face_index);
        const ON_MeshFaceRef& face_ref = top.FaceRef(ci);
        const ON_MeshTopologyFace* face = face_ref.MeshTopologyFace();
        if (face)
        {
          for (int i = 0; i < (face->IsQuad() ? 4 : 3); i++)
          {
            const ON_MeshTopologyEdge& edge = top.m_tope[face->m_topei[i]];
            if (1 != edge.m_topf_count)
            {
              for (int j = 0; j < edge.m_topf_count; j++)
                adjacent_faces.Append(edge.m_topfi[j]);
            }
          }

          adjacent_faces.QuickSort(&ON_CompareIncreasing<int>);

          int index = *adjacent_faces.Last();
          for (int i = adjacent_faces.Count() - 2; i >= 0; i-- )
          {
            if (index == adjacent_faces[i])
              adjacent_faces.Remove(i);
            else
              index = adjacent_faces[i];
          }
          adjacent_faces.Shrink();
        }
      }
    }
  }

  return adjacent_faces.Count();
}

Thanks Dale.

Brian.