SYMBOLIC COMPUTATION Managing Editors: 1. Enearna~äo P. Hayes Computer Graphics Editors: K. B0 1.D. Foley R. Guedj 1. W. ten Hagen F.R.A. Hopgood M. Hosaka M. Lueas A. G. Requieha G. Enderle K. Kansy G. Pfaff Computer Graphics Programming GKS - The Graphics Standard With 93 Figures, Some in Color Springer-Verlag Berlin Heidelberg NewYork Tokyo 1984 Dr. Günter Enderle Kemforschungszentrum Karlsruhe Weberstraße 5 7500 Karlsruhe Dr. Klaus Kansy Gesellschaft für Mathematik und Datenverarbeitung Schloß Birlinghoven 5201 St. Augustin 1 Dipl.-Inform. Günther Pfaff Technische Hochschule Darmstadt Alexanderstraße 24 6100 Darmstadt ISBN-13: 978-3-642-96709-2 e-ISBN-13: 978-3-642-96707-8 001: 10.1007/978-3-642-96707-8 Library of Congress CataJoging in Publication Data Enderle, Günter, 1944- Computer graphics programming. (Symbolic computation. Computer graphics) Bibliography: p. Includes index. I. Computer graphics-Standards. I. Kansy, Klaus, 1945- Il. Pfarr, Günther, 1951- . III. Title. IV. Series. T385.E531984 001.64'43 83-12438 TSBN-13: 978-3-642-96709-2 (U.S.) This work is subject to copyright. All rights are reserved, whether the whole or part of the material is concemed, specifically those of translation, reprinting, re-use of illus trations, broadcasting, reproduction by photocopying machine or similar means, and storage in data banks. Under §54 of the German Copyright Law where copies are made for other than private use, a fee is payable to "Verwertungsgesellschaft Wort", Munich. © Springer-Verlag Berlin Heidelherg 1984 Softcover reprint of the hardcover 1s t edition 1984 2145/3140-543210 FOREWORD For several years the authors of this book have been involved in the design and the national and international review of the forthcoming graphical standard. When the end of this process could be foreseen and the International Standard "Graphical Kernel System" (GKS) was cast into its. final form, the urgent need arose for detailed information to the graphics community about this stan dard and for the education of graphics programmers. One major goal of GKS, besides the portability of graphical application programs and the device inde pendence, is "programmer portability" by establishing a common base for train ing of graphics programmers. Having accompanied the path of GKS from the very early stages of defining the basic concepts and designing its first versions up to the final draft of the International Standard, we feIt it worthwhile to start the venture of a text book on computer graphics programming based on GKS. This book is aimed, at one hand, at graphics users, experts and managers who want to get an overview of the new standard and a better understanding of its concepts. On the other hand, it addresses the graphics programmers who want to use GKS for realizing their graphical applications. It can serve as the base for teaching and studying functions, concepts and methods of GKS. Addi tionally, it will be a valuable source of information for implementors of GKS. One of the main application areas for computer graphics is Computer Aided Design (CAD). GKS can serve as an excellent base on which portable CAD systems can be designed. A thorough introduction into CAD is presented in another book of this SYMBOLIC COMPUTA TION series: CAD - Funda mentals and System Architectures - by J. L. Encarna~äo and E. G. Schlechten dahl [ENCA82a]. The standard document defining GKS has to be complete and consistent, it uses a formal description where possible, and it has to adhere to certain formal rules for the specification of the standard. Only rarely it gives informal introductions, examples, or explana~ions for the .decisions taken. For an over view, however, an informal and incomplete presentation will be the better way, and teaching has to use examples, figures and explanations. We want to offer an easy access to the GKS building and to the graphics environment in which it is situated. Of course, in a book dealing with a standard, it is unavoidable to use infor mation from the standard document. The authors were members of the editorial team that, up to GKS version 4.8 [DIN79] was designing GKS. Since then we were taking part in developing the following versions of the GKS document up to the GKS standard. However, the GKS document is the result of combined contributions from many different persons. It is an excellent document and, VI Foreword in several parts, there is no better way to describe the GKS standard. In these cases parts of the document are reproduced in this book with no or little change. The book is divided into four main parts. In Part I, an overview of the integration of GKS into the Computer Graphics framework is given and the principles and basic concepts of GKS are introduced and explained. Part II describes the process of the GKS design. GKS, designed by the committee NIjUA-5.9 of the DIN (Deutsches Institut für Normung), has been reviewed and refined in a long international process that was carried on by experts in the working group TC97 jSC5jWG2 of the ISO (International Organization for Standardization). The groups participating in this process, important events and major design decisions are presented as well as the methods used for han dling the review and the revision ofthe standard draft and for resolving conflicts. Part III of the book is devoted to explaining the GKS functions and their application. All GKS functions and their parameters are described, both in the language-independent form presented in the standard document, and in the FORTRAN subroutine version. Various examples are given both in the FORTRAN and Pascal programming languages. Exercises can serve for deepen ing the understanding of the functions and they can be a guide for teaching Computer Graphics programming on the basis of GKS. The last part of the book covers the various interfaces of the standard within the Computer Graphics environment. Before a standardized graphics system can be used, it has to be implemented on existing hardware and operating systems. There is adesire that such implementations be validated and that their conformity to the standard be certified. The application of the standard in a given programming language is made possible by adapting the standard functions to the rules of that language. We describe the FORTRAN binding of GKS. Further interfaces exist to graphical input and output devices, and to graphics metafiles for storage of pictures. The communication between hu mans is made possible by a common graphics terminology developed parallel to the GKS standard. Finally, expected extensions of GKS in the areas of 3D-graphics applications are outlined. Novices to the Computer Graphics field and persons that want to get an overview over GKS concepts should read Part land then use the table of contents or the index at the end of the book to find information of special interest to them. Part II addresses itself to persons interested in standards and how they are created. Programmers and scientists designing graphics applica tions will find a detailed description of the GKS functions in Part III. This part will also be the main reference for training Computer Graphics program ming on the ground of GKS. Part IV will be of special importance to GKS implementors. We hope this book will help to disseminate the application of the Graphical Kernel System, to understand its principles and concepts, and to assist in Com puter Graphics education on the base of the first standard in Computer Graph ics. Karlsruhe, Bonn, Darmstadt, July, 1983 Günter Enderle Klaus Kansy Günther Pfaff DEDICATION The subject of this book the Graphical Kernel System - has been developed in a long process since 1976 and finally evolved as an International Standard. This book is dedicated to the graphics experts that designed GKS within the DIN (Deutsches Institut für Normung) and that accompanied its evolution in the international review process within the working group TC97/SC5(WG2 "Computer Graphics" of the ISO (International Organization for Standardiza tion) and various national standardization organizations. More than 100 scien tists from all over the world invested probably more that 50 man-years in this adventure, making GKS to the consistent and complete graphics standard it is today, developing a concise terminology for Computer Graphics, establish ing the firm base of a methodology for Computer Graphics, and co operating in a spirit of mutual confidence and friendship. Members and experts ofDIN-NI/UA-5.9 "Computer Graphics" 1975-1982: R. Anderl, E. Bauböck, H. Borik, H.-G. Borufka, L. Brandenburger, H. Brüggemann, P. Dobrowolski, R. Eckert, P. Egloff, J. Encarnac;ao, G. Enderle, B. Fink, H. Flegel, R. Gnatz, M. Gonauser, H. Grauer, I. Grieger, Th. Johannsen, E. Jungmann, K. Kansy, R. Karg, W. Klingenberg, R. Konkart, H. Kuhlmann, G. Lang-Lendorff, St. Lewan dowski, G. Mitte!straß, G. Nees, H. Nowacki, D. Otto, K. Pasemann, G. Pfaff, F.-J. Prester, K. Reumann, J. Rix, H.-J. Rosenberg, F.-K. Roth, E. G. Schlechtendahl, J. Schönhut, R. Schuster, D. Stroh, D. Völkel, J. Weiss, J. Weskott, H. Wetze!, P. Wißkir ehen. Members and experts of ISO TC97/SC5/WG2 "Computer Graphics" 1977-1982: J. Bettels (CH), K. Bö (N), P. Bono (USA), H.-G. Borufka (D), K. Brodlie (UK), L. Brown (NL-C), F. Canfield (USA), St. Carson (USA) J. Chin (USA), U. Cugini (I), J. Daabeck (DK), G. Dettori (I), F. de Witte (NL), D. Duce (UK), A. Ducrot (F), R. Dunn (USA), R. Eckert (D), P. Egloff (D), J. Encarnac;ao (D), G. Enderle (D), J. Ero (NL), D. Fisher (UK), A. Francis (UK), J. Gallop (UK), P. Gauriat (F), R. Gnatz (D), T. H. Gossling (UK), I. Grieger (D), R. Guedj (F), Y. Gueniot (F), Ch. Hatfield (USA), W. Herzner (A), B. Herzog (USA), F. R. A. Hopgood (UK), M. Hosaka (J), K. Kansy (D), R. Kessener (NL), F. Kimura (J), J. Kivi (SF), A. Kotzauer (GDR), G. Krammer (H), H. Kuhlmann (D), R. Langridge (UK), M. Lucas (F), V. Lvov (USSR), J. Matthijs (B), J. Michener (USA), L. Moltedo (I), G. Nees (D), H. Newman (C), Ch. Osland (UK), Ch. Pellegrini (CH), G. Pfaff (D), A. Planman (SF), M. Polisher (USA), F.-J. Prester (D), R. Puk (USA), T. Reed (USA), K. Reumann (D), J. Rix (D), D. S. H. RosenthaI (UK), J. Rowe (USA), J. Schönhut (D), B. Shepherd (USA), E. Sonderegger (USA), R. Spiers (UK), D. Stroh (D), R. Sulonen (SF), D. Sutcliffe (UK), Z. Tolnay-Knefely (H), P. ten Hagen (NL), J. van der Star (NL), H. van Velden (NL), A. Warman (UK), M. Wein (C), J. Weiss (A), M. Whyles (USA), K. Willet (USA), A. Williams (UK), G. Williams (C), R. Williams (USA), P. Wißkirchen (D). CONTENTS Part I - Introduction to Computer Graphics Based on GKS 1 1 What is Computer Graphics? . . 2 1.1 Definition of Computer Graphics 2 1.2 Areas of Computer Graphics 2 1.3 Impact of the Graphical Kernel System on Computer Graphics 4 2 Intention and Contents of Part I 4 3 The Computer Graphics User . . 5 4 Interfaces of the Graphical Kernel System 6 5 Principles and Goals of the Graphical Kernel System 8 6 Main Concepts of the Graphical Kernel System 11 7 Creating Graphical Output 13 7.1 Coordinate Graphics and Raster Graphics 13 7.2 Output Primitives and Attributes 14 7.2.1 Output Primitives 15 7.2.2 Output Primitive Attributes 16 7.3 Indices, Bundles and Tables 20 8 Coordinate Systems and Transformations 25 8.1 Coo rdinate Systems 25 8.2 Transformations 26 8.3 The Normalization Transformation 26 8.4 Clipping 28 9 The Graphical Workstation 28 9.1 Routing Output to Workstations 29 9.2 Types of GKS Workstations 30 9.3 The Workstation Transformation 30 9.4 The Deferral State 32 9.5 Addressing Special Workstation Capabilities 32 X Contents 10 Input 33 10.1 Interactive Computer Graphics 33 10.2 Logical Input Device Classes 33 10.3 Operating Modes 34 10.4 Echos, Prompts, and Input Device Initialisation 36 11 Segments 37 11.1 Structuring Pictures 37 11.2 Manipulating Segments 38 11.3 Segment Attributes 39 11.4 Segment Transformations 40 11.5 Workstation-Dependent and Workstation-Independent Segment Storage 40 11.6 Copying Segments 41 12 The GKS Metafile 42 12.1 Graphics Metafiles 42 12.2 The Metafile Interface 43 12.3 The Metafile Format 44 13 States and State Lists 45 13.1 The GKS Operating State 45 13.2 The State Lists 45 13.3 Inquiring State List Values 46 14 Error Handling 47 Part 11 - The Process of Generating a Standard 49 1 The Evolution of Computer Graphics 50 1.1 Graphical Devices 50 1.2 Graphics Software 51 1.3 SEILLAC I 53 2 Committees, People and Events 55 2.1 Graphics Standardization Committees 55 2.2 People 57 2.3 Overview over Main Events 57 3 GKS Review - Issues and Their Solution 60 3.1 Scope of the Standard 62 3.2 Output Primitives 64 3.3 Segmentation 67 3.4 Input. 71 3.5 Transformations 74 3.6 Workstation Concept 77 Contents XI Part In - Graphics Kernel System Programming 79 1 Format and Structure of Part III 80 1.1 Contents of Part III 80 1.2 Format of GKS Function Definitions 81 1.2.1 Example for the Definition of GKS Functions 81 1.2.2 Format of Language-Independent Definition 81 1.2.3 Format ofFORTRAN-Definition 83 1.3 Format of Examples 84 1.3.1 Example for an Example 84 1.3.2 Format of Pascal Examples 84 1.3.3 Format of FORTRAN Examples 85 1.4 Exercises 85 2 Levels 86 2.1 Overview 86 2.2 Functionality of the GKS Levels 88 2.2.1 The Minimal or Lowest Level of GKS (Level Oa) 89 2.2.2 Level Ob 92 2.2.3 LevelOc 93 2.2.4 Levels la, 1b , lc 94 2.2.5 Levels 2a, 2b, 2c 96 2.3 Impacts on Writing Portable Application Pro grams 97 2.4 Exercises 98 3 States and State Lists 99 3.1 Int rodu ction 99 3.2 Operating States 100 3.3 Functions Allowed in Individual States 103 3.4 State Lists 105 3.5 Basic Control Functions 111 3.6 Examples 113 4 Workstations 115 4.1 Introduction 115 4.2 Workstation Description Table 117 4.3 Workstation State List 124 4.4 GKS Functions Applying to Workstations 128 4.5 Workstation Control 134 4.6 Deferring Picture Changes 139 4.7 Addressing Workstation Capabilities Not Covered by GKS 144 4.8 Examples 146 4.9 Exercises 148 5 Transformations 149 5.1 Coordinate Systems 149 XII Contents 5.2 Normalization Transformation 150 5.3 Workstation Transformation 152 5.4 Clipping ........ . 155 5.5 Transformation ofLOCATOR and STROKE Input 157 5.6 Examples ... . 159 5.7 Exercises ... . 167 6 Output Primitives 168 6.1 Introduction 168 6.2 POLY LINE Primitive 176 6.2.1 Global POLY LINE Attributes 177 6.2.2 Workstation-Dependent POLYLINE Attributes 180 6.3 POLYMARKER Primitive ........ . 181 6.3.1 Global Polymarker Attributes . . . . . . . . 183 6.3.2 Workstation-Dependent POLYMARKER Attributes 186 6.4 TEXT Primitive . . . . . . 187 6.4.1 TEXT Attributes for Beginners 188 6.4.2 Character Body 190 6.4.3 Text Extent Rectangle 192 6.4.4 Text Font and Precision 194 6.4.5 Setting Global Text Attributes 196 6.4.6 Workstation-Dependent TEXT Attributes 201 6.5 FILL AREA Primitive .. . . . . . . 203 6.5.1 Global FILL AREA Attributes .... 205 6.5.2 Workstation-Dependent FILL AREA Attributes 210 6.6 CELL ARRAY Primitive . . . . . . . . . . 212 6.7 GENERALIZED DRAW ING PRIMITIVE (GDP) 214 6.8 Attribute Setting Functions Conceming All Primitives 216 6.8.1 Setting the Colour Table 216 6.8.2 Setting the Aspect Source Flags 217 6.8.3 Setting the Pick Identifier 219 6.9 Examples 220 6.10 Exercises . 228 7 Segments . 230 7.1 Introduction 230 7.2 How are Segments Generated ? 231 7.3 What is Stored in a Segment? . 232 7.4 When are Primitives Taken off the Transformation Pipeline ? 232 7.5 Segment Creation and Deletion ......... . 235 7.6 Manipulation of the Segment Attributes . . . . . . . 239 7.7 The Workstation-Independent Segment Storage (WISS) 245 7.8 Different Levels of Segmentation 250 7.9 Utility Functions 250 7.10 Examples 252 7.11 Exercises ... 265 8 Input ..... 267 8.1 Introduction to Logical Input Devices 267