Jump Over Left Menu
Chapter 6: Viewing in 2D
In Chapter 5, the desk and its accessories were defined in modelling coordinates which, on traversal, generated a display with coordinates in the range 0 to 1 in the X and Y-directions. PHIGS guarantees that the defaults set by the system will ensure that this unit square will be visible on the display. In this Chapter, the viewing facilities in PHIGS will be described which allow the application to choose an appropriate coordinate system and orientation for the description of the scene to be viewed. PHIGS allows the application to control how the scene is mapped down to the unit square so that it can be displayed.
PHIGS is primarily a 3D system with a 2D subset. The form of viewing in PHIGS is defined with the functionality required for 3D. The 2D viewing is kept as similar to the 3D as possible. Consequently, the 2D viewing is not as elegant as it might be but it includes additional functionality not normally present in a straightforward 2D system.
The 2D functionality will be described first as it provides a good introduction to the concepts used in the more complex 3D viewing and completes the description of the 2D functionality before tackling the 3D.
Viewing in PHIGS can be split into two separate sections. The first takes a PHIGS structure that is to be traversed and describes how it is to be mapped onto a device independent coordinate space called Normalized Projection Coordinates (NPC). PHIGS guarantees that it is possible to display on a device the part of NPC space in the range 0 to 1 in the X and Y -directions. The second section of viewing is to take the picture defined in NPC space and describe where it is to be positioned on the display of the device or on the sheet of paper.
In this Chapter, the first section of viewing will be described which produces the NPC picture. The term scene is used to describe the graphics produced by the structure traversal and picture to describe the parts of the scene, converted to NPC coordinates, that are available for display.
The viewing process which maps the scene to the picture has 4 main components:
- Partition by view index: the scene to be displayed may consist of a number of separate parts some of which may be magnified or have different viewing characteristics from the rest. PHIGS allows an attribute called the view index to be associated with the graphics primitives generated on structure traversal. This is used to differentiate the parts of a scene.
- Orientate the view: for each part of the scene differentiated by a view index, the application may redefine the origin and orientation of the world coordinate system. This new coordinate system is called the View Reference Coordinate (VRC) system. It should be defined such that it is the most appropriate for the view mapping.
- Map to NPC: define the window to viewport mapping that maps part of a scene defined by a specific view index from its description in VRC coordinates to one in NPC.
- Clip: decide whether the resulting NPC picture part should be clipped against a specified boundary defined in NPC coordinates. This can be distinct from the viewport used in the window to viewport mapping.
View indices in PHIGS playa similar role to Normalization Transformations in GKS. They give the application the ability to compose a picture in the NPC space out of a set of distinct parts. Similar to GKS, PHIGS has a default setting of view index which is 0 and the view associated with view index 0 cannot be changed. For view index 0, both orientation and mapping are identity matrices with clipping set at the boundary of the unit square. This is why the examples so far have all worked as long as the output has been constrained to the unit square in world coordinates. Effectively, WC, VRC and NPC are the same coordinate system. That is, the position (X,Y) in each coordinate system represents the same point in the graphics to be displayed. A major difference between the viewing function in GKS and PHIGS is that in PHIGS the mapping from world to NPC coordinates can be defined differently for each workstation.
6.3 VIEW INDEX
The view index attribute is defined by a structure element:
SET VIEW INDEX(I)
On traversal, all subsequent output primitives generated have view index I associated with them until the view index attribute is changed by another SET VIEW INDEX element. The current value of view index is stored in the traversal state list. The initial default value is 0. For example:
OPEN STRUCTURE(ENV) POLYLINE(5, XA, YA) SET VIEW INDEX(1) EXECUTE STRUCTURE(DESK) SET VIEW INDEX(2) EXECUTE STRUCTURE (DESK) CLOSE STRUCTURE
will, on traversal, define a polyline to be viewed using the default view 0 and two views of the same desk. How they will appear in the NPC picture will depend on the definition of the views set up for view index 1 and 2.
6.4 METRIC DESK
The desk defined previously could be redefined using a more realistic coordinate system, say metres:
SUBROUTINE DLARGE REAL XL(5), YL(5) DATA XL/0, 0, 2, 2, 0/ DATA YL/0, 1, 1, 0, 0/ POLYLINE(5, XL, YL) RETURN END
This defines a desk 2 metres long and 1 metre across with the origin at the bottom left corner.
The corner desk defined previously could also be redefined as:
SUBROUTINE DCORNR REAL XC(12), YC(12) REAL PI INTEGER I XC(1)=0 YC(1)=0 XC(2)=0 YC(2)=1 Pl=4*ATAN(1.0) DO 50 I=3,10 XC(I)=COS((11-I)*PI/18) YC(I)=SIN((11-I)*PI/18) 50 CONTINUE XC(11)=1 YC(11)=0 XC(12)=0 YC(12)=0 POLYL1NE(12, XC, YC) RETURN END
This is a desk with 1 metre radius. The complete desk could be defined by:
OPEN STRUCTURE(DESK) DLARGE MVRP(2, 0) DCORNR MVRP(2, -1) BUILD LOCAL TRANSFORMATION(0, 0, 0, 0, 0, 0.5, 1, ER, MT) SET LOCAL TRANSFORMATION(MT, PRE) DLARGE CLOSE STRUCTURE
The small desk has been defined as an asymmetrically scaled version of the large desk where the X-dimension has been halved giving a metre square desk.
The individual pieces of the desk have been defined in their own coordinate systems (modelling coordinates). On traversal, the complete desk produced is defined in World Coordinates (WC) which extends from 0 to 3 metres in the X-direction and -1 to 1 metres in the Y-direction as the origin is at the bottom left corner of the large desk. The various desk accessories could also be defined and scaled to fit on the desk as before.
6.5 VIEW ORIENTATION
View orientation is specified in PHIGS by a 3 Ã— 3 homogeneous matrix similar to the modelling transformations specified using BUILD TRANSFORMATION MATRIX. A special utility function is provided specifically to define the View orientation matrix:
EVALUATE VIEW ORIENTATION MATRIX (VRPX, VRPY, VUPDX, VUPDY, ER, VOM)
The aim of view orientation is to change the origin and orientation of the world coordinate scene to be viewed to one more appropriate for the mapping to NPC coordinates. The point (VRPX,VRPY) defines the new origin to be used and (VUPDX,VUPDY) is a vector from (VRPX,VRPY) that specifies the new Y-direction of the axes. The function builds the matrix VOM that performs this change of origin and orientation. The parameter ER is set to 0 if a matrix has been built successfully or to a non-zero error value otherwise.
In the example above, it may be desired to view the desk, which extends from 0 to 3 metres in the X-direction and -1 to 1 metres in the Y-direction, at an angle of rotation about the centre point. To do this conveniently would require the origin to be moved to the point (1.5, 0). By specifying the Y-axis as a vector from this point of dimension (1,1), this would define the Y-axis as being in the direction from (1.5, 0) to (2.5, 1). Effectively the desk is rotated by 45Â° anti-clockwise to the initial origin. Note that the up direction could equally well have been defined by the vector (2,2), the direction remains the same.
To produce the desired change of orientation requires:
EVALUATE VIEW ORIENTATION MATRIX(1.5, 0, 1, 1, ER, VOM)
A mistake often made is to take (VUPDX,VUPDY) to mean an absolute position rather than a vector direction.
Although changing the orientation angle is provided mainly to allow the viewing of 3D objects from different angles, it can be equally effective in the 2D area.
6.6 VIEW MAPPING
Once the view reference coordinates have been established, the mapping to NPC space needs to be defined. Again, a specific utility function is provided to construct the 3 Ã— 3 homogeneous view mapping matrix:
EVALUATE VIEW MAPPING MATRIX(WL, PVL, ER, VMM)
WL defines the X and Y-limits of an area in view reference coordinates (called the window) to be mapped onto the area defined by the X and Y-limits specified in PVL (called the viewport) in NPC coordinates. The limits are specified in the order XMIN, XMAX, YMIN, YMAX.
If the desk defined above has its origin moved to the middle, it will extend by 1.5 metres in the X or Y-direction depending on the orientation given. To map this onto the centre part of the NPC unit square would require:
WL(1)=-1.6 WL(2)= 1.6 WL(3)=-1.6 WL(4)= 1.6 PVL(1)=0.25 PVL(2)=0.75 PVL(3)=0.25 PVL(4)=0.75 EVALUATE VIEW MAPPING MATRIX(WL, PVL, ER, VMM)
As before, the required view mapping matrix is returned in VMM with ER set to 0 if successful otherwise a non-zero error value is returned.
6.7 VIEW DEFINITION AND CLIPPING
So far, the production of the two matrices that define view orientation and view mapping have been described. The definition of the view itself is given by:
SET VIEW REPRESENTATION(WS, VI, VOM, VMM, VC, XYC)
The workstation WS has the view transformation for view index VI defined by the two matrices YOM and VMM generated by the utility functions described above. The view representation is defined by this single function invocation to ensure that intermediate definitions cannot be produced with illegal transformations. As the view representation can be redefined while a structure is posted, the effect occurs as soon as is possible. All that remains is to describe the final two parameters which decide whether clipping should be applied and where.
The parameter VC defines that part of NPC space to clip against. Frequently, the values of the clipping limits VC and the viewport specified by PVL in the function EVALVATE VIEW MAPPING MATRIX are identical. However, this is not essential and in some applications it is necessary to separate the definition of the window/viewport mapping which defines the coordinate transformation from the clipping limits themselves. Although the parameter VC defines the clipping region, it does not specify that it is operative. The final parameter XYC can be set to CLIP or NOCLIP and specifies whether the clipping limits VC have any effect.
To clip the desk defined above so that only the part between 0.4 and 0.6 were visible would require:
VC(l)=0.4 VC(2)=0.6 VC(3)=0.4 VC(4)=0.6 XYC=CLIP SET VIEW REPRESENTATION(WS, VI, VOM, VMM, VC, XYC)
6.8 A COMPLETE EXAMPLE
Let us assume that the desk with its 3 parts has been defined in metres with all the accessories placed on it. Suppose a view of the complete desk is required at some angle of rotation and, at the same time, a detail of a part of the desk is required. To delineate the two views a boundary round each view is drawn. An example of the overall picture is shown in Figure 6.1. The desk has been displayed without rotation and the detail is of the phone on the left side of the corner desk.
Figure 6.1: Two views of desk
View index 0, the default view, could be used to specify the boundary around the two separate views of the desk:
REAL AX(8), AY(8) DATA AX /0.666, 0, 0, 0.666, 0.666, 1, 1, 0.666/ DATA AY /1, 1, 0.333, 0.333, 1, 1, 0.333, 0.333/ OPEN STRUCTURE(ENV) POLYLINE(8, XA, YA) SET VIEW INDEX(1) EXECUTE STRUCTURE(DESK) SET VIEW INDEX(2) EXECUTE STRUCTURE (DESK) CLOSE STRUCTURE
The polyline defines the two areas in NPC space as the square from (0,0.333) to (0.666,1) and the rectangle from (0.666,0.333) to (1,1). Before posting the structure ENV, the two views 1 and 2 need to be defined otherwise the default view which is the same as view 0 will be used:
EVALUATE VIEW ORIENTATION MATRIX(1.5, 0, VUPDX, VUPDY, ER, VOMI) WL1(1)=-1.6 WL1(2)= 1.6 WL1(3)=-1.6 WL1(4)= 1.6 PVL1(l)=0 PVL1(2)=0.666 PVL1(3)=0.333 PVL1(4)=1 EVALUATE VIEW MAPPING MATRIX(WL1, PVL1, ER, VMM1) VC1(1)=0 VC1(2)=0.666 VC1(3)=0.333 VC1(4)=1 XYC1=CLIP SET VIEW REPRESENTATION(WS, 1, VOM1, VMM1, VC1, XYC1)
This defines the first view in the left top square of the NPC space. The orientation of the desk will depend on the values of VUPDX and VUPDY. If VUPDX=0 and VUPDY=1, the desk will not be rotated. The clipping rectangle is initially defined so that the clipping boundary coincides with the limits of the viewport. As the window is defined greater than the boundary of the desk, all the desk should be visible in this viewport.
In the rectangular area to the right, a detail of the desk at normal orientation is to be displayed. The main item to be focussed on initially is the left telephone on the corner desk so the origin is placed at the bottom left of the corner desk and the orientation is with the Y-axis vertical:
EVALUATE VIEW ORIENTATION MATRIX(2, 0, 0, 1, ER, VOM2) WL2(1)=0 WL2(2)=0.5 WL2(3)=0 WL2(4)=H PVL2(1)=0.666 PVL2(2)=1 PVL2(3)=0.333 PVL2(4)=1 VC2(1)=0.666 VC2(2)=1 VC2(3)=0.333 VC2(4)=1 XYC2=CLIP SET VIEW REPRESENTATION(WS,2, VOM2, VMM2, VC2, XYC2) POST STRUCTURE(WS, ENV, 0.2)
With the value of H set to 1, the aspect ratio in the right area (1:2) is the same for both the window in view reference coordinates and the viewport in normalized projection coordinates giving a picture as in Figure 6.1.
Figure 6.2: Changed orientation in first view
If the values of (VUPDX, VUPDY) are set to (1,1), the orientation of the desk in view 1 would be rotated by 45Â° anti-clockwise. If the clipping limits for view 1 were reset to (0.1, 0.566, 0.433, 0.9), the result would be as in Figure 6.2. If H is changed to 0.5, the aspect ratio is changed in the viewing transformation giving the picture in Figure 6.3.
This type of display is often used in computer aided design when the operator requires to manipulate the complete scene while still having a detailed view of the particular part currently being defined. As will be seen in Chapter 10, it is possible for the application to allow the operator to interact with the display in either of the two regions.
Figure 6.3: Changing aspect ratio
This emphasizes the point that the viewing transformation can change the aspect ratio in the transformation from world coordinates to NPC coordinates and this can be set differently for each view.
Figure 6.4: Change rotation in first view
By changing (VUPDX,VUPDY) to (-1,1), the desk rotation is in the opposite direction in view 1 while retaining the same view in the right area (see Figure 6.4).
This shows the flexibility possible using multiple views in 2 dimensions. The potential uses in 3 dimensions are much greater as it is often only through multiple views that an impression of the scene can be obtained.