예제 #1
0
    def _updateActorPolydata(self, actor, polydata, color):
        # Modifies an actor with new polydata
        bounds = polydata.GetBounds()

        # Generate colors
        colors = vtk.vtkElevationFilter()
        #colors.SetInputData(polydata)
        if vtk.VTK_MAJOR_VERSION <= 5:
            colors.SetInputConnection(polydata.GetProducerPort())
        else:
            colors.SetInputData(polydata)
        colors.SetLowPoint(0, 0, bounds[5])
        colors.SetHighPoint(0, 0, bounds[4])
        colors.SetScalarRange(color)
        # Visualization
        mapper = actor.GetMapper()
        if mapper == None:
            mapper = vtk.vtkPolyDataMapper()
        if vtk.VTK_MAJOR_VERSION <= 5:
            mapper.SetInput(colors.GetOutput())
        else:
            colors.Update()
            mapper.SetInputData(colors.GetOutput())

        actor.SetMapper(mapper)
        transform = vtk.vtkTransform()
        actor.SetPosition(transform.GetPosition())
        actor.SetOrientation(transform.GetOrientation())
        size = 4 / len(str(polydata.GetNumberOfPoints())) + 1
        actor.GetProperty().SetPointSize(size)
예제 #2
0
    def _test(self, fname):
        reader = vtk.vtkXMLUnstructuredGridReader()
        reader.SetFileName(VTK_DATA_ROOT + fname)

        elev = vtk.vtkElevationFilter()
        elev.SetInputConnection(reader.GetOutputPort())
        elev.SetLowPoint(-0.05, 0.05, 0)
        elev.SetHighPoint(0.05, 0.05, 0)

        grad = vtk.vtkGradientFilter()
        grad.SetInputConnection(elev.GetOutputPort())
        grad.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, "Elevation")

        grad.Update()

        vals = (10, 0, 0)

        for i in range(3):
            r = grad.GetOutput().GetPointData().GetArray("Gradients").GetRange(i)

            self.assertTrue(abs(r[0] - vals[i]) < 1E-4)
            self.assertTrue(abs(r[1] - vals[i]) < 1E-4)

        elev.SetLowPoint(0.05, -0.05, 0)
        elev.SetHighPoint(0.05, 0.05, 0)
        grad.Update()

        vals = (0, 10, 0)

        for i in range(3):
            r = grad.GetOutput().GetPointData().GetArray("Gradients").GetRange(i)

            self.assertTrue(abs(r[0] - vals[i]) < 1E-4)
            self.assertTrue(abs(r[1] - vals[i]) < 1E-4)
예제 #3
0
    def SuperquadricSource():
        """
        Make a torus as the source.
        """
        source = vtk.vtkSuperquadricSource()
        source.SetCenter(0.0, 0.0, 0.0)
        source.SetScale(1.0, 1.0, 1.0)
        source.SetPhiResolution(64)
        source.SetThetaResolution(64)
        source.SetThetaRoundness(1)
        source.SetThickness(0.5)
        source.SetSize(10)
        source.SetToroidal(1)

        # The quadric is made of strips, so pass it through a triangle filter as
        # the curvature filter only operates on polys
        tri = vtk.vtkTriangleFilter()
        tri.SetInputConnection(source.GetOutputPort())

        # The quadric has nasty discontinuities from the way the edges are generated
        # so let's pass it though a CleanPolyDataFilter and merge any points which
        # are coincident, or very close
        cleaner = vtk.vtkCleanPolyData()
        cleaner.SetInputConnection(tri.GetOutputPort())
        cleaner.SetTolerance(0.005)
        cleaner.Update()
        cleanerBounds = cleaner.GetOutput().GetBounds()

        elev = vtk.vtkElevationFilter()
        elev.SetInputConnection(cleaner.GetOutputPort())
        elev.SetLowPoint(0, cleanerBounds[2], 0)
        elev.SetHighPoint(0, cleanerBounds[3], 0)
        elev.Update()
        return elev
예제 #4
0
def main():
    colors = vtk.vtkNamedColors()
    renderer = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(renderer)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    sphere = vtk.vtkSphereSource()
    sphere.SetPhiResolution(12)
    sphere.SetThetaResolution(12)

    colorIt = vtk.vtkElevationFilter()
    colorIt.SetInputConnection(sphere.GetOutputPort())
    colorIt.SetLowPoint(0, 0, -1)
    colorIt.SetHighPoint(0, 0, 1)

    mapper = vtk.vtkDataSetMapper()
    mapper.SetInputConnection(colorIt.GetOutputPort())

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

    renderer.AddActor(actor)
    renderer.SetBackground(colors.GetColor3d("SlateGray"))
    renWin.SetSize(640, 480)

    renWin.Render()

    # Interact with the data.
    iren.Start()
예제 #5
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkElevationFilter(), 'Processing.',
         ('vtkDataSet',), ('vtkDataSet',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
예제 #6
0
def main():
    res = 6
    plane = vtk.vtkPlaneSource()
    plane.SetResolution(res, res)
    colors = vtk.vtkElevationFilter()
    colors.SetInputConnection(plane.GetOutputPort())
    colors.SetLowPoint(-0.25, -0.25, -0.25)
    colors.SetHighPoint(0.25, 0.25, 0.25)
    planeMapper = vtk.vtkPolyDataMapper()
    planeMapper.SetInputData(colors.GetPolyDataOutput())
    planeActor = vtk.vtkActor()
    planeActor.SetMapper(planeMapper)
    planeActor.GetProperty().SetRepresentationToWireframe()

    # create simple poly data so we can apply glyph
    squad = vtk.vtkSuperquadricSource()

    def Glyph():
        """
        # procedure for generating glyphs
        :return:
        """
        xyz = glypher.GetPoint()
        x = xyz[0]
        y = xyz[1]
        length = glypher.GetInput(0).GetLength()
        scale = length / (2.0 * res)

        squad.SetScale(scale, scale, scale)
        squad.SetCenter(xyz)
        squad.SetPhiRoundness(abs(x) * 5.0)
        squad.SetThetaRoundness(abs(y) * 5.0)

    glypher = vtk.vtkProgrammableGlyphFilter()
    glypher.SetInputConnection(colors.GetOutputPort())
    glypher.SetSourceConnection(squad.GetOutputPort())
    glypher.SetGlyphMethod(Glyph)
    glyphMapper = vtk.vtkPolyDataMapper()
    glyphMapper.SetInputConnection(glypher.GetOutputPort())
    glyphActor = vtk.vtkActor()
    glyphActor.SetMapper(glyphMapper)

    colors = vtk.vtkNamedColors()

    # Create the rendering stuff
    ren1 = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.SetMultiSamples(0)
    renWin.AddRenderer(ren1)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    ren1.AddActor(planeActor)
    ren1.AddActor(glyphActor)
    ren1.SetBackground(colors.GetColor3d('White'))
    renWin.SetSize(450, 450)
    renWin.Render()

    iren.Start()
예제 #7
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkElevationFilter(),
                                       'Processing.', ('vtkDataSet', ),
                                       ('vtkDataSet', ),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
예제 #8
0
def render_image(png_reader):
    square = 8
    color_map = vtk.vtkLookupTable()
    color_map.SetNumberOfColors(16)
    color_map.SetHueRange(0, 0.667)

    magnitude = vtk.vtkImageMagnitude()
    magnitude.SetInput(png_reader.GetOutput())

    geometry = vtk.vtkImageDataGeometryFilter()
    geometry.SetInput(magnitude.GetOutput())

    warp = vtk.vtkWarpScalar()
    warp.SetInput(geometry.GetOutput())
    warp.SetScaleFactor(0.25)

    merge = vtk.vtkMergeFilter()
    merge.SetGeometry(warp.GetOutput())
    merge.SetScalars(png_reader.GetOutput())

    elevation_mtHood = vtk.vtkElevationFilter()
    elevation_mtHood.SetInput(merge.GetOutput())
    elevation_mtHood.SetLowPoint(0, 0, 0)
    elevation_mtHood.SetHighPoint(0, 0, 50)

    mapper_3D_mtHood = vtk.vtkDataSetMapper()
    mapper_3D_mtHood.SetInput(elevation_mtHood.GetOutput())
    mapper_3D_mtHood.SetLookupTable(color_map)

    mapper_2D_mtHood = vtk.vtkPolyDataMapper2D()
    mapper_2D_mtHood.SetInput(elevation_mtHood.GetOutput())
    mapper_2D_mtHood.SetLookupTable(color_map)
    
    actor_2D_mtHood = vtk.vtkActor2D()
    actor_2D_mtHood.SetMapper(mapper_2D_mtHood)
    actor_2D_mtHood.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay()
    actor_2D_mtHood.GetPositionCoordinate().SetValue(0.25,0.25)
    
    actor_3D_mtHood = vtk.vtkActor()
    actor_3D_mtHood.SetMapper(mapper_3D_mtHood)


    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)

    renderer.AddActor(actor_3D_mtHood)
    renderer.SetBackground(.5, .5, .5)

    renderWindow.SetSize(600, 600)
    renderWindow.Render()
    renderWindowInteractor.Start()
예제 #9
0
def isoFile(filename):

    reader = vtk.vtkStructuredPointsReader()
    reader.SetFileName(filename)
    reader.Update()

    iso = vtk.vtkMarchingCubes()
    iso.SetInput(reader.GetOutput())
    iso.SetValue(0, 0.4)
    poly_map = vtk.vtkPolyDataMapper()
    poly_map.SetInput(iso.GetOutput())

    isoActor = vtk.vtkActor()
    isoActor.SetMapper(poly_map)

    ren.SetBackground(1, 1, 1)

    elevation = vtk.vtkElevationFilter()
    elevation.SetInputConnection(iso.GetOutputPort())
    elevation.ReleaseDataFlagOn()

    normals = vtk.vtkPolyDataNormals()
    normals.SetInput(elevation.GetPolyDataOutput())
    normals.SetFeatureAngle(60)
    normals.ConsistencyOff()
    normals.SplittingOff()
    normals.ReleaseDataFlagOn()

    demMapper = vtk.vtkPolyDataMapper()
    demMapper.SetInputConnection(normals.GetOutputPort())
    demMapper.ImmediateModeRenderingOn()

    demActor = vtk.vtkLODActor()
    demActor.SetMapper(demMapper)
    #ren.AddActor(demActor)

    ren.AddActor(isoActor)

    cam1 = ren.GetActiveCamera()
    cam1.SetViewUp(0, 0, 1)
    cam1.SetFocalPoint(reader.GetOutput().GetCenter())
    cam1.SetPosition(0, 0, 0)

    ren.ResetCamera()
    #Changing Elevation, Azimuth,and Zoom
    elevation = input("Please Enter the Value of Elevation:")
    azimuth = input("Please Enter the Value of Azimuth:")
    zoom = input("Please Enter the Value of Zoom:")

    cam1.Elevation(elevation)
    cam1.Azimuth(azimuth)
    cam1.Zoom(zoom)
예제 #10
0
    def SphereSource():
        sphere = vtk.vtkSphereSource()
        sphere.SetPhiResolution(11)
        sphere.SetThetaResolution(11)
        sphere.Update()
        sphereBounds = sphere.GetOutput().GetBounds()

        elev = vtk.vtkElevationFilter()
        elev.SetInputConnection(sphere.GetOutputPort())
        elev.SetLowPoint(0, sphereBounds[2], 0)
        elev.SetHighPoint(0, sphereBounds[3], 0)
        elev.Update()
        return elev
예제 #11
0
def main():
    colors = vtk.vtkNamedColors()
    renderer = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(renderer)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    sphere = vtk.vtkSphereSource()
    sphere.SetThetaResolution(12)
    sphere.SetPhiResolution(12)

    aTransform = vtk.vtkTransform()
    aTransform.Scale(1, 1.5, 2)

    transFilter = vtk.vtkTransformFilter()
    transFilter.SetInputConnection(sphere.GetOutputPort())
    transFilter.SetTransform(aTransform)

    colorIt = vtk.vtkElevationFilter()
    colorIt.SetInputConnection(transFilter.GetOutputPort())
    colorIt.SetLowPoint(0, 0, -1)
    colorIt.SetHighPoint(0, 0, 1)

    lut = vtk.vtkLookupTable()
    lut.SetHueRange(0.667, 0)
    lut.SetSaturationRange(1, 1)
    lut.SetValueRange(1, 1)

    mapper = vtk.vtkDataSetMapper()
    mapper.SetLookupTable(lut)
    mapper.SetInputConnection(colorIt.GetOutputPort())

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

    renderer.AddActor(actor)
    renderer.SetBackground(colors.GetColor3d("SlateGray"))
    renderer.ResetCamera()
    renderer.GetActiveCamera().Elevation(60.0)
    renderer.GetActiveCamera().Azimuth(30.0)
    renderer.ResetCameraClippingRange()

    renWin.SetSize(640, 480)
    renWin.SetWindowName('TransformSphere')

    renWin.Render()

    # Interact with the data.
    iren.Start()
예제 #12
0
def MakeElevations(src):
    '''
    Generate elevations over the surface.
    :param: src - the vtkPolyData source.
    :return: - vtkPolyData source with elevations.
    '''
    bounds = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    src.GetBounds(bounds)
    elevFilter = vtk.vtkElevationFilter()
    elevFilter.SetInputData(src)
    elevFilter.SetLowPoint(0, bounds[2], 0)
    elevFilter.SetHighPoint(0, bounds[3], 0)
    elevFilter.SetScalarRange(bounds[2], bounds[3])
    elevFilter.Update()
    return elevFilter.GetPolyDataOutput()
def MakeElevations(src):
    '''
    Generate elevations over the surface.
    :param: src - the vtkPolyData source.
    :return: - vtkPolyData source with elevations.
    '''
    bounds = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]
    src.GetBounds(bounds)
    elevFilter = vtk.vtkElevationFilter()
    elevFilter.SetInputData(src)
    elevFilter.SetLowPoint(0, bounds[2], 0)
    elevFilter.SetHighPoint(0, bounds[3], 0)
    elevFilter.SetScalarRange(bounds[2], bounds[3])
    elevFilter.Update()
    return elevFilter.GetPolyDataOutput()
예제 #14
0
def create_grid_actor(grid):
    elevation_filter = vtkElevationFilter()
    elevation_filter.SetInput(grid)
    
    mapper = vtkDataSetMapper()
    mapper.SetInput(elevation_filter.GetOutput())

    actor = vtkActor()
    actor.SetMapper(mapper)

    bounds = actor.GetBounds()
    elevation_filter.SetLowPoint(0, 0, bounds[4])
    elevation_filter.SetHighPoint(0, 0, bounds[5])
    elevation_filter.Update();

    return actor
