Exemplo n.º 1
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkBrownianPoints(), 'Processing.',
         ('vtkDataSet',), ('vtkDataSet',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
Exemplo n.º 2
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkBrownianPoints(),
                                       'Processing.', ('vtkDataSet', ),
                                       ('vtkDataSet', ),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
Exemplo n.º 3
0
def SphereActor(lut, interpolateBeforeMapping):
    ss = vtk.vtkSphereSource()
    if interpolateBeforeMapping:
        ss.SetCenter(-1, 0, 0)

    bp = vtk.vtkBrownianPoints()
    bp.SetInputConnection(ss.GetOutputPort())
    bp.AddObserver(vtk.vtkCommand.EndEvent, SetRandomSeed)

    pm = vtk.vtkPolyDataMapper()
    pm.SetInputConnection(bp.GetOutputPort())
    pm.SetScalarModeToUsePointFieldData()
    pm.SelectColorArray("BrownianVectors")
    pm.SetLookupTable(lut)
    pm.SetInterpolateScalarsBeforeMapping(interpolateBeforeMapping)

    a = vtk.vtkActor()
    a.SetMapper(pm)
    return a
Exemplo n.º 4
0
def SphereActor(lut, interpolateBeforeMapping):
    ss = vtk.vtkSphereSource()
    if interpolateBeforeMapping:
        ss.SetCenter(-1, 0, 0)

    bp = vtk.vtkBrownianPoints()
    bp.SetInputConnection(ss.GetOutputPort())
    bp.AddObserver (vtk.vtkCommand.EndEvent, SetRandomSeed)

    pm = vtk.vtkPolyDataMapper()
    pm.SetInputConnection(bp.GetOutputPort())
    pm.SetScalarModeToUsePointFieldData()
    pm.SelectColorArray("BrownianVectors")
    pm.SetLookupTable(lut)
    pm.SetInterpolateScalarsBeforeMapping(interpolateBeforeMapping)

    a = vtk.vtkActor()
    a.SetMapper(pm)
    return a
Exemplo n.º 5
0
import vtk.test.Testing

try:
    import numpy
except ImportError:
    print("Numpy (http://numpy.scipy.org) not found.")
    print("This test requires numpy!")
    vtk.test.Testing.skip()

import vtk
import vtk.numpy_interface.dataset_adapter as dsa
import vtk.numpy_interface.algorithms as algs

w = vtk.vtkRTAnalyticSource()

bp = vtk.vtkBrownianPoints()
bp.SetInputConnection(w.GetOutputPort())
bp.Update()

elev = vtk.vtkElevationFilter()
elev.SetInputConnection(bp.GetOutputPort())
elev.SetLowPoint(-10, 0, 0)
elev.SetHighPoint(10, 0, 0)
elev.SetScalarRange(0, 20)

g = vtk.vtkMultiBlockDataGroupFilter()
g.AddInputConnection(elev.GetOutputPort())
g.AddInputConnection(elev.GetOutputPort())

g.Update()
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# create a semi-cylinder
#
line = vtk.vtkLineSource()
line.SetPoint1(0, 1, 0)
line.SetPoint2(0, 1, 2)
line.SetResolution(10)

lineSweeper = vtk.vtkRotationalExtrusionFilter()
lineSweeper.SetResolution(20)
lineSweeper.SetInputConnection(line.GetOutputPort())
lineSweeper.SetAngle(270)

bump = vtk.vtkBrownianPoints()
bump.SetInputConnection(lineSweeper.GetOutputPort())

warp = vtk.vtkWarpVector()
warp.SetInputConnection(bump.GetOutputPort())
warp.SetScaleFactor(.2)

smooth = vtk.vtkSmoothPolyDataFilter()
smooth.SetInputConnection(warp.GetOutputPort())
smooth.SetNumberOfIterations(50)
smooth.BoundarySmoothingOn()
smooth.SetFeatureAngle(120)
smooth.SetEdgeAngle(90)
smooth.SetRelaxationFactor(.025)

normals = vtk.vtkPolyDataNormals()
def main():
    # Generate an image data set with multiple attribute arrays to probe and view
    rt = vtk.vtkRTAnalyticSource()
    rt.SetWholeExtent(-3, 3, -3, 3, -3, 3)
    grad = vtk.vtkImageGradient()
    grad.SetDimensionality(3)
    grad.SetInputConnection(rt.GetOutputPort())
    brown = vtk.vtkBrownianPoints()
    brown.SetMinimumSpeed(0.5)
    brown.SetMaximumSpeed(1.0)
    brown.SetInputConnection(grad.GetOutputPort())
    elev = vtk.vtkElevationFilter()
    elev.SetLowPoint(-3, -3, -3)
    elev.SetHighPoint(3, 3, 3)
    elev.SetInputConnection(brown.GetOutputPort())

    # Updating here because I will need to probe scalar ranges before
    # the render window updates the pipeline
    elev.Update()

    # Set up parallel coordinates representation to be used in View
    rep = vtk.vtkParallelCoordinatesRepresentation()
    rep.SetInputConnection(elev.GetOutputPort())
    rep.SetInputArrayToProcess(0, 0, 0, 0, 'RTDataGradient')
    rep.SetInputArrayToProcess(1, 0, 0, 0, 'RTData')
    rep.SetInputArrayToProcess(2, 0, 0, 0, 'Elevation')
    rep.SetInputArrayToProcess(3, 0, 0, 0, 'BrownianVectors')
    rep.SetUseCurves(0)  # set to 1 to use smooth curves
    rep.SetLineOpacity(0.5)

    # Set up the Parallel Coordinates View and hook in representation
    view = vtk.vtkParallelCoordinatesView()
    view.SetRepresentation(rep)
    view.SetInspectMode(view.VTK_INSPECT_SELECT_DATA)
    view.SetBrushOperatorToReplace()
    view.SetBrushModeToLasso()

    # Create a annotation link to access selection in parallel coordinates view
    annotationLink = vtk.vtkAnnotationLink()
    # If you don't set the FieldType explicitly it ends up as UNKNOWN
    # (as of 21 Feb 2010)
    # See vtkSelectionNode doc for field and content type enum values
    annotationLink.GetCurrentSelection().GetNode(0).SetFieldType(1)  # Point
    annotationLink.GetCurrentSelection().GetNode(0).SetContentType(
        4)  # Indices
    # Update before passing annotationLink to vtkExtractSelection
    annotationLink.Update()
    # Connect the annotation link to the parallel coordinates representation
    rep.SetAnnotationLink(annotationLink)

    # Extract portion of data corresponding to parallel coordinates selection
    extract = vtk.vtkExtractSelection()
    extract.SetInputConnection(0, elev.GetOutputPort())
    extract.SetInputConnection(1, annotationLink.GetOutputPort(2))

    def update_render_windows(obj, event):
        """
        Handle updating of RenderWindow since it's not a "View"
        and so not covered by vtkViewUpdater

        :param obj:
        :param event:
        :return:
        """
        # ren.ResetCamera()
        renWin.Render()

    # Set up callback to update 3d render window when selections are changed in
    # parallel coordinates view
    annotationLink.AddObserver("AnnotationChangedEvent", update_render_windows)

    def toggle_inspectors(obj, event):

        if view.GetInspectMode() == 0:
            view.SetInspectMode(1)
        else:
            view.SetInspectMode(0)

    # Set up callback to toggle between inspect modes (manip axes & select data)
    view.GetInteractor().AddObserver("UserEvent", toggle_inspectors)

    # 3D outline of image data bounds
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(elev.GetOutputPort())
    outlineMapper = vtk.vtkPolyDataMapper()
    outlineMapper.SetInputConnection(outline.GetOutputPort())
    outlineActor = vtk.vtkActor()
    outlineActor.SetMapper(outlineMapper)

    # Build the lookup table for the 3d data scalar colors (brown to white)
    lut = vtk.vtkLookupTable()
    lut.SetTableRange(0, 256)
    lut.SetHueRange(0.1, 0.1)
    lut.SetSaturationRange(1.0, 0.1)
    lut.SetValueRange(0.4, 1.0)
    lut.Build()

    # Set up the 3d rendering parameters
    # of the image data which is selected in parallel coordinates
    coloring_by = 'Elevation'
    dataMapper = vtk.vtkDataSetMapper()
    dataMapper.SetInputConnection(extract.GetOutputPort())
    dataMapper.SetScalarModeToUsePointFieldData()
    dataMapper.SetColorModeToMapScalars()
    data = elev.GetOutputDataObject(0).GetPointData()
    dataMapper.ScalarVisibilityOn()
    dataMapper.SetScalarRange(data.GetArray(coloring_by).GetRange())
    dataMapper.SetLookupTable(lut)
    dataMapper.SelectColorArray(coloring_by)
    dataActor = vtk.vtkActor()
    dataActor.SetMapper(dataMapper)
    dataActor.GetProperty().SetRepresentationToPoints()
    dataActor.GetProperty().SetPointSize(10)

    # Set up the 3d render window and add both actors
    ren = vtk.vtkRenderer()
    ren.AddActor(outlineActor)
    ren.AddActor(dataActor)
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    ren.ResetCamera()
    renWin.Render()

    # Finalize parallel coordinates view and start interaction event loop
    view.GetRenderWindow().SetSize(600, 300)
    view.ResetCamera()
    view.Render()
    view.GetInteractor().Start()
    }
  </Shader>
