[lecture notes in computer science] computational science and its applications – iccsa 2005 volume...

10
Numerical-Symbolic Matlab Toolbox for Computer Graphics and Differential Geometry AkemiG´alvez 1, and Andr´ es Iglesias 1,2 1 Department of Applied Mathematics and Computational Sciences, University of Cantabria, Avda. de los Castros, s/n E-39005, Santander, Spain 2 Department of Computer Science, University of Tsukuba, Laboratory of Advanced Research, Building B, Room # 1025, Kaede Dori, 305-8573, Tsukuba, Japan [email protected], [email protected] http://personales.unican.es/iglesias Abstract. In the last few years, computer algebra systems (CAS) have become standard and very powerful tools for scientific computing. One of their most remarkable features is their ability to integrate numerical, symbolic and graphical capabilities within a uniform framework. In ad- dition, in most cases, these systems also incorporate a nice user interface making them specially valuable for educational purposes. In this work we introduce a user-friendly Matlab toolbox for dealing with many of the most important topics in Computer Graphics and Differential Geometry. The paper describes the main features of this program (such as the tool- box architecture, its simulation flow, some implementation issues and the possibility to generate standalone applications) and how the symbolic, numerical and graphical Matlab capabilities have been effectively used in this process. 1 Introduction Much progress has been made in the world of computer algebra systems (CAS) during the last few years [2, 8, 9, 10, 11]. Nowadays, computer algebra systems (such as Mathematica, Maple, Derive, Axiom, Matlab, Scilab, etc.) have become standard and very powerful tools for scientific computing. As a consequence, they imply strong changes, almost a revolution, in the way of understanding scientific computing, with new mathematical algorithms, advanced programming features, numerical/symbolic integration tools, nice user interfaces, etc. In this paper we will focus on the system Matlab [1], a numerical-oriented package that also includes a number of symbolic computation features. In fact, its most recent versions incorporate a Maple kernel totally integrated into the numerical layer. Even although such symbolic capabilities are not as powerful Corresponding author. O. Gervasi et al. (Eds.): ICCSA 2005, LNCS 3482, pp. 502–511, 2005. c Springer-Verlag Berlin Heidelberg 2005

Upload: chih-jeng-kenneth

Post on 03-Feb-2017

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: [Lecture Notes in Computer Science] Computational Science and Its Applications – ICCSA 2005 Volume 3482 || Numerical-Symbolic Matlab Toolbox for Computer Graphics and Differential

Numerical-Symbolic Matlab Toolbox forComputer Graphics and Differential Geometry

Akemi Galvez1,� and Andres Iglesias1,2

1 Department of Applied Mathematics and Computational Sciences,University of Cantabria, Avda. de los Castros, s/n

E-39005, Santander, Spain2 Department of Computer Science, University of Tsukuba,

Laboratory of Advanced Research, Building B, Room # 1025,Kaede Dori, 305-8573, Tsukuba, Japan

[email protected], [email protected]

http://personales.unican.es/iglesias

Abstract. In the last few years, computer algebra systems (CAS) havebecome standard and very powerful tools for scientific computing. Oneof their most remarkable features is their ability to integrate numerical,symbolic and graphical capabilities within a uniform framework. In ad-dition, in most cases, these systems also incorporate a nice user interfacemaking them specially valuable for educational purposes. In this workwe introduce a user-friendly Matlab toolbox for dealing with many of themost important topics in Computer Graphics and Differential Geometry.The paper describes the main features of this program (such as the tool-box architecture, its simulation flow, some implementation issues and thepossibility to generate standalone applications) and how the symbolic,numerical and graphical Matlab capabilities have been effectively used inthis process.

1 Introduction

Much progress has been made in the world of computer algebra systems (CAS)during the last few years [2, 8, 9, 10, 11]. Nowadays, computer algebra systems(such as Mathematica, Maple, Derive, Axiom, Matlab, Scilab, etc.) have becomestandard and very powerful tools for scientific computing. As a consequence, theyimply strong changes, almost a revolution, in the way of understanding scientificcomputing, with new mathematical algorithms, advanced programming features,numerical/symbolic integration tools, nice user interfaces, etc.

In this paper we will focus on the system Matlab [1], a numerical-orientedpackage that also includes a number of symbolic computation features. In fact,its most recent versions incorporate a Maple kernel totally integrated into thenumerical layer. Even although such symbolic capabilities are not as powerful

