Contact us Heritage collections Image license terms
HOME ACL ACD ICF SUS DCS G&A STARLINK Literature
Further reading □ OverviewContentsPrefaceNotation1. Introduction2. Graphical output3. Coordinates4. Segments and Attributes5. Input devices6. Interaction styles7. Workstations8. Environment9. Input control10. Segment storage11. Metafiles12. Further facilities13. Individual attributesA. AbbreviationsB. Language bindingC. Complete programIndex
C&A INF CCD CISD Archives Contact us Heritage archives Image license terms

Search

   
ACDLiteratureBooksGKS
ACDLiteratureBooksGKS
ACL ACD C&A INF CCD CISD Archives
Further reading

OverviewContentsPrefaceNotation1. Introduction2. Graphical output3. Coordinates4. Segments and Attributes5. Input devices6. Interaction styles7. Workstations8. Environment9. Input control10. Segment storage11. Metafiles12. Further facilities13. Individual attributesA. AbbreviationsB. Language bindingC. Complete programIndex

Chapter 4: Segments and their Attributes

4.1 INTRODUCTION

The earlier chapters in this book have described how to construct a picture and position it on a virtual device in a natural way. In many application areas, there is a need to display the same or similar graphical information many times possibly at different positions on the device. This leads to the need for some storage mechanism whereby pictures or subpictures can be saved for later use during a program's execution. GKS has the concept of a segment for this purpose. Graphical output can be stored in segments during the execution of a program and later reused. Segments have a number of segment attributes associated with them which allow the user to modify the appearance of the whole segment in a significant way when it is reused.

To take a simple example not using segments, consider a crude animation system in which the user constructs a scenic background and then displays an object moving across the scene on successive frames; the initial frame might be something like Figure 4-1. Suppose it is the duck we want to move across the pond on successive frames; the position of the duck can be input by the operator on a keyboard and read by the program using a FORTRAN READ statement. A sequence of frames with the duck in positions such as shown in Figure 4-2 might be generated. The outline of a program to do this might be:

Figure 4-1

Figure 4-2
 100  CONTINUE 
      READ(5, '(2F6.2)') X, Y 
      NEW FRAME 
      DRAW BACKGROUND 
      DRAW DUCK AT(X, Y) 
      GOTO 100 

where the subroutine DRAW BACKGROUND draws the outline of the tree, pond and landscape and the subroutine DRAW DUCK AT draws the duck at the position (X,Y). Note that NEW FRAME clears the display but is not a GKS function. Control of the display surface and how it is cleared will be described in Chapter 7.

This is, however, a very inefficient program, because unnecessary work has to be performed. For example, the normalization transformation has to be applied afresh to the background scene for each frame despite the fact that the background does not change from frame to frame. An obvious solution to this problem would be for GKS to store the background after the normalization transformation has been applied so that on each new frame it is only necessary to perform the minimum of computation to redraw the background on the display. That is a good solution if the display is, say, a storage tube or pen plotter. However, there are more sophisticated displays, such as vector refresh displays and raster displays which allow the user to selectively erase parts of the picture or move parts of a picture. Using such a display, the most efficient implementation of this example program would be to draw the background and the duck in its initial position, then erase the duck (if necessary) and move it to the new position specified. As another example, consider the left hand picture in Figure 4-3. The picture contains one tree, one pond, one landscape and three ducks. A program to draw such a picture might well be structured as four subroutines, each corresponding to one of the graphical objects (tree, pond, landscape and duck), where the subroutine to draw the duck would be parameterized on the position of the duck:

Picture Objects

Figure 4-3
      TREE 
      LANDSCAPE 
      POND 
      DO 100 I = I, 3 
 100  DRAW DUCK AT(X(I), Y(I))

Figure 4-3 illustrates the correspondence between graphical objects and the picture. In particular, note that one object can have more than one instance in the picture. The order in which the output primitives are presented to GKS then reflects the structure of the picture, but we have as yet seen no way in which this structure can be recorded and made use of in GKS.

In GKS, as mentioned above, output primitives may be grouped together into segments, which are then associated with the output device. They can be manipulated in several ways as will be described later in this chapter. Further segment manipulations are described in Chapter 10.

4.2 CREATING AND DELETING SEGMENTS

A segment is created by the function:

CREATE SEGMENT(ID)

where ID is the name by which the segment is to be known. This segment is then the open segment. Subsequent calls to output primitive functions will result in those primitives being inserted into this open segment, as well as being output, until such time as the function:

CLOSE SEGMENT

is invoked. For example:

      CREATE SEGMENT(1) 
      DUCK 
      CLOSE SEGMENT

will create a segment with name 1 which contains the duck outline.

It is important to note that at any time, only one segment can be open, thus a series of function calls such as:

      CREATE SEGMENT(1) 
      output primitives
      CREATE SEGMENT(2)     ILLEGAL!!
      output primitives 
      CLOSE SEGMENT 
      CLOSE SEGMENT

is not permitted and will generate an error. It is also important to realize that once a segment has been closed, further output primitives cannot be added to it.

Once created, there are a number of operations which can be performed on segments. The simplest of these is deletion! A segment is deleted by calling the function:

DELETE SEGMENT(ID)

where ID is the name of the segment to be deleted. After a segment has been deleted, the segment's name can be reused.

4.3 SEGMENT ATTRIBUTES

4.3.1 Segment Transformations

In the introduction to this chapter we discussed the need to move objects, or parts of objects, around on a display in response either to some computation or to some operator direction. Segment transformations provide the way to do this efficiently. The segment transformation is a transformation operating on all the coordinates in the segment definition. When a segment is created, the segment transformation is set to the null, or identity, transformation. The segment transformation can be subsequently changed by invoking the function:

SET SEGMENT TRANSFORMATION(ID, MATRIX)

where ID is the name of the segment whose transformation is to be changed. Note that this name can be the name of the open segment; this is very useful as examples later will show. The parameter MATRIX is a 2 × 3 transformation matrix.

Constructing transformation matrices can be a tricky task and so GKS provides two utility functions, EVALUATE TRANSFORMATION MATRIX and ACCUMULATE TRANSFORMATION MATRIX to help the application programmer. The first function:

EVALUATE TRANSFORMATION MATRIX(FX, FY, TX, TY, R, SX, SY, SWITCH, MATRIX)

calculates a transformation matrix which may be fed straight into SET SEGMENT TRANSFORMATION. FX and FY specify a fixed point; TX and TY specify a translation or shift vector; R is an angle of rotation in radians and SX and SY are scale factors. The transformation matrix computed is returned in the parameter MATRIX. Scale and rotation are relative to the specified fixed point. The coordinate switch, SWITCH, can take the value WC or NDC. In the former case, the values specified for the fixed point and shift vector are taken as world coordinates, in the latter case as normalized device coordinates (Chapter 3 explains the distinction). If SWITCH takes the value WC, then the fixed point (FX,FY) and the shift vector (TX,TY) are transformed to normalized device coordinates by the current normalization transformation.

Initial picture Firstly scaling Then rotation Finally shifting

Figure 4-4

The elements of the resulting transformation matrix, which represent the shift component of the transformation, are expressed in normalized device coordinates. The transformation matrix is computed so that the order in which the transformations are applied to coordinate data is scale, rotate and shift. The sequence of diagrams in Figure 4-4 illustrates this.

We will now see some examples of the use of EVALUATE TRANSFORMATION MATRIX. The duck used in the earlier examples in this chapter is defined by a polyline beginning at the point (0,8.8) as shown in Figure 4-5. Suppose we want to move the duck so that it starts at the point (5,13.8), in world coordinates. First we need to construct a transformation matrix, which expresses the fact that we want to move the point (0,8.8) to the point (5,13.8). The point (0,8.8) has to be shifted by (5,5) to produce the point (5,13.8); no rotation or scaling (other than by 1) is required. Thus we have determined the following parameters to EVALUATE TRANSFORMATION MATRIX:

      TX=5 
      TY=5 
      R=0 
      SX=1 
      SY=1
      SWITCH=WC

What values do we assign to FX and FY? It is clear that a fixed point does not need to be specified for a shift operation, since the effect of a shift is the same on all points in the picture. However, since EVALUATE TRANSFORMATION MATRIX computes the combined effects of a scale, rotation and shift, and a fixed point does need to be specified for the first two, a fixed point must be given. Any point could be chosen in this instance, since the scaling and rotation operations (by unity and zero) do not affect the appearance of the picture. Typically the origin (0,0) would be specified as the fixed point, although if a particular point is used to calculate the shift vector, it may be clearer to take that point as the fixed point. We will use (0,8.8) as the fixed point.

Figure 4-5

