How to get boundary edges from STL file?

Hi everyone,

I’m trying to get boundaries from STL model.

I’ve tried the following method with converting stl to vtk, it works, but maybe there’s something more convenient?

mesh = meshio.Mesh.read(
"motor.stl",  
file_format="stl",)

mesh.write("motorMesh.vtk")

part = vtk.vtkUnstructuredGridReader()
part.SetFileName("motorMesh.vtk")
part.Update()

featureEdges = vtk.vtkExtractEdges()
featureEdges.SetInputConnection(part.GetOutputPort())

featureEdges.Update()

However, it shows all the edges, but not the boundaries.

Also, I don’t know how to use vtkExtractEdges() to get some data about the edges. Is there any option to check connected faces using vtkExtractEdges()?

You need to use vtkFeatureEdges filter and BoundaryEdgesOn()

Below is the C++ code to do that

vtkSmartPointer< vtkFeatureEdges > featureEdges = vtkSmartPointer< vtkFeatureEdges >::New();
featureEdges->SetInputConnection(diskSource->GetOutputPort());
featureEdges->BoundaryEdgesOn();
featureEdges->FeatureEdgesOff();
featureEdges->ManifoldEdgesOff();
featureEdges->NonManifoldEdgesOff();
featureEdges->Update();

Also, to save a step, VTK has a native STL reader:
vtk.vtkSTLReader()