def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkThresholdTextureCoords(), 'Processing.', ('vtkDataSet',), ('vtkDataSet',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def main(): dataFn1, dataFn2, textureFn = get_program_parameters() colors = vtk.vtkNamedColors() # Read the data. pl3d = vtk.vtkMultiBlockPLOT3DReader() pl3d.SetXYZFileName(dataFn1) pl3d.SetQFileName(dataFn2) pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() output = pl3d.GetOutput().GetBlock(0) # Make the wall (floor). wall = vtk.vtkStructuredGridGeometryFilter() wall.SetInputData(output) wall.SetExtent(0, 100, 0, 0, 0, 100) wallMap = vtk.vtkPolyDataMapper() wallMap.SetInputConnection(wall.GetOutputPort()) wallMap.ScalarVisibilityOff() wallActor = vtk.vtkActor() wallActor.SetMapper(wallMap) wallActor.GetProperty().SetColor(colors.GetColor3d('PeachPuff')) # Make the fin (rear wall) fin = vtk.vtkStructuredGridGeometryFilter() fin.SetInputData(output) fin.SetExtent(0, 100, 0, 100, 0, 0) finMap = vtk.vtkPolyDataMapper() finMap.SetInputConnection(fin.GetOutputPort()) finMap.ScalarVisibilityOff() finActor = vtk.vtkActor() finActor.SetMapper(finMap) finActor.GetProperty().SetColor(colors.GetColor3d('DarkSlateGray')) # Get the texture. tmap = vtk.vtkStructuredPointsReader() tmap.SetFileName(textureFn) texture = vtk.vtkTexture() texture.SetInputConnection(tmap.GetOutputPort()) texture.InterpolateOff() texture.RepeatOff() # Create the rendering window, renderer, and interactive renderer. ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Make the planes to threshold and texture. plane = list() thresh = list() planeMap = list() planeActor = list() # Define the extents of planes that we will use. planeExtents = [[10, 10, 0, 100, 0, 100], [30, 30, 0, 100, 0, 100], [35, 35, 0, 100, 0, 100]] # Now set up the pipeline. for i in range(0, len(planeExtents)): plane.append(vtk.vtkStructuredGridGeometryFilter()) plane[i].SetInputData(output) plane[i].SetExtent(*planeExtents[i]) thresh.append(vtk.vtkThresholdTextureCoords()) thresh[i].SetInputConnection(plane[i].GetOutputPort()) thresh[i].SetInputConnection(plane[i].GetOutputPort()) # If you want an image similar to Fig 9-43(a) in the VTK textbook, # set thresh[i].ThresholdByUpper(1.5) for all planes. if i == 1: thresh[i].ThresholdByLower(1.5) elif i == 2: thresh[i].ThresholdBetween(1.5, 1.8) else: thresh[i].ThresholdByUpper(1.5) planeMap.append(vtk.vtkDataSetMapper()) planeMap[i].SetInputConnection(thresh[i].GetOutputPort()) planeMap[i].SetScalarRange(output.GetScalarRange()) planeActor.append(vtk.vtkActor()) planeActor[i].SetMapper(planeMap[i]) planeActor[i].SetTexture(texture) # The slight transparency gives a nice effect. planeActor[i].GetProperty().SetOpacity(0.999) ren.AddActor(planeActor[i]) # Get an outline of the data set for context. outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(output) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineProp = outlineActor.GetProperty() outlineProp.SetColor(colors.GetColor3d('Black')) # Add the remaining actors to the renderer, set the background and size. ren.AddActor(outlineActor) ren.AddActor(wallActor) ren.AddActor(finActor) ren.SetBackground(colors.GetColor3d('MistyRose')) renWin.SetSize(512, 512) renWin.SetWindowName('TextureThreshold') cam = vtk.vtkCamera() cam.SetClippingRange(1.51176, 75.5879) cam.SetFocalPoint(2.33749, 2.96739, 3.61023) cam.SetPosition(10.8787, 5.27346, 15.8687) cam.SetViewAngle(30) cam.SetViewUp(-0.0610856, 0.987798, -0.143262) ren.SetActiveCamera(cam) iren.Initialize() iren.Start()
finMap.SetInputConnection(fin.GetOutputPort()) finMap.ScalarVisibilityOff() finActor = vtk.vtkActor() finActor.SetMapper(finMap) finActor.GetProperty().SetColor(0.8, 0.8, 0.8) # planes to threshold tmap = vtk.vtkStructuredPointsReader() tmap.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/texThres2.vtk") texture = vtk.vtkTexture() texture.SetInputConnection(tmap.GetOutputPort()) texture.InterpolateOff() texture.RepeatOff() plane1 = vtk.vtkStructuredGridGeometryFilter() plane1.SetInputData(output) plane1.SetExtent(10, 10, 0, 100, 0, 100) thresh1 = vtk.vtkThresholdTextureCoords() thresh1.SetInputConnection(plane1.GetOutputPort()) thresh1.ThresholdByUpper(1.5) plane1Map = vtk.vtkDataSetMapper() plane1Map.SetInputConnection(thresh1.GetOutputPort()) plane1Map.SetScalarRange(output.GetScalarRange()) plane1Actor = vtk.vtkActor() plane1Actor.SetMapper(plane1Map) plane1Actor.SetTexture(texture) plane1Actor.GetProperty().SetOpacity(0.999) plane2 = vtk.vtkStructuredGridGeometryFilter() plane2.SetInputData(output) plane2.SetExtent(30, 30, 0, 100, 0, 100) thresh2 = vtk.vtkThresholdTextureCoords() thresh2.SetInputConnection(plane2.GetOutputPort()) thresh2.ThresholdByLower(1.5)
finMap.SetInputConnection(fin.GetOutputPort()) finMap.ScalarVisibilityOff() finActor = vtk.vtkActor() finActor.SetMapper(finMap) finActor.GetProperty().SetColor(0.8,0.8,0.8) # planes to threshold tmap = vtk.vtkStructuredPointsReader() tmap.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/texThres2.vtk") texture = vtk.vtkTexture() texture.SetInputConnection(tmap.GetOutputPort()) texture.InterpolateOff() texture.RepeatOff() plane1 = vtk.vtkStructuredGridGeometryFilter() plane1.SetInputData(output) plane1.SetExtent(10,10,0,100,0,100) thresh1 = vtk.vtkThresholdTextureCoords() thresh1.SetInputConnection(plane1.GetOutputPort()) thresh1.ThresholdByUpper(1.5) plane1Map = vtk.vtkDataSetMapper() plane1Map.SetInputConnection(thresh1.GetOutputPort()) plane1Map.SetScalarRange(output.GetScalarRange()) plane1Actor = vtk.vtkActor() plane1Actor.SetMapper(plane1Map) plane1Actor.SetTexture(texture) plane1Actor.GetProperty().SetOpacity(0.999) plane2 = vtk.vtkStructuredGridGeometryFilter() plane2.SetInputData(output) plane2.SetExtent(30,30,0,100,0,100) thresh2 = vtk.vtkThresholdTextureCoords() thresh2.SetInputConnection(plane2.GetOutputPort()) thresh2.ThresholdByLower(1.5)