� Corresponding author.

O. Gervasi et al. (Eds.): ICCSA 2005, LNCS 3482, pp. 502–511, 2005.c© Springer-Verlag Berlin Heidelberg 2005

Page 2: [Lecture Notes in Computer Science] Computational Science and Its Applications – ICCSA 2005 Volume 3482 || Numerical-Symbolic Matlab Toolbox for Computer Graphics and Differential

Numerical-Symbolic Matlab Environment for CG and Differential Geometry 503

as their counterpart in Maple, they are much faster and still very suitable formany purposes. In addition, the graphical Matlab capabilities (based on OpenGL graphical routines and, hence, much better than those from many otherCAS) and its excellent graphical user interface improve substantially the powerof the system.

All these features have been exploited in this work to implement a uni-fied symbolic/numerical Matlab Graphical User Interface (GUI) and toolbox forComputer Graphics and Differential Geometry. In this paper we describe themain features of this program and how the symbolic, numerical and graphicalMatlab facilities have been applied to tackle this issue.

The structure of this paper is as follows: Section 2 describes the architecture ofthis symbolic/numerical Matlab toolbox, its main components and the simulationflow. Some implementation issues and the possibility of compiling and linkingthe toolbox files for generating standalone applications are also discussed in thissection. Then, Section 3 analyzes the performance of this system by describingsome illustrative examples. Finally, Section 4 closes with the main conclusionsof this work.

2 The Matlab Toolbox Architecture

This section analyzes the architecture of the Matlab toolbox introduced in thispaper. In addition, some implementation issues as well as the simulation flow arebriefly described in this section. Finally, we discuss the possibility of compilingand linking the toolbox files for standalone applications.

2.1 System Architecture

The main system components as well as the simulation flow are depicted inFigure 1. In that figure, a dashed line is used to enclose those modules associ-ated specifically with our Matlab toolbox. Basically, it consists of the followingelements (see Figure 1):

– a graphical user interface (GUI): Matlab provides a set of routines to createGUIs, incorporating menus, push and radio buttons, text boxes and manyother interface devices. Most of computer algebra systems do not supportGUIs. This fact was specially valuable for us, since our pedagogical orienta-tion requires an interactive and user-friendly program. In addition, the GUItakes advantage of the powerful Matlab graphical capabilities. This was oneof the most important features we are interested to deal with, and finally,one of the most important reasons to choose Matlab. Graphical Matlab fea-tures allow interactivity in the way of manipulating graphics, support manydrawing commands and provide the components necessary to create com-puter graphics, including shading, texture mapping, hidden line removal,lighting, z-buffering, etc. In fact, we think they improve the usual graphicalfacilities available in other computer algebra systems. Reference [3] discusses

Page 3: [Lecture Notes in Computer Science] Computational Science and Its Applications – ICCSA 2005 Volume 3482 || Numerical-Symbolic Matlab Toolbox for Computer Graphics and Differential

504 A. Galvez and A. Iglesias

(6)

Matlab GUIs

Open GL

(1)

Graphical User Interface

Matlab Programming Language

Matlab Toolbox Matlab Functions

Over 120 Matlabfunctions developed by the authors in Matlab

Symbolic Kernel(Maple functions)

MATLAB KERNEL

Numerical Kernel Matlab functions m files C/C++ mex files Matlab API filesMath Built-in files

MATLAB TOOLBOX

(3)(4)

(2)

(5)

Fig. 1. Architecture of the Matlab GUI and toolbox described in this paper

these and other (oriented to computer graphics) interesting graphical Matlabfeatures.

In our system, the GUI is comprised of a set of different windows asso-ciated with different tasks. Some windows are for differential geometry cal-culations and include some dialogue boxes in order to allow users to inputthe symbolic equations of the geometric entities. Other windows are mostlyintended for graphical outputs and include a number of different commandsfor visualization. Those windows will be illustrated in Section 3.

– a Matlab toolbox: In our system, we implemented more than 120 functions forboth Computer Graphics and Differential Geometry. Those functions call forauxiliar functions defined in Matlab kernel and allow us to deal with paramet-ric curves and surfaces and other geometric entities. Of course, the librariesmust be continuously updated, so the system must be flexible enough toallow the programmer to improve the algorithms and codes in an efficient,quick and easy way. Interesting enough is the fact that we can deal withthose entities in either numerical or symbolic way. In this last case, we in-voke the symbolic Math Toolbox, which is based on the kernel of Maple, oneof the most popular symbolic computation programs.