</Material>'''

renWin = vtk.vtkRenderWindow()
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
renderer = vtk.vtkRenderer()
renWin.AddRenderer(renderer)

src1 = vtk.vtkSphereSource()
src1.SetRadius(5)
src1.SetPhiResolution(20)
src1.SetThetaResolution(20)

randomVectors = vtk.vtkBrownianPoints()
randomVectors.SetMinimumSpeed(0)
randomVectors.SetMaximumSpeed(1)
randomVectors.SetInputConnection(src1.GetOutputPort())

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(randomVectors.GetOutputPort())

actor = vtk.vtkActor()
actor.SetMapper(mapper)

# Load the material. Here, we are loading a material
# defined in the VTK Library. One can also specify
# a filename to a material description xml.
actor.GetProperty().LoadMaterialFromString(xmlMaterial)
# Set red color to show if shading fails.
Exemplo n.º 9
0
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren0)
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

ren1.SetActiveCamera(ren0.GetActiveCamera())

# Pipeline stuff. Create a sphere source at high resolution.
sphere = vtk.vtkSphereSource()
sphere.SetThetaResolution(res)
sphere.SetPhiResolution(int(res / 2))

# Add some noise
random = vtk.vtkBrownianPoints()
random.SetInputConnection(sphere.GetOutputPort())
random.SetMinimumSpeed(0.0)
random.SetMaximumSpeed(0.01)

# Now warp the sphere with the noise
warp = vtk.vtkWarpVector()
warp.SetInputConnection(random.GetOutputPort())
warp.SetScaleFactor(1.0)

# Smooth it
smooth = vtk.vtkWindowedSincPolyDataFilter()
smooth.SetInputConnection(warp.GetOutputPort())
smooth.SetNumberOfIterations(20)
smooth.FeatureEdgeSmoothingOff()
smooth.BoundarySmoothingOff()
# data set attributes.
# Use the "u" character to toggle between "inspect modes" on the parallel
# coordinates view (i.e. between selecting data and manipulating axes).
# Lines which are commented out show alternative options.
 
import vtk
 
# Generate an example image data set with multiple attribute arrays to probe
# and view.
# This is where you would put your reader instead of this rt->elev pipeline...
rt = vtk.vtkRTAnalyticSource()
rt.SetWholeExtent(-3, 3, -3, 3, -3, 3)
grad = vtk.vtkImageGradient()
grad.SetDimensionality(3)
grad.SetInputConnection(rt.GetOutputPort())
brown = vtk.vtkBrownianPoints()
brown.SetMinimumSpeed(0.5)
brown.SetMaximumSpeed(1.0)
brown.SetInputConnection(grad.GetOutputPort())
elev = vtk.vtkElevationFilter()
elev.SetLowPoint(-3, -3, -3)
elev.SetHighPoint(3, 3, 3)
elev.SetInputConnection(brown.GetOutputPort())
 
# Set up the parallel coordinates Representation to be used in the View
rep = vtk.vtkParallelCoordinatesRepresentation()
 
# Plug your reader in here for your own data
if vtk.VTK_MAJOR_VERSION <= 5:
    rep.SetInput(elev.GetOutput())
else:
def main():
    colors = vtk.vtkNamedColors()

    # Generate an example image data set with multiple attribute arrays to probe
    # and view.
    # This is where you would put your reader instead of this rt->elev pipeline...
    rt = vtk.vtkRTAnalyticSource()
    rt.SetWholeExtent(-3, 3, -3, 3, -3, 3)
    grad = vtk.vtkImageGradient()
    grad.SetDimensionality(3)
    grad.SetInputConnection(rt.GetOutputPort())
    brown = vtk.vtkBrownianPoints()
    brown.SetMinimumSpeed(0.5)
    brown.SetMaximumSpeed(1.0)
    brown.SetInputConnection(grad.GetOutputPort())
    elev = vtk.vtkElevationFilter()
    elev.SetLowPoint(-3, -3, -3)
    elev.SetHighPoint(3, 3, 3)
    elev.SetInputConnection(brown.GetOutputPort())

    # Set up the parallel coordinates Representation to be used in the View
    rep = vtk.vtkParallelCoordinatesRepresentation()

    # Plug your reader in here for your own data
    rep.SetInputConnection(elev.GetOutputPort())

    # List all of the attribute arrays you want plotted in parallel coordinates
    rep.SetInputArrayToProcess(0, 0, 0, 0, 'RTDataGradient')
    rep.SetInputArrayToProcess(1, 0, 0, 0, 'RTData')
    rep.SetInputArrayToProcess(2, 0, 0, 0, 'Elevation')
    rep.SetInputArrayToProcess(3, 0, 0, 0, 'BrownianVectors')

    rep.SetUseCurves(0)  # set to 1 to use smooth curves
    rep.SetLineOpacity(0.5)
    rep.SetAxisColor(colors.GetColor3d('Gold'))
    rep.SetLineColor(colors.GetColor3d('MistyRose'))

    # Set up the Parallel Coordinates View and hook in the Representation
    view = vtk.vtkParallelCoordinatesView()
    view.SetRepresentation(rep)

    # Inspect Mode determines whether your interactions manipulate the axes or
    # select data
    # view.SetInspectMode(view.VTK_INSPECT_MANIPULATE_AXES)    # VTK_INSPECT_MANIPULATE_AXES = 0,
    view.SetInspectMode(
        view.VTK_INSPECT_SELECT_DATA)  # VTK_INSPECT_SELECT_DATA = 1

    # Brush Mode determines the type of interaction you perform to select data
    view.SetBrushModeToLasso()
    # view.SetBrushModeToAngle()
    # view.SetBrushModeToFunction()
    # view.SetBrushModeToAxisThreshold()  # not implemented yet (as of 21 Feb 2010)

    # Brush Operator determines how each new selection interaction changes
    # selected lines
    # view.SetBrushOperatorToAdd()
    # view.SetBrushOperatorToSubtract()
    # view.SetBrushOperatorToIntersect()
    view.SetBrushOperatorToReplace()

    def ToggleInspectors(obj, event):
        # Define the callback routine which toggles between 'Inspect Modes'
        if view.GetInspectMode() == 0:
            view.SetInspectMode(1)
        else:
            view.SetInspectMode(0)

    # Hook up the callback to toggle between inspect modes
    # (manip axes & select data)
    view.GetInteractor().AddObserver('UserEvent', ToggleInspectors)

    # Set up render window
    view.GetRenderWindow().SetSize(600, 300)
    view.GetRenderWindow().SetWindowName('ParallelCoordinatesView')
    view.GetRenderer().GradientBackgroundOn()
    view.GetRenderer().SetBackground2(colors.GetColor3d('DarkBlue'))
    view.GetRenderer().SetBackground(colors.GetColor3d('MidnightBlue'))
    view.ResetCamera()
    view.Render()

    # Start interaction event loop
    view.GetInteractor().Start()
    }
  </Shader>
</Material>"""

renWin = vtk.vtkRenderWindow()
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
renderer = vtk.vtkRenderer()
renWin.AddRenderer(renderer)

src1 = vtk.vtkSphereSource()
src1.SetRadius(5)
src1.SetPhiResolution(20)
src1.SetThetaResolution(20)

randomVectors = vtk.vtkBrownianPoints()
randomVectors.SetMinimumSpeed(0)
randomVectors.SetMaximumSpeed(1)
randomVectors.SetInputConnection(src1.GetOutputPort())

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(randomVectors.GetOutputPort())

actor = vtk.vtkActor()
actor.SetMapper(mapper)

# Load the material. Here, we are loading a material
# defined in the VTK Library. One can also specify
# a filename to a material description xml.
actor.GetProperty().LoadMaterialFromString(xmlMaterial)
# Set red color to show if shading fails.