Positioning Image Objects in a View
By default, IDLgrImage objects are drawn at Z=0 and are positioned and sized with respect to two points:
p1 = [LOCATION(0), LOCATION(1), 0] p2 = [LOCATION(0) + DIMENSION(0), LOCATION(1) + DIMENSION(1), 0].
where LOCATION and DIMENSION are properties of the image object. These two points are transformed in three dimensions, and then projected onto the screen to form the opposite corners of a 2-D rectangle resulting in screen space points designated as p1' and p2':
The image data is drawn on the display as a 2-D image within this 2-D rectangle whose sides are parallel to the screen sides. The image data is scaled in two dimensions (not rotated) to fit into this projected rectangle and then drawn with Z buffering disabled.
To draw an image with the current full 3D transformation (the same way other objects such as polygons are transformed), set the IDLgrImage TRANSFORM_MODE property to 1. See the IDLgrImage TRANSFORM_MODE property in the IDL Reference Guide for details.
Objects are drawn to a destination device in the order that they are added (via the Add method) to the model, view, or scene that contains them. By default, image objects do not take into account the depth locations of other objects that may be included in the view object unless you enable depth testing (see "DEPTH_TEST_DISABLE" (IDL Reference Guide) for details).
This means that objects that are drawn to the destination object (window or printer) after the image is drawn will appear to be in front of the image, even if they are located behind the image object. And this also means that objects drawn after the image is drawn will appear to be in front of the image even if they are located behind the image. Since the image is drawn by default with depth testing disabled, you can think of the image primitive as `painting' the image onto the screen without regard for other objects that might already have been drawn there.
This behavior can be changed by enabling depth testing to make the image primitive behave like other primitives such as polygons when they are drawn with depth testing enabled.
The following example uses the LOCATION keyword to control image position. For information on other ways to define the position of an image object in a view, see Example: Centering an Image.
Displaying Multiple Images in Object Graphics
The following example imports an RGB image from the rose.jpg image file. This RGB image is a close-up photograph of a red rose and is pixel interleaved. This example extracts the three color channels of this image, and displays them as grayscale images in various locations within the same window. Complete the following steps for a detailed description of the process.
Example Code
See displaymultiples_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 displaymultiples_object at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT displaymultiples_object.pro.
- Determine the path to the
rose.jpgfile: - Use QUERY_IMAGE to query the file to determine image parameters:
- Set the image size parameter from the query information:
- Use READ_IMAGE to import the image from the file:
- Extract the channels (as images) from the pixel interleaved RGB image:
- Initialize the display objects:
- Now initialize the image objects and arrange them with the LOCATION keyword, see IDLgrImage for more information:
- Add the image objects to the model, which is added to the view, then display the view in the window:
- Initialize another window object:
- Change the view from horizontal to vertical:
- Change the locations of the channels:
- Display the updated view within the new window:
- Initialize another window object:
- Change the view to prepare for a diagonal display:
- Change the locations of the channels:
- Display the updated view within the new window:
- 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.
redChannel = REFORM(image[0, *, *]) greenChannel = REFORM(image[1, *, *]) blueChannel = REFORM(image[2, *, *])The LOCATION keyword to the Init method of the image object can be used to position an image within a window. The LOCATION keyword uses data coordinates, which are the same as device coordinates for images. Before initializing the image objects, you should initialize the display objects. The following steps display multiple images horizontally, vertically, and diagonally.
oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $
DIMENSIONS = imageSize*[3, 1], $
TITLE = 'The Channels of an RGB Image')
oView = OBJ_NEW('IDLgrView', $
VIEWPLANE_RECT = [0., 0., imageSize]*[0, 0, 3, 1])
oModel = OBJ_NEW('IDLgrModel')
oRedChannel = OBJ_NEW('IDLgrImage', redChannel)
oGreenChannel = OBJ_NEW('IDLgrImage', greenChannel, $
LOCATION = [imageSize[0], 0])
oBlueChannel = OBJ_NEW('IDLgrImage', blueChannel, $
LOCATION = [2*imageSize[0], 0])
oModel -> Add, oRedChannel oModel -> Add, oGreenChannel oModel -> Add, oBlueChannel oView -> Add, oModel oWindow -> Draw, oViewThe following figure shows the resulting grayscale images.
These images can be displayed vertically in another window by first initializing another window and then updating the view and images with different location information.
oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $
DIMENSIONS = imageSize*[1, 3], $
TITLE = 'The Channels of an RGB Image')
oGreenChannel -> SetProperty, LOCATION = [0, imageSize[1]] oBlueChannel -> SetProperty, LOCATION = [0, 2*imageSize[1]]
oWindow -> Draw, oViewThe following figure shows the resulting grayscale images.
These images can also be displayed diagonally in another window by first initializing the other window and then updating the view and images with different location information.The LOCATION can also be used to create a display overlapping images. When overlapping images in Object Graphics, you must remember the last image added to the model will be in front of the previous images.
oWindow = OBJ_NEW('IDLgrWindow', RETAIN = 2, $
DIMENSIONS = imageSize*[2, 2], $
TITLE = 'The Channels of an RGB Image')
oGreenChannel -> SetProperty, $ LOCATION = [imageSize[0]/2, imageSize[1]/2] oBlueChannel -> SetProperty, $ LOCATION = [imageSize[0], imageSize[1]]


