mirror of
https://github.com/OpenFOAM/ThirdParty-6.git
synced 2025-12-08 06:57:43 +00:00
ParaView-5.0.1: Added the source-tree to ThirdParty-dev and patched as described in the README file
Resolves bug-report http://bugs.openfoam.org/view.php?id=2098
This commit is contained in:
124
ParaView-5.0.1/VTK/Examples/VolumeRendering/Python/PseudoVolumeRendering.py
Executable file
124
ParaView-5.0.1/VTK/Examples/VolumeRendering/Python/PseudoVolumeRendering.py
Executable file
@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Perform psuedo volume rendering in a structured grid by compositing
|
||||
# translucent cut planes. This same trick can be used for unstructured
|
||||
# grids. Note that for better results, more planes can be created. Also,
|
||||
# if your data is vtkImageData, there are much faster methods for volume
|
||||
# rendering.
|
||||
|
||||
import vtk
|
||||
from vtk.util.colors import *
|
||||
from vtk.util.misc import vtkGetDataRoot
|
||||
VTK_DATA_ROOT = vtkGetDataRoot()
|
||||
|
||||
# Create pipeline. Read structured grid data.
|
||||
pl3d = vtk.vtkMultiBlockPLOT3DReader()
|
||||
pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin")
|
||||
pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin")
|
||||
pl3d.SetScalarFunctionNumber(100)
|
||||
pl3d.SetVectorFunctionNumber(202)
|
||||
pl3d.Update()
|
||||
|
||||
pl3d_output = pl3d.GetOutput().GetBlock(0)
|
||||
|
||||
# A convenience, use this filter to limit data for experimentation.
|
||||
extract = vtk.vtkExtractGrid()
|
||||
extract.SetVOI(1, 55, -1000, 1000, -1000, 1000)
|
||||
extract.SetInputData(pl3d_output)
|
||||
|
||||
# The (implicit) plane is used to do the cutting
|
||||
plane = vtk.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.SetInputConnection(extract.GetOutputPort())
|
||||
cutter.SetCutFunction(plane)
|
||||
cutter.GenerateCutScalarsOff()
|
||||
cutter.SetSortByToSortByCell()
|
||||
|
||||
clut = vtk.vtkLookupTable()
|
||||
clut.SetHueRange(0, .67)
|
||||
clut.Build()
|
||||
|
||||
cutterMapper = vtk.vtkPolyDataMapper()
|
||||
cutterMapper.SetInputConnection(cutter.GetOutputPort())
|
||||
cutterMapper.SetScalarRange(.18, .7)
|
||||
cutterMapper.SetLookupTable(clut)
|
||||
|
||||
cut = vtk.vtkActor()
|
||||
cut.SetMapper(cutterMapper)
|
||||
|
||||
# Add in some surface geometry for interest.
|
||||
iso = vtk.vtkContourFilter()
|
||||
iso.SetInputData(pl3d_output)
|
||||
iso.SetValue(0, .22)
|
||||
normals = vtk.vtkPolyDataNormals()
|
||||
normals.SetInputConnection(iso.GetOutputPort())
|
||||
normals.SetFeatureAngle(45)
|
||||
isoMapper = vtk.vtkPolyDataMapper()
|
||||
isoMapper.SetInputConnection(normals.GetOutputPort())
|
||||
isoMapper.ScalarVisibilityOff()
|
||||
isoActor = vtk.vtkActor()
|
||||
isoActor.SetMapper(isoMapper)
|
||||
isoActor.GetProperty().SetDiffuseColor(tomato)
|
||||
isoActor.GetProperty().SetSpecularColor(white)
|
||||
isoActor.GetProperty().SetDiffuse(.8)
|
||||
isoActor.GetProperty().SetSpecular(.5)
|
||||
isoActor.GetProperty().SetSpecularPower(30)
|
||||
|
||||
outline = vtk.vtkStructuredGridOutlineFilter()
|
||||
outline.SetInputData(pl3d_output)
|
||||
outlineTubes = vtk.vtkTubeFilter()
|
||||
outlineTubes.SetInputConnection(outline.GetOutputPort())
|
||||
outlineTubes.SetRadius(.1)
|
||||
|
||||
outlineMapper = vtk.vtkPolyDataMapper()
|
||||
outlineMapper.SetInputConnection(outlineTubes.GetOutputPort())
|
||||
outlineActor = vtk.vtkActor()
|
||||
outlineActor.SetMapper(outlineMapper)
|
||||
|
||||
# Create the RenderWindow, Renderer and Interactor
|
||||
ren = vtk.vtkRenderer()
|
||||
renWin = vtk.vtkRenderWindow()
|
||||
renWin.AddRenderer(ren)
|
||||
iren = vtk.vtkRenderWindowInteractor()
|
||||
iren.SetRenderWindow(renWin)
|
||||
|
||||
# Add the actors to the renderer, set the background and size
|
||||
ren.AddActor(outlineActor)
|
||||
outlineActor.GetProperty().SetColor(banana)
|
||||
ren.AddActor(isoActor)
|
||||
isoActor.VisibilityOn()
|
||||
ren.AddActor(cut)
|
||||
opacity = .1
|
||||
cut.GetProperty().SetOpacity(1)
|
||||
ren.SetBackground(1, 1, 1)
|
||||
renWin.SetSize(640, 480)
|
||||
|
||||
cam1 = ren.GetActiveCamera()
|
||||
cam1.SetClippingRange(3.95297, 50)
|
||||
cam1.SetFocalPoint(9.71821, 0.458166, 29.3999)
|
||||
cam1.SetPosition(2.7439, -37.3196, 38.7167)
|
||||
cam1.ComputeViewPlaneNormal()
|
||||
cam1.SetViewUp(-0.16123, 0.264271, 0.950876)
|
||||
|
||||
# Cut: generates n cut planes normal to camera's view plane
|
||||
def Cut(n):
|
||||
global cam1, opacity
|
||||
plane.SetNormal(cam1.GetViewPlaneNormal())
|
||||
plane.SetOrigin(cam1.GetFocalPoint())
|
||||
cutter.GenerateValues(n, -5, 5)
|
||||
clut.SetAlphaRange(opacity, opacity)
|
||||
renWin.Render()
|
||||
|
||||
|
||||
# Generate 10 cut planes
|
||||
Cut(20)
|
||||
|
||||
iren.Initialize()
|
||||
renWin.Render()
|
||||
iren.Start()
|
||||
66
ParaView-5.0.1/VTK/Examples/VolumeRendering/Python/SimpleRayCast.py
Executable file
66
ParaView-5.0.1/VTK/Examples/VolumeRendering/Python/SimpleRayCast.py
Executable file
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# This is a simple volume rendering example that uses a
|
||||
# vtkVolumeRayCast mapper
|
||||
|
||||
import vtk
|
||||
from vtk.util.misc import vtkGetDataRoot
|
||||
VTK_DATA_ROOT = vtkGetDataRoot()
|
||||
|
||||
# Create the standard renderer, render window and interactor
|
||||
ren = vtk.vtkRenderer()
|
||||
renWin = vtk.vtkRenderWindow()
|
||||
renWin.AddRenderer(ren)
|
||||
iren = vtk.vtkRenderWindowInteractor()
|
||||
iren.SetRenderWindow(renWin)
|
||||
|
||||
# Create the reader for the data
|
||||
reader = vtk.vtkStructuredPointsReader()
|
||||
reader.SetFileName(VTK_DATA_ROOT + "/Data/ironProt.vtk")
|
||||
|
||||
# Create transfer mapping scalar value to opacity
|
||||
opacityTransferFunction = vtk.vtkPiecewiseFunction()
|
||||
opacityTransferFunction.AddPoint(20, 0.0)
|
||||
opacityTransferFunction.AddPoint(255, 0.2)
|
||||
|
||||
# Create transfer mapping scalar value to color
|
||||
colorTransferFunction = vtk.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)
|
||||
colorTransferFunction.AddRGBPoint(192.0, 0.0, 1.0, 0.0)
|
||||
colorTransferFunction.AddRGBPoint(255.0, 0.0, 0.2, 0.0)
|
||||
|
||||
# The property describes how the data will look
|
||||
volumeProperty = vtk.vtkVolumeProperty()
|
||||
volumeProperty.SetColor(colorTransferFunction)
|
||||
volumeProperty.SetScalarOpacity(opacityTransferFunction)
|
||||
volumeProperty.ShadeOn()
|
||||
volumeProperty.SetInterpolationTypeToLinear()
|
||||
|
||||
# The mapper / ray cast function know how to render the data
|
||||
compositeFunction = vtk.vtkVolumeRayCastCompositeFunction()
|
||||
volumeMapper = vtk.vtkVolumeRayCastMapper()
|
||||
volumeMapper.SetVolumeRayCastFunction(compositeFunction)
|
||||
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.SetMapper(volumeMapper)
|
||||
volume.SetProperty(volumeProperty)
|
||||
|
||||
ren.AddVolume(volume)
|
||||
ren.SetBackground(1, 1, 1)
|
||||
renWin.SetSize(600, 600)
|
||||
renWin.Render()
|
||||
|
||||
def CheckAbort(obj, event):
|
||||
if obj.GetEventPending() != 0:
|
||||
obj.SetAbortRender(1)
|
||||
|
||||
renWin.AddObserver("AbortCheckEvent", CheckAbort)
|
||||
|
||||
iren.Initialize()
|
||||
renWin.Render()
|
||||
iren.Start()
|
||||
60
ParaView-5.0.1/VTK/Examples/VolumeRendering/Python/SimpleTextureMap2D.py
Executable file
60
ParaView-5.0.1/VTK/Examples/VolumeRendering/Python/SimpleTextureMap2D.py
Executable file
@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# This is a simple volume rendering example that uses a
|
||||
# vtkVolumeTextureMapper2D mapper
|
||||
|
||||
import vtk
|
||||
from vtk.util.misc import vtkGetDataRoot
|
||||
VTK_DATA_ROOT = vtkGetDataRoot()
|
||||
|
||||
# Create the standard renderer, render window and interactor
|
||||
ren = vtk.vtkRenderer()
|
||||
renWin = vtk.vtkRenderWindow()
|
||||
renWin.AddRenderer(ren)
|
||||
iren = vtk.vtkRenderWindowInteractor()
|
||||
iren.SetRenderWindow(renWin)
|
||||
|
||||
# Create the reader for the data
|
||||
reader = vtk.vtkStructuredPointsReader()
|
||||
reader.SetFileName(VTK_DATA_ROOT + "/Data/ironProt.vtk")
|
||||
|
||||
# Create transfer mapping scalar value to opacity
|
||||
opacityTransferFunction = vtk.vtkPiecewiseFunction()
|
||||
opacityTransferFunction.AddPoint(20, 0.0)
|
||||
opacityTransferFunction.AddPoint(255, 0.2)
|
||||
|
||||
# Create transfer mapping scalar value to color
|
||||
colorTransferFunction = vtk.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)
|
||||
colorTransferFunction.AddRGBPoint(192.0, 0.0, 1.0, 0.0)
|
||||
colorTransferFunction.AddRGBPoint(255.0, 0.0, 0.2, 0.0)
|
||||
|
||||
# The property describes how the data will look
|
||||
volumeProperty = vtk.vtkVolumeProperty()
|
||||
volumeProperty.SetColor(colorTransferFunction)
|
||||
volumeProperty.SetScalarOpacity(opacityTransferFunction)
|
||||
|
||||
# The mapper knows how to render the data
|
||||
volumeMapper = vtk.vtkVolumeTextureMapper2D()
|
||||
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.SetMapper(volumeMapper)
|
||||
volume.SetProperty(volumeProperty)
|
||||
|
||||
ren.AddVolume(volume)
|
||||
renWin.Render()
|
||||
|
||||
def CheckAbort(obj, event):
|
||||
if obj.GetEventPending() != 0:
|
||||
obj.SetAbortRender(1)
|
||||
|
||||
renWin.AddObserver("AbortCheckEvent", CheckAbort)
|
||||
|
||||
iren.Initialize()
|
||||
renWin.Render()
|
||||
iren.Start()
|
||||
209
ParaView-5.0.1/VTK/Examples/VolumeRendering/Python/VolumePicker.py
Executable file
209
ParaView-5.0.1/VTK/Examples/VolumeRendering/Python/VolumePicker.py
Executable file
@ -0,0 +1,209 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
##
|
||||
# This is an example of how to use the vtkVolumePicker.
|
||||
##
|
||||
|
||||
import math
|
||||
import vtk
|
||||
from vtk.util.misc import vtkGetDataRoot
|
||||
VTK_DATA_ROOT = vtkGetDataRoot()
|
||||
|
||||
#---------------------------------------------------------
|
||||
# renderer and interactor
|
||||
ren = vtk.vtkRenderer()
|
||||
renWin = vtk.vtkRenderWindow()
|
||||
renWin.AddRenderer(ren)
|
||||
iren = vtk.vtkRenderWindowInteractor()
|
||||
iren.SetRenderWindow(renWin)
|
||||
|
||||
#---------------------------------------------------------
|
||||
# read the volume
|
||||
reader = vtk.vtkImageReader2()
|
||||
reader.SetDataExtent(0,63,0,63,0,92)
|
||||
reader.SetFileNameSliceOffset(1)
|
||||
reader.SetDataScalarTypeToUnsignedShort()
|
||||
reader.SetDataByteOrderToLittleEndian()
|
||||
reader.SetFilePrefix(str(VTK_DATA_ROOT) + "/Data/headsq/quarter")
|
||||
reader.SetDataSpacing(3.2,3.2,1.5)
|
||||
|
||||
#---------------------------------------------------------
|
||||
# set up the volume rendering
|
||||
volumeMapper = vtk.vtkVolumeTextureMapper3D()
|
||||
volumeMapper.SetInputConnection(reader.GetOutputPort())
|
||||
volumeMapper.CroppingOn()
|
||||
volumeMapper.SetCroppingRegionPlanes((0.0, 141.6, 0.0, 201.6, 0.0, 138.0))
|
||||
|
||||
volumeColor = vtk.vtkColorTransferFunction()
|
||||
volumeColor.AddRGBPoint(0,0.0,0.0,0.0)
|
||||
volumeColor.AddRGBPoint(180,0.3,0.1,0.2)
|
||||
volumeColor.AddRGBPoint(1000,1.0,0.7,0.6)
|
||||
volumeColor.AddRGBPoint(2000,1.0,1.0,0.9)
|
||||
|
||||
volumeScalarOpacity = vtk.vtkPiecewiseFunction()
|
||||
volumeScalarOpacity.AddPoint(0,0.0)
|
||||
volumeScalarOpacity.AddPoint(180,0.0)
|
||||
volumeScalarOpacity.AddPoint(1000,0.2)
|
||||
volumeScalarOpacity.AddPoint(2000,0.8)
|
||||
|
||||
volumeGradientOpacity = vtk.vtkPiecewiseFunction()
|
||||
volumeGradientOpacity.AddPoint(0,0.0)
|
||||
volumeGradientOpacity.AddPoint(90,0.5)
|
||||
volumeGradientOpacity.AddPoint(100,1.0)
|
||||
|
||||
volumeProperty = vtk.vtkVolumeProperty()
|
||||
volumeProperty.SetColor(volumeColor)
|
||||
volumeProperty.SetScalarOpacity(volumeScalarOpacity)
|
||||
volumeProperty.SetGradientOpacity(volumeGradientOpacity)
|
||||
volumeProperty.SetInterpolationTypeToLinear()
|
||||
volumeProperty.ShadeOff()
|
||||
volumeProperty.SetAmbient(0.6)
|
||||
volumeProperty.SetDiffuse(0.6)
|
||||
volumeProperty.SetSpecular(0.1)
|
||||
|
||||
volume = vtk.vtkVolume()
|
||||
volume.SetMapper(volumeMapper)
|
||||
volume.SetProperty(volumeProperty)
|
||||
|
||||
#---------------------------------------------------------
|
||||
# Do the surface rendering
|
||||
boneExtractor = vtk.vtkMarchingCubes()
|
||||
boneExtractor.SetInputConnection(reader.GetOutputPort())
|
||||
boneExtractor.SetValue(0,1150)
|
||||
|
||||
boneNormals = vtk.vtkPolyDataNormals()
|
||||
boneNormals.SetInputConnection(boneExtractor.GetOutputPort())
|
||||
boneNormals.SetFeatureAngle(60.0)
|
||||
|
||||
boneStripper = vtk.vtkStripper()
|
||||
boneStripper.SetInputConnection(boneNormals.GetOutputPort())
|
||||
|
||||
boneLocator = vtk.vtkCellLocator()
|
||||
boneLocator.SetDataSet(boneExtractor.GetOutput())
|
||||
boneLocator.LazyEvaluationOn()
|
||||
|
||||
boneMapper = vtk.vtkPolyDataMapper()
|
||||
boneMapper.SetInputConnection(boneStripper.GetOutputPort())
|
||||
boneMapper.ScalarVisibilityOff()
|
||||
|
||||
boneProperty = vtk.vtkProperty()
|
||||
boneProperty.SetColor(1.0,1.0,0.9)
|
||||
|
||||
bone = vtk.vtkActor()
|
||||
bone.SetMapper(boneMapper)
|
||||
bone.SetProperty(boneProperty)
|
||||
|
||||
#---------------------------------------------------------
|
||||
# Create an image actor
|
||||
table = vtk.vtkLookupTable()
|
||||
table.SetRange(0,2000)
|
||||
table.SetRampToLinear()
|
||||
table.SetValueRange(0,1)
|
||||
table.SetHueRange(0,0)
|
||||
table.SetSaturationRange(0,0)
|
||||
|
||||
mapToColors = vtk.vtkImageMapToColors()
|
||||
mapToColors.SetInputConnection(reader.GetOutputPort())
|
||||
mapToColors.SetLookupTable(table)
|
||||
mapToColors.Update()
|
||||
|
||||
imageActor = vtk.vtkImageActor()
|
||||
imageActor.GetMapper().SetInputConnection(mapToColors.GetOutputPort())
|
||||
imageActor.SetDisplayExtent(32,32,0,63,0,92)
|
||||
|
||||
#---------------------------------------------------------
|
||||
# make a transform and some clipping planes
|
||||
transform = vtk.vtkTransform()
|
||||
transform.RotateWXYZ(-20,0.0,-0.7,0.7)
|
||||
|
||||
volume.SetUserTransform(transform)
|
||||
bone.SetUserTransform(transform)
|
||||
imageActor.SetUserTransform(transform)
|
||||
|
||||
c = volume.GetCenter()
|
||||
|
||||
volumeClip = vtk.vtkPlane()
|
||||
volumeClip.SetNormal(0,1,0)
|
||||
volumeClip.SetOrigin(c[0],c[1],c[2])
|
||||
|
||||
boneClip = vtk.vtkPlane()
|
||||
boneClip.SetNormal(1,0,0)
|
||||
boneClip.SetOrigin(c[0],c[1],c[2])
|
||||
|
||||
volumeMapper.AddClippingPlane(volumeClip)
|
||||
boneMapper.AddClippingPlane(boneClip)
|
||||
|
||||
#---------------------------------------------------------
|
||||
ren.AddViewProp(volume)
|
||||
ren.AddViewProp(bone)
|
||||
ren.AddViewProp(imageActor)
|
||||
|
||||
camera = ren.GetActiveCamera()
|
||||
camera.SetFocalPoint(c[0],c[1],c[2])
|
||||
camera.SetPosition(c[0] + 500,c[1] - 100,c[2] - 100)
|
||||
camera.SetViewUp(0,0,-1)
|
||||
|
||||
renWin.Render()
|
||||
|
||||
#---------------------------------------------------------
|
||||
# the cone points along the -x axis
|
||||
coneSource = vtk.vtkConeSource()
|
||||
coneSource.CappingOn()
|
||||
coneSource.SetHeight(12)
|
||||
coneSource.SetRadius(5)
|
||||
coneSource.SetResolution(31)
|
||||
coneSource.SetCenter(6,0,0)
|
||||
coneSource.SetDirection(-1,0,0)
|
||||
|
||||
coneMapper = vtk.vtkDataSetMapper()
|
||||
coneMapper.SetInputConnection(coneSource.GetOutputPort())
|
||||
|
||||
redCone = vtk.vtkActor()
|
||||
redCone.PickableOff()
|
||||
redCone.SetMapper(coneMapper)
|
||||
redCone.GetProperty().SetColor(1,0,0)
|
||||
|
||||
greenCone = vtk.vtkActor()
|
||||
greenCone.PickableOff()
|
||||
greenCone.SetMapper(coneMapper)
|
||||
greenCone.GetProperty().SetColor(0,1,0)
|
||||
|
||||
# Add the two cones (or just one, if you want)
|
||||
ren.AddViewProp(redCone)
|
||||
ren.AddViewProp(greenCone)
|
||||
|
||||
#---------------------------------------------------------
|
||||
# the picker
|
||||
picker = vtk.vtkVolumePicker()
|
||||
picker.SetTolerance(1e-6)
|
||||
picker.SetVolumeOpacityIsovalue(0.1)
|
||||
# locator is optional, but improves performance for large polydata
|
||||
picker.AddLocator(boneLocator)
|
||||
|
||||
# A function to point an actor along a vector
|
||||
def PointCone(actor,nx,ny,nz):
|
||||
actor.SetOrientation(0.0, 0.0, 0.0)
|
||||
n = math.sqrt(nx**2 + ny**2 + nz**2)
|
||||
if (nx < 0.0):
|
||||
actor.RotateWXYZ(180, 0, 1, 0)
|
||||
n = -n
|
||||
actor.RotateWXYZ(180, (nx+n)*0.5, ny*0.5, nz*0.5)
|
||||
|
||||
# A function to move the cursor with the mouse
|
||||
def MoveCursor(iren,event=""):
|
||||
renWin.HideCursor()
|
||||
x,y = iren.GetEventPosition()
|
||||
picker.Pick(x, y, 0, ren)
|
||||
p = picker.GetPickPosition()
|
||||
n = picker.GetPickNormal()
|
||||
redCone.SetPosition(p[0],p[1],p[2])
|
||||
PointCone(redCone,n[0],n[1],n[2])
|
||||
greenCone.SetPosition(p[0],p[1],p[2])
|
||||
PointCone(greenCone,-n[0],-n[1],-n[2])
|
||||
iren.Render()
|
||||
|
||||
#---------------------------------------------------------
|
||||
# custom interaction
|
||||
iren.AddObserver("MouseMoveEvent", MoveCursor)
|
||||
|
||||
iren.Start()
|
||||
Reference in New Issue
Block a user