Skip to content
Snippets Groups Projects
Commit 8dd3a553 authored by Andrew Maclean's avatar Andrew Maclean
Browse files

VolumeRendering updated

parent f5acfeb6
Branches dev/0.0.3
No related tags found
1 merge request!237Only allow specific imports for python 7
#!/usr/bin/env python
import vtkmodules.all as vtk
# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkCommonCore import vtkLookupTable
from vtkmodules.vtkCommonDataModel import vtkPlane
from vtkmodules.vtkFiltersCore import (
vtkContourFilter,
vtkCutter,
vtkPolyDataNormals,
vtkStripper,
vtkStructuredGridOutlineFilter,
vtkTubeFilter
)
from vtkmodules.vtkFiltersExtraction import vtkExtractGrid
from vtkmodules.vtkIOParallel import vtkMultiBlockPLOT3DReader
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkPolyDataMapper,
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkRenderer
)
def main():
xyzFile, qFile = get_program_parameters()
colors = vtk.vtkNamedColors()
colors = vtkNamedColors()
# Create pipeline. Read structured grid data.
#
pl3d = vtk.vtkMultiBlockPLOT3DReader()
pl3d = vtkMultiBlockPLOT3DReader()
pl3d.SetXYZFileName(xyzFile)
pl3d.SetQFileName(qFile)
pl3d.SetScalarFunctionNumber(100)
......@@ -20,50 +43,50 @@ def main():
pl3dOutput = pl3d.GetOutput().GetBlock(0)
# A convenience, use this filter to limit data for experimentation.
extract = vtk.vtkExtractGrid()
extract = vtkExtractGrid()
extract.SetVOI(1, 55, -1000, 1000, -1000, 1000)
extract.SetInputData(pl3dOutput)
# The (implicit) plane is used to do the cutting
plane = vtk.vtkPlane()
plane = vtkPlane()
plane.SetOrigin(0, 4, 2)
plane.SetNormal(0, 1, 0)
# The cutter is set up to process each contour value over all cells
# (SetSortByToSortByCell). This results in an ordered output of polygons
# which is key to the compositing.
cutter = vtk.vtkCutter()
cutter = vtkCutter()
cutter.SetInputConnection(extract.GetOutputPort())
cutter.SetCutFunction(plane)
cutter.GenerateCutScalarsOff()
cutter.SetSortByToSortByCell()
clut = vtk.vtkLookupTable()
clut = vtkLookupTable()
clut.SetHueRange(0, 0.67)
clut.Build()
cutterMapper = vtk.vtkPolyDataMapper()
cutterMapper = vtkPolyDataMapper()
cutterMapper.SetInputConnection(cutter.GetOutputPort())
cutterMapper.SetScalarRange(0.18, 0.7)
cutterMapper.SetLookupTable(clut)
cut = vtk.vtkActor()
cut = vtkActor()
cut.SetMapper(cutterMapper)
# Add in some surface geometry for interest.
iso = vtk.vtkContourFilter()
iso = vtkContourFilter()
iso.SetInputData(pl3dOutput)
iso.SetValue(0, .22)
normals = vtk.vtkPolyDataNormals()
normals = vtkPolyDataNormals()
normals.SetInputConnection(iso.GetOutputPort())
normals.SetFeatureAngle(60)
isoMapper = vtk.vtkPolyDataMapper()
isoMapper = vtkPolyDataMapper()
isoMapper.SetInputConnection(normals.GetOutputPort())
isoMapper.ScalarVisibilityOff()
isoActor = vtk.vtkActor()
isoActor = vtkActor()
isoActor.SetMapper(isoMapper)
isoActor.GetProperty().SetDiffuseColor(colors.GetColor3d('Tomato'))
isoActor.GetProperty().SetSpecularColor(colors.GetColor3d('White'))
......@@ -71,29 +94,29 @@ def main():
isoActor.GetProperty().SetSpecular(0.5)
isoActor.GetProperty().SetSpecularPower(30)
outline = vtk.vtkStructuredGridOutlineFilter()
outline = vtkStructuredGridOutlineFilter()
outline.SetInputData(pl3dOutput)
outlineStrip = vtk.vtkStripper()
outlineStrip = vtkStripper()
outlineStrip.SetInputConnection(outline.GetOutputPort())
outlineTubes = vtk.vtkTubeFilter()
outlineTubes = vtkTubeFilter()
outlineTubes.SetInputConnection(outline.GetOutputPort())
outlineTubes.SetInputConnection(outlineStrip.GetOutputPort())
outlineTubes.SetRadius(0.1)
outlineMapper = vtk.vtkPolyDataMapper()
outlineMapper = vtkPolyDataMapper()
outlineMapper.SetInputConnection(outlineTubes.GetOutputPort())
outlineActor = vtk.vtkActor()
outlineActor = vtkActor()
outlineActor.SetMapper(outlineMapper)
# Create the RenderWindow, Renderer and Interactor.
#
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
ren1 = vtkRenderer()
renWin = vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
......
#!/usr/bin/env python
import vtkmodules.all as vtk
# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkCommonDataModel import vtkPiecewiseFunction
from vtkmodules.vtkIOLegacy import vtkStructuredPointsReader
from vtkmodules.vtkRenderingCore import (
vtkColorTransferFunction,
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkRenderer,
vtkVolume,
vtkVolumeProperty
)
from vtkmodules.vtkRenderingVolume import vtkFixedPointVolumeRayCastMapper
# noinspection PyUnresolvedReferences
from vtkmodules.vtkRenderingVolumeOpenGL2 import vtkOpenGLRayCastImageDisplayHelper
def main():
fileName = get_program_parameters()
colors = vtk.vtkNamedColors()
colors = vtkNamedColors()
# This is a simple volume rendering example that
# uses a vtkFixedPointVolumeRayCastMapper
# Create the standard renderer, render window
# and interactor.
ren1 = vtk.vtkRenderer()
ren1 = vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin = vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# Create the reader for the data.
reader = vtk.vtkStructuredPointsReader()
reader = vtkStructuredPointsReader()
reader.SetFileName(fileName)
# Create transfer mapping scalar value to opacity.
opacityTransferFunction = vtk.vtkPiecewiseFunction()
opacityTransferFunction = vtkPiecewiseFunction()
opacityTransferFunction.AddPoint(20, 0.0)
opacityTransferFunction.AddPoint(255, 0.2)
# Create transfer mapping scalar value to color.
colorTransferFunction = vtk.vtkColorTransferFunction()
colorTransferFunction = vtkColorTransferFunction()
colorTransferFunction.AddRGBPoint(0.0, 0.0, 0.0, 0.0)
colorTransferFunction.AddRGBPoint(64.0, 1.0, 0.0, 0.0)
colorTransferFunction.AddRGBPoint(128.0, 0.0, 0.0, 1.0)
......@@ -39,19 +54,19 @@ def main():
colorTransferFunction.AddRGBPoint(255.0, 0.0, 0.2, 0.0)
# The property describes how the data will look.
volumeProperty = vtk.vtkVolumeProperty()
volumeProperty = vtkVolumeProperty()
volumeProperty.SetColor(colorTransferFunction)
volumeProperty.SetScalarOpacity(opacityTransferFunction)
volumeProperty.ShadeOn()
volumeProperty.SetInterpolationTypeToLinear()
# The mapper / ray cast function know how to render the data.
volumeMapper = vtk.vtkFixedPointVolumeRayCastMapper()
volumeMapper = vtkFixedPointVolumeRayCastMapper()
volumeMapper.SetInputConnection(reader.GetOutputPort())
# The volume holds the mapper and the property and
# can be used to position/orient the volume.
volume = vtk.vtkVolume()
volume = vtkVolume()
volume.SetMapper(volumeMapper)
volume.SetProperty(volumeProperty)
......@@ -77,7 +92,7 @@ def get_program_parameters():
'''
parser = argparse.ArgumentParser(description=description, epilog=epilogue,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('filename', help='ironProt.vtk.')
parser.add_argument('filename', help='ironProt.vtk')
args = parser.parse_args()
return args.filename
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment