Vedo: Cell data, threshold and created inner surface?

Created on 18 May 2020  路  11Comments  路  Source: marcomusy/vedo

Hi,

I would like to apply Mesh.threshold() to cell data, and simply passing useCells=True does not work. So I used Mesh.mapCellsToPoints() and it works (with useCells=False), but the resulting mesh has only the original surface - not the new (inner) surface that was created by removing points/cells with the threshold. Is it possible to display the surface of the hole created by the threshold application?

bug

All 11 comments

Try
pip install -U git+https://github.com/marcomusy/vtkplotter.git
then

from vtkplotter import *

man = load(datadir+"man_low.vtk").lw(0.1)

scals = man.cellCenters()[:, 0] + 37  
man.cellColors(scals, cmap="jet").addScalarBar()
printc(man.getArrayNames())

# make a copy and threshold the mesh
cutman = man.clone().threshold('CellScalars', 36.6, 37.5, useCells=True)

# distribute the meshes on 2 renderers
show(man, cutman, N=2, elevation=-30, axes=1)

image

Is it possible to display the surface of the hole created by the threshold application?

I 'm not sure ..it's not well defined (a contour does not define a unique surface)

Thanks! useCells=True works fine now.

As for the other question, let me explain what I want to achieve. I have a 3D tetrahedral mesh with two materials - a solid matrix (blue) and channels with a fluid (green):
screenshot1

When I apply the threshold, the resulting mesh is surface only:
screenshot2

So, its silhouette is:
screenshot3

After the channels material (green) is removed (without using vtkplotter) and a new mesh file is created and loaded:
screenshot4

the silhouette is then:
screenshot5

Is it possible to achieve the end result with vtkplotter/vtk only, without resorting to other tools to remove the green material elements, and without having to save the intermediate mesh to a file? It looks like the threshold filter might not be the right choice for this purpose, as its output is no longer a tetrahedral (volume) mesh. Newbie questions... :)

Is it possible to achieve the end result with vtkplotter/vtk only, without resorting to other tools to remove the green material elements, and without having to save the intermediate mesh to a file? It looks like the threshold filter might not be the right choice for this purpose, as its output is no longer a tetrahedral (volume) mesh.

Yes.
although vtkplotter focuses on polygonal meshes and Volumes (uniform grids of voxels) you can still use the native VTK class vtkThreshold to fill the intermediate step, something like:
_[see next message]_

...I actually had a dataset to test it:

from vtk import vtkThreshold
from vtkplotter import *

tetmesh = loadUnStructuredGrid(datadir+'limb_ugrid.vtk')

thres = vtkThreshold()
thres.SetInputData(tetmesh)
thres.SetInputArrayToProcess(0,0,0, 1, 'chem_0') # name of the array
thres.ThresholdByUpper(0.8)
thres.Update()
ugrid = thres.GetOutput()

# if False will only show the outer surface:
# settings.visibleGridEdges = True

msh = Mesh(ugrid).cellColors(cmap='nipy_spectral')
show(msh)

image

Perfect, thank you! So the first trick was to use loadUnStructuredGrid() instead of just load()...

cool , i hope it work with your mesh too

Perfect, thank you! So the first trick was to use loadUnStructuredGrid() instead of just load()...

yes, because load already transforms it into a polygonal mesh, all this makes me think i should add a class to explicitly support tet meshes

thanks for your feedback, m.

Yes, it works for my meshes!

@rc
with the latest version
pip install -U git+https://github.com/marcomusy/vtkplotter.git
you can:

from vtkplotter import *

tetmesh = load(datadir+'limb_ugrid.vtk')
tetmesh.color('prism').alpha([0,1])#.printInfo()

# Threshold the tetrahedral mesh for values in the range:
tetmesh.threshold(above=0.9, below=1)
tetmesh.addScalarBar3D(title='chem_0  expression levels', c='k', italic=1)

show(tetmesh.toMesh(shrink=0.9), axes=1)

Run the built-in examples with:
vtkplotter -ir tet_threshold

image

More examples here for isosurfacing cutting and slicing.

image
image
image
image

Very nice!

FYI: I have run pip install -U git+https://github.com/marcomusy/vtkplotter.git, but the new examples seem to be missing from the package:

vtkplotter -ir tet_threshold
No matching example found containing string: tet_threshold
  • there is no examples/tetmesh/ in the installed package.

I think I forgot to add the new dir to the pip manifesto.. this time should work..
pip install -U git+https://github.com/marcomusy/vtkplotter.git
then
vtkplotter -ir tet_threshold

Let me know if you find any problems using it (it's still a bit experimental!)

No more problems, all the new examples work now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mahendra-ramajayam picture mahendra-ramajayam  路  3Comments

vianamp picture vianamp  路  3Comments

jrdkr picture jrdkr  路  7Comments

bhaveshshrimali picture bhaveshshrimali  路  6Comments

FedeClaudi picture FedeClaudi  路  7Comments