vtkTextureMapToSphere and PreventSeamOff not working as expected

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

vtkTextureMapToSphere and PreventSeamOff not working as expected

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


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers

one.png (7K) Download Attachment
testOne.png (70K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: vtkTextureMapToSphere and PreventSeamOff not working as expected

Meehan, Bernard
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" <[hidden email]> 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()
>


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: vtkTextureMapToSphere and PreventSeamOff not working as expected

Alex Pletzer
In reply to this post by Alex Pletzer
All,

One way to solve the above problem is to set the end theta coordinate to 360 - eps, where eps is ~ 1.e-4.

eps = 1.e-4
sphere1.SetEndTheta(360. - eps)

A very small gap remains visible but the topology is now correct.

--Alex
Reply | Threaded
Open this post in threaded view
|

Re: vtkTextureMapToSphere and PreventSeamOff not working as expected

Alex Pletzer
In reply to this post by Meehan, Bernard
Thanks Bernard! Works!

--Alex
Reply | Threaded
Open this post in threaded view
|

Re: vtkTextureMapToSphere and PreventSeamOff not working as expected

Alex Pletzer
In reply to this post by Meehan, Bernard
Below is the corrected code...

import vtk
"""
How to add texture to a sphere
"""

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.vtkTexturedSphereSource()
sphere1.SetThetaResolution(12)
sphere1.SetPhiResolution(12) # co-latitude
 
# Read the image data from  file
reader1 = vtk.vtkPNGReader()
reader1.SetFileName(filename1)
 
# Create texture object
texture1 = vtk.vtkTexture()
texture1.SetInputConnection(reader1.GetOutputPort())
 
# Create mapper and set the mapped texture as input
mapper1 = vtk.vtkPolyDataMapper()
mapper1.SetInputConnection(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()