[vtkusers] vtkTextureMapToSphere and PreventSeamOff not working as expected

Meehan, Bernard MEEHANBT at nv.doe.gov
Wed Aug 6 20:52:16 EDT 2014


I was trying to do the same thing last week. Try the
vtkTexturedSphereSource instead:
http://www.vtk.org/doc/nightly/html/classvtkTexturedSphereSource.html


On 8/6/14 3:57 PM, "Alexander Pletzer" <pletzer at txcorp.com> wrote:

>Hi,
>
>I'm trying to wrap the simple attached image around a sphere using
>vtkTextureMapToSphere and got some unexpected result -- the word
>"center" appears twice. Also the blue line is completely absent. There
>also appears to be a small gap at longitude 0 (see testOne.png). It
>looks as if the texture file was used twice.
>
>Does anyone know hoe to fix this? After some googling I found that some
>people had to write a custom vtkTextureMapToSphere class to deal with
>this problem. I'd like the texture to completely cover the sphere, each
>of the "nw", "sw", "se", "ne", and "center" texts should only appear
>once, each of the red, blue, white, and green should also appear only
>once.
>
>Thanks in advance.
>
>--Alex
>
>
>import vtk
>import sys
>
>filename1 = "one.png"
>
># Create a render window
>ren = vtk.vtkRenderer()
>renWin = vtk.vtkRenderWindow()
>renWin.AddRenderer(ren)
>renWin.SetSize(480,480)
>iren = vtk.vtkRenderWindowInteractor()
>iren.SetRenderWindow(renWin)
>
># Generate a sphere polydata
>sphere1 = vtk.vtkSphereSource()
>sphere1.SetThetaResolution(12)
>sphere1.SetPhiResolution(12)
>sphere1.SetStartTheta(0)
>sphere1.SetEndTheta(360)
>
># Read the image data from  file
>reader1 = vtk.vtkPNGReader()
>reader1.SetFileName(filename1)
>
># Create texture object
>texture1 = vtk.vtkTexture()
>texture1.SetInputConnection(reader1.GetOutputPort())
>
># Map texture coordinates
>map_to_sphere1 = vtk.vtkTextureMapToSphere()
>map_to_sphere1.SetInputConnection(sphere1.GetOutputPort())
>map_to_sphere1.PreventSeamOff()
>
># Create mapper and set the mapped texture as input
>mapper1 = vtk.vtkPolyDataMapper()
>mapper1.SetInputConnection(map_to_sphere1.GetOutputPort())
>
># Create actor and set the mapper and the texture
>actor1 = vtk.vtkActor()
>actor1.SetMapper(mapper1)
>actor1.SetTexture(texture1)
>
>ren.AddActor(actor1)
>
>iren.Initialize()
>renWin.Render()
>iren.Start()
>




More information about the vtkusers mailing list