[ Previous | Next | Contents | Glossary | Home | Search ]
The graPHIGS Programming Interface: Understanding Concepts

Chapter 14. Explicit Traversal Control


Overview

The default processing of the graPHIGS API is to collect primitives and attributes into groups called structures. This grouping allows data to be defined hierarchically and permits easy modification through structure editing operations. In addition, to draw the picture that is defined by the structure content, the graPHIGS API traverses the structures. This traversal makes the displayed picture correct, but requires that all the affected contents be redrawn.

There may be reasons that the structures are not a benefit to some applications; such as, the data is not hierarchical or the structure changes are extensive enough as to require complete replacement of all structure content. In addition, you may want to perform your own traversal in your application rather than invoking the graPHIGS API to perform the traversal. (By doing your own traversal, you can realize your own optimizations and "short-cuts" that the graPHIGS API does not provide, thus improving end-user responsiveness).

To allow an application to directly control the traversal and drawing process, the graPHIGS API provides subroutine calls that access the very basic rendering controls of the workstation. These controls suspend the normal (implicit) processing of the graPHIGS API rendering and allow your application to provide its own (explicit) processing. These controls provide your application explicit traversal control in the following ways:

Together, these three facilities, Immediate Elements, Direct Traversal Processing, and Workstation Resource Control, are called Explicit Traversal Control, since they suspend the default graPHIGS traversal and allow the application to perform the traversal directly (i.e. explicitly). By using these facilities, a graPHIGS application can implement update techniques that are optimized for the application's requirements, and can use data organizations other than the hierarchical, centralized structure store. For example, an application could:


Explicit Traversal Capabilities

Existing graPHIGS applications operate without change and still obtain all the internal optimizations implicitly performed. When using the explicit traversal functions, the application defines its own traversal and can provide its own optimizations in place of those of the graPHIGS API If the workstation is in WAIT deferral state and NO_IMMEDIATE_VISUAL_EFFECT (NIVE) modification mode, changes are processed only at the application's request. Other combinations of deferral states and modification modes are ignored and the explicit processing forces the workstation into a "conceptual" mode of WAIT /NO_IMMEDIATE_VISUAL_EFFECT

Explicit Traversal

All explicit traversals are initiated by the application by calling the Begin Traversal (GPBGTR) subroutine, which specifies the workstation to receive the elements produced by the application's traversal. The function parameters include a workstation identifier, a processing type, and processing-type-specific information. This function sets a new workstation state Workstation Selected (WSSL) and can only be called from state Workstation Open (WSOP), which implies GPBGTR can not be nested. The selected workstation receives subsequent explicit traversal commands. The workstation becomes dedicated to the traversal processing, and is conceptually put in WAIT deferral state and NO_IMMEDIATE_VISUAL_EFFECT modification mode, since the application explicitly directs the traversal and rendering processing. (This processing state is similar to the Update Workstation (GPUPWS) and Redraw All Structures (GPRAST) subroutines, where a traversal is performed on the contents of the structure store. However, GPBGTR identifies the workstation to interpret the elements: the application is performing the traversal).

Upon receiving the Begin Traversal (GPBGTR) subroutine, the workstation:

The application process that issues GPBGTR cannot change the contents of the WSL until after an End Traversal (GPENTR) subroutine is called. This restriction is to ensure consistency of the rendering of primitives during explicit traversal processing.

GPENTR completes an explicit traversal sequence and requires the structure state Structure Open (STOP) or Structure Close (STCL) and the workstation state Workstation Selected (WSSL). The structure state can not be the newly defined state Non-Retained Structure Open (NROP). Upon receiving this command, the workstation completes any processing of the scene. Notice that this function does not delete the scene or clear the Rendering Resources. The scene can be appended to if the application invokes another GPBGTR - GPENTR sequence. The effect of appending to an existing scene is Renderer dependent. In addition, the results of appending to a scene are indeterminate if the WSL is changed between GPENTR and the next GPBGTR

Immediate Elements

In order for an application to send structure elements directly to a workstation or explicitly traverse structures in the Centralized Structure Store, an application must first call the Begin Structure (GPBGST) subroutine. GPBGST changes the structure state to Non-Retained Structure Open (NROP) and directs all subsequent elements to the workstation. The End Structure (GPENST) subroutine completes the explicit traversal sequence started by GPBGST and returns the structure state to Structure Closed (STCL).

GPBGST precedes immediate structure elements that are to be interpreted by a workstation. It is part of the application's traversal processing, and is analogous to the graPHIGS API processing performed by a workstation when traversing a root structure, where the Traversal State List (TSL) is initialized. (Refer to The graPHIGS Programming Interface: Technical Reference for details on the Travers al State List.) The Begin Structure (GPBGST) subroutine does not reference any retained structures nor does it cause elements to be retained. Rather, it indicates that the application is sending elements for interpretation and display by the workstation.

