Introduction to Computer Graphics Using Java 2D and 3D

Computer graphics provides methods to generate images using a computer. The word “image” should be understood in a more abstract sense here. An image can represent a realistic scene from the real world, but graphics like histograms or pie charts as well as the graphical user interface of a software tool are also considered as images. The following section provides a brief overview on typical application fields and facets of computer graphics.

Application Fields

Graphical user interfaces can be considered as an application of computer graphics, although they do not play an important role in computer graphics anymore. On the one hand, there are standard programming tools and APIs (Application Programming Interfaces) for the implementation of graphical user interfaces and on the other hand the main emphasis of user interfaces is the construction of user-friendly human computer interfaces and not the generation of complex graphics.

In advertising and certain fields of art pictures are sometimes designed using the computer only or photos serve as a basis and are modified or changed with computer graphics techniques.

Large amounts of data are collected in business, industry, economy and science. In addition to suitable data analysis techniques, methods for visualising highdimensional data are needed. Such visualisation techniques reach much further than simple representations like graphs of functions, pie or bar charts—graphics that can already be generated by today’s standard spreadsheet tools. Two- or threedimensional visualisations of high-dimensional data, problem-specific representations of the data [6-8] or animations that show dynamic aspects like the flow of currents or the change of weather phenomena belong to this class of applications of computer graphics.

Apart from constructing and representing such more abstract graphics, the generation of realistic images and sequences of images—not necessarily of the real world—are the main application field of computer graphics. Other areas that were the driving force in the early days of computer graphics are CAD/CAM (Computer-Aided Design/Manufacturing) for the design and construction of objects like cars or chassis. The objects are designed using a suitable computer graphics software and their geometry is stored in computers. Nowadays, not only industrial products are designed in the computer, but also buildings, gardens or artificial environments for computer games. Very often, real existing objects have to be modelled and combined with hypothetical objects, for instance when an architect wants to visualise how a possible extension of an old house might look. The same applies to flight or driving simulators, where existing landscapes and cities need to be modelled in the computer.

The possibilities of designing, modelling and visualising objects play an important role in computer graphics, but also the generation of realistic models and representations of objects based on measurement data. There are various techniques to obtain such data. 3D laser scanners can be used to scan the surface of objects or a set of calibrated cameras allows to reconstruct 3D information of objects from their images. Medical informatics [2] is another very important application field of computer graphics where measurements are available in the form of X-ray images or data from computerised tomography and ultrasonic testing. Such data allow a 3D visualisation of bones or viscera.

The combination of real data and images with techniques from computer graphics will probably gain more importance than it has today. Computer games allow to navigate through scenes and to view the scenes from different angles. For movies, as they are shown on TV or in cinemas, the choice of the viewpoint is not possible anymore once the movie has been produced. Even if various cameras where used to capture the same scene from different angles, one can only choose between the perspectives of the different cameras. But it is not possible to view the scene from a position between the cameras. The elementary techniques allowing a free choice of the viewpoint are available in principle today [1]. However, this will not only need “intelligent” TV sets, but also the processing of the movie from several perspectives. In order to view a scene from a viewpoint different from the cameras, the 3D scene is reconstructed using image processing methods exploiting the information coming from the different perspectives of the cameras. Once the scene is reconstructed, computer graphics techniques can show it from any viewpoint, not only from the camera perspectives. For this application, a combination of image analysis and image recognition techniques with image synthesis methods—i.e., computer graphics algorithms—is required [9].

Other important fields of application of computer graphics are virtual reality [5], where the user should be able to move and act more or less freely in a virtual 3D world, and augmented reality [4], where the real world is enriched by additional information in the form of text or virtual objects.

From a Real Scene to an Image

The various application examples of computer graphics discussed in the previous section demonstrate already that a large variety of different problems and tasks must be solved within computer graphics. Figure 1.1 illustrates crucial steps that are needed in order to generate an image from a real or virtual scene.

As a first step, the objects in the scene in Fig. 1.1a have to be modelled with the techniques and methods provided by a computer graphics tool. In general, these models will not be exact copies of the real or virtual objects of the scene, but only approximations of them. Depending on how detailed the objects should be modelled, how much effort one wants to invest and on the techniques provided by the computer graphics tool, the approximation of the objects can be almost exact or very rough only. Figure 1.1b illustrates this problem of approximation by assuming that the computer graphics tool is very restricted and the bowl in the real scene can only be approximated by a semisphere.

The modelled objects usually cover a much larger region than the part that is visible for the virtual viewer from his viewpoint. The model might for instance include a group of buildings surrounded by gardens and the viewer can move in the buildings and through the gardens. When the viewer is in a room of one of the buildings looking into the room, but not outside the window, he can only see a very small fraction of the objects of this virtual world. Most of the objects can therefore be neglected, when the image is generated. Taking the viewer’s position and the direction of his view into account, a three-dimensional region must be defined that determines which objects might be visible for the viewer (see Fig. 1.1c). The computation of which objects belong completely or at least partly to this region is called clipping or, more specifically, 3D-clipping. Not all objects located in the clipping region might be visible for the viewer, since some of them might be hidden from the viewer’s view by other objects, which are closer to the viewer.

The visible objects in the clipping region need to be projected onto a twodimensional plane in order to obtain a flat pixel image as shown in Fig. 1.1d that can be printed out or shown on a computer screen. This projection requires the application of hidden line and hidden surface algorithms in order to find out whether objects or parts of the objects are visible or hidden by other objects. The effects of light like shading, shadows and reflection are extremely important issues for the generation of realistic images. 2D-clipping is also necessary to decide which parts of the projection of an object in the 3D-clipping region lie within the projection plane.

From a scene to an image

Fig. 1.1 From a scene to an image

The whole process of generating a pixel image from a three-dimensional virtual scene is called rendering. The successive composition of the single techniques that are roughly outlined in Fig. 1.1 is also referred to as the rendering pipeline. The details of the rendering pipeline depend on the chosen techniques and algorithms, for instance whether shadows can be neglected or not. In [3] five different rendering pipelines are explained only within the context of lighting and shading.

Organisation of the topic

The organisation of the topic reflects the structure of the rendering pipeline. On the one hand, the techniques for two-dimensional images comprise one part of the rendering of three-dimensional virtual scenes. On the other hand, they can be viewed on their own for instance as a drawing tool.

The next topics are devoted to modelling, representation and rendering of three-dimensional virtual scenes and provide in parallel an introduction to Java 3D.

Various techniques for the hidden line and hidden surface problem—i.e., to identify which objects are hidden from the view by other objects—are described in Chap. 7.

In order to generate photo-realistic images, it is necessary to incorporate lighting effects like shading, shadows and reflections.

The topic contains links to web pages that might be of interest to the reader of this topic. All example programs mentioned in this topic are also listed in the topic including references to the pages where they are discussed in more detail.

Next post:

Previous post: