Handling%20Exceptions - PowerPoint PPT Presentation

About This Presentation
Title:

Handling%20Exceptions

Description:

Catch block should restore program to a 'continuable'state. ... Simplest scheme: color darkens to black; darkness increases with distance. ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 31
Provided by: Techs
Category:

less

Transcript and Presenter's Notes

Title: Handling%20Exceptions


1
Lecture 9
  • Handling Exceptions
  • 3D graphics
  • Help Options
  • More on Events, Producers/Consumers.
  • DND 3 Demo
  • AnimCursor Demo
  • QA. Final.

2
Dealing with Exceptions
  • Exceptions as a way of life.
  • Cant avoid them when doing File I/O, external
    processes, or networking.
  • Catch block should restore program to a
    continuablestate.
  • In most cases, the user must be notified of the
    failure. Often a retry option should be
    offered.

3
  • try
  • // Input filename 1
  • // Input filename 2
  • // exec(movecommand f1 f2)
  • // capture output from process
  • // refresh directory windows involved.
  • catch (FileNotFoundException e)
  • String mesg e.getLocalizedMessage()
  • if (mesg null)
  • mesg DEFAULT_FNF_MESSAGE
  • JOptionPane.showMessageDialog(mesg)
  • catch (IOException e)
  • //...

4
Notifying the User
  • Throwable.getLocalizedMessage() gets a
    locale-specific message for the error.
  • Exceptions do not always provide good messages.
    If you know more precisely what the problem is,
    tell the user.
  • Provide default messages.

5
  • try
  • // ...
  • // exec(movecommand1) backup f2(undo)
  • // exec(movecommand2)
  • // capture outputs
  • // refresh directory windows involved.
  • catch (Exception e)
  • JOptionPane.showMessageDialog(mesg)
  • // What if movecommand1 was done?

6
Dont catch, prevent!
  • When possible, catch Exceptions before they
    occur.
  • Example In move command, user gives a
    non-existent source filename. This should be
    checked for immediately, and the move command
    should be aborted with a warning message (and
    option to correct filename).

7
3D Graphics, Overview
  • Internal representation of a 3D environment.
  • Representation of screen location within the
    context of the above.
  • Rendering mechanism to display screen view based
    on both the above.
  • Methods of manipulating all the above.

For each of these, there are many methods!
8
3D Internal Model
  • Primary object is a Surface (2-dimensional
    manifold).
  • Surfaces are usually represented as a quilt
    made up of triangular or polygonal pieces.
  • Each vertex of these is represented by an
    (x,y,z) triple of real numbers.
  • Each piece also has a color attribute.

9
3D Screen as Window
  • As with 2D graphics, we think of the screen as
    corresponding to a particular 2-dimensional
    window within the model. For 3D graphics, we
    also must include a point representing the eyes
    of the user. This point and rectangle together
    determine the viewable area which is to be
    displayed on-screen.

10
3D Internals
Eye
Screen
Surfaces
11
The Visible Cone
  • Each point on the screen corresponds to a ray,
    from the eye through the point, extending
    infinitely onward.
  • Each rectangle on the screen corresponds to a
    rectangular cone of points, which lie on rays
    from the eye through the points in the rectangle.
  • Visible cone cone for entire screen.

12
The Visible Cone
13
Ideal on-screen image
  • Surfaces which intersect the visible cone are
    potentially visible. Principal light rays
    reflected from surfaces within the visible cone
    can pass through the window, reaching the eye.
  • Closer surfaces block farther surfaces. For
    each screen point, take the first surface struck
    by its ray.

14
Actual on-screen image
  • Cant check every point in screen.
  • Find first surface for each integer point in
    screen rectangle.
  • Color pixel by averaging the 4 colors of its
    corners.
  • Alternative approach often used draw each
    polygon on screen, working back-to-front
    (z-ordering).

15
Colors Paints
  • The previous approach is pretty good at
    displaying shapes of surfaces. We assumed the
    color of each polygon was given to us. More
    likely, it is not.
  • Prefer to deduce the screen image from a Paint
    applied to the surface. Texture-mapping is the
    art of rendering such an image.

16
Level-coloring
  • To emphasize differences in depth between
    polygons, often want the coloration to depend on
    distance from eye. Simplest scheme color
    darkens to black darkness increases with
    distance. Fog effect is reverse fartherwhiter.
  • Base color and brightness can be specified for
    each surface.

17
Texture-mapping
  • Slightly more complicated than displaying
    TexturePaints, because the polygon which is
    painted may be at an oblique angle to the screen.
  • Conversion is affine transformation.

Polygon
Eye
Screen
18
Operations on 3D model
  • Change of view
  • Can be thought of as moving the eye and screen,
    or moving everything else.
  • Can also think of as changing coordinate system.
    The screen rectangle defines an x and a y axis,
    and the eye defines a z-axis.
  • Any 2 coordinate systems are related by an affine
    transformation, just as in 2D case. Completely
    described by a 4x4 matrix.

19
Operations on 3D model II
  • Translating and rotating individual surfaces or
    pieces of surfaces requires applying an affine
    transformation to all the vertices defining those
    surfaces.

20
Proper 3D support
  • High-level constructs for creating surfaces and
    specifying Paints on surfaces.
  • Trivial view support you specify only where the
    eye and screen are.
  • VRML support.
  • 3D affine transformations on Surfaces.
  • Fast performance.

21
Hardware support
  • Many video cards provide support for high-speed
    graphics operations. So do some microprocessors
    (Pentium, AMD).
  • Generally, this means special hardware commands
    for defining, transforming, and displaying 3D
    surfaces, often with texture-mapped paints.
  • Performance. Standards??.

22
Ray-tracing
  • Idea simulate real life. Rays of light emanate
    from various sources, and are reflected,
    absorbed, and scattered to varying extents by
    each surface.
  • Proceeds in steps. Initially, only lights are
    lit, and all surfaces are jet black. Each step
    re-evaluates the light from each surface, based
    on previous step.

23
Ray-tracing
  • Can produce almost photo-realistic images,
    especially when combined with texture-mapping.
  • Very computationally intensive (slow).

24
Existing 3D Systems, I
  • OpenGL (faq) (home page). Introduced in 1992.
    Not open-source, yes 3rd party, platform
    independent.
  • DirectX Microsofts multimedia suite.
  • Both of these are medium-level langs, designed
    as intermediaries between programs and
    acceleration hardware.

25
Existing 3D systems, II
  • Java3D still in alpha-beta-testing at Sun.
    Follows VRMLs approach.
  • VRML multi-participant interactive simulations.
    Invented 1994, latest standard VRML97. VRML 2.0
    soon.
  • Nodes may be sounds, images, 3D surfaces, web
    sites, affine transformations.
  • Nodes are arranged in scene graphs.

26
Advanced Help
  • Topic Selector
  • Use a JTabbedPane or CardLayout to offer more
    than one topic selection method.
  • Table of Contents
  • Use a JTree to present hierarchically arranged
    help topics.
  • Searchable Index
  • Store topics as string, search with
    String.indexOf()

27
History Tools
Preferences
Hypertext, Expandable Nodes
Card Layout
ToolTip
Topic Display
Topic Selector
28
Events, Sources, Listeners
Source
Listener(s)
listener added to the source
new event
Event
pass reference to event
process the event
new event
Event
pass reference to event
process the event
29
Events
  • For each event a single Event is created, and
    all registered Listeners are given a reference to
    this Event.
  • Listeners are not generally aware of the event
    source. After the event happens, they can
    discover the source by interacting with the Event
    itself. (Event.getSource).

30
Producers and Consumers
  • Similar to Sources and Listeners, except that
    production is not generally a result of an
    external user action.
  • Producer notifies consumers when the produced
    item is ready by invoking a special method,
    rather than using the event mechanism. Consumers
    need not all be treated the same way.
Write a Comment
User Comments (0)
About PowerShow.com