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.

  1. Select the file containing the world elevation image. Define the array, read in the data and close the file:
  2. file = FILEPATH('worldelv.dat', $ 
       SUBDIRECTORY = ['examples', 'data']) 
    image = READ_BINARY(file, DATA_DIMS = [360, 360]) 
    
  3. Prepare the display device to display a PseudoColor image:
  4. DEVICE, DECOMPOSED = 0 
    
  5. 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.
  6. LOADCT, 33 
    TVLCT, 255,255,255, !D.TABLE_SIZE - 1 
     

    (For comparison, TVLCT, 0, 0, 0, !D.TABLE_SIZE+1 would designate a black window background.)

  7. Create a window and display the image containing the world elevation data:
  8. WINDOW, 0, XSIZE = 360, YSIZE = 360  
    TVSCL, image 
     

    This image, shown in the following figure, will be mapped onto the sphere.

Figure 3-5: World Elevation Image

Mapping_an_Image_onto_a_Sphere-5.jpg

  1. 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:
  2. MESH_OBJ, 4, vertices, polygons, REPLICATE(0.25, 360, 360), $ 
       /CLOSED 
     

    The 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.

  3. 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:
  4. 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 
    
  5. 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]:
  6. SET_SHADING, LIGHT = [-0.5, 0.5, 2.0] 
    
  7. Set the system background color to the default color index, defining a white window background:
  8. !P.BACKGROUND = !P.COLOR 
    
  9. Use TVSCL to display the world elevation image mapped onto the sphere. POLYSHADE references the sphere created with the MESH_OBJ routine, sets SHADES = image to map the image onto the sphere and uses the image transformation defined by the T3D transformation matrix:
  10. TVSCL, POLYSHADE(vertices, polygons, SHADES = image, /T3D) 
     

    The specified view of the image mapped onto the sphere is displayed in a Direct Graphics window as shown in the following figure.

Figure 3-6: Direct Graphics Display of an Image Mapped onto a Sphere

Mapping_an_Image_onto_a_Sphere-6.jpg

  1. After displaying the image, restore the system's default background color:
  2. !P.BACKGROUND = 0 
    

    Note
    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).