def render_image(pointset):
    '''
    square = 10
    color_map = vtk.vtkLookupTable()
    color_map.SetNumberOfColors(square * square)
    color_map.SetTableRange(0, square * square - 1)
    for ii in range(0, square):
        for jj in range(0, square):
            color_map.SetTableValue(ii, jj / square, jj / square, ii /square)
    '''

    color_map = vtk.vtkLookupTable()
    color_map.SetNumberOfColors(16)
    color_map.SetHueRange(0, 0.667)

    delaunay = vtk.vtkDelaunay2D()
    delaunay.SetTolerance(0.001)
    delaunay.SetAlpha(18)
    delaunay.SetInput(pointset);
    delaunay.Update();

    elevation_thorax = vtk.vtkElevationFilter()
    elevation_thorax.SetInput(delaunay.GetOutput())
    elevation_thorax.SetLowPoint(0, 0, -25)
    elevation_thorax.SetHighPoint(0, 0, 25)

 
    meshMapper = vtk.vtkPolyDataMapper2D()
    meshMapper.SetInput(elevation_thorax.GetOutput())
    meshMapper.SetLookupTable(color_map)
    #meshMapper.SetScalarRange(0,255)
 
    meshActor = vtk.vtkActor2D()
    meshActor.SetMapper(meshMapper)

    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)
    renderer.AddActor(meshActor)
    #renderer.AddActor(boundaryActor)
    renderer.SetBackground(.5, .5, .5)

    renderWindow.SetSize(600, 600) 
    renderWindow.Render()
    renderWindowInteractor.Start()
예제 #16
0
def render_image(pointset):
    '''
    square = 10
    color_map = vtk.vtkLookupTable()
    color_map.SetNumberOfColors(square * square)
    color_map.SetTableRange(0, square * square - 1)
    for ii in range(0, square):
        for jj in range(0, square):
            color_map.SetTableValue(ii, jj / square, jj / square, ii /square)
    '''

    color_map = vtk.vtkLookupTable()
    color_map.SetNumberOfColors(16)
    color_map.SetHueRange(0, 0.667)

    delaunay = vtk.vtkDelaunay2D()
    delaunay.SetTolerance(0.001)
    delaunay.SetAlpha(18)
    delaunay.SetInput(pointset)
    delaunay.Update()

    elevation_thorax = vtk.vtkElevationFilter()
    elevation_thorax.SetInput(delaunay.GetOutput())
    elevation_thorax.SetLowPoint(0, 0, -25)
    elevation_thorax.SetHighPoint(0, 0, 25)

    meshMapper = vtk.vtkPolyDataMapper2D()
    meshMapper.SetInput(elevation_thorax.GetOutput())
    meshMapper.SetLookupTable(color_map)
    #meshMapper.SetScalarRange(0,255)

    meshActor = vtk.vtkActor2D()
    meshActor.SetMapper(meshMapper)

    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)
    renderer.AddActor(meshActor)
    #renderer.AddActor(boundaryActor)
    renderer.SetBackground(.5, .5, .5)

    renderWindow.SetSize(600, 600)
    renderWindow.Render()
    renderWindowInteractor.Start()
예제 #17
0
    def ConeSource():
        cone = vtk.vtkConeSource()
        cone.SetResolution(6)
        cone.CappingOn()
        cone.Update()
        coneBounds = cone.GetOutput().GetBounds()

        coneNormals = vtk.vtkPolyDataNormals()
        coneNormals.SetInputConnection(cone.GetOutputPort())

        elev = vtk.vtkElevationFilter()
        elev.SetInputConnection(coneNormals.GetOutputPort())
        elev.SetLowPoint(coneBounds[0], 0, 0)
        elev.SetHighPoint(coneBounds[1], 0, 0)

        # vtkButterflySubdivisionFilter and vtkLinearSubdivisionFilter operate on triangles.
        tf = vtk.vtkTriangleFilter()
        tf.SetInputConnection(elev.GetOutputPort())
        tf.Update()
        return tf
예제 #18
0
def main():
    colors = vtk.vtkNamedColors()

    renderer = vtk.vtkRenderer()
    renderer.GetCullers().RemoveAllItems()

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

    sphere = vtk.vtkSphereSource()
    sphere.SetThetaResolution(12)
    sphere.SetPhiResolution(12)

    shrink = vtk.vtkShrinkFilter()
    shrink.SetInputConnection(sphere.GetOutputPort())
    shrink.SetShrinkFactor(0.9)

    colorIt = vtk.vtkElevationFilter()
    colorIt.SetInputConnection(shrink.GetOutputPort())
    colorIt.SetLowPoint(0, 0, -.5)
    colorIt.SetHighPoint(0, 0, .5)

    mapper = vtk.vtkDataSetMapper()
    mapper.SetInputConnection(colorIt.GetOutputPort())

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

    renderer.AddActor(actor)
    renderer.SetBackground(colors.GetColor3d('LavenderBlush'))
    renWin.SetSize(600, 600)
    renWin.SetWindowName('LoopShrink')

    renWin.Render()

    renderer.GetActiveCamera().Zoom(1.5)

    #  Interact with the data.
    iren.Start()
예제 #19
0
    def _test(self, fname):
        reader = vtk.vtkXMLUnstructuredGridReader()
        reader.SetFileName(VTK_DATA_ROOT + fname)

        elev = vtk.vtkElevationFilter()
        elev.SetInputConnection(reader.GetOutputPort())
        elev.SetLowPoint(-0.05, 0.05, 0)
        elev.SetHighPoint(0.05, 0.05, 0)

        grad = vtk.vtkGradientFilter()
        grad.SetInputConnection(elev.GetOutputPort())
        grad.SetInputArrayToProcess(0, 0, 0,
                                    vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS,
                                    "Elevation")

        grad.Update()

        vals = (10, 0, 0)

        for i in range(3):
            r = grad.GetOutput().GetPointData().GetArray("Gradients").GetRange(
                i)

            self.assertTrue(abs(r[0] - vals[i]) < 1E-4)
            self.assertTrue(abs(r[1] - vals[i]) < 1E-4)

        elev.SetLowPoint(0.05, -0.05, 0)
        elev.SetHighPoint(0.05, 0.05, 0)
        grad.Update()

        vals = (0, 10, 0)

        for i in range(3):
            r = grad.GetOutput().GetPointData().GetArray("Gradients").GetRange(
                i)

            self.assertTrue(abs(r[0] - vals[i]) < 1E-4)
            self.assertTrue(abs(r[1] - vals[i]) < 1E-4)
예제 #20
0
def DisplayCone(nc):
    '''
    Create a cone, contour it using the banded contour filter and
        color it with the primary additive and subtractive colors.
    :param: nc: The vtkNamedColor class
    :return: The render window interactor.
    '''
    # Create a cone
    coneSource = vtk.vtkConeSource()
    coneSource.SetCenter(0.0, 0.0, 0.0)
    coneSource.SetRadius(5.0)
    coneSource.SetHeight(10)
    coneSource.SetDirection(0, 1, 0)
    coneSource.Update()

    bounds = [1.0, -1.0, 1.0, -1.0, 1.0, -1.0]
    coneSource.GetOutput().GetBounds(bounds)

    elevation = vtk.vtkElevationFilter()
    elevation.SetInputConnection(coneSource.GetOutputPort())
    elevation.SetLowPoint(0, bounds[2], 0)
    elevation.SetHighPoint(0, bounds[3], 0)

    bcf = vtk.vtkBandedPolyDataContourFilter()
    bcf.SetInputConnection(elevation.GetOutputPort())
    bcf.SetScalarModeToValue()
    bcf.GenerateContourEdgesOn()
    bcf.GenerateValues(7, elevation.GetScalarRange())

    # Build a simple lookup table of
    # primary additive and subtractive colors.
    lut = vtk.vtkLookupTable()
    lut.SetNumberOfTableValues(7)
    # Test setting and getting a color here.
    # We are also modifying alpha.

    # Convert to a list so that
    # SetColor(name,rgba) works.
    rgba = list(nc.GetColor4d("Red"))
    rgba[3] = 0.5
    nc.SetColor("My Red", rgba)
    rgba = nc.GetColor4d("My Red")
    lut.SetTableValue(0, rgba)
    # Does "My Red" match anything?
    match = FindSynonyms(nc, "My Red")
    print("Matching colors to My Red:", match)

    rgba = nc.GetColor4d("DarkGreen")
    rgba[3] = 0.3
    lut.SetTableValue(1, rgba)
    #  Alternatively we can use our wrapper functions:
    lut.SetTableValue(2, nc.GetColor4d("Blue"))
    lut.SetTableValue(3, nc.GetColor4d("Cyan"))
    lut.SetTableValue(4, nc.GetColor4d("Magenta"))
    lut.SetTableValue(5, nc.GetColor4d("Yellow"))
    lut.SetTableValue(6, nc.GetColor4d("White"))
    lut.SetTableRange(elevation.GetScalarRange())
    lut.Build()

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(bcf.GetOutputPort())
    mapper.SetLookupTable(lut)
    mapper.SetScalarModeToUseCellData()

    contourLineMapper = vtk.vtkPolyDataMapper()
    contourLineMapper.SetInputData(bcf.GetContourEdgesOutput())
    contourLineMapper.SetScalarRange(elevation.GetScalarRange())
    contourLineMapper.SetResolveCoincidentTopologyToPolygonOffset()

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

    contourLineActor = vtk.vtkActor()
    actor.SetMapper(mapper)
    contourLineActor.SetMapper(contourLineMapper)
    contourLineActor.GetProperty().SetColor(nc.GetColor3d("black"))

    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)

    renderer.AddActor(actor)
    renderer.AddActor(contourLineActor)
    renderer.SetBackground(nc.GetColor3d("SteelBlue"))

    renderWindow.Render()

    fnsave = "TestNamedColorsIntegration.png"
    renLgeIm = vtk.vtkRenderLargeImage()
    imgWriter = vtk.vtkPNGWriter()
    renLgeIm.SetInput(renderer)
    renLgeIm.SetMagnification(1)
    imgWriter.SetInputConnection(renLgeIm.GetOutputPort())
    imgWriter.SetFileName(fnsave)
    # imgWriter.Write()

    return renderWindowInteractor
예제 #21
0
def main():
    file_name, color_scheme = get_program_parameters()

    color_scheme = abs(color_scheme)
    if color_scheme > 2:
        color_scheme = 0;

    colors = vtk.vtkNamedColors()
    # Set the background color. Match those in VTKTextbook.pdf.
    bkg = map(lambda x: x / 256.0, [25, 51, 102])
    colors.SetColor("BkgColor", *bkg)

    # Read a vtk file
    #
    hawaii = vtk.vtkPolyDataReader()
    hawaii.SetFileName(file_name)
    hawaii.Update()
    bounds = [0.0] * 6
    hawaii.GetOutput().GetBounds(bounds)

    elevation = vtk.vtkElevationFilter()
    elevation.SetInputConnection(hawaii.GetOutputPort())
    elevation.SetLowPoint(0, 0, 0)
    elevation.SetHighPoint(0, 0, 1000)
    elevation.SetScalarRange(0, 1000)

    lut = MakeLUT(color_scheme)

    hawaiiMapper = vtk.vtkDataSetMapper()
    hawaiiMapper.SetInputConnection(elevation.GetOutputPort())
    hawaiiMapper.SetScalarRange(0, 1000)
    hawaiiMapper.ScalarVisibilityOn()
    hawaiiMapper.SetLookupTable(lut)

    hawaiiActor = vtk.vtkActor()
    hawaiiActor.SetMapper(hawaiiMapper)

    # Create the RenderWindow, Renderer and both Actors
    #
    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(hawaiiActor)
    # Match the window shape to the object.
    # renWin.SetSize(500, int(500 * bounds[1] / bounds[3]))
    renWin.SetSize(500, 500)

    iren.Initialize()

    # Render the image.
    # Centered on Honolulu.
    # Diamond Head is the crater lower left.
    # Punchbowl is the crater in the centre.
    renWin.Render()
    ren.SetBackground(colors.GetColor3d("BkgColor"))
    ren.GetActiveCamera().Zoom(1.5)
    ren.GetActiveCamera().Roll(-90)

    renWin.Render()
    iren.Start()
예제 #22
0
def main():
    colors = vtk.vtkNamedColors()

    # Generate an image data set with multiple attribute arrays to probe and view
    # We will glyph these points with cones and scale/orient/color them with the
    # various attributes

    # The Wavelet Source is nice for generating a test vtkImageData set
    rt = vtk.vtkRTAnalyticSource()
    rt.SetWholeExtent(-2, 2, -2, 2, 0, 0)

    # Take the gradient of the only scalar 'RTData' to get a vector attribute
    grad = vtk.vtkImageGradient()
    grad.SetDimensionality(3)
    grad.SetInputConnection(rt.GetOutputPort())

    # Elevation just to generate another scalar attribute that varies nicely over the data range
    elev = vtk.vtkElevationFilter()
    # Elevation values will range from 0 to 1 between the Low and High Points
    elev.SetLowPoint(-2, 0, 0)
    elev.SetHighPoint(2, 0, 0)
    elev.SetInputConnection(grad.GetOutputPort())

    # Generate the cone for the glyphs
    sph = vtk.vtkConeSource()
    sph.SetRadius(0.1)
    sph.SetHeight(0.5)

    # Set up the glyph filter
    glyph = vtk.vtkGlyph3D()
    glyph.SetInputConnection(elev.GetOutputPort())
    glyph.SetSourceConnection(sph.GetOutputPort())
    glyph.ScalingOn()
    glyph.SetScaleModeToScaleByScalar()
    glyph.SetVectorModeToUseVector()
    glyph.OrientOn()

    # Tell the filter to 'clamp' the scalar range
    glyph.ClampingOn()

    # Set the overall (multiplicative) scaling factor
    glyph.SetScaleFactor(1)

    # Set the Range to 'clamp' the data to
    #   -- see equations above for nonintuitive definition of 'clamping'
    # The fact that I'm setting the minimum value of the range below
    #   the minimum of my data (real min=0.0) with the equations above
    #   forces a minimum non-zero glyph size.

    glyph.SetRange(-0.5, 1)  # Change these values to see effect on cone sizes

    # Tell glyph which attribute arrays to use for what
    glyph.SetInputArrayToProcess(0, 0, 0, 0, 'Elevation')  # scalars
    glyph.SetInputArrayToProcess(1, 0, 0, 0, 'RTDataGradient')  # vectors
    # glyph.SetInputArrayToProcess(2,0,0,0,'nothing')		# normals
    glyph.SetInputArrayToProcess(3, 0, 0, 0, 'RTData')  # colors

    # Calling update because I'm going to use the scalar range to set the color map range
    glyph.Update()

    coloring_by = 'RTData'
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(glyph.GetOutputPort())
    mapper.SetScalarModeToUsePointFieldData()
    mapper.SetColorModeToMapScalars()
    mapper.ScalarVisibilityOn()
    mapper.SetScalarRange(
        glyph.GetOutputDataObject(0).GetPointData().GetArray(
            coloring_by).GetRange())
    mapper.SelectColorArray(coloring_by)
    actor = vtk.vtkActor()
    actor.SetMapper(mapper)

    ren = vtk.vtkRenderer()
    ren.AddActor(actor)
    ren.SetBackground(colors.GetColor3d('MidnightBlue'))
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    renWin.SetWindowName('ClampGlyphSizes')

    iren = vtk.vtkRenderWindowInteractor()
    istyle = vtk.vtkInteractorStyleTrackballCamera()
    iren.SetInteractorStyle(istyle)
    iren.SetRenderWindow(renWin)
    ren.ResetCamera()
    renWin.Render()
    iren.Start()
