Graphical Transformations and Hierarchic Picture Structures*,* W . I{.
~ALLGI~EN
AND A . C . Stt.A_w
Department of Compuler Science, University of Washington, Seattle, Washinglon 98195 Received July 6, 1976; revised December 7, 1977 and June 26, 1978 Precise definitions are given for the notions of picture-object, graphical transformation, overlaying of pictures, and hierarchic picture s~ructnre. Graphical transformations inchide pure geometric transformations and specifieati(msthat restrict the domain of a picture-object, for example, clipping regions and picture extents. General algorRhms based on these de~nitions arc described for composing and applying transformations i,l hierarchic graphics systems. The results are pertinent to a wu,iety of systems tha~ use hierarchic picture descriptions. The main contributions are the clarification of the concepts used in general transformation systems and the simple algorithms that result {rein this clarification.
Common
i. INTRODUCTION features of many graphics systems and applications include the
organization of pictures in a hierarchical manner, the use of geometric picture transformations such as translation and rotation, and the definition of areas or volumes either for clipping or the specification of picture extents. The purpose of this paper is to clarify the concepts underlying transformation systems, and t o present simple general algorithms for the composition (concatenation) of transformations within and between levels in hierarchic picture structures. The next section precisely defines the notions of picture-object, region, picture sum, transformationi and hierarchic picture structure, and develops formulas for composing transformations and for applying them to picture-objects. Structure traversal algorithms t h a t compose transformations and perform picture visibility (boxing) tests are t h e n described. The last section discusses some useful applications. Our definitions and algorithms apply to a variety of systems, including b o t h those based on graphics data structures and on display procedures [13]. 2. PICTURES AN]) TRA_NSFORMATIONS Algorithms which operate on objects should be based upon precise definitions of b o t h the objects and the operations which may be performed on them. In this * This paper is a revised and extended version of an earlier paper (Technical Report No. 76-0202, Department of Computer Science, University of Washington) presented at the ACM/CIPS Northwest 76 I~egional Conference, Seattle, Wash., June, 1976. This work was supported in part by the National Science Foundation tlu'ough Grant No. !VICS75-19480. 2,3.7 0146-664X/78/(}(182-0237502,00/tl Copyright, ~ 1978 by Academic Press, Ine. All rights of reproduction in any form reserved.
238
h[ALLGREN AND SHAW
p~per the objects to be operated upon are picture-objects, and the operations to be performed are the transformation and combination of pictures. Each of these concepts is defined below.
2.1. Picture Functions We start with the abstract notion of a two-dimensional picture in t h e plane. Any such picture can be mathematically characterized by a reM-valued picture function f(x) of two real numbers x = (xl, x2) with the property 0_< f(x) < M
f o r a ] l x ~ U,
where U (the "universe") denotes the plane, that is, the set of all ordered pairs of real numbers, M is the maximum intensity or gray level of the picture, and the level 0 denotes background [14, 15]. We also have occasion to use the s t a n d a r d mathematical representation of a function as a set of ordered pairs,
{(x, f(x))Ix The definition of a picture function extends naturally to ~ dimensions (n > 1) by letting x be an ordered n-tuple (x~, x~, x3 . . . . , x,,), and U be n-space [1.61. The results which follow may be interpreted for any co, slant value of ~z, b u t we are primarily concerned with two and three dimensions. W h e n a picture is a collection of "shapes," as in many computer graphics applications, it is sometimes convenient to specify the picture function as a set of points, curves, etc., for which the function is nonzero. This is especially true with binary pictures, where f is restricted to values 0 and 1 only. Two picture functions, fl and f~, may be overlayed or summed to yield a new picture function ] = fl -k f2, where for any x the resulting picture f u n c t i o n is defined as follows: f(x) = (fl q- f~)(x) = maximum(fl(x), f2(x)). This corresponds to the common operation of overlaying or merging two pictures. (Other definitions that correspond to the intuitive notion of combining pictures m a y also be used; for example, in [14], the definition f(x) = minimurn(fl(x) -]- f2 (x), M) is given.)
2.2. Regions a~d Picture Specification In computer graphics, one frequently requires facilities for selecting parts of pictures that lie within a certain area or volume called the clipping region, and for eliminating those parts outside the region. Also, it is often convenient to declare t h a t pictures already lie only within some region called an extent? For example, the "within" option of X P L / G [101 specifies a clip to a rectangular region, a n d the "size" statement of Newman's extended LOGO can be interpreted as declaring an extent of a picture (provided no clipping is required) [12]. In current twoThe term "extent" has been used by severM authors [7, 13] but has not been precisely defined. For our purposes an extent of a picture is any regkm which includesthe picture domain. (Region and picture domain ~re definedin the next two paragraphs.)
GRAPHICAL TRANSFORMATIONS
239
dimensional graphics, regions are usually constrained to he rectangular areas, b u t more complex regions such as the interiors of arbitrary polygons seem practical and useful. To cover all foreseeable cases, we define a region as a set of points in the universe U. Recognizing the fact that most real pictures are finite in size, we now formally define a picture-object P as a partial picture function defined only within some region. P is represented by the pair if, D], where f is a picture function and D is the domain of the picture-object. Thus we have: P = if, D ] = {(x, f(x))Ix E D, D ___ U}.
(1)
Delimiters "[-" and "]" around a pair denote a picture-object. (Other delimiters are introduced later to attach other meanings to pairs.) Tlfis definition of a picture-object not only relieves us of having to specify parts of a picture which do no~ interest as, but also shows the domain of a pict~lre explicitly. We lose no generality since if D = U then P is identicM to J'. :Note that two picturc-ebjects P~ = [A, Di] and P.2 = [J',~, D~'~ are identical objects provided only that ])i = D., and fi(x) = f2(x) for all x inside Di; fi and f~ need not be identicM outside of Dv Thus, a particular choice of f such that P = i f , D] gives ill generM only one of many possible representations of P. The + operator for overlaying awe picture functions is now extended for summing two picture-objects, say Pi = i f i, D1] and P~ = [J'.~, D~-], to yield a new pieture-obi eet : z-,' = P~ + p~ = If,, D'], (2) wherc D' = Di U D,~ and f ( x ) = fi(x)
for all x E D1 -- D~
-- :f~(x)
for all x E D,~ -- D~
= fi(x) + f2(x)
for all x E Di [~1 D~
:EKi~PLE. Consider a binary picture containing only the line seglrtent from (--1, --i) to (1, 1) in the plane. Two ways to represent this line segmen~ are illustrated ia Fig. 1. If intensity 0 is interpreted as "background," P~ and P~ look the same when displayed, but, by our definition, they arc not the same pictureobject. P~ represents a section of an infinite 45 ° line and is defined everywhere within the square area of D~. P~ has intensity 1 on the liIie segment and is undefined everywhere else. In the first case the concept of "line" is embodied in ~he picture function f~; in the second case the domain D~ acts as the "Fine" specifier.
2.8. Transformations on Pictures Almost all computer graphics applications require the ability to transform pictures geometrically; common transformations are translation, scaling, and rotation. In its most general form a geometric transformation may be characterized by a function G which maps points to points in U. We have already noted that the ability either to clip pictures or to specify their extent without clipping is also useful in many cases. Both of these operations
MALLGREN AND SHAW
9,40
Pl = [FI'DI ] where fl(x) =
I i f Xl=X2 0 otherwise
D1 = (~ I "1:xi:1, -I::x2~I}, i.e. the points nf Dl form a square area.
1'I:
D1:
Pl:
r-T-,
L_ I _ ; (-I,-I)
7 "-(~,-i)
I
-
-
i
°~ (-I,
P~ = [f2,D21 where f2(~) = I for all D2 = {~ i -LXl~l, -L~x2=l, Xl=XZ}, i,e. the paints of g2 are onlzon the llne segment.
f2:
I]2: x2
P2: x2
F,o. 1. Two representations Gf a line segment. may be thought of as restrictions of the domain of a picture-object. Any such restriction m a y be characterized by a region R as defined in Section 2.2. I n order to conveniently handle both geometric and restriction operations on picture-objects, we define a generalized graphical transformation T as a function between picture-objects which may be represented by the ordered pair (G, R). ttere G is a function between points of U, and R is a region (R __c U) ; G is the geometric part and R the restriction part of the transformation T. We require t h a t G be a one-to-one correspondence so that we may use its inverse G-I. (Since G cannot be many-to-one, projections from 3D to 2D cannot be handled directly; but see Section 4.3.) The action of T = (G, R) on picture-object P = If, D] to produce a new picture-object P ' = FJ",D'] is defined as follows :
T h a t is, we first restrict the domain of P t o / ~ A D. Then the resulting pictureobject is mapped (i.e., "moved") by application of G. These ideas are illustrated ill Fig. 2. F r o m (3), wo can derive D' and the mos~ obvious f~ explicitly : Let x' -~ G(x).
GRAPHICAL TRANSFORMATIONS
x2
241
/f-'hD !
\
I
1 I
z
l/~" \
: f(x)
~
k7
Da~
EJ ~
/ x_' : G(x)
\ / v
D' : G(DaR)
> xI
xI
Restrict the domain to region R.
Apply function G to each p o i . t .
Fro. 2. Transforming ~ picture-obiect by
Then
T(P) = {(x', f(G-~(x')))la-*(x ') ~ R ~ D} = {(x',/oa-~(x')) Ix' E a ( 2 ( - / D ) } , where o denotes function {G(x) lx E R}. Therefore, D ' = G ( R CI D), and
composition and the expression G(/~) means using definition (1), we have f ' --- f o G -1 ,
T(P) = <~, R>([/, i)]) = [foG-~, a(R N D)].
(4)
Equation (4) is primarily useful for obtaining later results. Here G-~ appears in the expression for f' because all points have been moved by G; the intensity of a given x' in D ~ is identical to that of x = G-~(x ') in D, as shown in Fig. 2. We m a y now define a pure geometric transformation as a graphical transformation (G, U), t h a t is, R = U so t h a t no restriction is performed. Similarly a pure restriction is a transformation (I, R), where I is the identity function so t h a t no points are moved. EXamPLES. (1) The usual 3]:) transformations translation, scale change, and rotation m a y be expressed a s graphical transformations
242
.MALLGREN AND SItAW
preted as an extent. (LOGO actually treats it as a clipping region.) TO T R I A N G L E 10 SIZE "0 0 10 I0" 2O MOVETO 0 0 3O L I N E T O 5 10 4O L I N E T O 10 0 50 L I N E T O 0 0 END Here the graphical transformation is restricts the picture-object to a particular region of definition, but does not change the triangle itself. =
2.~. Tra~sformation Composition a~d tl~e Visibility Test A computer-produced picture or picture part P,~ is often the result o f a series of transformations T1, f2, . . . , T, applied to some starting picture P0. Clearly one m a y compute P1 = TI(P0), P2 = T~.(P~), and so on to reach P~ = T,~(P~_I), b u t it is often more efficient to first compose all the trausformations to a single equivMent transformation T, thus transforming each of the elements of P0 only once. The remMnder of this paper is concerned primarily with such compositions. Let T~ and T~ be graphical transformations to be applied, iI~ the order ~iven, to picture-object P. Then the co~nposition or concatenation T of Ti and T2 is defined by :
T(P)
=
T~(T~(P))
=
T~oTI(P).
Using Eq. (4) from Section 2.3, we can compute T as follows :