Panning in Object Graphics

In Object Graphics, the VIEWPLANE_RECT keyword is used to change the view object. The entire image is still contained within the image object, but the view is changed to pan over specific areas of the image object.

The following example imports a grayscale image from the nyny.dat binary file. This grayscale image is an aerial view of New York City. The image contains byte data values and is 768 pixels by 512 pixels. The VIEWPLANE_RECT keyword to the view object is updated to zoom in on the lower left corner of the image. Then the VIEWPLANE_RECT keyword is used to pan over the bottom edge of the image. Complete the following steps for a detailed description of the process.

Example Code
See panning_object.pro in the examples/doc/objects subdirectory of the IDL installation directory for code that duplicates this example. Run the example procedure by entering panning_object at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT panning_object.pro.

  1. Determine the path to the nyny.dat file:
  2. file = FILEPATH('nyny.dat', $ 
       SUBDIRECTORY = ['examples', 'data']) 
    
  3. Initialize the image size parameter:
  4. imageSize = [768, 512] 
    
  5. Import the image from the file:
  6. image = READ_BINARY(file, DATA_DIMS = imageSize) 
    
  7. Resize this large image to entirely display it on the screen:
  8. imageSize = [256, 256] 
    image = CONGRID(image, imageSize[0], imageSize[1]) 
    
  9. Initialize the display objects:
  10. oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $ 
       DIMENSIONS = imageSize, $ 
       TITLE = 'A Grayscale Image') 
    oView = OBJ_NEW('IDLgrView', $ 
       VIEWPLANE_RECT = [0., 0., imageSize]) 
    oModel = OBJ_NEW('IDLgrModel') 
    
  11. Initialize the image object:
  12. oImage = OBJ_NEW('IDLgrImage', image, /GREYSCALE) 
    
  13. Add the image object to the model, which is added to the view, then display the view in the window:
  14. oModel -> Add, oImage 
    oView -> Add, oModel 
    oWindow -> Draw, oView 
     

    The following figure shows the resulting grayscale image display.

    Figure 4-6: A Grayscale Image Of New York in Object Graphics

    imgdisp22.gif

  15. Initialize another window:
  16. oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $ 
       DIMENSIONS = imageSize, TITLE = 'Panning Enlarged Image') 
    
  17. Change the view to zoom into the lower left quarter of the image:
  18. viewplane = [0., 0., imageSize/2] 
    oView -> SetProperty, $ 
       VIEWPLANE_RECT = [0., 0., imageSize/2] 
     

    The view object still contains the entire image object, but the region displayed by the view (the viewplane rectangle) is reduced in size by half in both directions. Since the window object remains the same size, the view region is enlarged to fit it to the window.

  19. Display the updated view in the new window:
  20. oWindow -> Draw, oView 
     

    The following figure shows the resulting enlarged image area.

    Figure 4-7: Enlarged Image Area of New York in Object Graphics

    imgdisp23.gif

  21. Pan the view from the left side of the image to the right side of the image:
  22. FOR i = 0, ((imageSize[0]/2) - 1) DO BEGIN & $ 
       viewplane = viewplane + [1., 0., 0., 0.] & $ 
       oView -> SetProperty, VIEWPLANE_RECT = viewplane & $ 
       oWindow -> Draw, oView & $ 
    ENDFOR 
    
    

    Note
    The & after BEGIN and the $ allow you to use the FOR/DO loop at the IDL command line. These & and $ symbols are not required when the FOR/DO loop in placed in an IDL program as shown in Panning_Object.pro in the examples/doc/objects subdirectory of the IDL installation directory.

    The following figure shows the resulting enlarged image area panned to the right side.

    Figure 4-8: Enlarged New York Image Area Panned to the Right in Object Graphics

    imgdisp24.gif

  23. Clean up the object references. When working with objects always remember to clean up any object references with the OBJ_DESTROY routine. Since the view contains all the other objects, except for the window (which is destroyed by the user), you only need to use OBJ_DESTROY on the view object.
  24. OBJ_DESTROY, oView