Contact us Heritage collections Image license terms
HOME ACL ACD ICF SUS DCS G&A STARLINK Literature
Further reading □ OverviewContentsPrefaceNotation1. Introduction2. Structures3. Output primitives4. Attributes5. Networks6. 2D viewing7. 3D PHIGS8. Examples9. Input Classes10. Interaction11. Workstations12. Environment13. Further output14. Archives15. BindingsIndex
C&A INF CCD CISD Archives Contact us Heritage archives Image license terms

Search

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

OverviewContentsPrefaceNotation1. Introduction2. Structures3. Output primitives4. Attributes5. Networks6. 2D viewing7. 3D PHIGS8. Examples9. Input Classes10. Interaction11. Workstations12. Environment13. Further output14. Archives15. BindingsIndex

Chapter 2: Structures

2.1 INTRODUCTION

In a low-level graphics system, such as GKS, the production of graphical output consists of a single process. The application requests a polyline to be drawn and the graphical output is generated and appears on the relevant workstation displays as soon as it is required. The advantage of this approach is that not much internal storage is required and the model of the system is easy for the user to comprehend - he asks for a line to be drawn and it appears. The disadvantage of this approach comes when the output generated needs to be modified dependent, say, on some operator input. In this case, each time the graphical output is to be updated, it has to be drawn again. For complex pictures, this can be quite time consuming.

PHIGS is a higher-level graphics system than GKS. Its main purpose is to define computer graphics output that can be easily changed in response to application or operator actions. In order to do this, it must store the information to be displayed internally so that it can be updated efficiently. As it is likely that sets of lines or primitives will be manipulated rather than individual primitives, PHIGS defines a structure as the entity to be used for storing graphical output. Structures are stored in a Central Structure Store (CSS). The PHIGS standard itself calls the store the Centralized Structure Store but the slightly shorter name will be used throughout this book. There is a close analogy between the CSS of PHIGS and an office filing system. Documents that are created are very similar to the structures in PHIGS. The CSS is very similar to the filing system where the documents are kept. Just as it is possible for documents to have common parts, so several structures can have a common sub-structure.

2.2 STORAGE AND TRAVERSAL

The main concepts of PHIGS are shown in Figure 2.1. To create graphical output, the application needs to define structures that are stored in the CSS. The breakdown of the graphical output into structures would normally be in terms of the requirements of the application. For a circuit design application, structures might be defined for the basic components such as resistors and capacitors. Higher application building blocks, such as an oscillator, could be defined as a structure which referenced the individual component structures. Finally, complete circuits would be defined in terms of the higher level building blocks. The adjective hierarchical which is the H in the PHIGS name comes from its ability to define higher level graphics in terms of lower level components. PHIGS structures consist of a sequence of structure elements. Different types of structure elements exist, for example to specify attribute values or create an output primitive.

Application December Central Structure Store Archive Traverser Workstations

Figure 2.1: PHIGS Traverser and Central Structure Store

There is no point in defining structures containing graphical output unless it is possible for these to be displayed on a workstation. This is similar to writing letters or creating documents, putting them in envelopes and leaving them on a desk. This does not provide any communication to your correspondent. When the writer is satisfied with the information to be delivered, it is necessary to post the letter. Similarly, in PHIGS, when a structure that has been created is to be displayed, it must be posted to the relevant workstation. The assumption in PHIGS is that it may be possible for the post operation to be extremely fast so that posting can cause the graphical output to appear immediately.

Unlike the posting of a document, the post operation in PHIGS does not actually send the structure. Conceptually, the post operation in PHIGS opens a hatch on the central structure store so that the workstation can see the posted structure. It is as though the postman does not take the letter and deliver it but instead delivers a telescope so that the letter in the files tore can be viewed.

PHIGS describes the display of a structure on a workstation as traversal. Posting a structure to a workstation effectively starts the traversal process. Each element in the structure is examined and, if appropriate, the traverser will create some graphical output to be displayed on the workstation equivalent to that structure element. Operations on structures and structure traversal are the most important concepts in PHIGS and, for that reason, they are being described first. However, it is difficult to describe these in graphical terms without knowing something about the graphical output that is allowed. Consequently, at this stage, there will be a short interlude while some minimal features of one output primitive are described. A full description of the main types of graphical output in PHIGS will be postponed until Chapter 3.

2.3 GRAPHICAL OUTPUT

Two types of structure elements are defined in PHIGS for specifying graphical output and the attributes to be associated with the output. For example, an invocation of:

POLYLINE(N, XA, Y A)

will create a structure element which, on traversal, will produce graphical output consisting of a sequence of straight lines from (XA(1), YA(1)) to (XA(2), YA(2)) to ... (XA(N), YA(N)). The appearance of the polyline on the display is controlled by attributes. These attributes are also defined by structure elements. Two examples are:

SET LINETYPE(DASHED) 
SET LINEWIDTH SCALE FACTOR(THICK)

The polyline has other attributes but the two given above are sufficient for the description of structure operations. The function SET LINETYPE defines the type of line to be displayed for future output. Possibilities are DASHED, DOTTED and SOLID with the last being the default value. The actual parameter is an integer but the mnemonics will be used in this Chapter to make examples easier to read. Similarly, the function SET LINEWIDTH SCALE FACTOR (sometimes written as SET LSF) defines the thickness of line to be displayed for future output. The possible parameter values are NORMAL, THICK and THIN. Actually, there is a whole range of possible values which define the thickness of a line relative to the NORMAL thickness (1.0). A full description of the polyline primitive will be postponed to Section 3.2. It is the main line drawing primitive of PHIGS. Single lines are drawn by specifying a polyline with just two points.

So far, no mention has been made of the coordinates to be used in the definition of graphical output. Suffice it to say, for now, that the application has complete freedom to choose a relevant coordinate system applicable to the problem. In this Chapter, the graphical output will be defined to be 2-dimensional and within the unit square from 0 to 1 in both the X and Y -directions. This happens to be the default settings in place when PHIGS is entered. Consequently, these examples should execute without change on most PHIGS implementations.

2.4 STRUCTURE DEFINITION

A structure definition is started by the function:

OPEN STRUCTURE(ID)

where ID is the name of the structure. In PHIGS, the names of structures are positive integers. Invoking functions that create structure elements will result in these structure elements being added to the structure that has been opened. The structure definition is completed by invoking the function:

CLOSE STRUCTURE

For example:

      OPEN STRUCTURE(3) 
      POLYLINE(N, X1, Y1) 
      SET LINETYPE(DASHED) 
      SET LINEWIDTH SCALE FACTOR(THICK) 
      POLYLINE(M, X2, Y2) 
      CLOSE STRUCTURE

will define a structure named 3 with 4 structure elements. When the structure is posted to a workstation, the display will consist of two polylines. The first will have the current default appearance while the second will be dashed and thick.

The form of the central structure store while this structure is being defined is shown in Figure 2.2. The central structure store consists of the set of structures already defined. When a structure is opened initially, the structure state list will have the name of the open structure set to point to the structure being defined. The element pointer in the structure state list will be set to 0. The edit mode will initially be set to INSERT. Invoking the function POLYLINE(N, X1, Y1) will result in the structure state list being examined to find out which structure is open and what elements have already been defined. The element pointer is incremented by 1 and the new structure element stored at that position. While inserting a set of elements into a structure, the element pointer always points to the last structure element inserted. More complex operations on structures will be discussed later. The CLOSE STRUCTURE function resets the structure state list to have null values in the name of the open structure and the element pointer.

STRUCTURE STATE LIST Open Structure Element Pointer Edit Mode INSERT Structure Identifier 0 1 2 3 4 5 6 Structure Identifier Structure Identifier

Figure 2.2: Central Structure Store

2.5 POSTING A STRUCTURE

A structure is posted to a workstation by invoking the function:

POST STRUCTURE(WS, SI, PR)

where WS defines the workstation and SI the name of the structure to be posted. The third parameter defines the priority of the posting which will be described later (see Section Section 2.10). The form of the traverser is conceptually shown in Figure 2.3. The traverser will have a set of structures that have already been posted. These are defined in a post list. To this will be added the new posting defined above. It is the function of the traverser to ensure that each workstation has the correct display corresponding to the structures that have been posted to it. Conceptually, the traverser can be thought of as going through the post list one entry at a time interpreting the entries. Once all have been interpreted, it starts again repeating the operation. This is necessary as will be seen later because the structures that have been posted can be changed.

Workstation Identifier Structure Identifier Display Priority 1 2 3 4 5 WS SI PR PHIGS DESCRIPTION TABLE Defaults TRAVERSAL STATE LIST linetype lsf global m. t. local m. t. INTERPRETER CSS Output Primitives to Workstation WS Structure Elements extracted in sequence from Structure SI

Figure 2.3: PHIGS Traverser

Posting the structure defined in Section 2.4 named 3 would cause the traverser to add the structure 3 to its post list. Before each structure is traversed, the traverser initializes the traversal state list from the PHIGS Description Table. This contains all the default values associated with posted structures. The traversal state list has very many values in it. Figure 2.3 just shows the entries for the two polyline attributes and two modelling transformations (to be described later). The default values of the polyline attributes are SOLID and NORMAL. Therefore, the first structure element in the structure 3 will be interpreted as a solid normal polyline. The second entry in the structure is the SET LINETYPE entry. Interpreting an attribute setting element will update the relevant entry in the traversal state list to the value specified (in this case DASHED). Similarly, the interpretation of the third structure element will result in the LINEWIDTH SCALE FACTOR entry in the traversal state list being set to THICK. As a result of these two elements being interpreted and changing the traversal state list, the interpretation of the fourth element will result in a dashed thick polyline being displayed on the workstation.

It should be made clear that this is conceptually how the traverser works. The application cannot enquire the state of the traversal state list nor can it force the traverser to update the displays in a sequential order. As long as the traverser does the job correctly, it can use any technique it likes. Consequently, the traverser could be built in hardware possibly with multiple processors doing the interpretation. It is defined as a black box in PHIGS so that implementations can choose a traversal strategy that best fits the hardware available.

To stop traversal of a structure, the application invokes:

UNPOST STRUCTURE(WS, SI)

This will cause the specified entry in the post list to be deleted and the structure SI will no longer be visible on workstation WS. Using the postman analogy used earlier, the POST function is equivalent to the delivery of a telescope to view the relevant part of the central structure store and the UNPOST function is the removal of the telescope. Neither function changes the central structure store itself. To batch updates to a display, it is sometimes useful to UNPOST, update and POST the structure again.

2.6 REOPENING STRUCTURES

So far, the separation of structure definition and display has not shown up any real advantages over, say, the segment facility in GKS. However, the structure facility in PHIGS is a much richer one. The first difference is that, unlike GKS, the structure is not an entity that is defined once and cannot be changed. Instead, it is a highly dynamic entity that can be under continual change. The simplest way of changing a structure is to reopen it. If the function:

      OPEN STRUCTURE(3)

was invoked a second time, instead of setting the structure state list to have 3 as the open structure and element pointer set to 0, the element pointer is set to point to the last element in the structure. Invoking the POLYLINE function again would cause this structure element to be added to the end of the open structure. Thus:

      OPEN STRUCTURE(3) 
      POLYLINE(N, X1, Y1) 
      CLOSE STRUCTURE 
      OPEN STRUCTURE(3) 
      SET LINETYPE(DASHED) 
      SET LINEWIDTH SCALE FACTOR(THICK) 
      POLYLINE(M, X2, Y2) 
      CLOSE STRUCTURE

will result in the same structure as before.

Posting a non-existent structure will cause an empty structure to be defined. Consequently:

      POST STRUCTURE(WS, 3, PR) 
      OPEN STRUCTURE(3) 
      POLYLINE(N, X1, Y1) 
      SET LINETYPE(DASHED) 
      SET LINEWIDTH SCALE FACTOR(THICK) 
      POLYLINE(M, X2, Y2) 
      CLOSE STRUCTURE

will have the same final effect as defining the complete structure 3 before posting it. However, the intermediate effect may be different. By posting the structure first, the workstation will start displaying the empty structure. After the first POLYLINE element has been added to the structure, the traverser will attempt to display it on the workstation. Consequently, in this case, intermediate displays may appear depending on the speed and strategy adopted by the traverser. If the traverser is quite slow, there may be advantages in defining the structure before posting it.

2.7 AN EXAMPLE

In this book, a single running example will be used to describe a number of the PHIGS features. PHIGS is both a 2D and a 3D system. To keep the early examples simple, 2D examples are used most of the time. Only when viewing is described is it necessary to use 3D in the examples. The first example consists of displaying an office desk (see Figure 2.4). The desk consists of three parts whose positions are constrained relative to each other. Initially, the parts of the desk can be defined in the coordinates of the unit square. To get the right aspect ratio for the book page, the X-coordinates lie between 0 and 1 while the Y-coordinates lie between 0.333 and 1. Three subroutines DLARGE, DCORNR and DSMALL define the structure element for each desk. The complete structure is defined as DESK. The complete program to display the structure DESK follows.

Figure 2.4: Office desk example
      SUBROUTINE DLARGE 
      REAL XL(5),YL(5) 
      DATA XL /0.2,0.2,0.6,0.6,0.2/ 
      DATA YL /0.6,0.8,0.8,0.6,0.6/ 
      POLYLINE(5, XL, YL) 
      RETURN 
      END
      SUBROUTINE DCORNR 
      REAL PI, XC(12),YC(12) 
      INTEGER I 
      XC(1)=0.6 
      YC(1)=0.6 
      XC(2)=0.6 
      YC(2)=0.8 
      PI=4.0*ATAN(1.0) 
      DO 50 I=3,10 
      XC(I)=0.6+0.2*COS((11-I)*PI/18.0) 
      YC(I)=0.6+0.2*SIN((11-I)*PI/18.0) 
 50   CONTINUE 
      XC(11)=0.8 
      YC(11)=0.6
      XC(12)=0.6 
      YC(12)=0.6 
      POLYLINE(12,XC,YC) 
      RETURN 
      END
      SUBROUTINE DSMALL 
      REAL XS(5),YS(5) 
      DATA XS /0.6,0.8,0.8,0.6,0.6/ 
      DATA YS /0.6,0.6,0.4,0.4,0.6/ 
      POLYLINE(5, XS, YS) 
      RETURN
      END
      OPEN STRUCTURE(DESK) 
      DLARGE 
      DCORNR 
      DSMALL 
      CLOSE STRUCTURE
      POST STRUCTURE(WS, DESK, PR)

The identifier DESK must have a unique value different from other structure identifier names. Either the application has to keep a record of the integer values representing the names already used or a utility has to be defined which converts the identifier DESK into a unique integer.

As was described above, polyline attribute settings remain in force and apply to all subsequent polylines until reset. Consequently, to have the parts of the desk drawn in different linestyles, it is necessary to insert attribute setting functions that establish the required linestyles:

      OPEN STRUCTURE(DESK) 
      SET LINETYPE(DASHED) 
      DLARGE 
      SET LINETYPE(SOLID) 
      DCORNR 
      SET LINETYPE(DOTTED) 
      DSMALL 
      CLOSE STRUCTURE 
      POST STRUCTURE(WS, DESK, PR)

This will produce the display in Figure 2.5. Both the attributes linestyle and linewidth could have been defined in the structure. On traversal, the polyline structure element would use the current values of the attributes in the traversal state list when the output primitive was created.

Figure 2.5: Different line types

2.8 LOCAL MODELLING TRANSFORMATIONS

The coordinates used to define the desk by the application are called modelling coordinates in PHIGS. As stated earlier, the application can use a coordinate system appropriate to the application. In the example above, the desk could have been defined in metres.

PHIGS defines structure elements that provide a coordinate transformation to be applied to all subsequent output in a structure. Similar to the handling of polyline attributes, the default local modelling transformation is loaded from the PHIGS description table at the start of a traversal. Its value is the identity matrix. Resetting the local modelling transformation is achieved by:

SET LOCAL TRANSFORMATION(MT, TYPE)

where MT is a 3 × 3 homogeneous matrix and TYPE is one of PRE, POST or REPLACE. Homogeneous coordinates are ones where a 2D point is represented by a point in a 3D space. The point (X, Y) is represented by (XW, YW, W) where X=XW/W and Y=YW/W. In homogeneous coordinates, transformations such as scale, rotate and shift can all be represented as matrix multiplications. The current local modelling transformation (CLMT) is stored in the traversal state list. It is applied to all output primitives as they are traversed. As no changes have been made to CLMT in the examples so far, the identity transformation has been applied which has no effect. Invoking SET LOCAL TRANSFORMATION updates CLMT as follows:

      REPLACE     CLMT' = MT 
      PRE         CLMT' = CLMT × MT 
      POST        CLMT' = MT × CLMT

Each coordinate (XM, YM) in structure elements traversed is transformed to (XW, YW) as follows:

           XW           XM
           YW  =  CLMT  YM
           W            1

where X=XW/W and Y=YW/W. To aid in the definition of homogeneous matrices, a utility function is provided:

BUILD TRANSFORMATION MATRIX (XF, YF, DX, DY, PHI, SX, SY, ER, MT)

This function builds the matrix MT. The parameter ER is set to 0 if a matrix has been built successfully or to a non-zero error value otherwise. The transformation built can be a mixture of scaling, rotation and shifting. The parameters (XF,YF) define a fixed point which is the origin for scaling and rotation. (DX,DY) define the translation to be applied. PHI defines the anti-clockwise rotation around the fixed point. (SX,SY) scale the coordinates about the fixed point (XF,YF). If all parameters are defined with non-identity transformations, the operations are performed in the order scale, rotate, and shift.

The meaning of PRE multiplication is that the new operation is performed before the existing CLMT while POST multiplication is that it is performed after CLMT. The effect of PRE and POST is, in general, different. The exception is if CLMT and MT are similar operations and have the same fixed point, if appropriate. For example, the desk can be exploded (see Figure 2.6) by:

      OPEN STRUCTURE(DESK) 
      DLARGE 
      BUILD TRANSFORMATION MATRIX(0, 0, 0.03, 0, 0, 1, 1, ER, MT) 
      SET LOCAL TRANSFORMATION(MT, REPLACE) 
      DCORNR 
      BUILD TRANSFORMATION MATRIX(0, 0, 0, -0.03, 0, 1, 1, ER, MT) 
      SET LOCAL TRANSFORMATION(MT, PRE) 
      DSMALL 
      CLOSE STRUCTURE 
      POST STRUCTURE(WS, DESK, PR) 

Figure 2.6: Local modelling transformations

The REPLACE function could have been PRE or POST equally well as the replaced matrix is the identity matrix. As the concatenated matrices are both shifts, the final transformation could have been POST as well as PRE to give the same effect.

Mixing rotation and scaling will give different effects even about the same fixed point. For example:

      OPEN STRUCTURE(DESK) 
      DLARGE
      BUILD TRANSFORMATION MATRIX(0.2, 0.6, 0, 0, PI/8, 1, 1, ER, MT) 
      SET LOCAL TRANSFORMATION(MT, XXX) 
      SET LINETYPE(DOTTED)
      DLARGE
      BUILD TRANSFORMATION MATRIX(0.2, 0.6, 0, 0, 0, 1.25, 1, ER, MT) 
      SET LOCAL TRANSFORMATION(MT, XXX) 
      SET LINETYPE(DASHED) 
      DLARGE
      CLOSE STRUCTURE
      POST STRUCTURE(WS, DESK, PR) 

Figure 2.7 shows the effect when XXX is PRE and Figure 2.8 when XXX is POST. The dashed desk is significantly different.

Press

Figure 2.7: Example of pre-multiplication

Press

Figure 2.8: Example of post-multiplication

For PRE multiplication, the dashed rectangle is expanded about the bottom left hand corner and then rotated. For POST multiplication, the rotation of the rectangle takes place followed by the expansion about the bottom left corner. This produces the parallelogram shown in Figure 2.8. The points to the left of the origin are expanded leftwards while the points to the right of the origin are expanded rightwards.

2.9 STRUCTURE EDITING

PHIGS is designed for use in an interactive environment where the graphical output is likely to be modified as a result of operator action or that of the application. For example, the operator might want to orientate the desk differently or change the positions of the parts making up the desk. Rather than this being achieved by a complete redrawing of the graphical output, PHIGS allows structures to be edited. One example of editing has been described already, the appending of new elements to the end of a structure. PHIGS provides a range of editing facilities which can be classified as absolute, relative and via labels. The third is the easiest to use but the least efficient.

2.9.1 Edit mode

As has been described earlier, structure elements have a position associated with them where 0 is the position before the first element of a structure. For example, the structure:

      OPEN STRUCTURE(DESK) 
      POLYLINE(5, XL, YL) 
      POLYLINE(12, XC, YC) 
      POLYLINE(5, XS, YS) 
      CLOSE STRUCTURE

can be represented as:

0 DESK
1 POLYLINE(5, XL, YL)
2 POLYLINE (12, XC, YC)
3 POLYLINE (5, XS, YS)

where the element pointer 0 value is pointing before the first element in the structure. When a structure is opened, the element pointer is set to point at the last element in the structure. When a structure is opened for the first time, no elements exist so the pointer is set to O. PHIGS has a global switch for the central structure store which is either in INSERT or REPLACE mode. Initially it is set to INSERT mode. In this mode, when a structure element is defined by invoking a function such as POLYLINE, the element pointer is incremented for the open structure and the new structure element is entered there. Consequently, after each insertion, the element pointer the element pointer becomes undefined until another structure is opened. However, the edit mode remains set to its current value. As the invoking of a function, such as POLYLINE, has very different effects depending on whether the edit mode is INSERT or REPLACE, it is good practice to leave the mode set one way or the other so that the program is more readable. In the examples in this book, we will tend to leave the EDIT MODE set to INSERT. Consequently, if not set explicitly, the assumption made is that the EDIT MODE is INSERT.

In REPLACE mode, a new element is inserted at the element pointer position and the element pointer is not changed. In the special case where the element pointer is set to 0, the new element is inserted at the beginning of the structure. If several elements are defined in INSERT mode one after the other, the effect is as expected and the elements get added to the structure one after the other. If several elements are defined in REPLACE mode one after the other, the effect is that each element overwrites the previous one. This is not always very meaningful. Consequently, in REPLACE mode, it is more normal for the element pointer to be updated between each element replaced.

The PHIGS function for setting the edit mode is:

SET EDIT MODE(XXX)

where XXX can either be INSERT or REPLACE.

The PHIGS function for changing the position of the element pointer is:

SET ELEMENT POINTER(N)

where N is the new position of the element pointer. If N is negative, the element pointer is set to 0. If N is larger than the length of the structure, it is set to point at the last element in the structure. This method of avoiding errors applies to a number of the functions in PHIGS.

2.9.2 Absolute editing

By setting the element pointer to a position other than the end of the structure, it is possible to insert new elements into the structure or replace existing ones. Given the structure DESK defined in Section 2.9.1, with edit mode set to INSERT, the following functions:

      OPEN STRUCTURE(DESK) 
      SET ELEMENT POINTER(0) 
      SET LINETYPE(DASHED)

would change the structure to:

0 DESK
1 SET LINETYPE (DASHED)
2 POLYLINE(5, XL, YL)
3 POLYLINE (12, XC, YC)
4 POLYLINE (5, XS, YS)

The first thing to notice is that all the element pointer positions for the elements already in the structure have been incremented by 1. The element inserted is numbered 1 and the other element positions are all greater by 1. If the following functions are invoked:

      SET ELEMENT POINTER(2) 
      SET LINETYPE(SOLID)

the structure changes to:

0 DESK
1 SET LINETYPE (DASHED)
2 POLYLINE(5, XL, YL)
3 SET LINETYPE (SOLID)
4 POLYLINE (12, XC, YC)
5 POLYLINE (5, XS, YS)

Note, the user has to keep an update of the element positions in mind each time an edit is done otherwise subsequent edits will be done at the wrong place. The situation can be further complicated by not doing the edits in ascending order. The application can set the element position backwards and forwards if desired. (Actually, doing the edits in reverse order would keep the initial line numbers correct for all the edits!) To change the last polyline to be dotted would require a further edit:

      SET ELEMENT POINTER(4) 
      SET LINETYPE(DOTTED) 
      CLOSE STRUCTURE

The complete structure generated would be as shown below.

0 DESK
1 SET LINETYPE (DASHED)
2 POLYLINE(5, XL, YL)
3 SET LINETYPE (SOLID)
4 POLYLINE (12, XC, YC)
5 SET LINETYPE (DOTTED)
6 POLYLINE (5, XS, YS)

Absolute editing in INSERT mode tends to be used only in well defined situations such as adding elements to the start of a structure or the end of a structure.

The effect of the previous example in REPLACE mode would be completely different. The first edit would still add SET LINETYPE(DASH) to the start of the structure. The second edit would replace the second element giving:

0 DESK
1 SET LINETYPE (DASHED)
2 SET LINETYPE (SOLID)
3 POLYLINE (12, XC, YC)
4 POLYLINE (5, XS, YS)

while the third edit would replace the fourth element giving:

0 DESK
1 SET LINETYPE (DASHED)
2 SET LINETYPE (SOLID)
3 POLYLINE (12, XC, YC)
4 SET LINETYPE(DOTTED)

While the invocation of a set of functions that generate structure elements is sensible in INSERT mode as they are added to the structure one after another, it is much less useful in REPLACE mode. If the element pointer is not changed, each new element will overwrite the previous one. Consequently, REPLACE mode is mainly useful in a loop consisting of setting the element pointer position, replacing the element and repeating the pair of functions. Its use in an interactive session will be described later (see Section 9.3). Here, continually updating the same element may be what is required by the application.

2.9.3 Relative editing

If a number of edits are to be made to a structure in INSERT or REPLACE mode, it is often easier if the edits are specified relative to the last one performed. PHIGS provides the function:

OFFSET ELEMENT POINTER(N)

for this purpose. The element pointer is incremented by N where N can have a positive, negative, or zero value. To avoid errors, the same approach is taken as with SET ELEMENT POINTER. If the resulting element pointer is before the start of the structure it is set to 0 and if it is after the end of the structure the element pointer is set to point to the last element in the structure. Starting from the structure DESK with the three polylines:

0 DESK
1 POLYLINE(5, XL, YL)
2 POLYLINE (12, XC, YC)
3 POLYLINE (5, XS, YS)

The following set of edits in INSERT mode will produce the new structure DESK with the attributes of each of the polylines set differently.

      OPEN STRUCTURE(DESK) 
      SET ELEMENT POINTER(0) 
      SET LINETYPE(DASHED) 
      SET LINEWIDTH SCALE FACTOR(THIN) 
      OFFSET ELEMENT POINTER(1) 
      SET LINETYPE(SOLID) 
      SET LINEWIDTH SCALE FACTOR(NORMAL) 
      OFFSET ELEMENT POINTER(1) 
      SET LINETYPE(DOTTED) 
      SET LINEWIDTH SCALE FACTOR(THICK) 
      CLOSE STRUCTURE 
0 DESK
1 SET LINETYPE (DASHED)
2 SET LSF (THIN)
3 POLYLINE (5, XL, YL)
4 SET LINETYPE (SOLID)
5 SET LSF (NORMAL)
6 POLYLINE (12, XC, YC)
7 SET LINETYPE (DOTTED)
8 SET LSF (THICK)
9 POLYLINE (5, XS, YS)

Each time, the element pointer only has to be incremented by 1 to move over the next POLYLINE element position to achieve the desired effect.

In REPLACE mode, a loop consisting of an element generating function followed by OFFSET ELEMENT POINTER(1) would replace a sequence of structure elements by new ones.

2.9.4 Labels

Neither of the above methods of locating positions in a structure is easy to use for complex edits. PHIGS has a user-defined labelling facility for handling these. Invoking the function:

LABEL(ID)

creates a structure element that is added to the structure in the normal way. The label ID can be any integer value. On structure traversal, the interpretation of the element has no effect. Its purpose is to provide a position in the structure that can be located other than by remembering the element pointer position. An important point is that the label ID need not be unique. If the same edit is to be applied to several positions in a structure, it may be useful to label each one by the same name.

To set the element pointer at a label, the function provided is:

SET ELEMENT POINTER AT LABEL(ID)

The structure is searched from the current element pointer position until the label structure element is reached whose name is ID. The element pointer is left pointing at the label structure element. If the search is started from a label structure element with label ID. the search starts from the next element so that the next occurrence of ID is found. PHIGS issues an error message and stops if the label does not exist between the current element pointer position and the end of the structure. For novice PHIGS users, this tends to be a common error. For example:

      OPEN STRUCTURE(XYZ) 
      SET ELEMENT POINTER AT LABEL(ID)

will always cause an error as the element pointer will be set to the last position in the structure when it is opened. To search the whole structure for the first occurrence of ID requires:

      OPEN STRUCTURE(XYZ) 
      SET ELEMENT POINTER(0)
      SET ELEMENT POINTER AT LABEL(ID)

To do a similar edit to the ones described already, requires labels to be added at the points where edits might be made:

      OPEN STRUCTURE(DESK) 
      LABEL(LARGE) 
      POLYLINE(5, XL, YL) 
      LABEL(CORNER) 
      POLYLINE(l2, XC, YC) 
      LABEL(SMALL) 
      POLYLINE(5, XS, YS) 
      CLOSE STRUCTURE

producing a structure:

0 DESK
1 LABEL (LARGE)
2 POLYLINE(5, XL, YL)
3 LABEL (CORNER)
4 POLYLINE (12, XC, YC)
5 LABEL (SMALL)
6 POLYLINE (5, XS, YS)

Label editing is ideally suited to adding structure elements at defined points in a structure. The element pointer is positioned at the label structure element and, consequently, the inserted elements will be added just after the label element. A similar edit to that in Section 2.9.2 is:

      OPEN STRUCTURE(DESK)
      SET ELEMENT POINTER(0) 
      SET ELEMENT POINTER AT LABEL(LARGE) 
      SET LINETYPE(DASHED)
      SET ELEMENT POINTER AT LABEL(CORNER) 
      SET LINETYPE(SOLID)
      SET ELEMENT POINTER AT LABEL(SMALL) 
      SET LINETYPE(DOTTED) 
      CLOSE STRUCTURE

The assumption is that the edit mode is INSERT. This produces the structure:

0 DESK
1 LABEL (LARGE)
2 SET LINETYPE (DASHED)
3 POLYLINE(5, XL, YL)
4 LABEL (CORNER)
5 SET LINETYPE (SOLID)
6 POLYLINE (12, XC, YC)
7 LABEL (SMALL)
8 SET LINETYPE (DOTTED)
9 POLYLINE (5, XS, YS)

2.9.5 Deleting elements

PHIGS provides a number of functions for deleting elements from a structure. The simplest is:

DELETE ELEMENT

which deletes the structure element pointed at by the element pointer. After the deletion, the element pointer is set to the element before the element deleted. This has the odd effect that multiple calls of DELETE ELEMENT will delete elements going backwards in the structure from the initial position.

Attempting to delete the element at position 0 in a structure has no effect. Each time DELETE ELEMENT is invoked, the subsequent elements in the structure will have their positions decremented by 1. To delete a range of elements, PHIGS provides:

DELETE ELEMENT RANGE(EP1, EP2)

All elements between the two positions are deleted including positions EP1 and EP2. The smaller position need not be specified as the first parameter. The effect is the same either way round with the element pointer being left pointing at the element just before the range of deleted elements. If the range specified is larger than from position 0 to the last position in the structure, the deletions are constrained to be within the structure. Given the structure:

0 DESK
1 SET LSF(THICK)
2 SET LINETYPE(DASHED)
3 POLYLINE(5, XL, YL)
4 SET LSF(NORMAL)
5 SET LINETYPE(SOLID)
6 POLYLINE(12, XC, YC)
7 ET LSF(THIN)
8 SET LINETYPE (DOTTED)
9 POLYLINE (5, XS, YS)

the following edits:

      OPEN STRUCTURE(DESK) 
      SET ELEMENT POINTER(5) 
      DELETE ELEMENT 
      DELETE ELEMENT RANGE(6,5) 
      DELETE ELEMENT RANGE(1,3)
      CLOSE STRUCTURE

would produce the following structure. Note how it is quite difficult to work out exactly what the positions of the structure elements are after each edit. As for inserting elements in a structure, performing the deletions in reverse order will preserve the element positions of the earlier entries but this may not always be easy to program.

0 DESK
1 SET LSF(NORMAL)
2 SET LINETYPE (DOTTED)
3 POLYLINE (5, XS, YS)

The first deletion will remove SET LINETYPE(SOLID). This will decrement the subsequent positions by 1 so that the second deletion will remove the original positions 6 and 7 while the third deletion removes elements 1 to 3.

PHIGS also provides deletions dependent on labels:

DELETE ELEMENTS BETWEEN LABELS(LB1, LB2)

The structure is searched from the current element pointer until LB1 is found at, say, position EP1. Starting from the position immediately after EP1, label LB2 is searched for and found at, say, EP2. The elements deleted are the set between the labels, that is EP1+1 to EP2-1. After the deletion, the element pointer is set to EP1. The label elements are not deleted.

For complex applications, editing and deleting using labels is probably the most sensible approach. However, the application could build its own structure editor (possibly with a display of the structure) and in this case it might be more convenient to do absolute editing. The aim is for PHIGS to provide the basic facilities that satisfy the needs of the application possibly with the introduction of tools built on top of PHIGS.

2.10 POSTING PRIORITY

The PHIGS facilities described so far allow the application to define graphical objects as structures and have them displayed by the POST function. While the structures are being displayed, they can be edited and the traverser is responsible for ensuring that the displayed structure is kept up-to-date with the structure in the central structure store. The POST function has 3 parameters:

POST STRUCTURE(WS, SI, PR)

The first parameter defines the workstation and the second the structure to be posted. The third parameter PR is a value in the range 0 to 1 and defines the priority of the structure posted. A set of structures can be posted to a workstation by multiple calls of the POST function. The traverser will generate a display for each one and keep them all up-to-date.

Ambiguity can occur if the posted structures occupy the same part of the display space. For example, if a red graph is to be drawn over a blue background grid, where two lines cross each other would require the red line to appear over the blue grid line. By defining the two posted structures at different priority values, the traverser is expected to achieve the desired effect. For example:

      POST STRUCTURE(WS, GRAPH, 0.6) 
      POST STRUCTURE(WS, GRID, 0.1)

The structure with the highest display priority is visible when several posted structures occupy the same part of the display space.

The same effect can be obtained by posting the structures with the same priority but being careful to order the posting operations. If two posted structures have the same display priority, the last posted takes precedence and, in effect, is given a higher priority. The same effect could be achieved by:

      POST STRUCTURE(WS, GRID, 0.2) 
      POST STRUCTURE(WS, GRAPH, 0.2)

However, this may not always be convenient. Using priority to define which display takes precedence is a much cleaner way of ensuring the display is correct for highly interactive applications making considerable use of the editing, posting and unposting facilities available.

⇑ 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