Mapping an Image onto a Sphere
The following example maps an image containing a color representation of world elevation onto a sphere using both Direct and Object Graphics displays. The example is broken down into two sections:
Mapping an Image onto a Sphere Using Direct Graphics
Complete the following steps for a detailed description of the process.
Example Code
See maponsphere_direct.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. Run the example procedure by entering maponsphere at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT maponsphere.pro.
- Select the file containing the world elevation image. Define the array, read in the data and close the file:
- Prepare the display device to display a PseudoColor image:
- Load a color table and using TVLCT, set the final index value of the red, green and blue bands to 255 (white). Setting these index values to white provides for the creation of a white window background in a later step.
- Create a window and display the image containing the world elevation data:
file = FILEPATH('worldelv.dat', $
SUBDIRECTORY = ['examples', 'data'])
image = READ_BINARY(file, DATA_DIMS = [360, 360])
LOADCT, 33 TVLCT, 255,255,255, !D.TABLE_SIZE - 1(For comparison,
TVLCT, 0, 0, 0, !D.TABLE_SIZE+1would designate a black window background.)
- Use MESH_OBJ to create a sphere onto which the image will be mapped. The following line specifies a value of
4, indicating a spherical surface type: - Create a window and define the 3D view. Use SCALE3 to designate transformation and scaling parameters for 3D viewing. The AX and AZ keywords specify the rotation, in degrees about the x and z axes:
- Set the light source to control the shading used by the POLYSHADE function. Use SET_SHADING to modify the light source, moving it from the default position of [0,0,1] with rays parallel to the z-axis to a light source position of [-0.5, 0.5, 2.0]:
- Set the system background color to the default color index, defining a white window background:
MESH_OBJ, 4, vertices, polygons, REPLICATE(0.25, 360, 360), $ /CLOSEDThe vertices and polygons variables are the lists that contain the mesh vertices and mesh indices of the sphere. REPLICATE generates a 360 by 360 array, each element of which will contain the value 0.25. Using REPLICATE in the Array1 argument of MESH_OBJ specifies that the vertices variable is to consist of 360 by 360 vertices, each positioned at a constant radius of 0.25 from the center of the sphere.
WINDOW, 1, XSIZE = 512, YSIZE = 512 SCALE3, XRANGE = [-0.25,0.25], YRANGE = [-0.25,0.25], $ ZRANGE = [-0.25,0.25], AX = 0, AZ = -90
- After displaying the image, restore the system's default background color:
!P.BACKGROUND = 0Note
To create a Object Graphics display featuring a sphere that can be interactively rotated and resized, complete the steps contained in the section, Mapping an Image Object onto a Sphere (Object Programming).

