1 / 20

2D Graphics: Advanced Topics

2D Graphics: Advanced Topics. Chapter 4. Bird’s Eye View. Overview of Computer Graphics 2D Graphics: Basics 2D Graphics: Rendering Details 2D Graphics: Advanced topics

zora
Télécharger la présentation

2D Graphics: Advanced Topics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2D Graphics: Advanced Topics Chapter 4

  2. Bird’s Eye View • Overview of Computer Graphics • 2D Graphics: Basics • 2D Graphics: Rendering Details • 2D Graphics: Advanced topics • Advanced techniques in 2D graphics including B-spline curves, custom shape primitives, image processing, animation, fractal images, and printing

  3. Objectives • To understand B-spline curves • To construct custom shape primitives • To apply basic image processing techniques • To create fractal images • To create 2D animation • To perform graphics printing

  4. Key Classes and Methods • javax.awt.geom.GeneralPath.curveTo() • A method to construct a cubic curve segment • javax.awt.image.BufferedImage – A class encapsulating an image • javax.awt.image.BufferedImageOp • An interface for image-processing operators • java.swing.Timer – A class generating action events in a periodic fashion • java.lang.Runnable • An interface to define code executable as a separate thread • java.lang.Thread – A class encapsulating a thread of execution of a program • java.lang.Thread.sleep(long ms) • A method to place the thread to sleep for a specified time period • java.util.Calendar – A class encapsulating a calendar for date and time • java.awt.image.Raster – A class encapsulating image data • java.awt.image.WritableRaster • A class encapsulating writable image data • java.awt.print.PrinterJob – A class for printing management • java.awt.print.Printable – An interface to define print contents

  5. Key Terms • B-spline curve • A curve defined as a parametric equation of piecewise polynomials blending with a sequence of control points. • Bezier curve • A curve defined as a parametric equation of polynomials blending with control points. • NURB – Non-uniform rational B-spline • Image processing • Computer manipulation of digital images to enhance or extract information. • Convolution – A type of linear operations often used in signal and image processing • Kernel – A function to define a convolution. • Complex numbers – An extension of real numbers • Complex plane – The set of complex numbers interpreted as points on a plane. • Frame rate – The speed of an animation measured in frames per second (fps) • THREAD • A LINE OF EXECUTION IN A RUNNING PROGRAM. In a multithreading environment a single program may have several threads running simultaneously. • Cellular automata • A dynamic system on a grid of cells, evolving based a simple set of rules that specify the next state of a cell using the previous states of itself and its neighbors.

  6. General Bezier Curve Bernstein basis

  7. B-Spline Curve Normalized B-spline blending functions

  8. B-Spline to Bezier Conversion Source

  9. Shape Interface public boolean contains(Rectangle2D rect) public boolean contains(Point2D point) public boolean contains(double x, double y) public boolean contains(double x, double y, double w, double h) public Rectangle getBounds() public Rectangle2D getBounds2D() public PathIteratorgetPathIterator(AffineTransform at) public PathIteratorgetPathIterator(AffineTransform at, double flatness) public boolean intersects(Rectangle2D rect) public boolean intersects(double x, double y, double w, double h)

  10. A Custom Primitive • Cannot extend the final class GeneralPath • Wrap a GeneralPath public class Heart implements Shape { GeneralPathpath; public Heart(float x,floaty,floatw,floath){ path = new GeneralPath(); … Source

  11. Image Processing • AWT – push model • Java 2D – immediate model • JAI – pull model

  12. BufferedImage Create BufferedImage bi = new BufferedImage(300, 400, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = (Graphics2D)(bi.createGraphics()); Read BufferedImage bi = ImageIO.read(file); Display g2.drawImage(image, 0, 0, new Component() {});

  13. Operators Source

  14. Raster and WritableRaster int[] getPixel(int x, int y, int[] data) float[] getPixel(int x, int y, float[] data) double[] getPixel(int x, int y, double[] data) int[] getPixels(int x, int y, int w, int h, int[] data) float[] getPixels(int x, int y, int w, int h, float[] data) double[] getPixels(int x, int y, int w, int h, double[] data) void setPixel(int x, int y, int[] data) void setPixel(int x, int y, float[] data) void setPixel(int x, int y, double[] data) void setPixels(int x, int y, int w, int h, int[] data) void setPixels(int x, int y, int w, int h, float[] data) void setPixels(int x, int y, int w, int h, double[] data)

  15. Mandelbrot Set Iterations on the complex plane Source

  16. Animation: Multi-threading Outline of a typical multi-threading animation public void paintComponent(Graphics g) { <* render a frame *> } public void run() { while(true) { <* update frame data *> repaint(); try { Thread.sleep(sleepTime); } catch (InterruptedException ex) {} } } Source

  17. Animation: Timer Outline of an animation with Timer Timer timer = new Timer(period, listener); timer.start(); public void actionPerformed(ActionEvent event) { <* do frame rendering *> } Source

  18. Cellular Automata The iteration of the system proceeds by assigning the next state of each cell based on the previous configuration. Each cell follows the same set of rules and the new state depends only upon the current states of the same cell and its neighbors. Example: A cell is black if exactly one of its neighbors in the current configuration is black Source

  19. Printing • PrintJob • getPrintJob • printDialog • setPrintable • print • Printable • Print • PageFormat • getOrientation • getWidth • getHeight • getImageableX • getImageableY • getImageableWidth • getImageableHeight Source

  20. Summary • A B-spline curves can be converted to a sequence of Bezier curves, which may then be rendered directly by the Graphics2D object. The control point of each Bezier curve are linear combinations of controls points of the B-spline curve. • Shape interface and GeneralPath class • BufferedImage class is the main representation for images in Java 2D. BufferedImageOp interface provides convenient ways to process BufferedImage objects. • Raster and WritableRaster classes offer access to the pixel data in a BufferedImage. Mandelbrot set is given. • The Thread class and the Runnable interface provide essential multithreading support. The Timerclass of the Swing package provides a convenient utility to trigger the periodic frame rendering. • Graphics2D class provides the rendering engine. The Printable interface allows for the necessary callback structure for defining the graphics output. The PrinterJob class facilitates the special tasks in printing.

More Related