0% found this document useful (0 votes)
135 views21 pages

Segmented Display File Overview

Clipping

Uploaded by

kk2430669
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
135 views21 pages

Segmented Display File Overview

Clipping

Uploaded by

kk2430669
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

lOMoARcPSD|59599391

3. Unit III Segmented Display File

Bachelor of computer application (Swami Ramanand Teerth Marathwada University)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by MANOJ KHARDE (khardemr@[Link])
lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

UNIT III

Segmented Display Files and Clippeing and


Windowing

Contents:
3.1) SEGMENT TABLE:- .................................................................................................................. 2
3.2) FUNCTIONS FOR SEGMENTING DISPLAY FILE ................................................................ 4
1) Create segment:- ......................................................................................................................... 4
2) Close segment:- .......................................................................................................................... 5
3) Delete segment:- ......................................................................................................................... 5
4) Rename segment:- ...................................................................................................................... 5
3.3) POSTING AND UNPOSTING SEGMENT ............................................................................... 6
3.4) SEGMENT NAMING SCHEME:- ............................................................................................ 7
3.5) DEFAULT ERROR CONDITION ............................................................................................. 8
1) Opensegment(n):- ....................................................................................................................... 8
2) Closesegment(n):- ....................................................................................................................... 8
.3) Deletesegment(n):- .................................................................................................................... 8
4) Postsegment(n):- ......................................................................................................................... 8
4.5.5) Unpostedsegment(n):- .......................................................................................................... 8
3.6) APPENDING TO SEGMENT .................................................................................................... 8
3.7) Viewing Transformtion ...................................... Error! Bookmark not defined.
3.8) 2-D Clipping ........................................................................................................ 11
3.9) Simple Visibility Algorithm ................................................................................ 12
3.10) End Point Codet................................................................................................. 13
3.11) Midpoint Subdivision algorithm ....................................................................... 15
3.12) Polygon clipping algorithm (Sutherland-Hodgman algorithm ) ............. 1Error!
Bookmark not defined.

By: Saudagar Asif 1 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

3.1) SEGMENT TABLE:-

Segment is a part or unit of picture that is named for modification purpose.

Segment is a unit of display file to use the segment we must know display file is
used for representation of picture on screen and segment is a part of display file.

The segment is a logical unit it may be continuous or not continuous area of display
or on the screen.

It is a simply a collection of display file instruction which represents a part of


graphics that can manipulate as a single unit.

1) Segment are used to define and modify the picture in a set of sub pictures.
2) Segment is a output primitive or operations that are joined for modification
purpose.

Segments are interlinked with one another in segmented display file.

Graphics program generates output in a segmented display file then display


processor read the input and stored in refresh display file then finally display
controller displays the output on screen as shown below:

Segments are created in program using the following format.

By: Saudagar Asif 2 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

Segment format:

Segment Name

Visibility pointer field

Next pointer segment


Field To next segment

 Segment parameters


 Output primitives

End of segment
pointer field

Fig:- Segment format


Segment parameters are the parameters passed to the segment output primitive are
output specification of segment.

Next pointer field indicates the address of next segment visibility pointer field
indicates visible area of segment.

By: Saudagar Asif 3 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

3.2) FUNCTIONS FOR SEGMENTING DISPLAY FILE

Generally the graphics program generates the graphics output in a display file instead
of displaying directly on the screen.

The display controller card available in system display the content of display file on
screen.

Segmenting the display file means creating the part of display file for displaying
changing & modifying the graphics on screen when program is in running mode.

Creating dynamic graphics we can create the segment or parts of program of set of functions for
display file manipulation.

The common method of creating and modifying sequential disk file is to open a file
before we add data to it and close the file when we have added the last data item and
the file is complete.

To change the content of file we open it again add the new data to replace the old
and close the new file.

The every same operation can be used for manipulating display file segment.

To create a new segment we open it and then use the graphics functions to add line,
circle, rectangle and text etc. The segment to be displayed then we close the
segment.

We have four basic functions for segments.

1) Create segment
2) Close segment
3) Delete segment
4) Rename segment

1) Create segment:-

In segment creation process, initially we have to check weather some other segment
is still open.

It is not allow to open two segment at a same time. Because it is difficult to assign
the drawing instruction to particular segment.

By: Saudagar Asif 4 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

Segment must be created and opened when no other segment is currently open.

We must give segment name and check it is valid or not.

To initialize the instructions of a segment located at next free storage area.

