show scalar data, use to show material of grid

This commit is contained in:
Martin Diehl 2022-02-21 07:27:35 +01:00
parent 9fe51686e5
commit 45dc9cf7a6
2 changed files with 14 additions and 2 deletions

View File

@ -683,7 +683,9 @@ class Grid:
def show(self) -> None: def show(self) -> None:
"""Show on screen.""" """Show on screen."""
VTK.from_image_data(self.cells,self.size,self.origin).show() v = VTK.from_image_data(self.cells,self.size,self.origin)
v.add(self.material.flatten(),'material')
v.show('material')
def add_primitive(self, def add_primitive(self,

View File

@ -12,6 +12,7 @@ from vtk.util.numpy_support import vtk_to_numpy as vtk_to_np
from ._typehints import FloatSequence, IntSequence from ._typehints import FloatSequence, IntSequence
from . import util from . import util
from . import Table from . import Table
from . import Colormap
class VTK: class VTK:
@ -436,7 +437,7 @@ class VTK:
return writer.GetOutputString() return writer.GetOutputString()
def show(self): def show(self,label=None,colormap=Colormap.from_predefined('strain')):
""" """
Render. Render.
@ -457,8 +458,17 @@ class VTK:
width = 1024 width = 1024
height = 768 height = 768
lut = vtk.vtkLookupTable()
lut.SetNumberOfTableValues(len(colormap.colors))
for i,c in enumerate(colormap.colors):
lut.SetTableValue(i,c if len(c)==4 else np.append(c,1.0))
lut.Build()
self.vtk_data.GetCellData().SetActiveScalars(label)
mapper = vtk.vtkDataSetMapper() mapper = vtk.vtkDataSetMapper()
mapper.SetInputData(self.vtk_data) mapper.SetInputData(self.vtk_data)
mapper.SetLookupTable(lut)
mapper.SetScalarRange(self.vtk_data.GetScalarRange())
actor = vtk.vtkActor() actor = vtk.vtkActor()
actor.SetMapper(mapper) actor.SetMapper(mapper)