How to highlight a smooth region on a polygonal mesh

The goal is to highlight a smooth region on a polygonal mesh. I am investigating two different techniques:

  • select cells on the surface of the mesh itself and apply some texture on them, but then I can’t have smooth borders because the triangles making up the cells are “irregular” (see purple region on the left of the image below - easy to position but does not look good)
  • display a transparent polygon on top of the polygonal mesh, but then I have to compute its position precisely to be on top of the region i want to highlight (see light blue region on the right of the image below - looks good but difficult to position)
1 Like

You can hide the jagged edge by showing a curve at the edge using a tube filter. Tube radius should be about the size of a mesh cell.

I do not think there is anyway to get around the jagged edges of the selection - even a tube around the feature edges would be jagged.

Here is the best thing I currently can do with PyVista by adding the selection (as an extracted mesh) to the scene with opacity and using SetInterpolationToPhong for smooth shading on that selected mesh:

from pyvista import examples
import pyvista as pv
pv.set_plot_theme('default')

mesh = examples.load_random_hills()

p = pv.Plotter(notebook=False)
p.add_mesh(mesh, color='white')

def overlay(selection):
    p.add_mesh(selection, name='selection', color='lightblue',
               opacity=0.5, smooth_shading=True)
    return

p.enable_cell_picking(mesh=mesh, show=False,
                     callback=overlay)
p.show()

You can easily smooth the curve before you apply tube filter on it, so it would not be jagged.

I tried with a smooth poly data filter and like 10000 iterations without any luck… is there a trick to it?

Thanks Andras and Bane for sharing all that,
Let me share some of my experimentation (my blue areas are defined by 4 points - not necessarily co-planar):

  1. Using tubes around 4 points on the mesh
    See image below.
    The area is drawn using vtkSelectPolyData with four points as a loop and the underlying mesh, and the edges by tubes linking the four adjacent points.
    It does smooth the jagged edges, but obviously the tubes sometimes go under the mesh so they become invisible, sometimes there is some area that goes outside of the tubes and sometimes not close enough to the tube. Making the tubes big enough to hide all those would make them huge and visually bad.
    Screenshot%20from%202019-10-04%2010-06-51

  2. Using tubes around selected polydata edges
    See image below.
    As above, the area is drawn using vtkSelectPolyDara with four points as a loop, but the tubes are drawn using the selected polydata edges.
    The edges are still very much jagged because they are strictly following the mesh triangles. I tried to use a vtkParametricSpline with selected edges point as an input to draw the tube filters, but without success so far (a little like in https://vtk.org/Wiki/VTK/Examples/Cxx/VisualizationAlgorithms/TubesFromSplines).
    I should try harder in that direction, but I at the same time I feel we are always going to be limited by the underlying mesh triangle size.
    Screenshot%20from%202019-10-04%2010-02-41

  3. Using a 2D polygon on top of the mesh
    See image below.
    The area is a simple planar polygon drawn on top of the mesh, using point normals to detach the area from the mesh. It really looks like what I want it to look, it does not rely on the underlying mesh triangles, but there are several drawbacks:

  • I have not succeeded to compute automatically the exact shift along the normal from the bone,
  • It might not look as good for larger regions or if the camera z axis is not perpendicular to the area being displayed on the mesh
    Screenshot%20from%202019-10-04%2010-11-40

I wonder if there would be a way to clip data from the mesh and as we do, split the triangles of the mesh so that they strictly follow the specified edges (using a tesselator filter)?

You can project each tube centerline point to the surface to avoid this problem.

The fundamental issue is that the region you cut has jagged edges. You would solve all the problems by making the cutout surface edge smoother. I think some filters can make smooth cuts (cut into cells) based on thresholding of point scalar values.

Thanks I’ll try that

So I did end-up with a satisfying result by:

  • subdividing the regions with intermediate point
  • project those points on the closest point on the bone
  • using vtkSelectPolyData with those points
  • using vtkClipPolyData with vtkSelectPolyData output

It’s not perfectly smooth but good enough not to have to add a tube,
In any case thanks for your input

See image below
Screenshot%20from%202019-10-07%2016-23-41

1 Like

I´m trying to replicate your result but I can´t. Could you sheare an example of your code to get this smooth footprint in bone?
Thanks in advance!!