[vtkusers] vtkTextureMapToSphere maps 0-340 degrees

Ernvik Aron Aron.Ernvik at smhi.se
Fri Oct 19 09:33:05 EDT 2001


Hi all,

I'm trying to map a texture onto a sphere. The texture is basically a
128x128 image with a word written on it. When using the Python code
below, the texture is mapped from 0 to about 340 degrees around the
sphere, and then, another distorted (compressed) version of the texture
is mapped from 340 to 360 degrees. I believe this is the same problem as
Wilfrid Lefer had on 17 Nov 1999 - I found his question in the archives
but I haven't found any answer to it.

I've also tried to use Delaunay triangulation of the sphere
(dela=vtkDelaunay3D(); dela.SetInput(sph.GetOutput());
tmap.SetInput(dela.GetOutput())) but then about half of the generated
triangles are black (no texture on them). The black triangles appear
seemingly randomly over the sphere.

I'm using Linux/MESA and VTK3.2. Thanks for any help!

Aron Ernvik, Swedish Metheorological and Hydrological Institute


        # create sphere
        sph = vtkSphereSource()
        sph.SetRadius(radius)
        sph.SetThetaResolution(20)
        sph.SetPhiResolution(20)
        sph.SetCenter(0, 0, 0)

        # load texture
        texReader = vtkPNMReader()
        texReader.SetFileName("some_image.pnm")
        tex = vtkTexture()
        tex.SetInput(texReader.GetOutput())
        tex.InterpolateOn()

        # map texture to sphere
        tmap = vtkTextureMapToSphere()
        tmap.SetInput(sph.GetOutput())
        tmap.PreventSeamOff()
        xform = vtkTransformTextureCoords()
        xform.SetInput(tmap.GetOutput())
        xform.FlipSOn()
        xform.FlipTOn()

        # create sphere mapper and actor
        sphMapper = vtkDataSetMapper()
        sphMapper.SetInput(xform.GetOutput())
        sphActor = vtkActor()
        sphActor.SetMapper(sphMapper)
        sphActor.SetTexture(tex)



More information about the vtkusers mailing list