We have not entered any instructions into the segment it`s size is initialized with
zero and attribute of the segment are initialize as a default value.

2) Close segment:-

Once a segment is open, We can enter the display file instructions in it.

After completion of entering all instruction, The segment must be closed.


To close segment it is necessary to change the name of the currently open segment
say zero that is unnamed segment.

If there are two unnamed segment in the display file; one has to be deleted.

3) Delete segment:-

When we want to delete a particular segment from the display file. Then we must
recover the storage space and make this space free for some other segment use of
array`s makes the recovery of the storage space accupies by the segment.

EX:- Deletesegment(T);
Where, T is the segment name.

4) Rename segment:-

Renaming segment we can display new image in the sequence.

We have to delete current segment and recreate it with the altered characters.

This process is complex so we can avoid this problem by keeping the next image
ready in the display file before deleting the current segment.

EX:-Renamesegment(T);

By: Saudagar Asif 5 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

3.3) POSTING AND UNPOSTING SEGMENT

We can extend the unusefulness of our graphics package consider by allowing


segments to become temporarily invisible for this we need two additional functions.

Posting is a action of including a segment in the display refresh cycle thus posting
makes segment visible.

Unposting removes the segment from the refresh cycle, so that it is no longer visible.

These segment is not destroyed by unposting and so it can be visible again without
predefining it simply by posting it .

The two functions to achieve this affect are:-


1) Postsegment(n) // Add segment n
2) Unpostsegment(n) // Remove segment n

By conversion we assume that new segment is in the unposted state immediately


after they have been defined and closed. Thus a segment call is always necessary
before a segment become a visible.

Posting and unposting are particularly useful in avoiding the need for repeatedly
redefining graphics edges, commands, menus and other segment that are removed
only temporarily from the screen.

3.4) SEGMENT NAMING SCHEME:-

The most common scheme for naming segment is to provide each segment with
unique integer name.

Normally text strings are more popular as names but if we assign integer names to
segment in a program then we can easily manipulate the segment.

Segment names are used only within the program.

Integer names are more useful and easy to remember than string names and more
easily manipulated than string.

Integer names are more convenient for making relation with segment.

By: Saudagar Asif 6 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

Integer names are more easily manipulated when storing a segment into data
structure like array.

Suppose there are so many segments in the program we have created, internally all
these segment will be stored in array.

Then for accessing any segment from the array we can use the index as a segment
name as follows:

Segment list Segment 1

Segment 2

Fig:- List structure representation of segment

In this way we can easily determine the names of segment.

3.5) DEFAULT ERROR CONDITION

While creating and using the segment in a program we can make one or more
programming displays with the five functions:-

1) Opensegment:
2) Closesegment:
3) Deletesegment:
4) Postsegment:
5) Unpostsegment:

By issuing functions calls in wrong order.

For e.g:-1) We can forgot to close segment and then they try to open another. or
By: Saudagar Asif 7 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

2) We can try to delete a segment which is not present. or


3) We can try to close a segment which is not present.

There are several solutions to the class If problem we can simply display an error
message.

We can handle this error message using following ways:


1) Opensegment(n):-

Any currently open segment is closed then we can open a new segmet.

2) Closesegment(n):-

If no segment is currently open , no effect.

.3) Deletesegment(n):-

Any currently open segment is closed if segment n doesnot exist no further effect.

4) Postsegment(n):-

Any currently open segment is closed if segment n is non existent or already posted,
no effect.

5) Unpostedsegment(n):-

Any currently open segment is closed if segment n is nonexistent or already


unposted, no effect.

These default actions take case of the more common mistake of error.

3.6) APPENDING TO SEGMENT

Adding a new drawing or picture to the existing segment is called Appending to


segment.

By adding new drawing to existing segment we can change the picture at run time.

By: Saudagar Asif 8 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

For e.g:- A program to display the result of two concurrent processes in the form of
two graphs plotted on the same axes as shown in following figure:-

x
0

Fig:-Plotting the result of two concurrent processes.

Every two minute each process generates a new data point and the graphs are
extended.

One method of writing such program would be to create a new segment for each
addition made to be either graph.

This would be a time consuming on the other hand any alternative approach such as
the use of the single statement for each graph could involve reconstructing the entire
segment after every step.

In this situation like this a function is appends.

Appendsegment(n)

