Graphical transformations and hierarchic picture structures

Graphical transformations and hierarchic picture structures

COMPUTER GRAPHICS AND IMAGE PROCESSING 8, 237-258 (].978) Graphical Transformations and Hierarchic Picture Structures*,* W . I{. ~ALLGI~EN AND A ...

1MB Sizes 33 Downloads 85 Views

COMPUTER

GRAPHICS AND IMAGE PROCESSING 8,

237-258 (].978)

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(P) = (G, R)(['f, D]) = {(G(x), f(x))lx ~ R (~ D}.

(3)

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 :

~r~(T~(P)) = ([foGc ~, C,~(R~ N Z))]) [foal-lOG2-1, G,~(R2n G~(R~n D))] =

= [/o(G:oG0-% ¢~oG, oO~-~(R~ N G~(I~, n 29))]

= [fo(a~oa,)-% ¢,~o¢,((¢~-,(:~:) N ~,) n z))] = ([f, D ] ) = T(P). Thus, we ca11 now compose any two arbitrary graphical transformations into a single equivMent transformation using the formula :

= .

(5)

The new geometric function is the composition of the constituent geometric functions, as one would expect. The new restriction region is the intersection of the two constituent regbns performed in the untransformed coordinate system. The equivalence of T2(T~(P)) and T2 oT~(P) is demonstrated informally in Fig. 3. Using (5), any composition of graphicM transformations T~ oT~_~ . . . . . T~ may be reduced to a single transformation To b y computing T2oT~ first, then T~o(T2oTi), and so on. Any other bracketing requires transformation coinposition to be associative. Fortunately, associativity does hold, as proved in

GRAPHICAL

243

TRANSFORMATIONS

Appendix 1. This result is needed for the hierarchic composition algorithm in Section 3.2. In Eq. (5) the expression a~-~(R,,) A R t results in an empty region if at -~ (R~) and R~ are disjoint sets. In this ease, T(P) is ~he empty 1cloture and there is no need to look at P at all. This is the simplest example of a visibility test, also called a boziug test [-11]~ which can be applied in many graphics situations to terminate picture generation and avoid unnecessary computation. Recall that regions can be used either for clipping or to define extents (Section 2.2). The visibility ~es~ is meaningful in either ease. x2

/

G2(GI( D r ' ~ l l ) " g 2 ) ~ ~

"

I

\

i

z = f(x)

1

I

I

r'---'-'~ ~ -... RI

/ r

x" o G2(Gi ( y ) )

.....r.xxk~

\ ~ /

.

/ D"h

?~,Gi ~

\\\,

-~' : GI(X)

GI(D'~RI)aR2 ~ 2

'~\

'..."GI(DIIRI)

-"GIIDaRII

X1

xI applying <~G2,R2>

applying ~GI,RI>

;

,......D

~

~ .,Gi(~i~(a2},~Rl,m)

I i /'-VGI(R~) \ GI (R2)LiRI'ID ) \ / x" = G2-GI(x_)= G2(GI(X))

> x1 F I G . . 3 . C o m p o s i t i o n of g r a p h i c a l t r a n s f o r m a t i o n s . (b) T2oT'I(P) = (G~oGI, Gl-i(R.,) ~ RI)(P).

(a) T ~ ( T I ( P ) ) = (G~,R2>((G1, R I > ( P ) ) ;

EXA~rLI~. The display procedure call [10], draw bridge within (0, 0, 1, 1)o~to ( - 1 , - 1 , 1, 1);

24-4

MALLGEEN AND SHAW x2

x2/

(1,1) . . . .

(i,I)

~

r---

]

....

--

l ]

I , ] I

---0

>x i

vlewport I

t

(-i,-i)

FzG. 4. A graphical ~ransformation. defines both a clipping operation and a geometric transformation as shown in Fig. 4.. The desired transformation may be expressed as a sequence of graphical transformations T~, T2 in at least two ways so that the resulting picture is " " (bridge) : (i)

T~ = <~, T,~ =
a>,

G~(x~, z.~)

= (2x~ -

i, 2~..~ -

l),

R,,.>,R~ = {x I - - I _< x~ __< I, - - I < x.,. < i } .

l-lere scaling and translation are specified first (Ti), followed by a clip to the

viewport (T2). The composition of i'.2 and T1 may be computed using Eq. (5) : o = . (2)

T~ = , R1 = {x[0 _< x,~ __< i, 0 < ~2 < 1}, T~ = , ¢2(xl, x~) =

(2x~

-

1, 2~9. --

1).

I-Iere the opposite order is shown: T~ specifies a clip to the 'wi~tdow and T2 the scaling and translation. Because of our choice of representation for graphical transformations, the composition T2o T~ is especially simple in this case. Applying Eq. (5),

<¢~, ~)o = , since G2 = G~ and R1 = GI-~(R2). As suggested by the last example, our notation does not prevent a graphical transformation from being specified in either of two orders : (1) A pure geometric transformation followed by a pure restriction; or (2) a pure restriction followed by a pure geometric transformation. Similarly, a graphical transformation might actually be applied to a pictureobject either by doing a restriction before the geometric transformation, as implied by the notation T = (G, R> (Section 2.3), or restricting after the geometric transformation. If the other order, denoted , is chosen, formulas (4) and (5) are altered: Application to a picture:

<17, G>([J', D]) = [fog -~, R ~ G(D)];

(4.')

GRAPttICAL TRANSFOI~MATIONS

245

The conversions between the
(R, G)(P) =
and


(6)

Often, it is most efficient to use the
2.5. Hierarchic Picture Structures Many pictures defined and manipulated in computer graphics applications are naturally described as a finite combination (sum) of subpietures; i.e., P = ~ P~ = ~ [-]'i, Di~. The components Pi are derived from a hierarchic description of the picture that is obtained by tracing through a program and/or data structure when generating P. Each P~ is the result of successively applying geometric and restriction transformations to some "primitive" pieture-obiect during the tracing process. In order to present the transformatio~t algorithms in their most general form, an abstract hierarchic picture structure is defined. An ordered tree H is a set of nodes that can be divided into a root node and a seque~ce of disioint subsets H~, H2, . . . , I-/~, k >_ 0, each of which is an ordered tree [-9J. Each H~ will be called a progeny of the root. If a node has no progeny, it is called a leaf. A hierarchic picture structure is an ordered tree with the following information associated with each node : (1) If the node is a nonleaf, a sequence of graphical transformations T1, T2, . . . , T~, n >_ 1, where each Tj = (Gj., Rj.); or (2) if the node is a leaf, a pieture-obiec% P. Part of a sample hierarchic picture structure is shown pictorially in Fig. 5b. The picture-object represented by a hierarchic picture structure is defined as follows : (1) If the root is a nonleaf, the picture-object T~.T,,_~ . . . . . T~( E~=~k P~), where P~, P 2 , . . . , P~ are the picture-objects represented by the progeny HI, H~, . . . , If, ; or (2) if the root is a leaf, the picture-object P. This picture-object may be obtained by a preordcr (root first) traversal of the hierarchic picture structure [-91, concatenating transformations at the nodes to produce a transformed picture-object at each leaf. Detailed algorithms are presented in Section 3.

24:6

-i i tl h[:~I,I,(.~I, EN AND SIIAW "

T h e above defini~ion for a hierarchic picture structure was chosen because it is especially simple, yet it can model all hierarchic araphics structures t hat we have seem All picture information is h~ the leaves while all transformations a~d strt~ctu r e information are in the nonleaves. The use of the ordered tree in our definition allows for modeling the ordered trace through a data structure or for modeling display procedures where the structure exists only as an execution trace.

ii

I

I Figure

II

I I

X. Schematic

i'agram~Iclp(x]efty' b°Cii:i:~ity' t°p) scale(s)

©

= n o n l e a f node

= l e a f node b

FIa. 5. Ca) The "diagram" picture-object. (b) I-Iierarohic pictm'e structure for "diagram."

GRAPHICAL TRANSF()I:I MATIONS

247

EXAMPLES. The examples show how some pra(.tical equivalents of hierarchic picture structures are realized. (1) Suppose a programming system has facilities to directly manipulate a graphics data structure, such as found in ~2-6]. Part of a picture structure might be produced b y the following code : b o r d e r : = new node; {Get new node block.} b o r d e r , translate : = (xcorner, ycorner) ; {Insert geometric transformation. } b o r d e r , progeny : = list (]'~lew box(length,width), T~elo text ('Figure X. Schematic')); {Insert list containing pointers (T) to two leaf nodes. } d i a g r a m : = ,~lew node; {Get another new node block.} d i a g r a m , scale : = s ; d i a g r a m , clip : = (xleft,ybottom,xright,ytop) ; {Inser~ restriction. } diagram.translate : -- (delta.r,,deltay) ; d i a g r a m , progeny : = list (Tschematic,Tborder) ; {Insert list of pointers to other nodes like this one.} Here, scale, clip, tra~slate, and proge~y are field names in a node block. B o x atzd text are primitives each of which returns a leaf node. Figure 5a shows the picture-object which might be generated from this code, and Fig. 5b depicts the corresponding hierarchic picture structure. (2) The same picture-object with the same underlying hierarchic picture s t r u c t u r e as in (1) might be produced with the following code using display procedures El0]: procedure diagram ; draw schematic ... ; draw border translate ( xcorner,yeorner) ; end diagram; procedure border ;

box (length,width) ; text ('Figure X. Schematic') ; end border; draw diagram scale s within (xleft,ybottom, xright,ytop) translate (deltax,deltay) ;

W e assume that the transformations scale, within, and tra~slate are applied in the same order as their counterparts in (1). Each node name in Fig. 5b should be interpreted as a call to that procedure with associated ~ransformations. 3. COMPOSITION AND VISIBILITY ALGOI%ITHMS Transformation compositions are required in two different contexts in a general hierarchic graphics system: (1) Intranode composition: Several transformations appearing within a single n o d e m a y be combined into one transformation.

248

MALLGREN AND SHAW TABLE 1 Intranode Composition and Visibility Algori~lim (INA) G : = I ; R : = U; for i : = 1 to n do begin 1: R := G-~(R,) r~R; if R = 0 then exitloop ;

2: G:=G~oG;

{Eq. (5) } {visibility test } {Eq. (5) }

end

(2) Hierarchic composition: Transformations in successive levels of a picture hierarchy m a y be combined into a single transformation for each leaf. For efficiency and simplicity, it is desirable to produce a single (G, R> pair from given sequence of transformations in both of the above cases. Similarly, visibility tests can be incorporated into both intranode and interlevel compositions. The purpose of this section is to present simple algorithms for these tasks. 8.I. I n t r a n o d e Procedures

Given a sequence of transformations Ti, T~, . . . , T~, n ~ 1, Ti = (G~, R~.>, where each G~ defines ~ geometric transformstion and each R~ is a region, it is required to produce a single transformation T = ( G , R } such t h a t T ( P ) = T . ( . . . T 2 ( T ~ ( P ) ) . . . ) for an arbitrary picture-object P. The algorithm INA, shown in Table 1, is an iterative application of Eq. (5). I N A can be proved correct by induction, since the correctness of the compositions at statements 1 and 2 are established in Section 2.4. Suppose that the above transformation sequence appegrs at a single node N in a picture hierarchy and that the sum of the picture-objects represented b y the progeny of node N (Section 2.5) is P = i f , D]. Then the picture-object P ' represented b y the subtrec with root iV is T ( P ) , where T = (G, R} is the transformation arrived at b y applying INA at node N. If R = 0 (failure at intranode visibility test) or R A D = 0, the picture P ' is not visible ~nywhere. The alternate definition of ~ graphical transformgtion as a pair _(R, G}, where G is applied before R, yields a similar algorithm. The only change is to replace statement 1 in INA b y : 1': R : = R~ A @;(R) ; 8.2. Hierarchic Co~nposition

The algorithm for hierarchic structures is similar to but more complex t h a n the intrgnode algorithm. Here, the entire picture structure must be systematically traversed, while saving transformation information for each substructure. We assume ~ hierarchic picture structure as defined in Section 2.5, with the following selection mechanisms : (1) Each nonleaf node n has an associated transformation (n. G, n. R} (Assume that intranode compositions have already been performed.)

GRAPHICAL TRANSFOR~IATIONS

249

TABLE 2 Hierarchic (h,nl)ositicn and Visibility Algorithm (HA) proee&~re Trace (node,(G, R)) ; begi~ case node.type of nonleaf: begin

1 : R : = (node. G)-i(R) ~ node. R ; {new restriction part~Eq. (5)} {visibility ~est } if R = ~ then return; G : = Gonode.G; {new geometric part~Eq. (5) t {Trace each progeny } repeat progeny : = GetNextProgeny(nede) ; if progeny ~ 0 then relurn; Trace (progeny,(G, R)) end repeat end; {visibility tcs~} leaf; if E r~node.D ~ ~ then {Combine transformed leaf 2: P : ~- P q- (G, R)([node.f, node.D]) with current picLurc--Eqs. (2) and (3)} end ease end Trace (2) E a c h leaf node n contains a picture-object n. P = En. f, n . D J . (3) A proced~n'e Oet~extPi'ogeny (n) returns the root node of the next progeny of the node n in the progeny sequence, if one exists; if the progeny have been exhausted, OetNextProgeny returns 0. The objective of the algorithm is to compute the picture-object represented by the given structure (Section 2.5). The algorithm HA, shown in Table 2, is most naturally presented as a recursive procedure. It relies on the facts that the operation of composition of transformations is associative (Section 2.4 and Appendix 1), and that T(P~ q- P~) = T(P~) q- T(P~). The call Trace(n, ) performs compositions and visibility testing on a picture structure with root node n and initial transformation (Go, R0> (normally Go = I, R0 = U). As in the intranode case, if a picture transforination is defined as (R, G), where the restriction is applied last instead of first, simple changes to H A will give the correct algorithm for this variation; change all occurrences of "(G, R ) " to "(R G)" and replace the lines labeled 1 and leaf b y : 1': E : = R N G(node.E); leaff : if R ('] G (node. D) ~ 0 then The (R, G)_ ordering is useful in the special case of rectangular clipping regions with restricted rotations (Section 4.2.4). If the procedure Display (P) generates the picture P = El,D] on some real or abstract display device, then H A can be modified to "generate" the picture described by the structure by replacing statement 2 by : 2": Display((G, R)(Fnode. f, n o d e . D ] ) ) The GetNextProgeny procedure deserves some elaboration. If the abstract hierarchic picture structure corresponds to an actual structure constructed before

250

R:[ALLGREN AND SHAW

Trace is invoked, then GetNextProgeny may be a very simple data structure search. At the other extreme, the picture structure might exist only dynamically during the interpretation of some more general data structure or the execution of display procedure programs; in these cases, GetNextProgeny might be a:'very complex algorithm. Our only assumption is that there exists some mechanism for obtaining the next node. Algorithms INA and HA may be combined to give a complete transformation system. This can be accomplished by performing intranode compositions within HA. INA is inserted, with suitable housekeeping changes, at the beginning of the nonleaf case in HA.

'~. APPLICATIONS In the preceding sections, no restrictions were placed on the "shape" of regions or the form of geometric transformations. There are, however, many current graphics aDDlications for which various special cases are nseful and sufficient.

4.I. A fi~ze Geometric Trat~sformatio~s The most commonly used transformations in graphics are the affine transformation~ which include translation~ scaling, rotation s and skewing. In three dimensions, any function of the form G(xl, x2, xs) = (axl "1 dx2 + gx8 "-~ j, bxl -~ ex2 + hx3 + l~, cxl + fx~ + ix~ -~- l) is affine [13. We may represent x as a column vector in homogeneous coordinates [13], X2 8

and then any affine %ransformation may be eharacteri~,ed by a ~t X 4 matrix M of the form

Ii o o i1 %0 be multiplied by x as follows:

Ii i11111r 0

0

1

If matrix M is nonsingular, then the function G (x) = Mx will be a one-to-one correspondence as required. Note that x may be represented as a row vector to be postmultiplied by the transpose of matrix M as is commonly done in the literature [-13]. Premultiplieation is used here~ however, since it corresponds more closely to functional notation.

GRAPHICAL TRANSF0t%MATIONS

251

The three transformations given in Example (1) in Section 2.3 may be represented as matrices with

M=

I 0

0 1

0

0

s2 0

0 s8

0

0

t~

for translation,

111 =

0

[oso o !l

for scaling, and

sin ~

M=

0

cos ~ 0 0 1 0 0

for rotation.

4.2. Polygonal Regions in Two Di~ne~lsions We now examine some special cases for region R in two dimensions. Throughon~ this section we assume that G is affine so that it may be represented by a matrix for performing computations.

,~.2.1. Convex Polygons We first assume that R may be represented by a convex polygon with a finite number of vertices. (More precisely, assume t h a t / 7 contains those points which are on the boundary and interior of ~ convex polygon.) Since any concave polygon can be defined as the unlo~ of a set of convex polygons, this is not a %heoretical limitation. The convex polygon case is of interest because of the existence of a practical algorithm due to Sutherland and Hodgman [18], which computes %he intersection of any two planar convex polygonal regions. We represent the convex polygonal region R by a vertex matrix VR =

i

y~... 1

,

where

~.

are %he homogeneous coordinates of the ith vertex of the polygon. The affine transformation G is represented by a 3 X 3 matrix, Mm Then, the transformed region G(R) can be defined as G(R) = {x'[x' inside or on the polygon represented by MaV~}, where MoVR is an ordinary matrix multiplication defining a new vertex matrix. Since the intersection of two convex polygonal regions is always convex, all region intersections may be performed using the Sutherland/Hodgman algorithm on the vertex matrices.

252

MALLGI1EN AND SHAW

4.2.2. Recla~tgular Regio~ls with R~,tatiml Regions may be defined by rectangles aligned with the two coordinate axes. One would expect a great simplification of the mathematics of "composing" regions with this restriction. However, rotation and skewing transformations can rotate or skew the rectangles; intersection of such transformed regions can result in general convex polygons, and we are back to the ease of Section ,t.2.1. This restriction is useful, nevertheless, since rectangular regions are easy to specify and sufficiently general for many applications.

4.2.3. Rectawular Regimes with No Rotations The composition process is simplified considerably if rotations are not permitted. Any rectangular region R with sides parallel to the coordinate axes may be represented by a vertex matrix of the form

[~xl V ', = /Yb [1

X.~]

xr

xr

yb

yt

1

1

,

where each column represents a vertex point at one of the four corner,s of the rectangle (1 = left, r = right, b = bottom, t = toi)). First, assume that M can specify scaling and translation only. Such a trans:formation can be represented by a matrix °

ll:l'~ =

sy

,

0 where sx and sy are sealing parameters and tx and ty are translation parameters in the x and y directions, respectively. The product ~IstV/~ =

/

yb'

yt'

1

1

'

,

where xl' = sx.xl + tx, yb' = sy.yb + ty, xr' = sz.xr -Ftx, yt' = s y . y t - F t y . Thus the region property of rectangularity with axes alignment is preserved. The intersection of rectangular regions also preserves the simple rectangularity and alignment properties. R ' = Ri A R2 is defined by x l ' = max(xll, xl2), yb' = max(ybi, yb~), xr' = min@ri, xr~), and yV = min(yti, y%), where al, a2, and a' refer to the coordinates of VR~, V~, and V~,, respectively. Note t h a t the visibility test is easily performed here. If xl' > xr' or yb' > yt', the intersection is empty and no rectangle corresponding to V~, exists. Finally, the inverse M~ -~ of the matrix .~/£~is a matrix M,t -i =

sy' o

t

where sz' = 1/sx, tj:' = ~ t z / s x , sy' = 1/sy, and ty' = - t y / s y .

GRAPHICAL TRANSFORMATIONS

253

All the computations necessary for the algorithms of Sections 3.1 and 3.2 may be performed by the straightforward techniques illustrated here, provided that the regions and transformations are properly restricted. The -~I,t and VR matrices are convenient pedagogic representations; for any implementation, only the parameters sx, sy, tz, ty, and zl, xr, yb, yt need be explicitly carried with the computations.

4.2.~. Rectangular Region,s with Limited Rotations Prohibiting rotations is often too severe a constraint. Fortunately, it is possible to allow rotations in a limited context and still use aligned rectangular regions. This can be done with an "adaptive transformation and clipping routine" as pointed out by Newman and SprouI1 [13]. Details of one such system, called X P L / G , are given in Turrill and Mallgren [-19]. In XPL/G, rotation is permitted anywhere, but clipping is not allowed in any subtree whose root contains a rotation (i.e., R = U at the nonleaf nodes, D = U at the leaves). Transformations are composed using the (G, E) form of T and Eq. (5) until a rotation is en= countered at some node n. Within the subtree of ~, composition is done using the (R, G)_ form and Eq. (50. The conversion from (G, R) to {R, G} form (Eq. (6)) is done before node n is processed. Since R1 = D = U in Eqs. (4-') and (59, the clipping region remains constant inside the subtree. X P L / G performs both intranode and hierarchic compositions. The XPL/G programmer can use windows as either clipping regions or extents. Because of automatic visibility testing, the use of multilevel windowing by XPL/G programs has caused dramatic speed-ups in picture generation and hit processing. For example, in one logic circuit diagram application, declaring a rectangular extent around each gate reduced the time required for hit processing by at least a factor of three. The formalism presented in this paper describes the XPL/G mechanisms clearly and faithfully, yet it was worked out long after the XPL/G implementation. As a result of going back and looking at XPL/G in this new light, the authors have gained a better understanding of how the system works. Certainly, had this work been available earlier, the XPL/G effort would have been considerably easier.

4.3. Modeling, Viezoing, and Image Transformatio~s In this section we discuss transformations used to produce a two-dimensional view of an object from an object description in either two or three dimensions. In general, the 3D case requires both a clip to a viewing volume (usually a pyramid) and a perspective transformation. The 2D analog is a somewhat simpler window-to-viewpoint mapping. We use as our example the graphics standard proposed by a committee of A C M / S I G G R A P H [17]. That document divides the facilities required for wireframe graphics into two parts: the ~liodeli~g system in which objects are defined and manipulated in world coordinates and the core graphics system, which displays images on a view surface ii1 device coordi~ates. A picture-object as we define it

25~

MALLGREN AND SHAW "project" t o

c l i p to

•, ~C t

view volume Tc

]

I

map into physical

3D image

vimw,e, I

i t ene .... too

Tp

device coordinates

Ti

Td

WC : world coordinates NDC : normalized device coordinates PDC = physical device coordinates

Fro. O. Picture generation process for three dimensions. may be interpreted either as an obiect in world coordinates or as an image in device coordinates. The transformations suggested for the modeling system include the geometric transformations. Tools for manipulating these transformations--composition, stacking, and application to a point--are those provided by our algorithms INA and H A (Section 3). The core graphics system allows specification of viewi~g trm~sfor~Tatio~s which map from world coordinates to normalized device coordinates with optional clipping, and image transformations which further modify images before actual display. Our formalism can easily describe this sequence of transformations. Fig~lre 6 shows the transformations used by the picture generation process in three dimensions. The equivalent composite transformation may be written T = T~oT~oT~oTm defined as follows: (1) Ta = (I, R~>, w h e r e / ~ is a truncated, possibly skewed pyramid or parallelepiped if window and depth clipping are enabled, a semi-infinite pyramid or infinite parallelepiped if only window clipping is enabled, a region1 bounded b y two parallel planes if only depth clipping is enabled, or U if no clipping is enabled. (2) T, =
li

o o

o

g/c + 1/d

"

(We assume that the perspective division is postponed until ~he trallsformations are actually applied to the picture-obiect.) As the viewing distance d becomes iufinite Mp reduces to the matrix for a scale change (Section zt.1) as one would expect. (3) Ti = (G~, U>, where &i is an affine transformation made up of translation, scaling, and rotation.

GRAPHICAL

255

TRANSFORMATIONS x2

View volume:

x3

x2 viewpart parallelepiped:

Xl

×3

Fro. 7. A 3D perspective transformation. (4) Ta cannot be strictly modeled by a geometric transformation since it represents a mapping from 3D to 2D which is not one-to-one (Section 2.3). We may, however, view Ta as an affine transformation {Go, U} in three dimensions (containing scale and translation) with the understanding t h a t the xa coordinate of all points in the resultant picture-object is ignored for display on a twodimensional viewing surface. Since the proposed standard specifies that the image transformation consist of rotation, sealing, and translation, applied in that order, we can break down T~ still further as follows:

T, = (V~, U)o(as, U)o(G,, V), where the G's define translation, scaling, and i'otation respectively. Applying algorithm INA to the sequence of 5ransformations making up T (excluding the final conversion to 2D) we obtain the following result :

T = (aa, r/)o(e. U>o(a~, V)o(a., V)oia., V)o(Z, no) = (GaoGtoG~oG,.oG~, R,). This expression is especially simple because the only restriction (the clip to the view volume) is specified before all geometric transformations.

256

MALLGREN

_

WC

) F - c T i ~

] wind°wI Tc

"l

inapfromwindow~ to viewport [

AND

SHAW

" 2D image ~ - - - map - inta physical i transformation device coordinates

Tp

Ti

PDC>

Td

WC= world coordinates NDC= normalizeddevicecoordinates PDC= physical devicecoordinate~

FIe. 8. Picture generation process for two dimensions. As shown in Fig. 8, the series of transformations for two dimensions can be viewed in a very similar way. Again, the overall graphical transformation can be written T = TeeThe T~oT~ described as follows : (1) Ta (2) T~ rotation. (3) Ti (4) Te

= (I, Re), where Re is a possibly rotated rectangular region. = (@, U>, where @ performs translation, sealing, and (possibly5 = , where Ge performs translation and sealing. 5. CONCLUSION

We have characterized some important elements of the picture transformation process which are common to graphics systems employing a hierarchic picture organization. Current literature in this area is either specific to particular systems or particular types of transformations, and fails to elucidate the underlying concepts. There are also some interesting and useful problems generated by this research, which we have not yet considered in depth. These include :

(1) geometric transformations that are not one-to-one, (25 other types of transformations, often treated as "modes," such as intensity, line type, and character size, (3) the use of a more general definition of a picture-object employing a vectorvalued picture function to handle extra attributes as in (25, and (4) the treatment of picture properties, such as extents, as assertions about picture-objects. The main contributions of this paper are the following. The idea of a graphical transformation has been extended to include both one-to-one geometric transformations and restrictions on the domain of a picture-object. Using this extended definition of a graphical transformation, as well as general definitions of the concepts picture-object and hierarchic picture structure, we derived formulas for composing and applying transformations, and algorithms for generating pictures from a hierarchic structure. At the same time, we showed that our results are helpful in modeling both actual and proposed graphics facilities. We

GRAPHICAL

TRANSFOR,MATIONS

257

believe t h a t the definitions and resulting algorithms given here will contribute to the understanding and implementation of a large class of graphics systems. APPENDIX 1. ASSOCIATIVITY OF GRAPHICAL TRANSFORMATION COMPOSITION Using Eq. (5) we can show that the operation of composing graphical transformations is associative, i.e., Tso(T2oT1) = (TsoT~)oTI:

=
(G2oG1)-I(/T~3) (~ (Gl-l(i~2) ('~ R1)>

Wo have made use of the following {ac~s [-8"]: (1) The el)era!lion of composing one-to-one functions is associative, i.e., (2) A one-to-one hnlction distributes over region intersection, i.e., G(R~ n R1) = o(R ) Cl

(3) The inwu'se or' a composite functiou may be expressed, = Gi-~ o(72-1.

(G2oG~)-~

A more elegant proof of associaifivity may be constructed by using the fact that graphical transformation is a function over the set of picture-objects. Then the fact t h a t (t.~ot~)ot~ = tee (t~ot~) for arbitrary functions t~, t~, and t~ [-8] gives ~he result directly. No~e t h a t graphical transformation composition is not commutative, i.e., T~oTt # T~ oT~ in general. ACKNOWLEDGMENT The authors wish to t h a n k Ingrid Carlbom, Gael Curry, Andries van Dam, and Steve Tanimoto for their constructive comments and suggestions. REFERENCES 1. G. Birkhoff and S. MacLan¢, A ~urvey of Modern Algebra, MacMillan, New York, 1953. 2. G. Bracchi and D. Ferrari, A language for treating geometric patterns in a two-dimension'fl space, Commun. ACM 14, 1971, 26-32. 3. L. C. Caruthers, J. van den Bos, and A. van Dam, GPGS--a device-independent general purpose graphics system for stand-alone and satellite graphics~ Compuler Graphics 11, 2 Summer 1977, 112-119.

258

MALLGREN AND SHAW

4. C. Christensen and E. N. Pinson, Multi-function graphics for a ll~rge computer system, Proc. AFIPS 1967 I,'JCC 31, pp. 697--711. 5. P. G. Comba, A language for three-dimensional geometry, IBM Syslems J. 7, 1968, 292-307. 6. E. Denert, G. Ernst, and H. Wetzel, Oraphex68 graphical language features in algol 68, Compulers and Graphics 1, 1975, 195-202. 7. J. D. Foley, Specifying symbol instances, Dept. of Computer Science, University of North Carolina, Chapel Hill, N.C., April~ 1976, unpublished manuscript. 8. J. L. Kelley, General Topology, Van Nos~rand, New York, 1955. 9. D. E. I~nuth, The Art of Compuler Programming, Vol. 1, second ed., Addison-Wesley, I~eading, h'[ass., 1973. 10. W. R. Mallgren and C. hr. Turrill, XPLG--a programming system for easy computer graphics, Technical Note No. 60, Computer Science Teaching Laboratory, University of Washington, Seattle, Washington, October 1974:. 11. W. iVl. Newman, Display procedures, Uommun. ACM 14, 1971, 651-660. 12. W. M. Newman, Instance rectangles and picture structure, Proo. Conf. on Compuler Graphics, Pagern Recognition, and Data Slructures, University of California, Los Angeles, 1975, pp. 297-301. 13. W. M. Newman and R. F. Sproull~ Principles of Interactive Comp'tttor Graphics, McGraw-Hill, New York, 1973. 1~. J. E. I~ieber and A. C. Shaw, Interactive picture generation and manipuh~tiou through formal descriptions, Compitters and Graphics 1, 1975, 95-1(}7. 15. A. Rosenfeld, Picture Processing by Computer, Academic Press, New York, 1960. 16. A. C. Shaw, Picture graphs, grammars, and parsing. In Frontiers of Pattern Recognition (M. S. Watanabe, Ed.), pp. 491-510, Academic Press, New York, 1972. 17. Status report of the graplfic standards planning committee of ACM/SIGGRAPH, Compuler Graphics 11, 3 (Fall 1977). 18. I. E. Sutherla,nd and G. W. Hodgman, Iteentrant polygon clipping, Commun. ACM 17, 1974, 32-,t2. 19. C. N. Turrill and W. R. Mallgren, XPLG--expcrienees in implementing an experimental int,eraetive graphics programming system, Compulsrs and Graphics 1, 1975~ 55-63.