Upon receiving a Begin Structure (GPBGST) subroutine call, the workstation:

A GPBGST - GPENST sequence is only permitted in workstation state Workstation Selected (WSSL) which implies that they must be bracketed by Begin Traversal (GPBGTR) and End Traversal (GPENTR) subroutine calls.

Following the GPBGTR and GPBGST subroutine calls, output primitives and attributes (e.g., Polyline 3 [GPPL3]) are passed to the traversing workstation for interpretation. Your application can use any API call that, in the default processing, would create a structure element. (These are the subroutine calls in the Output Primitives and Attributes chapters of The graPHIGS Programming Interface: Subroutine Reference manual.) In immediate mode, the same element is sent to the workstation for interpretation rather than being stored in a structure. This includes the Execute Structure element, which results in the traversal of the identified structure. Thus, an application can use immediate mode processing to also traverse structures and their contents. The End Traversal (GPENTR) and End Structure (GPENST) subroutines indicate completion of the corresponding GPBGTR and GPBGST subroutines.

The following immediate elements are valid only in state NROP (these are not valid elements to insert into a structure):

Direct Traversal Processing

In the default graPHIGS API processing, traversal is the process of stepping through a structure network, and is performed on the structures associated to a view. The result of traversal is the set of elements (primitives and attributes) to be interpreted by the workstation.

Your application can replace the graPHIGS API default traversal processing with its own traversal. By doing this, your application determines the primitives and attributes to be processed by the workstation and directs the rendering of these elements by the workstation. This processing is called direct traversal

Your application has two methods to provide the elements to the workstation during direct traversal:

The application can use these methods either independently or together to perform the traversal. Thus, direct traversal can be performed using both elements in structures and immediate elements.

Two functions are defined to allow an application to traverse a subset of an entire structure. These two function are the Traversal Elements (GPTE) and Accumulate Traversal State (GPATS) subroutines. Both functions are only valid in structure state Non-Retained Structure Open (NROP).

The Traversal Elements (GPTE) subroutine function causes the traversal of a group of structure elements found in a structure in the associated structure store. Start and end criteria can be specified, allowing the application to render a subset of a structure (for example, traversing the elements between two labels in a structure).

GPATS causes traversal of a group of structure elements found in a structure in the associated structure store. The elements are interpreted only to update the Traversal State List (TSL). No drawing of any primitive elements is performed. Execute Structure elements are ignored, but do increment the element counter. Accumulating the traversal state can be used, for example, to set the TSL before rendering immediate mode primitives. The effect of Accumulate Traversal State is to modify the current TSL which is sometimes called "Pseudo Traversal"

Both functions accept a flexible specification for the location in the structure to start and end traversal. These locations may be specified as pick identifier, label, element number, element type, or end-of-structure. An error is generated if the start location does not exist. If the end condition does not exist, traversal stops when the end of the structure is reached.

The element counter in the current TSL is incremented for each element that is traversed by these two functions.

In addition, to the direct traversal subroutines, two other subroutine calls are available for direct processing.


Control of Workstation Resources

The workstation is responsible for interpreting elements for display on the display surface. The process of converting the elements to displayable data is called rendering Each workstation has certain resources that are used during rendering, such as frame buffers, Z-buffers, and memory. The workstation's resources are grouped according to purpose:

A workstation has only one type of rendering target (for example, a frame buffer), although the workstation can have several of them (for example, a double buffered device.) The application can select which of the resources are used during the traversal process. In addition, the application can perform operations such as clearing the resource.

Control of Rendering Targets

Explicit control of the rendering target allows the application to control which target is updated by rendering and when pictures are displayed. There are several functions in this category. All require workstation state Workstation Open (WSOP). These functions include:

Any Rendering Target can be chosen for modification and/or for display. The Rendering Target chosen for modification is called the Selected Rendering Target and the Rendering Target chosen for display is called the Displayed Rendering Target

For ease in specifying Rendering Targets, they are conceptually organized in a ring as shown in the figure, "Rendering Target Ring." To specify a Rendering Target, an application must specify an offset from either the Selected Rendering Target or the Displayed Rendering Target. The offset must be an integer number; positive, negative, or zero. For example, for a double-buffered workstation an application could select the displayed buffer plus one for the next update. Upon completion of the update, the displayed buffer is set to the one just drawn (0 relative to the currently Selected Rendering Target).

Additional resource control subroutines allow your application to control the areas that are defined by the extents of a view:

Control of Rendering Resources