Thus, the complete program to create a segment containing the duck, display it at position (0,8.8), and then move it to position (5,13.8) would be:

      CREATE SEGMENT(1) 
      DUCK 
      CLOSE SEGMENT 
      FX=0 
      FY=8.8 
      TX=5 
      TY=5 
      R=0 
      SX=1 
      SY=1 
      SWITCH=WC 
      EVALUATE TRANSFORMATION MATRIX(FX, FY, TX, TY, R, SX, SY, SWITCH, MAT) 
      SET SEGMENT TRANSFORMATION(1, MAT)

The final effect of this program is shown in Figure 4-6.

We can now write the central part of the crude animation program described in the introduction to this chapter, which obtains the position at which the duck is to be displayed from the display operator and moves the duck to this position. The duck starts at the point (0,8.8) and is to be redisplayed at the point (XL,YL) which is the position input by the operator. The program is thus:

Figure 4-6
      CREATE SEGMENT(1) 
      DUCK 
      CLOSE SEGMENT 
      FX=0 
      FY=8.8 
      R=0 
      SX=1 
      SY=1 
      SWITCH=WC
 100  CONTINUE
      READ(5, '(2F6.2)') XL, YL 
      TX=XL 
      TY=YL-8.8 
      EVALUATE TRANSFORMATION MATRIX(FX, FY, TX, TY, R, SX, SY, SWITCH, MAT) 
      SET SEGMENT TRANSFORMATION(1, MAT)
      GOTO 100

The size, at which a segment is displayed, is controlled by the scaling factors. To decrease the size uniformly by a factor of 2, relative to the start point (0,8.8), the transformation matrix is constructed as follows:

      FX=0 
      FY=8.8 
      TX=0 
      TY=0 
      R=0 
      SX=0.5 
      SY=O.5 
      SWITCH = WC 
      EVALUATE TRANSFORMATION MATRIX(FX, FY, TX, TY, R, SX, SY, SWITCH, MAT) 
      SET SEGMENT TRANSFORMATION(1, MAT)

The effect on the duck is shown in Figure 4-7. An anticlockwise rotation of the segment by 30 degrees (π/6 radians), about the fixed point (0,8.8) would be expressed by:

Figure 4-7
      FX=0 
      FY=8.8 
      TX=0 
      TY=0 
      R=PI/6 
      SX=1 
      SY=1 
      SWITCH=WC 
      EVALUATE TRANSFORMATION MATRIX(FX, FY, TX, TY, R, SX, SY, SWITCH, MAT) 
      SET SEGMENT TRANSFORMATION(1, MAT)

and the effect produced is shown in Figure 4-8.

It is important to remember that the order in which transformations are computed by EVALUATE TRANSFORMATION MATRIX is scale, rotate, shift. It is important because if rotation is applied before scaling different effects may be produced, for example in the case where scaling is not uniform (i.e. X scale factor differs from Y scale factor).

The function ACCUMULATE TRANSFORMATION MATRIX allows more general transformation matrices to be composed:

Figure 4-8
ACCUMULATE TRANSFORMATION MATRIX(MATIN, FX, FY, 
    TX, TY, R, SX, SY, SWITCH, MATOUT)

The parameters FX, FY, TX, TY, R, SX, SY and SWITCH have the same meanings as in EVALUATE TRANSFORMATION MATRIX. The transformation specified by these parameters is concatenated with the transformation specified by the matrix, MATIN, and the resulting transformation matrix is returned in MATOUT. The order in which the transformations are applied is input matrix, scale, rotate and shift. One likely use of this function is to change the order in which scale, rotate and shift are applied, by specifying each elementary transformation separately and using a call to EVALUATE TRANSFORMATION MATRIX followed by two calls to ACCUMULATE TRANSFORMATION MATRIX to build up the required matrix.

4.3.2 Segment Transformation and Clipping

To explain the effects of clipping on transformed segments, something has to be said about when segment transformation takes place. The segment transformation is actually applied after the normalization transformation (which, it will be recalled, maps world coordinates into normalized device coordinates) but before any clipping. Coordinates stored in segments are in fact normalized device coordinates. It will be recalled that the elements of the transformation matrix which define the shift to be applied are expressed in normalized device coordinates.

A primitive in a segment is transformed by the normalization and segment transformations and then, if the clipping indicator was set to CLIP when the primitive was put into the segment, is clipped against the viewport (of the normalization transformation) that was active at that time. In each segment is stored, in effect, a clipping rectangle for each primitive it contains. However, the clipping rectangles are not transformed by the segment transformation. An example will make this clear. Consider the program:

      SET WINDOW(1, 0, 30, 0, 30) 
      SET VIEWPORT(1, 0, 0.5, 0, 0.5)
      SELECT NORMALIZATION TRANSFORMATION(1) 
      SET CLIPPING INDICATOR(NOCLIP) 
      CREATE SEGMENT(1) 
      DUCK 
      CLOSE SEGMENT
      EVALUATE TRANSFORMATION MATRIX(0, 0, 0.25, 0.25, 0, 1, 1, NDC, MAT) 
      SET SEGMENT TRANSFORMATION(1, MAT)

If the clipping indicator is NOCLIP when a primitive is put into a segment, the clipping rectangle [0,1] × [0,1] in normalized device coordinates is stored with the primitive. Thus, in this example, the clipping rectangle [0,1] × [0,1] is stored with the polyline primitives describing the duck. The effect of this program is to generate a picture in the lower left hand quadrant of NDC space as shown in the left hand picture in Figure 4-9, This is then shifted by (0.25, 0.25) in NDC space, as shown in the right hand picture. (Note the use of the coordinate switch NDC in EVALUATE TRANSFORMATION MATRIX.) Now if the clipping indicator is set to CLIP before CREATE SEGMENT is invoked, the clipping rectangle stored with the polyline primitives is the viewport of normalization transformation 1 ([0,0.5] × [0,0.5]). The polyline primitives will be clipped against this rectangle as shown in Figure 4-10.

Figure 4-9

Figure 4-10

Note that the clipping rectangle was not transformed by the segment transformation.

Now we will consider a more complicated example in which more than one normalization transformation is used in the definition of a segment:

      SET WINDOW(1, 0, 30, 0, 30) 
      SET VIEWPORT(1, 0, 0.5, 0, 0.5)
      SET WINDOW(2, 0, 70, 0, 70) 
      SET VIEWPORT(2, 0, 0.5, 0.5, 1)
      SET CLIPPING INDICATOR(NOCLIP) 
      CREATE SEGMENT(1) 
      SELECT NORMALIZATION TRANSFORMATION(1) 
      DUCK 
      SELECT NORMALIZATION TRANSFORMATION(2) 
      TREE 
      CLOSE SEGMENT
      EVALUATE TRANSFORMATION MATRIX(0, 0, 0.25, 0, 0, 1, 1, NDC, MAT) 
      SET SEGMENT TRANSFORMATION(1, MAT)

The picture produced is shown in Figure 4-11, Now if the clipping indicator is set to CLIP before CREATE SEGMENT is invoked, the polyline defining the duck will be clipped against the NDC space rectangle [0,0,5] × [0,0,5] and the tree will be clipped against the rectangle [0,0,5] × [0,5,1], as shown in Figure 4-12,

Figure 4-11

Figure 4-12

4.3.3 Segment Visibility

The segment visibility attribute determines whether a segment will be displayed or not. By default when a segment is created it is visible; thus:

      CREATE SEGMENT(1) 
      DUCK 
      CLOSE SEGMENT

will result in the duck picture being displayed. Normally the operator will see the picture being built up on the display as each line is drawn. The visibility attribute may be changed by the function:

SET VISIBILITY(ID, VIS)

where VIS specifies the visibility of segment ID. VIS may take the values VISIBLE and INVISIBLE. Hence, if the program is modified by the insertion of:

      SET VISIBIUTY(1, INVISIBLE)

after the call to CREATE SEGMENT, the duck will not be displayed on the screen. A subsequent invocation of:

      SET VISIBIUTY(1, VISIBLE)

will cause the duck to be made visible.

The visibility attribute is particularly useful for controlling the display of messages and menus (though there are other ways to deal with menus in GKS). Typically each message will be put into a separate segment, initially invisible. As a message is required, the segment containing it is made visible.

4.3.4 Segment Highlighting

Most vector refresh display hardware has the capability of highlighting a segment, for example by causing it to blink. The principal use of this facility is in drawing the operator's attention to some facet of the display. For example, in the animation program described in this chapter, when the operator has selected a new position at which the duck is to be displayed, we might highlight the duck segment in this new position and ask the operator to confirm that this is the position he really intends.

The highlighting attribute is set by the function:

SET HIGHLIGHTING(ID, HIGH)

where HIGH specifies the highlighting for segment ID. HIGH may take the values HIGHLIGHTED and NORMAL. When a segment is created, the highlighting attribute is NORMAL. It is set to HIGHLIGHTED by:

      SET HIGHLIGHTING(SEGNAME, HIGHLIGHTED)

For a segment to appear highlighted, not only must the highlighting attribute have the value HIGHLIGHTED, but also the visibility attribute must have the value VISIBLE. If a segment needs to be highlighted as it is being created, the CREATE SEGMENT function should be followed by the SET HIGHLIGHTING function. The precise manner in which highlighting is implemented will depend on the particular display hardware that is being used. For some hardware, there will be no visible distinction between HIGHLIGHTED and NORMAL segments.

4.3.5 Segment Priority

Suppose that the scene at the start of this chapter is to be displayed on a raster scan display; then it might be done as follows. Firstly cover the entire display surface with a blue background. This could be done using a fill area primitive with a rectangular area whose boundary corresponds with that of the display surface. We now have a blue sky over the entire display! Now paint-in the rolling green pastures. This could be done using a fill area primitive. Painting-in means changing the current colour value of every picture element (or pixel), in the portion of the frame buffer over which the filled area lies, to the colour associated with the fill area primitive. Similarly the tree, pond and duck can be added to produce the scene shown in Figure 4-1.

Now it is clear that the appearance of the final picture depends on the order in which the fill area primitives are written into the frame buffer; for example, if the duck is created before the pond, then since the area defining the duck lies wholly within the pond, the pixels corresponding to the duck will. be overwritten with the colour of the pond and the duck will disappear.

Suppose now we add the sun and wish, over a series of frames to observe a sunset! We could define the sun as a segment, and let the operator define successive positions of the sun. This works very well until the sun meets the green landscape, because the sun will then overwrite pixels corresponding to the landscape and will not be observed to set. If the landscape had a higher priority than the sun, in the sense that pixels corresponding to the landscape were not overwritten by the setting sun, the desired effect would be achieved.

GKS provides a mechanism for doing this, segment priority, which can be set by the function:

      SET SEGMENT PRIORITY(ID, PRIORITY)

where PRIORITY is a value in the range 0 to 1, which specifies the priority of segment ID.

In this example, the sun would be put in a segment with priority higher than the sky, but lower than that of the tree, landscape, pond and duck; the pond and tree need priority higher than the landscape and the duck needs priority higher than the tree and pond. Suitable priorities would be:

Segment Priority
sky 0.0
sun 0.25
landscape 0.5
pond 0.75
tree 0.75
duck 1.0

Segment priority controls the order in which segments are redrawn when the picture is changed.

There are a number of points which need to be stressed about segment priority, because it is not as universally useful as it might at first sight seem. The first point is that segment priority only works for devices which have the appropriate hardware capability. It cannot be used to force software checking of interference between segments for displays which do not have the appropriate hardware capability. In practice this is likely to mean that segment priority will only be available for colour raster scan displays. Secondly, the description of the SET SEGMENT PRIORITY routine given above conveys the impression that it is possible to distinguish between an infinite number of segment priorities. In practice the particular display being used is likely to have a finite range of priorities available, in which case the priority value specified is mapped onto this range. This means that segments specified to GKS as having different priorities can end up having the same priority because the hardware cannot distinguish sufficient levels.

A final point to note is that if two segments of the same priority overlap, or if primitives within a given segment overlap, then the effects will be defined, but may vary from one implementation of GKS to another.

4.4 RENAMING SEGMENTS

Segments can also be renamed, by invoking the function:

RENAME SEGMENT(OLD, NEW)

where OLD and NEW are the old and new segment names respectively. Thus, if segment 1 contains the duck outline and we invoke:

      RENAME SEGMENT(1, 2)

the duck outline will now be segment 2 and the segment name 1 can be reused for some other purpose. There are two points to note about this function. Firstly, there must be no segment called NEW in existence when the function is called. If there is, an error message will be generated. Secondly, it is perfectly permissible to do the following:

      CREATE SEGMENT(1)
      output primitives
      RENAME SEGMENT(1, 2)
      output primitives 
      CLOSE SEGMENT

that is, rename the open segment.

A typical usage of RENAME SEGMENT is the following. In the animation program at the start of this chapter, the operator wishes to determine a new position for the duck. Sometimes the placement is facilitated if the duck in the initial position is still displayed whilst the new position is selected. However, the application program wishes to use a particular segment name for the duck, say 1. The duck would be created in segment I and a second duck in some other segment, say 2. When the new position has been determined by positioning segment 2, segment 1 is deleted and segment 2 is renamed segment 1. In some applications, a common technique is to use a set of segment names cyclically to hold a segment in intermediate positions, renaming the latest segment when the position is correct and deleting the others.

⇑ Top of page
© Chilton Computing and UKRI Science and Technology Facilities Council webmaster@chilton-computing.org.uk
Our thanks to UKRI Science and Technology Facilities Council for hosting this site