예제 #23
0
shrink16.SetShrinkFactors(16, 16, 1)
shrink16.SetInputConnection(demModel.GetOutputPort())
shrink16.AveragingOn()

geom16 = vtk.vtkImageDataGeometryFilter()
geom16.SetInputConnection(shrink16.GetOutputPort())
geom16.ReleaseDataFlagOn()

warp16 = vtk.vtkWarpScalar()
warp16.SetInputConnection(geom16.GetOutputPort())
warp16.SetNormal(0, 0, 1)
warp16.UseNormalOn()
warp16.SetScaleFactor(Scale)
warp16.ReleaseDataFlagOn()

elevation16 = vtk.vtkElevationFilter()
elevation16.SetInputConnection(warp16.GetOutputPort())
elevation16.SetLowPoint(0, 0, lo)
elevation16.SetHighPoint(0, 0, hi)
elevation16.SetScalarRange(lo, hi)
elevation16.ReleaseDataFlagOn()

normals16 = vtk.vtkPolyDataNormals()
normals16.SetInputConnection(elevation16.GetOutputPort())
normals16.SetFeatureAngle(60)
normals16.ConsistencyOff()
normals16.SplittingOff()
normals16.ReleaseDataFlagOn()

demMapper16 = vtk.vtkPolyDataMapper()
demMapper16.SetInputConnection(normals16.GetOutputPort())
예제 #24
0
    def __init__(self, parent = None):
        super(VTKFrame, self).__init__(parent)

        self.vtkWidget = QVTKRenderWindowInteractor(self)
        vl = QtGui.QVBoxLayout(self)
        vl.addWidget(self.vtkWidget)
        vl.setContentsMargins(0, 0, 0, 0)
 
        self.ren = vtk.vtkRenderer()
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
         
        sphere = vtk.vtkSphereSource()
        sphere.SetCenter(1, 1, 1)
        sphere.SetRadius(1)
        sphere.SetThetaResolution(100)
        sphere.SetPhiResolution(100)
        sphere.Update()
         
        cube = vtk.vtkCubeSource()
        cube.SetBounds(-1,1,-1,1,-1,1)
        cube.Update()
         
        # Create 3D cells so vtkImplicitDataSet evaluates inside vs outside correctly
        tri = vtk.vtkDelaunay3D()
        tri.SetInput(cube.GetOutput())
        tri.BoundingTriangulationOff()
         
        # vtkImplicitDataSet needs some scalars to interpolate to find inside/outside
        elev = vtk.vtkElevationFilter()
        elev.SetInputConnection(tri.GetOutputPort())
         
        implicit = vtk.vtkImplicitDataSet()
        implicit.SetDataSet(elev.GetOutput())
         
        clipper = vtk.vtkClipPolyData()
        clipper.SetClipFunction(implicit)
        clipper.SetInputConnection(sphere.GetOutputPort())
        clipper.InsideOutOn()
        clipper.Update()
         
        # Vis for clipped sphere
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(clipper.GetOutputPort())
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetRepresentationToWireframe()
         
        # Vis for cube so can see it in relation to clipped sphere
        mapper2 = vtk.vtkDataSetMapper()
        mapper2.SetInputConnection(elev.GetOutputPort())
        actor2 = vtk.vtkActor()
        actor2.SetMapper(mapper2)
        #actor2.GetProperty().SetRepresentationToWireframe()
         
        #create renderers and add actors of plane and cube
        self.ren.AddActor(actor)
        self.ren.AddActor(actor2)
        self.ren.SetBackground(0.1, 0.2, 0.4)

        self.ren.ResetCamera()
        self._initialized = False
예제 #25
0
except ImportError:
    print "Numpy (http://numpy.scipy.org) not found.",
    print "This test requires numpy!"
    sys.exit(0)

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()

elev2 = vtk.vtkElevationFilter()
elev2.SetInputConnection(bp.GetOutputPort())
elev2.SetLowPoint(0, -10, 0)
elev2.SetHighPoint(0, 10, 0)
예제 #26
0
def main():
    input = vtk.vtkPolyData()
    #double bounds[6]

    argc = 1
    if(argc == 1):

        # Create a sphere to warp
        sphere = vtk.vtkSphereSource()
        sphere.SetThetaResolution(51)
        sphere.SetPhiResolution(17)
        sphere.Update()
        bounds = sphere.GetOutput().GetBounds()

        # Generate some scalars on the polydata
        ele = vtk.vtkElevationFilter()
        ele.SetInputConnection(sphere.GetOutputPort())
        ele.SetLowPoint(0,0,-0.5)
        ele.SetHighPoint(0,0,0.5)
        ele.SetLowPoint((bounds[1] + bounds[0]) / 2.0,
                         (bounds[3] + bounds[2]) / 2.0,
                         -bounds[5])
        ele.SetHighPoint((bounds[1] + bounds[0]) / 2.0,
                          (bounds[3] + bounds[2]) / 2.0,
                          bounds[5])

        ele.Update()
        input.ShallowCopy(ele.GetOutput())

    else:
        inputFilename = argv[1]

        reader = vtk.vtkXMLPolyDataReader()
        reader.SetFileName(inputFilename)
        reader.Update()

        input.ShallowCopy(reader.GetOutput())
        bounds = input.GetBounds()


    # Now create a control mesh, in this case a octagon that encloses
    # the point set

    pts = vtk.vtkPoints()
    pts.SetNumberOfPoints(6)
    pts.SetPoint(0,
                  bounds[0] - .1 * (bounds[1] - bounds[0]),
                  (bounds[3] + bounds[2]) / 2.0,
                  (bounds[5] + bounds[4]) / 2.0)
    pts.SetPoint(1,
                  bounds[1] + .1 * (bounds[1] - bounds[0]),
                  (bounds[3] + bounds[2]) / 2.0,
                  (bounds[5] + bounds[4]) / 2.0)
    pts.SetPoint(2,
                  (bounds[1] + bounds[0]) / 2.0,
                  bounds[2] - .1 * (bounds[3] - bounds[2]),
                  (bounds[5] + bounds[4]) / 2.0)
    pts.SetPoint(3,
                  (bounds[1] + bounds[0]) / 2.0,
                  bounds[3] + .1 * (bounds[3] - bounds[2]),
                  (bounds[5] + bounds[4]) / 2.0)
    pts.SetPoint(4,
                  (bounds[1] + bounds[0]) / 2.0,
                  (bounds[3] + bounds[2]) / 2.0,
                  bounds[4] - .1 * (bounds[5] - bounds[4]))
    pts.SetPoint(5,
                  (bounds[1] + bounds[0]) / 2.0,
                  (bounds[3] + bounds[2]) / 2.0,
                  bounds[5] + .1 * (bounds[5] - bounds[4]))

    tris = vtk.vtkCellArray()
    tris.InsertNextCell(3)
    tris.InsertCellPoint(2)
    tris.InsertCellPoint(0)
    tris.InsertCellPoint(4)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(1)
    tris.InsertCellPoint(2)
    tris.InsertCellPoint(4)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(3)
    tris.InsertCellPoint(1)
    tris.InsertCellPoint(4)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(0)
    tris.InsertCellPoint(3)
    tris.InsertCellPoint(4)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(0)
    tris.InsertCellPoint(2)
    tris.InsertCellPoint(5)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(2)
    tris.InsertCellPoint(1)
    tris.InsertCellPoint(5)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(1)
    tris.InsertCellPoint(3)
    tris.InsertCellPoint(5)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(3)
    tris.InsertCellPoint(0)
    tris.InsertCellPoint(5)

    pd = vtk.vtkPolyData()
    pd.SetPoints(pts)
    pd.SetPolys(tris)

    # Display the control mesh
    meshMapper = vtk.vtkPolyDataMapper()
    meshMapper.SetInputData(pd)
    meshActor = vtk.vtkActor()
    meshActor.SetMapper(meshMapper)
    meshActor.GetProperty().SetRepresentationToWireframe()
    meshActor.GetProperty().SetColor(0,0,0)

    # Do the intitial weight generation
    deform = vtk.vtkDeformPointSet()
    deform.SetInputData(input)
    deform.SetControlMeshData(pd)
    deform.Update() # this creates the initial weights

    # Now move one point and deform
    #double controlPoint[3]
    controlPoint = pts.GetPoint(5)
    pts.SetPoint(5, controlPoint[0],
                  controlPoint[1],
                  bounds[5] + .8 * (bounds[5] - bounds[4]))
    pts.Modified()

    # Display the warped polydata
    polyMapper = vtk.vtkPolyDataMapper()
    polyMapper.SetInputConnection(deform.GetOutputPort())
    polyActor = vtk.vtkActor()
    polyActor.SetMapper(polyMapper)

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

    renderer.AddActor(polyActor)
    renderer.AddActor(meshActor)

    renderer.GetActiveCamera().SetPosition(1,1,1)
    renderer.ResetCamera()
    renderer.SetBackground(.2, .3, .4)

    renWin.SetSize(300,300)
    renWin.Render()

    iren.Start()

    return
