Research on generic interactive deformable 3D models: focus on the human inguinal region
Abstract
The goal of this project is to research for real-time approximate methods of physicallybased animation in conjunction with static polygonal meshes with the aim of deforming them and simulating an elastic behaviour for these meshes. Because of this, in this project it has been developed a software suite capable of doing a lot of tasks, each one from different computer graphics research fields, conforming a versatile capability project.
Full text
MASTER IN COMPUTING (VISUALIZATION, VIRTUAL REALITY,AND GRAPHIC INTERACTION) Research on Generic Interactive Deformable 3D Models —Focus on the Human Inguinal Region— ;Research Thesis for Master in Computing Thesis Student: Marc Musquera Moreno [[email protected]] Thesis Director: Antonio Sus´ın S´anchez (MA1-UPC) [[email protected]] Thesis Reader: Isabel Navazo Alvaro (LSI-UPC) [[email protected]] Spring 2008; v1.1
! Acknowledgements You will never find time for anything. If you want the time, you must make it. - Charles Buxton First, I would like to thank my Thesis Director Dr. Antonio Susin for guiding me through this awesome research project in physically-based animation. Many thanks also to Prof. Isabel Navazo for her help, interest, collaboration as Thesis Reader, in addition of her support in burocratic tasks during this project. Also, I would like to thank the staff of the Master teachers, specially Profs. Carlos And´ ujar and Pere Pau V´ azquez for their unvaluable help on voxelization and shader programming respectively, and my Master mates, Ricardo (I still remember we helping us each other with Mac peculiarities in front of PC), Quim and Jordi, for the good moments and friendly environment during all the Master. My most sincere gratitude also to Laia, who has corrected from Toulouse, where she is achieving her PhD, the state of the art part in terms of making the text more comprehensive and easier to understand. Thanks also to Alba for doing the same with the introduction part. And, overcoat, my most sincere gratitude for my three most closer people, who have supported me and have helped me improving my life while they were adapting their own to mine: my dear parents Joan and Montse, of course —I don’t know what could I do without them—, and my particular jewel, Gemma, who has wanted to share with me these complex times, and have lived my good research moments as long as also supported me in the bad ones all the time. The love from you three have been essential for the success of this project. I
* Table of Contents Acknowledgements I Table of Contents III List of Figures VII List of Tables XI List of Codes XIII PROJECT’SFIRST CONTACT 1 Project Abstract 3 1.1 Overview ...................................... 3 1.2 Focusing on the research thesis aims ...................... 4 1.2.1 Interests and research fields ....................... 4 1.2.2 Final result ................................. 5 1.2.3 A non-interactive simulator ....................... 5 2 Objectives and Research Contribution Overview 7 2.1 Motivations and interests ............................ 7 2.1.1 Physically-based computing animation ................ 7 2.1.1.1 Computer Animation typologies .............. 7 2.1.1.2 The 3Dcomputer animation ................. 8 2.1.1.3 Kinds of 3Dcomputer animation. Focus on physicallybased animation ........................ 8 2.1.2 Human musculature studies ...................... 9 2.1.2.1 Introduction to Human Body Modeling and Animation . 9 2.1.2.2 Evolution of Human Animation ............... 10 III
IV Table of Contents 2.1.2.3 Main goal for this project ................... 11 2.1.3 Surgery simulation ............................ 12 2.1.3.1 Virtual surgery’s brief overview ............... 12 2.1.3.2 This project’s approach and developed work ....... 12 2.2 Research fields and contributions ........................ 13 2.2.1 Deformable models over static meshes ................. 13 2.2.1.1 Objectives ............................ 13 2.2.1.2 Methodology Overview .................... 13 2.2.2 Multiresolution meshes ......................... 14 2.2.2.1 Idea and motivation ...................... 14 2.2.2.2 A little brief scheme about remeshing steps ........ 14 2.2.3 Surgery on a 3Dobject .......................... 15 2.2.3.1 A virtual scalpel for cutting ................. 15 2.2.3.2 Proposal for this project .................... 16 THE STATE OF THE ART 3 Volumetric Model from a Polygonal Mesh 19 3.1 Polygonal Meshes ................................. 19 3.1.1 Introduction to Polygonal Meshes. The Triangle Meshes . . . . . . 19 3.1.2 The Face-Vertex Mesh Format ...................... 20 3.2 Mesh Voxelization ................................. 20 3.2.1 The volumetric models. The voxelization process .......... 20 3.2.1.1 Introduction to the voxel space ............... 20 3.2.1.2 The 3Ddiscrete topology ................... 21 3.2.2 The Problem: Triangle VS Voxel ..................... 22 3.2.2.1 Introduction .......................... 22 3.2.2.2 The test’s simplest case: gigantic meshes in low-grid voxelmaps ............................. 22 3.2.2.3 Test’s generic case: voxelization of any mesh at any LOD. Alternative techniques .................... 24 3.3 The search tree structures applied to voxelization ............... 28 3.3.1 Reasons for using trees .......................... 28 3.3.2 The most common Search Trees Structures .............. 28 3.3.2.1 Binary Space Partition Tree —BSP-Tree— .......... 29 3.3.2.2 Kd-Tree ............................. 29 3.3.2.3 Quadtree (2D) and Octree (3D)................ 30 4 Polygonal Mesh Reconstruction: Multiresolution Meshes 31 4.1 Introduction to Multiresolution Meshes .................... 31 4.1.1 The need of a multiresolution mesh capability ............ 31 Research on Generic Interactive Deformable 3D Models
Table of Contents V 4.1.2 The IsoSurfaces .............................. 32 4.2 VoxelMap Refilling. The Model Carving .................... 32 4.2.1 Space Carving ............................... 33 4.2.2 Voxel Carving ............................... 33 4.3 IsoSurface Extraction Algorithms ........................ 34 4.3.1 IsoSurface extraction as multiresolution mesh construction . . . . . 34 4.3.2 Marching Cubes ............................. 34 4.3.2.1 Overview ............................ 34 4.3.2.2 Advantages and disadvantages ............... 36 4.3.2.3 The isosurface-voxel intersection case LUT. Shortcomings 36 4.3.3 Marching Tetrahedron .......................... 37 4.3.3.1 Overview and shortcomings ................. 37 4.3.3.2 The Marching Tetrahedra LUT ................ 38 5 3D Object Model Animation/Deformation 41 5.1 Point-Oriented Deformation ........................... 41 5.1.1 The Point-Sampled Geometry ...................... 41 5.1.2 Point-sampled deformation ....................... 42 5.2 Geometric Deformation ............................. 43 5.2.1 Global or local deformation operators ................. 43 5.2.1.1 Reminder: the jacobian matrix JFof a function F..... 43 5.2.1.2 Method Overview ....................... 44 5.2.1.3 Global and local operators .................. 44 5.2.1.4 Examples of global operator deformations ......... 44 5.2.2 Free Form Deformation —FFD—.................... 47 5.2.2.1 Introduction to FFD ...................... 47 5.2.2.2 Methodology details ..................... 48 5.2.2.3 Grid of Control Points ..................... 48 5.2.2.4 Capabilities and limitations ................. 49 5.2.3 Interactive Axial Deformations —AXDF—.............. 49 5.2.3.1 Method Overview ....................... 49 5.2.3.2 Algorithm Details ....................... 50 5.2.3.3 Advantages and lacks of AXDF............... 51 5.2.4 Deformation by Wires .......................... 51 5.2.4.1 Introduction and wire definition ............... 51 5.2.4.2 Algorithm overview ...................... 52 6 Physically-Based Deformations 53 6.1 Introduction to deformation based on physics ................ 53 6.1.1 Overview of time stepping deformation algorithms ......... 53 6.1.1.1 Accuracy VS speed performance ............... 53 6.1.2 A simple particle Pas the deformation system ............ 54 6.1.2.1 State Vector and Vector Field of a simple particle . . . . . 54 Master Thesis in Computer Graphics by Marc Musquera Moreno
VI Table of Contents 6.1.2.2 The time step ∆t. The numerical integrator concept. The Euler numerical integrator .................. 54 6.1.2.3 The integration system scheme ............... 55 6.1.2.4 The most used ODE integrators ............... 55 6.1.2.5 Accuracy and stability of numerical integrators . . . . . . 56 6.1.2.6 Movement restrictions .................... 58 6.2 Dynamic Deformable Model Systems ..................... 59 6.2.1 Introduction to deformable systems .................. 59 6.2.1.1 Definition of Particle System ................. 59 6.2.1.2 The deformable models as dependent-particle system. The continuum elasticity ...................... 60 6.2.2 Points of View of a Physical Simulation. Solver Typologies ..... 61 6.3 Physical Simulation based on Lagrangian POV descriptions ......... 62 6.3.1 Mesh Based Methods ........................... 62 6.3.1.1 Finite Element Method —FEM—............... 62 6.3.1.2 Finite Differences Method .................. 64 6.3.1.3 Boundary Element Method .................. 64 6.3.1.4 Mass-Spring Systems ..................... 65 6.3.2 Mesh Free Methods ............................ 68 6.3.2.1 What are Mesh Free Methods ................ 68 6.3.2.2 Smoothed Particle Hydrodynamics —SPH—........ 68 6.3.2.3 Meshless Deformations based on Shape matching . . . . 69 6.3.3 The Hybrid Approaches ......................... 69 6.3.3.1 Overview of the hybrid simulation approaches . . . . . . 69 6.3.3.2 Pump it Up ........................... 69 6.3.3.3 Mass-Spring with Volume Conservation .......... 70 6.4 Physical Simulation based on Eulerian POV descriptions .......... 71 6.4.1 Overview ................................. 71 6.4.2 Fluid Simulation ............................. 71 6.4.2.1 The Navier-Stokes equations for fluids ........... 71 6.4.2.2 The yielding idea of display and computation ....... 72 6.4.2.3 A small summary of variants and proposals ........ 72 7 Topological Changes on Polygonal Meshes 75 7.1 Mesh Cutting or Mesh Splitting ......................... 75 7.1.1 Introduction ................................ 75 7.1.2 Motivations and applications ...................... 76 7.1.2.1 Surgery simulation. Constraints and requirements . . . . 76 7.1.2.2 Another applications of mesh splitting ........... 76 7.2 Mesh Dissection: Some Proposals ........................ 76 7.2.1 Spring Framework Tools: Cutting Interaction ............. 76 7.2.1.1 The generic alrgorithm scheme ............... 77 Research on Generic Interactive Deformable 3D Models
Table of Contents VII 7.2.1.2 Examples and applications .................. 77 7.2.2 Finite Element Methodologies ..................... 78 7.2.3 Discontinuous FFD approach ...................... 78 7.2.4 Hybrid Cutting .............................. 79 7.2.5 Off-line virtual node algorithm based on replicas .......... 80 CONTRIBUTIONS AND RESULTS 8 External Used Libraries and Employed Hardware 85 8.1 Mac Computers with MacOsX v10.5 “Leopard” ................ 85 8.2 Used Developing Platforms ........................... 86 8.2.1 QT4.4 for GUI design with C++ as Native Language ........ 86 8.2.2 Matlab for testings ........................... 87 9 Computer Graphics Programming 89 9.1 OPENGL as the primary graphics specification ................ 89 9.1.1 A Little Brief on Computer Graphics using OPENGL ........ 89 9.1.2 API overview: The OPENGL graphical computing steps ...... 90 9.1.2.1 Initial considerations; introduction ............. 90 9.1.2.2 Drawing primitives ...................... 90 9.1.2.3 Vertex transformations; the matrix stack .......... 92 9.1.2.4 Camera positioning and configuration; the viewport . . . 94 9.1.3 The Standard Graphics Pipeline .................... 96 9.1.4 The OPENGL Extensions. The GLEW Library ............. 97 9.2 The programmable graphics technology .................... 98 9.2.1 The Shading Languages ......................... 98 9.2.2 A New Programming Paradigm .................... 98 9.2.2.1 The GPU’s Vertex and Fragment Processors ........ 98 9.2.2.2 The New Programmable Graphics Pipeline ........ 99 9.2.2.3 Geometry Shaders ....................... 99 9.2.3 OPENGL 2.0and GLSL .......................... 100 9.2.3.1 Brief introduction to OPENGL 2.0and GLSL ........ 100 9.2.3.2 Data types and qualifiers ................... 100 9.2.3.3 The most important implicit variables ........... 102 9.2.3.4 A shader example: the toon shading ............. 102 9.3 GPGPU: The New Computing Paradigma .................. 104 9.3.1 The Programmable Graphics Pipeline, used for General Purpose Algorithms ................................ 104 9.3.1.1 The Frame Buffer Object —FBO— Extension ........ 104 9.3.1.2 General-Purpose Graphics Processor Unit —GPGPU—. . . . 105 9.3.2 The nVidia CUDA approach ....................... 107 Master Thesis in Computer Graphics by Marc Musquera Moreno
XIV List of Figures 3.2 A triangle mesh with face-vertex specification composing a cube. . . . . . 20 3.3 Examples of three voxelizations of the model dolphin, executed by MeshInspeQTor software. ................................. 21 3.4 Voxel connectivity policies ............................ 21 3.5 2Drelative position between a square and a triangle. ............. 22 3.6 Testing T∩Vby triangle-box test based on vertex containing checking; output by a Matlab code written for this thesis by its author. ........ 23 3.7 Tipology of Bounding Boxes depending on their orientation; source [voxB] (edited). ...................................... 24 3.8 The Gernot Hoffmann Triangle-Voxel intersection test. ............ 25 3.9 The Gernot Hoffmann Triangle-Voxel intersection test results adquired by this document’s author by his own Matlab programmed implementation of this proposal. .................................. 25 3.10 The first three iterations of the Sierpi´ nski Fractal. ............... 26 3.11 The Sierpi´ nski Fractal Matlab plottings of the thesis’ author own adaptation code for triangle area discretizations. ................... 26 3.12 Scheme of a separator axis; notice that the normal projections of two meshes MAand MBare not intersecting; so, the two meshes are not intersecting, and thus, πsis a separator plane. ........................ 27 3.13 A generic tree structure for being used in computer algorithm data structuration and search accelerations; in this example, Ais the root of the tree, being E,I,J,K,G,H,Dnodes without children, called leaves. Moreover, in the remarked subtree context, Cis the root and G,Hthe leaves. . . . . 28 3.14 2D BSP construction based on a polygon, extracted from [vox8]. Notice that the satisfactory condition for stopping the BSP construction is that the two subspaces contain a convex polygon. ...................... 29 3.15 A point cloud based 2DKd-Tree structure construction; source [vox9]. . . 29 3.16 The 3DOctree recursive subdivision; source [voxA]. ............. 30 4.1 Multiresolution mesh of an airplane, at different LODs; source [mrs1]. . . . 31 4.2 Scheme of IsoSurface renderization as a triangular mesh. .......... 32 4.3 Voxelization of the sphere model. Notice the emptiness in the voxelmap section, so the volumetric model is not filled but empty, like the original convex mesh. Output frameset from MeshInspeQTor.............. 32 4.4 The Space Carving algorithm in action; source [mrs4] (edited). ....... 33 4.5 Detailed methodology for the Voxel Carving algorithm; source [mrs5] (edited). 33 4.6 Voxel Carving applied to a standard 64 ×64 ×64 voxelization of the torus model. Since the final voxelmap is the intersection of the six voxel carving steps, the volumetric model of torus is filled. As usual, frameset created by the thesis purpose software MeshInspeQTor................. 35 4.7 The 15 absolute cube-isosurface intersection situations; source [mrs8]. . . 36 4.8 An example of hole in a marching cubes generated mesh, as the result of an ambiguous case; source [mrs8] (edited). .................. 37 4.9 The Marching Tetrahedra cell subdivision scheme. Each voxel will be treated as five independent tetrahedrons, so the method is more accurate and smooth with the discrete shape of volumetric unit than marching Cubes; source [mrs8]. ............................... 38 4.10 The Marching Tetrahedra cell subdivision scheme; source [mrs8]. . . . . . 38 Research on Generic Interactive Deformable 3D Models
List of Figures XV 5.1 Hybrid system featured in [geo2], consisting in a hybrid geometry representation combining point clouds with implcit surface definitions. Note: the middle image is the colored sample density map. ............ 41 5.2 Scheme of the contact handling framework developed in [geo3]. . . . . . . 42 5.3 Penalty and friction force processing for Γ1in front of a Γ2collision; source [geo3]. ....................................... 43 5.4 Example of point-sampled object animation with the [geo4] method; the two left figures are representing the phyxel-surfel representation and the MLS reconstructed mesh. ............................. 43 5.5 The cube and teapot undeformed models. ................. 45 5.6 The ‘taper’ effect on cube and teapot models; source [geoA]. ....... 45 5.7 The ‘twist’ effect on cube and teapot models; source [geoA]. ....... 46 5.8 The ‘bend’ effect on cube and teapot models; source [geoA]. ....... 46 5.9 The ‘vortex’ deformation over a solid primitive; source [geo7]. ....... 47 5.10 A complete deformation animation is shown in this couple of figures: (a) two local FFD are applied to the bar —only one is shown—, for transformating the bar onto a ‘phone receiver’, and (b) after, a global FFD bends the ‘receiver’; source [geoC]. ........................... 47 5.11 There is a complete Free Form Deformation —FFD— executed over several objects (cubes and spheres) clearly embedded in the bounding flexible plastic; source [geoC]. .............................. 49 5.12 A sphere axis deformation: on the left there’s the undeformed sphere with the defined axis, also undeformed; on the right, the sphere, deformed in an intuitive and consistent way with the axis deformation; source [geoD]. 50 5.13 The horseshoe axis deformation. Please notice the axis, now adapted to the object surface; thus, the deformation can be so complex as can be seen in the right image; source [geoD]. ........................ 50 5.14 An example of a facial modeling by ‘wire’ specification, and the next animation and deformation by ‘wire’ manipulation; source [geoE]. . . . . . . 51 5.15 Deformation of a point Pto Pdef by a wire W. The figure parameter pRis the correspondence point, within R, of P; source [geoE]. .......... 52 6.1 Architecture of an iterative integration system for animation by deformation; source [phy4]. ................................ 55 6.2 Stability scheme by ODE system plottings depending on the time step h; source [phy3]. ................................... 57 6.3 Intersection between 3Dbounding volumes of 3Dobjects. .......... 58 6.4 Force equilibrium in a particle system with connection restrictions; source [phy9]. ....................................... 59 6.5 ODE numerical integration scheme for a single particle P........... 59 6.6 Some εelastic strain deformation parameters, from left to right: Cauchy, Cauchy (simplified) and Green; source [phyA]. ................. 60 6.7 Visual results of the two object animation description point of views; source [phy5]. ....................................... 61 6.8 A scheme of the approximate deformation ˜u(m)of a continuous deformation u(m), done by the Finite Element Method; source [phy5]. ....... 62 6.9 Hexahedral finite element volumetric representation of a topologically inconsistent mesh, ready for FEM application (notice that each hexahedron is one of the Ejsubdivisions or elements); source [phy5]. ........... 64 Master Thesis in Computer Graphics by Marc Musquera Moreno
XVI List of Figures 6.10 A typical mass-spring system three-dimensional representation; source [phy5]. 66 6.11 Effect of viscosity on a physically-based elastic deformations. Each figure has ten times higher viscosity than its left neighbour; source [phyC]. . . . 66 6.12 Here’s the scheme of the three different internal forces for the 2Dcloth mass-spring simulation model, including the connection affecting and a detailed visualization of the different force effects. .............. 67 6.13 A cloth piece with four different hanging —relaxing— postures after a realtime simulation steps by shaking the cloth and sliding it over obstacles before allowing it to rest; source [phyD]. .................... 67 6.14 Interface tension force SPH-based simulation between fluids of different (i) polarity, (ii) temperature diffusion and (iii) buoyancy; source [phy5]. . . . 69 6.15 Stable original shape recovering after a —literally— rigid and heavy deformation; [phy5]. ................................. 69 6.16 The Chen and Zeltzer finite element mesh and contraction approach. . . . . 70 6.17 A silver block catapulting some wooden blocks into an oncoming ‘wall’ of water; source [phy5]. ............................... 71 6.18 Sand-based bunny model deformation; source [phy5]. ............ 72 6.19 A liquid drop falling into a liquid pool. In the six-figure frameset can be clearly noticed the three layers of the system: the Lagrangian layer (blue), the bridge connection layer (green) and the Eulerian one (red); source [phyB] (edited). .................................. 73 6.20 Here is the velocity field for a certain instant time of the above frameset. Notice the communication between the Lagrangian and Eulerian layers by the connection stage; source [phyB]. ...................... 73 7.1 Frameset for a fractured spherical shell; source [cut1]. ............ 75 7.2 The interactive deformation with cutting capability algorithm scheme from [cut3]. ........................................ 77 7.3 Virtual Scalpel cutting a 2-layered surface, top (left) and side (right) views; source [cut3]. .................................... 77 7.4 The cutting plane sequence implementation over a cube model; notice the cutting sequence from left to right; source [cut7] (edited). .......... 78 7.5 A cut movement to a initially regularly triangulariez surface model with delaunay triangulation on the cut primitives; source [cut8]. ......... 78 7.6 The interactive mesh cutting implemented by Sela, Schein & Elber in [cut5]. 79 7.7 The scheme for the primitive approximatting cutting process by the [cut2] method. ....................................... 79 7.8 The interactive mesh cutting implemented by Steinemann et al in [cut2]. . 79 7.9 A complete frameset example of a volumetric mesh cutting by the [cut2] method. ....................................... 80 7.10 High resolution cutting shell of the 3Dvolumetric complex armadillo model (380Ktetrahedrons), by using the virtual node algorithm at [cut1]. 80 7.11 Tearing a plastically fragmentation deformation to the armadillo’s high resolution volumetric mesh; source [cut1]. ................... 81 Research on Generic Interactive Deformable 3D Models
List of Figures XVII CONTRIBUTIONS AND RESULTS 8.1 Mainly used tools for the thesis’ software suite design and implementation. 86 8.2 The Trolltech’s QT4 versatile capabilities and framework diagram. . . . . 87 8.3 The Mathworks’ Matlab mathematic environment logo. .......... 87 9.1 The OPENGL logo by Silicon Graphics Inc. .................. 89 9.2 The OPENGL primtive drawing styles; source [gpuE]. ............ 91 9.3 The resulting rendered triangle from CPP code 2.3............... 92 9.4 A scheme of the three basic geometric transformations: ‘translation’, ‘scaling’ and ‘rotation’, with the implicit correspondence between the transformation matrix and the OPENGL command. .................. 92 9.5 The order of the multiplying applied geometric transformations is important: it’s not the same a translation applied to a roation (left) that a rotation applied to a rotation (right); source [gpuE]. .................. 93 9.6 The resulting scheme of the matrix stack CPP code 2.4; source [gpuE]. . . . 93 9.7 The coordinate system transformations from scene specification to scene screen displaying; this figure is taken directly from [gpuF]. ......... 94 9.8 The two OPENGL available volume viewing specification and the camera positioning and orientation methods; figure sources from [gpuF]. . . . . . 95 9.9 Overview of OPENGL method for display, on screen displays, geometric primitives —in the figure they have been markes as triangles due to the most common case— as pixels; source [gpu3]. ................ 96 9.10 Detailed scheme of the OPENGL’s Standard Graphics Pipeline; source [gpu4]. 97 9.11 The GPU’s vertex and fragment processor managment tasks; source [gpu3]. 98 9.12 Detailed scheme of the Programmable Graphics Pipeline; source [gpu4]. . 99 9.13 The effects of two shaders applied to two models: the upper figures show the graphical results for a shader computing the Phong illumination model, and in the lower ones are featured the same models with the toon shading shader over them. This has been possible by the shader addition to this thesis’ developed software MeshInspeQTor................... 103 9.14 nVidia’s CUDA is the next (theoretical) step on GPGPU computing. . . . . . 107 9.15 The new nVidia CUDA-compatible GPU architecture; source [gpuD]. . . . . 107 10.1 Informal UML diagram of MeshInspeTor internal functionalities. ...... 109 10.2 The schematic triangularization for generic polygonal faces —here, an hexagon— ............................................ 114 10.3 Illumination contrasts between vertex’s normal assigment in relation to the face comprising, or the normal assignment by the mean of normals per each vertex. .................................... 115 10.4 An example of internal oblique inguinal muscle, extracted by using the IRI tool; please notice the defficiences on the extraction —the model is rendered by remarking the polygon edges—. ................... 115 10.5 The specific GUI within MeshInspeQTor for converting IRI-P3D format files to OBJ..................................... 116 10.6 An example of a 2Dconvex hull, executed over a 2Dpoint set. ....... 117 10.7 A graphical scheme for an entire process of Jarvis March .......... 118 Master Thesis in Computer Graphics by Marc Musquera Moreno
XVIII List of Figures 10.8 MeshInspeQTor’s main rendering offerings. Notice that the dolphins.obj model is really composed by three dolphins, each one clearly identified in the ‘model list’ at the top of the right panel. .................. 121 10.9 MeshInspeQTor’s ‘draft’ rendering style. Notice that, because of the flat face shading, the triangular faces are perfectly detailed and can be clearly observed. ....................................... 123 10.10Renderization of a model with its bounding box surrounding it, in MeshInspeQTor....................................... 123 10.11Renderization of a model with its per-face normals shown, in MeshInspe- QTor. The model is rendered with the ‘draft’ style for a better per-face normal visualization. ............................... 124 10.12Graphical scheme of Phong equation for the selftitled illumination model: here the light is white, the ambient and diffuse colors are both blue, and the specular color is white, reflecting almost all of the light hitting the surface, but only in very narrow highlights. The intensity of the diffuse component varies with the direction of the surface, and the ambient component is uniform (independent of direction). Figure extracted from [ami8]. . . . . 126 10.13Differences between OPENGL standard illumination rendering and a Phong model implemented over the programmable GPU pipeline. Notice the more specular accuracy on the left part of the model, as well as the more delimited shaded zones in the right one. .................... 127 10.14Graphical scheme of a negative space located point p, and the q≡p0point, being the pprojection to the plane π....................... 130 10.15Results example of applying a VirtualCutter to a generic three-dimensional model with MeshInspeTor............................. 131 10.16An arm dissected by two VirtualCutters, featured on MeshInspeQTor. Please notice that the computer positive space is the intersection of all the positive spaces of all VirtualCutters. ........................... 132 10.17The ‘triangle-voxel’ testing implemented in MeshInspeQTor, based on 2D axis projections and implicit parallelogram approximation of the triangle. 137 10.18The ‘triangle-voxel’ testing conflict situations; notice the particular location and orientation of the triangle in relation to the cube. The test will validate as intern every external triangle with this particularity. . . . . . . 139 10.192Dprojection of the triangle-voxel postfiltering test based on space location of the eight cube —a square here— vertices in relation to the triangle plane —the thick plane on the figures—. ....................... 139 10.20A clear examples of applied set theory; by considering the squares Ma and Mbas three-dimensional volumetric representations, the application on mesh voxelization is noticeable. ....................... 141 10.21A n×nlinear tracking —the X+one indeed— of a cylinder voxel carving. 142 11.1 Informal UML diagram of ForceReaQTor internal functionalities. ...... 145 11.2 The total conversion from a 3Dmodel to its mass-spring system —the voxelmap is omitted but it can be deduced from the mass-spring system nodes. 149 11.3 The ForceReaQTor dynamic force configuration panel —zoomed—. . . . . . 150 11.4 The dynamic force configuration panels for ‘fixing’ and ’cutting’ classes. . 152 11.5 The ForceReaQTor implemented restricting forces, in a 2Dscheme. . . . . . 157 Research on Generic Interactive Deformable 3D Models
List of Figures XIX 11.6 ForceReaQTor applying ‘stretch’ and ‘bend’ deformation effects to a 4×4×4 cube after fixing the upper vertices and applying gravity force; notice that the combined deformation offers more equilibred results. .......... 161 11.7 One of the four diagonals of a single cube. ................... 162 11.8 A 4×4×4cube mass-spring system where it’s applied ‘shear’ deformation forces together with some ‘stretch’ and ‘bend’ factors after applying gravity to the deformation model. ....................... 163 11.9 The shape/volume preserving example problem. .............. 163 11.10Fixing nodes as volume preservation solution example. ........... 164 11.11Autostretching as volume preservation solution example. .......... 166 11.12Scheme of the ForceReaQTor mass-point volumetric approximation buy using a sphere instead of a cube. Obviously, the sphere and the cube has the same center, and moreover, the sphere is tangent to all the cube faces. . . . 167 11.13Scheme of sphere intersection; if ||c2−c1|| ≡ L≤D, it must be ensured that the two spheres S1and S2are intersecting. ................ 168 11.14Scheme of the per-mass-point adapting collision testing. .......... 170 11.15Physically-based deformation with real-time cutting behaviour modification.173 11.16pseudo-FFD rendering process for deforming a triangular mesh w.r.t. its inner non-rigid skeleton —the mass-spring system indeed—. ........ 175 11.17The texture compression schemes for the desired shader data: the gray cells of the final matrices indicate unused and value-emptied cells. . . . . 176 11.18ForceReaQTor deformable model rendering types: only the model skeleton —mass-spring system— or the model’s skin —its triangular mesh, that lays over the mass-spring system—. ...................... 177 11.192Dcurve generation by the Marching Squares —2DMarching Cubes— technique. The example’s threshold value for curve extraction is 5.. . . . 179 11.20Example of ForceReaQTor autogenerated mesh of the highly featured 4× 4×4cube; the normals are per-face configured, but by applying the Phong illumination GLSL program —section 10.3.4—, the renderization is robust. 180 11.21Three-dimensional scheme of which voxels have to be checked for adjacency with a certain voxel, if it’s desired to compute the isovalue of the LUF voxel vertex. ................................. 181 11.22Example of ForceReaQTor extracted mesh of the ‘left external oblique human muscle’, wrongly extracted from the Visual Human Project with the extractor software provided by the IRI at UPC; notice the simplicity of the extracted mesh by using Marching Cubes —w.r.t. the original mesh—, but also its consistency in relation of the original. ............... 182 11.23An example of deformation force set applied to the 4×4×4cube Marching Cubes autoextracted mesh in ForceReaQTor................... 184 12.1 The original bunny.capped polygonal mesh surface model. ........ 189 12.2 The resulting voxelmaps from the bunny.capped voxelization processes. 190 12.3 The resulting marching cubes’ autoextracted meshes from bunny.capped voxelmaps. ..................................... 191 12.4 Lenghten (a,c,e,g) and shorten (b,d,f,h) force set deformation examples over the dolphins model. The rendering process has been at 25 FPS, with ‘stretch’ restrictive forces and Euler integrator. The forces are all 20N amount. ....................................... 192 Master Thesis in Computer Graphics by Marc Musquera Moreno
XX List of Figures 12.5 A deformation force set of the obliqext model, based on a dense 64×64× 64 voxelmap; here there is an abbuse of the simacc adaptative methodology for computing Force Accumulators. The integrator is the Verlet one using a 30 FPS animation, and the forces are 20Nall ............. 193 12.6 A deformation force set for the transversus model, based on a 32×32× 32 voxelmap; here can be seen the influence of a cutting on a dynamically deformable model. Here there is 30 FPS animation with a Verlet integrator with ‘stretching’ and ‘bending’; the force is 30Namount .......... 194 13.1 Scheme of a possible splitting for a marching cubes’ extracted mesh. . . . 197 13.2 Examples of ‘workbench-haptic’ virtual environment systems. . . . . . . . 198 13.3 The CAVE virtual environment scheme. .................... 199 BIBLIOGRAPHY AND APPENDIXES B.1 MeshInspeQTor rendering the dolphins model with materials and phong algorithm illumination. Notice the three application panel functionalities: models,virtualcutters and voxelizer......................... 211 B.2 From up to down, wireframe, draft —with normal displaying; see below— and nodeset renderings of the dolphins model. Notice in the right panels the information about the dolphin1 entity, already selected: 285 vertices composing 564 faces. ............................... 213 B.3 Here’s the bunnycapped model in dissection by a VirtualCutter. . . . . . 214 B.4 The previous and final dolphins’<32 ×32 ×32 >voxelmap automatic generation steps. ................................. 215 B.5 Two fish 3Dmodels, fish1 and fish2, will be used to obtain complex voxelizations by using basic set theory. Notice that the entity individual bounding boxes are really intersecting. ..................... 216 B.6 The <32 ×32 ×32 >fish1 ∩fish2 automatic voxelization. Let’s see that the valid nodes only those that were valid on the both two voxelizations.216 B.7 The <32×32×32 >VoxelMap equivalent to those voxels that are containing fish1 but not fish2: so, the set theory operation is [fish1 ∩fish2].217 B.8 Voxelizer Navigator’s manipulation example. Notice the added cube on the upper left screen part, within the torus voxelmap. ........... 217 B.9 A voxelmap finite range visible with the Voxelizer Navigator’s range visualization option. .................................. 218 B.10 The thesis carving purpose scene sphecylcub <64×64×64 >VoxelMap. Notice the emptyness of the cylinder inner space, so the contained objects —cube and sphere— are also empty and clearly visualizable. ........ 218 B.11 Portion of the <64 ×64 ×64 >sphecylcub voxelization that shows the absolute emptyness of the standard 3Dscene objects voxelization. . . . . . 219 B.12 Space Carving policy selection dialog. ..................... 219 B.13 Space Carving done with ‘Total Refilling’ policy. Notice that all the inner zone corresponding to the more exterior voxelization is totally refilled. . . 220 B.14 Space Carving done with ‘Hole Preserving’ policy. Notice that the more exterior voxelization is refilled, but the inner ones are considered holes, so they are still empty. ................................ 220 Research on Generic Interactive Deformable 3D Models
List of Figures XXI B.15 MeshInspeQTor software and hardware requirements logos. ......... 221 C.1 ForceReaQTor’s simulation example by deformable forces to dolphin model.223 C.2 An example of <16 ×16 ×16 >skeleton-node-modeling from sphere model voxelmap. ................................. 225 C.3 The preview of a previously specified dynamic force —yellow lines, maintaining the specified force vector direction, on the ‘front right leg’ zone—, applied to the cow skeleton. ........................... 226 C.4 The preview of a fixed nodes application —red remarked nodes, on the ‘head’ zone—, also to the cow skeleton. .................... 226 C.5 The preview of a specified cutting —orange remarked lines, on the ‘front left knee’ zone—, applied to the cow skeleton too. .............. 227 C.6 The ForceReaQTor’s Marching Cubes extracted mesh rendering of a bunny.228 C.7 The FPS error message thrown when the framerate cannot be achieved. . . 229 C.8 ForceReaQTor’s fatal destiny: destabilized simulation. ............ 230 C.9 ForceReaQTor software and hardware requirements logos. ......... 231 Master Thesis in Computer Graphics by Marc Musquera Moreno
* List of Tables PROJECT’SFIRST CONTACT ··· ∅··· THE STATE OF THE ART 3.1 The progressive data increasing with Sierpi´ nski Fractal adaptation . 27 4.1 Advantages and disadvantages of the Marching Cubes algorithm; extracted details from [mrs7]. ....................... 36 6.1 Iterative ODE integration estimated errors in relation to the numerical integrator. ............................... 56 CONTRIBUTIONS AND RESULTS 8.1 Used Mac computers’ specification table. ................ 85 9.1 Basic vectorial data types on GLSL ....................101 9.2 Basic texture data types on GLSL .....................101 9.3 Vectorial component indexes in relation to the data type conventions.101 9.4 Most important ‘uniform’ automatically shader input variables. . . 102 9.5 Most important ‘attribute’ automatically shader input variables. . . 102 9.6 Most important ‘varying’ automatically shader input variables. . . . 102 10.1 Table of supported tokens for the developed OBJ model loader. . . . 110 XXIII
CHAPTER 1 Project Abstract Overview 1.1 3Dpolygonal meshes are, as a simple overview, collections of vertices and polygons defined by vertex pair junctions, here called faces. They are, with no doubt, a good and efficient discrete modelling approximation of a physically real object, widely used in Computer Graphics, because this kind of objects are representing the surface of an object —not its volume; the objects are empty indeed—. On the other side, the simulation of animation or movement in 3DComputer Graphics has been an important research field for some years ago, since the appearance of Pixarrentertainment films. Not only the modelling but also the simulation of realistic movement is essential for a good computing animation. Figure 1.1: A montage of a physicallu-based animation done with AERO simulator, a animation software whose web is www.aero-simulation.de. 3
4 Chapter 1. Project Abstract However, there are two different classes of computer animation, in relation to computational time —not to the methodology complexity—: •exact behaviour, useful for awesome performance with no matters of time, specially coherent for computer animation films, due to there isn’t real-time algorithms1; •approximate behaviour, not exact but approximately realistic, faster and more efficient. These techniques are the adequate for real-time applications like videogames or simulators, and the interesting ones for this thesis purposes; Focusing on the research thesis aims 1.2 Interests and research fields 1.2.1 The goal of this project is to research for real-time approximate methods of physicallybased animation in conjunction with static polygonal meshes with the aim of deforming them and simulating an elastic behaviour for these meshes. Because of this, in this project it has been developed a software suite capable of doing a lot of tasks, each one from different computer graphics research fields, conforming a versatile capability project; so, the developed applications can briefly: •specify a volumetric representation of any polygonal mesh, and will be able to be empty or entirely solid; •building a reconstruction of any mesh, at any desired LOD, directly proportional on the volumetric representation; •interact with any polygonal mesh by a real-time physically-based deformable dynamic model with run-time configurable parameters, based on deforming a 3D non-rigid skeleton built from a volumetric representation; •split any polygonal mesh in the same way as a real solid object by a virtual scalpel; (a) Initial step, before any external force application. The 3D model is relaxed, no internal forces are activated. (b) Deformation in curse; the restricting internal forces are not yet performing but the elasticity is activating them . (c) Force totally applied; now the shape-managing restricting forces are avoiding an uncontrolled deformation. Figure 1.2: Three steps of a dolphin mouth pulling with a 50Napplied force —notice the yellow lines, representing the applied forces to the model—. The snapshots are from one of the two developed applications for this thesis, ForceReaQTor, that executes all the deformation simulations. 1As also happens with the illumination methods like raytracing, which are incredibly realistic but too much computationally expensive for real-time applications. Research on Generic Interactive Deformable 3D Models
1.2. Focusing on the research thesis aims 5 Final result 1.2.2 All the above cited characteristics will be possible and fully-functional due to the two previously mentioned applications comprising an entire dynamic simulation software suite based on physical laws: 1. a mesh visualizer with an integrated volumetric representation generator; 2. a dynamic model simulator that allows force applying and a kind of virtual scalpel, and simulates a physically-based deformation behaviour to the entered 3Dmodels; So, though this software is able to deform any kind of 3Dobjects with a shapemaintaining restricted elastic behaviour —as it can be seen in figure 1.2, where a dolphin’s mouth is the aim of a deformation force—, this interface will be used for a simulation of a human anatomy, focused on the inguinal region, by interacting with the polygonal meshes as approximation of the Visual Human Project gigantic data. A non-interactive simulator 1.2.3 Pitifully, due to the lack of 2Ddesktop applications, the simulator hasn’t a run-time interactive user external force interface with the simulator. This implies, it has been developed a complete external force inducer through a discretized time-line, that allows to create, to modify and to delete external forces as long as specifying cuttings or object fixed portions. There was the intention of developping an interactive simulator within a workbench equipped with a haptic device, but it hasn’t been possible by a matter of time. Master Thesis in Computer Graphics by Marc Musquera Moreno
CHAPTER 2 Objectives and Research Contribution Overview Motivations and interests 2.1 Physically-based computing animation 2.1.1 Computer Animation typologies 2.1.1.1 It’s known that the generic concept of animation refers to show a set of subsequent static images that, displayed coherently fast, offers a feeling of motion. So, the computer animation field don’t differ at all: the basic computer animation consists in an automatic sequence of computer generated frames. However, how this frame sequence differ each other is the problem of computer animation: •the simplest solution is programming explicitly each frame, but it’s at the same the most difficult way; •there are other techniques about specifying —parametrizing— the description of the scene —composed by geometric objects—. Thus, the task of specifying all the image sequences is transformed to the task of specifying how the scene changes through the time. Thanks to the last decade, when the first computer animation movies appeared and the visualization quality of the videogames has been increased exponentially, a wide variety of computer animation techniques have been created and used and improved. However, as it’s said in [mot1], these animation techniques can be subdivided in two fields: •the 2Dtechniques, mainly worried about image manipulation; •the 3Dtechniques, focused overcoat in building huge three-dimensional worlds with also three-dimensional objects and characters, and the way of interaction between each other; 7
8 Chapter 2. Objectives and Research Contribution Overview (a) the classical emphsprite 2Danimation. (b) A3Dmodel with mobile articulation nodes. Figure 2.1: Examples of two and three-dimensional computer animation methodologies. The 3Dcomputer animation 2.1.1.2 The 2Dtechniques will be omitted because this research thesis is about the animation using 3Dtechniques, where the clearly different three steps are: 1. model the scene, describing and placing the different elements of the scene; for this task there is a great offer on modeling 3Dtools as long as multiple 3Dmodel data formats with their own specifications and data storage management; 2. animate the scene, specifying how the scene elements has to be moved in the world in relation to time —or a user actions—; 3. render, converting the instant scene description in screen displayed images; It’s true that, really, the first and last steps are not really an animator task, but although the model stage can be avoided by taking previously built models, the render stage is really a must-have in computer graphics, and computer animation is a branch of computer graphics —CG—. Hence, this thesis will focus the animation and render stages. Kinds of 3Dcomputer animation. Focus on physically-based animation 2.1.1.3 The task of specifying a computer object animation is surprisingly difficult. There are a lot of subtle details that have important weight for getting a coherent animation, and due to that, there are multiple developed techniques for developing three-dimensional animated scenes: •keyframing, that uses inverse kinematics, or linear interpolation for moving objects following determined mathematical equations. It also receives the name of geometric deformation, because the 3Dobject is animated with a deformation due to geometric shape modification. •motion capture, consisting on position sensor capturing within a real object, and after reproducing the different sensor movements in the modelled clone object nodes. •procedural methods, based on using determined iterative algorithms that computing and generating the animation at any moment. Research on Generic Interactive Deformable 3D Models
2.1. Motivations and interests 9 This thesis is focused on procedural methods, and concretely, in the physicallybased techniques. These techniques make use of physical laws —or a numeric approximation to those laws2to generate realistic motion, and due to this, are the most engineeral and programming techniques in front of the more animator talent techniques. Physycally-based simulation is obviously realistic if the model is compatible to the physical characteristics of the method (e.g., particle systems or flexible surfaces), but the main disadvantage is the must-be depth understanding of physical laws. Figure 2.2: Some frameset examples of physically-based animation possibilities. Human musculature studies 2.1.2 Introduction to Human Body Modeling and Animation 2.1.2.1 Since the 1970’s, one of the most interesting areas of computer graphics have been the human figure modeling and animation. Due to the human body complexity, its movement simulation has an equivalent difficulty —the human body is capable to execute a huge number of movements—; it’s known that the human body is composed mainly by a conglomerate of skeleton, muscles, fat and skin, as can be seen in the following computer graphics example system figure: (a) The skeleton-muscle animated system; source [mot2]. (b) Skin over skeleton-muscle; [mot3]. Figure 2.3: The computer graphics standard human anatomy model: skin, skeleton and muscles. 2An approximation is maybe required in the cases —more common than the really desired— where the exact law model is too much complex for being computed in a reasonable computational time. It has to be noticed that the aim of this simulations is to offer a real-time simulation, so the physical behaviour has to be implemented in direct relation to the human smooth continuous vision, between 20 and 40 frames per second —FPS—, although a frame rate of 10 FPS is acceptable in term of interactivity instead of real-time simulation. Master Thesis in Computer Graphics by Marc Musquera Moreno
10 Chapter 2. Objectives and Research Contribution Overview The more standard animated model is —according to [mot2] and [mot5]—: •the skeleton, the vertebrate body, is composed by a hierarchical tree structure, as it’s used, for example, in [mot3] and [mot5], that links the bones between the others, with tree nodes on the articulations with information based on the predefined articulation mobility with respect to their degrees of freedom —DOF—; •the muscles, independently each others, are composed by a inner skeleton covered by a polygonal mesh; thus, the skeleton is moved and the mesh follows the skeleton; •the idea behind the skin is the same for the polygonal muscle mesh; •and the fat, for computer graphics, is modeled into the skin model because the fat is a tissue located beneath the skin, between muscles and skin; Evolution of Human Animation 2.1.2.2 The goal of the human animation has always been the looking for realism of the behaviour movements. hence, during the last 30 years there have been a lot of approaches, and obviously, the more the time passes, the more complexity these approaches have. Articulated Stick Figure Models. So, the first approaches were involved in articulated stick figure models consisting in a hierarchical set or rigid segments —bones— connected at joints —articulations—; besides, each joint could have up to three DOF —Degrees of Freedom— to become a real human articulation. (a) The front and lateral views of the human skeleton, with the remarkes joints; source [mot3]. (b) An computerized stick articulated male; source [mot1]. Figure 2.4: The articulated stick human model scheme. Surface Models. Due to the limitations of the articulated stick model— —mainly the impossibility to perform some kind of movements like twist—, another approach appear: the surface models, composed by a skeleton surrounded by surfaces, made from planar or curved patches that simulate the skin. Thalmann and Thalmann developed in [mot6] the Jointdependent Local Deformation animation algorithm —JLD—, a method based on a local deformation operators set that controls the evolution of these surfaces. Research on Generic Interactive Deformable 3D Models
2.1. Motivations and interests 11 Volume Models. Additionally, there is another proposal: a model that approximate the structure of a 3Dobjet by a grid of volumetric primitives, such as ellipsoids or cylinders; these are the volumetric models3. However, they suffer from non easy control management, due to the huge number of comprising-primitives during the animation. Multi-layered Models. In this approach, a skeleton is the support for intermediate layers that simulate the body —this layers are really an abstract concept of simulation for skin, muscles, or tissues—. Therefore, the animator only has to define the connections between the layers, because animation is an iterative process that: 1. motion specification at joints; 2. deformation according to the new positions; 3. mapping of the overlying layer vertices to the world space; 4. relaxing algorithm for adjusting the elastic equilibrium forces; Figure 2.5: The multi-layered human body animation proposal by Scheepers et al in [mot2]. Main goal for this project 2.1.2.3 This thesis’ interests are focused on the muscle parts, concretely on their physical behaviour and movement simulation but besides, about non-anatomic movements but surgery interactive movements. So, the skin, fat, and human skeleton will be omitted for being out-of-range. Additionally, the developed animation model within the range of this thesis will be able to deform any 3Dmodel with the muscle’s viscuoelastic behaviour, because there will be some configurable parameters, and therefore, any 3Dobject will be capable to be treated as a cuddly toy. 3And the VoxelMaps are the evolution of these volume models, since the cubes —voxels— can occupe all the object volume without intersecting each other. Master Thesis in Computer Graphics by Marc Musquera Moreno
CHAPTER 3 Volumetric Model from a Polygonal Mesh Polygonal Meshes 3.1 Introduction to Polygonal Meshes. The Triangle Meshes 3.1.1 Apolygonal mesh is the basic shape that we use to build our 3Dmodel, or better said, its surface, parametrized by a collection of polygons —composed by a set of vertices that indicate the edges of every polygon—. On the other side, it’s known that a mesh is any of the open spaces in a net or network; that means, an interstice. In front of this apparent contradiction, more explanation is needed. The reason a polygonal mesh is called a mesh, even though the form looks solid when we do a mesh rendering, is that the previously cited surface is actually a wireframe (a mesh of interconnected wires) that gives the surface its shape; even, this object (assuming it’s convex) is empty. In the following figure can be seen this phenomenon, with snapshots from one of the two applications developed for this thesis, MeshInspeQTor: (a) Polygon mesh as wireframe (b) Polygon refilling (c) Phong illumination rendering Figure 3.1: The wireframe essence of a polygonal mesh; here, the dyrtManArmTris. Since the collection of polygons forming the mesh are called faces, it’s obvious that every polygon must define a plane. Because of this, the most used polygons are the triangles —three vertices always define a plane—. 19
20 Chapter 3. Volumetric Model from a Polygonal Mesh The Face-Vertex Mesh Format 3.1.2 There are a lot of mesh specifications, as commented in [vox1], but the most common one is the face-vertex mesh format. It consists in two lists: 1. a list of vertices, consisting in the coordinates of every vertex; 2. a list of faces, consisting in a set of indexes, indicating which vertices are forming the cited face —polygon—; Here is a simple example of a cube with the face-vertex specification, where every face is a triangle —a cube is composed by 8 vertices and 6 quads (12 triangles)—: index coordinates 0 0.0 0.0 0.0 1 0.0 0.0 1.0 2 0.0 1.0 0.0 3 0.0 1.0 1.0 4 1.0 0.0 0.0 5 1.0 0.0 1.0 6 1.0 1.0 0.0 7 1.0 1.0 1.0 (a) Vertex List index vertex indexs 0 0 6 4 1 0 2 6 2 0 3 2 3 0 1 3 4 2 7 6 5 2 3 7 6 4 6 7 7 4 7 5 8 0 4 5 9 0 5 1 10 1 5 7 11 1 7 3 (b) Face List (c) Displaying the cube Figure 3.2: A triangle mesh with face-vertex specification composing a cube. Mesh Voxelization 3.2 The volumetric models. The voxelization process 3.2.1 Introduction to the voxel space 3.2.1.1 Let’s divide the computer graphics space into a grid of n×n×ntangent boxes containing the volumetric space inside every box, or cube. Then the space has been transformed to a voxel space, or voxelmap, and every box is called voxel, abbreviation for volume element. Conceptually, the 3Dvoxel is the 3Dcounterpart of the 2Dpixel, and in the same way, exactly like a voxel is the quantum unit of volume —it has a numeric value (or values) associated with some measurable properties of the polygonal mesh scene—. So, through a parallelism with the process of making a photograph of the real world5, it’s called voxelization, according to [vox2], the process of transformating a geometric representation (a polygonal mesh, or a parametric surface) into a voxelmap where the associated voxel values are representing the best approximation of the scene model within the discrete voxel space. 5More accurate and technical, the more adequate counterpart of voxelization is the rasterization —screen drawing by pixels— of 2Dgeometric objects, although voxelization process does not render the voxels but generates a discrete digitization of a continuous 3Dobject. Research on Generic Interactive Deformable 3D Models
3.2. Mesh Voxelization 21 Here can be seen three different voxelizations of the same model, dolphin; notice the ascendent accuracy as long as the number of voxels in the grid increase: (a) Original mesh (b) 8×8×8voxels (c) 32 ×32 ×32 voxels (d) 128 ×128 ×128 voxels Figure 3.3: Examples of three voxelizations of the model dolphin, executed by MeshInspeQTor software. The 3Ddiscrete topology 3.2.1.2 Like any discretization process, voxelization is not infallible; that means, the voxelization can result in the existence of valid voxels considered invalid ones, which can make harder the voxel entity identification with respect to the voxelmap. For solving this problematic situations, a connectivity postfilter is needed. This filter passes through the voxel space, or voxelmap, and analyses the connectivity of different voxels considering three possible adjacency settings; hence, one voxel is connected to another one by following these three policies from [vox3]: •6-adjacency, where two voxels are considered linked if they are adjacent by any entire face; •18-adjacency, where the connectivity is accepted for the previous 6 voxels, and also their upper and lower ones; •26-adjacency, where the entire surrouding voxels for each voxels are candidates; Figure 3.4: Voxel connectivity policies Master Thesis in Computer Graphics by Marc Musquera Moreno
22 Chapter 3. Volumetric Model from a Polygonal Mesh The Problem: Triangle VS Voxel 3.2.2 Introduction 3.2.2.1 Given a mesh M, composed by a set of faces F, and a voxelmap X, the voxelization process VX(M)that modifies Xwill set valid voxels —that is, voxels that are intersecting any face composing the mesh— to true boolean value, and invalid voxels to false; so, the final result is a discrete approximation by cubes within Xof the mesh M, and it implies that, supposing Ma convex mesh (thus, empty), there will be invalid voxels outside as long as inside the voxelization of M,VX(M). More accurately, focusing in the intersection test between a voxel Vand a triangle T6, both two in R3, their relative position is given by the existence of a finite and delimited coplanar zone between them. This is, two conditions must be accomplished, one more restrictive than the previous: 1. the T’s containing plane must intersect the voxel —cube— V: T∩V6= Ø ⇐⇒ T⊂π∈R3∧π∩V6= Ø 2. T—or a piece of it— must intersect V: Q≡π∩V=⇒T⊆Q Indeed, the problem is equilavent to its 2Danalogue discussion: coplanar trianglesquare relative position. In the next figure the four relative positions between a triangle and a square are featured: Figure 3.5: 2Drelative position between a square and a triangle. The test’s simplest case: gigantic meshes in low-grid voxelmaps 3.2.2.2 When a gigantic mesh M, composed by n10000 faces, is voxelized over a voxelmap Vwith a grid of big voxels, it can be assumed that, if the mesh is well-formed, every triangle will be tiny with respect to the voxel face area; that implies that: •the surrounded relative position at figure 3.5 between Tand Vis impossible; •each triangle Twill be included only in 1-level connectivity adjacent voxels; •if all the triangles are adjacent to any other triangle, there won’t be valid voxels with no mesh vertex; Therefore, the triangle-voxel intersection in that case is very simple: the algorithm only has to test if there are some triangle vertices within the voxel. 6From now, faces will be triangles for a more simple point of view of the problem. Research on Generic Interactive Deformable 3D Models
3.2. Mesh Voxelization 23 (a) 1inner vertex (b) All inner vertices (c) No inner vertices (d) Method unstability example Figure 3.6: Testing T∩Vby triangle-box test based on vertex containing checking; output by a Matlab code written for this thesis by its author. This method is the most powerful and fast, because the checking is direct or quasidirect, depending on the voxel bounding box typology, as there is in the figure 3.7: •Axis-Aligned Bounding Box AABB: all the voxel faces are parallel to one of the canonical axis, so with the minimum and maximum bounding box coordinates; so the i-th vertex of a triangle tis within the cube if its (x, y, z)coordinates are all in the box range: T=t1t2t3→ti⊂V≡ tix∈[Vminx, Vmaxx] tiy∈[Vminy, Vmaxy] tiz∈[Vminz, Vmaxz] =⇒ ∃i∈ {1,2,3}t.q. ti⊂V=⇒T∩V •Object-Oriented Bounding Box OOBB: knowing that, given the plane πequation and a point P, the plane-point relative position is able for knowing the plane normal with this calculus: π:ax +by +cz +d= 0, P = (px, py, pz) =⇒ π(P)>0→upper π(P)>0→contained π(P)>0→lower ; so, the testing is done by checking if, for all the six cube faces, any vertex of a triangle is intern. However, if any of the three previous conditions is not fulfilled (e.g., the longest triangle edge is greater than the middle of voxel edge), this method is too unstable. Master Thesis in Computer Graphics by Marc Musquera Moreno
24 Chapter 3. Volumetric Model from a Polygonal Mesh Figure 3.7: Tipology of Bounding Boxes depending on their orientation; source [voxB] (edited). Here’s the pseudocode for the triangle-box —AABB assuming— test by vertex checking; at the figure 3.6 on previous page there are some examples from the same code written in Matlab, including an unstable test where an inner triangle is considered extern. 1function triboxAABB_vertexcheck( Cube C, Triangle T ) 2returns bool 3Vertex cubemin = getCubeMinorVertex( C ); 4Vertex cubemax = getCubeMajorVertex( C ); 5int innerverts = 0; 6for k= 1 to 3do 7Vertex vert = T.getVertex(k); 8if between( vert.x, [cubemin.x, cubemax.x] and ... 9between( vert.y, [cubemin.y, cubemax.y] and ... 10 between( vert.z, [cubemin.z, cubemax.z] then 11 innerverts = innerverts + 1; 12 endif 13 endfor 14 if( innerverts > 0 ) return true; 15 else return false; 16 endif 17 endfunction PSEUDO code 3.1: Triangle-box test by vertex checking. Test’s generic case: voxelization of any mesh at any LOD. Alternative techniques 3.2.2.3 Due to the huge amount of mesh pecualiarities, it cannot be supposed that vertexvoxel testing will be always valid, so a generic case is needed. Let’s present some of the different alternatives. Greedy Algorithm. The first approach, the greedy algorithm, is computationally prohibitive: 1. to find the Qarea mentioned in the section 3.2.2.1, on the page 22, then, the intersection zone between (π⊃T)∩V; 2. if Qis not null, check if the triangle, or a part of it, is in Q:T⊂Q; because the first step implies: •find the six intersections between (π⊃T)∩fi, i = 1..6, being fithe i-th face of V; •store the polygon generated by the six lines; Research on Generic Interactive Deformable 3D Models
3.2. Mesh Voxelization 25 Intersection between triangle and voxel edges. Gernot Hoffmann, in [vox4], presents an alternative to greedy algorithm, to give more efficiency on the same calculus: his algorithm doesn’t find the intersection between π⊃Tand the six voxel faces but with its twelve edges, as can be seen in the next figure. Finally, it’s easy to check a possible intersection between the two areas, the Pintersection polygon one, and the Tone. (a) Plane-cube intersection test at [vox4]. (b) Triangle-Point container area method (intern, extern) Figure 3.8: The Gernot Hoffmann Triangle-Voxel intersection test. However, this method is still unstable due to those cases where a voxel’s inner triangle doesn’t intersect any cube’s edge, as it can be seen in these Matlab plots obtained by this project’s student own code implementation of this method. (a) Inner triangle. (b) Outer triangle. (c) Algorithm conflict. Figure 3.9: The Gernot Hoffmann Triangle-Voxel intersection test results adquired by this document’s author by his own Matlab programmed implementation of this proposal. Sierpi´nski’s Fractal for Triangle Area Discretization. This fractal7was introduced in 1915 by the polish mathematic Wac law Sierpi´nski, and consists, as said in [vox5] and [vox6], in this iterative triangle subdivision, that starts with an equilater triangle: 1. draw three lines that connect the midpoints of the triangle’s sides. The result is a centered white triangle; 2. the original triangle is now divided into three smaller triangles, and for each one, repeat again; 7A Fractal is a semi-geometric object with a peculiar structure: it’s repeated whatever the scale you use to represent it. Master Thesis in Computer Graphics by Marc Musquera Moreno
26 Chapter 3. Volumetric Model from a Polygonal Mesh Here you can see the starting point and the first three iterations, made from an arbitrary —non equilater— triangle with a Matlab code written by this thesis author for research testing purposes: (a) Starting point (b) 1st iteration (c) 2nd iteration (d) 3rd iteration Figure 3.10: The first three iterations of the Sierpi´nski Fractal. This fractal is able to, indeed, be used for discretizing the triangle area, by modifying the fractal method with not rejecting the centre triangle but also counting with it for post subdivisions, hence, the final result is a coherent and equitative discretization of the triangle area: (a) Starting point (b) 1st iteration (c) 2nd iteration (d) 3rd iteration Figure 3.11: The Sierpi´nski Fractal Matlab plottings of the thesis’ author own adaptation code for triangle area discretizations. Since the main problem for the generic voxelization case is the abstract level of the triangle area, this fractal can be used for implementing the fast algorithm decribed in 3.2.2.2, on page 22; that is, execute the vertex-voxel test for every vertex as result of each triangle area discretization from a mesh, with a code like the following one: 1function triboxAABB_sierpinski( Cube C, Triangle T, ... 2int level ) 3returns bool 4{ ’level’ indicated the algorithm recursive steps } 5Set<Triangle> AST = getAdaptedSierpinski( T, level ); 6for k=1to AST.length() do 7if( triboxAABB_vertexcheck( C, AST.elem(k) ) then 8return true; 9endif 10 endfor 11 return false; 12 endfunction PSEUDO code 3.2: Triangle-box test based on Sierpinski fractal adaptation. However, there are two great disadvantges for this methodology, both focused on the number of desired fractal iteration levels: Research on Generic Interactive Deformable 3D Models
3.2. Mesh Voxelization 27 •what is the most adequate iteration limit level per each triangle, due to, although it’s a good discretization of the total triangle area, it’s not sure that if the triangle intersects a voxel, there will be some discretization vertices within the cube; •as long as the iteration level increases, the number of triangles also increases; consequently, the number of vertices per original triangle grows very much, as it’s shown on this table: # iteration 0 1 2 3 ... n # triangles 1 4 16 64 ... 4n # vertices 3 6 15 46 ... Pαn i=0 i, nα0=2 αi=α(i−1)+(α(i−1)−1) Table 3.1: The progressive data increasing with Sierpi´nski Fractal adaptation Separating Axis Theorem Derived Approach. Tomas Akenine-M¨oller featured in 2001, on [vox7], a fast testing for 3Dtriangle-cube overlap checking. This method is based on the separating axis theorem, saying that two meshes, MAand MB, are not intersecting if and only if there is a plane πsseparating them, one in each “side” of the plane: •let πsbe a considered separator plane of two meshes MAand MB; •let nπsthe πsnormal rect; if the two mesh projections over nπsdon’t intersect, this line is called separator axis;ergo,πsis a separator plane. Figure 3.12: Scheme of a separator axis; notice that the normal projections of two meshes MAand MBare not intersecting; so, the two meshes are not intersecting, and thus, πsis a separator plane. Besides, Akenine-M¨ oller proofs that, for a 3Dconvex meshes8there is a more focuses theorem; two convex meshes CAand CBare disjoint if and only if one of these three axis are tipified as separator axis: 8The most common 3Dmeshes that model a really physical object. Master Thesis in Computer Graphics by Marc Musquera Moreno
34 Chapter 4. Polygonal Mesh Reconstruction: Multiresolution Meshes In the next page there’s a complete visual guide of the six voxel carving steps applied to the voxelization of a torus mesh. Let’s notice the clear difference of the carved torus voxelmap (down) with respect to the uncarved one (up), where only a standard mesh voxelization has been executed. IsoSurface Extraction Algorithms 4.3 IsoSurface extraction as multiresolution mesh construction 4.3.1 Far away from volume rendering techniques, that are out of the range of this thesis, the aim of this section is to introduce a few techniques, the most famous ones, for generating a fast extrapolated triangular mesh from an isosurface. It’s a computational field commonly used for medical purposes —as really aimed this thesis—, since isosurfaces are widely created from a set of three-dimensional CT scan, allowing the visualization of internal organs, bones, or other structures. However, this thesis only concerns preloaded polygonal meshes; thus, the 3Disosurface generation from this medical images is, again, out of the range of this project. Nevertheless, the main idea of these algorithms, due to the efficient mesh generation provided by two techniques, called Marching Cubes and Marching Tetrahedra9, is to build a multiresolution clone of any mesh, calling one of these methods by passing them the isosurface for the mesh voxelmap. Marching Cubes 4.3.2 Overview 4.3.2.1 Originally proposed by Lorensen and Cline in their 1984 paper [mrs6], it consists basically —and without entering into implementation details— in: 1. with the support of a look up table —LUT— of all the possible unit voxel tipologies with their triangulations (precalculated in relation to a real isosurface offset), it generates the most coherent connectivity inter slices10; 2. after that, it processes de 3Ddata and, using linear interpolation, calculates the current triangle vertices; 3. for a convenient mesh shading, the normals are calculated from the original isosurface data gradient; With this method, all the voxel locations where the isosurface passes through are determined, so it’s possible to generate triangles joining this isosurface-voxel intersection points. The final surface is generated when all the triangles are generated and coherently joined. 9Although the second is really a variation of the first, considered a standard approach to the isosurface extraction problem from a volumetric dataset. 10 This LUT, that will deserve its own section later at the page 36, , is only for frontier voxels, that is, voxels partially included in the original isosurface. In other words, a voxel is tipified as frontier if there are some voxel vertices considered inner the isosurface, and the rest of vertices are considered outer. Research on Generic Interactive Deformable 3D Models
4.3. IsoSurface Extraction Algorithms 35 (a) Torus 64 ×64 ×64 uncarved voxelmap. (b) Transversal section of uncarved voxelmap. ⇓ (c) Voxel Carving, step 1:X+.(d) Voxel Carving, step 2:Y+.(e) Voxel Carving, step 3:Z+. (f) Voxel Carving, step 4:X−.(g) Voxel Carving, step 5:Y−.(h) Voxel Carving, step 6:Z−. ⇓ (i) Torus 64 ×64 ×64 carved voxelmap.. (j) Transversal section of carved voxelmap. Figure 4.6: Voxel Carving applied to a standard 64 ×64 ×64 voxelization of the torus model. Since the final voxelmap is the intersection of the six voxel carving steps, the volumetric model of torus is filled. As usual, frameset created by the thesis purpose software MeshInspeQTor. Master Thesis in Computer Graphics by Marc Musquera Moreno
36 Chapter 4. Polygonal Mesh Reconstruction: Multiresolution Meshes Advantages and disadvantages 4.3.2.2 Advantages Disadvantages A1 High resolution, voxelmap D1 Possible holes in the generated size depending. mesh from the isosurface. A2 Easy and fast rendering. D2 Final quality of the mesh is strongly A3 Good quality meshes with isosurface-depending; and the low cost (CPU time). isosurface is threshold-segmented so the original data must be excellent to avoid problems. Table 4.1: Advantages and disadvantages of the Marching Cubes algorithm; extracted details from [mrs7]. The isosurface-voxel intersection case LUT. Shortcomings 4.3.2.3 When the algorithm is analyzing the cube-isosurface intersections for a voxel, there are 256 possible intersections; however, they are reduced to 128 by complement situations11, and by rotations, this number is reduced again, obtaining 15 absolute possible intersections, shown in the following figure: Figure 4.7: The 15 absolute cube-isosurface intersection situations; source [mrs8]. 11 Inverting the marked intersection points within the voxel, and the triangle normals must be inverted too for coherence. Research on Generic Interactive Deformable 3D Models
4.3. IsoSurface Extraction Algorithms 37 However, there are some ambiguous cases where, in case of choosing a bad cubeisosurface intersection type, a mesh hole can be produced, as the remarked table 4.1(D1) disadvantage tells; there are some solution approaches, like those who can be found on [mrs9] and [mrsA]. A clear example of hole can be seen in the following figure: Figure 4.8: An example of hole in a marching cubes generated mesh, as the result of an ambiguous case; source [mrs8] (edited). Nevertheless, it’s a good algorithm and widely used for automatic generation of triangular meshes from an isosurface —e.g., taken from tomographies and medical scanners properly—; so its pseudocode should be something like that: 1function marchingcubes( VoxelGrid VG, Isosurface S ) 2returns TriangularMesh 3Set<Point> SP; 4foreach Voxel V in VG do 5{ marks the voxel as inside or outside in 6relation to the isosurface volume } 7VG.setStatus( V, S ); 8foreach Edge E in Vdo 9{ an edge is an isosurface boundary 10 if it has an inner vertex being 11 outer the other, from isosurface } 12 if isBoundary( E, S ) then 13 SP.add( middlepoint(E) ); 14 endif 15 endforeach 16 endforeach 17 TriangularMesh M; 18 M = generateMeshByPointSetTriangulation( SP ); 19 endfunction PSEUDO code 4.1: The Marching Cubes isosurface extraction algorithm. Marching Tetrahedron 4.3.3 Overview and shortcomings 4.3.3.1 As explained previously in the introduction of this section, there is a Marching Cubes method variant, called Marching Tetrahedra. Its approach is based on the same Marching Cubes philosophy but here, each voxel will be subdivided in five tetrahedrons. This technique can produce a smoother generated mesh than the Marching Cubes resulting one, but it’s also true that due to this tetrahedron subdivision, an increasing number of triangles is produced, and it’s possible to have too much polygons where it isn’t needed. Master Thesis in Computer Graphics by Marc Musquera Moreno
38 Chapter 4. Polygonal Mesh Reconstruction: Multiresolution Meshes Figure 4.9: The Marching Tetrahedra cell subdivision scheme. Each voxel will be treated as five independent tetrahedrons, so the method is more accurate and smooth with the discrete shape of volumetric unit than marching Cubes; source [mrs8]. As it can be deduced, the algorithm steps are the same that the Marching Cubes method, but taking into acount that the planar facet approximation to the isosurface is calculated for each tetrahedron independently. The facet vertices are determined by linearly interpolating the place where isosurface cuts the edges of the tetrahedron, as in Marching Cubes. The Marching Tetrahedra LUT 4.3.3.2 Figure 4.10: The Marching Tetrahedra cell subdivision scheme; source [mrs8]. Research on Generic Interactive Deformable 3D Models
4.3. IsoSurface Extraction Algorithms 39 The figure on the previous page illustrates the tetrahedron-isosurface possible intersections, after complementation and rotation reducements12. The hollow and filled circles at the vertices of the tetrahedron indicate that the vertices are on different sides of the isosurface. The most important advantage with respect to its original method, Marching Cubes, is that this triangulation intersection LUT has no ambiguous situations. But, as it has been said, the number of generated triangles will be much greater than the Marching Cubes generated mesh would have. 12 There is a configuration left. The case not illustrated is where all the vertices are either above of below the isosurface; then no facets are generated. Master Thesis in Computer Graphics by Marc Musquera Moreno
CHAPTER 5 3D Object Model Animation/Deformation Point-Oriented Deformation 5.1 The Point-Sampled Geometry 5.1.1 There is a recent branch, appeared since 2002 due to Zwicker et al’s Pointshop3D [geo1] proposal; it’s a system for interactive and appearance editing of 3Dpoint-sampled geometry; that is, a geometry with no vertex connectivity information. Based on a novel interactive point cloud parameterization and an adaptive remeshing method, this system permits to transfer the 2Dimage editing capabilities to an irregular 3Dpoint set. Unlike 2Dpixels, the absence of connectivity gathered with the irregularity of the point-sampled patterns are the reasons for this system, like a 3Dphoto editing software. The idea behind that is purely based on irregular 3Dpoints as the image primitives. Briefly, the process is, as seen in the autoexplanatory example figure above, to spread 2Dimage pixels over 3Dsurface pixels —surfels—. Figure 5.1: Hybrid system featured in [geo2], consisting in a hybrid geometry representation combining point clouds with implcit surface definitions. Note: the middle image is the colored sample density map. 41
42 Chapter 5. 3D Object Model Animation/Deformation One year later, in 2003,Pauly et al proposed in [geo2] a free-form shape modeling framework for point-sampled geometry that takes benefit of the minimum consistency requirements of point clouds for developing an on-the-fly surface restructuration, supporting geometric deformations in interactive time. In the figure above there’s an example of a reconstructed planck 3Dmodel mesh from a point cloud. Point-sampled deformation 5.1.2 In [geo3] there’s an approach for collision detecting and dynamical deformation response, based on continuum mechanics, everything done on 3Dobjects where the volume as well as the representing surface are point-based sets. Developed by M¨uller et al from their previous work [geo4], it offers a complete animation framework schematized in the following figure. Figure 5.2: Scheme of the contact handling framework developed in [geo3]. In more technical terms, in [geo3] a point-based object, called Γk, is defined as a cloud of nsurfels sk—surface elements—, animated over a set of mphyxels pk—points, physical elements— with position xk∈R3. So, an overview of this point-based animation system, in relation to this nomenclature, should be the following: •dynamic simulation; the scheme for all msample points —and for each time step ∆t— dynamic simulation loop is something like this, extracted from [geo4] quasidirectly: ut (displacements) =⇒ Out→εt→σt→ft (derivatives) (strains) (stresses) (forces) |{z } spatial derivatives by Moving Least Squares —MLS— procedure =⇒ut+∆t (integration) where the MLS procedure is the most common position interpolation in mesh free algorithms13, consisting in, according to [geo5], the calculation of a biased weighted least squares measure towards the region around the point at which the reconstructed value is requested. 13 A mesh-free is a mesh composed by a set of unorganized point samples. Research on Generic Interactive Deformable 3D Models
5.2. Geometric Deformation 43 •collision detection; here the goal is to find new surfels inside of any of the other n surfel-bounding objects for a collision between Γ1and Γ2; that is, to find a contact surface Φ1,2lying in the intersection volume V1,2= Γ1∩Γ2. The surfels of Φ1,2are called contact surfels, and for each of them, there’s a penalty and friction force to be computed, like in the following figure14: Figure 5.3: Penalty and friction force processing for Γ1in front of a Γ2collision; source [geo3]. This research field is totally outside this thesis, so the details of the algorithms won’t be explained and studied deeply. However, it’s an entire and innovative method of rendering, deformation and animation, so it has deserved a special mention about its basis and capabilities. Thus, in the following figure there’s a complete example of Max Planck bust where elastic, plastic, melting and solidifying animation models are shown: . Figure 5.4: Example of point-sampled object animation with the [geo4] method; the two left figures are representing the phyxel-surfel representation and the MLS reconstructed mesh. Geometric Deformation 5.2 Global or local deformation operators 5.2.1 Reminder: the jacobian matrix JFof a function F 5.2.1.1 First of all, a jacobian matrix must be defined as a reminder: assuming F:Rn→Rm a function, n, m ∈N+,Fis given by mreal-value component functions: F:Rn//Rm x//y=F(x) ⇓ x∈Rn≡x1, x2, . . . , xn=⇒y∈Rm≡y1(x), y2(x), . . . , ym(x) 14 The details won’t be explained here; for more information, please read [geo3]. Master Thesis in Computer Graphics by Marc Musquera Moreno
50 Chapter 5. 3D Object Model Animation/Deformation Figure 5.12: Asphere axis deformation: on the left there’s the undeformed sphere with the defined axis, also undeformed; on the right, the sphere, deformed in an intuitive and consistent way with the axis deformation; source [geoD]. Algorithm Details 5.2.3.2 This method’s problem is to find the way to pass the axis deformations to the object. For managing this obstacle, the authors propose a three-step process: 1. each object vertex Vhas to be attached to one axis point AV, and its local coordinates have to be computed; for doing this, the authors implement the closestvertex-point strategy, though they warn that it may be conflictive for complex axis20. 2. the deformed transformation for finding axis point A0 V—homologous to AV— is used to compute the deformation of the object vertex’s (x, y, z)local coordinates; the direct transformation doesn’t need any explanation, but the problem of finding the local coordinate frames between AVand A0 Vis solved with the Frenet frame21. 3. in order to localize the to-be-deformed area by this local coordinate system, a zone of influence is defined for finding the desired 3Dspace portion. Figure 5.13: The horseshoe axis deformation. Please notice the axis, now adapted to the object surface; thus, the deformation can be so complex as can be seen in the right image; source [geoD]. 20 e.g., two —or more— axis points at the closest distance from a object vertex. 21 For each point of a 3Dcurve, the Frenet frame is represented by three ortogonal unitary vectors: tangent, normal and binormal of the curve at that point. A binormal unit vector Bassociated to a curve point is defined as the cross product of the tangent vector Tand the normal one N. A non-unique normal at curve point is obviously a huge problem Research on Generic Interactive Deformable 3D Models
5.2. Geometric Deformation 51 Advantages and lacks of AXDF 5.2.3.3 •since the deformation is object-independent, it can be re-used as much as wanted, and besides, it can be applied to any kind of modeled objects; •it can be combined with other deformation techniques, such FFD; •a set of subsequent axis can be used for a keyframing object-deforming animation. However, the technique isn’t infalible, due to a lack of ambiguity in the two steps of deformation process:(i) it can be more than one axis point candidate for being associated to an object vertex, and (ii) a3Dcurve hasn’t a unique normal at a single point, so the coordinate frame following the Frenet method is not a good solution. Nevertheless, for simple axis, it’s a successful method. Deformation by Wires 5.2.4 Introduction and wire definition 5.2.4.1 Related to the previous axial deformations, there is an approach from 1998 by Singh and Fiume at [geoE], where they bring geometric and deformation modeling joined together by using a collection of wires as a representation of the object surface, and a directly manipulated deformation primitive at the same time. Figure 5.14: An example of a facial modeling by ‘wire’ specification, and the next animation and deformation by ‘wire’ manipulation; source [geoE]. The authors define a wire as a curve whose manipulation deforms the surface of an associated object near the curve. Its specification is a tuple < W, R, s, r, f >, where: •Wand Rare free-form parametric curves —the wire curve and the reference curve respectively; Wwill be deformed and Rwill be useful for comparatives and transformations, and can be swapped within the method for complex calculum—, •sis a scalar that controls radial scaling around the curve, •ris another scalar defining an influence radius around the curve, •and f:R+→[0,1] is the density function, and must be at least C1and monotonically decreasing. Master Thesis in Computer Graphics by Marc Musquera Moreno
52 Chapter 5. 3D Object Model Animation/Deformation Algorithm overview 5.2.4.2 Briefly, when an object is bound to the wire, the method follows these steps: 1. the wire’s domain of influence is indicated by a r-radial surface offset around the reference curve R; 2. using f, the within-offset object points are computed to find its deformation influence; 3. Wis manipulated, and every undeformed point object will be deformed if its deformation influence is great; next, a W-R-swapping is executed, in order to have as reference the last deformation; Figure 5.15: Deformation of a point Pto Pdef by a wire W. The figure parameter pRis the correspondence point, within R, of P; source [geoE]. Research on Generic Interactive Deformable 3D Models
CHAPTER 6 Physically-Based Deformations Introduction to deformation based on physics 6.1 Overview of time stepping deformation algorithms 6.1.1 Accuracy VS speed performance 6.1.1.1 Nowadays, some precise and complex simulation methods based on physics and dynamics have been developed from engineering22. These deformation-based animation algorithms are non-real-time because of their complexity, since they are so sofisticated; however, as Thomas Jacobsen says in [phy1], for an interactive use, real-time is the primary concert, so the accuracy is not as important as three another handicaps: •belieavability, properly parameterized for immersive feeling improvements; •stability: a physical deformation method isn’t good if the object seems to drift, or vibrates, or if the model simply explodes by an iteration’s result divergence; •execution time, because the available computational time is really a little portion of the single-frame timing. From now, this timing will be called time step. 1time_step = sys_clock(); 2while true do 3time_step = sys_clock() - time_step; 4foreach Object O in Scene S do 5S.O = deformObject( S.O, time_step ); 6drawObject( S.O ); 7endforeach; 8endwhile PSEUDO code 6.1: vast algorithm for a deformation animation. 22 And almost of them are always composed by an iterative method due to the computer graphics iterative rendering integration —each animation frame must be rendered subsequently from the previous one—. 53
54 Chapter 6. Physically-Based Deformations A simple particle Pas the deformation system 6.1.2 Before entering the complex analysis and deformation management and handling methodologies for deformation models, a list of concepts and strategies will be defined now as if the entire system was a simple particle, called P. So, according to Susin’s Volume Modeling Course at [phy2], there are two concepts to be taken in account: the state vector, and the time step associated to a numerical integrator. State Vector and Vector Field of a simple particle 6.1.2.1 State vector x(t) . The Pposition through the time-line will be defined by its state vector x(t), which can contain several parameters: position,velocity,previous position,mass. . . Besides, the time-dependent evolution of the state vector is given by the following ODE23: ˙x=dx dt =fx(t), t where velocity ˙xis the space variation in relation to the time; so, by knowing the initial Pposition, the initial value problem is about to find the Pposition at any time step. The state vector dimension will, at least, be the same dimension of the space where Pis moving along. So, for the most physically-based deformation system, implementing the Newton’s 2nd law, the velocity will have to be introduced as a variable (since acceleration ais the second order derivative of the position x,ergo a≡¨x:) a=F m=⇒¨x=f(x, t)→˙x=v ˙v=f(x, t)=⇒˙x ˙v=⇒v fx, t; now the system dimension is 2n, being nthe dimension of x∈Rn. ODE vector field. The ˙xvelocity can be interpreted as the x(t)tangent line’s slope at instant t. In other words, a vector that indicates the direction. Thus, for each space coordinates where the ODE is defined, there will be a director vector. The set of these plane point-director vector is called ODE vectorial field. The time step ∆t. The numerical integrator concept. The Euler numerical integrator 6.1.2.2 Almost every particle P’s path-tracking method is based on a time discretization, so the particle is going along its trajectory by small time steps ∆t, called here integration steps. Thus, the next step position will be defined as xt+ ∆t=x(t)+∆tf(x, t); so it’s easy to generate subsequent configurations x(0), x(∆t), x(2∆t), . . . , x(n∆t). Additionally, following the previously mentioned iterative scheme, the resulting equation is the ODE integration’s Euler method: xn+1 =xn+ ∆tf(xn, tn) 23 Acronym of Ordinary Differential Equation. An ODE is an equation that involves a function and its derivatives, such that a n-order ODE has the form F`x, y, y0,...,y(n)´= 0. Research on Generic Interactive Deformable 3D Models
6.1. Introduction to deformation based on physics 55 The integration system scheme 6.1.2.3 The numerical integrators have been finally defined, and also the common approach of Newton’s 2nd law for their resulting convergence. But, additionally, as said in [phy4], there are another two important factors for any physically-based deformation iterative system, external to the system itself and of stochastic nature: 1. collision handling; a collision can be between two objects, or self-collisions between different parts of the same object; besides, the object can be rigid or nonrigid, and the collision handling can derive to one of two kinds: elastic or inelastic; 2. constraint management; a deformable object can be configured with some constraints or restrictions; e.g., volume preservation, maximum deformation angle, elasticity or damping limit values, . .. and all those constraints must be managed and solved if anyone is violated; This two factors will be studied later, on the next pages, in more detail. Nevertheless, now in the next figure there is a scheme of a simple iteration on a numerical integration system focused on physically-based deformations; please notice all the stages: the integration step, the solver due to the Newton’s 2nd law applying to the system, and constraint and collision management24. Figure 6.1: Architecture of an iterative integration system for animation by deformation; source [phy4]. The most used ODE integrators 6.1.2.4 Apart from the Euler method, there are other numerical integrators; the most common, however, are the following: •Modified Euler Method, or Runge-Kutta 2; the idea is to improve the main time step by an intermediate step; in more tecnhical terms, the formula is as follows: xn+1 =xn+ ∆t fxn+ (∆t/2)f(xn, tn), tn+ (∆t/2) 24 The scheme indicates clearly that collisions and constraints are external factors of the system; that is, stochastic events to be handled that modify extremely a particle’s state vector. Master Thesis in Computer Graphics by Marc Musquera Moreno
56 Chapter 6. Physically-Based Deformations •Runge-Kutta 4; following the strategy of the Runge-Kutta 2method, but now there are 4subiterations: xn+1 =xn+(1/6)k1+2k2+2k3+k4⇐= k1= ∆tfxn, tn k2= ∆tfxn+ (k1/2), tn+ (∆t/2) k3= ∆tfxn+ (k2/2), tn+ (∆t/2) k4= ∆tfxn+k3, tn+ ∆t •Verlet; this is an approach featured on [phy1] by Thomas Jakobsen; he calls this method a velocityless integrator due to the velocity approximation by the difference between the actual and the previous position25: xnew =xold +vold∆t vnew =vold +aold∆t=⇒xnew = (2xold −xprev) + aold∆t xprev =xold Accuracy and stability of numerical integrators 6.1.2.5 Each possible numerical integrator has to find the equilibrium between accuracy — the accumulated error in a certain step in relation to the real value— and stability —the integrator must always make the system converge to the correct solution— in contrast to the time step. Accuracy. The accumulated error of an iterative step cannot be calculated because the real value isn’t available, but can be estimated in function of the time step ∆tand the numerical integrator used;e.g., the already cited Euler method has an error of O(∆t)2. Hence, there are two possible strategies to improve the particle path calculus: 1. decrease the time step; this will improve the precision but the computation step number will increase and besides physics-dedicated-time per frame will be reduced26, so the method modification maybe can not be possible; 2. to change the numerical integrator, with a greater error order O(∆t)k, k ≥3; in the following table are shown the error measure estimations of the most common numerical integrators Numeric Integrator Estimated Error Euler O(∆t)2 Euler Modified (Runge-Kutta 2)O(∆t)3 Runge-Kutta 4O(∆t)5 Verlet O(∆t)2 Table 6.1: Iterative ODE integration estimated errors in relation to the numerical integrator. 25 In other words, this method doesn’t store the position and velocity values but the previous and actual position; by this, a linear and energy-constant approximation of the velocity is assumed, but the number of perations is dramatically reduced. 26 Here it’s studied only a particle P, but when there is a particle system, this computation step is transformed to a equation system, and then the time step is very important. Research on Generic Interactive Deformable 3D Models
6.1. Introduction to deformation based on physics 57 Stability or Convergence. The most important requirement on a ODE deformation system like the studied in this chapter is, with no doubt, its stability. So, is defined a stiff ODE the system who always converges —and quickly— to an equilibrium state, whatever it is. Thus, an integration scheme that is yielding a bounded solution —due to a suitable numerical method— is called stable. The stability of a system is extremely related to the time step. There is a clear example of that in the following figure about the state vector ˙x=−kx. Notice that the system is oscillating for a time step h > 1/k, and is completely unstable for time steps h > 2/k: Figure 6.2: Stability scheme by ODE system plottings depending on the time step h; source [phy3]. However, there are some proposals for solving possible unstablements. For example, by using adaptative time step handling, and always selecting the greater time step possible, the stability will be increased27. Nevertheless, since computation requires to establish a native minimum time step, the stability is not always warranted. Another good solution is considering an implicit methodology, where all the possible slope changings are taken into account; indeed, the idea is to find the mean of slopes x(t+ ∆t) = x(t) ∆th(1 −λ)f(x, t) + λf(x+ ∆x, t + ∆t)i; it’s important to notice that, for λ= 1, here’s the Euler implicit method: xn+1 =xn+ ∆tfxn+1, tn+1 and the way for solving it is isolating xn+1. 27 This is because a big time step makes the system becoming unstable, as seen in figure 6.2; however, a very small time step may be stable but (i) not computable, or great-error-accumulating, so the system won’t be considered stable due to converging to invalid solutions. Master Thesis in Computer Graphics by Marc Musquera Moreno
58 Chapter 6. Physically-Based Deformations Movement restrictions 6.1.2.6 It has been seen the path-tracking and management of a single particle Pwithin the space, but with no counting the possible interactions and restrictions,e.g., interaction between Pand the other space objects. This restrictions can provoque extremal particle path modifications. Collisions. Two or more particles can collide between them if they are in the same animation space. At this moment, a stochastic process has occurred, and the path-tracking is being terribly affected, so the involved particles will modify their trajectory according to an external factor, and this affair must be managed by the deformation system after the solver integration step, as can be seen in the figure 6.1, on page 55. Additionally, there are two extremal kinds of collisions, and of course, the intermediate types: from a perfect inelastic 28 colliding stucking until a 180odirection-turning by a perfect elastic29 one. The collision management must be robust and efficient in the same level, so for a collision between two generic 3Dobjects this task is really impossible. Because of that, the collision checking is often done by reducing an object to its bounding box or even its bounding sphere, geometrically easier30. (a) Intersection between bounding boxes (b) Intersection between bounding spheres Figure 6.3: Intersection between 3Dbounding volumes of 3Dobjects. Let’s see now the geometrical computation for checking the intersection between two bounding spheres S1and S2, defined by their respectives center C, radius rand velocity vector ~v: S1= (C1, r1, ~v1) S2= (C2, r2, ~v2)=⇒ C1(t) = C1+~v1t C2(t) = C2+~v2t rmax = max (r1, r2) ⇓ kC2(ti)−C1(ti)k ≤ rmax →intersection in titime instant kC2(ti)−C1(ti)k> rmax →no intersection in ti 28 An inelastic collision is a collision such that the involving objects suffer deformations; ideally, the two objets will be stuck from that moment. 29 A collision is considered elastic if the kinetic energy and the linear momentum is conserved for the implied objects. 30 A sphere is specified by its center and its radius using the equation (x−cx)2+(y−cy)2+(z−cz)2=r2, while a prismatic box is defined by 6 planes, each one delimited by its intersections with the others. Research on Generic Interactive Deformable 3D Models
6.2. Dynamic Deformable Model Systems 59 Constraints. A system constraint is based on particle forced behaviours, like connection with other particles —e.g., a delimited distance range with respect to another particle, or the same relative position between them—, or determined surface passing-through —e.g., a forced friction with floor, or an elastic behaviour in relation to another particle or object—. In the following figure there is a set of particles with two constraints: (i) connections between subsequent particles —generating a kind of spring—, and (ii) delimited length range for all these springs. Notice that, when a gravity force is applied, the constraints are maintained —red arrows are remarking the gravity as long as the constraining forces— by a deformation (red image) of the original relaxing shape (left image). (a) Before ggravity force application. (b) Equilibrium state with gforce applied Figure 6.4: Force equilibrium in a particle system with connection restrictions; source [phy9]. Dynamic Deformable Model Systems 6.2 Introduction to deformable systems 6.2.1 Definition of Particle System 6.2.1.1 A single particle Pis usually displayed as a graphical point or sphere, and stores a set of attributes, including its vector state and another object parameters such as temperature, mass, lifetime, . . . These attributes are, in essence, the numerical definition of the particle behaviour in front of dynamic deformations and movements over time, computed by a solver for each animation time step. Asolver will be an algorithm that executes the time step integration for any particle P, given its attributes, its state vector and, of course, the time step. A solver is directly related to a numerical integrator, so each integrator within the table 6.1, on page 56 will must have its own solver: xn vn Fn m . . . −→ numerical integration solver ∆t ↓ −→ xn+1 vn+1 Fn+1 m . . . Figure 6.5: ODE numerical integration scheme for a single particle P. Master Thesis in Computer Graphics by Marc Musquera Moreno
66 Chapter 6. Physically-Based Deformations Architecture of a mass-spring system. Tipycally, a mass-spring system is configured such that the mass points are regularly spaced in a lattice, connected together along the twelve edges of each hexahedron by structural springs. Additionally, each cell —that means, empty space between eight mass points comprising a perfect cube; in other words, a kind of voxel—masses on opposite corners are also connected together by shear springs. Figure 6.10: A typical mass-spring system three-dimensional representation; source [phy5]. Longitudinal and shear force formulation according to Newton mechanics. The springs are commonly modeled with linearly elastic behaviour; therefore, the acting force on a mass point igenerated by a spring connection with another mass point jis the following: fi=ks|xij|−lij·xij |xij|, fj=−fi where •xij is the distance difference between the mass points iand j—(xj−xi)—, • |xij|is the euclidean distance in relation to the mass point positions xiand xj, •ksis the spring’s stiffness —that is, the elasticity coefficient, arbitrary—, •and lij is the initially fixed spring length. Additionally, physical bodies are never perfectly elastic, they dissipate deformation energy due to the damping effect; so, a dampening coefficient is used over the difference between the implied mass point velocities to give a viscoelastic behaviour to the deformation: fi=kdvj−vi, fj=−fi Figure 6.11: Effect of viscosity on a physically-based elastic deformations. Each figure has ten times higher viscosity than its left neighbour; source [phyC]. Research on Generic Interactive Deformable 3D Models
6.3. Physical Simulation based on Lagrangian pov descriptions 67 Clothing simulation. One of the most interesting research contributions about mass-spring particle systems is the cloth simulation. Interestingly, Xavier Provot introduced in 1995 on [phy7] a 2D physically-based model for animating cloth objects directly derived from the elastically deformable mass-spring model, and due to the unrealistic behaviour when a small region is victim of a huge number of high stresses, his method is also inspired on dynamic inverse procedures. While a great amount of proposals, variants, improvements and algorithm accelerations have been featured since the Provot approach, they won’t be discussed nor explained. For more information, be referred directly to [phy9], a good survey on cloth simulation by Yongjoon Lee. Basically, the Provot cloth model is based on a regular 2Dgrid of mass points, each one connected with its neighbours with elastic springs; that is, a 2Dmass-spring model, and even maintaining the same Newton-mechanics-based internal force. Additionally, he adds, apart from the longitudinal internal force activation, here called stretching, two more forces: shear and bending, that can be seen in the next figure in a self-explanatory interaction scheme with graphical reaction. (a) Cloth internal forces’ interaction scheme; source [phy6] (b) Clopth internal forces’ graphical reaction (the two left images are the two ‘stretching’ movements); source [phy8] Figure 6.12: Here’s the scheme of the three different internal forces for the 2Dcloth mass-spring simulation model, including the connection affecting and a detailed visualization of the different force effects. So, by executing the mass-spring generic iterative deformation animation, some cloth pieces can be deformed by applying external forces and fixing some mass points, as features the next figure: Figure 6.13: A cloth piece with four different hanging —relaxing— postures after a real-time simulation steps by shaking the cloth and sliding it over obstacles before allowing it to rest; source [phyD]. Master Thesis in Computer Graphics by Marc Musquera Moreno
68 Chapter 6. Physically-Based Deformations Mesh Free Methods 6.3.2 What are Mesh Free Methods 6.3.2.1 The Mesh Free Methods enter in clear contrast with the previous Mesh Based Methods; while all the Mesh Based ones yield over a explicit connectivity and a surface boundary, the Mesh Free are more similar to point-based animation. Indeed, the pointbased physically-based animation is found here —see the first section of the previous chapter for a point-based geometric animation explanation—. In this subsection a rough explanation of some of the most famous and commonly used Mesh Free Methods will be able to be found; however, if more detail is desired, or due to bibliographical references, please read the survey at [phy5]. Smoothed Particle Hydrodynamics —SPH— 6.3.2.2 Abbreviated with the SPH letters, this is a technique where discrete and smoothed particles are used to calculate approximate values of needed physical quantities and their spatial derivatives. In essence, a function Ais, as said in [phy5], is interpolated at a position x∈R3from its neighbors by using a summation interpolant: A(x) = X j mj·A(xj) ρj·W(r, h), where the interpolation parameters are: •mjand ρjare the particle pj’s mass and density respectively; •W(r, h)is a smoothing kernel with the following properties —or restrictions—: ZW(r, h)dr = 1,lim h→0W(x, h) = δ(x), being r=|x−xj|and δ(x)the Dirac function. A finite differences methodology, or even a node grid, is not necessary. Indeed, this method is based on assigning an initial density to each particle, and then, the continuity equation —mass conservation— is then used for computing the density variation through the timeline: ˙ρi=−ρ∇vi, where ∇viis called divergence of particle i’s velocity, and can be approximated to ∇vi≈1 ρiX j6=i mj(vj−vi)·∇W(r, h); now the equations of motion can be solved by deriving forces, after finding the relation between the density variation and the resulting internal force. Here’s an example of SPH applied to an elastic solid melting to a fluid. Research on Generic Interactive Deformable 3D Models
6.3. Physical Simulation based on Lagrangian pov descriptions 69 Figure 6.14: Interface tension force SPH-based simulation between fluids of different (i) polarity, (ii) temperature diffusion and (iii) buoyancy; source [phy5]. Meshless Deformations based on Shape matching 6.3.2.3 Proposed by M¨uller et al in 2005, this is a meshless method to animate deformable objects in an iterative algorithm such that, at every time step, the original pointset configuration is fitted to the actual point cloud using shape matching techniques for point clouds with correspondence. The nodes of a volumetric mesh are treated as mass points and are animated as a simple particle system with no connectivity —only the shape matching and point correspondence techniques—. This is a very suitable method for original shape recovering after a heavy deformation. Figure 6.15: Stable original shape recovering after a —literally— rigid and heavy deformation; [phy5]. The Hybrid Approaches 6.3.3 Overview of the hybrid simulation approaches 6.3.3.1 In the previous chapter, deformation algorithms based on geometric transformations have been treated, instead of physically-accomplishing laws. However, there are some approaches that are really joining these two deformation methodologies: by using a bridge layer, a 3Dis animated with geometric and physically-based deformation simulations. Thus, in this section a few methods will be featured and explained —there have been another proposals in the recent years but they will be omitted—. Pump it Up 6.3.3.2 Proposed by Chen and Zeltzer, it’s a hybrid approach focused on tissue deformation: •afinite element method —FEM— analysis is performed on a prismatic bounding box embedding the muscle —or generic 3Dobject indeed—; •the FEM resulting deformation is mapped onto the object surface mesh following a Free-Form Deformation —FFD— principle. Master Thesis in Computer Graphics by Marc Musquera Moreno
70 Chapter 6. Physically-Based Deformations The object will be assumed to be composed by an homogeneous, incomprenssible, linear isotropic material, so the contraction force reaction is simulated by applying biomechanically-based processes on the mesh. The only problem with this method is that is too expensive to be considered for interactive applications. (a) Schematic hybrid model based on FEM mesh and FFD transformation; [phyE] (b) Muscle contraction example (relaxed in left figure, shorten in right one); source [phyE] Figure 6.16: The Chen and Zeltzer finite element mesh and contraction approach. Mass-Spring with Volume Conservation 6.3.3.3 Promayon and Baconnier features a previous proposal by themselves in [phyF, section 1.4] about the volume conservation constraint on physically-based deformations. The control of the volume is necessary in order to simulate the incompressibility of 3Dob- jects —like some human organs— as well as to control the volume variation of other scene objects, everything in run-time. The main advantage of this proposed method is that the volume can be preserved constant during deformation in real-time without using an iterative process, in contrast to almost all other Lagrangian approaches. So, the idea behind this method is to consider a 3Dobject composed by a triangular mesh with npoints p1, . . . , pn, that will be used as a particle system. Let: •V0the initial volume, also called the relaxing volume; •and V(p1, . . . , pn)a volume function that describes the actual volume parameterized by the particle system positions; If, in a deformation step, the volume is deformed, this method is able to find the particle-respective correct displacements to maintain the correct volume in the current p1, . . . , pnsystem positioning, by solving the following equation system: p1corrected =p1+λ∂V (p1, . . . , pn) ∂p1 . . . pncorrected =p1+λ∂V (p1, . . . , pn) ∂pn V(p1, . . . , pn) = V0 Research on Generic Interactive Deformable 3D Models
6.4. Physical Simulation based on Eulerian pov descriptions 71 Physical Simulation based on Eulerian POV descriptions 6.4 Overview 6.4.1 This section, as mentioned before, will not be an exhaustive reference for Eulerian techniques; nevertheless, this simulation descriptions deserves a special mention because it’s a different point of view, and it is really being used for physically-based animation. The main drawback in relation to the Lagrangian methodologies is that the boundaries of the object are not being explicitly defined because the point set is stationary, so it can be understood as a heavy world of voxels. But, this kind of representation makes the Eulerian approach ideal for simulating fluids, since a fluid doesn’t have explicit boundaries. Figure 6.17: A silver block catapulting some wooden blocks into an oncoming ‘wall’ of water; source [phy5]. Fluid Simulation 6.4.2 The Navier-Stokes equations for fluids 6.4.2.1 The Eulerian approach for simulating fluids —in CG— was featured and become popular due to the Foster and Metaxas paper series between 1996 and 1997 —see [phy5, section 6] for more bibliographical references—. Their proposal solves the Navier-Stokes fluid equations on a regular voxel grid and uses finite difference formulation for all the equations in a single step. So, as a reminder, there are two Navier-Stokes equations, representing, respectively, the mass conservation and the incomprensible fluid momentum: ((eq1) → ∇u= 0 (eq2) →ut=−(u·∇)u+∇(vu)− ∇p+f; where the several variables are the following concepts: •utis the time-derivative vector field for the fluid velocity; •pis the scalar pressure —assumed a constant density, implicitly absorbed into the pressure term for simplicity—; •fis the body force vector field per mass unit; Master Thesis in Computer Graphics by Marc Musquera Moreno
72 Chapter 6. Physically-Based Deformations then, in this Eulerian formulation the results are stored in a grid of cells —similar to a grid of voxels—. It’s important to be noticed that the position xis not computed nor stored, since the grid positions remain fixed. The yielding idea of display and computation 6.4.2.2 Based on Foster and Metaxas approaches, a liquid is displayed as a height field, or in other words, a massless particle set. These massless particles are quite different from the material coordinate particles from the Lagrangian simulation because of the path tracking: here, the particles are passively moved into the fluid’s velocity field, and their velocity is interpolated from the grid33. A small summary of variants and proposals 6.4.2.3 It has been said that the Eulerian approach is used in fluid simulation. It’s true, but there’s a commonly used analogy with some non-fluid materials: the multi-particle materials, like sand,smoke or even viscoelastic materials. Due to this, some variants and proposals have been proposed in the recent years; a little overview of some of them is given now —for a more detailed explanation and bibliographical references, please go to [phy5, section 6]—: •smoke is simulated by Foster and Metaxas by defining a temperature field on the grid, and using that temperature for defining a floating thermal nature and using it, the turbulence motion is generated; Stam, on the other hand, defines smoke focusing their approach in a grid subdivision and defining a scalar density field that can be used by process quantities of smoke within the same environment —grid—. •Zhu and Briudson’s approach takes sand modeled as a fluid by using Lagrangian simulation for moving the particles and Eulerian simulation for interpolating velocities. Figure 6.18: Sand-based bunny model deformation; source [phy5]. 33 As a vast alternative explanation, and not-much-exact overview but more clear, the moving execution is done by a stationary cell swapping between massless particles, or between massless particles and empty cells. Research on Generic Interactive Deformable 3D Models
6.4. Physical Simulation based on Eulerian pov descriptions 73 •Goktekin et al generates viscoelastic materials —materials that have both solid and liquid properties at the same time, which behave in a similar way to the honey (but not exactly)— by adding elastic terms to the basic Navier-Stokes equations. •Su´arez and Susin developed in [phyB] —a reference is needed because this approach has not been included [phy5]— another hybrid development for fluid simulation composed by two layers: an Eulerian-based underlayer and a Lagrangian-based surface layer for gigantic fluids where the more complex phenomena occur on the surface. These two layers are based, respectively, on the MAC —Marker and Cell— method, not explained here, and the Lagrangian SPH —Smoothed Particles Hydrodynamic—, in more detail on section on page 68. Figure 6.19: A liquid drop falling into a liquid pool. In the six-figure frameset can be clearly noticed the three layers of the system: the Lagrangian layer (blue), the bridge connection layer (green) and the Eulerian one (red); source [phyB] (edited). Figure 6.20: Here is the velocity field for a certain instant time of the above frameset. Notice the communication between the Lagrangian and Eulerian layers by the connection stage; source [phyB]. Master Thesis in Computer Graphics by Marc Musquera Moreno
CHAPTER 7 Topological Changes on Polygonal Meshes Mesh Cutting or Mesh Splitting 7.1 Introduction 7.1.1 As said in [cut1], there is an intimate connection between the Lagrangian simulation model of a deformable solid and its discretization; because of that, research in Lagrangian simulation can be classified into three categories: (i) mesh generation —omitted in this thesis—, (ii) mesh simulation —the main goal of this project indeed—, and finally, (iii) mesh alteration while its simulation. This section is about this last category. Figure 7.1: Frameset for a fractured spherical shell; source [cut1]. While some approaches have been features in the last decades —with the virtual environment appearance overcoat—, there are three main approaches for Lagrangian mesh material splitting: 1. element cracking with connectivity preservation by arbitrary stretching; 2. mesh splitting along element boundaries; 3. continuuous remeshing based on the dissection zones; and the first two can, a priori, produce visual artifacts on the volumetric mesh. 75
PART III Contributions and Results
CHAPTER 8 External Used Libraries and Employed Hardware Mac Computers with MacOsX v10.5 “Leopard” 8.1 In the development of this Master Thesis codes and software suite composed by the two programs, MeshInspeQTor and ForceReaQTor, only Mac Computers have been used, with the latest version of MacOsX operating system, the 10.5one, called Leopard. Here are the following specifications for the two used machines —only the most importants in relation to this thesis focus—: iMac MacBook Pro CPU model 2.4GHz Intel Core 2 Duo 2.2GHz Intel Core 2 Duo CPU RAM 2GB 667(Mhz) DDR2 SDRAM 2GB 667(Mhz) DDR2 SDRAM Frontside bus freq. 800MHz bus 800MHz bus Hard-disk capacity 500GB SATA@7200 rpm 160GB SATA@5400 rpm Monitor Display Built-in 20-inch (viewable) MacBook Pro 15-inch new TFT widescreen TFT active-matrix LED technology widescreen liquid crystal display. display. GPU model ATI Radeon HD 2600 PRO nVIDIA GeForce 8600M GT GPU RAM 256MB GDDR3 SDRAM 128MB GDDR3 SDRAM Table 8.1: Used Mac computers’ specification table. 85
86 Chapter 8. External Used Libraries and Employed Hardware Used Developing Platforms 8.2 QT4.4 for GUI design with C++ as Native Language 8.2.1 The chosen programming language for all the software components is the structuredprogramming language named C++ because of its modularity capabilities and the possibility of the generic programming: •Every implemented algorithm and technique, from the mentioned in the past chapter, has been isolated in an independent module, with the minimum relation between other modules (e.g., the mesh class is not directly related to the voxelization class, while they have generic data input and output for relating them coherently). •Structure inheritance and overloading operators have also been used in the code design for a more clear and intuitive operations with the complex data transparently, for avoiding unchained errors. On the MacOsX systems, there is a complete IDE35 called Xcode, that has been used for deploying the two application components of this master thesis developed software suite,MeshInspeQTor and ForceReaQTor. (a) C++ logo. (b) Apple’s Xcode logo. (c) Trolltech’s QT4logo. Figure 8.1: Mainly used tools for the thesis’ software suite design and implementation. Also, for Graphical User Interface —GUI— design and implementation, the Trolltech’s cross-platform QTlibrary36 (in its version 4.4) has been the chosen one, for its multiple platform compatibilities (including MacOs X, Linux and Windows). QTis a complete development framework for C++37 that features: •non-standard C++ extensions that produces native C++ code in precompilation; •obviously, all the needed GUI components and resources; •thread management for parallel computing; •other non-used and non-GUI features, like SQL database access, XML parsing or NETWORK support, and others.. . 35 Acronym of Integrated Development Environment, defines the software capable of design, implement, compile and execute applications. It normally consists of a source code editor, a compiler and/or interpreter, build automation tools, and (usually) a debugger. Sometimes a version control system and various tools are integrated to simplify the construction of a Graphical User Interface —GUI—. 36 http://trolltech.com/products/qt/. 37 Although there are existing bindings for other languages like C#, JAVA, Python, or PHP. Research on Generic Interactive Deformable 3D Models
8.2. Used Developing Platforms 87 Figure 8.2: The Trolltech’s QT4versatile capabilities and framework diagram. Matlab for testings 8.2.2 Parallel to the C++ complex software suite design and implementation, for some graphic techniques a Matlab previous testing application is developed, and its R2007aversion has been the used one. Figure 8.3: The Mathworks’ Matlab mathematic environment logo. Matlab38 is a powerful numerical computing environment with its own programming language, the called m-code. Created by The MathWorks,Matlab features, apart from other awesome characteristics: •easy matrix manipulation39 and data structs —no pointers!— management; •plotting of functions and data; •an optional toolbox interface with the Maple symbolic engine, allowing access to computer algebra capabilities. Thus, some voxelization methods, or even FFD technique, have been tested firstly on a selfmade Matlab applications, because its versatile plotting capability permits an easy data structure visualization and besides, potential math-programming errors like bad array pass-throughs or bad designed mathematic operations are completely avoided. 38 http://www.mathworks.com/products/matlab/. 39 Really, Matlab is the acronym of Matrix Laboratory, and within it, the float matrix Mm×n∈R2, i, j > 0∈Nis a native data type, in a clear difference with other languages like textscc++ where the native data type is the scalar. Master Thesis in Computer Graphics by Marc Musquera Moreno
88 Chapter 8. External Used Libraries and Employed Hardware Research on Generic Interactive Deformable 3D Models
CHAPTER 9 Computer Graphics Programming OPENGL as the primary graphics specification 9.1 A Little Brief on Computer Graphics using OPENGL 9.1.1 As it’s said in [gpu1], OPENGL, the acronym of Open Graphics Library, is a standard specification developed in 1992 by Silicon Graphics Inc —SGI— and defines a crosslanguage cross-platform API40 for producing 2Dand 3Dgraphics. The mentioned interface permits, by calling simple primitives and setting some parameters and configurations, to draw complex three-dimensional scenes. As a simple API overview, it’s said that OPENGL is a specification; that implies that it’s actually a document that describes the must-fulfilled functions and procedures. From this spec, hardware vendors41 have to create spec-compatible implementations. Figure 9.1: The OPENGL logo by Silicon Graphics Inc. Hence, there exists so much vendor-supplied implementations of OpenGL —making use of graphics acceleration hardware for achieving a good specification compatibility— for multiple systems: MacOs X, Windows, Linux, many Unix platforms, and so on. 40 Acronym of Application Programming Interface, is a set of declarations of procedures that external software, like operating systems, libraries or service provides to support requests made by computer programs. 41 The greatest vendors are at this moment nVidia and ATI, with no doubt, since it’s the GPU hardware instead of the CPU the executing chip. 89
90 Chapter 9. Computer Graphics Programming API overview: The OPENGL graphical computing steps 9.1.2 Initial considerations; introduction 9.1.2.1 This section is not pretending to be a complete tutorial for OPENGL computer graphics programming; the aim of the following explanations is to give a brief of the computation style of this API, because on the next sections, this knowledgments will be so necessary. An important thing, however, is to notice that all the OPENGL methods always begin with the gl prefix. The classical rendering action with OPENGL hasn’t any complication, but if there’s an animation wanted to be shown, now appears the problem: this process requires a smooth sequence of final animation frames42, and due to this, the double buffering technique is available. The drawing occurs on the background buffer, and once the scene is completed, it’s brought to the front —displayed on the monitor display—. 1{ this process is done forever } 2while true do 3resetBackgroundBuffers(); 4setCameraViewing(); 5{ now the user point of view of the scene is 6set: ‘camera’ position and orientation, and 7vision perspective configuration } 8foreach Object O in Scene S do 9{ animation + rendering steps } 10 animateObject( S.O ); 11 drawObject( S.O ); 12 endforeach; 13 swapBuffers(); 14 { by swapping buffers, the scene displaying 15 is automatic } 16 endwhile PSEUDO code 9.1: OPENGL animation scene drawing steps. This thesis is about the line 10,animateObject(), so this line is eclipsed by all this document. Also the first and last commands, resetBackgroundBuffers() and swapBuffers() will be omitted. This section, hence, will treat accurately the other two commands —lines 4and 11 respectively—:setCameraViewing() and the own drawing process drawObject( Object O ), based on [gpuE] and [gpuF] tecahings. Drawing primitives 9.1.2.2 For the drawing process, OPENGL needs to specify where start and where the primitive generation commands finish. Since the geometric primitives, whatever they are, are com posed by vertices, this will be the geometric primitive coherent definition; so, any primitive will be a sequence of 3Dor 2Dvertices. Additionally, there are some different primitive styles, as the figure 9.2 shows. The constant must be declarated at the primitive drawing starting command. 42 Afinal frame is a totally generated and rendered image; e.g., a sequence of two triangles is rendered by painting each triangle sequentially, and no animator wants an animation showing one and two triangles intermitently. Research on Generic Interactive Deformable 3D Models
9.1. OpenGL as the primary graphics specification 91 1glBegin( GL_PRIMITIVE_STYLE ); 2glVertex3f( [...] ); // v0 3glVertex3f( [...] ); // v1 4glVertex3f( [...] ); // v2 5[...] 6glVertex3f( [...] ); // vN 7glEnd(); CPP code 9.2: Drawing primitives with OPENGL. In this generic code for OPENGL primitive drawing, the glBegin() parameter, that receives the name of GL PRIMITIVE STYLE can be one of the following constants: Figure 9.2: The OPENGL primtive drawing styles; source [gpuE]. Besides, there’s the possibility of integrating vertex color definition with a vertexcoords previous command that specifies the RGB color codification —RGBαif transparencies are enabled—. OPENGL lighting effects are not telled here, but the primitive colorizing due to the vertex colors is done by a code like the following: 1glBegin( GL_TRIANGLES ); 2glColor4f( 0.0, 0.0, 1.0, 1.0 ); 3glVertex3f( 0.0, 0.0, 0.0 ); 4glColor4f( 1.0, 0.0, 0.0, 1.0 ); 5glVertex3f( 3.0, 0.0, 0.0 ); 6glColor4f( 0.0, 0.0, 1.0, 1.0 ); 7glVertex3f( 1.5, 3.0, 0.0 ); 8glEnd(); CPP code 9.3: A colorized triangle drawn with OPENGL. Master Thesis in Computer Graphics by Marc Musquera Moreno
98 Chapter 9. Computer Graphics Programming So, since each vendor is different, and even there are multiple graphics accelerator models for each vendor, a availability test is required before using an extension; each system has its own availability mechanism, but crossplatform external libraries like GLEW50 —acronym of GL Extension Wrapper— simplify the process. The programmable graphics technology 9.2 The Shading Languages 9.2.1 From the year 2002, there appeared some proposals for a new kind of programming languages: the real-time shading languages; that is, a language used to determine the final surface properties of an object or image, or more technically said, a language that provides code overlapped within graphics standard pipeline51. From the three proposals, the nVidia’s CG—acronym of C for Graphics—, the Microsoft’s HLSL —DirectX High-Level Shading Language—, and the OPENGL ARB’s GLSL —OpenGL Shading Language—, the last is the chosen one, due to: •appeared in 2003, it’s part of the OPENGL 2.0 API, so it’s independent of Microsoft’s DirectX52 specification; •it’s very similar to nVidia’s CGin syntax, though different in semantics; •it’s included to an application by including the extensions GL ARB vertex shader and GL ARB fragment shader. A New Programming Paradigm 9.2.2 The GPU’s Vertex and Fragment Processors 9.2.2.1 For achieving this new programming paradigm focused on specific graphics data management, the hardware vendors had to build specific GPU architecture that were supporting that. Thus, the vertex processors and the fragment processors were born, and there are multiple processors for each type within a single GPU: Figure 9.11: The GPU’s vertex and fragment processor managment tasks; source [gpu3]. 50 http://glew.sourceforge.net/ 51 The name of shading language is received because the initial aim of this new programming paradigm was the real-time shade and shadow generation. 52 It’s a collection of APIs for handling miultimedia tasks on Microsoft platforms. Direct3D is the concrete API that can be compared to OPENGL with respect to concepts and aims. Research on Generic Interactive Deformable 3D Models
9.2. The programmable graphics technology 99 (1) the vertex processor is the responsible of computing the final 3Dvertex position, with the peculiarity of knowing nothing about other vertices —thus, this processor is found before the primitive assembler—; (2) on the other side, the fragment processor has the mission of defining each fragment —potential pixel— final color, from illumination, material and texture properties; obviously, there’s no direct vertex-fragment computing proportion, because a single triangle —3 vertices— can be placed over a lot of fragments. Nevertheless, a vertex shader can pass data to all its derived fragment shaders by the varying variables. The New Programmable Graphics Pipeline 9.2.2.2 So, the old per-vertex operations and fragment processing stages, from the standard graphics pipeline —figure 9.10—, now have been replaced by the vertex processor and fragmenrt processors respectively, as can be seen in the next figure: Figure 9.12: Detailed scheme of the Programmable Graphics Pipeline; source [gpu4]. The GLSL shader programs —vertex and fragment ones— loading process is possible by a special OPENGL functions for sending to GPU: •the shader codes to the adient processors; •the shader input data structures, common for every shader execution, called uniform variables; however, as it’s done for the OPENGL section, there won’t be an API tutorial, but an overview of these kind of technologies. Geometry Shaders 9.2.2.3 In the last year, a new kind of GPU processor unit has been introduced with Shader Model 4.0 of Microsoft DirectX 10 specification: the geometry processor, able to execute the new geometry shaders. Although it’s really a DirectX approach, OPENGL is able to use it by the extension, though it will likely be incorporated into the upcoming version 3.0standard spec. Master Thesis in Computer Graphics by Marc Musquera Moreno
100 Chapter 9. Computer Graphics Programming Geometry shaders are executed after vertex shaders, and their input is a whole primitive —that is, vertex-relation information, and possibily adjacency information too— . These shaders can emit zero or more primitives as the output, and they will be rasterized —ergo, these generated primitive fragments will be passed to the pixel shader—. Nevertheless, this thesis has been focused into the Shader Model 3.0; hence, this kind of shaders are not able to use, and only the vertex and fragment ones will be programmed for determined tasks. OPENGL 2.0and GLSL 9.2.3 Brief introduction to OPENGL 2.0and GLSL 9.2.3.1 As in OPENGL’s section 9.1.2, on 90,this won’t be a detailed tutorial for the GLSL shading language in connection with the OPENGL specification 2.0; however, here it can be encountered a brief vision of the basic philosophy about shader programming. With entering to no deep details of OPENGL code for invoquing a GLSL program loading to the GPU, it’s important that any GLSL SHADER must •to write the gl Position variable if it’s a vertex shader; •to write the gl FragColor variable —or to return by a discard command if the actual fragment has to be rejected— if it’s a fragment shader; additionally, the steps for executing a shader program —composed by a vertex shader and a fragment shader— are the following, and they have to be done by any OPENGL application that wants to use GPU programming: 1{ this process is executed once, at the 2application beginning } 3ShaderCode vs = loadShader( VERTSHADER_GLSLCODE ); 4ShaderCode fs = loadShader( FRAGSHADER_GLSLCODE ); 5ShaderProg glslprog = createGLSLProgram( vs, fs ); 6[...] 7{ the glsl program must be selected for being 8executed before the scene drawing commands } 9useGLSLProgram( glslprog ); 10 setUniformParams( glslpros, Set<UniformParam> ); 11 renderScene(); PSEUDO code 9.5: Steps for executing a GLSL shader program. Data types and qualifiers 9.2.3.2 The GLSL is a computer graphics programing language •oriented to be executed on GPU; •focused on performing geometric computing ; due to this curious nature and also due to GPU’s architecture is vectorial, GLSL basic data type is a R3vector53 and 1D, 2Dand 3Dtextures. 53 With 4-coord compatibibility because of possible geometric transformation sets applied to a vector or a position. Research on Generic Interactive Deformable 3D Models
9.2. The programmable graphics technology 101 Just like that, the next table shows the basic data types allowed by glsl —it also accepts structs, but as the specification format is analogous to the ANSI C one, they will be ommitted here—: Data Dimension Format 1 2 3 4 2×2 3×3 4×4 int int ivec2 ivec3 ivec4 float float vec2 vec3 vec4 mat2 mat3 mat4 bool bool bvec2 bvec3 bvec4 Table 9.1: Basic vectorial data types on GLSL Texture Dimension Format N N×N N×N×N normalized sampler1D sampler2D sampler3D shadow sampler1DShadow sampler2DShadow unnormalized sampler1DRect sampler2DRect Table 9.2: Basic texture data types on GLSL Besides, each vectorial data formats —plus the texture elements—, have indexed elements: they are the two, three or four implicit elements; all of these four-index sets are capable to index every data format, but due to the position,color and texture coordinate convention, the coherent indexes are: Convention Indexes position/vector xyzw color codification rgba texture coordinates stpq Table 9.3: Vectorial component indexes in relation to the data type conventions. Additionally, the shader global variables can be defined with three different prefixes that are determining their characteristics: •uniform: vertex and fragment shader input data from OPENGL application —that is, from CPU—; vertex set global read-only; •attribute; the same as uniform but only for vertex shader; read-only; •varying; fragment shader input data, interpolated from vertex shader54; read-only for fragment shader, read-write for vertex shader; •const; not really a kind of gobal variable, it specifies a shader-local compile-time constant with a predetermined value; 54 Because, as a reminder, it has to be noticed that each vertex shader execution derives onto various fragment shader processings. Master Thesis in Computer Graphics by Marc Musquera Moreno
102 Chapter 9. Computer Graphics Programming The most important implicit variables 9.2.3.3 The OPENGL 2.0constructs an automatic bridge with GLSL, and uses it for sending some uniform and attribute automatically defined values when a shader program is called for execution. The total number of uniform and attribute sent variables is huge and involves a lot of graphical parameters and configurations.The most important of them are typeset in the following tables, though all the variables can be found at [gpuG]: Uniform Variables mat4 gl ModelViewMatrix mat4 gl ProjectionMatrix mat4 gl ModelViewProjectionMatrix mat4 gl NormalMatrix float gl NormalScale Table 9.4: Most important ‘uniform’ automatically shader input variables. Attribute Variables vec3 gl Vertex vec3 gl Normal vec4 gl Color vec4 gl SecondaryColor vec4 gl MultiTexCoord0..7 Table 9.5: Most important ‘attribute’ automatically shader input variables. Varying Variables vec4 gl FrontColor vec4 gl TexCoord[] Table 9.6: Most important ‘varying’ automatically shader input variables. Ashader example: the toon shading 9.2.3.4 1varying vec3 normal, lightDir; 2void main() 3{ 4vec3 vVertex = vec3(gl_ModelViewMatrix * 5gl_Vertex ); 6lightDir = vec3(gl_LightSource[0].position.xyz - 7vVertex ); 8 9lightDir = normalize( lightDir ); 10 normal = gl_NormalMatrix *gl_Normal; 11 gl_Position =ftransform(); 12 } GLSL code 9.6: The ‘vertex shader’ of toon shading. Research on Generic Interactive Deformable 3D Models
9.2. The programmable graphics technology 103 1varying vec3 normal, lightDir; 2void main() 3{ 4float intensity; 5vec4 color; 6vec3 n = normalize(normal); 7 8// intensity is the relativization of 9// light w.r.t. the vertex normal 10 intensity = dot( lightDir, n ); 11 12 // toon effect w.r.t. the intensity 13 if( intensity > 0.95 ) 14 color = vec4( 1.0, 1.0, 1.0, 1.0 ); 15 else if( intensity > 0.5 ) 16 color = vec4( 0.6, 0.6, 0.6, 1.0 ); 17 else if( intensity > 0.25 ) 18 color = vec4( 0.3, 0.3, 0.3, 1.0 ); 19 else 20 color = vec4( 0.2, 0.1, 0.1, 1.0 ); 21 22 gl_FragColor = color; 23 } GLSL code 9.7: The ‘fragment shader’ of toon shading. (a) The cow model illuminated by the GPU-Phong realistic illumination model. (b) The dyrtManArmTris model illuminated by the GPU-Phong realistic illumination model. (c) The GPU-implemented toon shading algorithm over cow model. (d) The GPU-implemented toon shading algorithm over dyrtManArmTris model. Figure 9.13: The effects of two shaders applied to two models: the upper figures show the graphical results for a shader computing the Phong illumination model, and in the lower ones are featured the same models with the toon shading shader over them. This has been possible by the shader addition to this thesis’ developed software MeshInspeQTor. Master Thesis in Computer Graphics by Marc Musquera Moreno
104 Chapter 9. Computer Graphics Programming GPGPU: The New Computing Paradigma 9.3 The Programmable Graphics Pipeline, used for General Purpose Algorithms 9.3.1 Although the vertex and fragment processors are built for executing only graphicsoriented tasks, it’s possible to use these multi-processor capabilities offered by a GPU for computing general tasks, in conjunction with an existent OPENGL extension called Frabe Buffer Object —FBO—, able to be includes to an OPENGL graphics program by the invocation of the GL EXT framebuffer object constant. The Frame Buffer Object —FBO— Extension 9.3.1.1 As it’s said on [gpu7], the FBO is an OPENGL extension that allows flexible off-screen rendering, including rendering to a texture55. Thus, image filters and post processing effects are able to be implemented for CPU algorithms as long as for GPU shaders. The following code lines create a FRAMEBUFFER with previous usage of GLEW —see section 9.1.4, on the page 97—, by a 2Dtexture binding and its association with the FBO: 1unsigned int fbo, tex; 2 3void setFBO() 4{ 5glewInit(); 6if( !glewIsSupported( ” GL EXT framebuffer object ” ) ) 7{ 8std::cout << ”EXT framebuffer object unsupported” 9<< std::endl; 10 exit( -1 ); 11 } 12 // generate texture 13 glGenTextures( 1, &tex ); 14 glBindTexture( GL_TEXTURE_2D, tex ); 15 glTexImage2D( GL_TEXTURE_2D, 0, innerFormat, 16 texSize, texSize, 0, 17 texFormat, GL_FLOAT, 0); 18 // create fbo and attach texture to it 19 glGenFramebuffersEXT( 1, &fbo ); 20 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fbo ); 21 glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, 22 GL_COLOR_ATTACHMENT0_EXT, 23 GL_TEXTURE_2D, tex, 0 ); 24 } 25 26 void drawScene() 27 { 28 glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fbo ); 29 // primitive generation from now; if the normal 30 // rendering is wanted, please type the follow: 31 // glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); 32 } CPP code 9.8: Creation of a FRAMEBUFFER with a previous GLEW usage. 55 That means, the generated frame won’t appear onto screen display but stored into a CPU-read texture. Research on Generic Interactive Deformable 3D Models
9.3. GPGPU: The New Computing Paradigma 105 General-Purpose Graphics Processor Unit —GPGPU— 9.3.1.2 Due to the usability of this versatile extension, it’s possible to use theoretical textures as data matrix structures, accessible from the vertex and fragment shaders and then, take advantage of the parallel computing capabilities of a GPU for using the graphics unit as a little supercomputer. Dominik G¨oddeke in his web [gpu8] offers three advanced GLSL tutorials for using shader capabilities for executing general-purpose algorithms using the nVidia CGlanguage. His teachings, in a simple overview of [gpu9], are focusing on the general purpose methods and algorithms by using GPU potence with the aid of the shaders. He tells that there are three basical steps on performing that: Textures as data arrays. For a CPU, the native data layout is the 1Darray, but for a GPU the native one is the 2D one —but the available graphics memory is a layout size limit—. Besides, on the CPU we define the array elements as array indices, but on the GPU they are texture coordinates56. So, you must convert any ND-array to a 2D-array in this way: aN-length 1Darray is mapped into a texture of √N×√Ntexels57 for single float values, or pN/4×pN/4 texels for RGBA formats, always assuming Nas a power-of-two scalar value. Shaders as Kernels. The shaders have to be taken as kernels, so the vertex and fragment processors compute general purpose algorithms to texture data in parallel within the GPU58; One-to-one mapping from array index to texture coordinates. The drawing process is equivalent to a parallel computing by using the FBO extension and render-to-texture capabilities. Due to this, a similar code to the one shown on code 9.8 will be necessary. However, by doing this, this methodology must be preceeded by a specific special projection that maps model-coordinate 3d space to 2Dscreen-display- coordinate space by a 1:1mapping between wished rendered pixels and accessed data texels; a functional code would be like this: 1void enableOneToOneMapping() 2{ 3glMatrixMode( GL_PROJECTION ); 4glLoadIdentity(); 5 6gluOrtho2D( 0.0, texSize, 0.0, texSise ); 7glMatrixMode( GL_MODELVIEW ); 8glLoadIdentity(); 9glViewport( 0, 0, texSize, texSize ); 10 } CPP code 9.9: Creation of a FRAMEBUFFER with a previous GLEW usage. 56 And these coordinates are storing four-element tuples, referring the four color channels: red, green, blue, alpha (RGBA)—. 57 A texel is a texture quantum unit; texel is an abbreviation form of texture element. 58 So, the contained data must be independent in relation to each other texture element. Master Thesis in Computer Graphics by Marc Musquera Moreno
106 Chapter 9. Computer Graphics Programming Besides, since the general purpose algorithm will be executed by a fragment shader, so a fragment shader is executed for each data element we stored in the target texture. Therefore, the idea is make sure that each data item is computed uniquely into a fragment, and obviously, by a unique fragment shader. Then, given our projection and viewport settings one-to-one mapped, this is simply accomplished by drawing a simple quad that covers the whole viewport —with texture coordinates correctly assigned—, with one of the next codes, depending on used texture style: 1glPolygonMode( GL_FRONT, FL_FILL ); 2glBegin( GL_QUADS ); 3glTexCoord2f( 0.0, 0.0 ); 4glVertex2f( 0.0, 0.0 ); 5glTexCoord2f( texSize, 0.0 ); 6glVertex2f( texSize, 0.0 ); 7glTexCoord2f( texSize, texSize ); 8glVertex2f( texSize, texSize ); 9glTexCoord2f( 0.0, texSize ); 10 glVertex2f( 0.0, texSize ); 11 glEnd(); CPP code 9.10: Drawing the GPGPU quad, using texture rectangles —texture coordinates identical to pixel coordinates—. 1glPolygonMode( GL_FRONT, FL_FILL ); 2glBegin( GL_QUADS ); 3glTexCoord2f( 0.0, 0.0 ); 4glVertex2f( 0.0, 0.0 ); 5glTexCoord2f( 1.0, 0.0 ); 6glVertex2f( texSize, 0.0 ); 7glTexCoord2f( 1.0, 1.0 ); 8glVertex2f( texSize, texSize ); 9glTexCoord2f( 0.0, 1.0 ); 10 glVertex2f( 0.0, texSize ); 11 glEnd(); CPP code 9.11: Drawing the GPGPU quad, using 2Dtextures —texture coordinates normalized to the range [0,1 Additionally, for transferring data from GPU’s FBO to a CPU’s texture, after a rendering step the programmer should add this code: 1void enableOneToOneMapping() 2{ 3glReadBuffers( GL_COLOR_ATTACHMENT0_EXT ); 4float*data = new float[texSize*texSize]; 5glReadPixels( 0, 0, texSize, texSize, texFormat, 6GL_FLOAT, data ); 7} CPP code 9.12: Transferring the framebuffer content to a CPU array. Then, data will contain the shader program complete computation calculum. Obviously, you can use data as shader input, and create a hardware looping algorithm. Research on Generic Interactive Deformable 3D Models
9.3. GPGPU: The New Computing Paradigma 107 The nVidia CUDA approach 9.3.2 The next step in GPU computation 9.3.2.1 As acronym of Compute Unified Device Architecture,CUDA is a C-precompiler that allow programmers to use the Cprogramming language to code general-purpose algorithms for execution on a CUDA-compatible nVidia GPU —that is, from the 8000 series—. (a) The nVidia logo. (b) The CUDA logo. Figure 9.14: nVidia’s CUDA is the next (theoretical) step on GPGPU computing. GPU as a multi-threaded coprocessor 9.3.2.2 Because of the new CUDA approach, nVidia has created the new vision of a GPU: a highly multi-threaded coprocessor; now, a GPU is viewed as a computing device that: 1. is a coprocessor of the host —CPU— with its own DRAM; 2. runs many threads in parallel due to its multiple processors59; 3. each GPU processor is an independent kernel, and each one is computing dataparallel portions of an application, with no data intersections;. Figure 9.15: The new nVidia CUDA-compatible GPU architecture; source [gpuD]. 59 Since the 8000 series, nVidia GPU doesn’t have vertex processors and fragment processors but a unified architecture capable of adapting to vertex or fragment requirements in relation to the resource demands. Master Thesis in Computer Graphics by Marc Musquera Moreno
114 Chapter 10. Thesis Software Suite: (1) MeshInspeQTor Automatic modelOBJ enhancements and improvements 10.2.3 Indeed, the modelOBJ parsing process is not limited to read the data from the OBJ text file. As it has been said previously, there are some internal processes done by this parsing —done offline, when data is loaded into memory, and directly usable once processed without reprocessings—, due to a better performance and better data managing, like normal adequation and triangularization of generic polygonal faces. Only triangular faces 10.2.3.1 The most common type of polygonal face is the triangle: three points are the minimum size for specifying a polygon, and it will sure be flat. However, the OBJ format supports polygona faces of any size, with no limit, so the parser will triangularize nontriangular faces following the method shown in the next figure: Figure 10.2: The schematic triangularization for generic polygonal faces —here, an hexagon—. Obviously, there are better methods that generate triangles from the first indexed vertex from any non-triangular face —like the Delaunay triangulation—; however, a priori, this will be the major face (in relation to number of vertices) because almost 3D models are already based on triangles, so this approximation is: 1. fast, because this strategy doesn’t require to create another vertices; 2. assuming all the faces being convex, all the triangles will be surely non-intersecting; Same number of vertices and normals: the per-vertex normals 10.2.3.2 The OBJ specification supports different number of vertices and normals, so (i) a certain normal can be assigned to more than one vertex, and (ii) the same vertex can have different normal directions, because the same vertex will be in more than one face. Thus, the flat shading will be probably sharped, as in the figure 10.3(a) —on the next page—. So, for a better shading rendering, like in the figure 10.3(b), the way is so simple as compute one normal per vertex by calculating the mean of all normals assigned to that vertex; in more technical words, changing the normals per face ~nfi, assigned to the faces’ vertices v∈fi, to unitary normals per vertex ~nvj: ~nvj=1 kj kj X i=1 ~nfi, fi⊃vj,∀vj∈R3 Research on Generic Interactive Deformable 3D Models
10.2. Loading 3d models 115 (a) Normals per face. (b) Mean normals per vertex. Figure 10.3: Illumination contrasts between vertex’s normal assigment in relation to the face comprising, or the normal assignment by the mean of normals per each vertex. Automatic generation of normals 10.2.3.3 Moreover, this methodology can be used for generating normals for those OBJ models not containing them —not necessary for defining geometry but so much important for a realistic model display—, by calculating all the per-face normals, and then executing the previous formula for every vertices within the geometry. IRI’s own P3D format conversion to OBJ models 10.2.4 Dedicated GUI for file format conversion to OBJ format 10.2.4.1 Some time ago, Eva Moncl´ us —researcher at IRI— told me how to extract threedimensional models from the Visual Human project65, available from this University. From a previous degree project implementation, done by another student, a 3Disosurface extractor of the different human organs, listed in a database, is available; however, the quality of that extractions is poor, due to two reasons, explained on the next image: Figure 10.4: An example of internal oblique inguinal muscle, extracted by using the IRI tool; please notice the defficiences on the extraction —the model is rendered by remarking the polygon edges—. 65 The Visible Human Project, as can be seen in [ami6], was a anatomical project promoted by NLM — United States’ National Library of Medicine— in 1986 for creating a complete, anatomically detailed, 3Drepre- sentations of the normal male and female human bodies, by acquisition of transverse CT —Computed Tomographies—, MR —Magnetic Ressonances— and cryosection images from adequate corpse sectionings. Master Thesis in Computer Graphics by Marc Musquera Moreno
116 Chapter 10. Thesis Software Suite: (1) MeshInspeQTor •some organs are too huge for being extracted at once because of memory overflow problems, so they have to be extracted at piecewise, with the inherent loss of quality —because the 3Dmodel is built from an isosurface—. •the isosurface extraction algorithm is no good; there are great defficiences in the triangular meshing, like dense rings of triangles. Nevertheless, this extractor generates a three-dimensional model based on a text format called P3D, with no relation to the existent Lisp-based format for representing general 3Dmodels. This IRI-P3D format —named ust like that for provoquing a differenciation with the another P3D format file— is a own specification for IRI purposes, and modelOBJ supports a conversion from P3D to OBJ, by a dedicated MeshInspeQTor GUI: Figure 10.5: The specific GUI within MeshInspeQTor for converting IRI-P3D format files to OBJ. This IRI-P3D format wont be detailed here; however, the GUI —and, of course, the implemented converter— will be roughly explained: 1. since the human organ will be stored into several P3D files —or maybe because the user desired to convert more than a human organ at once—, a multiple P3D file selector is available on the left of the gui, as well as a textbox that supports the path for the single OBJ file destiny path where all the files will be stored. 2. before clicking on start button, there are some parametrizations of the conversion that must be explained: •desired resolution: one single P3D file contains three different resolutions for the same three-dimensional representation of a isosurface extraction. The selection will be applied to every P3D file listed in the box when its conversion starts. •conversion mode: as mentioned before, OBJ models support face groups to separate different entities within the same 3Dmodel. Hence, this option permits the user to establish if every P3D is wished to be trated as an independent group within the OBJ, or all must be combined in a unique group. 2Dconvex hulls for piecewise isosurface extraction merging 10.2.4.2 Additionally, on the MeshInspeQTor GUI for P3D->OBJ conversion there’s a checkbox entitled ‘‘They Are A Unique Model’’. This checkbox enables —or disables— a experimental —not fully functional— preprocess that tries to merge in a better way the human organs badly generated by a piecewise extraction. Research on Generic Interactive Deformable 3D Models
10.2. Loading 3d models 117 For doing this, the process assumes that the P3D files are subsequently selected, from left to right, and by generating a 2Dconvex hull for the more extreme zones remarked as Piecewise Organ Extractions at figure 10.466; then, computing inter-convex- hull relations between vertices, some vertex mergings are processed. The results are shown, indeed, in the figure 10.4. Figure 10.6: An example of a 2Dconvex hull, executed over a 2Dpoint set. So, the convex hull problem is the following: given a planar set Sof npoints pi∈ R2,compute the vertices of CH(S), sorted in counterclockwise order. There are a lot of proposals, like Graham Scan,Jarvis March, or the Quickhull —a variant of quicksort sorting algorithm for computing convex hulls—, but the taken in account for this project was the Jarvis March, consisting in something similar like this: 1function jarvis-march( Set<Point2D> S ) 2returns Stack<Point2D> 3Point2D p0 = pointWithMinimumY( S ); 4Stack<Point2D> H; 5H.push( p0 ); 6minpoint = getPointWithMinAngle( H.top(), ... 7S.delete(H.top()) ); 8 9{ sort the point set w.r.t. the angle related to 10 the entered point, from monimum to maximum angle } 11 Set<float> vecAng = getPolarAnglePointRelated( S, p0 ); 12 Set<Point2D> vecSortedS := sortByAng( S, vecAng ); 13 H.push( vecSortedS.first() ); 14 15 { the stack will be filled with the minimum angle 16 point sequence until the reached point will be p0 } 17 S.insert( p0 ); 18 while H.top() != p0 in vecSortedS do 19 minpoint = getPointWithMinAng( H.top(), ... 20 S.delete(H.top()) ); 21 H.push( vecSortedS.first() ); 22 endwhile 23 return H; 24 endfunction PSEUDO code 10.4: Jarvis March for computing a 2Dconvex hull. 66 It’s possible to compute a valid 2Dconvex hull for a extremal zone of a isosurface extraction generated mesh because all the vertices of these zones have one of the coordinates with the same value. Master Thesis in Computer Graphics by Marc Musquera Moreno
118 Chapter 10. Thesis Software Suite: (1) MeshInspeQTor Agraphical scheme of Jarvis March is given in the next figure for a better feeling about the algorithm: Figure 10.7: A graphical scheme for an entire process of Jarvis March so the developed algorithm for piecewise Visual Human isosurface extractions is done by the next code within the Graph2D class, a generic module for operating with 2D pointsets: 1function jarvis-march( Mesh<Point3D> MA, Mesh<Point3D> MB ) 2returns Mesh<Point3D> 3{ assumed MA is adjacent and left to MB } 4Set<Point3D> XMA = getGreaterXPoints( MA ); 5Set<Point3D> XMB = getLowerXPoints( MB ); 6{ XMA and XMB have the same ’x’ coordinate, 7so it can be omitted for having a 2D set } 8Set<Point2D> CHA = getConvexHull( XMA ); 9Set<Point2D> CHB = getConvexHull( XMB ); 10 11 { mixCHulls merges any CHA point with the 12 most euclidean-distant closer point of CHB } 13 Set<Point2D> CHmix = mixCHulls( CHA, CHB ); 14 15 { Mmixed is generated by combining the sets 16 MA-XMA, MB-XMB (basic set theory), and CHmix 17 with ’x’ coordinate the mean(XMA,XMB) ’x’ } 18 Mesh<Point3D> Mmixed = ... 19 generateMesh( MA, MB, XMA, XMB, CHmix ); 20 return Mmixed; 21 endfunction PSEUDO code 10.5: Developed idea for merging isosurface portioned extractions. Displaying 3Dmodels 10.3 Overview of MeshInspeQTor rendering capabilities. The Vertex Arrays 10.3.1 Once the three-dimensional models have been charged into memory, MeshInspeQTor is able to display them in several ways, with the aim of offering the best model displaying capabilities. Research on Generic Interactive Deformable 3D Models
10.3. Displaying 3d models 119 So, by using the OPENGL technique of Vertex Arrays, the 3Dmodel rendering is faster than with single primitive callings with the glBegin( ... ); glVertex3f( ... ); ... glVertex3f( ... ); | {z } nvertices glEnd(); methodology explained on section 9.1.2.2, on page 90; as mentioned in [ami7], with the glBegin->glEnd philosophy, a lot of OPENGL calls are needed for specifying even a simple geometry. However, with vertex arrays, the geometry associated data is placed into arrays stored in the OPENGL client —CPU— address space. These blocks of data may then be used to specify multiple geometric primitives with a single OPENGL command: glDrawElements( enum mode, sizei count, enum type, void *indices ); where mode can receives the same modes as glBegin,count specifies the length of indices —composed it by the geometry indexes—, and type specifies the type of data of indices:GL FLOAT,GL INT, ans so on. Therefore, the supported OPENGL storing client arrays are the following six, which must be enabled/disabled by the command glEnableClientState(enum array) or glDisablelCientState(enum array): Array Enumerator Size Supported Types EDGE FLAG ARRAY 1boolean TEXTURE COORD ARRAY 1,2,3,4short,int,float,double COLOR ARRAY 3,4(u)byte,(u)short,(u)int,float,double INDEX ARRAY 1ubyte,short,int,float,double NORMAL ARRAY 3byte,short,int,float,double VERTEX ARRAY 2,3,4short,int,float,double Table 10.3: Supported enumeration for the vertex array data block assignment. Rendering typologies 10.3.2 Once the vertex arrays have been introduced67, let’s go with the different rendering typologies offered by MeshInspeQTor, with a snapshot of the resulting rendering a threedimensional object —in this case, a dolphin— together with its respective code. The different kinds of rendering include: 1. a solid object; 2. a wireframe model, similar to the solid representation but without filled faces, only the connection edges betwen the vertices will be painted; 3. a point based representation, based on only rendering the vertex positions without connection edges; 67 There’s another rendering methodology, called Display Lists, but in this thesis this technique has been rejected; the Vertex Arrays give good results for this project’s purposes. Master Thesis in Computer Graphics by Marc Musquera Moreno
120 Chapter 10. Thesis Software Suite: (1) MeshInspeQTor 4. a different style called draft, based on a mix of the two first renderings, but without real illumination —the aim of this display style is to show the real geometry of a 3D model, so the faces (with normal per face) as well as the edges between vertices are clearly featured—. Solid object, wireframe and point set 10.3.2.1 There are three basically distinct ways of model rendering, but for OPENGL they are only differing in some parameters before sending de geometry68; basically, there is a variable called visualization that manages which renderization style is desired — please notice that in the following code the material properties and colors are omitted—: 1int elementsdrawed = GL_TRIANGLES; 2switch( visualization ) 3{ 4case STYL_SOLID: 5// the polygons will be rendered solid & filled 6glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); 7break; 8case STYL_WIREF: 9// only the polygon edges will be painted 10 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); 11 break; 12 case STYL_NODES: 13 // the primitive won’t be a triangle but a point 14 elementsdrawed = GL_POINTS; 15 glPointSize( pointsize ); 16 break; 17 } 18 19 // there are 3 components for vertex position and 20 // normal direction because we are in R3 space, and 21 // there are 3 indexes per face because every model 22 // face is a triangle; so: 23 // float*vecvertices = new float[nfaces*3]; 24 // float*vecnormals = new float[nfaces*3]; 25 // int*vecvertices = new int[nfaces*3]; 26 glEnableClientState( GL_VERTEX_ARRAY ); 27 glEnableClientState( GL_NORMAL_ARRAY ); 28 glVertexPointer( 3, GL_FLOAT, 0, vecvertices ); 29 glNormalPointer( GL_FLOAT, 0, vecnormals ); 30 glDrawElements( elementsdrawed, nfaces*3, 31 GL_UNSIGNED_INT, vecfaces ); 32 glDisableClientState( GL_NORMAL_ARRAY ); 33 glDisableClientState( GL_VERTEX_ARRAY ); CPP code 10.6: Solid, wireframe and point-based rendering capabilities. On the next page figures, there can be seen these three types of rendering, within the MeshInspeQTor GUI for a deeper feeling about the application. Please notice that the rendering can be easily set by a combobox in the middle of the right panel. 68 It’s not really true; for point set rendering the sent geometry is different from solid and wireframe geometry, because the vertices must be sent only once, while for polygonal rendering, each vertex must be sent once per face comprising. However, for simplifying the task, the geometry will be the same for polygonal and point-based rendering. Research on Generic Interactive Deformable 3D Models
10.3. Displaying 3d models 121 (a) The ‘solid’ rendering style. (b) The ‘wireframe’ rendering style. (c) The ‘node’ point-based rendering style. Figure 10.8: MeshInspeQTor’s main rendering offerings. Notice that the dolphins.obj model is really composed by three dolphins, each one clearly identified in the ‘model list’ at the top of the right panel. Master Thesis in Computer Graphics by Marc Musquera Moreno
122 Chapter 10. Thesis Software Suite: (1) MeshInspeQTor Object Draft 10.3.2.2 As it has been said before, there’s another rendering type, with the aim of featuring a non-nice vision but a visual scheme of the model structure; in more technical words, offering a solid representation of a model that at the same time schematizes its face composition. For doing this, this rendering is composed by two rendering iterations, a wireframe one, with smooth shading69 and another based on solid representation, with flat shading70. Moreover, the material properties are disabled and the faces are rendered using a quasi-white material color —for a quasi-black color for the polygon edges—. In the following code there are the commands for achieving this kind of renderization; pay special attention on shading configuration and specific coloring settings —then, the original material properties disabling— for the two rendering iterations: 1// the data array blocks are, of course, the same that 2// the used with the previous renderization methods. 3 4// first iteration: 5// wireframe renderization with quasi-black 6// material properties and smooth shading. 7glShadeModel( GL_SMOOTH ); 8glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); 9glColor4f( 0.3, 0.3, 0.3, 1.0 ); 10 glEnableClientState( GL_VERTEX_ARRAY ); 11 glEnableClientState( GL_NORMAL_ARRAY ); 12 glVertexPointer( 3, GL_FLOAT, 0, vecvertices ); 13 glNormalPointer( GL_FLOAT, 0, vecnormals ); 14 glDrawElements( GL_TRIANGLES, nfaces*3, 15 GL_UNSIGNED_INT, vecfaces ); 16 glDisableClientState( GL_NORMAL_ARRAY ); 17 glDisableClientState( GL_VERTEX_ARRAY ); 18 19 // second iteration: 20 // solid renderization with quasi-white 21 // material properties and flat shading. 22 glShadeModel( GL_FLAT ); 23 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); 24 glColor4f( 0.8, 0.8, 0.8, 1.0 ); 25 glEnableClientState( GL_VERTEX_ARRAY ); 26 glEnableClientState( GL_NORMAL_ARRAY ); 27 glVertexPointer( 3, GL_FLOAT, 0, vecvertices ); 28 glNormalPointer( GL_FLOAT, 0, vecnormals ); 29 glDrawElements( GL_TRIANGLES, nfaces*3, 30 GL_UNSIGNED_INT, vecfaces ); 31 glDisableClientState( GL_NORMAL_ARRAY ); 32 glDisableClientState( GL_VERTEX_ARRAY ); CPP code 10.7: Draft rendering mode OPENGL commands. 69 This is the illumination model based on per-vertex normal instead of per-face normal. This mode is supported here because, as mentioned in section 10.2.3.2 on page 114,MeshInspeQTor computes always the per-vertex normals when an OBJ file is loaded into memory. 70 This is the illumination model with per-face normal as its basis. This type of shading is enabled although the normals are normalized per-vertex, adn the final result is lower than the smoothed one, but for the purpose of this kind of rendering is ideal. Research on Generic Interactive Deformable 3D Models
10.3. Displaying 3d models 123 Then, as done in the previous section, here’s an example figure featuring the cited draft renderization methodology, using the same model that with the another methods: Figure 10.9: MeshInspeQTor’s ‘draft’ rendering style. Notice that, because of the flat face shading, the triangular faces are perfectly detailed and can be clearly observed. Additional 3Dmodel properties’ visualization 10.3.3 Model’s bounding box 10.3.3.1 The MeshInspeQTor parser also computes, for every model group read from an OBJ file, its own bounding box; that is, an axis aligned prism that envolves all the model; it’s stored simply with two vertices ∈R3:(i) pmin, containing the minimum (x, y, z)coordinates of all the group vertices —with the three coordinate values indepedendent w.r.t. the vertex where found—, and (ii) pmax, containing the maximum ones. The code for rendering the bounding box of a model will be omitted because follows the same strategy for painting a square given its minimum and maximum coordinates —though here there are six wireframe squares to be painted, one for each cube face—; but an example will be shown in the next figure, where a bunny is sourrounded by its bounding box —notice that the bounding box isn’t involved on lighting parameters—. Figure 10.10: Renderization of a model with its bounding box surrounding it, in MeshInspeQTor. Master Thesis in Computer Graphics by Marc Musquera Moreno
226 Appendix C. End-User Software Data Sheet: ‘ForceReaQTor’ Setting the Dynamic Force List C.2.1.3 As said on the previous page, independelty of having a 3Dskeleton charged in memory, ForreReaQTor offers a complete configuration panel for creating, deleting and updating dynamic actions through the time-line, for setting three types of dynamic successes, each one with some restricted parameters: •dynamic forces; this item has all the available paramaters:(i) skeleton node range, (ii) force direction, (iii) force amount —in newtons— and (iv) time-line active action —that is, initial and final milisecond of force enabling—; Figure C.3: The preview of a previously specified dynamic force —yellow lines, maintaining the specified force vector direction, on the ‘front right leg’ zone—, applied to the cow skeleton. •fixed skeleton nodes; obviously, force direction and amount is unnecessary, and besides, ForceReaQTor will fix these nodes during all the simulation, so the time-line is also unnecessary. Then, only the skeleton node range is available here. Figure C.4: The preview of a fixed nodes application —red remarked nodes, on the ‘head’ zone—, also to the cow skeleton. Research on Generic Interactive Deformable 3D Models
C.2. Product Details 227 •skeleton spring cuttings; as in the fixed nodes settings, force amount and direction will be disabled; nevertheless, a cut is permanent but only from the moment of cut, so apart from the node range, the initial time-line milisecond are the available settings. Figure C.5: The preview of a specified cutting —orange remarked lines, on the ‘front left knee’ zone—, applied to the cow skeleton too. As it can be seen in the figures C.3,C.4 and C.5,every dynamic action can be previewed on the previously charged 3Dskeleton. This process is error-managed; that means, if there is some dynamic action which node range is skeleton-out-of-range, ForceReaQ- Tor does nothing, and the same with existing but not validated nodes. Controls and management C.2.1.4 Since 3Dnon-rigid skeletons are generated automatically in the MeshInspeQTor VoxelMap file format importing action, the VOX file format will be the chosen for loading this kind of data. Additionally, the dynamic force lists —including forces, node fixing and spring cutting— are saveable and loadable by the property DFL file format. Also, as for the dynamic action preview as long as for the simulation playing, there is some visualization camera settings by Camera menu, where camera can be automatically skeleton-centered, or its position can be modified: top-view, side-view and frontview —this last is the default one—. Besides, there are itneractive camera controls with the dragging mouse movement while any mouse button is pressed; these are the mouse actions: Mouse Button Action while dragging Left Scene Rotation Middle Center-of-Scene Displacement Right Camera Zoom Table C.1: ForceReaQTor mouse controls. Master Thesis in Computer Graphics by Marc Musquera Moreno
228 Appendix C. End-User Software Data Sheet: ‘ForceReaQTor’ Simulator tab: The Real-Time Deformable Simulator C.2.2 Deformable system visualization styles C.2.2.1 ForceReaQTor offers three types of deformable system rendering for the visualization, perfectly modificable in simulation run-time: 1. the first of them has been seen in all the previous figures, it’s the 3Dskeleton model;, comprising nodes and springs; 2. the second mode is the original polygonal mesh from where the voxelmap was generated —in case it exists—; 3. the another mode is the Marching Cubes’ extracted polygonal mesh, an automatically generated mesh from the 3Dskeleton shape by using the isosurface extraction algorithm Marching Cubes; Figure C.6: The ForceReaQTor’s Marching Cubes extracted mesh rendering of a bunny. Playing the simulation C.2.2.2 Once there is a 3Dskeleton charged in memory, and a dinamyc force list is correctly configured —by a DFL file loading, or manually—, the deformation set can be simulated in the Simulation tab. There are three main buttons for simulation controlling: •PLAY, that reproduces the previously specified deformation set in a discrete smoothed time-line, applying subsequently all the set dynamic deformable actions; •PAUSE, that pauses the simulation; if then the user clicks on textbfPLAY again, the simulation continues from the pause moment; •STOP, that resets the simulation; that is, a pause but with a returning-to-zero timing —by clicking PLAY again, the simulation doesn’t continue but begins again—; Research on Generic Interactive Deformable 3D Models
C.2. Product Details 229 additionally, it’s important to notice that in every simulation moment —played, paused, stopped—, the scene visualization is interactively enabled by using the specified mouse controls on the table C.1. The numerical integrators: Euler and Verlet C.2.2.3 Before starting a simulation, the user must choose a numerical integrator for the 3D non-rigid skeleton; there are two possible choices: 1. the Euler numerical integrator, more accurate and realistic but also more unstable under time step closer to the limit; 2. the Verlet one, more stable for extremal conditions; however, it is also a linear approximation of the Euler iterator, and that implies two things: it’s more faster but the simulation is more still restricting on deformations. The frames per second —FPS— rate specification C.2.2.4 In ForceReaQTor there is also a pre-beginning simulation parameter: the FPS-rate. The simulation displaying and the deformation algorithm execution are computationally independent —although they are really data-dependent—, so the user can specify which framerate desires. Figure C.7: The FPS error message thrown when the framerate cannot be achieved. However, if the specified FPS rate is too much high an error message will be shown and the simulation will be stopped. There are —briefly— two reasons for that: 1. too much high framerate in FPS for so much complex deformation system —so, the computer is inherently not capable to display so much FPS—; 2. the specified framerate has a normal value but the deformable system has too much deformation restrictions —e.g. the three effects, stretch,shear and bending—; it will may execute only with stretch restriction; Master Thesis in Computer Graphics by Marc Musquera Moreno
230 Appendix C. End-User Software Data Sheet: ‘ForceReaQTor’ Besides, if the numerical integrator selection has been the Euler one, it can be a good solution trying the Verlet integrator, due to its more efficiency and more stability — though caused by its more deformative restrictions—. Run-Time simulation parameters C.2.2.5 ForceReaQTor provides real run-time simulation parameters that modify the deformation characteristics; that is, parameters that can be enabled/disabled/modified before as long as during simulation. These run-time modifying parameters can: •define the deformation nature by enabling or disabling some restricting and relaxing forces that avoid the total chaos of the skeleton deformations: stretch,shear and bending; those restricting forces acts between skeleton nodes and springs, and habiliting each one increases the computational time; •set the numerical values of elasticity and dampening of the 3Dskeleton node connection springs; these values can easily destabilize the system103. Figure C.8: ForceReaQTor’s fatal destiny: destabilized simulation. Controls and management C.2.2.6 The file format management is the same that for the dynamic force list, due to the skeleton is the deformable base and the list of forces is the deformation settings through the time-line; so, the file formats VOX and DFL are required104. Additionaly, apart from the mouse controls of the table C.1, there are some hot keys —actionable by pressing at the same time CMD + the specified hotkey— for controlling the simulation in an easy and fast way, instead of the mouse clickings: 103 Indeed, by enabling more than one restricting force can also destabilize the system, but due to computational reasons, not to numerical reasons. 104 However, the dynamic force lists can be defined manually with the intervention of a DFL file loading. Research on Generic Interactive Deformable 3D Models
C.3. Requirements and recommendations 231 Hot Key Simulation Action CMD + ‘I’ Play Simulation CMD + ‘J’ Pause Simulation CMD + ‘K’ Stop Simulation Table C.2: ForceReaQTor simulation hot key controls. Requirements and recommendations C.3 ForceReaQTor is a complete dynamic physically-based deformable model simulator, that admits any volumetric representation —voxelmap— and the application transforms into a 3Dnon-rigid skeleton.ForceReaQTor is capable to perform any kind of force deformation by a three —accumulative— relaxing types of forces as long as also implements a virtual mesh cutting that acts as a virtual scalpel. However, theres no user-app interface105 but a dynamic time-line panel that permits to set a dynamic force list —admitting cuttings too—, saveable and loadable as DFL files. (a) The Apple logo. (b) The Mac logo. (c) The ForceReaQTor logo. Figure C.9: ForceReaQTor software and hardware requirements logos. This application has been developed for Apple Mac Intel platforms using the QT4 framework for GUI design and OPENGL API for the graphics displaying. A Shader Model 3.0 compatible GPU with minimum of 128MB of own textscram is required for the deformable model visualization and computations. 105 So, this is only a real-time simulator, not a complete interactive system. Master Thesis in Computer Graphics by Marc Musquera Moreno