<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<title></title>
<big>I had this exact problem. It turns out that the regular vtkSphereSource
class has no normals, so it can't be given a texture. And no, you can't just
add normals using the vtkPolyDataNormals class; I tried that. In the end,
there were only 2 ways to make this work:<br>
<br>
1) Use a vtkTexturedSphereSource class instead of a regular SphereSource.
This is the simplest way, but the downside is that you can only create full
spheres, not partial spheres.<br>
<br>
2) A more flexible, but more complex way, is to create a PLANE (using vtkPlaneSource),
and then warp it into a spherical shape. This is done by passing it through
a vtkTransformPolyDataFilter that uses a vtkSphericalTransform.<br>
The correct dimensions for the plane (if you're creating a full sphere)
can be obtained like this:<br>
<br>
//---------------------------------------------------------------------<br>
<br>
deg2rad = PI / 180<br>
<br>
Radius = 1.0 (or whatever you want for it)<br>
Theta = Longitude angle<br>
min_theta = 0.0 * deg2rad = 0.0<br>
max_theta = 360.0 * deg2rad = 2.0 * PI<br>
Phi = Latitude angle<br>
min_phi = 0.0 * deg2rad = 0.0<br>
max_phi = 180.0 * deg2rad = PI<br>
<br>
plane = vtkPlaneSource()<br>
plane.SetOrigin(radius, max_phi, min_theta)<br>
plane.SetPoint1(radius, max_phi, max_theta)<br>
plane.SetPoint2(radius, min_phi, min_theta)<br>
plane.SetXResolution(36) //or whatever you want, but don't make it too low<br>
plane.SetYResolution(36) //ditto<br>
plane.Update()<br>
<br>
</big><big>//---------------------------------------------------------------------</big><br>
<big><br>
<br>
Now that you have your plane set to the correct size, you warp it into a
sphere like this:<br>
<br>
<br>
</big><big>//---------------------------------------------------------------------<br>
<br>
transform = vtkSphericalTransform()<br>
<br>
tpoly = vtkTransformPolyDataFilter()<br>
tpoly.SetInput(plane.GetOutput())<br>
tpoly.SetTransform(transform)<br>
tpoly.Update()<br>
<br>
mapper = vtkPolyDataMapper()<br>
mapper.SetInput(tpoly.GetOutput())<br>
......<br>
<br>
</big><big>//---------------------------------------------------------------------<br>
<br>
And then just go from there as usual.<br>
<br>
<br>
Hope that helps :-)</big><br>
<blockquote type="cite">
<pre>Hi all, I'm trying to texture a sphere with a PNG image. I do this with
code similar to
PNGReader->SetFileName("file.png");
Texture->SetInput(PNGReader->GetOutput());
Texture->InterpolateOn(); //also tried w/o setting this
SphereSource->SetCenter(0,0,0);
SphereSource->SetRadius(1);
PolyDataMapper->SetInput(SphereSource->GetOutput());
Actor->SetMapper(PolyDataMapper);
Actor->SetTexture(Texture);
My sphere changes a deep blue when I enable the texture code, but I do
not see the actual texture on it. The actual image is small and of even
dimensions,
earth.png: PNG image data, 32 x 32, 16-bit/color RGB, non-interlaced
so I do not believe this to be a power-of-2 issue or problem loading a
texture that is beyond what my opengl implementation can do.
Perhaps most importantly, I tried running the 'TPlane.py' example and
got some disappointing output (in addition to no visible texture on the
plane):
ERROR: In /home/tfogal/tarballs/VTK/Rendering/vtkOpenGLTexture.cxx,
line 111
vtkOpenGLTexture (0x6640d0): No scalar values found for texture input!
Any ideas?
-tom
</pre>
</blockquote>
<br>
</body>
</html>