[vtkusers] ScalarVisibilityOff() and opacity

Matthijs Sypkens Smit matthijs at mired.nl
Wed Oct 15 03:26:15 EDT 2003


Hi All,

I'm using a vtkStructuredGrid with vtkExtractEdges to visualize the complete 
grid. Because the grid can be quite complex it's desirable to draw with a 
certain opacity. When there is scalar-data this works perfectly. However when 
there is no scalar-data or when I call ScalarVisibilityOff() the grid is 
drawn without transparency.

The example below illustrates this. A small grid with scalar-data is 
presented. When the line
#sgridMapper2.ScalarVisibilityOff()
is uncommented the grid is shown in black seemingly without influence of
sgridActor2.GetProperty().SetOpacity(0.3)

Is this expected behaviour? How would I be able to have the grid drawn in 
black with a certain opacity?


---- begin python example code -----
#!/usr/bin/env python

import vtk
import math

x = range(3)
dims = [4,4,4]
rMin = 0.5
rMax = 1.0

sgrid = vtk.vtkStructuredGrid()
sgrid.SetDimensions(dims)

scalars = vtk.vtkDoubleArray()
scalars.SetNumberOfComponents(1)
scalars.SetNumberOfValues(dims[0]*dims[1]*dims[2])
points = vtk.vtkPoints()
points.Allocate(dims[0]*dims[1]*dims[2], 1000)

deltaZ = 2.0 / (dims[2]-1)
deltaY = 2.0 / (dims[1]-1)
deltaX = 2.0 / (dims[0]-1)
for k in range(dims[2]):
    zs = -1.0 + k*deltaZ
    kOffset = k * dims[0] * dims[1]
    for j in range(dims[1]):
        ys = -1.0 + j*deltaY
        jOffset = j * dims[0]
        for i in range(dims[0]):
            xs = -1.0 + i*deltaX
            x[0] = xs
            x[1] = ys
            x[2] = zs
            offset = i + jOffset + kOffset
            points.InsertPoint(offset, x)
            scalars.InsertValue(offset, 0.5*(xs+ys+zs+3)/3);
sgrid.SetPoints(points)
sgrid.GetPointData().SetScalars(scalars)

edges = vtk.vtkExtractEdges()
edges.SetInput(sgrid)
sgridMapper2 = vtk.vtkPolyDataMapper()
sgridMapper2.SetInput(edges.GetOutput())
#sgridMapper2.ScalarVisibilityOff()
sgridActor2 = vtk.vtkActor()
sgridActor2.SetMapper(sgridMapper2)
sgridActor2.GetProperty().SetColor(0.0,0.0,0.0)
sgridActor2.GetProperty().SetOpacity(0.3)

renderer = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(renderer)

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

renderer.AddActor(sgridActor2)
renderer.SetBackground(1, 1, 1)
renderer.GetActiveCamera().Elevation(30.0)
renderer.GetActiveCamera().Azimuth(15.0)
renWin.SetSize(300,300)

renWin.Render()
iren.Start()
---- end python example code -----


-- 
Matthijs




More information about the vtkusers mailing list