Hello, I am having trouble detecting BoundaryEdges of a triangulated surface mesh.
As I am not yet allowed to upload files, I share here the code and the stl file I am using for this test. The stl is a cube made out of 6*2 triangles. I deleted one of these triangles to create a hole the algorithm should detect. However, when I run the script, the featureEdges object does not contain any cells, which looks like the hole is not detected properly. Am I doing something wrong?
I also loaded the file in Paraview and used the FeatureEdges filter there and it detects the hole without any problem.
// the code
import os
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkPolyDataMapper,
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkRenderer
)
from vtk import vtkSTLReader
from vtkmodules.vtkFiltersCore import vtkFeatureEdges
def main(argv):
colors = vtkNamedColors()
stlName = 'box_open.stl'
workDir = os.getcwd()
fileName = os.path.join(workDir, stlName)
# create an instance of vtkSTLReader to process stl file
reader = vtkSTLReader()
# pass filename to the reader
reader.SetFileName(fileName)
polydata = reader.GetOutput()
featureEdges = vtkFeatureEdges()
featureEdges.FeatureEdgesOff()
featureEdges.BoundaryEdgesOn()
featureEdges.NonManifoldEdgesOn()
featureEdges.SetInputData(polydata)
featureEdges.Update()
print(featureEdges.GetOutput().GetNumberOfCells())
mapper = vtkPolyDataMapper()
mapper.SetInputData(featureEdges.GetOutput())
actor = vtkActor()
actor.GetProperty().SetColor(colors.GetColor3d('Black'))
#actor.GetProperty().SetOpacity(1)
actor.SetMapper(mapper)
renderer = vtkRenderer()
ren_win = vtkRenderWindow()
ren_win.AddRenderer(renderer)
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(ren_win)
renderer.AddActor(actor)
renderer.SetBackground(colors.GetColor3d('white'))
ren_win.Render()
iren.Initialize()
iren.Start()
if __name__ == '__main__':
import sys
main(sys.argv)
// the stl, save this box_open.stl and put it next to the python file.
solid cube
facet normal -1.000000 0.000000 0.000000
outer loop
vertex 0.000000 0.000000 0.000000
vertex 0.000000 0.000000 10.000000
vertex 0.000000 10.000000 10.000000
endloop
endfacet
facet normal 1.000000 0.000000 0.000000
outer loop
vertex 10.000000 0.000000 10.000000
vertex 10.000000 0.000000 0.000000
vertex 10.000000 10.000000 0.000000
endloop
endfacet
facet normal 1.000000 0.000000 0.000000
outer loop
vertex 10.000000 10.000000 10.000000
vertex 10.000000 0.000000 10.000000
vertex 10.000000 10.000000 0.000000
endloop
endfacet
facet normal 0.000000 -1.000000 0.000000
outer loop
vertex 0.000000 0.000000 0.000000
vertex 10.000000 0.000000 0.000000
vertex 10.000000 0.000000 10.000000
endloop
endfacet
facet normal -0.000000 -1.000000 0.000000
outer loop
vertex 10.000000 0.000000 10.000000
vertex 0.000000 0.000000 10.000000
vertex 0.000000 0.000000 0.000000
endloop
endfacet
facet normal 0.000000 1.000000 0.000000
outer loop
vertex 10.000000 10.000000 0.000000
vertex 0.000000 10.000000 0.000000
vertex 0.000000 10.000000 10.000000
endloop
endfacet
facet normal 0.000000 1.000000 0.000000
outer loop
vertex 10.000000 10.000000 10.000000
vertex 10.000000 10.000000 0.000000
vertex 0.000000 10.000000 10.000000
endloop
endfacet
facet normal 0.000000 0.000000 -1.000000
outer loop
vertex 0.000000 0.000000 0.000000
vertex 0.000000 10.000000 0.000000
vertex 10.000000 10.000000 0.000000
endloop
endfacet
facet normal 0.000000 -0.000000 -1.000000
outer loop
vertex 10.000000 10.000000 0.000000
vertex 10.000000 0.000000 0.000000
vertex 0.000000 0.000000 0.000000
endloop
endfacet
facet normal 0.000000 0.000000 1.000000
outer loop
vertex 0.000000 10.000000 10.000000
vertex 0.000000 0.000000 10.000000
vertex 10.000000 0.000000 10.000000
endloop
endfacet
facet normal 0.000000 0.000000 1.000000
outer loop
vertex 10.000000 10.000000 10.000000
vertex 0.000000 10.000000 10.000000
vertex 10.000000 0.000000 10.000000
endloop
endfacet
endsolid