The Clear All Rendering Resources (GPCARR) subroutine resets all Rendering Resources for the specified workstation. The function requires workstation state Workstation Open (WSOP) which means that GPCARR is not allowed between the Begin Traversal (GPBGTR) subroutine and the End Traversal (GPENTR) subroutine. This reset occurs in a workstation-dependent manner, depending on the type of resources. For example, if a workstation has a Z-buffer, then GPCARR causes the Z-buffer to be cleared.

Inquiry Functions

The Inquire Rendering Targets (GPQART) subroutine returns the number of Rendering Targets available on a workstation for explicit use by an application. If the number returned is zero, explicit traversal control is not supported on the workstation.

Effect of Explicit Traversal Functions on Display Surface States

PHIGS defines the following two fields in the WSL to describe the state of the display surface:

The state of the currently Displayed Rendering Target defines the state of the display surface of the graPHIGS API workstation. In addition, these fields are maintained for every Rendering Target of the workstation.

If a change is made to the WSL or any of the structure networks posted to the workstation, the State of Visual Representation for the currently Selected Rendering Target is set appropriately depending on whether the change was simulated or deferred. The State of Visual Representation is a flag that is set when you post structures to a workstation. Instead of displaying the change to a structure when it is posted, you can make a group of changes and then update the display once. The State of Visual Representation keeps track of whether the display is correct (shows all the changes that have been posted.) (Refer to "Frame Buffer Manipulation" for an explanation of the State of Visual Representation values.) The State of Visual Representation for the other Rendering Targets is set to DEFERRED but their content is not modified.

A Redraw All Structures (GPRAST) subroutine results in a CORRECT State of Visual Representation for the currently displayed Rendering Target (after completion). That is, the GPRAST causes the workstation to be cleared and to redisplay all the posted structures. The Clear Rendering Target (GPCRT) subroutine resets the Display Surface Empty status of the specified Rendering Target to EMPTY The effect of Update Workstation with control flag set to PERFORM is conditional:

All explicit traversal control functions set the state of the Selected Rendering Target to SIMULATED.

Notice that the display of a different Rendering Target could cause the State of Visual Representation and Display Surface Empty status of the PHIGS workstation to change.

Interactions with Implicit Updates

All of the explicit traversal functions can be used with any combination of deferral states and modification modes. If a change is made to the WSL while in workstation state Workstation Selected (WSSL) and that change requires a modification be made to the display surface, the modification is postponed until the workstation state changes from WSSL to Workstation Open (WSOP). When the workstation state changes to WSOP, then the display is updated if required by the current deferral state and modification mode.

Implicit traversals performed by a workstation are affected by the explicit traversal processing of the application. Implicit regenerations and simulations of updates are not performed while in state WSSL. Implicit correlations and input device echoes are not performed while in state NROP.

When an implicit update traversal is performed, the graPHIGS API changes the contents of the current displayed and selected Rendering Target. The value of the display status is set to CORRECT for the displayed Rendering Target, and is unchanged for any other Rendering Targets. After completion of an implicit update, the selected rendering target is the same as the display rendering target.

Considerations When Using Explicit Traversal

There are several important considerations when using the explicit traversal functions. These considerations must be addressed to ensure that your use of explicit traversal does not cause problems with other parts of the graPHIGS API


Explicit Traversal Control Examples

This section contains a set of example pseudocode fragments which illustrate the use of Explicit Traversal Control.

Trivial Updates

This example shows the changing of the color of a polyline without forcing a redraw of the entire screen. Through use of the explicit traversal controls, the application can be written to modify the polyline's color attribute and then retraverse just the attribute and polyline primitive. The code fragment listed below illustrates this type of trivial update, with the following assumptions:

.
.
.
CALL GPOPST(structure_id)                                                                
  CALL GPEP(element_number-1)                                                            
  CALL GPDLE                                                                              
    CALL GPPLCI(HIGHLIGHT_COLOR)                                                            
CALL GPCLST                                                                               
                                                                                          
CALL GPBGTR(WORKSTATION_ID, DRAWING, NULL)                                                
  CALL GPBGST(ANY_INTEGER)                                                                
    CALL GPTE(structure_id, START(element_number-1), END(element_number))                 
  CALL GPENST                                                                             
CALL GPENTR                                                                               
.
.
.

Accumulate State and Traversal State List Manipulation

