Skip to content

ProbeCombustor

vtk-examples/Python/VisualizationAlgorithms/ProbeCombustor

Description

Probing obtains dataset attributes by sampling one dataset (the input) with a set of points (the probe). Probing is also called “resampling.” Examples include probing an input dataset with a sequence of points along a line, on a plane, or in a volume. The result of the probing is a new dataset (the output) with the topological and geometric structure of the probe dataset, and point attributes interpolated from the input dataset. Once the probing operation is completed, the output dataset can be visualized with any of the appropriate techniques in VTK.

This example illustrates the details of the probing process. For every point in the probe dataset, the location in the input dataset (i.e., cell, subcell, and parametric coordinates) and interpolation weights are determined. Then the data values from the cell are interpolated to the probe point. Probe points that are outside the input dataset are assigned a nil (or appropriate) value. This process repeats for all points in the probe dataset.

Other languages

See (Cxx)

Question

If you have a question about this example, please use the VTK Discourse Forum

Code

ProbeCombustor.py

#!/usr/bin/env python

# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkCommonTransforms import vtkTransform
from vtkmodules.vtkFiltersCore import (
    vtkAppendPolyData,
    vtkContourFilter,
    vtkProbeFilter,
    vtkStructuredGridOutlineFilter
)
from vtkmodules.vtkFiltersGeneral import vtkTransformPolyDataFilter
from vtkmodules.vtkFiltersModeling import vtkOutlineFilter
from vtkmodules.vtkFiltersSources import vtkPlaneSource
from vtkmodules.vtkIOParallel import vtkMultiBlockPLOT3DReader
from vtkmodules.vtkRenderingCore import (
    vtkActor,
    vtkPolyDataMapper,
    vtkRenderWindow,
    vtkRenderWindowInteractor,
    vtkRenderer
)


