Extract Vertex on Mesh Boundaries¶
Synopsis¶
Print the vertices in order which lie on each boundary of a given mesh.
Results¶
Input mesh¶
Interactive input mesh
Example output:
There are 1 borders on this mesh
0: 684 -> 3848 -> 955 -> 1643 -> 4340 -> 178 -> 1160 -> 6650 -> 3539 -> 523 ->
6052 -> 9 -> 7619 -> 2876 -> 4010 -> 102 -> 1451 -> 557 -> 5658 -> 3326 -> 4606
-> 1154 -> 4584 -> 5553 -> 6739 -> 1725 -> 7207 -> 3978 -> 3116 -> 7770 -> 2293
-> 3285 -> 2215 -> 6505 -> 7128 -> 7973 -> 6479 -> 3292 -> 3719 -> 3111 -> 6566
-> 1227 -> 3410 -> 3418 -> 7208 -> 5732 -> 7203 -> 645 -> 314 -> 7872 -> 6941
-> 5076 -> 1965 -> 2017 -> 3235 -> 3801 -> 4754 -> 1348 -> 2390 -> 7367 -> 6319
-> 5458 -> 7572 -> 151 -> 4095 -> 3873 -> 7336 -> 7260 -> 2112 -> 6373 -> 1664
-> 7247 -> 7661 -> 5790 -> 1698 -> 572 -> 5783 -> 3042 -> 5259 -> 7802 -> 6192
-> 894 -> 4545 -> 1298 -> 684
Code¶
C++¶
#include "itkQuadEdgeMesh.h"
#include "itkVTKPolyDataReader.h"
#include "itkQuadEdgeMeshBoundaryEdgesMeshFunction.h"
int
main(int argc, char * argv[])
{
  if (argc != 2)
  {
    std::cerr << "Usage: " << argv[0] << " <InputFileName>" << std::endl;
    return EXIT_FAILURE;
  }
  constexpr unsigned int Dimension = 3;
  using CoordType = double;
  using MeshType = itk::QuadEdgeMesh<CoordType, Dimension>;
  using VTKReaderType = itk::VTKPolyDataReader<MeshType>;
  VTKReaderType::Pointer reader = VTKReaderType::New();
  reader->SetFileName(argv[1]);
  try
  {
    reader->Update();
  }
  catch (itk::ExceptionObject & e)
  {
    std::cerr << e.what() << std::endl;
    return EXIT_FAILURE;
  }
  MeshType::Pointer mesh = reader->GetOutput();
  using BoundaryExtractorType = itk::QuadEdgeMeshBoundaryEdgesMeshFunction<MeshType>;
  BoundaryExtractorType::Pointer extractor = BoundaryExtractorType::New();
  using MeshPointIdentifier = MeshType::PointIdentifier;
  using MeshQEType = MeshType::QEType;
  using MeshIteratorGeom = MeshQEType::IteratorGeom;
  using EdgeListType = MeshType::EdgeListType;
  using EdgeListPointer = MeshType::EdgeListPointerType;
  using EdgeListIterator = EdgeListType::iterator;
  EdgeListPointer list = extractor->Evaluate(*mesh);
  if (list->empty())
  {
    std::cerr << "There is no border on this mesh" << std::endl;
    return EXIT_FAILURE;
  }
  std::cout << "There are " << list->size() << " borders on this mesh" << std::endl;
  auto                   it = list->begin();
  const EdgeListIterator end = list->end();
  size_t i = 0;
  while (it != end)
  {
    std::cout << i << ": ";
    MeshIteratorGeom       eIt = (*it)->BeginGeomLnext();
    const MeshIteratorGeom eEnd = (*it)->EndGeomLnext();
    MeshPointIdentifier id = MeshType::m_NoPoint;
    while (eIt != eEnd)
    {
      MeshQEType * qe = eIt.Value();
      if (qe->GetOrigin() != id)
      {
        std::cout << qe->GetOrigin();
      }
      id = qe->GetDestination();
      std::cout << " -> " << id;
      ++eIt;
    }
    std::cout << std::endl;
    ++it;
  }
  return EXIT_SUCCESS;
}
Classes demonstrated¶
- 
template<typename 
TMesh>
classQuadEdgeMeshBoundaryEdgesMeshFunction: public itk::FunctionBase<TMesh, TMesh::EdgeListPointerType> Build a list of references to edges (as GeometricalQuadEdge::RawPointer) each one representing a different boundary component.
- Note
 Each resulting edge has the surface on its right and is hence ready for a walk on with the help of BeginGeomLnext().
- Note
 The size() of the resulting list is the number of boundary components.