Open segment n for additions keeping it`s present content as it.

Append to segment function it is used to writing such applications programs.

By: Saudagar Asif 9 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

3.8) 2D Clipping:

Removing the portion outside the window area or window region is called
clipping.
For getting the portion of any picture we need to clip the picture, means we
need to remove the unwanted part of picture.
For removing any unwanted part we have first specify the window or define
the window.
Many application programs such as Adobe Photoshop, MS-Word provide the
facility of removing the unwanted part from picture or drawing.
For writing such application program of our own we need to understand the
clipping procedure.
Window: A world-coordinate area selected for display is called a window.
Viewport: An area on a display device to which a window is mapped is called a
viewport.
The window defines what is to be viewed; the viewport defines where it is to be
displayed.
Clipping: Removing the portion outside the window area is called clipping.
To understand clipping first we start from point clipping
How the points are clipped that you can understand using following fig:

In the above figure the points P1 & P2 are inside the window that is defined & point
p3 and p4 are outside the window.
When we perform the clipping operation only points with in the window will be
visible as shown in following fig

By: Saudagar Asif 10 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

Line Clipping:
Line clipping is an operation through which, the unwanted portion of line is
removed.
To understand the line clipping consider the following figure.

In the above figure the Line P1 & P2 is inside the window & lines p3 to p4 and p6 to
p7 is partially in window and p8 to p9 is totally outside the window.
When we perform the clipping operation only lines with in the window will be
visible as shown in following fig

By: Saudagar Asif 11 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

3.9) SIMPLE VISIBILITY ALGORITHM:


This algorithm is used to identify weather the line is visible in windows area or
partially visible or not visible.
If both end points of the lines are inside in windows area then the line is totally
visible.
If both end points of the lines are in outside the windows area then the line is
totally not visible.
And if one end points of the line is inside the windows area and another end point is
outside the windows area then the line is partially visible.

In the above figure line p1 to p2 is totally visible line and line p3 to p4 and p6 to p7
is partially visible lines and line p8 to p9 is totally not visible line.
If p1 & p2 are the two end points of the line then the algorithms for identifying
visible, not visible & partially visible lines is:

Simple Visibility Algorithm:


1. Consider p1(x1, y1) and p2(x2, y2) are the end points of the line.
2. If both end points are left, right, bottom or top side of the window then the line is
not visible.
3. Consider WL (Window Left), WR (Window Right), WB (Window Bottom) and
WT (Window Top) are the four points of window that is defined.
4. Visibility =true // initializes variable to check visibility.

5. If (x1<WL and x2<WL) then Visibility=False


6. If (x1<WR and x2>WR) then Visibility=False
7. If (y1>WT and y2>WT) then Visibility=False
8. If (y1<WB and y2<WB) then Visibility=False

9. If (x1<WL and x1>WR) then Visibility=Partial


10. If (x2<WL and x2>WR) then Visibility=Partial
11. If (y1>WB and y1>WT) then Visibility=Partial
12. If (y2<WB and y2>WT) then Visibility=Partial
13. If (Visibility=Partial) then
14. Print Line is partially visible.
By: Saudagar Asif 12 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

15. If (Visibility=False) then


16. Print Line is not visible.

17. If (Visibility=True) then


18. Print Line is visible.

3.10) END POINT CODE:


For line clipping we need to identify both end points of lines are in window area or
outside the window area, or weather one end point is inside the window area & other
is outside the window area.
To check this we need to write conditions such as
If(x1>wx1 && y1>wy1 && x2<wx2 && y2<wy2) then
// Line is visible
End if
Where (wx1, wy1) & (wx2, wy2) are the two point which represents window area.
And (x1, y1) & (x2, y2) represents the two end points of lines.
But writing such condition are not convenient & very time consuming.
For providing solution for this they have invented end point codes.

End Point Code is four digit binary codes.


Initially, every line endpoint is assigned a four digit binary value called a region
code or end point code, and each bit is used to indicate whether the point is inside or
outside one of the clipping window boundaries.
In a four bit end points code
i. First bit is 1 if the line endpoints are on exactly left side.
ii. Second bit is 1 if the line endpoints are on exactly right side.
iii. Third bit is 1 if the line endpoints are on exactly bottom side.
iv. Fourth bit is 1 if the line endpoints are on exactly top side.
This is shown as follows

And all other bits are zero.


•The four window borders create nine Regions
•The Figure below lists the value for the binary code in each of these regions.

By: Saudagar Asif 13 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

Thus, an endpoint that is below and to the left of the clipping window is assigned the
region (0101).
The region code for any endpoint inside the clipping window is (0000).
1. A value of 1 (true) in any bit position indicate that the endpoint is outsides of
that border.
2. A value of 0 (false) indicates that the endpoint is inside or on that border.

Every end-point of line is labeled with the appropriate region code as shown in
following fig.

By: Saudagar Asif 14 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

Lines completely contained within the window boundaries have region code [0000]
for both end-points so are not clipped
Any lines with 1 in the same bit position for both end-points are completely outside
and must be clipped.
For example a line with 1010 code for one endpoint and 0010 for the other (line P11,
P12) is completely to the right of the clipping window.
•We can perform inside/outside test for lines using logical operators.
•When the OR operation between two endpoint codes is false (0000), the line is
inside the clipping window, and we save it.
•When the AND operation between two endpoint codes is true (not 0000), the line is
completely outside the clipping window, and we can eliminate it.

3.11) MIDPOINT SUBDIVISION ALGORITHM:


Midpoint subdivision algorithm is used to find visible area of line on clipping
window (clipping window is that portion of picture or image that we want to view).
This method is based on bisection method i.e we calculate mid value of a line by
adding end points of line and then dividing that line by 2.
Steps:
1. If the end points are visible as shown in following fig. means two end points are
in window area then there is no need to calculate the midpoint of line for
clipping line. The process is complete.

2. If the end point are not visible. Means two end points are completely outside
the windows area as shown in following fig. then we simple ignore the line.
The process is complete.

By: Saudagar Asif 15 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

3. If one end point of line in outside the window & one is inside the window or
both the end point are outside the window area but line is passing through
window area as shown in fig. then we have to calculate midpoint.

4. Suppose p1(x1, y1) and p2(x2, y2) are points of line p1 and p2 then mid
value is:
Pm = xm = (x1+x2)/2 and ym = (y1+y2)/2
So new line is p1 pm and pm p2.
5. Again we check if their end points are in visible area of clipping window. If
not we further divide p1 pm into two line segments i.e. p1 pm1 and pm1 pm

6. This procedure will continue until all part of line are either visible or
invisible totally

By: Saudagar Asif 16 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

7. If any part of line is partially visible then we continue with process again

Example:
A Clipping window ABCD is specified as A (100,100), B(300,100) ,C (300,300) and
D(100,300) using midpoint subdivision algorithm find the visible portion of the line
with points p1(50,200) and p2(250,200)
Solution
Using the above points the window & line will look like as shown in fig.

Line is partially visible. We need to calculate the midpoint.


Then : pm= xm=(x1+x2) /2 =(50+250)/2=150
ym=(y1+y2) /2 =(200+200)/2=200
Here xm is not equal to 100 because window start from 100. Then save the p2 as old
p2
Replace p2 as pm because pm is greater than 100
Then :
p1(50,200) & new p2(150,200)
Then :
pm= xm=(x1+x2) /2 =(50+150)/2=100
ym=(y1+y2) /2 =(200+200)/2=200

Here xm is equal to 100 because window starts from this. We can consider this point
for clipping lines means new p1 of line will be (100,200) and p2 (250,200).

After this if we redraw the clipped line, line will be displayed as shown in fig:

By: Saudagar Asif 17 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

3.12) POLYGON CLIPPING ALGORITHM (SUTHERLAND-HODGMAN


ALGORITHM):
Polygon is an object having closed outlines bounded by straight edges.
An example of polygon clipping is shown below.

It uses a divide and conquers strategy. It solves a series of simple and identical
problems that, when combined, solve the entire problem. The simple problem is
to clip a polygon against a single infinite clip edge. Four clip edges, each defining
one boundary of the clip rectangle successively clip a polygon against a clip
rectangle.
A technique for clipping areas developed by Sutherland & Hodgman
By: Saudagar Asif 18 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

Put simply the polygon is clipped by comparing it against each boundary in turn

There are four possible cases when processing vertices in sequence around the
perimeter of a polygon. As each pair of adjacent polygon vertices is passed to a
window boundary clipper, we make the following tests:
(1) If the first vertex is outside the window boundary and the second vertex is
inside, both the intersection point of the polygon edge with the
window boundary and the second vertex are added to the output vertex list.

(2) If both input vertices are inside the window boundary, only the second
vertex is added to the output vertex list.

(3) If the first vertex is inside the window boundary and the second vertex is
outside, only the edge intersection with the window boundary is added to the
output vertex list.

By: Saudagar Asif 19 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])


lOMoARcPSD|59599391

Class: BCASY(Sem IV) COCSIT, Latur Sub: Computer Graphics

(4) If both input vertices are outside the window boundary, nothing is added to
the output list.

By: Saudagar Asif 20 / 20

Downloaded by MANOJ KHARDE (khardemr@[Link])

You might also like