This script does not work! Remember what we learned about the vtk pipeline and how the data is exchanged between the different parts of the pipeline and fix it!. Once you fix it, write a brief description of what you did to fix it. Also embed an image of the result in your notebook (Tip. Use the vtk_show
function).
In [7]:
import vtk
In [8]:
pl3d = vtk.vtkMultiBlockPLOT3DReader()
xyx_file = "data/combxyz.bin"
q_file = "data/combq.bin"
pl3d.SetXYZFileName(xyx_file)
pl3d.SetQFileName(q_file)
pl3d.SetScalarFunctionNumber(100)
pl3d.SetVectorFunctionNumber(202)
pl3d.Update()
In [9]:
b0 = blocks.GetBlock(0)
points = vtk.vtkVertexGlyphFilter()
points.SetInputData(b0)
outline = vtk.vtkStructuredGridOutlineFilter()
outline.SetInputData(b0)
blocks = pl3d.GetOutput()
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
renderWindow.SetInteractor(interactor)
renderer.AddActor(outlineActor)
outlineActor = vtk.vtkActor()
outlineActor.SetMapper(outlineMapper)
outlineActor.GetProperty().SetColor(1,1,1)
outlineMapper = vtk.vtkPolyDataMapper()
outlineMapper.SetInputConnection(outline.GetOutputPort())
scalarsMapper = vtk.vtkPolyDataMapper()
scalarsMapper.SetInputConnection(points.GetOutputPort())
scalarsMapper.SetScalarModeToUsePointData()
scalarsActor = vtk.vtkActor()
scalarsActor.SetMapper(scalarsMapper)
renderer.SetBackground(0.2,0.2,0.2)
interactor.SetRenderWindow(renderWindow)
interactor.Start()
In [14]:
# VTK module is already imported from the previous challenge so we do not need to do it again
# create a reader for your unstructured_grid
ugridReader = vtk.vtkUnstructuredGridReader()
ugridReader.SetFileName("data/exercise_op1.vtk")
ugridReader.Update()
ugrid = ugridReader.GetOutput()
scalarRange = ugrid.GetScalarRange()
# mapper
ugridMapper = vtk.vtkDataSetMapper()
ugridMapper.SetInputData(ugrid)
#ugridMapper.SetScalarModeToUseCellData()
#ugridMapper.SetScalarModeToUsePointData()
ugridMapper.SetScalarRange(scalarRange)
# actor
ugridActor = vtk.vtkActor()
ugridActor.SetMapper(ugridMapper)
# create a rendering window and renderer
renderer = vtk.vtkRenderer()
renderer.SetBackground(0.5, 0.5, 0.5)
renderer.AddActor(ugridActor)
renderWindow = vtk.vtkRenderWindow()
renderWindow.SetSize(500, 500)
renderWindow.AddRenderer(renderer)
renderWindow.Render()
# create and enable a renderWindowInteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renderWindow)
iren.Start()
In [ ]: