Jump Over Left Menu
Chapter 5: Networks
Chapter 2 gave a description of the main structure creation and editing functions. Chapter 3 gave full details of the structure elements associated with output primitives and their attributes. PHIGS, the Programmer's Hierarchical Interactive Graphics System is so named because structures need not be independent but can be related to each other in a hierarchy. This is of particular value when complex pictures are being composed from parts which are themselves defined by lower-level units. If the interaction with such pictures needs to have access to the hierarchy description, the facilities described so far are inadequate.
In this Chapter, the remaining types of structure elements will be described (there are 9 different types and only 4 have been described so far). The main element to be described is the one that defines the hierarchy. However, associated with it are the transformation and clipping facilities that provide a much more extensive descriptive ability than has been suggested so far. Clipping will be described in Section 5.8.
5.2 STRUCTURE HIERARCHY
PHIGS provides a structure element:
which allows one structure to be linked to another. If the above structure element occurs in the traversal of structure ST, the traverser will suspend the traversal of structure ST remembering the current contents of the traversal state list. The structure SI is traversed from its beginning using the current contents of the traversal state list. Consequently, any attribute settings or transformations applying to the structure ST will also apply to the structure SI when its traversal starts. Thus the structure SI inherits the environment created by its parent. The organization of how any modelling transformations of ST are inherited by SI will be described in Section 5.3.
On completing the traversal of SI, the saved PHIGS traversal state list is restored and traversal of SI continues at the element immediately after the EXECUTE STRUCTURE(SI) element. Therefore, nothing that has happened in the traversal of structure SI can effect the traversal of structure ST. This has the advantage that the meaning of structure ST can be deduced without needing to examine in detail the structure SI.
The structure SI can, itself, have EXECUTE STRUCTURE elements in its body. When these are traversed, the same process of saving the current state and traversing the sub-structure applies. There is no limit to the depth of structure nesting that can be specified except for any implementation restrictions on the total storage available.
The structure ST may have several appearances of the EXECUTE STRUCTURE(SI) within it so multiple instances of the same structure can be traversed. If this is done with different settings in the traversal state list when the EXECUTE STRUCTURE element is interpreted, the effect of each traversal of structure SI will be different. For example, the positions of the graphical objects described by structure SI or their appearance may be different for each execution of SI.
The structure posted to a workstation is called the root structure. The root structure and all structures linked to it by EXECUTE STRUCTURE elements making up the complete hierarchy is called a structure network.
The only constraint placed on a structure network is that it cannot be recursive. For any structure ST that includes, say, an EXECUTE STRUCTURE(SI) element, traversal of SI or any of the structures traversed as part of the traversal of SI cannot result in an execution of structure ST. This applies to all the structures in the network. Effectively, this means that each structure only has to have storage associated with it that can contain one saved traversal state list. In particular, the structure ST cannot contain structure elements of the form EXECUTE STRUCTURE(ST).
If a structure is defined containing an element EXECUTE STRUCTURE(NEW) and NEW does not exist, a null structure NEW is created with no elements.
5.3 MODELLING TRANSFORMATIONS
In Section 2.8, a local modelling transformation was described. For single structures, not in a network, it was sufficient to describe modelling transformations in terms of the Current Local Modelling Transformation (CLMT) that could be defined and changed during the execution of a structure. It was stated that the traversal state list had the CLMT set to the identity matrix at the start of structure traversal initiated by the POST STRUCTURE function.
None of that description is incorrect but it does not describe what happens when a structure traversal occurs as a result of an EXECUTE STRUCTURE function being executed. Clearly, it would be sensible for any modelling transformations already applied to the parent structure to be inherited by the child structure. PHIGS achieves this by defining both local and global modelling transformations.
Global modelling transformation
The PHIGS traversal state list, as shown in Figure 2.3, has entries for both a global and local modelling transformation. Let these matrices have their current values defined as CGMT (Current Global Modelling Transformation) and CLMT (Current Local Modelling Transformation). When a structure, say STRA, is posted to a workstation, the values of CGMT and CLMT are both set to the identity matrix. The modelling transformation applied to the coordinates of structure elements on traversal is a composition of the two transformations (say COMP) where:
COMP = CGMT Ã— CLMT
Effectively, the local modelling transformation is applied to the coordinates followed by the global modelling transformation. For the posted structure, STRA, unless the Global Modelling Transformation is changed, the only transformation applied to its elements is the Current Local Modelling Transformation.
When an EXECUTE STRUCTURE element is traversed, the values of CGMT and CLMT are stored. Before executing the sub-structure, the CGMT in the traversal state list is set to COMP, the composition of CGMT and CLMT, and the CLMT is set to identity. Thus the complete set of transformations in force is passed to the sub-structure as its Global Modelling Transformation.
Consider the two structures given below:
|1||SET LMT (MT1,REPLACE)|
SET LMT is a shorthand for SET LOCAL TRANSFORMATION in the figure. If the structure, STRA, is posted, on entry the values of CLMT, CGMT and COMP are all identity. The first element in STRA, on traversal, will replace CLMT and COMP by MT1. The second element will replace both CLMT and COMP by MT2 Ã— MT1 (POST implies MT2 is performed after MT1).
On traversal of the third element, EXECUTE STRUCTURE(STRB), the values of CGMT and CLMT will be stored (identity and MT2 Ã— MT1) and the structure STRB will be traversed with CGMT set to MT2 Ã— MT1 and CLMT set to identity. In consequence, the coordinates of the POLYLINE in the first element of STRB will be transformed by COMP which is MT2 Ã— MT1.
The second element of STRB will, on traversal, set CLMT to MT3, but it will not change CGMT which is still MT2 Ã— MT1, and this will result in COMP being MT2 Ã— MT1 Ã— MT3. The third element on traversal will update the value of CLMT by PRE-multiplying the CLMT. In consequence, CLMT will have value MT3 Ã— MT4 (MT4 applied before MT3). CGMT remains as MT2 Ã— MT1 so that the value of COMP, the composite modelling transformation, becomes MT2 Ã— MT1 Ã— MT3 Ã— MT4 and this is the transformation applied to the POLYLINE element in the fourth position of structure STRB.
On the completion of STRB traversal, the saved values are restored so CGMT will revert to identity and CLMT to MT2 Ã— MT1. The value of COMP is, therefore, MT2 Ã— MT1 and this is applied to the coordinates of the fourth structure element in STRA. As was stated before, this can be deduced just by examining STRA.
5.3.3 Picture composition
The EXECUTE STRUCTURE element provides a powerful facility for composing graphical objects out of parts which may themselves be made from sub-parts. As local transformations can be applied at each level, it is quite feasible for each structure to have its own local coordinate system and the composition of parts into the complete graphical object can include the necessary positioning and scaling as transformations applied to the parts.
In the example in Section 2.7, the parts of the desk were all defined using the same coordinate system and positioned absolutely in the unit square coordinate space. Consequently, the individual parts of the desk are largely hard-wired into their current positions apart from global operations applied to them. In PHIGS, for complex graphical output, it would be more usual for the individual parts to be defined in their own local coordinate system and the picture built up by placing those individual parts relative to each other. This is described in Section 5.4.
The use of PRE and POST concatenation of matrices tends to be a matter of style. If complex objects are defined by a network, the inheritance of transformations effectively gives the local transformation as a PRE multiplication before the global transformation. In consequence, a sequential read of a structure tends to be more natural if the local transformations are defined as PRE multiplications. Most applications can be defined using just PRE multiplication. Mixing PRE and POST multiplications can cause confusion and make the application program less readable.
5.4 A NETWORK EXAMPLE
Figure 5.1 shows a typical open plan office layout with a number of desk configurations placed in a room. There are five different desk arrangements with at least two examples of all but one. The desks are made up of standard components both in terms of the parts of the desk and the accessories on the desk. There are two sizes of telephone but the basic design is identical in both cases. This Chapter will show how such an office plan could be derived and the structure network produced.
As none of the objects has an absolute coordinate position, the proposed strategy is:
- Define the components such as chair, blotter, phone etc in a local coordinate system.
- Construct sub-parts from these components. Examples of sub-parts are the large desk with the accessories added.
- Construct complete desks from the sub-parts.
- Construct a person's work environment including the chair.
- Fit the individual work environments into the office plan.
Figure 5.1: Typical open plan office
Note that there is some natural structuring to the problem although there are choices to be made. Why define a work environment as a desk plus a chair rather than define the chair as part of the desk? Is the lamp a basic component or a sub-part made up of base, arm and light? To a large extent, these decisions are the ones that require knowledge of the application and the possible modifications allowed. Considerable care should be taken in the overall design of the structure network to make sure it meets the needs of the application.
As stated above, it is sensible to define the components in terms of their own local coordinate system. For example, the large desk defined in Section 2.7 might be defined by:
SUBROUTINE DLARGE REAL XL(5), YL(5) DATA XL /0.0, 0.0, 0.4, 0.4, 0.0/ DATA YL /0.0, 0.2, 0.2, 0.0, 0.0/ POLYLINE(5, XL, YL) RETURN END
The large desk is now defined with the origin at the lower left hand corner.
As it appears in many places, this is more sensible than the absolute position defined previously. The polyline defining the large desk could be added to a structure defining the desk and its accessories. Alternatively, the large desk could be defined as a structure:
OPEN STRUCTURE(DESK) DLARGE CLOSE STRUCTURE
There is a danger in proliferating structures unnecessarily as there is quite an overhead in saving and restoring during structure traversal. To simplify the overall structure network in order to make it readable in this book, the desk will be defined as a single polyline as part of a structure defining the large desk and its accessories.
Figure 5.2 shows the accessories that have been defined as separate structures. For simplicity, all have been defined at the required size. To illustrate that this is not necessary, the two instances of the phone in use require the basic components to be scaled for one instance at least. The other components only need to be positioned. The individual components are made up of one or more polylines.
Figure 5.2: Desk accessories
The corner and small desks are also positioned at the origin similar to the large desk. The data values in Section 2.7 would be modified by decreasing both X and Y by 0.6 throughout. The origin is, therefore, the bottom left corner of both the small and corner desks. All three desks will appear at the origin by invoking:
POLYLINE(5, XL, YL) POLYLINE(12, XC, YC) POLYLINE(5, XS, YS)
To achieve the desired arrangement, transformations must be applied to the parts.
To simplify the description of the transformations, four routines are defined which do specific operations:
SUBROUTINE MVRP(DX, DY) BUILD TRANSFORMATION MATRIX(0, 0, DX, DY, 0, 1, 1, ER, MT) SET LOCAL TRANSFORMATION(MT, REPLACE) RETURN END
This routine defines a move of the component relative to the origin. It replaces the current local transformation thus its name of MVRP.
SUBROUTINE RTRP(TH) BUILD TRANSFORMATION MATRIX(0, 0, 0, 0, TH, 1, 1, ER, MT) SET LOCAL TRANSFORMATION(MT, REPLACE) RETURN END
This routine defines a rotation of the component about the origin in an anti-clockwise direction. Again, it replaces the current local transformation thus its name, RTRP.
SUBROUTINE RTPR(TH) BUILD TRANSFORMATION MATRIX(0, 0, 0, 0, TH, 1, 1, ER, MT) SET LOCAL TRANSFORMATION(MT, PRE) RETURN END
This routine defines a rotation about the origin to occur before any other transformation currently in place, thus its name RTPR (PR for PRE).
SUBROUTINE SCPR(S) BUILD LOCAL TRANSFORMATION MATRIX(0, 0, 0, 0, 0, S, S, ER, MT) SET LOCAL TRANSFORMATION(MT, PRE) RETURN END
This routine defines a scaling by S in both X and Y-directions about the origin to occur before any other transformation currently in place, thus its name SCPR.
5.4.5 Define one environment
The aim is to produce the work environment shown in Figure 5.3. This will be done in a set of separate parts.
Figure 5.3: A work environment
To create the large desk with blotter and calculator requires:
OPEN STRUCTURE(LG) POLYLINE(5, XL, YL) MVRP(0.l, 0.025) EXECUTE STRUCTURE(BLOT) MVRP(0.3, 0.025) EXECUTE STRUCTURE(CALC) CLOSE STRUCTURE
The structure LG has been defined relative to the coordinates of the large desk. The blotter has been placed on the desk relative to the lower left corner of the desk as has been the calculator. As a result, any global transformation of the desk will also be applied to the blotter and calculator sitting on it.
To define the work environment consisting of the large desk and a chair would require:
OPEN STRUCTURE(WKNV) MVRP(0.2, 0.6) EXECUTE STRUCTURE(LG) MVRP(0.325, 0.525) EXECUTE STRUCTURE(CHAIR) CLOSE STRUCTURE POST STRUCTURE(WS, WKNV, PR)
To illustrate that the work environment has no obvious origin, the desk and chair have been placed in the unit square coordinate space at the position given before. The structure created is shown in Figure 5.4 and the associated image in Figure 5.5. The abbreviation MVRP denotes the SET LOCAL TRANSFORMATION structure element created by the routine MVRP.
Figure 5.4: Structure for large desk and chair
To add the lamp to the desk requires the structure LG to be extended:
OPEN STRUCTURE(LG) MVRP(0.225, 0.15) EXECUTE STRUCTURE(LMP) CLOSE STRUCTURE
Figure 5.5: Large desk and chair
At this stage, the structure LMP has not been defined so a null structure will be created and no change will be made to the display.
The lamp consists of three parts. The base is defined relative to its centre, the arm is defined relative to one end, and the light itself is defined relative to its centre (see Figure 5.2).
To illustrate the concatenation of modelling transformations, the lamp will be defined so that the light itself can rotate about the arm, the arm can rotate about the base, and the base can rotate on the desk:
REAL ARMX(2), ARMY(2) OPEN STRUCTURE(LMP) RTRP(THBS) EXECUTE STRUCTURE(LMPB) RTPR(THAR) EXECUTE STRUCTURE(ARM) CLOSE STRUCTURE ARMX(1)=0 ARMX(2)=LENGTH ARMY(1)=0 ARMY(2)=0 OPEN STRUCTURE(ARM) POLYLINE(2, ARMX, ARMY) MVRP(ARMX(2), ARMY(2)) RTPR(THLT) EXECUTE STRUCTURE(LITE) CLOSE STRUCTURE
THBS, THAR and THLT are the rotations to be applied to the base, arm and light respectively. If the structure is traversed, the lamp base is rotated by THBS. The arm is rotated by THAR first and then by THBS so it rotates THAR about the base. The light is rotated by THLT, displaced by the length of the arm, rotated by THAR and then rotated by THBS. Consequently, it rotates around the end of the arm and rotates as the arm and base rotate. The structure network for the environment with the lamp on the desk is illustrated in Figure 5.6.
Figure 5.6: Desk with lamp structure
To define the complete desk, the number of hierarchy levels defined so far is probably not the best. The environment has been defined as the chair and large desk. It would have been more sensible to define the environment as the chair and complete desk where the complete desk is defined as the large, corner and small desks and so on:
OPEN STRUCTURE(WKNV) MVRP(0.2, 0.6) EXECUTE STRUCTURE(DESK) MVRP(0.325, 0.525) EXECUTE STRUCTURE(CHAIR) CLOSE STRUCTURE
The following defines the structure DESK:
OPEN STRUCTURE(DESK) EXECUTE STRUCTURE(LG) MVRP(0.4, 0.0) EXECUTE STRUCTURE(CN) MVRP(0.4, -0.2) EXECUTE STRUCTURE(SM) CLOSE STRUCTURE
As neither CN or SM have been defined, the display at the workstation will be as before. Note that the corner and small desks have been defined with a displacement relative to the origin of the large desk. By choosing the contents of the structures carefully, the display can be broken down into manageable parts using local coordinates. The corner and small desks can now be defined with their contents relative to the origin of the particular desk.
OPEN STRUCTURE(CN) POLYLINE(12, XC, YC) MVRP(0.01, 0.025) EXECUTE STRUCTURE(PHON) MVRP(0.123, 0.023) EXECUTE STRUCTURE(PHON) CLOSE STRUCTURE OPEN STRUCTURE(SM) POLYLINE(5, XS, YS) MVRP(0.05, 0.075) EXECUTE STRUCTURE(INLY) CLOSE STRUCTURE
The complete structure network is shown in Figure 5.7 and the resulting picture in Figure 5.8. The phone has not been scaled to simplify the example. After the MVRP, a SCPR function invocation would have scaled the phone appropriately if it was the wrong size. The example has been constrained to 4 hierarchical levels and one more would have been needed at least for the complete office layout.
Figure 5.7: Complete structure network for desk
The structure has been arranged in levels starting from the complete environment. This is made up of two distinct items, the desk and chair, positioned independently in the environment. The complete desk is made up of three parts defined at the next level down. The next level defines the accessories on the desk. The most complex object, the lamp, has another two levels of hierarchy. As can be seen, quite simple scenes require significant networks. A detailed schematic of a complex object could require between 10 and 20 levels with 2000 structures involved. Care should be taken in ensuring that the inter-relationship of objects and the parts making up them are specified prior to programming the application. A badly defined structure hierarchy will be difficult to debug and difficult to change.
Figure 5.8: Complete desk
To reposition the lamp on the desk would require the relevant structures to be modified. The two structures in question are LMP and ARM. The former contains the structure elements that rotate the base and the arm while the latter defines the rotation of the light itself.
The relevant edits to change the orientation of the base, arm and light require the values of THBS, THAR or THLT to be changed. Given the new values, the required edit to change all three is:
SET EDIT MODE(REPLACE) OPEN STRUCTURE(LMP) SET ELEMENT POINTER(1) RTRP(THBS) SET ELEMENT POINTER(3) RTPR(THAR) CLOSE STRUCTURE OPEN STRUCTURE(ARM) SET ELEMENT POINTER(3) RTPR(THLT) CLOSE STRUCTURE
It is quite appropriate to use absolute edits in replace mode as the element positions do not change. If this set of commands were repeated in a loop, with different values to the parameters, the lamp could be animated to rotate. Figure 5.9 shows the position of the lamp if THBS was 0.4Ï€, THAR was 0.3Ï€ and THLT was 0.5Ï€.
Figure 5.9: Desk with lamp rotated
5.5 GLOBAL TRANSFORMATION RESETTING
So far, the global modelling transformation has been defined as the composition of all the modelling transformations defined prior to the execution of the current structure.
In the structure network defined in Figure 5.7, the global modelling transformation applied to the ARM of the light is:
- WKNV: a move of (0.2, 0.6);
- DESK: no additional transformation;
- LG: a move of (0.225, 0.15);
- LMP: a rotation of THBS with a pre-multiplication of a rotation by THAR.
It is possible that at this stage of the hierarchy, some graphical output is required which has an intrinsic connection to the object being displayed but for which the current global modelling transformation is inappropriate. For example, suppose a dial is required to indicate the amount of rotation to be applied to the light itself. The dial is to be displayed at a fixed position on the display and should only be there if the lamp is part of the accessories on the desk (see Figure 5.10).
PHIGS provides the function:
SET GLOBAL TRANSFORMA TION(MT)
This replaces the current global modelling transformation by MT. To place the dial in the top right hand corner, the structure ARM defined in Section 5.4.5 could be extended as shown in the program following.
Figure 5.10: Lamp with associated dial
OPEN STRUCTURE(ARM) BUILD TRANSFORMATION MATRIX(0, 0, 0.83, 0.83, 0, 1, 1, ER, MT) SET GLOBAL TRANSFORMATION(MT) MVRP(0, 0) DO 10 1=1,37 DIALX(I)=0.1 * COS(PI*(I-1)/18) DIAL Y(I)=0.1 * SIN(PI*(I-1)/18) 10 CONTINUE POLYLINE(37, DIALX, DIALY) DO 20 1=1,37,3 TICKX(I)=0.1 * COS(PI*(I-l)/18) TICKY(I)=0.1 * SIN(PI*(I-l)/18) TICKX(2)=0.11 * COS(PI*(I-1)/18) TICKY(2)=0.11 * SIN(PI*(I-l)/18) POLYLINE(2, TICKX, TICKY) 20 CONTINUE RTPR(THLT) DRAW POINTER CLOSE STRUCTURE
The global modelling transformation is replaced by a move to the point (0.83, 0.83) which is to be the centre of the dial. The local modelling transformation is reset to the identity matrix by the MVRP function. The dial is then produced centred on the position defined by the global modelling transformation. Finally, the pointer defined by DRAW POINTER is drawn. This is a vertical arrow centred on the origin which will be rotated by THLT, the local modelling transformation defined by RTPR. THLT will be set to the same value that is used to rotate the light. The result is shown in Figure 5.10.
5.6 UTILITY FUNCTIONS
The local and global modelling transformations defined so far have been created using the BUILD TRANSFORMATION MATRIX function. This is an all embracing function. Some simpler functions (MVRP, RTRP, RTPR, SCPR) have been defined in Section 5.4.4 which provide only one of the transformations shift, rotate or scale and create a SET LOCAL TRANSFORMATION structure element. Whether it is replacing the existing matrix is defined by the last two letters. RP for replace and PR for pre-multiply.
PHIGS provides a number of additional utility functions similar to these functions. These are:
TRANSLATE(DX, DY, ER, MT)
This creates a matrix MT that defines a translation by (DX, DY).
SCALE(SX, SY, ER, MT)
This creates a matrix MT that defines a scaling relative to the current origin.
ROTATE(TH, ER, MT)
This creates a matrix MT that defines a rotation of TH radians anti-clockwise about the current origin.
These three functions are similar to the ones defined earlier but the major difference is that they do not create structure elements. In consequence, they can be used for creating both local and global modelling transformations with pre or post-multiplication or replacing the existing local transformation.
Two further functions are provided to create a new matrix from an existing one:
COMPOSE MATRIX(MT A, MTB, ER, MT)
The composition of matrices is needed if several global modelling transformations are required to be concatenated. The SET GLOBAL TRANS FORMATION function only provides a replace capability. Composition is sometimes needed when the application wishes to keep a record of the composite matrix that is being applied to some part of a structure network. As will be seen in Chapter 10, it is sometimes needed when input positions are returned in world coordinates and the application wishes to find the equivalent modelling coordinate position. The resulting matrix MT consists of MTA Ã— MTB.
COMPOSE TRANSFORMATION MATRIX (MTA, XF, YF, DX, DY, PHI, SX, SY, ER, MT)
This is exactly equivalent to:
BUILD TRANSFORMATION MATRIX (XF, YF, DX, DY, PHI, SX, SY, ER, MTB) COMPOSE MATRIX(MTA, MTB, ER, MT)
5.7 STRUCTURE FUNCTIONS
PHIGS provides a number of structure handling operations to allow structures to be manipulated in the central structure store. The functions are similar to the set that would be available in a conventional filestore (renaming, copying etc). However, more care is needed as the structures themselves often contain references to other structures.
5.7.2 Changing the name of a structure
The PHIGS function for changing the name of a structure is:
CHANGE STRUCTURE IDENTIFIER(ORIG, RESLT)
The structure with the name ORIG has it changed to RESLT in the central structure store. There are several uses for this function. For example, a structure network may have been defined that shows a view of a car. Two types of wheels may be available for the car and these are defined in structures WH1 and WH2. The structure describing the car has elements EXECUTE STRUCTURE(WH) to define the wheels. To choose a particular type of wheel, say WH1, would require:
CHANGE STRUCTURE IDENTIFIER(WH1, WH)
The problems that can occur are where WH is already defined and where WH1 is being used in some other structure network. If WH is already defined, the function effectively replaces the old contents of WH by the contents of WH1. If WH1 is in use, a new empty WH1 structure is created. This applies whether the use is a reference to it, whether it has been posted to a workstation, or if it is the open structure. This is just done to ensure that PHIGS does not produce an error in this situation. In practice, care should be taken not to change a structure's name while it is being used.
5.7.3 Changing structure references
The same effect could be achieved by changing all the references to WH to either WH1 or WH2 depending on which type of wheel is required. The function is:
CHANGE STRUCTURE REFERENCES(ORIG, RESLT)
All the EXECUTE STRUCTURE elements in the central structure store that refer to ORIG are changed to RESLT. Any references to RESLT remain unchanged. This means that at a subsequent time it will not be easy to change the references to RESLT back to ORIG if only the set changed are to be reversed.
To change the name of the structure and all references to it, the following function is provided:
CHANGE STRUCTURE IDENTIFIER AND REFERENCES (ORIG, RESLT)
This is equivalent to invoking the CHANGE STRUCTURE IDENTIFIER function followed by CHANGE STRUCTURE REFERENCES.
5.7.4 Adding elements from another structure
It is possible to use the central structure store as a filestore of useful sequences of structure elements. The structures themselves will never be posted or executed as part of a structure network. Instead, they are used to build other structures. The relevant PHIGS function is:
COPY ALL ELEMENTS FROM STRUCTURE(SI)
All the elements of SI are added to the open structure at the element pointer position. By copying templates and editing them, specific structures can be constructed from the parts. Care must be taken if the structure SI contains modelling transformation elements. The effect in this case may be different from executing structure SI even when no changes are made due to the nesting of local transformations. It is even possible to copy the open structure in which case the structure will have its contents copied into itself. For example:
XA(1)=0 YA(1)=0 XA(2)=LENGTH YA(2)=0 OPEN STRUCTURE(SI) RTPR(0.1*PI) POLYLINE(2, XA, Y A) DO 10 I=1,4 COPY ALL ELEMENTS FROM STRUCTURE(SI) 10 CONTINUE CLOSE STRUCTURE
The resulting structure will consist of 16 lines of length LENGTH radiating from the origin and rotated by 0.1Ï€ from each other.
5.7.5 Deleting structures
The simplest function available in PHIGS for deleting structures is:
which deletes the structure SI and all references to it are removed. If it is posted to a workstation, it will be unposted. If it is the open structure, it will remain the open structure but its contents will be removed. This means that the sequence numbers of elements in other structures may change including possibly the open structure. In this latter case, the element pointer is adjusted to point at the same element it was pointing at before the deletion unless it happens to be an EXECUTE STRUCTURE element with the deleted structure as parameter. In this case, the element pointer is moved to point at the element before this one.
To delete a structure network:
DELETE STRUCTURE NETWORK(SI, FLAG)
If FLAG is set to DELETE, the structure SI and all the structures that it EXECUTEs are deleted. For example, the structure network in Figure 5.7 would be completely deleted by:
DELETE STRUCTURE(WKNV, DELETE)
If FLAG is set to KEEP, the same would happen unless the structures in the network were referenced elsewhere. Consequently, if the complete office environment had other references to the items on the desk, deleting WKNV would not delete the structures such as PHON.
To completely clear out the central structure store, PHIGS provides:
DELETE ALL STRUCTURES
This ensures that no structures are inadvertently left in the store. As structures can be archived (see Chapter 14), this may be a sensible function to invoke before starting a separate task in an application.
5.7.6 Emptying structures
The DELETE STRUCTURE function makes changes to any structure that has EXECUTE elements invoking the structure to be deleted. A less severe command which removes the elements in the structure but leaves all the pointers to it intact is:
It is as though all the elements in the structure had been deleted by structure editing.
5.8 MODELLING CLIP
So far, it has been assumed that the scene created by the traversal of a structure network will be viewed in its entirety. The viewing process may suppress some parts of the scene so that the picture to be displayed is not the complete scene. During structure traversal, it is also possible to remove parts of the output primitives generated so that the scene to be viewed does not contain all of the output primitives generated. This is achieved by a modelling clip.
In PHIGS, structure elements can be defined that specify a clip to be performed on all subsequent output primitives once the clip is enabled. The traversal state list contains two entries, the current modelling clipping volume and a modelling clipping indicator. As output primitives are created on traversal, if the indicator is set to clipping being enabled, the parts of primitives outside the clipping volume will be removed and will not be part of the scene created. During structure traversal, it is possible to change the modelling clipping volume and to set the modelling clipping indicator to clip or not at any time.
5.8.2 The function
The function that defines the extent of a clip is:
SET MODELLING CLIPPING VOLUME(OP, N, HLFSPA)
At the start of structure traversal, the modelling clipping volume is infinite, that is no part of the scene will be clipped even if clipping is enabled. The occurrence of this structure element on traversal will change the clipping volume depending on the value of the first parameter OP:
- REPLACE: if OP is specified as REPLACE, the clipping volume defined by this structure element will replace the current clipping volume.
- INTERSECT: if OP is set to INTERSECT, the new modelling clipping volume will be the intersection of the current clipping volume with the clipping volume specified by this structure element. The new clipping volume cannot be larger than the previous one. That is anything that would have been clipped by the old clipping volume will continue to be clipped and anything clipped by the new clipping volume just defined will also be clipped.
The modelling clipping volume is specified by a set of half-spaces. The third parameter is an array of N entries where each one defines a halfspace. The half-space is defined by a point on its boundary and the normal to the half-space in the direction of the clipped part of space. The second parameter, N, defines the number of half-spaces.
The third parameter has entries:
HLFSPA(1,I)=X HLFSPA(2,I)=Y HLFSPA(3,I)=DX HLFSPA(4,I)=DY
where I specifies the definition of the Ith half-space. The point on the boundary is (X, Y) and the normal is the vector from (X,Y) to (X+DX, Y+DY).
The function that enables or stops clipping is:
SET MODELLING CLIPPING INDICATOR(MCLIPI)
When structure traversal starts, the entry in the traversal state list is set to NOCLIP. On traversal, this function will reset the current value of this entry to CLIP or NOCLIP depending on the value of MCLIPI.
When an EXECUTE STRUCTURE element is encountered during structure traversal, the child structure to be traversed inherits the current value of the modelling clipping volume and clipping indicator in the same way as other values in the traversal state list are inherited. These values are restored when the traversal of the child structure is complete.
A function is provided to allow the modelling clipping volume inherited by a structure to be restored after it has been changed in the traversal of the child structure. The function is:
RESTORE MODELLING CLIPPING VOLUME
The current value of the modelling clipping volume is replaced by the one in existence when traversal of this child structure started.
5.8.3 A window clip
A simple example of the modelling clip in use would be to define a window (XMIN, XMAX, YMIN, YMAX) within which the scene remains and the outside of which is clipped away.
If the structure in Figure 5.7 is to be modified so that the scene displayed in Figure 5.8 is to be constrained, the WKNV structure would be changed by editing as follows:
OPEN STRUCTURE(WKNV) SET ELEMENT POINTER(0) SET MODELLING CLIPPING INDICATOR(CLIP) HLFSPA(1,1 )=XMIN HLFSPA(2,1)=0 HLFSPA(3,1)=0 HLFSPA(4,1)=-1 HLFSPA(1,2)=XMAX HLFSPA(2,2)=0 HLFSPA(3,2)=0 HLFSPA(4,2)=1 HLFSPA(1,3)=0 HLFSPA(2,3)= YMIN HLFSPA(3,3)=-1 HLFSPA(4,3)=0 HLFSPA(1,4)=0 HLFSPA(2,4)= YMAX HLFSPA(3,4)=1 HLFSPA(4,4)=0 SET MODELLING CLIPPING VOLUME(REPLACE, 4, HLFSPA) CLOSE STRUCTURE
An example of the result is shown in Figure 5.11.
Figure 5.11: Modelling clip
Currently, it is difficult to do the reverse operation of shielding in PHIGS. That is to define a volume within which clipping is to occur and outside of which it is not to occur. Although facilities for doing this were proposed during the standardization of PHIGS, they were not included as part of the standard in its final form.
On a monochrome bit-map display, it can be achieved by:
DELETE STRUCTURE(WKNV) OPEN STRUCTURE(WKNV) SET MODELLING CLIPPING INDICATOR(CLIP) HLFSPA(1,1)=XMIN HLFSPA(2,1)=0 HLFSPA(3,1)=0 HLFSPA(4,1)=1 SET MODELLING CLIPPING VOLUME(REPLACE, 1, HLFSPA) MVRP(0.2, 0.6) EXECUTE STRUCTURE (DESK) HLFSPA(1,1)=XMAX HLFSPA(4,1)=-1 SET MODELLING CLIPPING VOLUME(REPLACE, 1, HLFSPA) MVRP(0.2,0.6) EXECUTE STRUCTURE(DESK) HLFSPA(1,1)=0 HLFSPA(2,1)=YMIN HLFSPA(3,1)=1 HLFSPA(4,1)=0 SET MODELLING CLIPPING VOLUME(REPLACE, 1, HLFSPA) MVRP(0.2, 0.6) EXECUTE STRUCTURE(DESK) HLFSPA(2,1)=YMAX HLFSPA(3,1)=-1 SET MODELLING CLIPPING VOLUME(REPLACE, 1, HLFSPA) MVRP(0.2, 0.6) EXECUTE STRUCTURE(DESK) CLOSE STRUCTURE POST STRUCTURE(WS, WKENV, 0.2)
This is a cumbersome way of achieving the effect but it does indicate that careful use of the modelling clipping volume can produce a range of effects. The picture is drawn with everything above the bottom boundary of the shield clipped followed by drawing the picture again with everything below the top boundary clipped. This gives the top part and bottom part of the picture. The picture is drawn a third time with everything drawn to the right of the left hand shield boundary clipped and finally it is drawn a fourth time with everything to the left of the right hand boundary clipped. This generates the picture shown in Figure 5.12. The four corners have been drawn twice but as it is a monochrome display with a single bit per pixel, this will not be noticeable!
Figure 5.12: Four modelling clips producing a shield
5.9 APPLICATION DATA
The following function is provided in PHIGS to relate the PHIGS structure store to any application database associated with the application:
APPLICATION DATA(LDR, DATREC)
On traversal, this structure element has no effect (just like label elements). Its use is mainly to provide additional information relevant to the application. Section 10.2.4 gives the format of the data record. A frequent use is to store pointers in the central structure store that point to the equivalent parts of the application database.
5.10 GENERALIZED STRUCTURE ELEMENT
Just as the generalized drawing primitive extends the output primitive structure elements in an unspecified way, the function:
GENERALIZED STRUCTURE ELEMENT(GSEID, LDR, DA TREC)
defines an element of type GSEID. Its usage is undefined. It provides a mechanism for implementations to define non-standard activities. The local implementation manual needs to be consulted to see what, if any, values of the function have been defined.