Another important factor to choose Matlab concerns the efficiency. SinceMatlab is based on C, it runs faster than other analyzed symbolic and nu-merical programs. Moreover, its basic element is an array that does notrequire dimensioning, so it takes less time to be computed. Although thesymbolic operations are not suitable for these based-on-array advanced fea-tures, numerical and graphical operations (which are the key ingredient ofmany commands for computer graphics and scientific visualization) havebeen greatly improved by applying those features on a regular basis.

– Matlab graphics library: This module includes the graphical commandsneededfor our setup. For instance, in the case of PC platforms, it is a set of DLLs

Page 4: [Lecture Notes in Computer Science] Computational Science and Its Applications – ICCSA 2005 Volume 3482 || Numerical-Symbolic Matlab Toolbox for Computer Graphics and Differential

Numerical-Symbolic Matlab Environment for CG and Differential Geometry 505

(Dynamic Link Libraries). In general, they are not included in the Matlabstandard version and should be purchased separately.

2.2 Simulation Flow

Figure 1 also shows the simulation flow of the system: firstly, the user launchesMatlab and calls for the GUI, that looks like the three windows shown on theleft of that figure. Then, the user inputs some values and/or equations in thecorresponding forms (dialogue boxes, radio buttons, check buttons and so on)which are sent to the system to be interpreted. User’s input typically requireshigh-level functions developed by the authors in the toolbox described above(step 1 in Figure 1). At their turn, these functions invoke low-level functionsfrom the numerical kernel (2), which are given either as Matlab functions, m-files, C/C++ MEX files, API files or built-in files (see [1] for details). If theuser wishes to perform calculations in symbolic way, the symbolic kernel is alsoinvoked; that input is subsequently sent to the symbolic kernel (based on Maplefunctions) in order to compute the corresponding output accordingly (3). It isreturned to Matlab to be combined with numerical routines if, for instance, theuser calls for graphical representations in addition to the symbolic output (4).Those results are sent back to the toolbox for subsequent calculations and/ormanipulations (5), and eventually returned to the user as the final output (6).

2.3 Implementation Issues

Regarding the implementation, the toolbox has been developed by the authorsin Matlab v6.0 by using a Pentium III processor at 2.2 GHz. with 256 MBof RAM. However, the program (whose minimum requirements are listed inTable 1) supports many different platforms, such as PCs (with Windows 9x,2000, NT, Me and XP), Macintosh (Power Mac, 68040 and MacOSX) and UNIXworkstations from Sun, Hewlett-Packard, IBM, Silicon Graphics and Digital. Allfigures in this paper correspond to the PC platform version.

As shown in Figure 1, the graphical tasks are performed by using the MatlabGUI for the higher-level functions (windowing, menus, or input) while it uses thegraphical library Open GL for rendering purposes. The toolbox itself has beenimplemented in the native Matlab programming language, that is based on C forcompiled functions.

Table 1. Minimum hardware configuration to install the toolbox

Hardware Requirement

Operating System Windows (9x, 2000, NT, Me, XP), MacOS, MacOSX, UNIX

RAM 128 MB

Disk storage 25 MB (60 MB recommended)

Monitor Super VGA monitor

Screen resolution minimum of 640 × 480

Matlab versions supported 5.3 - 7.0

Page 5: [Lecture Notes in Computer Science] Computational Science and Its Applications – ICCSA 2005 Volume 3482 || Numerical-Symbolic Matlab Toolbox for Computer Graphics and Differential

506 A. Galvez and A. Iglesias

Matlab Toolbox

C/C++ source fileversion of the M-file

Object files

Standalone C/C++ applications

Built-in Installer

LINKER

VISUAL BASIC/C++

C/C++ COMPILER

MATLAB

C/C++

MATLAB COMPILER

VisualBasic/ C++

Fig. 2. Process for creating a C/C++ standalone application

2.4 Generation of Standalone Applications

