8 2D Viewing

T. Raghuveera

epgp books

 

 

 

Objectives:

  • Understand 2D viewing pipeline
  • Learn how to perform, window-viewport transformations
  • Understand the theory behind clipping in 2D with focus on Point Clipping.

 

Discussion:

 

2D Viewing Pipeline:

 

Let’s start our discussion with 2D viewing pipeline. This involves a series of transformations performed, right from creation, till the object is finally seen or displayed at a position or a viewing region on a display device like monitor. Each transformation step performed converts data from one coordinate system to the other. From the figure below (Recollect discussion from the first module),

 

 

 

The sequence of steps in the 2D viewing Pipeline are

 

MC -> WC->VC-> CC->NVC-> DC

where

MC – Modeling Coordinates (Modeling or Local Coordinate system)

WC – World coordinates (World Coordinate system)

VC – viewing coordinates (Viewing coordinate system)

CC – Clipping coordinates (Viewing coordinate system)

NVC – Normalized viewing or device independent coordinates (Viewing coordinate system, but normalized)

DC – Device coordinates (Device coordinate system specific to every device)

 

For conversion from MC to WC we perform a transformation called Modeling Transformation (MT), from WC to VC we perform Viewing Transformation (VT), From VC to NVC we perform window-viewport transformation (WV), From NVC to DC we perform Device coordinate system transformation (DT). When the object is first created it assumes MC and a Modeling Transformation is applied to convert to WC, which is in the world coordinate system. Then a viewing coordinate system is set up and data is now converted from WC to VC (recall discussion from the previous module on transformation between coordinate systems). Later VC are sent for clipping, depending on the window or region of interest, to get CC. In many graphics packages, Viewing and Clipping steps are combined to get clipped coordinates straight from world coordinates. Next the CC are converted to NVC, where we simply normalize data in a step called window-Viewport transformation. This step is performed to ensure that the data should be independent of the end display device so that the data can be conveniently mapped to any display device of choice. If this is not done we need to perform a separate transformation for each display device, which is a cumbersome task. Each kind of coordinates belong to a specific coordinate system or reference frame.

 

Window-Viewport Transformation:

 

In Computer Graphics terminology, a window is a rectangular region of interest, and a viewport is a display area chosen on the monitor screen for viewing the contents of the window. In short, window is ‘what we want to see’ and viewport is ‘where we want to see’. As shown in the figure below, we can define a rectangular region in the world coordinate system, and call that as window. The contents of the window are to be mapped to a region or a display area chosen as viewport. In a way this is, mapping contents between two rectangular regions of different dimensions. Window is generally defined in the world coordinate system, while viewport is defined in the end device coordinate system. Since we wish to convert data to device independent or normalized coordinates, we perform window-viewport transformation. So in window-viewport transformation contents of the window are mapped to normalized coordinates (coordinates between 0 and 1).

 

 

For simplicity, both window and viewport are chosen to be rectangular in shape whose boundaries are aligned with the coordinate axes. Because the dimensions of window and viewport are different, we will be performing a scaling like operation. If the window is bigger in size than the viewport, we perform a scale down operation and vice-versa. As you can notice from the figure above, the boundaries of the window and viewport are defined by four infinitely extending lines parallel to the coordinate axes. The window boundaries are defined by the four lines, xwmin, xwmax, ywmin, yWmax. Where xwmin, xwmax define the two vertical boundaries, while, ywmin and ywmax define the two horizontal boundaries of the window. Similarly the viewport boundaries are defined by four infinitely extending lines, xvmin, xvmax, yvmin, yvmax.

 

Now for a point (xw,yw) in the window, we have to identify an equivalent point in the viewport, say (xv,yv). i.e., for every point in the window, there is an equivalent point in the viewport. The four corner vertices of the window have got their equivalent vertex points in the viewport, which are nothing but the four corner points of the viewport. For the point (xwmin, ywmin) in the window, the equivalent point in the viewport is (xvmin, yvmin) and so on.

 

 

For any general point in the window, how do we find an equivalent point in the viewport? As we can see, from the figures above, the percentage horizontal distance of the point in the window from its left boundary, should be exactly equal to the percentage horizontal distance of the equivalent point in the viewport from its left boundary. We can apply the same analogy to the vertical distance of the point from its bottom boundary.

 

Here sy is a ratio and is also the scaling factor along y-direction. If the vertical boundary of the window is larger than that of the viewport then sy <1 (down scaling), otherwise sy >1 (up scaling). If both the boundaries are of same lengths then sy=1 (no scaling).

 

It is important to note that the transformation, converts real coordinates to normalized coordinates, which are device independent. Later the device independent coordinates are converted to appropriate screen coordinates as shown in the figure below.

 

 

 

Example:

 

Problem: For a point (1, 2) in the window, find the equivalent point in the viewport. Assume window at [(1,1) and (4,4)] and viewport at [(-1, -1) and (1,1)].

 

Sol:

 

The point (1, 2) is identified as (xw, yw) respectively. The aim is to compute the equivalent point (xv,yv).

 

xwmin=1, xwmax=5, ywmin=1, ywmax=5,

xvmin=-1, xvmax=1, yvmin=-1, yvmax=1,

Now compute  s   using the relation derived above

 

 

2D Clipping Algorithm:

 

In 2D clipping, we choose a rectangular region of interest in the world coordinate system and call that as window or clip window or clip rectangle. The contents inside the window are of interest to us and so to be clipped. So here clipping means select the contents that are inside the clip window region. It is cumbersome and less efficient to consider performing transformations on the regions that are not of interest to us, instead we can consider the inside of the clip window and perform any transformations on that. Thus clipping is ‘selecting what is of interest to us’ and not discarding what is not of interest to us’.

 

For better understanding and simplicity we choose the clip rectangle to be aligned such that its sides are parallel to the coordinate axes. In the most general case we can choose the clip rectangle to be oriented in any direction in 2D space. In the extreme case, the shape of the clip window region need not be rectangular, instead, it can be of any shape of choice.

 

The region against which the contents are clipped is called ‘clip window’. Any procedure that identifies those portions of a picture that are either inside or outside of a specified region of space is considered as the ‘clipping algorithm’. Usually a clipping region is a rectangle in standard position. These boundary edges typically correspond to a normalized square in which the x and y values range either from 0 to 1 or from -1 to 1.

 

Clipping transformation can be performed either in the world coordinate system or in the viewport coordinate system. Clipping in the World coordinate system involves selecting the contents inside the clip window region and apply transformations only on them. In viewport clipping, the whole of the contents from the world are brought to the viewport and then clipping against the viewport. It is thus more convenient to perform clipping in the world coordinate system.

 

The types of clipping that we are going to learn are

  • Point clipping
  • Line clipping
  • Polygon Clipping
  • Text Clipping

 

Point Clipping:

 

In point clipping, points that are inside the rectangular region are selected for display and points that are outside the region are discarded. Now the question is, how do we know whether a point is inside or outside a given rectangular region? For this we should perform a test as shown.

 

From the above two equations we can infer that if x and y satisfy the above equations, the point is an inside point, so can be selected for display, otherwise it is an outside point so can be discarded. In the above two equations, there are 4 inequalities,

 

 

 

Summary:

  • Understood the steps in 2D viewing pipeline
  • Learnt about window-viewport transformation
  • Also learnt the idea behind clipping, and in particular point clipping
you can view video on 2D Viewing