1. Trang chủ
  2. » Công Nghệ Thông Tin

computer graphics and geometric modeling - m. agoston

920 483 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 920
Dung lượng 7,77 MB

Nội dung

Computer Graphics and Geometric Modeling GOSPR 5/5/2005 5:47 PM Page i Max K. Agoston Computer Graphics and Geometric Modeling Implementation and Algorithms GOSPR 5/5/2005 5:47 PM Page iii Max K. Agoston, MA, MS, PhD Cupertino, CA 95014, USA British Library Cataloguing in Publication Data Agoston, Max K. Computer graphics and geometric modeling:implementation & algorithms 1. Computer graphics 2. Geometry—Data processing 3. Computer-aided design 4. Computer graphics—Mathematics I. Title 006.6 ISBN 1852338180 Library of Congress Cataloging-in-Publication Data Agoston, Max K. Computer graphics & geometric modeling/Max K. Agoston. p. cm. Includes bibliographical references and index. Contents: Implementation & algorithms ISBN 1-85233-818-0 (v. 1 : alk. paper) 1. Computer graphics. 2. Geometry—Data processing. 3. Mathematical models. 4. CAD/CAM systems. I. Title. T385.A395 2004 006.6—dc22 2004049155 Apart from any fair dealing for the purposes of research or private study, or criticism or review, as per- mitted under the Copyright, Designs and Patents Act 1988, this publication may only be reproduced, stored or transmitted, in any form or by any means, with the prior permission in writing of the publishers, or in the case of reprographic reproduction in accordance with the terms of licences issued by the Copyright Licensing Agency. Enquiries concerning reproduction outside those terms should be sent to the publishers. ISBN 1-85233-818-0 Springer is part of Springer Science+Business Media springeronline.com © Springer-Verlag London Limited 2005 Printed in the United States of America The use of registered names, trademarks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant laws and regulations and therefore free for general use. The publisher makes no representation, express or implied, with regard to the accuracy of the information contained in this book and cannot accept any legal responsibility or liability for any errors or omissions that may be made. Typesetting: SNP Best-set Typesetter Ltd., Hong Kong 34/3830-543210 Printed on acid-free paper SPIN 10971451 GOSPR 5/5/2005 5:47 PM Page iv This book and [AgoM05] grew out of notes used to teach various types of computer graphics courses over a period of about 20 years. Having retired after a lifetime of teaching and research in mathematics and computer science, I finally had the time to finish these books. The two books together present a comprehensive overview of com- puter graphics as seen in the context of geometric modeling and the mathematics that is required to understand the material. Computer graphics itself is a multifaceted subject, but it has grown up. It is no longer necessary that a book on graphics demon- strate the diversity of the subject with a long list of “fun” projects at the expense of the mathematics. From movies, television, and other areas of everyday life, readers have already seen what graphics is about and what it can do. It follows that one should be able to present the geometric modeling aspect of the subject in a systematic fashion. Unfortunately, the sheer amount of material that I wanted to cover meant that it had to be divided into two parts. This book contains the practical stuff and describes the various algorithms and implementation issues that one runs into when writing a geometric modeling program. The book [AgoM05] provides the mathemat- ical background for the underlying theory. Although each book can be read by itself without reading the other, one will get the most benefit from them if they are read in parallel. The intended audience of this book (and the combined two volumes especially) is quite broad. It can be used in a variety of computer graphics courses or by those who are trying to learn about graphics and geometric modeling on their own. In particu- lar, it is for those who are getting involved in what is referred to as computer-aided design (CAD) or computer-aided geometric design (CAGD), but it is also for mathe- maticians who might want to use computers to study geometry and topology. Both modeling and rendering issues are covered, but the emphasis is on the former. The basic prerequisites are that the reader has had an upper division data structure course, minimally three semesters of calculus, and a course on linear algebra. An additional course on advanced calculus and modern algebra would be ideal for some of the more advanced topics. On the companion CD there is a geometric modeling program (GM) that implements many of the algorithms discussed in the text and is intended to provide a programming environment both for further experimentation and applica- tion development. Another program (SPACE) on the CD is an application that uses some of the more advanced geometric modeling concepts to display the intrinsic Preface GOSPR 5/5/2005 5:47 PM Page v geometry of two- and three-dimensional manifolds. Both programs were written using the Microsoft Visual C++ compiler (and OpenGL) and run under Microsoft Windows 98 or later. Their source code and documentation are included on the CD. The ReadMe file on the CD lists what all is on the CD and also contains instructions for how to use what is there. As I began to develop this book on geometric modeling, one concern obviously was to do a good job in presenting a thorough overview of the practical side of the subject, that is, the algorithms and their implementation details. However, there were two other goals that were important from the very beginning. One was to thoroughly explain the mathematics and the other, to make the material as self-contained as pos- sible. In other words, pretty much every technical term or concept that is used should be defined and explained. The reason for putting all the computer graphics–related material into one book and all the mathematics into the other rather than inter- weaving the material was to keep the structure of the implementation of a modeling program as clear as possible. Furthermore, by separating out the mathematics it is easier for readers to skip those mathematical topics that they are already familiar with and concentrate on those with which they are not. In general, though, and in partic- ular as far as instructors using this book are concerned, the intent is that the mate- rial in the two books be covered in parallel. This is certainly how I always taught my courses. An added motivation for the given division was that the applied part of geo- metric modeling was often a moving target because, largely due to improvements in hardware (faster CPUs, more memory, more hard disk space, better display devices), the way that one deals with it is changing and will continue to change in the future. This is in contrast to the supporting mathematics. There may be new mathematics relevant to computer graphics in the future but it will be a long time before the math- ematics I do discuss will lose its relevance. A lot of it, in fact, is only now starting to be used as hardware becomes capable of dealing with computationally expensive algorithms. One property that sets this book apart from others on geometric modeling is its breadth of coverage, but there is another. The combined books, this one and [AgoM05], differ from other books on computer graphics or geometric modeling in an important way. Some books concentrate on implementation and basically add the relevant mathematics by tossing in appropriate formulas or mathematical algorithms. Others concentrate on some of the mathematical aspects. I attempt to be as compre- hensive on both the implementation and theory side. In [AgoM05] I provide a com- plete reference for all the relevant mathematics, but not in a cookbook fashion. A fundamental guiding principle was to present the mathematics in such a way that the reader will see the motivation for it and understand it. I was aiming at those indi- viduals who will want to take the subject further in the future and this is not possi- ble without such understanding. Just learning a few formulas is not good enough. I have always been frustrated by books that throw the reader some formulas without explaining them. Furthermore, the more mathematics that one knows, the less likely it is that one will end up reinventing something. There are instances (such as in the case of the term “geometric continuity”) where unfamiliarity with what was known caused the introduction of confusing or redundant terminology. The success or failure of the two books should be judged on how much understanding of the mathematics and algorithms the reader gets. In the case of this book by itself, it is a question of whether or not the major topics were covered adequately. In any case, because I vi Preface GOSPR 5/5/2005 5:47 PM Page vi emphasize understanding what is going on, there is a natural emphasis on theory and not on tricks of the trade. The reader will also not find any beautiful glossy pictures. Clearly, no one book can cover all that falls under the general heading of geo- metric modeling. As usual, the topics that are in fact covered and the degree to which they are covered reflect my own bias. In a large field, there are many special topics and it should not be surprising that some are not discussed at all and others only briefly in an overview. On the other hand, one would expect to see a discussion of principles and issues that are basic to the field as a whole. In that regard, I would like to alert the reader to one topic, namely, the issue of robustness of algorithms and com- putations, that really is a central issue in geometric modeling, but is not dealt with as thoroughly as it should be, given its importance. The only excuse for this is that to do this topic justice would have entailed a much larger book. It is important that readers who want to do serious work in geometric modeling realize that they will have to get more information elsewhere on this. The discussion in Section 5.10 is inade- quate (although I do devote the brief Chapter 18 to interval analysis). When it comes to the bibliography, as large as it is, it is also a victim of space constraints. In some cases I have tried to compensate for the lack of completeness by giving references to books or papers where additional references could be found. Most of this book covers material that is not new, but a few algorithms have not appeared in print before. One is the approach to trimmed surfaces based on the Vatti clipping algorithm described in Section 14.4. Another is the result in Section 17.5 about convex set intersections, which motivated the algorithm described in Section 13.2. Another aspect of the book that should be noted is Chapter 16 and the SPACE program. Although the material on intrinsic geometry in Sections 16.3 and 16.4 did not get developed as much as I would have liked, it is a start. The extensive material on topology in [AgoM05], in particular algebraic and differential topology, has hereto- fore not been found in books on geometric modeling. Although this subject is slowly entering the field, its coming has been slow. Probably the two main reasons for this are that computers are only now getting to be powerful enough to be able to handle the complicated computations and the material involves exceptionally advanced mathematics that even mathematics majors would normally not see until graduate school. Here is how the material in this book has been used successfully in teaching three different types of semester courses on computer graphics in the Department of Math- ematics and Computer Science at San Jose State University. The courses were (1) Introduction to Computer Graphics, (2) Computer Graphics Algorithms, and (3) Geometric Modeling. The first two were upper-division undergraduate courses and the third was a gradu- ate course. The prerequisites for the introductory course were three semesters of calculus, linear algebra, and an upper division course in data structures. The only prerequisite to both the algorithm and geometric modeling course was the introduc- tory computer graphics course. Some of the material in the introductory course was briefly reviewed in the other two courses. The courses used material from the fol- lowing parts of this book and [AgoM05] (but the material was not necessarily dis- Preface vii GOSPR 5/5/2005 5:47 PM Page vii cussed in the order listed, and listing a chapter or section in no way means that all of it was covered): Introduction to Computer Graphics: Chapters 1–4, a quick overview of Chapters 5, 6, 11, 12, and a brief discussion of visible surface algorithms and shading from Chapters 7 and 10. From [AgoM05]: Chapters 1–3. Computer Graphics Algorithms: Chapters 2–10, just enough of Chapter 12 to have surfaces to render, Sections 21.6– 21.8, and Chapter 22. From [AgoM05]: Chapter 1 and Sections 4.5, 4.7, 8.1–8.5. Geometric Modeling: Chapters 3–6, 11, 12, a sampling of topics from Chapters 13–15, and Sections 17.4– 17.5. From [AgoM05]: Review of parts of Chapters 1 and 2, Sections 4.2, 4.5, 4.7, Chapter 6, and Sections 8.1–8.5, 9.2–9.4, 9.9. The numbering of items in this book uses the following format: x.y.z refers to item number z in section y of chapter x. For example, Theorem 12.7.1 refers to the first item of type theorem, proposition, lemma, or example in Section 7 of Chapter 12. Algorithm 14.3.1 refers to the first algorithm in Section 3 of Chapter 14. Tables are numbered like algorithms. Figures are numbered by chapter, so that Figure 14.7 refers to the seventh figure in Chapter 14. Exercises and programming projects at the end of chapters are numbered by section. Finally, some comments on the language used in this book to describe algorithms. Even though the C/C++ language is the language of choice for most people writing computer graphics programs, with the exception of some initialization code found in Section 1.6, we have opted to use “the” more universal “standard” algorithmic lan- guage. The reason is that this book is mostly about concepts that are independent of any particular programming language and low-level optimization issues that hinge on the language being used do not play any role. Every reader with some general com- puter experience will understand the language used here (a detailed description of its syntax can be found in Appendix B) and so there seemed to be little point to restrict the audience to those familiar with C. Consider the following points: (1) There is little difference between the code that is presented and what the corresponding C code would look like, so that any translation would be straightforward. (2) The emphasis in the code and algorithms in this book is on clarity and the fact is that even in simple constructs like a for-loop or a case statement, C has more complicated syntax and uses more obscure terminology which would make it harder for the non-C reader to understand. A certain universality would be lost with no real corresponding gain. The efficiency advantage of C that is usually cited is only really viii Preface GOSPR 5/5/2005 5:47 PM Page viii significant in a relatively small number of places. It would be relevant, for example, if one wanted to implement low level drawing primitives, but that is not what this book is about. (3) C programmers who want to see C code can look at the GM and SPACE pro- grams, which are written in C++. Cupertino, California Max K. Agoston Preface ix GOSPR 5/5/2005 5:47 PM Page ix Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v I Basic Computer Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.2 The Basic Graphics Pipeline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.3 Hardware Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.4 Graphics Standards and Primitives . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.5 From Window to Viewport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 1.6 Programming Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 1.8 Programming Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2 Raster Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.2 Discrete Topology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.3 Border Following Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 2.4 Fill Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 2.5 Generating Discrete Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 2.5.1 Digital Differential Analyzers . . . . . . . . . . . . . . . . . . . . . . . 36 2.5.2 The Bresenham Line-Drawing Algorithm . . . . . . . . . . . . . . 38 2.5.3 The Midpoint Line-Drawing Algorithm . . . . . . . . . . . . . . . . 40 2.6 The Aliasing Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 2.7 Halftoning, Thresholding, and Dithering . . . . . . . . . . . . . . . . . . . . . 48 2.8 Choosing the Coordinates of a Pixel . . . . . . . . . . . . . . . . . . . . . . . . 49 2.9 More Drawing Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 2.9.1 Scan Converting Polygons . . . . . . . . . . . . . . . . . . . . . . . . . 49 2.9.2 Drawing Circles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 2.9.3 Drawing Ellipses and Other Conics . . . . . . . . . . . . . . . . . . 57 2.10 Bit Map Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 2.11 2D Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Contents GOSPR 5/5/2005 5:47 PM Page xi 2.12 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 2.13 Programming Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 3 Clipping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 3.2 Line Clipping Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 3.2.1 Cohen-Sutherland Line Clipping . . . . . . . . . . . . . . . . . . . . . 71 3.2.2 Cyrus-Beck Line Clipping . . . . . . . . . . . . . . . . . . . . . . . . . . 73 3.2.3 Liang-Barsky Line Clipping . . . . . . . . . . . . . . . . . . . . . . . . 77 3.2.4 Nicholl-Lee-Nicholl Line Clipping . . . . . . . . . . . . . . . . . . . . 81 3.3 Polygon Clipping Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 3.3.1 Sutherland-Hodgman Polygon Clipping . . . . . . . . . . . . . . . 84 3.3.2 Weiler Polygon Clipping . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 3.3.3 Liang-Barsky Polygon Clipping . . . . . . . . . . . . . . . . . . . . . . 86 3.3.4 Maillot Polygon Clipping . . . . . . . . . . . . . . . . . . . . . . . . . . 89 3.3.5 Vatti Polygon Clipping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 3.3.6 Greiner-Hormann Polygon Clipping . . . . . . . . . . . . . . . . . . 106 3.4 Text Clipping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 3.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 3.6 Programming Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 4 Transformations and the Graphics Pipeline . . . . . . . . . . . . . . . . . . . . . 111 4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 4.2 From Shape to Camera Coordinates . . . . . . . . . . . . . . . . . . . . . . . . 112 4.3 Vanishing Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 4.4 Windows and Viewports Revisited . . . . . . . . . . . . . . . . . . . . . . . . . . 119 4.5 The Clip Coordinate System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 4.6 Clipping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 4.7 Putting It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 4.8 Stereo Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 4.9 Parallel Projections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 4.10 Homogeneous Coordinates: Pro and Con . . . . . . . . . . . . . . . . . . . . 134 4.11 The Projections in OpenGL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 4.12 Reconstruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 4.13 Robotics and Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 4.14 Quaternions and In-betweening . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 4.15 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 4.16 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 4.17 Programming Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 5 Approaches to Geometric Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 5.2 R-sets and Regularized Set Operators . . . . . . . . . . . . . . . . . . . . . . . 158 5.3 Representation Schemes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 5.3.1 Early Representation Schemes . . . . . . . . . . . . . . . . . . . . . . 164 xii Contents GOSPR 5/5/2005 5:47 PM Page xii

Ngày đăng: 11/11/2013, 00:18

TỪ KHÓA LIÊN QUAN