JOMO KENYATTA UNIVERSITY
OF
AGRICULTURE & TECHNOLOGY
JKUAT SODeL
SCHOOL OF OPEN, DISTANCE AND eLEARNING
P.O. Box 62000, 00200
©2014
Nairobi, Kenya
E-mail: elearning@[Link]
ICS 2311 Computer Graphics
JJ II LAST REVISION ON October 16, 2014
J I
J DocDoc I
Back Close
ICS 2311 Computer Graphics
This presentation is intended to covered within one week.
The notes, examples and exercises should be supple-
mented with a good textbook. Most of the exercises have
solutions/answers appearing elsewhere and accessible by
JKUAT SODeL
clicking the green Exercise tag. To move back to the same
page click the same tag appearing at the end of the solu-
tion/answer.
©2014
Errors and omissions in these notes are entirely the re-
sponsibility of the author who should only be contacted
through the Department of Curricula & Delivery
(SODeL) and suggested corrections may be e-mailed to
elearning@[Link].
JJ II
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 0
ICS 2311 Computer Graphics
LESSON 8
Clipping and Markup Languages
8.1. introduction to Clipping
JKUAT SODeL
We have talked about 2D scan conversion of line-segments and
polygons What if endpoints of line segments or vertices of poly-
gons lie outside the visible device region? Need clipping!
©2014
• Clipping: Remove points outside a region of interest –
clip window. Want to discard everything that’s outside of
our window... Primitives: point, line-segment, and poly-
gon. Point clipping: Remove points outside window. A
point is either entirely inside the region or not.
JJ II • Line-segment clipping: Remove portion of line segment
J I outside window. Line segments can straddle the region
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 1
ICS 2311 Computer Graphics
boundary. Based on point clipping Compute the line seg-
ment inside the window Need to compute intersections be-
tween the line segment and window edges. Consider trivial
cases first to reduce computation. outcodes algorithm
JKUAT SODeL
• Polygon clipping: Remove portion of polygon outside
window
More complex. A convex polygon may be clipped into multi-
©2014
ple polygons. Based on line clipping Clip the polygon against
window edges in a sequence
Trivial tests are important in computer graphics: Particu-
larly if the trivial case is the most common one. Particularly if
we can reuse the computation for the non-trivial case
JJ II
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 2
ICS 2311 Computer Graphics
8.2. Markup Languages
What is a Markup language?
Some Examples:
• SGML
JKUAT SODeL
• HTML
• XML
©2014
• VRML
• SVG
How do they relate to writing Graphical Programs?
What are they? Not normal programming languages!
Way of specifying “mark up” - ie extra contextual information
JJ II about something for a document (in its broadest sense)
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 3
ICS 2311 Computer Graphics
8.2.1. SGML
• Standard Generalized Markup Language
• Publishers’ markup language
• Annotating layout information for a very general docu-
JKUAT SODeL
ment
• Pioneered idea of tag pairs <tag>. . . .</tag>
©2014
• Very complex!
• Led to HTML as a very “cut down” ML
8.2.2. HTML
• Hyper Text Markup Language
JJ II
• Used to specify web page info - [Link]
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 4
ICS 2311 Computer Graphics
• CERN and WWW (Tim Berners-Lee et al)
• Mosaic and Netscape
• Widely known and used sets of tags
• More recently introduced XHTML and standardised head-
JKUAT SODeL
ers etc
• Web browsers generally very tolerant of malformed HTML
©2014
• Look at the “source” option in your web browser
• HTML & variants as Graphics layout
• Not original design intent!
• But lots of layout and graphical tags added by vendors -
JJ II unstoppable!
J I • Colours, fonts, backgrounds, styles,. . .
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 5
ICS 2311 Computer Graphics
• Driven by market needs Originally about logical structure
rather than physical appearance
• Standard still developing
• Tools to Create Markup
JKUAT SODeL
• Can of course use a plain ordinary text editor - html files
are just plain ASCII text
©2014
• Many tools and products such as DreamWeaver that check
for correctness as well as provide a set of tools/buttons
• Tools like Word that try to “export” into an HTML format
• Tools to View Markup
JJ II • Web browsers know how to parse HTML Often have plug
J I ins to cope with other markups - eg XML or VRML or
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 6
ICS 2311 Computer Graphics
SVG
• Some language/libraries have built in tools
• See the JEditorPane in Java’s Swing
JKUAT SODeL
• Applets
• Applets are a special embedded entity in most web browsers
• The browser runs a Java Virtual Machine (JVM) and sets
©2014
up some screen space
• The applet tag <applet>. . . </applet> tells the browser
where to put and configure the byte code
8.2.3. XML
JJ II
• eXtensible Markup Language
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 7
ICS 2311 Computer Graphics
• W3C attempt to tidy up and standardise the mess that
markups have become
• Make every markup language a special case of XML
• Useful as can make XML parser tools that process other
JKUAT SODeL
markups
XML Example - (XGMML)
<?xml version=”1.0” ?>
©2014
<!DOCTYPE graph SYSTEM ”[Link]”>
<graph directed=”1” id=”42” label=”Hello, I am a graph”>
•.1. <node id=”1” label=”node 1” xmlns:xlink
=”[Link] />
JJ II <node id=”2” label=”node 2” xmlns:xlink
J I =”[Link] />
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 8
ICS 2311 Computer Graphics
<node id=”3” label=”node 3” xmlns:xlink
=”[Link] />
<edge source=”1” target=”2” label=”Edge from node 1 to
JKUAT SODeL
node 2” xmlns:xlink
=”[Link] />
<edge source=”2” target=”3” label=”Edge from node 2 to
©2014
node 3”
xmlns:xlink=”[Link] />
<edge source=”3” target=”1” label=”Edge from node 3 to
node 1
” xmlns:xlink=”[Link] />
JJ II </graph>
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 9
ICS 2311 Computer Graphics
8.2.4. VRML
• Virtual Reality Mark up Language
• Good for static scenes esp in browsers
• A file format
JKUAT SODeL
• Plug ins let you view a static scene - change viewing angle
etc
©2014
• Scene can be published on the Web as a vrml file - just a
format for eg triangles!
• VRML Sites
• [Link]
JJ II • [Link]
J I Several versions of VRML. VRML 97 etc
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 10
ICS 2311 Computer Graphics
Still used but not so popular with advent of VR programming
capabilities as in languages like Java 3D
8.2.5. SVG
• Scalable Vector Graphics
JKUAT SODeL
• An XML based way of saying “there is a triangle or line. . .
located here. . . with these features. . . ”
©2014
• And other shapes, and scalable graphical info Likely to
become popular standard for drawing programs - see W3C
site
8.2.6. Markup Languages -Summary
JJ II • SGML, HTML, XML, VRML, SVG,. . . ?
J I • Tools for creating Markup
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 11
ICS 2311 Computer Graphics
• Tools for Viewing Markup
• Markup is just a standardised (text) open file format
• Ultimately just a tree structure with text on the nodes!
• Java and other programming languages generally now have
JKUAT SODeL
good XML parsing toolkits
• You can easily manipulate these markup languages from
©2014
your own programs.
• Downside is that they can be quite verbose and hence large
file sizes. . .
JJ II
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 12
ICS 2311 Computer Graphics
Revision Questions
Example . Define the term clipping and explain how to achieve
Point clipping and Line clipping
Solution:
JKUAT SODeL
Clipping means limiting the drawing area - ie clipping un-
©2014
wanted parts. Or Remove points outside a region of interest –
clip window
or Want to discard everything that’s outside of our window
Primitives: point, line-segment, and polygon.
Point clipping: Remove points outside window. A point is
either entirely inside the region or not.
JJ II
Describe any process which compares points selected with
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 13
ICS 2311 Computer Graphics
the window edge points using a Boolean function.
Line clipping Remove portion of line segment outside win-
dow. Line segments can straddle the region boundary.
Describe recursive process which highlights the three cases:
JKUAT SODeL
a) The line segment is entirely inside: Keep it.
b) The line segment is entirely outside: Discard it.
c) The line segment is partially inside and partially outside:
©2014
Generate new line to represent part inside.
Or Based on point clipping
Compute the line segment inside the window
Need to compute intersections between the line segment and
window edges.
JJ II Consider trivial cases first to reduce computation.
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 14
ICS 2311 Computer Graphics
Exercise 1. Sutherland-Hodgman Polygon Clipping Algo-
rithm is a clipping technique that provides efficiency in polygon
clipping. State the pseudo procedure and explain the algorithm
JKUAT SODeL
©2014
JJ II
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 15
ICS 2311 Computer Graphics
Solutions to Exercises
Exercise 1.
Polygon Clipping (Sutherland-Hodgman):
JKUAT SODeL
• Window must be a convex polygon
• Polygon to be clipped can be convex or not
Approach:
©2014
• Polygon to be clipped is given as a sequence of vertices
• Each polygon edge is a pair
• Don’t forget wrap around; is also an edge
• Process all polygon edges in succession against a window
edge
JJ II • Polygon in - polygon out
J I • Repeat on resulting polygon with next sequential window
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 16
ICS 2311 Computer Graphics
edge
• Sutherland-Hodgman algorithm deals with concave poly-
gons efficiently
• Built upon efficient line segment clipping Exercise 1
JKUAT SODeL
©2014
JJ II
J I
J DocDoc I
JKUAT: Setting trends in higher Education, Research and Innovation
Back Close 17