예제 #27
0
    def testSphereWidget(self):

        # This example demonstrates how to use the vtkSphereWidget to control the
        # position of a light.

        # These are the pre-recorded events
        Recording = \
           "# StreamVersion 1\n\
            CharEvent 23 266 0 0 105 1 i\n\
            KeyReleaseEvent 23 266 0 0 105 1 i\n\
            EnterEvent 69 294 0 0 0 0 i\n\
            MouseMoveEvent 69 294 0 0 0 0 i\n\
            MouseMoveEvent 68 293 0 0 0 0 i\n\
            MouseMoveEvent 67 292 0 0 0 0 i\n\
            MouseMoveEvent 66 289 0 0 0 0 i\n\
            MouseMoveEvent 66 282 0 0 0 0 i\n\
            MouseMoveEvent 66 271 0 0 0 0 i\n\
            MouseMoveEvent 69 253 0 0 0 0 i\n\
            MouseMoveEvent 71 236 0 0 0 0 i\n\
            MouseMoveEvent 74 219 0 0 0 0 i\n\
            MouseMoveEvent 76 208 0 0 0 0 i\n\
            MouseMoveEvent 78 190 0 0 0 0 i\n\
            MouseMoveEvent 78 173 0 0 0 0 i\n\
            MouseMoveEvent 77 162 0 0 0 0 i\n\
            MouseMoveEvent 77 151 0 0 0 0 i\n\
            MouseMoveEvent 77 139 0 0 0 0 i\n\
            MouseMoveEvent 76 125 0 0 0 0 i\n\
            MouseMoveEvent 73 114 0 0 0 0 i\n\
            MouseMoveEvent 73 106 0 0 0 0 i\n\
            MouseMoveEvent 73 101 0 0 0 0 i\n\
            MouseMoveEvent 72 95 0 0 0 0 i\n\
            MouseMoveEvent 72 92 0 0 0 0 i\n\
            MouseMoveEvent 70 89 0 0 0 0 i\n\
            MouseMoveEvent 69 86 0 0 0 0 i\n\
            MouseMoveEvent 67 84 0 0 0 0 i\n\
            MouseMoveEvent 65 81 0 0 0 0 i\n\
            MouseMoveEvent 60 79 0 0 0 0 i\n\
            MouseMoveEvent 59 79 0 0 0 0 i\n\
            MouseMoveEvent 58 79 0 0 0 0 i\n\
            MouseMoveEvent 57 78 0 0 0 0 i\n\
            MouseMoveEvent 55 78 0 0 0 0 i\n\
            MouseMoveEvent 54 77 0 0 0 0 i\n\
            LeftButtonPressEvent 54 77 0 0 0 0 i\n\
            MouseMoveEvent 61 79 0 0 0 0 i\n\
            MouseMoveEvent 67 83 0 0 0 0 i\n\
            MouseMoveEvent 72 88 0 0 0 0 i\n\
            MouseMoveEvent 77 90 0 0 0 0 i\n\
            MouseMoveEvent 78 91 0 0 0 0 i\n\
            MouseMoveEvent 80 92 0 0 0 0 i\n\
            MouseMoveEvent 84 93 0 0 0 0 i\n\
            MouseMoveEvent 85 94 0 0 0 0 i\n\
            MouseMoveEvent 88 97 0 0 0 0 i\n\
            MouseMoveEvent 90 100 0 0 0 0 i\n\
            MouseMoveEvent 92 102 0 0 0 0 i\n\
            MouseMoveEvent 94 103 0 0 0 0 i\n\
            MouseMoveEvent 97 105 0 0 0 0 i\n\
            MouseMoveEvent 101 107 0 0 0 0 i\n\
            MouseMoveEvent 102 109 0 0 0 0 i\n\
            MouseMoveEvent 104 111 0 0 0 0 i\n\
            MouseMoveEvent 108 113 0 0 0 0 i\n\
            MouseMoveEvent 112 115 0 0 0 0 i\n\
            MouseMoveEvent 118 119 0 0 0 0 i\n\
            MouseMoveEvent 118 120 0 0 0 0 i\n\
            MouseMoveEvent 118 123 0 0 0 0 i\n\
            MouseMoveEvent 120 125 0 0 0 0 i\n\
            MouseMoveEvent 122 128 0 0 0 0 i\n\
            MouseMoveEvent 123 129 0 0 0 0 i\n\
            MouseMoveEvent 125 132 0 0 0 0 i\n\
            MouseMoveEvent 125 134 0 0 0 0 i\n\
            MouseMoveEvent 127 138 0 0 0 0 i\n\
            MouseMoveEvent 127 142 0 0 0 0 i\n\
            MouseMoveEvent 127 147 0 0 0 0 i\n\
            MouseMoveEvent 126 152 0 0 0 0 i\n\
            MouseMoveEvent 126 155 0 0 0 0 i\n\
            MouseMoveEvent 125 160 0 0 0 0 i\n\
            MouseMoveEvent 125 167 0 0 0 0 i\n\
            MouseMoveEvent 125 169 0 0 0 0 i\n\
            MouseMoveEvent 125 174 0 0 0 0 i\n\
            MouseMoveEvent 122 179 0 0 0 0 i\n\
            MouseMoveEvent 120 183 0 0 0 0 i\n\
            MouseMoveEvent 116 187 0 0 0 0 i\n\
            MouseMoveEvent 113 192 0 0 0 0 i\n\
            MouseMoveEvent 113 193 0 0 0 0 i\n\
            MouseMoveEvent 111 195 0 0 0 0 i\n\
            MouseMoveEvent 108 198 0 0 0 0 i\n\
            MouseMoveEvent 106 200 0 0 0 0 i\n\
            MouseMoveEvent 104 202 0 0 0 0 i\n\
            MouseMoveEvent 103 203 0 0 0 0 i\n\
            MouseMoveEvent 99 205 0 0 0 0 i\n\
            MouseMoveEvent 97 207 0 0 0 0 i\n\
            MouseMoveEvent 94 208 0 0 0 0 i\n\
            MouseMoveEvent 91 210 0 0 0 0 i\n\
            MouseMoveEvent 89 211 0 0 0 0 i\n\
            MouseMoveEvent 86 211 0 0 0 0 i\n\
            MouseMoveEvent 84 211 0 0 0 0 i\n\
            MouseMoveEvent 80 211 0 0 0 0 i\n\
            MouseMoveEvent 77 211 0 0 0 0 i\n\
            MouseMoveEvent 75 211 0 0 0 0 i\n\
            MouseMoveEvent 71 211 0 0 0 0 i\n\
            MouseMoveEvent 68 211 0 0 0 0 i\n\
            MouseMoveEvent 66 210 0 0 0 0 i\n\
            MouseMoveEvent 62 210 0 0 0 0 i\n\
            MouseMoveEvent 58 209 0 0 0 0 i\n\
            MouseMoveEvent 54 207 0 0 0 0 i\n\
            MouseMoveEvent 52 204 0 0 0 0 i\n\
            MouseMoveEvent 51 203 0 0 0 0 i\n\
            MouseMoveEvent 51 200 0 0 0 0 i\n\
            MouseMoveEvent 48 196 0 0 0 0 i\n\
            MouseMoveEvent 45 187 0 0 0 0 i\n\
            MouseMoveEvent 45 181 0 0 0 0 i\n\
            MouseMoveEvent 44 168 0 0 0 0 i\n\
            MouseMoveEvent 40 161 0 0 0 0 i\n\
            MouseMoveEvent 39 154 0 0 0 0 i\n\
            MouseMoveEvent 38 146 0 0 0 0 i\n\
            MouseMoveEvent 35 131 0 0 0 0 i\n\
            MouseMoveEvent 34 121 0 0 0 0 i\n\
            MouseMoveEvent 34 110 0 0 0 0 i\n\
            MouseMoveEvent 34 103 0 0 0 0 i\n\
            MouseMoveEvent 34 91 0 0 0 0 i\n\
            MouseMoveEvent 34 86 0 0 0 0 i\n\
            MouseMoveEvent 34 73 0 0 0 0 i\n\
            MouseMoveEvent 35 66 0 0 0 0 i\n\
            MouseMoveEvent 37 60 0 0 0 0 i\n\
            MouseMoveEvent 37 53 0 0 0 0 i\n\
            MouseMoveEvent 38 50 0 0 0 0 i\n\
            MouseMoveEvent 38 48 0 0 0 0 i\n\
            MouseMoveEvent 41 45 0 0 0 0 i\n\
            MouseMoveEvent 43 45 0 0 0 0 i\n\
            MouseMoveEvent 44 45 0 0 0 0 i\n\
            MouseMoveEvent 47 43 0 0 0 0 i\n\
            MouseMoveEvent 51 44 0 0 0 0 i\n\
            MouseMoveEvent 54 44 0 0 0 0 i\n\
            MouseMoveEvent 55 44 0 0 0 0 i\n\
            MouseMoveEvent 59 44 0 0 0 0 i\n\
            MouseMoveEvent 64 44 0 0 0 0 i\n\
            MouseMoveEvent 67 44 0 0 0 0 i\n\
            MouseMoveEvent 68 44 0 0 0 0 i\n\
            MouseMoveEvent 71 44 0 0 0 0 i\n\
            MouseMoveEvent 74 44 0 0 0 0 i\n\
            MouseMoveEvent 77 44 0 0 0 0 i\n\
            MouseMoveEvent 80 45 0 0 0 0 i\n\
            MouseMoveEvent 81 45 0 0 0 0 i\n\
            MouseMoveEvent 85 49 0 0 0 0 i\n\
            MouseMoveEvent 89 50 0 0 0 0 i\n\
            MouseMoveEvent 94 52 0 0 0 0 i\n\
            MouseMoveEvent 99 56 0 0 0 0 i\n\
            MouseMoveEvent 104 58 0 0 0 0 i\n\
            MouseMoveEvent 107 61 0 0 0 0 i\n\
            MouseMoveEvent 109 63 0 0 0 0 i\n\
            MouseMoveEvent 109 67 0 0 0 0 i\n\
            MouseMoveEvent 111 83 0 0 0 0 i\n\
            MouseMoveEvent 113 86 0 0 0 0 i\n\
            MouseMoveEvent 113 87 0 0 0 0 i\n\
            MouseMoveEvent 113 89 0 0 0 0 i\n\
            MouseMoveEvent 112 93 0 0 0 0 i\n\
            MouseMoveEvent 112 97 0 0 0 0 i\n\
            MouseMoveEvent 111 104 0 0 0 0 i\n\
            MouseMoveEvent 112 108 0 0 0 0 i\n\
            MouseMoveEvent 116 115 0 0 0 0 i\n\
            MouseMoveEvent 116 123 0 0 0 0 i\n\
            MouseMoveEvent 116 129 0 0 0 0 i\n\
            MouseMoveEvent 119 138 0 0 0 0 i\n\
            MouseMoveEvent 122 141 0 0 0 0 i\n\
            MouseMoveEvent 127 148 0 0 0 0 i\n\
            MouseMoveEvent 128 161 0 0 0 0 i\n\
            MouseMoveEvent 131 166 0 0 0 0 i\n\
            MouseMoveEvent 134 168 0 0 0 0 i\n\
            MouseMoveEvent 135 171 0 0 0 0 i\n\
            MouseMoveEvent 134 174 0 0 0 0 i\n\
            MouseMoveEvent 132 176 0 0 0 0 i\n\
            MouseMoveEvent 132 178 0 0 0 0 i\n\
            MouseMoveEvent 129 180 0 0 0 0 i\n\
            MouseMoveEvent 127 182 0 0 0 0 i\n\
            MouseMoveEvent 124 185 0 0 0 0 i\n\
            MouseMoveEvent 122 186 0 0 0 0 i\n\
            MouseMoveEvent 118 189 0 0 0 0 i\n\
            MouseMoveEvent 114 191 0 0 0 0 i\n\
            MouseMoveEvent 114 193 0 0 0 0 i\n\
            MouseMoveEvent 112 193 0 0 0 0 i\n\
            MouseMoveEvent 111 194 0 0 0 0 i\n\
            MouseMoveEvent 110 197 0 0 0 0 i\n\
            MouseMoveEvent 110 198 0 0 0 0 i\n\
            MouseMoveEvent 109 199 0 0 0 0 i\n\
            MouseMoveEvent 108 200 0 0 0 0 i\n\
            MouseMoveEvent 108 201 0 0 0 0 i\n\
            MouseMoveEvent 108 202 0 0 0 0 i\n\
            MouseMoveEvent 108 203 0 0 0 0 i\n\
            MouseMoveEvent 104 206 0 0 0 0 i\n\
            LeftButtonReleaseEvent 104 206 0 0 0 0 i\n\
            MouseMoveEvent 104 205 0 0 0 0 i\n\
            MouseMoveEvent 104 204 0 0 0 0 i\n\
            MouseMoveEvent 105 205 0 0 0 0 i\n\
            MouseMoveEvent 105 206 0 0 0 0 i\n\
        "

        # Start by loading some data.
        #
        dem = vtk.vtkDEMReader()
        dem.SetFileName(VTK_DATA_ROOT + "/Data/SainteHelens.dem")
        dem.Update()

        Scale = 2
        lut = vtk.vtkLookupTable()
        lut.SetHueRange(0.6, 0)
        lut.SetSaturationRange(1.0, 0)
        lut.SetValueRange(0.5, 1.0)
        lo = Scale * dem.GetElevationBounds()[0]

        hi = Scale * dem.GetElevationBounds()[1]

        shrink = vtk.vtkImageShrink3D()
        shrink.SetShrinkFactors(4, 4, 1)
        shrink.SetInputConnection(dem.GetOutputPort())
        shrink.AveragingOn()

        geom = vtk.vtkImageDataGeometryFilter()
        geom.SetInputConnection(shrink.GetOutputPort())
        geom.ReleaseDataFlagOn()

        warp = vtk.vtkWarpScalar()
        warp.SetInputConnection(geom.GetOutputPort())
        warp.SetNormal(0, 0, 1)
        warp.UseNormalOn()
        warp.SetScaleFactor(Scale)
        warp.ReleaseDataFlagOn()

        elevation = vtk.vtkElevationFilter()
        elevation.SetInputConnection(warp.GetOutputPort())
        elevation.SetLowPoint(0, 0, lo)
        elevation.SetHighPoint(0, 0, hi)
        elevation.SetScalarRange(lo, hi)
        elevation.ReleaseDataFlagOn()

        normals = vtk.vtkPolyDataNormals()
        normals.SetInputConnection(elevation.GetOutputPort())
        normals.SetFeatureAngle(60)
        normals.ConsistencyOff()
        normals.SplittingOff()
        normals.ReleaseDataFlagOn()
        normals.Update()

        demMapper = vtk.vtkPolyDataMapper()
        demMapper.SetInputConnection(normals.GetOutputPort())
        demMapper.SetScalarRange(lo, hi)
        demMapper.SetLookupTable(lut)

        demActor = vtk.vtkActor()
        demActor.SetMapper(demMapper)

        # Create the RenderWindow, Renderer and both Actors
        #
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.SetMultiSamples(0)
        renWin.AddRenderer(ren)
        iRen = vtk.vtkRenderWindowInteractor()
        iRen.SetRenderWindow(renWin)
        iRen.LightFollowCameraOff()

        #    iRen.SetInteractorStyle("")

        # The callback takes two arguments.
        # The first being the object that generates the event and
        # the second argument the event name (which is a string).
        def MoveLight(widget, event_string):
            light.SetPosition(rep.GetHandlePosition())

        # Associate the line widget with the interactor
        rep = vtk.vtkSphereRepresentation()
        rep.SetPlaceFactor(4)
        rep.PlaceWidget(normals.GetOutput().GetBounds())
        rep.HandleVisibilityOn()
        rep.SetRepresentationToWireframe()
        #  rep HandleVisibilityOff
        #  rep HandleTextOff
        sphereWidget = vtk.vtkSphereWidget2()
        sphereWidget.SetInteractor(iRen)
        sphereWidget.SetRepresentation(rep)
        #  sphereWidget.TranslationEnabledOff()
        #  sphereWidget.ScalingEnabledOff()
        sphereWidget.AddObserver("InteractionEvent", MoveLight)

        recorder = vtk.vtkInteractorEventRecorder()
        recorder.SetInteractor(iRen)
        #  recorder.SetFileName("c:/record.log")
        #  recorder.Record()
        recorder.ReadFromInputStringOn()
        recorder.SetInputString(Recording)

        # Add the actors to the renderer, set the background and size
        #
        ren.AddActor(demActor)
        ren.SetBackground(1, 1, 1)
        renWin.SetSize(300, 300)
        ren.SetBackground(0.1, 0.2, 0.4)

        cam1 = ren.GetActiveCamera()
        cam1.SetViewUp(0, 0, 1)
        cam1.SetFocalPoint(dem.GetOutput().GetCenter())
        cam1.SetPosition(1, 0, 0)
        ren.ResetCamera()
        cam1.Elevation(25)
        cam1.Azimuth(125)
        cam1.Zoom(1.25)

        light = vtk.vtkLight()
        light.SetFocalPoint(rep.GetCenter())
        light.SetPosition(rep.GetHandlePosition())
        ren.AddLight(light)

        iRen.Initialize()
        renWin.Render()

        # render the image
        renWin.Render()

        # Actually probe the data
        recorder.Play()

        img_file = "TestSphereWidget.png"
        vtk.test.Testing.compareImage(
            iRen.GetRenderWindow(),
            vtk.test.Testing.getAbsImagePath(img_file),
            threshold=25)
        vtk.test.Testing.interact()
