[vtkusers] vtkTexturedSphereSource::SetTheta has no effect?

Alexander Pletzer Alexander.Pletzer at noaa.gov
Fri Jul 23 16:57:31 EDT 2004


Hi,

We have some 2-d, rectilinear and uniform data (vtkImageData) that we 
want to project onto a partial sphere. We're attempting to do this by 
applying a texture map onto a partial sphere. We have some code that 
works great on the entire sphere but we have been struggling to make 
this work on a partial sphere (0 < longitudes < 360 deg, -90 < latitudes 
< 90) . From the online doc it seems that the size of the sphere can be 
controlled by two methods:

virtual void vtkTexturedSphereSource::SetTheta (  float    )  [virtual]

 

Set the maximum longitude angle.



virtual void vtkTexturedSphereSource::SetPhi (  float    )  [virtual]

 

Set the maximum latitude angle (0 is at north pole).




However using these methods on a vtkTexturedSphereSource objects appears 
to have no effect, as illustrated by the python code below.

Obviously there is something we're not doing right. Thanks in advance 
for your help:

--Alex.


#!/usr/bin/python

import sys
import Numeric as N
import vtk

def griddata(x1, x2):
    """ Given 2 coordinate vectors x1 and x2, return 2-d arrays grid
    arrays xx1, xx2 such that xx1[i,j] is the x1 coordinate at pt (i,j)"""
    n1, n2 = len(x1), len(x2)
    xx1 = N.multiply.outer( N.ones( (n2,), typecode=N.Float64 ), x1 )
    xx2 = N.multiply.outer( x2, N.ones( (n1,), typecode=N.Float64 ) )
    return xx1, xx2

nx = 11 #longitude
ny = 21 #latitude

xmin = -N.pi
xmax =  N.pi
ymin = -N.pi / 2
ymax =  N.pi / 2

dx = (xmax - xmin) / (nx-1)
dy = (ymax - ymin) / (ny-1)

x = xmin + dx*N.arange(0, nx)
y = ymin + dy*N.arange(0, ny)

xx, yy = griddata(x, y)

# generating the data
zz = 0.5 + 0.5*N.sin(xx) # the function to visualize

# cartesian coordinates
radius = 1.0
XX1 = radius * N.cos(yy) * N.cos(xx)
XX2 = radius * N.cos(yy) * N.sin(xx)
XX3 = radius * N.sin(yy)

xyz = N.zeros( (nx*ny*1, 3), N.Float64)
xyz[:,0] = XX1.astype(N.Float32).flat
xyz[:,1] = XX2.astype(N.Float32).flat
xyz[:,2] = XX3.astype(N.Float32).flat

vtk_xyz = vtk.vtkDoubleArray()
vtk_xyz.SetNumberOfTuples(nx*ny)
vtk_xyz.SetNumberOfComponents(3)
vtk_xyz.SetVoidArray(xyz, nx*ny*3, 1)

vtk_pts = vtk.vtkPoints()
vtk_pts.SetNumberOfPoints(nx*ny)
vtk_pts.SetDataTypeToDouble()
vtk_pts.SetData(vtk_xyz)

vtk_zz = vtk.vtkDoubleArray()
vtk_zz.SetNumberOfTuples(nx*ny)
vtk_zz.SetNumberOfComponents(1)
vtk_zz.SetVoidArray(zz, nx*ny, 1)

v = vtk.vtkStructuredGrid()
v.SetDimensions(nx, ny, 1)
v.SetPoints(vtk_pts)

lookup = vtk.vtkLookupTable()
lookup.SetHueRange(0.667, 0.0)
lookup.Build()

image = vtk.vtkImageData()
image.CopyStructure(v)
image.GetPointData().SetScalars(vtk_zz)
image.SetScalarTypeToDouble()

texture = vtk.vtkTexture()
texture.SetInput(image)
texture.SetLookupTable(lookup)
texture.MapColorScalarsThroughLookupTableOn()


sphere = vtk.vtkTexturedSphereSource()
sphere.SetRadius(1.0)
sphere.SetThetaResolution(ny)
sphere.SetPhiResolution(nx)
sphere.SetTheta(25.) # <<<<< this has no effect?
sphere.SetPhi(10.)   # <<<<< this has no effect?
print str(sphere)


mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(sphere.GetOutput())

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

ren1 = vtk.vtkRenderer()
ren1.AddActor(actor)

win = vtk.vtkRenderWindow()
win.AddRenderer(ren1)
win.SetSize(500, 500)

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

style = vtk.vtkInteractorStyleTrackballCamera()
iren.SetInteractorStyle(style)

iren.Initialize()
iren.Start()





More information about the vtkusers mailing list