Another remarkable feature of the Matlab toolbox is the possibility of compileand link it in order ot generate standalone applications. Figure 2 shows thedifferent steps to be performed in order to get such standalone application. Theup-down arrows indicate the compilation flow while dashed rectangles enclosethe different programming environments required for each step indicated within.Roughly, this process can be summarized as follows: firstly, the Matlab toolboxis compiled by using the Matlab compiler. The result is a set of multiple C orC++ source code modules that are actually versions in C/C++ of the initial m-files implemented in Matlab. These files are subsequently compiled in a C/C++environment to generate the object files. Then, those files are linked with theC++ graphics library, M-file library, Built-In library, API library and ANSIC/C++ library files. The final result is an executable program running on ourcomputer.

We should remark here the excellent integration of all these tools to gener-ate optimized code that can easily be invoked from C/C++ via Dynamic Link

Page 6: [Lecture Notes in Computer Science] Computational Science and Its Applications – ICCSA 2005 Volume 3482 || Numerical-Symbolic Matlab Toolbox for Computer Graphics and Differential

Numerical-Symbolic Matlab Environment for CG and Differential Geometry 507

Libraries (DLLs), providing both great portability and optimal communicationbetween all modules. Complementary, we can construct an installer for the tool-box by using either Visual C++ or Visual Basic environments. The authorshave accomplished all tasks mentioned above. The performance of this systemis discussed in the next section.

3 Some Illustrative Examples

In this section the performance of the Matlab toolbox is discussed by means ofsome illustrative examples.

Fig. 3. (left) parametric planar curve and its graphical representation; (right) graph-

ical representation and symbolic expression of its curvature

The first example is displayed in Figure 3: the computation of the curvature ofa planar parametric curve. On Fig. 3(left) the parametric equation of the curve,x = sin(5u) cos(u) , y = sin(5u) cos(4u) for u ∈ [−π, π] is given and, afterpressing the OK button, the graphical representation of the curve is obtained.On the right, the curvature of that curve is displayed and computed in symbolicway. The corrresponding output is shown in the dialogue box below the picture.Additional options allow the user to calculate the symbolic expression of allthe curvatures (Gauss, Mean and principals), the first and second fundamentalforms (a key topic in Differential Geometry), etc. and their visualization ontheir prescribed domain. All these topics have a singular importance in researchand industry. For instance, we use curvatures for designing smooth surfaces,derivatives for detecting surface irregularities, etc.

Several illumination effects can also be applied to simulate computer imageswith a high level of quality. In addition to their aesthetic effect, the illuminationmodels are important to detect irregularities on surfaces, for example, by usingsome illumination lines called isophotes [6]. This procedure can simulate the real

Page 7: [Lecture Notes in Computer Science] Computational Science and Its Applications – ICCSA 2005 Volume 3482 || Numerical-Symbolic Matlab Toolbox for Computer Graphics and Differential

508 A. Galvez and A. Iglesias

situation of looking for the different reflection lines on the surface of a car body.Figure 4 shows the isophotes of the surface z = sin(u∗v) with x, y ∈ [−6, 6]. Onceagain, note the symbolic expression of those isophotes just below the picture inFigure 4.

Fig. 4. Isophotes of the surface z = sin(u ∗ v) on the square [−6, 6] × [−6, 6]

A nice feature of our toolbox is that it can be applied not only for educationalpurposes (which was actually our primary goal for the system) but also for indus-trial applications. For instance, the system includes a IGES file translator thatdeals with the most usual geometric entities in industry, including arcs, straightlines, cubic spline curves, B-spline curves, B-splines and NURBS surfaces andtrimmed surfaces. Once the file is read, its geometric information is then ma-nipulated by means of the numerical libraries in order to obtain the associatedcurves and surfaces. The following step is to plot them through the graphicallibraries and the graphical Matlab options. These options include coloring, zoom-ing, hidden line removal, shading, interactive rotation, etc. In addition, as one orseveral different geometric entities can be selected at any time, different outputs(wireframe model, surfaces model, trimmed model, etc.) are available from the

Page 8: [Lecture Notes in Computer Science] Computational Science and Its Applications – ICCSA 2005 Volume 3482 || Numerical-Symbolic Matlab Toolbox for Computer Graphics and Differential

Numerical-Symbolic Matlab Environment for CG and Differential Geometry 509

system. Figure 5 shows an example of a typical output, in this case, the rightfront seat door of a car body from a real IGES file. This is a simple example, buteven in this case, more than 9500 B-spline curves, 1500 cubic spline curves, 3000straight lines, almost 3000 arcs, 4182 NURBS surfaces, 628 trimmed surfaces,etc. are read and displayed. Each file might typically include several thousandsof curves and surfaces of different types, and require some MB of hard disk tobe stored. These data illustrate how complex an IGES file can be.

