Unit – 4
Viewing pipeline
It is a term that describes a series of transformations.
The data that passed to end up image data being displayed on a device.
The viewing pipeline includes some coordinates as object coordinate, world coordinate, viewing coordinate, normalized coordinates, and device coordinates.
Object coordinate- an individual object that created by the coordinates
World coordinate- several objects into one scene
Viewing coordinate- the viewer after transformation into the coordinates system of the camera
Normalized coordinates- the projection onto a common plane that yields device-independent
Device coordinate- final mapping of normalized coordinates to a specific device
A window is a world-coordinated region that has been chosen for display. A viewport is the area on a display device to which a window is mapped. The window specifies what will be seen, while the viewport specifies where it will be presented. Rectangles in standard position, with the rectangle edges parallel to the coordinate axes, are frequently used for windows and viewports. Some applications employ other window or viewport geometries, such as general polygon shapes and circles, however these shapes take longer to analyze. A viewing transformation is the mapping of a portion of a world-coordinate scene to device coordinates in general.
The window-to-viewport transformation, often known as the windowing transformation, is a two-dimensional viewing transformation. However, watching entails more than just the transition from the window to the viewport in general. The mapping of a picture portion that falls within a rectangular window onto a defined angular viewport.
Key takeaway
It is a term that describes a series of transformations.
The data that passed to end up image data being displayed on a device.
We choose the window extends in viewing coordinates and selects the viewport limits in normalized coordinates once the item description has been delivered to the viewing reference frame.
The object descriptions are then converted to device coordinates that have been normalized:
We do this by employing a transformation that keeps an object's relative position in normalized space the same as it was in viewing coordinates.
If a coordinate position is in the viewing window's center:
It will appear in the viewport's center.
The mapping of the window to the viewport is shown in Figure. A point in the window at (xw, yw) is mapped to (xv, yv) in the related viewport.
Fig 1: Window to viewport mapping
To keep the point in the viewport in the same relative position as in the window, we need to do the following:
In order to solve these impressions for the viewport position (xv, yv), we have to first solve these impressions for the viewport position (xv, yv).
Xv=xvmin+(xw-xwmin)sx
Yv=yvmin+(yw-ywmin)sy ...........equation 2
Where scaling factors are
Equations (1) and (2) can alternatively be obtained by using a set of transformations to convert the window or world coordinate area to the viewport or screen coordinate area. This dialogue is carried out using the following transformations:
● Scale the window area to the size of the viewport with a scaling transformation using a fixed point position (xwmin,ywmin).
● Translate the scaled window area to the viewport's position. If the scaling factors are the same (sx=sy), the relative proportions of items are maintained.
Object descriptions are mapped to the various display devices using normalized coordinates.
We can open any number of output devices in a single program, and we can perform three windows to viewport transformations for each open output device.
Workstation transformation is the name for this mapping (It is accomplished by selecting a window area in normalized space and a viewport area in the coordinates of the display device).
Workstation transformation to split a view such that different regions of normalized space can be displayed on different output devices, as seen in the figure).
Fig 2: Mapping selected parts of a scene in normalized coordinates to different video monitors with workstation transformation
A clipping algorithm, or simply clipping, is a method that detects those sections of a picture that are either inside or outside of a specific region of space. A clip window is the area against which an object will be clipped.
Clipping can be used to extract a portion of a defined scene for viewing, identify visible surfaces in three-dimensionala1 views, antialias line segments or object boundaries, create objects using solid-modeling procedures, display a multi window environment, and perform drawing and painting operations that allow parts of a picture to be selected for copying, moving, erasing, or duplicating. The clip window can be a general polygon or possibly have curved boundaries, depending on the application. The methods for clipping rectangular clip regions are discussed first, followed by methods for different clip-region forms. -
Only those picture parts that are within the window area should be displayed during the viewing transition (assuming that the clipping flags have not been set to noclip). Outside the window, everything is thrown away. Only the contents of the window interior are transferred to device coordinates using clipping methods in world coordinates. Alternatively, the entire world-coordinate picture can be first translated to device coordinates, or normalized device coordinates, and then cropped to viewport bounds. Clipping world coordinates removes primitives outside the window from consideration, removing the computation required to convert those primitives to device space.
By permitting the concatenation of viewing and geometric transformation matrices, viewport clipping can simplify calculations. However, viewport clipping necessitates that all objects, including those outside the window region, be transformed to device coordinates. Clipping techniques are frequently coupled with scan conversion on raster systems.
In the sections that follow, we'll look into clipping methods for the primitive types listed below.
● Point Clipping
● Line clipping (straight-line segments)
● Area clipping (polygons)
● Curve Clipping
● Text Clipping
The clipping of point from the window is very easier than line and polygon clipping.
Following figure shows the point (x,y) is given on the window representing as rectangle.
To clip a point use maximum and minimum coordinates of the window.
If X- coordinate of point lies in between Wx1 and Wx2 i.e. Wx1<= X <= Wx2 then X coordinate lies inside the window.
If Y- coordinate of point lies in between Wy1 and Wy2 i.e. Wy1<= Y <= Wy2 then Y coordinate lies inside the window.
Key takeaway
The clipping of point from the window is very easier than line and polygon clipping.
Cohen Sutherland Method of Line Clipping
The line clipping is same as the point clipping method.
The line that is outside the window is cut and the line which is inside the window that will be displayed.
This algorithm uses the line clipping method.
The minimum coordinates for the clipping region is (XWmin, YWmin) and the maximum coordinates are (XWmax, YWmax).
As below figure 3 shows the concept of cohen Sutherland line clipping.
Fig. No. 3
There are three possibilities for line as-
● The line which is completely inside the window will be accepted.
● The line which is completely outside the window will be discarded.
● The line which is partially inside the window in that the portion which is inside that will be shown and other part will be discarded.
The 4 bits are used to divide the entire region.
These 4 bits represent the top, bottom, top and left as the figure shows.
Fig. No. 4
Following are steps to perform the cohen Sutherland algorithm which are based on 4 bits that are given above.
- Assign a region code for each end points.
- If both endpoints having bits 0000 then that line will be accepted.
- Else perform logical AND operation on the region code.
- If the result is not 0000 then reject line.
- Else need clipping process
- Choose an endpoint of the line that is outside the window.
- Find the intersection point at the window boundary.
- Replace the endpoints with that intersection points and update the region code.
- Repeat step 2 until we get the clipped line either trivially accepted or trivially rejected.
Repeat step 1 for other lines.
Key takeaway
The line clipping is same as the point clipping method.
The line that is outside the window is cut and the line which is inside the window that will be displayed.
● Accept/Reject test
– Does the bounding box of the circle intersect with the clipping box?
● If yes, condition pixel
Write on the clipping box inside/outside the test,
Also we can test Circle points by Point Clipping.
- the point P=(x, y) is displayed in the clipping Boundary if
Xmin< x <xmax and ymin<y<ymax
A polygon is a surface representation. It is basic in nature and is closed. It is made up of a series of lines. It's also known as a multi-sided figure. Sides or edges are the lines that make up a polygon. Two vertices are combined to form the lines.
Example
● Triangle
● Rectangle
● Hexagon
● Pentagon
Some polygons are shown in the figures below.
Fig 5: Example of polygon
Types of Polygons
● Concave
● Convex
When a line connecting any two inside points of a polygon lies inside the polygon, it is considered convex. Concave describes a non-convex polygon. One interior angle of a concave polygon is more than 180°. So that it can be cut into polygons that are comparable.
Fig 6: Convex polygon
Fig 7: Concave polygon
A polygon can be orientated in either a positive or negative direction. The orientation is considered to be positive if we visit vertices and the vertices visit generates a counter clockwise circuit.
Fig 8: Polygon with positive orientation
Fig 9: Polygon with negative orientation
Ellipse
Ellipse is defined as the locus of a point in a plane that moves in such a way that the ratio of its distance from a fixed point called focus in the same plane to its distance from a fixed straight line called directrix is always constant and less than unity.
The general equation of the ellipse can be expressed as d1+d2=constant if the distance between the two foci from any point P=(x,y) on the ellipse is labeled d1 and d2.
We have the following formula for expressing the distances d1 and d2 in terms of focal coordinates F1 and F2:
Ax2+By2+Cxy+Dx+Ey+F=0 where A, B, C, D,E, and F are evaluated in terms of focal coordinates and dimensions of the major and minor axes of the ellipse.
Midpoint ellipse algorithm
The midpoint ellipse approach is used in two sections during the first quarter. Let's start at (0,ry) and work our way around the ellipse path in clockwise order in the first quadrant.
The ellipse function is defined as follows:
fellipse(x,y)=ry2x2+rx2y2-rx2ry2
The following are some of the properties that have been generated as a result of this:
● fellipse(x,y)<0 which means (x,y) is inside the ellipse boundary.
● fellipse(x,y)>0 which means (x,y) is outside the ellipse boundary.
● fellipse(x,y)=0 which means (x,y) is on the ellipse boundary.
Initial decision parameter
Starting position = in area 1 yields the beginning value of a decision parameter (0,ry).
i.e. p10=ry2+1/4rx2-rx2ry
The initial position in region 2 is obtained from the last position selected in region 1, and the first decision parameter in region 2 is:
p20=ry2(x0+1/2)2+rx2(y0-1)2-rx2ry2
ALGORITHM
- Take the input and ellipse centre and obtain the first point on an ellipse centered on the origin as a (x,y0)= (0,ry).
- Now calculate the initial decision parameter in region 1 as:
p10=ry2+1/4rx2-rx2ry - At each xk position in region 1 perform the following task. If p1k<0 then the next point along the ellipse centered on (0,0) is (xk+1,yk).
i.e. p1k+1=p1k+2ry2xk+1+ry2
Otherwise the next point along the circle is (xk+1,yk -1)
i.e. p1k+1=p1k+2ry2xk+1 – 2rx2yk+1+ry2
4. Now, again calculate the initial value in region 2 using the last point (x0,y0) calculated in a region 1 as : p20=ry2(x0+1/2)2+rx2(y0-1)2-rx2ry2
5. At each yk position in region 2 starting at k =0 perform the following task. If p2k<0 the next point along the ellipse centered on (0,0) is (xk , yk-1)
i.e. p2k+1=p2k-2rx2yk+1+rx2
Otherwise the next point along the circle will be (xk+1,yk -1)
i.e. p2k+1 =p2k+2ry2xk+1 -2rx2yk+1+rx2
6. Now determine the symmetric points in another three quadrants.
7. Plot the coordinate value as: x=x+xc , y=y+yc
8. Repeat the steps for region 1 until 2ry2x>=2rx2y.
Key takeaway
A polygon is a surface representation. It is basic in nature and is closed. It is made up of a series of lines.
Ellipse is defined as the locus of a point in a plane that moves in such a way that the ratio of its distance from a fixed point called focus in the same plane to its distance from a fixed straight line called directrix is always constant and less than unity.
References:
- Foley J.D., Van Dam A, "Fundamentals of Interactive Computer Graphics", Addison Wesley, 1990
- Donald Hearn and Pauline Baker Computer Graphics, Prentice Hall, New Delhi, 2012
- Steven Harrington, "Computer Graphics- A programming approach", McGraw 3. Hill, 2nd Edition, 1987.
- Https://www.includehelp.com/basics/ellipse-algorithm.aspx
- Https://www.javatpoint.com/computer-graphics-clipping