예제 #28
0
def main():
    colors = vtk.vtkNamedColors()

    # The Wavelet Source is nice for generating a test vtkImageData set
    rt = vtk.vtkRTAnalyticSource()
    rt.SetWholeExtent(-2, 2, -2, 2, 0, 0)

    # Take the gradient of the only scalar 'RTData' to get a vector attribute
    grad = vtk.vtkImageGradient()
    grad.SetDimensionality(3)
    grad.SetInputConnection(rt.GetOutputPort())

    # Elevation just to generate another scalar attribute that varies nicely over the data range
    elev = vtk.vtkElevationFilter()
    # Elevation values will range from 0 to 1 between the Low and High Points
    elev.SetLowPoint(-2, -2, 0)
    elev.SetHighPoint(2, 2, 0)
    elev.SetInputConnection(grad.GetOutputPort())

    # Create simple PolyData for glyph table
    cs = vtk.vtkCubeSource()
    cs.SetXLength(0.5)
    cs.SetYLength(1)
    cs.SetZLength(2)
    ss = vtk.vtkSphereSource()
    ss.SetRadius(0.25)
    cs2 = vtk.vtkConeSource()
    cs2.SetRadius(0.25)
    cs2.SetHeight(0.5)

    # Set up the glyph filter
    glyph = vtk.vtkGlyph3D()
    glyph.SetInputConnection(elev.GetOutputPort())

    # Here is where we build the glyph table
    # that will be indexed into according to the IndexMode
    glyph.SetSourceConnection(0, cs.GetOutputPort())
    glyph.SetSourceConnection(1, ss.GetOutputPort())
    glyph.SetSourceConnection(2, cs2.GetOutputPort())

    glyph.ScalingOn()
    glyph.SetScaleModeToScaleByScalar()
    glyph.SetVectorModeToUseVector()
    glyph.OrientOn()
    glyph.SetScaleFactor(1)  # Overall scaling factor
    glyph.SetRange(0, 1)  # Default is (0,1)

    # Tell it to index into the glyph table according to scalars
    glyph.SetIndexModeToScalar()

    # Tell glyph which attribute arrays to use for what
    glyph.SetInputArrayToProcess(0, 0, 0, 0, 'Elevation')  # scalars
    glyph.SetInputArrayToProcess(1, 0, 0, 0, 'RTDataGradient')  # vectors

    coloring_by = 'Elevation'
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(glyph.GetOutputPort())
    mapper.SetScalarModeToUsePointFieldData()
    mapper.SetColorModeToMapScalars()
    mapper.ScalarVisibilityOn()

    # GetRange() call doesn't work because attributes weren't copied to glyphs
    # as they should have been...
    # mapper.SetScalarRange(glyph.GetOutputDataObject(0).GetPointData().GetArray(coloring_by).GetRange())

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

    ren = vtk.vtkRenderer()
    ren.AddActor(actor)
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    iren = vtk.vtkRenderWindowInteractor()
    istyle = vtk.vtkInteractorStyleTrackballCamera()
    iren.SetInteractorStyle(istyle)
    iren.SetRenderWindow(renWin)
    ren.ResetCamera()
    renWin.Render()
    iren.Start()
예제 #29
0
# Description de la scene
L = 10.
P = 5.
H = 4.

##################
# SPHERE
##################

# On cree une source (en l'occurence une sphere pour le pipeline vtk)
sphere = vtk.vtkSphereSource()
sphere.SetPhiResolution( 20 )
sphere.SetThetaResolution( 20 )

#Filtre de coloration
color_filter = vtk.vtkElevationFilter();
color_filter.SetInputConnection(sphere.GetOutputPort())
color_filter.SetLowPoint(0,0,-0.5);
color_filter.SetHighPoint(0,0,0.5);

# table de valeurs 
tv = vtk.vtkLookupTable()
tv.SetHueRange(0.667,0.)
tv.SetSaturationRange(1,1)
tv.SetValueRange(1,1)

# on utiliseur un traceur avec qui colore la sphere selon sa hauteur suivant l'axe
# des z a l'aide d'un filtre de coloration
sphereMapper = vtk.vtkPolyDataMapper()
sphereMapper.SetLookupTable(tv)
sphereMapper.SetInputConnection( color_filter.GetOutputPort() )
예제 #30
0
파일: progGlyphs.py 프로젝트: Guokr1991/VTK
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot

VTK_DATA_ROOT = vtkGetDataRoot()

res = 6
plane = vtk.vtkPlaneSource()
plane.SetResolution(res, res)
colors = vtk.vtkElevationFilter()
colors.SetInputConnection(plane.GetOutputPort())
colors.SetLowPoint(-0.25, -0.25, -0.25)
colors.SetHighPoint(0.25, 0.25, 0.25)
planeMapper = vtk.vtkPolyDataMapper()
planeMapper.SetInputConnection(colors.GetOutputPort())
planeActor = vtk.vtkActor()
planeActor.SetMapper(planeMapper)
planeActor.GetProperty().SetRepresentationToWireframe()
# procedure for generating glyphs
def Glyph(__vtk__temp0=0, __vtk__temp1=0):
    global res
    ptId = glypher.GetPointId()
    pd = glypher.GetPointData()
    xyz = glypher.GetPoint()
    x = lindex(xyz, 0)
    y = lindex(xyz, 1)
    length = glypher.GetInput(0).GetLength()
    scale = expr.expr(globals(), locals(), ["length", "/", "(", "2.0", "*", "res", ")"])
    squad.SetScale(scale, scale, scale)
    squad.SetCenter(xyz)
예제 #31
0
    def test(self):
        '''
          Create a cone, contour it using the banded contour filter and
              color it with the primary additive and subtractive colors.
        '''
        namedColors = vtk.vtkNamedColors()
        # Test printing of the object
        # Uncomment if desired
        #print namedColors

        # How to get a list of colors
        colors = namedColors.GetColorNames()
        colors = colors.split('\n')
        # Uncomment if desired
        #print 'Number of colors:', len(colors)
        #print colors

        # How to get a list of a list of synonyms.
        syn = namedColors.GetSynonyms()
        syn = syn.split('\n\n')
        synonyms = []
        for ele in syn:
            synonyms.append(ele.split('\n'))
        # Uncomment if desired
        #print 'Number of synonyms:', len(synonyms)
        #print synonyms

        # Create a cone
        coneSource = vtk.vtkConeSource()
        coneSource.SetCenter(0.0, 0.0, 0.0)
        coneSource.SetRadius(5.0)
        coneSource.SetHeight(10)
        coneSource.SetDirection(0,1,0)
        coneSource.Update();

        bounds = [1.0,-1.0,1.0,-1.0,1.0,-1.0]
        coneSource.GetOutput().GetBounds(bounds)

        elevation = vtk.vtkElevationFilter()
        elevation.SetInputConnection(coneSource.GetOutputPort());
        elevation.SetLowPoint(0,bounds[2],0);
        elevation.SetHighPoint(0,bounds[3],0);

        bcf = vtk.vtkBandedPolyDataContourFilter()
        bcf.SetInputConnection(elevation.GetOutputPort());
        bcf.SetScalarModeToValue();
        bcf.GenerateContourEdgesOn();
        bcf.GenerateValues(7,elevation.GetScalarRange());

        # Build a simple lookup table of
        # primary additive and subtractive colors.
        lut = vtk.vtkLookupTable()
        lut.SetNumberOfTableValues(7);
        rgba = [0.0,0.0,0.0,1.0]
        # Test setting and getting a color here.
        namedColors.GetColor("Red",rgba);
        namedColors.SetColor("My Red",rgba)
        namedColors.GetColor("My Red",rgba);
        lut.SetTableValue(0,rgba);
        namedColors.GetColor("DarkGreen",rgba);
        lut.SetTableValue(1,rgba);
        namedColors.GetColor("Blue",rgba);
        lut.SetTableValue(2,rgba);
        namedColors.GetColor("Cyan",rgba);
        lut.SetTableValue(3,rgba);
        namedColors.GetColor("Magenta",rgba);
        lut.SetTableValue(4,rgba);
        namedColors.GetColor("Yellow",rgba);
        lut.SetTableValue(5,rgba);
        namedColors.GetColor("White",rgba);
        lut.SetTableValue(6,rgba);
        lut.SetTableRange(elevation.GetScalarRange());
        lut.Build();

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(bcf.GetOutputPort());
        mapper.SetLookupTable(lut);
        mapper.SetScalarModeToUseCellData();

        contourLineMapper = vtk.vtkPolyDataMapper()
        contourLineMapper.SetInputData(bcf.GetContourEdgesOutput());
        contourLineMapper.SetScalarRange(elevation.GetScalarRange());
        contourLineMapper.SetResolveCoincidentTopologyToPolygonOffset();

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

        contourLineActor = vtk.vtkActor()
        contourLineActor.SetMapper(contourLineMapper);
        rgb = [0.0,0.0,0.0]
        namedColors.GetColorRGB("black",rgb)
        contourLineActor.GetProperty().SetColor(rgb);

        renderer = vtk.vtkRenderer()
        renderWindow = vtk.vtkRenderWindow()
        renderWindow.AddRenderer(renderer);
        iRen = vtk.vtkRenderWindowInteractor()
        iRen.SetRenderWindow(renderWindow);

        renderer.AddActor(actor);
        renderer.AddActor(contourLineActor);
        namedColors.GetColorRGB("SteelBlue",rgb)
        renderer.SetBackground(rgb);

        renderWindow.Render();
        img_file = "TestNamedColorsIntegration.png"
        vtk.test.Testing.compareImage(iRen.GetRenderWindow(),vtk.test.Testing.getAbsImagePath(img_file),threshold=25)
        vtk.test.Testing.interact()
예제 #32
0
    def DisplayCone(self):
        ''' 
            Create a cone, contour it using the banded contour filter and
                color it with the primary additive and subtractive colors.
        '''
        #print namedColors
 
        # Create a cone
        coneSource = vtk.vtkConeSource()
        coneSource.SetCenter(0.0, 0.0, 0.0)
        coneSource.SetRadius(5.0)
        coneSource.SetHeight(10)
        coneSource.SetDirection(0,1,0)
        coneSource.Update()
 
        bounds = [1.0,-1.0,1.0,-1.0,1.0,-1.0]
        coneSource.GetOutput().GetBounds(bounds)
 
        elevation = vtk.vtkElevationFilter()
        elevation.SetInputConnection(coneSource.GetOutputPort())
        elevation.SetLowPoint(0,bounds[2],0)
        elevation.SetHighPoint(0,bounds[3],0)
 
        bcf = vtk.vtkBandedPolyDataContourFilter()
        bcf.SetInputConnection(elevation.GetOutputPort())
        bcf.SetScalarModeToValue()
        bcf.GenerateContourEdgesOn()
        bcf.GenerateValues(7,elevation.GetScalarRange())      
 
        # Build a simple lookup table of
        # primary additive and subtractive colors.
        lut = vtk.vtkLookupTable()
        lut.SetNumberOfTableValues(7)
        # Test setting and getting a color here.
        # We are also modifying alpha.
        rgba = self.GetRGBAColor("Red")
        rgba[3] = 0.5
        self.namedColors.SetColor("My Red",rgba)
        rgba = self.GetRGBAColor("My Red")
        lut.SetTableValue(0,rgba)
        # Does "My Red" match anything?
        match = self.FindSynonyms("My Red")
        print "Matching colors to My Red:", match
 
        rgba = self.GetRGBAColor("DarkGreen")
        rgba[3] = 0.3
        lut.SetTableValue(1,rgba)
        #  Alternatively we can use our wrapper functions:
        lut.SetTableValue(2,self.GetRGBAColor("Blue"))
        lut.SetTableValue(3,self.GetRGBAColor("Cyan"))
        lut.SetTableValue(4,self.GetRGBAColor("Magenta"))
        lut.SetTableValue(5,self.GetRGBAColor("Yellow"))
        lut.SetTableValue(6,self.GetRGBAColor("White"))
        lut.SetTableRange(elevation.GetScalarRange())
        lut.Build()
 
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(bcf.GetOutputPort())
        mapper.SetLookupTable(lut)
        mapper.SetScalarModeToUseCellData()
 
        contourLineMapper = vtk.vtkPolyDataMapper()
        contourLineMapper.SetInputData(bcf.GetContourEdgesOutput())
        contourLineMapper.SetScalarRange(elevation.GetScalarRange())
        contourLineMapper.SetResolveCoincidentTopologyToPolygonOffset()
 
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
 
        contourLineActor = vtk.vtkActor()
        actor.SetMapper(mapper)
        contourLineActor.SetMapper(contourLineMapper)
        contourLineActor.GetProperty().SetColor(
            self.GetRGBColor("black"))
 
        renderer = vtk.vtkRenderer()
        renderWindow = vtk.vtkRenderWindow()
        renderWindow.AddRenderer(renderer)
        renderWindowInteractor = vtk.vtkRenderWindowInteractor()
        renderWindowInteractor.SetRenderWindow(renderWindow)
 
        renderer.AddActor(actor)
        renderer.AddActor(contourLineActor)
        renderer.SetBackground(
            self.GetRGBColor("SteelBlue"))
 
        renderWindow.Render()
 
        fnsave = "TestNamedColorsIntegration.png"
        renLgeIm = vtk.vtkRenderLargeImage()
        imgWriter = vtk.vtkPNGWriter()
        renLgeIm.SetInput(renderer)
        renLgeIm.SetMagnification(1)
        imgWriter.SetInputConnection(renLgeIm.GetOutputPort())
        imgWriter.SetFileName(fnsave)
        imgWriter.Write()
 
        renderWindowInteractor.Start()
#!/usr/bin/env python
import vtk
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

#
# Test butterfly subdivision of point data
#
sphere = vtk.vtkSphereSource()
sphere.SetPhiResolution(11)
sphere.SetThetaResolution(11)
colorIt = vtk.vtkElevationFilter()
colorIt.SetInputConnection(sphere.GetOutputPort())
colorIt.SetLowPoint(0,0,-.5)
colorIt.SetHighPoint(0,0,.5)
butterfly = vtk.vtkButterflySubdivisionFilter()
butterfly.SetInputConnection(colorIt.GetOutputPort())
butterfly.SetNumberOfSubdivisions(3)
lut = vtk.vtkLookupTable()
lut.SetNumberOfColors(256)
lut.Build()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(butterfly.GetOutputPort())
mapper.SetLookupTable(lut)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
linear = vtk.vtkLinearSubdivisionFilter()
linear.SetInputConnection(colorIt.GetOutputPort())
linear.SetNumberOfSubdivisions(3)
mapper2 = vtk.vtkPolyDataMapper()
mapper2.SetInputConnection(linear.GetOutputPort())
예제 #34
0
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