Fig. 5. Visualization of a real piece of a car body from a real IGES file

On the other hand, different effects (as ambient lights, especular and diffusiveillumination, several light sources in different positions and with different colors,etc.) contribute to simulate a real image by computer with a high level of quality.Figure 6 shows the window for computer graphics, with a head obtained froma collection of patches joined through the patch Matlab command. In orderto get this final image, several options have been applied: four different lightsources (two yellow and one green sources at the infinity and another yellowlocal source at the point (3,−4, 0)) following the phong illumination model [5],a shiny material and a copper colormap, a white ambient light, a 80 % ofspecular light, a 35 % of diffuse light, etc.

Page 9: [Lecture Notes in Computer Science] Computational Science and Its Applications – ICCSA 2005 Volume 3482 || Numerical-Symbolic Matlab Toolbox for Computer Graphics and Differential

510 A. Galvez and A. Iglesias

Fig. 6. Example of a computer graphics image generated in our system

4 Conclusions

In this paper we introduce a user-friendly Matlab toolbox for dealing with manyof the most important topics in Computer Graphics and Differential Geometry.The paper describes the main features of this program (such as the toolboxarchitecture, its simulation flow, some implementation issues and the possibil-ity to generate standalone applications) and how the symbolic, numerical andgraphical Matlab capabilities have been effectively used in this process.

The program have been successfully applied for both educational and indus-trial purposes. In this last case, the initiative is actually part of a project forapplying CAS to the automotive industry. This idea has been supported by therecent announcement of the use of Matlab by Daimler-Chrysler and Motor FordCompany (see [7] for details). To our knowledge, other similar approaches areexpected for the next years. From this point of view, the present work could behelpful to those interested to follow this way.

References

1. The MathWorks Inc: Using Matlab, (1997); see also its Web Page: http://www.mathworks.com

Page 10: [Lecture Notes in Computer Science] Computational Science and Its Applications – ICCSA 2005 Volume 3482 || Numerical-Symbolic Matlab Toolbox for Computer Graphics and Differential

Numerical-Symbolic Matlab Environment for CG and Differential Geometry 511

2. Dewar, M. C.: Integrating Symbolic and Numeric Computation. In Cohen, A.M.(ed.): Computer Algebra in Industry. John Wiley and Sons, Chichester (1993)221-232

3. Galvez, A., Iglesias, A., Gutierrez, F.: Applying Matlab to Computer Graphics andCAGD. Application to a Visualization Problem in the Automotive Industry. In:IX International Conference on Computer Graphics and Vision, GRAPHICON’99.Moscow (1999) 214-221

4. Galvez, A., Iglesias, A., Otero, C., Togores, R.: Matlab Toolbox for a first ComputerGraphics course for engineers. Lectures Notes in Computer Science 3044 (2004)641-650

5. Hall, R.: Illumination and Color in Computer Generated Imagery. Springer-Verlag,New York (1989)

6. Poeschl, T.: Detecting surface irregularities using isophotes. Computer Aided Ge-ometric Design 1 (1989) 163-168

7. Web Page: http://www.mathworks.com/company/pressroom.8. Richard, C., Weber, A.: A Symbolic Numeric Environment for Analyzing Measure-

ment Data in Multi-Model Settings. In Ganzha, V.G., Mayr, E.W., Vorozthtsov,E.V. (eds.): Computer Algebra in Scientific Computing, CASC’99. Springer-Verlag,Berlin Heidelberg New York (1999) 343-347

9. Ruhoff, P. T., Proestgaard, E., Perram, J. W.: Symbolic Derivation and Numer-ical Integration of the Equations of Motion for Constrained Dynamical SystemsUsing Mathematica. In: Keranen, V., Mitic, P. (eds.): Mathematics with Vision.Computational Mechanics Publications, Southampton (1995) 317-324

10. Suhonen, J., Lahde, O.: Combining Symbolic and Numerical Computating in theMulti-Band-Phonon-Projection-Model. In: Keranen, V., Mitic, P. (eds.): Mathe-matics with Vision. Computational Mechanics Publications, Southampton (1995)243-250

11. Wang, P.S.: FINGER: A Symbolic System for Automatic Generation of NumericalPrograms in Finite Element Analysis. Journal of Symbolic Computation 2 (1986)305-316