Given by Byeongseob Ki, Scott Klasky, Nancy McCracken at Basic Information Track Computational Science Course CPS616 on Spring Semester 1999. Foils prepared May 19 99
Outside Index
Summary of Material
The success of Java in providing cross-platform programming support in a browser has led to demand for more complex multi-media support for web-based applications. |
We first give a short overview of the Media API's. |
The following API's are described in more detail:
|
Outside Index Summary of Material
Byeongseob Ki, Scott Klasky, |
and Nancy McCracken |
Northeast Parallel Architectures Center |
Syracuse University |
111 College Place |
Syracuse, NY 13244-4100 |
The success of Java in providing cross-platform programming support in a browser has led to demand for more complex multi-media support for web-based applications. |
We first give a short overview of the Media API's. |
The following API's are described in more detail:
|
Java 2D:Provides an abstract imaging model that extends the JDK AWT package, including line art, images, color, transforms, and compositing |
Java Media Framework: Specifies a unified architecture, messaging protocol, and programming interface for media players, media capture, and conferencing; Comprises three separate packages
|
Java Collaboration: Allows for interactive, two-way, multi-party communications over a variety of networks |
Java Telephony: Integrates telephones with computers and provides basic functionality for first-party and third-party call control |
Java Speech: Provides Java based speech recognition and speech synthesis (text-to-speech) |
Java Animation: Provides for motion and transformations of 2D objects while utilizing the Java Media Framework for synchronization, composition, and timing |
Java 3D: Provides an abstract, interactive imaging model or behavior and control of 3D objects |
Basic Concepts and Examples |
The Java 2D is a set of Java 1.2 core classes that
|
The Java 2D API
|
http://www.javasoft.com/products/java-media/2D/ |
http://java.sun.com/products/jdk/1.2/docs/guide/2d/ |
Provides richer graphics, font, and image APIs |
Supports enhanced color definition and composition, hit detection on arbitrary geometric shapes and text, and a uniform rendering model for printers and display devices |
Enables the creation of advanced graphics libraries in Java, such as CAD/CAM and imaging special effects |
Can be used to create and display animations and other multimedia presentations |
Java 2D API defines two coordinate spaces: User Coordinate Space and Device Coordinate Space |
Java 2D API enhances the functionality of AWT by implementing new methods in existing classes, while extending existing classes and interfaces |
(0,0) |
x |
y |
The origin of User Coordinate Space lies in the upper left corner increasing to the right and downward |
The basic graphics rendering model has not changed with the addition of Java 2D |
The Java 2D API class Graphics2D extends the Graphics class to support more graphics attributes and provide new rendering methods |
Java 2D API uses the drawing model defined by the java.awt package |
In this model, each Component object implements a paint(...) method that is invoked automatically whenever the component needs to be drawn |
Example: Suppose you have a component whose job it is to draw a red rectangle |
|
public void paint( Graphics g ) { |
g.setColor( Color.red ); |
g.fillRect( 300, 300, 200, 100 ); |
} |
The basic drawing process:
|
Java 2D provides additional features for:
|
To use Java 2D, implement a paint(...) method and cast the Graphics argument to a Graphics2D object |
The following example demonstrates how you could use the Java 2D API to draw a red rectangle
|
Graphics2D g2d = (Graphics2D) g; |
public void paint( Graphics g ) { |
Graphics2D g2d = ( Graphics2D ) g; |
g2d.setColor( Color.red ); |
GeneralPath rect = new GeneralPath( GeneralPath.EVEN_ODD ); |
rect.moveTo( 300.0f, 300.0f ); // ul corner |
rect.lineTo( 500.0f, 300.0f ); // ur corner |
rect.lineTo( 500.0f, 400.0f ); // lr corner |
rect.lineTo( 300.0f, 400.0f ); // ll corner |
rect.closePath(); // close the rectangle |
g2d.fill( rect ); |
} |
To simplify the creation of standard shapes such as rectangles, Java 2D provides several subclasses of Shape in addition to GeneralPath: |
In addition to supporting solid color fills, Java 2D enables you to specify complex fills such as gradients and patterns |
Rectangle2D.Double rect = new Rectangle2D.Double( 300, 300, 200, 100 ); |
Graphics2D defines methods for drawing objects and state attributes to control rendering |
With state attributes, you can
|
Complex Paint Style |
Compositing |
Stroke Styles |
Java 2D adds new text-related classes that support sophisticated text layout and fine-grain font control |
Java 2D provides an enhanced Font class that supports:
|
A transform is used to generate a skewed version of the font before the string is drawn |
Java 2D provides support for high-quality color output |
The key color management classes in Java 2D:
|
http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html |
Java 2D provides a set of classes that define operations on BufferedImage and Tile objects
|
Image Processing Model |
Source image |
Destination image |
Image processing |
Filter |
Edge detection and enhancement |
Lookup-table Manipulation |
GraphicsDevice
|
GraphicsEnvironment
|
GraphicsConfiguration
|
The Java 2D Printing API defines three key printing abstractions:
|
1. Implement the Printable interface and provide the mechanism for imaging a page in a print(...) method |
2. Provide a way for the user to trigger the print operation such as button click |
3. When the user initiates printing, your application should:
|
Illustrates a Book containing two letter size pages in portrait orientation, a legal size page in landscape orientation, and a tabloid size page in portrait orientation |
Basic Concepts and Examples |
Java 3D is a set of classes for writing three-dimensional graphics applications and applets |
It is primarily for application developers |
It enables authors to build 3D models and control animation and interaction |
It also enables detailed control over rendering, input devices, the viewing model, and lots more |
API implementation released by Sun Microsystems |
http://java.sun.com/products/java-media/3D/ |
Current version is 1.1 |
Java 3D requires JDK1.2: |
The developer must have at least a basic knowledge of the principles of computer graphics:
|
The developer must possess a thorough understanding of the OOP paradigm |
The prospective developer should read and analyze the Java 3D specification located at http://java.sun.com/products/java-media/3D/ |
High performance
|
Rich set of features for creating interesting 3D worlds
|
Provide a high-level, object-oriented paradigm that enables developers to rapidly deploy sophisticated applications and applets |
Support for runtime loaders to accommodate a wide variety of file formats such as CAD and VRML |
The goal of this group is to improve interoperability between Java3D and VRML, and to maintain and extend the open source Java3D-based VRML97 browser. |
http://www.web3d.org/WorkingGroups/vrml-java3d |
The advantage of Java based VRML renderer is that it will run in any browser without a plug-in. The disadvantage is that the renderer is not as fast as the VRML plug-ins such as Cosmoplayer was, unless you have an underlying low-level renderer such as OpenGL. |
Scene Graph Programming Model
|
Rendering Modes
|
Extensibility
|
Scene graph superstructure:
|
A scene graph itself starts with BranchGroup nodes |
A BranchGroup serves as the root of a subgraph, called a branch group, of the scene graph---only BranchGroup objects can attach to Locale objects |
A scene graph consists of Java 3D objects, called nodes, arranged in a tree structure |
The user creates one or more scene subgraphs and attaches them to a virtual universe |
A Java 3D scene graph is a directed acyclic graph (DAG), which may not contain cycles |
Java 3D refines the Node object class into two subclasses: Group and Leaf node objects |
Group node objects group together one or more child nodes. A group node can point to zero or more children but can have only one parent |
Leaf node objects contain the actual definitions of shapes (geometry), lights, fog, sounds, and so forth |
A leaf node has no children and only one parent |
Java 3D defines a hierarchy of classes: |
Object |
SceneGraphObject |
Node |
Group |
Leaf |
NodeComponent |
Appearance |
Geometry |
... |
Transform3D |
... |
Java 3D has richer semantics for scoping lights, sound, fog, behaviors, and backgrounds |
Java 3D and VRML share similar notions of:
|
Example: Create a red 3D text shape "Hello World" |
Shape { |
appearance Appearance { |
material Material { |
diffuseColor 1.0 0.0 0.0 |
} |
} |
geometry Text { |
string "Hello world" |
fontStyle FontStyle { } |
} |
} |
Material blue = new Material( ); |
blue.setDiffuseColor( 0.0, 0.0, 1.0 ); |
Appearance color = new Appearance( ); |
color.setMaterial( blue ); |
Text3D hello = new Text3D( ); |
hello.setFont3D( someFont ); |
hello.setString( "Hello world" ); |
Shape3D sign = new Shape3D( ); |
sign.setGeometry( hello ); |
sign.setAppearance( color ); |
Every Java 3D application has five tasks:
|
In VRML, the last three are performed by the browser and cannot be fully controlled by a VRML script |
The Java 3D Shape3D leaf node creates a 3D shape with geometry and appearance node components |
Text3D geometry node component creates extruded 3D text in this example |
Shape3D sign = new Shape3D( ); |
sign.setGeometry( hello ); |
sign.setAppearance( color ); |
Most Java 3D geometry node components handle triangles and quads implicit or explicit (indexed) connectivity strips, fans, and arbitrary polygon collections: LineArray, PointArray, QuadArray, LineStripArray, TriangleFanArray, etc. |
VRML's primitive and specialized geometry can be implemented using Java 3D geometry arrays |
The Java 3D Raster geometry node component enables pixel read and write to the screen at a transformed location |
Detailed rendering control is available with Java 3D's attribute node components: |
Java3D Controls |
ColoringAttributes Shading model |
LineAttributes Line width and pattern |
PointAttributes Point size |
PolygonAttributes Polygon culling |
RenderingAttributes Z- and alpha-buffering |
TextureAttributes Transforms and rendering type |
TransparencyAttributes Transparency type |
Java3D has a set of nodes to create groups: OrderedGroup, Switch, TransformGroup, etc. |
Java 3D supports numerous utility methods to build and manipulate 4x4 matrices and vectors: |
Transform3D yAxis = new Transform3D( ); |
yaxis.roty( 0.785 ); |
TransformGroup scene = new TranformGroup( ); |
scene.addChild( sign ); |
scene.setTransform( yaxis ); |
Like VRML, Java 3D has a set of leaf nodes to create and manipulate lights: |
Light |
AmibientLight |
DirectionalLight |
PointLight |
SpotLight |
PointLight bulb = new PointLight( ); |
bulb.setColor( yellow ); |
bulb.setPosition( 0.0, 5.0, 3.0 ); |
Java 3D has a set of leaf nodes to add sounds: |
Sound |
BackgroundSound |
PointSound |
ConeSound |
Soundscape |
AuralAttributes |
MediaContainer |
PointSound ouch = new PointSound( ); |
ouch.setPosition( 0.0, 3.0, 8.0 ); |
ouch.setSoundData( ouchSound ); |
ouch.setLoop( 1 ); |
Sounds are scheduled only if their bounding volume intersects the viewer's activation volume |
The Java 3D Soundscape leaf node and AuralAttributes node component specify environment characteristics such as Reverberation, Echo, Frequency filtering, and Doppler effects |
Different parts of the world can have different characteristics
|
Java 3D has a typical set of fog nodes much like their VRML counterparts: |
Fog |
ExponentialFog |
LinearFog |
LinearFog murky = new LinearFog( ); |
murky.setColor( 0.8, 0.8, 0.8 ); |
murky.setFrontDistance( 0.0 ); |
murky.setBackDistance( 10.0 ); |
The Background leaf node defines either a solid color or a background image used to fill the window |
A Background node is active when its application region intersects the viewer's activation volume |
If no Background nodes are active, then the window is cleared to black |
Background mountains = new Background(); |
mountains.setColor( 0.0, 0.5, 1.0 ); |
mountains.setGeometry( mountainWorld ); |
Java 3D VirtualUniverse object builds a "universe" |
Locale object creates a world anchor point within a universe |
VirtualUniverse universe = new VirtualUniverse(); |
Locale locale = new Locale( universe ); |
A Java 3D BranchGroup node groups world scene graphs together and binds them to a locale |
BranchGroup world = new BranchGroup( ); |
world.addChild( part_of_world ); |
locale.addBranchGroup( world ); |
Once a universe is created, it may be viewed |
Java 3D ViewPlatform leaf node establishes a viewpoint for the universe
|
ViewPlatform spot = new ViewPlatform( ); |
TransformGroup navigate = new TransformGroup( ); |
navigate.addChild( spot ); |
Java 3D View object describes camera features to view the universe from a view platform: |
View camera = new View( ); |
camera.setFieldOfView( 0.785 ); |
camera.setFrontClipDistance( 0.1 ); |
camera.setBackClipDistance( 50.0 ); |
camera.setSceneAntialiasingEnabled( true ); |
camera.attachViewPlatform( spot ); |
Java 3D View also supports detailed specification of the real-world viewing situation
|
A behavior node consists of a
|