The PermMapPermMap is a rather more complicated MappingMapping than we have met previously. Its purpose is to change the order, or number, of coordinates. It is also able to substitute fixed values for coordinates.
To illustrate its action, suppose our input coordinates are denoted by
(
) in a 4-dimensional space and suppose our output
coordinates are to be (
). Our PermMap, therefore,
should rotate the coordinate values by one position.
To create such a PermMap, we first set up two integer arrays. One of these, “outperm”, controls the selection of input coordinates for use in the output and the other, “inperm”, controls selection of output coordinates for use in the input:
Note that the numbers we store in these arrays are the indices of the coordinates that we want to select. We have chosen these so that the forward and inverse transformations will perform complementary permutations on the coordinates.
The PermMap is then created by passing these arrays to its constructor, as follows:
Note that we specify the number of input and output coordinates separately, but set both to 4 in this example. The resulting PermMap would have the following effect when used to transform coordinates:
If the number of input and output coordinates are unequal so, also, will be the size of the “outperm” and “inperm” arrays. This means, however, that we cannot fill them with coordinate indices so that they perform complementary permutations, because one transformation will lose information (discard a coordinate) that the other cannot recover. To give an example, consider the following:
In this case, the forward transformation will change
(
) into (
) and will discard
. The
inverse transformation restores the original coordinate order, but has
no value to assign to the first coordinate. In this case, the number
entered in the “inperm” array is
1.
This negative value indicates that the coordinate value should be obtained by addressing the first element of the “con” array (i.e. element zero). This array, ignored in the previous example, may then be used to supply a value for the missing coordinate.
The constructor function:
will then create a PermMap with the following effect when used to transform coordinates:
The “con” array may contain more than one value if necessary and may
be addressed by both the “inperm” and “outperm” arrays using
coordinate indices 1,
2,
3, etc. to refer to the
first, second, third, etc. elements.
If there is no suitable replacement value that can be supplied via the “con” array, a value of zero may be entered into the “outperm” and/or “inperm” arrays. This causes the value AST__BAD to be used for the affected coordinate (as defined in the “ast.h” header file), thus indicating a missing coordinate value (ยง5.9).
The principle use for a PermMap lies in matching a coordinate system to a data array where there is a choice of storage order for the data. PermMaps are also useful for discarding unwanted coordinates so as to reduce the number of dimensions, such as when selecting a “slice” from a multi-dimensional array.