The trivial update example can be generalized to use a pick path of any depth by taking advantage of the Accumulate Traversal State (GPATS) subroutine. The pseudo code below also illustrates the use of the Push Set TSL (GPPSTS) subroutine and the Pop TSL (GPPTS) subroutine although, in this particular example, neither are required. The pseudo code was written with the following assumptions:

                                                                                          
.
.
.
CALL GPOPST(pick_path[depth]                                                      
  CALL GPEP(pick_path[depth]                                                      
  CALL GPDLE                                                                              
  CALL GPPLCI(HIGHLIGHT_COLOR)                                                            
CALL GPCLST                                                                               
                                                                                          
CALL GPBGTR(WORKSTATION_ID, DRAWING, NULL)                                                
  CALL GPBGST(ANY_INTEGER)                                                                
    DO 100 i = 1, depth                                                                   
      CALL GPPSTS(ANY_INTEGER)                                                            
      structure_id   = pick_path[i]                                               
      element_number = pick_path[i]                                               
      CALL GPATS(structure_id, START(ELEMENT1), END(element_number-1))                    
100 CONTINUE                                                                              
                                                                                          
    CALL GPTE(structure_id, START(element_number), END(element_number))                   
                                                                                          
    DO 200 i = 1, depth                                                                   
      CALL GPPTS                                                                          
  200  CONTINUE                                                                           
  CALL GPENST                                                                             
CALL GPENTR                                                                               
.
.
.

Animation and Double Buffering

The example code fragment below illustrates the animation of a line rotating about the origin. The animation is made "smooth" through the use of double buffering. The assumptions are as follows:

Note: The Inquire Available Rendering Targets (GPQART) subroutine function is called to ensure the workstation has at least two Rendering Targets.

                                                                                          
.
.
.
CALL GPQART(WORKSTATION_TYPE, error_indicator, number_of_rts)                             
                                                                                          
if (number_of_rts.GE> 2) THEN                                                             
  line[POINT1]                                                                    
  line[POINT1]                                                                    
  loop i = 1 to 360                                                                       
    CALL GPSRT(WORKSTATION_ID, DISPLAYED_RENDERING_TARGET+1)                              
    CALL GPCRT(WORKSTATION_ID, SELECTED_RENDERING_TARGET+0)                               
   CALL GPBGTR(WORKSTATION_ID, DRAWING, NULL)                                             
      CALL GPBGST(ANY_INTEGER)                                                            
        angle = angle + DELTA_ANGLE x i                                                   
        line[POINT2]                                                              
        line[POINT2]                                                              
        CALL GPPL2(TWO, line)                                                             
       CALL GPENST                                                                        
    CALL GPENTR                                                                           
    CALL GPDRT(WORKSTATION_ID, SELECTED_RENDERING_TARGET+0)                               
.
.
.

Redraw All Structures

The Redraw All Structures (GPRAST) subroutine function can be defined using the explicit traversal functions as shown in the following pseudo code:

                                                                                          
CALL GPRAST( workstation_id, flag )                                                       
  CALL GPSRT( workstation_id, DISPLAYED_RENDERING_TARGET+1 )                              
                                                                                          
  if ( not_empty(selected_rt) or (flag.EQ.ALWAYS )) THEN                                  
    CALL GPCRT(WORKSTATION_ID, SELECTED_RENDERING_TARGET+0)                               
                                                                                          
  CALL GPBGTR                                                                             
    for each root                                                                         
      CALL GPBGST(ANY_INTEGER)                                                            
        CALL GPTE(root, ELEMENT_1, END_OF_STRUCTURE)                                      
      CALL GPENST                                                                         
  CALL GPENTR                                                                             
                                                                                          
  CALL GPDRT(WORKSTATION_ID, SELECTED_RENDERING_TARGET+0)                                 
                                                                                          

Note: After a call to Redraw All Structures, both the Selected Rendering Target and Displayed Rendering Target are the same.

Update Workstation

The differences between the pseudo code for the Update Workstation (GPUPWS) and Redraw All Structures (GPRAST) subroutines are as follows:

CALL GPUPWS( workstation_id, flag )                                                       
  IF ( ( state_of_visual_rep(displayed_rt).EQ. DEFERRED or                                
         state_of_visual_rep(displayed_rt).EQ.SIMULATED ) &                               
       flag.EQ.PERFORM ) THEN                                                             
                                                                                          
    CALL GPSRT( workstation_id, DISPLAYED_RENDERING_TARGET+1 )                            
                                                                                          
    IF ( note_empty(selected_rt) ) THEN                                                   
      CALL GPCRT(WORKSTATION_ID, SELECTED_RENDERING_TARGET+0)                             
                                                                                          
    for each root                                                                         
      CALL GPBGST(ANY_INTEGER)                                                            
        CALL GPTE(root, ELEMENT_1, END_OF_STRUCTURE)                                      
      CALL GPENST                                                                         
                                                                                          
      CALL GPDRT(WORKSTATION_ID, SELECTED_RENDERING_TARGET+0)

Note:

If the control flag parameter is set to PERFORM , the State of Visual Representation for the currently displayed Rendering Target upon completion of this function is always CORRECT and the same Rendering Target is both selected and displayed.

[ Previous | Next | Contents | Glossary | Home | Search ]