Find the faces adjacent to a vertex

Given an ON_Point pointer, could you show us how to find the faces adjacent to this vertex in Rhino?

We use the following code to get an ON_Point pointer.

CRhinoObjRef obj_ref = go.Object(0);
// Get the Rhino object’s geometry
const ON_Geometry* geo = obj_ref.Geometry();
const ON_Point* prnPoint = ON_Point::Cast(geo);

Hi @XNurbs,

Here is some sample code to review:

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
  CRhinoGetObject go;
  go.SetCommandPrompt(L"Select Brep vertices to extract");
  go.SetGeometryFilter(CRhinoGetObject::brepvertex_filter);
  go.GetObjects(1, 0);
  if (go.CommandResult() != CRhinoCommand::success)
    return go.CommandResult();

  for (int i = 0; i < go.ObjectCount(); i++)
  {
    const CRhinoObjRef& obj_ref = go.Object(i);
    const ON_BrepVertex* pVertex = ON_BrepVertex::Cast(obj_ref.Point());
    const ON_Brep* pBrep = obj_ref.Brep();
    if (nullptr == pVertex || nullptr == pBrep)
      return CRhinoCommand::failure;

    RhinoApp().Print(L"ON_BrepVertex::m_vertex_index = %d\n", pVertex->m_vertex_index);

    for (int ei = 0; ei < pVertex->EdgeCount(); ei++)
    {
      const ON_BrepEdge& edge = pBrep->m_E[pVertex->m_ei[ei]];
      RhinoApp().Print(L" ON_BrepEdge::m_edge_index = %d\n", edge.m_edge_index);

      for (int ti = 0; ti < edge.TrimCount(); ti++)
      {
        const ON_BrepTrim& trim = pBrep->m_T[edge.m_ti[ti]];
        RhinoApp().Print(L"  ON_BrepTrim::m_trim_index = %d\n", trim.m_trim_index);
        const ON_BrepFace* pFace = trim.Face();
        if (nullptr != pFace)
        {
          RhinoApp().Print(L"   ON_BrepFace::m_face_index = %d\n", pFace->m_face_index);
          // todo...
        }
      }
    }
  }

  return CRhinoCommand::success;
}