2D and 3D graphics with PostScript and PHIGS

2D and 3D graphics with PostScript and PHIGS

Comput. & Graphics, Vol. 18. No. 3, pp. 295-298. 1994 Copyrighl (c, 1994 ElsevierScience Lid Printed in Great Britain 0097-8493/94 $6.00 + .00 Pergam...

646KB Sizes 0 Downloads 57 Views

Comput. & Graphics, Vol. 18. No. 3, pp. 295-298. 1994 Copyrighl (c, 1994 ElsevierScience Lid Printed in Great Britain 0097-8493/94 $6.00 + .00

Pergamon

0097-8493(94) E001 I-L

Computer Graphics in Education

2D AND 3D GRAPHICS WITH POSTSCRIPT AND PHIGS JEAN-CLAUDE LAFON Laboratoire 13S, C.N.R.S and Ecole d'Ingrnieurs ESSI, ESSI, Route des Colles, BP 145-06903 Sophia Antipolis Cedex, France Abstract--ln this paper we present a case study of the use of PostScript and PHIGS to teach 2D and 3D computer graphics to computer science students. As these students are planning to work in the computer graphic field, they need to have very good practical experience in the development of computer graphics programs in order to be quickly efficient in an industrial project. A 2-year experiment in the use of PostScript and PHIGS as practical tools to achieve this goal is described with an emphasis on all the aspects of the computer graphics knowledge that can be studied in this way. All the developments are made with public (free) versions of PostScript and PH1GS on low cost X terminals or SUN workstations. So, this project demonstrates that it is possible to teach computer graphics to numerous graduate students very efficiently with a low cost. I. INTRODUCTION To learn computer graphics, students have to study the theoretical basis, but also need to develop their own graphical applications in order to have an indepth knowledge of this field and practical programming techniques. There exist now very efficient graphical workstations and very beautiful software in graphical modelling and rendering of 3D objects. Our problem in teaching this field to numerous graduate students (80 per year) in an academic institution, is that we don't have the money to buy such workstations and software, and that the time devoted to the study of this field is limited (100 hours per student). We need to

teach this Jield in a veo' efficient way, with low cost materials and s~2/iware. After some other experiments, we decided in October 1991 to use PostScript to enable our students to develop 2D computer graphics programs and to use PHIGS for 3D modelling, animation, and visualization techniques. The materials were low cost X terminals and some color SUN workstations. The interest of this choice was that students can have very easy access to these materials in order to write their own programs.

play, Printers) with an emphasize on the architecture of raster display. The study of colors is also done in this part. 2.2. 2D graphics The fundamental concepts of 2D graphics are first studied by a presentation of the GKS standard in which the notions of World coordinates ( W C ) , Normalized Device coordinates ( N D C ) , and Device coordinates (DC) and of the Windows--Viewports transformations are very clear. The concepts of Logical input-output, of workstations and the different modes of interactivity of GKS (Sample, Request, Event) are also presented in the light of methodology of graphics system design. Then, we study the theoretical aspects of 2D Graphics: 2D transformations; discrete topology; image data structures (Bitmap, quadtrees); generation of lines (Bresenham); clipping; region filling-curves ( B-splines, Beziers curves): fractal images (IFP); electronic publishing and printing. The practical part of 2D graphics learning is the study of PostScript and the development of PostScript programs.

2.3. 3D objects modelling and visualization 2. COMPUTER GRAPHICS COURSE'S PROGRAM This is a one-semester course with theoretical lectures (40 hours) and practical computer graphic programming (60 hours). It deals with the study of 2D computer graphics, the modelling of 3D objects (wire frame, surfacic, and solid) and the realistic visualization of 3 D objects (image synthesis). Applications to Computer Assisted Design are also studied together with the use of Artificial Intelligence techniques in CAD. The technical part of this course deals with graphics standards (PostScript, P H I G S ) and with the presentation of some existing softwares (CATIA, EUCLID, AUTOCAD...). The different topics follow.

2.1. Graphics hardware This is a classical presentation of graphical input/ output technology ( C R T Display, Plasma Panel Dis-

In the theoretical part we present an indepth study of the following notions: homogeneous coordinates; 3D transformations; parametric 3D curves: biparametric cubic surfaces; B-splines, Nurbs-3D viewing (planar projections--3D Clipping); 3D models: wireframe, surfacic, solid (B Rep, CSG). PHIGS is used to illustrate all these notions and to enable our students to develop an individual project. All the problems of realistic computer representation of solids (coloring, light reflection, shadows and texture, ray t r a c i n g . . . ) are only presented in one lecture, as it is not the main objective of this course. 2.4. Computer assisted design This part is oriented to the presentation of the most advanced tools of CAD: parametrized objects: data exchanges (the SET standard ); use of constraints ( CSP ) 295

296

J.-C. LAFON

and artificial intelligence technics in CAD; object-oriented databases in CAD. 3. A POSTSCRIPT PROJECt To illustrate all the theoretical notions of 2D computer graphics, students use PostScript to conceive and realize one individual project. As our students are computer science students with a good practice of programming languages as C, C++, LISP, PROLOG, but in general no knowledge of PostScript, we decided to use a "programming by examples approach" to illustrate the different possibilities of the PostScript language. In this way, we don't spent too much time in the study of the PostScript operators or in the precise syntax of this language. This use of PostScript enables us to illustrate the following key points of 2D graphics:

q

• The concepts of object space, and screen space: This











is the user coordinate system of PostScript, which is the same for all printers with PostScript interpreters. The graphics state and paths: These notions are very important in PostScript. A path is constructed with simple graphics primitives such as moveto, lineto, curveto, arcto, closepath, together with graphics primitives defined by such operators as linewidth, setgray, setdash, currentlinejoin, setrgbcolor. It is very easy to the students to experiment (in the interpretative way of PostScript) the use of these graphics state operators together with the simple graphics operators to realize some simple drawings. 2D transformations: These transformations (and the interest of homogeneous coordinates) are illustrated in PostScript with the coordinate system and matrix operators as initmatrix, concatmatrix, invertmatrix, translate, scale, rotate, transform, dtransform. Clipping and filling: The clip, eoclip, clippath, charpath operators of PostScript illustrate the different algorithms to detect the interior of an area and to fill it with some colours or patterns. Recursivity: With the use of the recursivity of PostScript it is very easy to illustrate fractales (see for instance, Fig. 1). Characters and texts typesettings: At the present time, PostScript is really the only possibility to show to students all the problems in computer text processing. With PostScript operators such as definefont, findfont, scalefont, setfont, widthshow, kshow or stringwidth, students can realize programs to write a text along an arbitrary line and to do justification of the text.

All these points (together with the study of the execution model and the program structure of PostScript) are studied with some examples of drawings and some classical programs to write (see for instance [2]). So, after some hours to study these key points of 2D graphics, an individual project is given to the students: design a LOGO for our school or a tapestry pattern. These subjects leave a great freedom to the students, stimulating their creativity and also perhaps their artistical talent (but it is not our first objective).

Fig. 1. Fractal trees. Some of the results obtained are given in the Figs. 2-3. 4. 3D MODELLING, ANIMATION AND VISUALIZATION WITH PHIGS The study of 3D computer graphics is done by a collective project in PHIGS (two or three students are working together on the same program). io-,~ '

..oo*

t*e

•eQ*

Fig. 2. A logo.

2D and 3D graphics with PostScript and PHIGS

2~)7

4.2. Animation Cranes are also moving objects, so students also have to model their animation (with moving parts as the bottom on the rails, the tower, the jib, the wagon, and the load itself). The motion is described in a Cartesian coordinate frame. The relative position and orientation between objects is represented by homogeneous transformations between coordinate systems attached to links. The geometric transformation is described by homogeneous transformation or homogeneous matrix multiplication. The compactness of the homogeneous transformation matrices is advantageous for expressing consecutive transformations. This is well adapted with the viewing pipeline of PHIGS[5], which is used for this implementation.

Fig. 3. Tapestry pattern.

The subject of the last project was to realize a PHIGS program to create cranes, to animate them, and to visualize these moving cranes. We briefly described here the contents of this project and its interest to study PHIGS and 3D computer graphics. We don't give here an introduction to PHIGS, but the interested reader can find an introduction in [4], a fairly good presentation of PHIGS in the book of Hopgood and Duce, A Primerfl~r Phigs[ 5 ] and of Kasper and Arns, Graphi¢:sProgramming with Phigs and Phigs+[ 6 ], and a very complete description in the two books [7] and [8] of Tom Gaskins.

4.1. Objects modeUing A crane is in fact a rather complex object that is composed of different subobjects: Crane Rail Tower Top of Worker

Tower Cab

Carriage The hierarchical data structure of PH1GS is very convenient to the modelling of such objects. Each object is defined in its local coordinate system and is approximated by rectangle parallelepiped. So, in this part of the project, students can study the PHIGS structure hierarchy, the structures operators, the local and global modelling transformations and the structure editing of PHIGS.

4.3. Visualization To visualize cranes, students have to define the position of the camera and the type of projection. They have to study the viewing pipeline and the viewing model of PH1GS together with the different parallel and perspective projections. They mainly used monochrome X-terminals to develop their programs, but because they can also use some colour workstations, we imposed them to possibly visualize solid objects with different colours. In doing so, they also have to study and use the different PHIGS attributes and also the concepts of PH1GS Workstations. A great interest of this approach is also to show them the importance of program portability (one of the main objective of PHIGS). As this development was made under the R4 version of X-Window, we cannot use PHIGS+ facilities of shading and illumination of objects. Nevertheless, they have obtained some good results and attained a good programming practice (this was our main objective). 4.4. L.'ser inter/ace Students have also developed a graphical man-machine interface to enable the end user to specify the cranes to be placed on the land, and to specify some parameters. This interface is done with OSF-MOTIF, which was unknown for most of them. This was also another interest of this project to teach them how to develop in parallel the graphical man-machine interface and the application by specifying precisely all the widgets and all the callbacks used. 5. CONCLUSION

After 2 years of experiment, we can say that this use of both Postscript and PHIGS to teach 2D and 3D graphics programming has been a success. At the beginning, students are surprised by this stack-based programming language, but very quickly they enjoy very much creating new drawings with Postscript and using it to make individual projects. Students were also very motivated by the conception and the achievement of a collective project in PHIGS, and they learned PHIGS quite easily in this way. It

298

J.-C. LAFON

T [

~la~,m~t

ds la ¢~0

.

.

.

.

.

.

.

.

.

.

.

~.ww

J

Fig. 4.

was also interesting to include the realization of a motif interface in this graphical project. As all our developments are made under X 11 R4, we do not have the option of using PEX (The PHIGS Implementation for X), but this is our objective for the forthcoming year. At the end of their studies, our students must have spent 5 or 6 months in an industrial training period. Due to the diversity of materials and software presently in use in the French companies, they often have to develop with another tool, such as PostScript and PHIGS. In all cases, they were able to learn and use very quickly other similar tools like GL, or more complex C A D software like CATIA, EUCLID, PRO-ENGINEER. These facts also illustrate the interest in using standards like PostScript and PHIGS to teach the 2D and 3D graphics programming concepts. Presently, to our knowledge, there is not one unique tool to learn both 2D and 3D graphics that combines the 2D possibilities of PostScript (path constructors, arbitrary region clipping, fonts manipulation) and perhaps more facilities for bitmap image definition and manipulation, together with the 2D-3D advantages of

PHIGS (structure network definition and manipulation, modelling transformations, viewing and rendering pipeline, workstations definitions). This seems to be a challenging project. REFERENCES

1. Adobe Systems Incorporated, PostScript Language Referen~z, Manual. Addison Wesley, Reading, MA (1985 ). 2. B. Thomas, A PostScript Cookbook, Macmillan, New York (1988). 3. S. Roth (Ed.), Real World PostScript. Addison Wesley, Reading, MA (1988). 4. D. Shuey, D. Bailey, and T. P. Morrissey, PHIGS: A standard, dynamic, interactive graphics interface. IEEE Comp. Graph. Appl. August, 50-57 (1986). 5. F. R. A. Hopgood and D. A. Duce, A Primerjbr PHIGS, John Wiley and Sons, Chichester ( 1991 ). 6. J. E. Kasper and D. Arns, Graphics Programming with PttlGS and PHIGS+, Addison Wesley, Reading, MA (1993). 7. T. Gaskins, PHIGS Re[~'rence Manual. O'Reilly and Associates, Sebastopol. ( 1992 ). 8. T. Gaskins, PHIGS Programming Manual, O'Reilly and Associates, Sebastopol. ( 1992 ). 9. S.W. Thomas, X and PEX Programming (Tutorial Note #3), Eurographics '90 (1990).