Converting Data to Normal Coordinates

Most transformations are handled by the transformation matrix of a model object. For convenience, however, visualization objects may also have a simplified transformation applied to them. Coordinate transformations applied to individual graphic visualization objects allow you to change only the translation (position) and scale; this is useful when converting from one coordinate system to another.

For example, you may build your view object using normalized coordinates, so that values range between zero and one. If you create a graphic object—a surface object, say—based on the range of data values, you would need to convert your surface object (built with a data coordinate system) to match the view object (built with a normal coordinate system). To do this, use the [XYZ]COORD_CONV keywords to the graphic object in question. The [XYZ]COORD_CONV keywords take as their argument a two-element vector that specifies the translation and scale factor for each dimension.

Suppose you have a surface object whose data is specified in a range from [0, 0, zMin] to [xMax, yMax, zMax]. If you wanted to work with this surface as if it were in a normalized [–1, –1, –1] to [1, 1, 1] space, you could use the following coordinate conversions:

; Create some data: 
myZdata = DIST(60) 
; Use SIZE to determine size of each dimension of myZdata: 
sz = SIZE(myZdata) 
; Create a scale factor for the X dimension: 
xs = 2.0/(sz[1]-1) 
; Create a scale factor for the Y dimension: 
ys = 2.0/(sz[2]-1) 
; Create a scale factor for the Z dimension: 
zs = 2.0/MAX(myZdata) 

Now, use the [XYZ]COORD_CONV keywords to the IDLgrSurface::Init method to translate the surface by minus one unit in each direction, and to scale the surface by the scale factors:

mySurface = OBJ_NEW('IDLgrSurface', myZdata, $ 
   XCOORD_CONV = [-1, xs], YCOORD_CONV = [-1, ys], $ 
   ZCOORD_CONV = [-1, zs]) 

Remember that using the [XYZ]COORD_CONV keywords is simply a convenience—the above example could also have been written as follows:

; Create some data: 
myZdata = DIST(60) 
; Use SIZE to determine the size of each dimension of myZdata: 
sz = SIZE(myZdata) 
; Create a scale factor for the X dimension: 
xs = 2.0/(sz(1)-1) 
; Create a scale factor for the Y dimension: 
ys = 2.0/(sz(2)-1) 
; Create a scale factor for the Z dimension: 
zs = 2.0/(MAX(myZdata) 
; Create a model object: 
myModel = OBJ_NEW('IDLgrModel') 
; Apply scale factors: 
myModel->Scale, xs, ys, zs 
; Translate: 
myModel->Translate, -1, -1, -1 
; Create surface object: 
mySurface = OBJ_NEW('IDLgrSurface', myZdata) 
; Add surface object to model object: 
myModel->Add, mySurface 

A Function for Coordinate Conversion

Often, it is convenient to convert minimum and maximum data values so that they fit in the range from 0.0 to 1.0 (that is, so they are normalized). Rather than adding the code to make this coordinate conversion to your code in each place it is required, you may wish to define a coordinate conversion function.

For example, the following function definition accepts a two-element array representing minimum and maximum values returned by the XYZRANGE keyword to the GetProperty method, and returns two-element array of scaling parameters suitable for the XYZCOORD_CONV keywords:

FUNCTION NORM_COORD, range 
   scale = [-range[0]/(range[1]-range[0]), 1/(range[1]-range[0])] 
   RETURN, scale 
END 

If you define a function like this in your code, you can then call it whenever you need to scale your data ranges into normalized coordinates. The following statements create a plot object from the variable data, retrieve the values of the X and Y ranges for the plot, and the use the XYCOORD_CONV keywords to the SetProperty method and the NORM_COORD function to set the coordinate conversion.

plot = OBJ_NEW('IDLgrPlot', data) 
plot->GetProperty, XRANGE=xr, YRANGE=yr 
plot->SetProperty, XCOORD_CONV=NORM_COORD(xr), $ 
   YCOORD_CONV=NORM_COORD(yr) 

Example Code
The function NORM_COORD is defined in the file norm_coord.pro in the examples/doc/utilities subdirectory of the IDL distribution. Run this example procedure by entering norm_coord at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT norm_coord.pro.