Display subset of polydata

Hi, I have a structured grid whose cells have a property ‘Pressure’ which I have converted to polydata and am building an app for interacting with. One goal is for the user of my app to be able to interact with a slider that is mapped to the range of the Pressure data to threshold (not display) polygons that are below that threshold. Here is the general setup:

let vtpReader = vtkXMLPolyDataReader.newInstance(); vtpReader.parseAsArrayBuffer(file);

const source = vtpReader.getOutputData(0);
const data = source.getCellData().getArrayByName(‘Pressure’); //This is the data I want to threshold

actor.setMapper(mapper);
mapper.setInputData(source);
renderer.addActor(actor);
renderWindow.render();

I am struggling to decide how the best way to go about this. My intuition would be to use vtkCalculator to create a derived dataset which only contains polygons above the given Pressure threshold. But I am a little lost as to how this would be implemented. My other idea would be to loop through the data and manually define new polydata, which seems a bit excessive.

Does anyone have suggestions on the best way to approach this? I am relatively new to VTK so any advice is appreciated.

Do you want to do thresholding on the surface of your mesh (polydata) or inside your volume (structured grid)?

The data starts as a structured grid but is already converted to vtp by the time my app sees it, so I am assuming that I will be thresholding the polydata surfaces.

Sure, I get that, but I feel that is not what you are looking for. So providing a “complex” solution for something that you don’t want/need is probably not the best approach, that is why I was asking the question in the first place. Are you really looking for triangles floating in the air? If so, you can implement a threshold filter in vtk.js fairly easily. (That was what I mentioned as “complex”)

To some degree, you can have your structured grid mapped to an vtkImageData, run a contour filter (in vtk.js) and then remap the points coordinates to your original structured grid. (Which might not be as bad to do especially if you do not need the remapping part.)

Ideally this is what I would achieve:


The threshold has been applied to reveal the inner cells of interest but the outer surface has been retained with opacity dropped. This would involve computing the boundaries of the outermost cells, which I think I can precompute since I can easily figure out the indices of the outer cells. Unless there is a filter or combination of filters that can handle only rendering outer faces of polydata.

A polydata is already the outer cells since it is just the skin of your mesh. Based on what you are showing, you can implement such filter in the client side. But nothing like that is available as built-in.
If need be, Kitware can help you create such filter for your use case.

Okay, here’s what I didn’t realize and explain properly: my original data is structured in nature, but i converted it to unstructured, and then to vtp. Thus, the interior cells faces in my mesh are retained. I have created separate polydata from a my original structured grid to obtain the “skin” that I wanted. But now the problem remains: how do I best threshold those inner cells? Do I really have to create new polydata from scratch by manually re-defining verts, cell data, connectivity, etc after removing the cells I am not interested in?

I was able to achieve what I wanted. Here are the steps I took to display a subset of polygons. I first grabbed the cell data and indices of cell data above my threshold. I then created new polydata instance, and grabbed the appropriate polys and points using the thresholded indices. Then I set the new polydata instance with those newly created data arrays. I found these helpful:

https://public.kitware.com/pipermail/vtkusers/2004-July/025395.html