def main():
    colors = vtkNamedColors()

    fileName1, fileName2 = get_program_parameters()

    # Create the pipeline.
    #
    pl3d = vtkMultiBlockPLOT3DReader()
    pl3d.SetXYZFileName(fileName1)
    pl3d.SetQFileName(fileName2)
    pl3d.SetScalarFunctionNumber(100)
    pl3d.SetVectorFunctionNumber(202)
    pl3d.Update()

    sg = pl3d.GetOutput().GetBlock(0)

    # We create three planes and position them in the correct position
    # using transform filters. They are then appended together and used as
    # a probe.
    plane = vtkPlaneSource()
    plane.SetResolution(50, 50)

    transP1 = vtkTransform()
    transP1.Translate(3.7, 0.0, 28.37)
    transP1.Scale(5, 5, 5)
    transP1.RotateY(90)

    tpd1 = vtkTransformPolyDataFilter()
    tpd1.SetInputConnection(plane.GetOutputPort())
    tpd1.SetTransform(transP1)

    outTpd1 = vtkOutlineFilter()
    outTpd1.SetInputConnection(tpd1.GetOutputPort())

    mapTpd1 = vtkPolyDataMapper()
    mapTpd1.SetInputConnection(outTpd1.GetOutputPort())

    tpd1Actor = vtkActor()
    tpd1Actor.SetMapper(mapTpd1)
    tpd1Actor.GetProperty().SetColor(0, 0, 0)
    tpd1Actor.GetProperty().SetLineWidth(2.0)

    transP2 = vtkTransform()
    transP2.Translate(9.2, 0.0, 31.20)
    transP2.Scale(5, 5, 5)
    transP2.RotateY(90)

    tpd2 = vtkTransformPolyDataFilter()
    tpd2.SetInputConnection(plane.GetOutputPort())
    tpd2.SetTransform(transP2)

    outTpd2 = vtkOutlineFilter()
    outTpd2.SetInputConnection(tpd2.GetOutputPort())

    mapTpd2 = vtkPolyDataMapper()
    mapTpd2.SetInputConnection(outTpd2.GetOutputPort())

    tpd2Actor = vtkActor()
    tpd2Actor.SetMapper(mapTpd2)
    tpd2Actor.GetProperty().SetColor(0, 0, 0)
    tpd2Actor.GetProperty().SetLineWidth(2.0)

    transP3 = vtkTransform()
    transP3.Translate(13.27, 0.0, 33.30)
    transP3.Scale(5, 5, 5)
    transP3.RotateY(90)

    tpd3 = vtkTransformPolyDataFilter()
    tpd3.SetInputConnection(plane.GetOutputPort())
    tpd3.SetTransform(transP3)

    outTpd3 = vtkOutlineFilter()
    outTpd3.SetInputConnection(tpd3.GetOutputPort())

    mapTpd3 = vtkPolyDataMapper()
    mapTpd3.SetInputConnection(outTpd3.GetOutputPort())

    tpd3Actor = vtkActor()
    tpd3Actor.SetMapper(mapTpd3)
    tpd3Actor.GetProperty().SetColor(0, 0, 0)
    tpd3Actor.GetProperty().SetLineWidth(2.0)

    appendF = vtkAppendPolyData()
    appendF.AddInputConnection(tpd1.GetOutputPort())
    appendF.AddInputConnection(tpd2.GetOutputPort())
    appendF.AddInputConnection(tpd3.GetOutputPort())

    # The vtkProbeFilter takes two inputs. One is a dataset to use as the probe
    # geometry (SetInputConnection) the other is the data to probe
    # (SetSourceConnection). The output dataset structure (geometry and
    # topology) of the probe is the same as the structure of the input. The
    # probing process generates new data values resampled from the source.
    probe = vtkProbeFilter()
    probe.SetInputConnection(appendF.GetOutputPort())
    probe.SetSourceData(sg)

    contour = vtkContourFilter()
    contour.SetInputConnection(probe.GetOutputPort())
    contour.GenerateValues(50, sg.GetScalarRange())

    contourMapper = vtkPolyDataMapper()
    contourMapper.SetInputConnection(contour.GetOutputPort())
    contourMapper.SetScalarRange(sg.GetScalarRange())

    planeActor = vtkActor()
    planeActor.SetMapper(contourMapper)

    outline = vtkStructuredGridOutlineFilter()
    outline.SetInputData(sg)

    outlineMapper = vtkPolyDataMapper()
    outlineMapper.SetInputConnection(outline.GetOutputPort())

    outlineActor = vtkActor()
    outlineActor.SetMapper(outlineMapper)
    outlineActor.GetProperty().SetColor(0, 0, 0)
    outlineActor.GetProperty().SetLineWidth(2.0)

    # Create the RenderWindow, Renderer and both Actors
    #
    ren1 = vtkRenderer()
    renWin = vtkRenderWindow()
    renWin.AddRenderer(ren1)
    iren = vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    ren1.AddActor(outlineActor)
    ren1.AddActor(planeActor)
    ren1.AddActor(tpd1Actor)
    ren1.AddActor(tpd2Actor)
    ren1.AddActor(tpd3Actor)
    ren1.SetBackground(colors.GetColor3d('Gainsboro'))
    renWin.SetSize(640, 480)
    renWin.SetWindowName('ProbeCombustor')

    ren1.ResetCamera()
    ren1.GetActiveCamera().SetClippingRange(3.95297, 50)
    ren1.GetActiveCamera().SetFocalPoint(8.88908, 0.595038, 29.3342)
    ren1.GetActiveCamera().SetPosition(-12.3332, 31.7479, 41.2387)
    ren1.GetActiveCamera().SetViewUp(0.060772, -0.319905, 0.945498)

    renWin.Render()
    iren.Start()


def get_program_parameters():
    import argparse
    description = 'This shows how to probe a dataset with a plane. The probed data is then contoured. '
    epilogue = '''

    '''
    parser = argparse.ArgumentParser(description=description, epilog=epilogue,
                                     formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('filename1', help='combxyz.bin.')
    parser.add_argument('filename2', help='combq.bin.')
    args = parser.parse_args()
    return args.filename1, args.filename2


if __name__ == '__main__':
    main()