how to visualizate the tetrahedron?

I want to visualize a tetrahedron, and my code is:


nodes = [
    [ 3.56000000e+02,  2.56000000e+02,  0.00000000e+00],
    [ 1.56000000e+02,  1.56000000e+02,  1.22464676e-14],
    [ 1.56000000e+02,  2.06000000e+02, -8.66025391e+01],
    [ 1.56000000e+02,  3.06000000e+02, -8.66025391e+01],
    [ 1.56000000e+02,  3.56000000e+02, -2.44929351e-14],
    [ 1.56000000e+02,  3.06000000e+02,  8.66025391e+01],
    [ 1.56000000e+02,  2.06000000e+02,  8.66025391e+01]
]

elem = [
    [4, 0, 5, 3],
    [1, 2, 6, 0],
    [2, 5, 0, 3],
    [2, 5, 6, 0]
]

import vtkmodules.all as vtk

points = vtk.vtkPoints()

for p in nodes:
    points.InsertNextPoint(p[0], p[1], p[2])

unstructuredGrid = vtk.vtkUnstructuredGrid()
unstructuredGrid.SetPoints(points)
cellArray = vtk.vtkCellArray()
for tre in elem:

    tetra = vtk.vtkTetra()
    tetra.GetPointIds().SetId(0, tre[0])
    tetra.GetPointIds().SetId(1, tre[1])
    tetra.GetPointIds().SetId(2, tre[2])
    tetra.GetPointIds().SetId(3, tre[3])
    cellArray.InsertNextCell(tetra)
unstructuredGrid.SetCells(vtk.VTK_TETRA, cellArray)


mapper = vtk.vtkDataSetMapper()
mapper.SetInputData(unstructuredGrid)

actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetOpacity(0.3)
actor.GetProperty().SetColor(1, 1, 0)

renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
renderer.SetBackground(1, 1, 1)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(renderer)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
iren.Initialize()
iren.Start()


And the result is:

image

But, I expect the result figure could display the inner grid, for example:

How can I obtain the second result? Any suggestion is appreciated~~~

Hi

Maybe try the triangleFilter

Hope it helps

Thanks for your kindly reply. I have tried vtkTriangleFilter, but a bug is reported:

vtkCompositeDataPipeline (000001E8834ED360): Input for connection index 0 on input port index 0 for algorithm vtkTriangleFilter(000001E883D74E20) is of type vtkUnstructuredGrid, but a vtkPolyData is required.

The vtkTriangleFilter do not accept vtkUnstructuredGrid.

Please try using vtkGeometryFilter before vtkTriangleFilter

Hope it helps

vtkGeometryFilter & vtkTriangleFilter still can not display the inner details.

image

Maybe try using two props: wireframe and surface
https://vtk.org/doc/nightly/html/classvtkProperty.html#a2a4bdf2f46dc499ead4011024eddde5c

two props (wireframe and surface) should work, but it is inconvenient.

I find vtkShrinkFilter work in this situation:

image

And the complete code is:


nodes = [
    [ 3.56000000e+02,  2.56000000e+02,  0.00000000e+00],
    [ 1.56000000e+02,  1.56000000e+02,  1.22464676e-14],
    [ 1.56000000e+02,  2.06000000e+02, -8.66025391e+01],
    [ 1.56000000e+02,  3.06000000e+02, -8.66025391e+01],
    [ 1.56000000e+02,  3.56000000e+02, -2.44929351e-14],
    [ 1.56000000e+02,  3.06000000e+02,  8.66025391e+01],
    [ 1.56000000e+02,  2.06000000e+02,  8.66025391e+01]
]

elem = [
    [4, 0, 5, 3],
    [1, 2, 6, 0],
    [2, 5, 0, 3],
    [2, 5, 6, 0]
]

import vtkmodules.all as vtk

points = vtk.vtkPoints()

for p in nodes:
    points.InsertNextPoint(p[0], p[1], p[2])

unstructuredGrid = vtk.vtkUnstructuredGrid()
unstructuredGrid.SetPoints(points)
cellArray = vtk.vtkCellArray()
for tre in elem:

    tetra = vtk.vtkTetra()
    tetra.GetPointIds().SetId(0, tre[0])
    tetra.GetPointIds().SetId(1, tre[1])
    tetra.GetPointIds().SetId(2, tre[2])
    tetra.GetPointIds().SetId(3, tre[3])
    cellArray.InsertNextCell(tetra)
unstructuredGrid.SetCells(vtk.VTK_TETRA, cellArray)

sf = vtk.vtkShrinkFilter()
sf.SetInputData(unstructuredGrid)
sf.SetShrinkFactor(1)
sf.Update()

gf = vtk.vtkGeometryFilter()
gf.SetInputData(sf.GetOutput())
gf.Update()

# mapper = vtk.vtkDataSetMapper()
# mapper.SetInputData(unstructuredGrid)
tf = vtk.vtkTriangleFilter()
tf.SetInputData(gf.GetOutput())
tf.Update()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(tf.GetOutput())

actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetOpacity(0.3)
actor.GetProperty().SetColor(1, 1, 0)


renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
renderer.SetBackground(1, 1, 1)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(renderer)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
iren.Initialize()
iren.Start()

But, I don’t know why vtkShrinkFilter would work in this situation.