add scalebar
This commit is contained in:
parent
45dc9cf7a6
commit
22fa9c9772
|
@ -17,6 +17,7 @@ from . import util
|
||||||
from . import grid_filters
|
from . import grid_filters
|
||||||
from . import Rotation
|
from . import Rotation
|
||||||
from . import Table
|
from . import Table
|
||||||
|
from . import Colormap
|
||||||
from ._typehints import FloatSequence, IntSequence
|
from ._typehints import FloatSequence, IntSequence
|
||||||
|
|
||||||
class Grid:
|
class Grid:
|
||||||
|
@ -681,11 +682,20 @@ class Grid:
|
||||||
header='\n'.join(header), fmt=format_string, comments='')
|
header='\n'.join(header), fmt=format_string, comments='')
|
||||||
|
|
||||||
|
|
||||||
def show(self) -> None:
|
def show(self,
|
||||||
"""Show on screen."""
|
colormap: Colormap = Colormap.from_predefined('viridis')) -> None:
|
||||||
|
"""
|
||||||
|
Show on screen.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
colormap : damask.Colormap
|
||||||
|
Colors used to map material IDs.
|
||||||
|
|
||||||
|
"""
|
||||||
v = VTK.from_image_data(self.cells,self.size,self.origin)
|
v = VTK.from_image_data(self.cells,self.size,self.origin)
|
||||||
v.add(self.material.flatten(),'material')
|
v.add(self.material.flatten(),'material')
|
||||||
v.show('material')
|
v.show('material',colormap)
|
||||||
|
|
||||||
|
|
||||||
def add_primitive(self,
|
def add_primitive(self,
|
||||||
|
|
|
@ -205,7 +205,7 @@ class VTK:
|
||||||
VTK-based geometry from file.
|
VTK-based geometry from file.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not os.path.isfile(fname): # vtk has a strange error handling
|
if not os.path.isfile(os.path.expanduser(fname)): # vtk has a strange error handling
|
||||||
raise FileNotFoundError(f'No such file: {fname}')
|
raise FileNotFoundError(f'No such file: {fname}')
|
||||||
if (ext := Path(fname).suffix) == '.vtk' or dataset_type is not None:
|
if (ext := Path(fname).suffix) == '.vtk' or dataset_type is not None:
|
||||||
reader = vtk.vtkGenericDataObjectReader()
|
reader = vtk.vtkGenericDataObjectReader()
|
||||||
|
@ -437,7 +437,9 @@ class VTK:
|
||||||
return writer.GetOutputString()
|
return writer.GetOutputString()
|
||||||
|
|
||||||
|
|
||||||
def show(self,label=None,colormap=Colormap.from_predefined('strain')):
|
def show(self,
|
||||||
|
label: str = None,
|
||||||
|
colormap: Colormap = Colormap.from_predefined('viridis')):
|
||||||
"""
|
"""
|
||||||
Render.
|
Render.
|
||||||
|
|
||||||
|
@ -476,7 +478,15 @@ class VTK:
|
||||||
|
|
||||||
ren = vtk.vtkRenderer()
|
ren = vtk.vtkRenderer()
|
||||||
ren.AddActor(actor)
|
ren.AddActor(actor)
|
||||||
ren.SetBackground(67/255,128/255,208/255)
|
if label is None:
|
||||||
|
ren.SetBackground(67/255,128/255,208/255)
|
||||||
|
else:
|
||||||
|
colormap = vtk.vtkScalarBarActor()
|
||||||
|
colormap.SetLookupTable(lut)
|
||||||
|
colormap.SetTitle(label)
|
||||||
|
colormap.SetMaximumWidthInPixels(width//100)
|
||||||
|
ren.AddActor2D(colormap)
|
||||||
|
ren.SetBackground(0.3,0.3,0.3)
|
||||||
|
|
||||||
window = vtk.vtkRenderWindow()
|
window = vtk.vtkRenderWindow()
|
||||||
window.AddRenderer(ren)
|
window.AddRenderer(ren)
|
||||||
|
|
Loading…
Reference in New Issue