#
# Test butterfly subdivision of point data
#
sphere = vtk.vtkSphereSource()
sphere.SetPhiResolution(11)
sphere.SetThetaResolution(11)
colorIt = vtk.vtkElevationFilter()
colorIt.SetInputConnection(sphere.GetOutputPort())
colorIt.SetLowPoint(0, 0, -.5)
colorIt.SetHighPoint(0, 0, .5)
butterfly = vtk.vtkButterflySubdivisionFilter()
butterfly.SetInputConnection(colorIt.GetOutputPort())
butterfly.SetNumberOfSubdivisions(3)
lut = vtk.vtkLookupTable()
lut.SetNumberOfColors(256)
lut.Build()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(butterfly.GetOutputPort())
mapper.SetLookupTable(lut)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
linear = vtk.vtkLinearSubdivisionFilter()
linear.SetInputConnection(colorIt.GetOutputPort())
linear.SetNumberOfSubdivisions(3)
mapper2 = vtk.vtkPolyDataMapper()
예제 #35
0
import vtk, os, sys
from vtk.test import Testing

ss = vtk.vtkSphereSource() #make mesh to test with

af = vtk.vtkElevationFilter() #add some attributes
af.SetInputConnection(ss.GetOutputPort())

ef = vtk.vtkExtractEdges() #make lines to test
ef.SetInputConnection(af.GetOutputPort())

gf = vtk.vtkGlyph3D() #make verts to test
pts = vtk.vtkPoints()
pts.InsertNextPoint(0,0,0)
verts = vtk.vtkCellArray()
avert = vtk.vtkVertex()
avert.GetPointIds().SetId(0, 0)
verts.InsertNextCell(avert)
onevertglyph = vtk.vtkPolyData()
onevertglyph.SetPoints(pts)
onevertglyph.SetVerts(verts)
gf.SetSourceData(onevertglyph)
gf.SetInputConnection(af.GetOutputPort())

testwrites = ["points","lines","mesh"]
failed = False
for datasetString in testwrites:
  if datasetString == "points":
    toshow=gf
  elif datasetString == "lines":
    toshow = ef
예제 #36
0
    def __init__(self, parent = None):
        super(VTKFrame, self).__init__(parent)

        self.vtkWidget = QVTKRenderWindowInteractor(self)
        vl = QtGui.QVBoxLayout(self)
        vl.addWidget(self.vtkWidget)
        vl.setContentsMargins(0, 0, 0, 0)
 
        self.ren = vtk.vtkRenderer()
        self.ren.SetBackground(0.1, 0.2, 0.4)
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
 
        # Created a grid of points
        points = vtk.vtkPoints()
        gridSize = 10
        for x in range(10):
            for y in range(10):
                points.InsertNextPoint(x, y, (x+y) / (y+1))

        bounds = [1] * 6
        points.GetBounds(bounds)

        # Add the grid points to a polydata object
        inputPolyData = vtk.vtkPolyData()
        inputPolyData.SetPoints(points)

        # Triangulate the grid points
        delaunay = vtk.vtkDelaunay2D()
        delaunay.SetInput(inputPolyData)
        delaunay.Update()

        elevationFilter = vtk.vtkElevationFilter()
        elevationFilter.SetInputConnection(delaunay.GetOutputPort())
        elevationFilter.SetLowPoint(0, 0, bounds[4])
        elevationFilter.SetHighPoint(0, 0, bounds[5])
        elevationFilter.Update()

        output = vtk.vtkPolyData()
        output.ShallowCopy(vtk.vtkPolyData.SafeDownCast(elevationFilter.GetOutput()))

        elevation = vtk.vtkFloatArray.SafeDownCast(output.GetPointData().GetArray("Elevation"))

        # Create the color map
        colorLookupTable = vtk.vtkLookupTable()
        colorLookupTable.SetTableRange(bounds[4], bounds[5])
        colorLookupTable.Build()

        # Generate the colors for each point based on the color map
        colors = vtk.vtkUnsignedCharArray()
        colors.SetNumberOfComponents(3)
        colors.SetName("Colors")

        for i in range(output.GetNumberOfPoints()):
            val = elevation.GetValue(i)
            dcolor = [1.0] * 3
            colorLookupTable.GetColor(val, dcolor)
            color = [1] * 3
            for j in range(3):
                color[j] = 255 * dcolor[j]

            colors.InsertNextTupleValue(color)

        output.GetPointData().AddArray(colors)

        # Create a mapper
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(output.GetProducerPort())
 
        # Create an actor
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
 
        self.ren.AddActor(actor)
        self.ren.ResetCamera()

        self._initialized = False
예제 #37
0
import vtk, os, sys
from vtk.test import Testing

ss = vtk.vtkSphereSource()  #make mesh to test with

af = vtk.vtkElevationFilter()  #add some attributes
af.SetInputConnection(ss.GetOutputPort())

ef = vtk.vtkExtractEdges()  #make lines to test
ef.SetInputConnection(af.GetOutputPort())

gf = vtk.vtkGlyph3D()  #make verts to test
pts = vtk.vtkPoints()
pts.InsertNextPoint(0, 0, 0)
verts = vtk.vtkCellArray()
avert = vtk.vtkVertex()
avert.GetPointIds().SetId(0, 0)
verts.InsertNextCell(avert)
onevertglyph = vtk.vtkPolyData()
onevertglyph.SetPoints(pts)
onevertglyph.SetVerts(verts)
gf.SetSourceData(onevertglyph)
gf.SetInputConnection(af.GetOutputPort())

testwrites = ["points", "lines", "mesh"]
failed = False
for datasetString in testwrites:
    if datasetString == "points":
        toshow = gf
    elif datasetString == "lines":
        toshow = ef
    def test(self):
        '''
          Create a cone, contour it using the banded contour filter and
              color it with the primary additive and subtractive colors.
        '''
        namedColors = vtk.vtkNamedColors()
        # Test printing of the object
        # Uncomment if desired
        #print namedColors

        # How to get a list of colors
        colors = namedColors.GetColorNames()
        colors = colors.split('\n')
        # Uncomment if desired
        #print 'Number of colors:', len(colors)
        #print colors

        # How to get a list of a list of synonyms.
        syn = namedColors.GetSynonyms()
        syn = syn.split('\n\n')
        synonyms = []
        for ele in syn:
            synonyms.append(ele.split('\n'))
        # Uncomment if desired
        #print 'Number of synonyms:', len(synonyms)
        #print synonyms

        # Create a cone
        coneSource = vtk.vtkConeSource()
        coneSource.SetCenter(0.0, 0.0, 0.0)
        coneSource.SetRadius(5.0)
        coneSource.SetHeight(10)
        coneSource.SetDirection(0, 1, 0)
        coneSource.Update()

        bounds = [1.0, -1.0, 1.0, -1.0, 1.0, -1.0]
        coneSource.GetOutput().GetBounds(bounds)

        elevation = vtk.vtkElevationFilter()
        elevation.SetInputConnection(coneSource.GetOutputPort())
        elevation.SetLowPoint(0, bounds[2], 0)
        elevation.SetHighPoint(0, bounds[3], 0)

        bcf = vtk.vtkBandedPolyDataContourFilter()
        bcf.SetInputConnection(elevation.GetOutputPort())
        bcf.SetScalarModeToValue()
        bcf.GenerateContourEdgesOn()
        bcf.GenerateValues(7, elevation.GetScalarRange())

        # Build a simple lookup table of
        # primary additive and subtractive colors.
        lut = vtk.vtkLookupTable()
        lut.SetNumberOfTableValues(7)
        rgba = [0.0, 0.0, 0.0, 1.0]
        # Test setting and getting a color here.
        namedColors.GetColor("Red", rgba)
        namedColors.SetColor("My Red", rgba)
        namedColors.GetColor("My Red", rgba)
        lut.SetTableValue(0, rgba)
        namedColors.GetColor("DarkGreen", rgba)
        lut.SetTableValue(1, rgba)
        namedColors.GetColor("Blue", rgba)
        lut.SetTableValue(2, rgba)
        namedColors.GetColor("Cyan", rgba)
        lut.SetTableValue(3, rgba)
        namedColors.GetColor("Magenta", rgba)
        lut.SetTableValue(4, rgba)
        namedColors.GetColor("Yellow", rgba)
        lut.SetTableValue(5, rgba)
        namedColors.GetColor("White", rgba)
        lut.SetTableValue(6, rgba)
        lut.SetTableRange(elevation.GetScalarRange())
        lut.Build()

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(bcf.GetOutputPort())
        mapper.SetLookupTable(lut)
        mapper.SetScalarModeToUseCellData()

        contourLineMapper = vtk.vtkPolyDataMapper()
        contourLineMapper.SetInputData(bcf.GetContourEdgesOutput())
        contourLineMapper.SetScalarRange(elevation.GetScalarRange())
        contourLineMapper.SetResolveCoincidentTopologyToPolygonOffset()

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

        contourLineActor = vtk.vtkActor()
        contourLineActor.SetMapper(contourLineMapper)
        rgb = [0.0, 0.0, 0.0]
        namedColors.GetColorRGB("black", rgb)
        contourLineActor.GetProperty().SetColor(rgb)

        renderer = vtk.vtkRenderer()
        renderWindow = vtk.vtkRenderWindow()
        renderWindow.AddRenderer(renderer)
        iRen = vtk.vtkRenderWindowInteractor()
        iRen.SetRenderWindow(renderWindow)

        renderer.AddActor(actor)
        renderer.AddActor(contourLineActor)
        namedColors.GetColorRGB("SteelBlue", rgb)
        renderer.SetBackground(rgb)

        renderWindow.Render()
        img_file = "TestNamedColorsIntegration.png"
        vtk.test.Testing.compareImage(
            iRen.GetRenderWindow(),
            vtk.test.Testing.getAbsImagePath(img_file),
            threshold=25)
        vtk.test.Testing.interact()
ren1 = vtk.vtkRenderer()
ren1.SetViewport(0.5,0,1,1)
renWin = vtk.vtkRenderWindow()
renWin.SetSize(2*sze+100,sze)
renWin.AddRenderer(ren0)
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# Create pipeline, render simple object. We'll also color
# the sphere to generate color scalars.
sphere = vtk.vtkSphereSource()
sphere.SetCenter(0,0,0)
sphere.SetRadius(1)

ele = vtk.vtkElevationFilter()
ele.SetInputConnection(sphere.GetOutputPort())
ele.SetLowPoint(0,-1,0)
ele.SetHighPoint(0,1,0)

sphereMapper = vtk.vtkPolyDataMapper()
sphereMapper.SetInputConnection(ele.GetOutputPort())

sphereActor = vtk.vtkActor()
sphereActor.SetMapper(sphereMapper)

ren0.AddActor(sphereActor)
ren0.SetBackground(0,0,0)

iren.Initialize()
ren0.ResetCamera()
예제 #40
0
cone = vtk.vtkConeSource()
cone.SetHeight(3.0)
cone.SetRadius(1.0)
cone.SetResolution(10)

coneMapper = vtk.vtkPolyDataMapper()
coneMapper.SetInputConnection(cone.GetOutputPort())

# Actor for opacity as a property value.
coneActor = vtk.vtkActor()
coneActor.SetMapper(coneMapper)
coneActor.GetProperty().SetOpacity(0.5)

# Actor for opacity thru LUT.
elevation = vtk.vtkElevationFilter()
elevation.SetInputConnection(cone.GetOutputPort())

coneMapper2 = vtk.vtkPolyDataMapper()
coneMapper2.SetInputConnection(elevation.GetOutputPort())

lut = vtk.vtkLookupTable()
lut.SetAlphaRange(0.9, 0.1)
lut.SetHueRange(0, 0)
lut.SetSaturationRange(1, 1)
lut.SetValueRange(1, 1)

coneMapper2.SetLookupTable(lut)
coneMapper2.SetScalarModeToUsePointData()
coneMapper2.SetScalarVisibility(1)
coneMapper2.InterpolateScalarsBeforeMappingOn()
예제 #41
0
    def __init__(self, parent=None):
        super(VTKFrame, self).__init__(parent)

        self.vtkWidget = QVTKRenderWindowInteractor(self)
        vl = QtGui.QVBoxLayout(self)
        vl.addWidget(self.vtkWidget)
        vl.setContentsMargins(0, 0, 0, 0)

        self.ren = vtk.vtkRenderer()
        self.ren.SetBackground(0.1, 0.2, 0.4)
        self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
        self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()

        # Created a grid of points
        points = vtk.vtkPoints()
        gridSize = 10
        for x in range(10):
            for y in range(10):
                points.InsertNextPoint(x, y, (x + y) / (y + 1))

        bounds = [1] * 6
        points.GetBounds(bounds)

        # Add the grid points to a polydata object
        inputPolyData = vtk.vtkPolyData()
        inputPolyData.SetPoints(points)

        # Triangulate the grid points
        delaunay = vtk.vtkDelaunay2D()
        delaunay.SetInput(inputPolyData)
        delaunay.Update()

        elevationFilter = vtk.vtkElevationFilter()
        elevationFilter.SetInputConnection(delaunay.GetOutputPort())
        elevationFilter.SetLowPoint(0, 0, bounds[4])
        elevationFilter.SetHighPoint(0, 0, bounds[5])
        elevationFilter.Update()

        output = vtk.vtkPolyData()
        output.ShallowCopy(
            vtk.vtkPolyData.SafeDownCast(elevationFilter.GetOutput()))

        elevation = vtk.vtkFloatArray.SafeDownCast(
            output.GetPointData().GetArray("Elevation"))

        # Create the color map
        colorLookupTable = vtk.vtkLookupTable()
        colorLookupTable.SetTableRange(bounds[4], bounds[5])
        colorLookupTable.Build()

        # Generate the colors for each point based on the color map
        colors = vtk.vtkUnsignedCharArray()
        colors.SetNumberOfComponents(3)
        colors.SetName("Colors")

        for i in range(output.GetNumberOfPoints()):
            val = elevation.GetValue(i)
            dcolor = [1.0] * 3
            colorLookupTable.GetColor(val, dcolor)
            color = [1] * 3
            for j in range(3):
                color[j] = 255 * dcolor[j]

            colors.InsertNextTupleValue(color)

        output.GetPointData().AddArray(colors)

        # Create a mapper
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(output.GetProducerPort())

        # Create an actor
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)

        self.ren.AddActor(actor)
        self.ren.ResetCamera()

        self._initialized = False
예제 #42
0
파일: dem.py 프로젝트: 151706061/VTK
lods = "4 8 16"
for lod in lods.split():
    locals()[get_variable_name("shrink", lod, "")] = vtk.vtkImageShrink3D()
    locals()[get_variable_name("shrink", lod, "")].SetShrinkFactors(expr.expr(globals(), locals(),["int","(","lod",")"]),expr.expr(globals(), locals(),["int","(","lod",")"]),1)
    locals()[get_variable_name("shrink", lod, "")].SetInputConnection(demModel.GetOutputPort())
    locals()[get_variable_name("shrink", lod, "")].AveragingOn()
    locals()[get_variable_name("geom", lod, "")] = vtk.vtkImageDataGeometryFilter()
    locals()[get_variable_name("geom", lod, "")].SetInputConnection(locals()[get_variable_name("shrink", lod, "")].GetOutputPort())
    locals()[get_variable_name("geom", lod, "")].ReleaseDataFlagOn()
    locals()[get_variable_name("warp", lod, "")] = vtk.vtkWarpScalar()
    locals()[get_variable_name("warp", lod, "")].SetInputConnection(locals()[get_variable_name("geom", lod, "")].GetOutputPort())
    locals()[get_variable_name("warp", lod, "")].SetNormal(0,0,1)
    locals()[get_variable_name("warp", lod, "")].UseNormalOn()
    locals()[get_variable_name("warp", lod, "")].SetScaleFactor(Scale)
    locals()[get_variable_name("warp", lod, "")].ReleaseDataFlagOn()
    locals()[get_variable_name("elevation", lod, "")] = vtk.vtkElevationFilter()
    locals()[get_variable_name("elevation", lod, "")].SetInputConnection(locals()[get_variable_name("warp", lod, "")].GetOutputPort())
    locals()[get_variable_name("elevation", lod, "")].SetLowPoint(0,0,lo)
    locals()[get_variable_name("elevation", lod, "")].SetHighPoint(0,0,hi)
    locals()[get_variable_name("elevation", lod, "")].SetScalarRange(lo,hi)
    locals()[get_variable_name("elevation", lod, "")].ReleaseDataFlagOn()
    locals()[get_variable_name("toPoly", lod, "")] = vtk.vtkCastToConcrete()
    locals()[get_variable_name("toPoly", lod, "")].SetInputConnection(locals()[get_variable_name("elevation", lod, "")].GetOutputPort())
    locals()[get_variable_name("normals", lod, "")] = vtk.vtkPolyDataNormals()
    locals()[get_variable_name("normals", lod, "")].SetInputConnection(locals()[get_variable_name("toPoly", lod, "")].GetOutputPort())
    locals()[get_variable_name("normals", lod, "")].SetFeatureAngle(60)
    locals()[get_variable_name("normals", lod, "")].ConsistencyOff()
    locals()[get_variable_name("normals", lod, "")].SplittingOff()
    locals()[get_variable_name("normals", lod, "")].ReleaseDataFlagOn()
    locals()[get_variable_name("demMapper", lod, "")] = vtk.vtkPolyDataMapper()
    locals()[get_variable_name("demMapper", lod, "")].SetInputConnection(locals()[get_variable_name("normals", lod, "")].GetOutputPort())
예제 #43
0
    def probeUnstructuredGridVTKOverLine(self, lineVTK, readerUnstructuredGridVTK, varName,
                                         kernel="gaussian", radius=None, nullValue=None):
        """ Interpolate the data from the Unstructured Grid VTK onto a line (profile).

        The unstructured grid VTK is supposed to be a 2D surface in 3D space, such as the mesh used in 2D hydraulics
        models.

        To probe on them, the surface has to be flattened first.

        Parameters
        ----------
        lineVTK : vtkLineSource or vtkPoints
            coordinates of points in the vtkLineSource; the points don't need to ordered,
            thus they can be just a bunch of points
        readerUnstructuredGridVTK : vtkUnstructuredGridReader
            Unstructured Grid VTK reader
        varName : str
            name of the variable to be probed
        kernel : str
            name of the kernel for interpolation (linear, gaussin, voronoi, Shepard"
        radius : float
            radius for interpolation kernels
        nullValue: float
            value to be assigned to invalid probing points


        Returns
        -------
        points: numpy arrays [number of points, 3]; points on the profile
        probed result array:
        elev: elevation (z) of points in the profile

        """

        # Get data from the Unstructured Grid VTK reader
        data = readerUnstructuredGridVTK.GetOutput()

        # make sure the data is stored at points (for smoother interpolation)
        cell2point = vtk.vtkCellDataToPointData()
        cell2point.SetInputData(data)
        cell2point.Update()
        data = cell2point.GetOutput()   #after this, all data are stored at points, not cell centers.

        bounds = data.GetBounds()

        #print("Unstructured Grid VTK bounds = ", bounds)
        #print("Unstructured Grid number of cells: ", data.GetNumberOfCells())
        #print("Unstructured Grid number of points: ", data.GetNumberOfPoints())

        if radius is None:
            boundingArea = (bounds[1] - bounds[0]) * (bounds[3] - bounds[2])   #assume 2D Grid
            averageCellArea =  boundingArea/data.GetNumberOfCells()            #average cell area
            radius = np.sqrt(averageCellArea)                                  #average size of cell
            radius = 2.0*radius                                                #double the search radius

        ### make a transform to set all Z values to zero ###
        flattener = vtk.vtkTransform()
        flattener.Scale(1.0, 1.0, 0.0)

        ### flatten the input in case it's not already flat ###
        i_flat = vtk.vtkTransformFilter()

        if isinstance(lineVTK, vtk.vtkLineSource):
            i_flat.SetInputConnection(lineVTK.GetOutputPort())
        elif isinstance(lineVTK, vtk.vtkPoints):
            polydata_temp = vtk.vtkPolyData()
            polydata_temp.SetPoints(lineVTK)
            i_flat.SetInputData(polydata_temp)
        else:
            raise Exception("lineVTK type,", type(lineVTK),", not supported. Only vtkLineSource and vtkPoints are supported.")

        i_flat.SetTransform(flattener)

        ### transfer z elevation values to the source's point scalar data ###
        s_elev = vtk.vtkElevationFilter()
        s_elev.SetInputData(data)
        s_elev.SetHighPoint(0, 0, bounds[5])
        s_elev.SetLowPoint(0, 0, bounds[4])
        s_elev.SetScalarRange(bounds[4], bounds[5])
        s_elev.Update()

        #print("s_elev = ", s_elev.GetUnstructuredGridOutput())

        ### flatten the source data; the Z elevations are already in the scalars data ###
        s_flat = vtk.vtkTransformFilter()
        s_flat.SetInputConnection(s_elev.GetOutputPort())
        s_flat.SetTransform(flattener)

        # build the probe using vtkPointInterpolator
        # construct the interpolation kernel
        if kernel == 'gaussian':
            kern = vtk.vtkGaussianKernel()
            kern.SetSharpness(2)
            kern.SetRadius(radius)
        elif kernel == 'voronoi':
            kern = vtk.vtkVoronoiKernel()
        elif kernel == 'linear':
            kern = vtk.vtkLinearKernel()
            kern.SetRadius(radius)
        elif kernel == 'Shepard':
            kern = vtk.vtkShepardKernel()
            kern.SetPowerParameter(2)
            kern.SetRadius(radius)
        else:
            raise Exception("The specified kernel is not supported.")

        probe = vtk.vtkPointInterpolator()
        probe.SetInputConnection(i_flat.GetOutputPort())
        probe.SetSourceConnection(s_flat.GetOutputPort())
        probe.SetKernel(kern)
        if nullValue is not None:
            probe.SetNullValue(nullValue)
        else:
            probe.SetNullPointsStrategyToClosestPoint()

        probe.Update()

        # (This approach of using vtkProbeFilter is replaced by vtkPointInterpolator for smoother result)
        # vtkProbeFilter, the probe line is the input, and the underlying dataset is the source.
        #probe = vtk.vtkProbeFilter()
        #probe.SetInputConnection(i_flat.GetOutputPort())
        #probe.SetSourceConnection(s_flat.GetOutputPort())
        #probe.Update()

        # get the data from the VTK-object (probe) to an numpy array
        #print("varName =", varName)
        #print(probe.GetOutput().GetPointData().GetArray(varName))

        varProbedValues = VN.vtk_to_numpy(probe.GetOutput().GetPointData().GetArray(varName))

        numPoints = probe.GetOutput().GetNumberOfPoints()  # get the number of points on the line

        # get the elevation from the VTK-object (probe) to an numpy array
        elev = VN.vtk_to_numpy(probe.GetOutput().GetPointData().GetArray("Elevation"))

        # intialise the points on the line
        x = np.zeros(numPoints)
        y = np.zeros(numPoints)
        z = np.zeros(numPoints)
        points = np.zeros((numPoints, 3))

        # get the coordinates of the points on the line
        for i in range(numPoints):
            x[i], y[i], z[i] = probe.GetOutput().GetPoint(i)
            points[i, 0] = x[i]
            points[i, 1] = y[i]
            points[i, 2] = z[i]

        return points, varProbedValues, elev
예제 #44
0
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

