0% found this document useful (0 votes)
2K views51 pages

Segment and Window Clipping

Unit 4 discusses segments, windowing, and clipping in computer graphics. [1] A segment is the smallest displayable area defined by two points. Segments allow subdivision, scaling, rotation, and translation of images on a display. [2] Windowing allows viewing a portion of an image by defining a "window" that clips out the area of interest. The window is mapped to a viewport on the display. [3] Viewing transformations map parts of a scene from world coordinates to normalized device coordinates for display, applying windowing, clipping, and viewport mapping.

Uploaded by

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

Segment and Window Clipping

Unit 4 discusses segments, windowing, and clipping in computer graphics. [1] A segment is the smallest displayable area defined by two points. Segments allow subdivision, scaling, rotation, and translation of images on a display. [2] Windowing allows viewing a portion of an image by defining a "window" that clips out the area of interest. The window is mapped to a viewport on the display. [3] Viewing transformations map parts of a scene from world coordinates to normalized device coordinates for display, applying windowing, clipping, and viewport mapping.

Uploaded by

Yogita Ghumare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 51

Unit 4

SEGMENTS, WINDOWING AND


CLIPPING
Segment

• A Segment in graphics: A segment in graphics is defined as


the smallest possible area in two points. A Segment in
the computer graphics: It is located in the form of the array
like a table that keeps the commands in a way to display it at
the screen. It has 4 parts.
• Segments in Computer Graphics
• To view an entire image or a part of image with various
attributes, we need to organize image information in a
particular manner since existing structure of display file does
not satisfy our requirements of viewing an image. To achieve
this display, file is divided into Segments. Each segment
corresponds to a component and is associated with a set of
attributes and image transformation parameters like scaling,
rotation. Presence of Segment allows :
Cont..

• Subdivision of picture.
• Visualization of particular part of picture.
• Scaling, rotation and translation of picture.
Cont..

• Posted Segment : When visible attribute of segment is set to


1, it is called Posted segment. This is included in active
segment list.
• Unposted Segment : When visible attribute of segment is set
to 0, it is called Unposted segment. This is not included in
active segment list.
• Functions for Segmenting the display :
1. Segment Creation : Segment must be created or opened
when no other segment is open, since two segments can’t be
opened at the same time because it’s difficult to assign
drawing instruction to particular segment. The segment
created must be given a name to identify it which must be
a valid one and there should be no segment with the same
name.
Cont..

• After this, we initialize items in segment table under our


segment name and the first instruction of this segment is
allocated at next free storage in display file and attributes of
segments are initialized to default.
• Algorithm :
1. If any segment is open, give error message : “Segment is still
open” and go to step 8.
2. Read the name of the new segment.
3. If the segment name is not valid, give error
message : “Segment name not a valid name” and go to step
8.
4. If given segment name already exists, give error message: 
“Segment name already exists in name list” and go to step 8.
5. Make next free storage area in display file as start of new
segment.
Cont..

6. Initialize size of new segment to 0 and all its attributes to their


default values.
7. Inform that the new segment is now open.
8. Stop
2. Closing a Segment : After completing entry of all display file
instructions, the segment needs to be closed for which it has
to be renamed, which is done by changing the name of
currently open segment as 0. Now the segment with name 0
is open i.e. unnamed segment is open and if two unnamed
segments are present in display file one needs to be deleted.
Algorithm :
1. If any segment is not open, give error message : “No segment
is open now” and go to step 6.
Cont..

2. Change the name of currently opened segment to any


unnamed segment, lets say 0.
3. Delete any other unnamed segment instruction which may
have been saved and initialize above unnamed segment with
no instructions.
4. Make the next free storage area available in display file as
start of the unnamed segment.
5. Initialize size of unnamed segment to 0.
6. Stop.
Cont..

3. Deleting a Segment :
To delete a particular segment from display file, we must just
delete that one segment without destroying or reforming the
entire display and recover space occupied by this segment.
Use this space for some other segment.
The method to achieve this depends upon the data structure
used to represent display file. In case of arrays, the gap left by
deleted segment is filled by shifting up all the segments
following it.
Cont..
Cont..

Algorithm :
1. Read the name of the segment to be deleted.
2. If segment name is not valid, give error message : “Segment name
is not a valid name” and go to step 8.
3. If the segment is open, give error message : “Can’t delete an open
segment” and go to step 8.
4. If size of segment is less than 0, no processing is required and go to
step 8.
5. The segments which follow the deleted segment are shifted by its
size.
6. Recover deleted space by resetting index of next free instruction.
7. The starting position of shifted segments is adjusted by subtracting
the size of deleted segment from it.
8. Stop.
Cont..

4. Renaming a Segment : 
This is done to achieve Double Buffering i.e. the idea of storing
two images, one to show and other to create, alter and for
animation.
Algorithm :
1. If both old and new segment names are not valid, give error
message : “Segment names are not valid names” and go to step
6.
2. If any of two segments is open, give error message : “Segments
are still open” and go to step 6.
3. If new segment name given already exists in the display list, give
error message : “Segment name already exists” and go to step 6.
4. The old segment table entry are copied into new position.
5. Delete the old segment.
6. Stop.
Cont..

Advantages of using segmented display :


• Segmentation allows to organize display files in sub-picture
structure.
• It allows to apply different set of attributes to different
portions of image.
• It makes it easier to the picture by changing/replacing
segments.
• It allows application of transformation on selective portions of
image.
Windowing System

• A windowing system is a system for sharing a computer's


graphical display presentation resources among multiple
applications at the same time. In a computer that has a
graphical user interface (GUI), you may want to use a number
of applications at the same time (this is called task).
• Using a separate window for each application, you can
interact with each application and go from one application to
another without having to reinitiate it. Having different
information or activities in multiple windows may also make it
easier for you to do your work.
• A windowing system uses a window manager to keep track of
where each window is located on the display screen and its
size and status. A windowing system doesn't just manage the
windows but also other forms of graphical user interface
entities.
Cont..

• The method of selecting and enlarging a portion of a drawing


is called windowing. The area chosen for this display is called
a window. The window is selected by world-coordinate.
• Sometimes we are interested in some portion of the object
and not in full object. So we will decide on an imaginary box.
This box will enclose desired or interested area of the object.
Such an imaginary box is called a window.
• Viewport: An area on display device to which a window is
mapped [where it is to displayed].
• Basically, the window is an area in object space. It encloses
the object. After the user selects this, space is mapped on the
whole area of the viewport. Almost all 2D and 3D graphics
packages provide means of defining viewport size on the
screen. It is possible to determine many viewports on
different areas of display and view the same object in a
different angle in each viewport.
Cont..

• The size of the window is (0, 0) coordinate which is a bottom-


left corner and toward right side until window encloses the
desired area.
• Once the window is defined data outside the window is
clipped before representing to screen coordinates. This
process reduces the amount of data displaying signals.
• The window size of the Tektronix 4.14 tube in Imperial College
contains 4.96 points horizontally and 3072 points vertically.
• Viewing transformation or window to viewport
transformation or windowing transformation: The mapping of
a part of a world-coordinate scene to device coordinates is
referred to as a viewing transformation etc.
Cont..
Cont..

• Viewing transformation in several steps:


• First, we construct the scene in world coordinate using the
output primitives and attributes.
• To obtain a particular orientation, we can set up a 2-D viewing
coordinate system in the window coordinate plane and define
a window in viewing coordinates system.
• Once the viewing frame is established, are then transform
description in world coordinates to viewing coordinates.
• Then, we define viewport in normalized coordinates (range
from 0 to 1) and map the viewing coordinates description of
the scene to normalized coordinates.
• At the final step, all parts of the picture that (i.e., outside the
viewport are dipped, and the contents are transferred to
device coordinates).
Cont..
Cont..
Window to Viewport Co-ordinate
Transformation
• Once object description has been transmitted to the viewing
reference frame, we choose the window extends in viewing
coordinates and selects the viewport limits in normalized
coordinates.
• Object descriptions are then transferred to normalized device
coordinates:
• We do this thing using a transformation that maintains the
same relative placement of an object in normalized space as
they had in viewing coordinates.
• If a coordinate position is at the center of the viewing
window:
• It will display at the center of the viewport.
• Fig shows the window to viewport mapping. A point at
position (xw, yw) in window mapped into position (xv, yv) in
the associated viewport.
Cont..
Cont..

• Matrix Representation of steps of View


Transformation:
Cont..

T1=Translating viewport on screen.


Cont..
Cont..

Advantage of Viewing Transformation:


• We can display picture at device or display system according
to our need and choice.
Note:
• World coordinate system is selected suits according to the
application program.
• Screen coordinate system is chosen according to the need of
design.
• Viewing transformation is selected as a bridge between the
world and screen coordinate.
Line Clipping

• In computer graphics, line clipping is the process of removing


lines or portions of lines outside an area of interest. Typically,
any line or part thereof which is outside of the viewing area is
removed.
• There are two common algorithms for line clipping: Cohen–
Sutherland and Liang–Barsky.
• A line-clipping method consists of various parts. Tests are
conducted on a given line segment to find out whether it lies
outside the view volume. Afterwards, intersection calculations
are carried out with one or more clipping boundaries
Cont..

Line Clipping
• The concept of line clipping is same as point clipping. In line
clipping, we will cut the portion of line which is outside of
window and keep only the portion that is inside the window.
• It is performed by using the line clipping algorithm.

The line clipping algorithms are:


• Cohen Sutherland Line Clipping Algorithm
• Midpoint Subdivision Line Clipping Algorithm
• Liang-Barsky Line Clipping Algorithm
Cont..

• Cohen-Sutherland Line Clippings


• Cohen-Sutherland algorithm divides a two-dimensional space
into 9 regions and then efficiently determines the lines and
portions of lines that are inside the given rectangular area.
Cont..

We will use 4-bits to divide the entire region. These 4 bits


represent the Top, Bottom, Right, and Left of the region as
shown in the following figure. Here, the TOP and LEFT bit
is set to 1 because it is the TOP-LEFT corner.
Cont..
Cont..

There are three possible cases for any given line.


• Completely inside the given rectangle : Bitwise OR of region
of two end points of line is 0 (Both points are inside the
rectangle)
• Completely outside the given rectangle : Both endpoints
share at least one outside region which implies that the line
does not cross the visible region. (bitwise AND of endpoints !=
0).
• Partially inside the window : Both endpoints are in different
regions. In this case, the algorithm finds one of the two points
that is outside the rectangular region. The intersection of the
line from outside point and rectangular window becomes new
corner point and the algorithm repeats
Cont..
Cohen-Sutherland Algorithm

• Step 1 : Assign a region code for two endpoints of given line.


• Step 2 : If both endpoints have a region code 0000 then given line is
completely inside.
• Step 4:
• Step 3 : Else, perform the logical AND operation for both region codes.
– Step 3.1 : If the result is not 0000, then given line is completely
outside.
– Step 3.2 : Else line is partially inside.
• Step 3.2.1 : Choose an endpoint of the line that is outside the
given rectangle.
• Step 3.2.2 : Find the intersection point of the rectangular
boundary (based on region code).
• Step 3.2.3 : Replace endpoint with the intersection point and
update the region code.
• Step 3.2.4 : Repeat step 2 until we find a clipped line either
trivially accepted or trivially rejected.
 Step 4: Repeat step 1 for other lines
Cont..

Advantage of Cohen Sutherland Line Clipping:


• It calculates end-points very quickly and rejects and accepts
lines quickly.
• It can clip pictures much large than screen size.
Mid Point Subdivision Line Clipping Algorithm:

• It is used for clipping line. The line is divided in two parts. Mid
points of line is obtained by dividing it in two short segments.
Again division is done, by finding midpoint. This process is
continued until line of visible and invisible category is
obtained.
• Let (xi,yi) are midpoint
Cont..

Advantage of midpoint subdivision Line Clipping:


It is suitable for machines in which multiplication and division
operation is not possible. Because it can be performed by
introducing clipping divides in hardware.
Algorithm of midpoint subdivision Line Clipping:
• Step1: Calculate the position of both endpoints of the line
• Step2: Perform OR operation on both of these endpoints
• Step3: If the OR operation gives 0000
            then
                    Line is guaranteed to be visible
          else
                  Perform AND operation on both endpoints.
                  If AND ≠ 0000
            then the line is invisible
      else
            AND=6000
            then the line is clipped case.
Cont..

• Step4: For the line to be clipped. Find midpoint


            Xm=(x1+x2)/2
            Ym=(y1+y2)/2
        Xm is midpoint of X coordinate.
            Ym is midpoint of Y coordinate.
• Step5: Check each midpoint, whether it nearest to
the boundary of a window or not.
• Step6: If the line is totally visible or totally rejected
not found then repeat step 1 to 5.
• Step7: Stop algorithm.
Polygon Clipping
Cont..

• A set of connected lines are considered


as polygon; polygons are clipped based on the window and
the portion which is inside the window is kept as it is and
the outside portions are clipped. The polygon clipping is
required to deal different cases. Usually it clips the four
edges in the boundary of the clip rectangle.
Cont..
Cont..
Cont..
Cont..
Cont..
Cont..
Cont..
Cont..
Cont..
Cont..
Cont..

You might also like