Find the nearest triangle from a selected point

Hey guys,
i’m very new into VTK and using the 5.8. I already archieved to build a small 3D Plotter to open and view some .stl files. Now i’m trying to implementate a function that calculates me the nearest triangle from a selected point. I have red nearly everything about vtk on google, but still didnt find anything.
Maybe some of you can help me with this task.
Thank you so much!

Depending on your application, this may be easy or complex :slight_smile:

I would start with vtkDataSet::FindCell() and its cousins. Note that this virtual method is implemented in vtkDataSet derived classes (e.g., vtkPointSet::FindCell()) so you may want to poke around to learn more depending on the particulars of your data.

Now, if performance is a big concern, you need to become familiar with the cell locators (e.g., vtkCellLocator, vtkStaticCellLocator, etc. subclasses of vtkAbstractCellLocator).

Finally, if you want a trip down a deep rabbit hole, check out vtkFindCellStrategy class - some serious expertise is required to make sense of this.

1 Like

Thank you for your answer! I really hoped there is a library for it. I code it with C# and thought there is a function, that shows me the nearest triangle of my point :smiley:

You may want to check out ParaView. Its interactive point/cell/data interrogation capabilities are quite nice.

1 Like

Thank you, but i have to code it for myself. Can i use the FindCell() with an if condition or how does it work?

Given my schedule, the best I can recommend is to look at code examples. Other community members may be able to help, and of course Kitware pays the bills with support contracts (among other things :-))