res = 6
plane = vtk.vtkPlaneSource()
plane.SetResolution(res,res)
colors = vtk.vtkElevationFilter()
colors.SetInputConnection(plane.GetOutputPort())
colors.SetLowPoint(-0.25,-0.25,-0.25)
colors.SetHighPoint(0.25,0.25,0.25)
planeMapper = vtk.vtkPolyDataMapper()
planeMapper.SetInputConnection(colors.GetOutputPort())
planeActor = vtk.vtkActor()
planeActor.SetMapper(planeMapper)
planeActor.GetProperty().SetRepresentationToWireframe()
# create simple poly data so we can apply glyph
squad = vtk.vtkSuperquadricSource()
squadColors = vtk.vtkElevationFilter()
squadColors.SetInputConnection(squad.GetOutputPort())
squadColors.SetLowPoint(-0.25,-0.25,-0.25)
squadColors.SetHighPoint(0.25,0.25,0.25)
squadCaster = vtk.vtkCastToConcrete()
squadCaster.SetInputConnection(squadColors.GetOutputPort())
squadTransform = vtk.vtkTransform()
transformSquad = vtk.vtkTransformPolyDataFilter()
transformSquad.SetInputConnection(squadColors.GetOutputPort())
transformSquad.SetTransform(squadTransform)
transformSquad.Update()
    def testSphereWidget(self):

        # This example demonstrates how to use the vtkSphereWidget to control the
        # position of a light.

        # These are the pre-recorded events
        Recording = \
           "# StreamVersion 1\n\
            CharEvent 23 266 0 0 105 1 i\n\
            KeyReleaseEvent 23 266 0 0 105 1 i\n\
            EnterEvent 69 294 0 0 0 0 i\n\
            MouseMoveEvent 69 294 0 0 0 0 i\n\
            MouseMoveEvent 68 293 0 0 0 0 i\n\
            MouseMoveEvent 67 292 0 0 0 0 i\n\
            MouseMoveEvent 66 289 0 0 0 0 i\n\
            MouseMoveEvent 66 282 0 0 0 0 i\n\
            MouseMoveEvent 66 271 0 0 0 0 i\n\
            MouseMoveEvent 69 253 0 0 0 0 i\n\
            MouseMoveEvent 71 236 0 0 0 0 i\n\
            MouseMoveEvent 74 219 0 0 0 0 i\n\
            MouseMoveEvent 76 208 0 0 0 0 i\n\
            MouseMoveEvent 78 190 0 0 0 0 i\n\
            MouseMoveEvent 78 173 0 0 0 0 i\n\
            MouseMoveEvent 77 162 0 0 0 0 i\n\
            MouseMoveEvent 77 151 0 0 0 0 i\n\
            MouseMoveEvent 77 139 0 0 0 0 i\n\
            MouseMoveEvent 76 125 0 0 0 0 i\n\
            MouseMoveEvent 73 114 0 0 0 0 i\n\
            MouseMoveEvent 73 106 0 0 0 0 i\n\
            MouseMoveEvent 73 101 0 0 0 0 i\n\
            MouseMoveEvent 72 95 0 0 0 0 i\n\
            MouseMoveEvent 72 92 0 0 0 0 i\n\
            MouseMoveEvent 70 89 0 0 0 0 i\n\
            MouseMoveEvent 69 86 0 0 0 0 i\n\
            MouseMoveEvent 67 84 0 0 0 0 i\n\
            MouseMoveEvent 65 81 0 0 0 0 i\n\
            MouseMoveEvent 60 79 0 0 0 0 i\n\
            MouseMoveEvent 59 79 0 0 0 0 i\n\
            MouseMoveEvent 58 79 0 0 0 0 i\n\
            MouseMoveEvent 57 78 0 0 0 0 i\n\
            MouseMoveEvent 55 78 0 0 0 0 i\n\
            MouseMoveEvent 54 77 0 0 0 0 i\n\
            LeftButtonPressEvent 54 77 0 0 0 0 i\n\
            MouseMoveEvent 61 79 0 0 0 0 i\n\
            MouseMoveEvent 67 83 0 0 0 0 i\n\
            MouseMoveEvent 72 88 0 0 0 0 i\n\
            MouseMoveEvent 77 90 0 0 0 0 i\n\
            MouseMoveEvent 78 91 0 0 0 0 i\n\
            MouseMoveEvent 80 92 0 0 0 0 i\n\
            MouseMoveEvent 84 93 0 0 0 0 i\n\
            MouseMoveEvent 85 94 0 0 0 0 i\n\
            MouseMoveEvent 88 97 0 0 0 0 i\n\
            MouseMoveEvent 90 100 0 0 0 0 i\n\
            MouseMoveEvent 92 102 0 0 0 0 i\n\
            MouseMoveEvent 94 103 0 0 0 0 i\n\
            MouseMoveEvent 97 105 0 0 0 0 i\n\
            MouseMoveEvent 101 107 0 0 0 0 i\n\
            MouseMoveEvent 102 109 0 0 0 0 i\n\
            MouseMoveEvent 104 111 0 0 0 0 i\n\
            MouseMoveEvent 108 113 0 0 0 0 i\n\
            MouseMoveEvent 112 115 0 0 0 0 i\n\
            MouseMoveEvent 118 119 0 0 0 0 i\n\
            MouseMoveEvent 118 120 0 0 0 0 i\n\
            MouseMoveEvent 118 123 0 0 0 0 i\n\
            MouseMoveEvent 120 125 0 0 0 0 i\n\
            MouseMoveEvent 122 128 0 0 0 0 i\n\
            MouseMoveEvent 123 129 0 0 0 0 i\n\
            MouseMoveEvent 125 132 0 0 0 0 i\n\
            MouseMoveEvent 125 134 0 0 0 0 i\n\
            MouseMoveEvent 127 138 0 0 0 0 i\n\
            MouseMoveEvent 127 142 0 0 0 0 i\n\
            MouseMoveEvent 127 147 0 0 0 0 i\n\
            MouseMoveEvent 126 152 0 0 0 0 i\n\
            MouseMoveEvent 126 155 0 0 0 0 i\n\
            MouseMoveEvent 125 160 0 0 0 0 i\n\
            MouseMoveEvent 125 167 0 0 0 0 i\n\
            MouseMoveEvent 125 169 0 0 0 0 i\n\
            MouseMoveEvent 125 174 0 0 0 0 i\n\
            MouseMoveEvent 122 179 0 0 0 0 i\n\
            MouseMoveEvent 120 183 0 0 0 0 i\n\
            MouseMoveEvent 116 187 0 0 0 0 i\n\
            MouseMoveEvent 113 192 0 0 0 0 i\n\
            MouseMoveEvent 113 193 0 0 0 0 i\n\
            MouseMoveEvent 111 195 0 0 0 0 i\n\
            MouseMoveEvent 108 198 0 0 0 0 i\n\
            MouseMoveEvent 106 200 0 0 0 0 i\n\
            MouseMoveEvent 104 202 0 0 0 0 i\n\
            MouseMoveEvent 103 203 0 0 0 0 i\n\
            MouseMoveEvent 99 205 0 0 0 0 i\n\
            MouseMoveEvent 97 207 0 0 0 0 i\n\
            MouseMoveEvent 94 208 0 0 0 0 i\n\
            MouseMoveEvent 91 210 0 0 0 0 i\n\
            MouseMoveEvent 89 211 0 0 0 0 i\n\
            MouseMoveEvent 86 211 0 0 0 0 i\n\
            MouseMoveEvent 84 211 0 0 0 0 i\n\
            MouseMoveEvent 80 211 0 0 0 0 i\n\
            MouseMoveEvent 77 211 0 0 0 0 i\n\
            MouseMoveEvent 75 211 0 0 0 0 i\n\
            MouseMoveEvent 71 211 0 0 0 0 i\n\
            MouseMoveEvent 68 211 0 0 0 0 i\n\
            MouseMoveEvent 66 210 0 0 0 0 i\n\
            MouseMoveEvent 62 210 0 0 0 0 i\n\
            MouseMoveEvent 58 209 0 0 0 0 i\n\
            MouseMoveEvent 54 207 0 0 0 0 i\n\
            MouseMoveEvent 52 204 0 0 0 0 i\n\
            MouseMoveEvent 51 203 0 0 0 0 i\n\
            MouseMoveEvent 51 200 0 0 0 0 i\n\
            MouseMoveEvent 48 196 0 0 0 0 i\n\
            MouseMoveEvent 45 187 0 0 0 0 i\n\
            MouseMoveEvent 45 181 0 0 0 0 i\n\
            MouseMoveEvent 44 168 0 0 0 0 i\n\
            MouseMoveEvent 40 161 0 0 0 0 i\n\
            MouseMoveEvent 39 154 0 0 0 0 i\n\
            MouseMoveEvent 38 146 0 0 0 0 i\n\
            MouseMoveEvent 35 131 0 0 0 0 i\n\
            MouseMoveEvent 34 121 0 0 0 0 i\n\
            MouseMoveEvent 34 110 0 0 0 0 i\n\
            MouseMoveEvent 34 103 0 0 0 0 i\n\
            MouseMoveEvent 34 91 0 0 0 0 i\n\
            MouseMoveEvent 34 86 0 0 0 0 i\n\
            MouseMoveEvent 34 73 0 0 0 0 i\n\
            MouseMoveEvent 35 66 0 0 0 0 i\n\
            MouseMoveEvent 37 60 0 0 0 0 i\n\
            MouseMoveEvent 37 53 0 0 0 0 i\n\
            MouseMoveEvent 38 50 0 0 0 0 i\n\
            MouseMoveEvent 38 48 0 0 0 0 i\n\
            MouseMoveEvent 41 45 0 0 0 0 i\n\
            MouseMoveEvent 43 45 0 0 0 0 i\n\
            MouseMoveEvent 44 45 0 0 0 0 i\n\
            MouseMoveEvent 47 43 0 0 0 0 i\n\
            MouseMoveEvent 51 44 0 0 0 0 i\n\
            MouseMoveEvent 54 44 0 0 0 0 i\n\
            MouseMoveEvent 55 44 0 0 0 0 i\n\
            MouseMoveEvent 59 44 0 0 0 0 i\n\
            MouseMoveEvent 64 44 0 0 0 0 i\n\
            MouseMoveEvent 67 44 0 0 0 0 i\n\
            MouseMoveEvent 68 44 0 0 0 0 i\n\
            MouseMoveEvent 71 44 0 0 0 0 i\n\
            MouseMoveEvent 74 44 0 0 0 0 i\n\
            MouseMoveEvent 77 44 0 0 0 0 i\n\
            MouseMoveEvent 80 45 0 0 0 0 i\n\
            MouseMoveEvent 81 45 0 0 0 0 i\n\
            MouseMoveEvent 85 49 0 0 0 0 i\n\
            MouseMoveEvent 89 50 0 0 0 0 i\n\
            MouseMoveEvent 94 52 0 0 0 0 i\n\
            MouseMoveEvent 99 56 0 0 0 0 i\n\
            MouseMoveEvent 104 58 0 0 0 0 i\n\
            MouseMoveEvent 107 61 0 0 0 0 i\n\
            MouseMoveEvent 109 63 0 0 0 0 i\n\
            MouseMoveEvent 109 67 0 0 0 0 i\n\
            MouseMoveEvent 111 83 0 0 0 0 i\n\
            MouseMoveEvent 113 86 0 0 0 0 i\n\
            MouseMoveEvent 113 87 0 0 0 0 i\n\
            MouseMoveEvent 113 89 0 0 0 0 i\n\
            MouseMoveEvent 112 93 0 0 0 0 i\n\
            MouseMoveEvent 112 97 0 0 0 0 i\n\
            MouseMoveEvent 111 104 0 0 0 0 i\n\
            MouseMoveEvent 112 108 0 0 0 0 i\n\
            MouseMoveEvent 116 115 0 0 0 0 i\n\
            MouseMoveEvent 116 123 0 0 0 0 i\n\
            MouseMoveEvent 116 129 0 0 0 0 i\n\
            MouseMoveEvent 119 138 0 0 0 0 i\n\
            MouseMoveEvent 122 141 0 0 0 0 i\n\
            MouseMoveEvent 127 148 0 0 0 0 i\n\
            MouseMoveEvent 128 161 0 0 0 0 i\n\
            MouseMoveEvent 131 166 0 0 0 0 i\n\
            MouseMoveEvent 134 168 0 0 0 0 i\n\
            MouseMoveEvent 135 171 0 0 0 0 i\n\
            MouseMoveEvent 134 174 0 0 0 0 i\n\
            MouseMoveEvent 132 176 0 0 0 0 i\n\
            MouseMoveEvent 132 178 0 0 0 0 i\n\
            MouseMoveEvent 129 180 0 0 0 0 i\n\
            MouseMoveEvent 127 182 0 0 0 0 i\n\
            MouseMoveEvent 124 185 0 0 0 0 i\n\
            MouseMoveEvent 122 186 0 0 0 0 i\n\
            MouseMoveEvent 118 189 0 0 0 0 i\n\
            MouseMoveEvent 114 191 0 0 0 0 i\n\
            MouseMoveEvent 114 193 0 0 0 0 i\n\
            MouseMoveEvent 112 193 0 0 0 0 i\n\
            MouseMoveEvent 111 194 0 0 0 0 i\n\
            MouseMoveEvent 110 197 0 0 0 0 i\n\
            MouseMoveEvent 110 198 0 0 0 0 i\n\
            MouseMoveEvent 109 199 0 0 0 0 i\n\
            MouseMoveEvent 108 200 0 0 0 0 i\n\
            MouseMoveEvent 108 201 0 0 0 0 i\n\
            MouseMoveEvent 108 202 0 0 0 0 i\n\
            MouseMoveEvent 108 203 0 0 0 0 i\n\
            MouseMoveEvent 104 206 0 0 0 0 i\n\
            LeftButtonReleaseEvent 104 206 0 0 0 0 i\n\
            MouseMoveEvent 104 205 0 0 0 0 i\n\
            MouseMoveEvent 104 204 0 0 0 0 i\n\
            MouseMoveEvent 105 205 0 0 0 0 i\n\
            MouseMoveEvent 105 206 0 0 0 0 i\n\
        "

        # Start by loading some data.
        #
        dem = vtk.vtkDEMReader()
        dem.SetFileName(VTK_DATA_ROOT + "/Data/SainteHelens.dem")
        dem.Update()

        Scale = 2
        lut = vtk.vtkLookupTable()
        lut.SetHueRange(0.6, 0)
        lut.SetSaturationRange(1.0, 0)
        lut.SetValueRange(0.5, 1.0)
        lo = Scale * dem.GetElevationBounds()[0]

        hi = Scale * dem.GetElevationBounds()[1]


        shrink = vtk.vtkImageShrink3D()
        shrink.SetShrinkFactors(4, 4, 1)
        shrink.SetInputConnection(dem.GetOutputPort())
        shrink.AveragingOn()

        geom = vtk.vtkImageDataGeometryFilter()
        geom.SetInputConnection(shrink.GetOutputPort())
        geom.ReleaseDataFlagOn()

        warp = vtk.vtkWarpScalar()
        warp.SetInputConnection(geom.GetOutputPort())
        warp.SetNormal(0, 0, 1)
        warp.UseNormalOn()
        warp.SetScaleFactor(Scale)
        warp.ReleaseDataFlagOn()

        elevation = vtk.vtkElevationFilter()
        elevation.SetInputConnection(warp.GetOutputPort())
        elevation.SetLowPoint(0, 0, lo)
        elevation.SetHighPoint(0, 0, hi)
        elevation.SetScalarRange(lo, hi)
        elevation.ReleaseDataFlagOn()

        normals = vtk.vtkPolyDataNormals()
        normals.SetInputConnection(elevation.GetOutputPort())
        normals.SetFeatureAngle(60)
        normals.ConsistencyOff()
        normals.SplittingOff()
        normals.ReleaseDataFlagOn()
        normals.Update()

        demMapper = vtk.vtkPolyDataMapper()
        demMapper.SetInputConnection(normals.GetOutputPort())
        demMapper.SetScalarRange(lo, hi)
        demMapper.SetLookupTable(lut)

        demActor = vtk.vtkActor()
        demActor.SetMapper(demMapper)

        # Create the RenderWindow, Renderer and both Actors
        #
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.SetMultiSamples(0)
        renWin.AddRenderer(ren)
        iRen = vtk.vtkRenderWindowInteractor()
        iRen.SetRenderWindow(renWin)
        iRen.LightFollowCameraOff()
        #    iRen.SetInteractorStyle("")

        # The callback takes two arguments.
        # The first being the object that generates the event and
        # the second argument the event name (which is a string).
        def MoveLight(widget, event_string):
            light.SetPosition(rep.GetHandlePosition())

        # Associate the line widget with the interactor
        rep = vtk.vtkSphereRepresentation()
        rep.SetPlaceFactor(4)
        rep.PlaceWidget(normals.GetOutput().GetBounds())
        rep.HandleVisibilityOn()
        rep.SetRepresentationToWireframe()
        #  rep HandleVisibilityOff
        #  rep HandleTextOff
        sphereWidget = vtk.vtkSphereWidget2()
        sphereWidget.SetInteractor(iRen)
        sphereWidget.SetRepresentation(rep)
        #  sphereWidget.TranslationEnabledOff()
        #  sphereWidget.ScalingEnabledOff()
        sphereWidget.AddObserver("InteractionEvent", MoveLight)

        recorder = vtk.vtkInteractorEventRecorder()
        recorder.SetInteractor(iRen)
        #  recorder.SetFileName("c:/record.log")
        #  recorder.Record()
        recorder.ReadFromInputStringOn()
        recorder.SetInputString(Recording)

        # Add the actors to the renderer, set the background and size
        #
        ren.AddActor(demActor)
        ren.SetBackground(1, 1, 1)
        renWin.SetSize(300, 300)
        ren.SetBackground(0.1, 0.2, 0.4)

        cam1 = ren.GetActiveCamera()
        cam1.SetViewUp(0, 0, 1)
        cam1.SetFocalPoint(dem.GetOutput().GetCenter())
        cam1.SetPosition(1, 0, 0)
        ren.ResetCamera()
        cam1.Elevation(25)
        cam1.Azimuth(125)
        cam1.Zoom(1.25)

        light = vtk.vtkLight()
        light.SetFocalPoint(rep.GetCenter())
        light.SetPosition(rep.GetHandlePosition())
        ren.AddLight(light)

        iRen.Initialize()
        renWin.Render()

        # render the image
        renWin.Render()

        # Actually probe the data
        recorder.Play()

        img_file = "TestSphereWidget.png"
        vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25)
        vtk.test.Testing.interact()
예제 #46
0
shrink16.SetShrinkFactors(16, 16, 1)
shrink16.SetInputConnection(demModel.GetOutputPort())
shrink16.AveragingOn()

geom16 = vtk.vtkImageDataGeometryFilter()
geom16.SetInputConnection(shrink16.GetOutputPort())
geom16.ReleaseDataFlagOn()

warp16 = vtk.vtkWarpScalar()
warp16.SetInputConnection(geom16.GetOutputPort())
warp16.SetNormal(0, 0, 1)
warp16.UseNormalOn()
warp16.SetScaleFactor(Scale)
warp16.ReleaseDataFlagOn()

elevation16 = vtk.vtkElevationFilter()
elevation16.SetInputConnection(warp16.GetOutputPort())
elevation16.SetLowPoint(0, 0, lo)
elevation16.SetHighPoint(0, 0, hi)
elevation16.SetScalarRange(lo, hi)
elevation16.ReleaseDataFlagOn()

normals16 = vtk.vtkPolyDataNormals()
normals16.SetInputConnection(elevation16.GetOutputPort())
normals16.SetFeatureAngle(60)
normals16.ConsistencyOff()
normals16.SplittingOff()
normals16.ReleaseDataFlagOn()

demMapper16 = vtk.vtkPolyDataMapper()
demMapper16.SetInputConnection(normals16.GetOutputPort())
예제 #47
0
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()

elev2 = vtk.vtkElevationFilter()
elev2.SetInputConnection(bp.GetOutputPort())
elev2.SetLowPoint(0, -10, 0)
elev2.SetHighPoint(0, 10, 0)
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()