I would like to have some suggestions on how to implement the following:
I have a STL file and I would like to allow the user to draw a closed polygon and pick points of the mesh inside the closed contour.
How have I to approach the problem? I couldn’t find any example online.
I think it is doable on 2d and 3d (like blender) but you’ll need to put some work into it. Maybe check the contourFilter class
I would go with selection.
For a quick preview open up a .stl file in ParaView and click either of these buttons at the top of the RenderView window, then mouse drag in the view.
VTK’s selection is the basis for that. You should be able to find examples and tests in the VTK books and online sources.
Thanks for the reply,
what do you mean for “selection”?
Thanks for the reply. I forgot to add that I would like to achieve this using Python.
Is there any example involving python?
As suggested, I looked at HardwareSelector example. In the example linked ( TestPolygonSelection.cxx) the draw-polygon interactor style is involved. As concerns the Python wrapper the method “GetPolygonPoints” has not been implemented because it returns a vtkVector2i, which is difficult to wrap. So I found this re-write of the vtk class on github HERE. Just to test the class I wrote this piece of code:
readerSTL = vtk.vtkSTLReader()
# 'update' the reader i.e. read the .stl file
polydata = readerSTL.GetOutput()
print ("Number of Cells:", polydata.GetNumberOfCells())
print ("Number of Points:", polydata.GetNumberOfPoints())
# If there are no points in 'vtkPolyData' something went wrong
if polydata.GetNumberOfPoints() == 0:
raise ValueError("No point data could be loaded from " + filenameSTL)
colors = vtk.vtkNamedColors()
mesh_path = path of the STL file
mesh = loadSTL(mesh_path)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(mesh) # maps polygonal data to graphics primitives
actor = vtk.vtkActor()
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
iren = vtk.vtkRenderWindowInteractor()
#interactor style-->draw polygon
polystyle = InteractorStyleDrawPolygon()
The STL file is loaded correctly but the interactor seems not working because anything happens when I clicked the mouse left button. I added–> print (“pressed”) inside the callback OnLeftButtonUp and it is executed so that it seems that self.interactor is None. How can I fix it?