An introduction to Geometrical Modelling and Mesh Generation The ...
An introduction to Geometrical Modelling and Mesh Generation The ...
An introduction to Geometrical Modelling and Mesh Generation The ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>An</strong> <strong>introduction</strong> <strong>to</strong> <strong>Geometrical</strong> <strong>Modelling</strong> <strong>and</strong> <strong>Mesh</strong><br />
<strong>Generation</strong><br />
<strong>The</strong> Gmsh Companion<br />
Chris<strong>to</strong>phe Geuzaine Emilie March<strong>and</strong>ise Jean-François Remacle
Contents<br />
1 Introduction 7<br />
1.1 <strong>The</strong> Design of Gmsh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8<br />
1.1.1 Fast <strong>and</strong> Light . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8<br />
1.1.2 User-friendly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9<br />
2 Solid Models 13<br />
2.1 Principal characteristics of a solid modeling software . . . . . . . . . . . . . 13<br />
2.1.1 Feature-based modeling . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
2.1.2 Constraint-based modeling . . . . . . . . . . . . . . . . . . . . . . . 13<br />
2.1.3 Parametric modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . 14<br />
2.1.4 His<strong>to</strong>ry-based modeling . . . . . . . . . . . . . . . . . . . . . . . . . 14<br />
2.1.5 Associative modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
2.2 CSG Representation of Solids . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
2.2.1 Basic Primitives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
2.2.2 Regularized Boolean Opera<strong>to</strong>rs . . . . . . . . . . . . . . . . . . . . . 15<br />
2.2.3 <strong>The</strong> CSG tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16<br />
2.2.4 Gluing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18<br />
2.3 Boundary Representation of Solids . . . . . . . . . . . . . . . . . . . . . . . 18<br />
2.4 Topological Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . 19<br />
2.4.1 Winged-edge data structure . . . . . . . . . . . . . . . . . . . . . . . 19<br />
2.4.2 Manifold <strong>and</strong> Non-Manifold models . . . . . . . . . . . . . . . . . . 20<br />
2.4.3 Non-manifold <strong>to</strong>pologies . . . . . . . . . . . . . . . . . . . . . . . . . 21<br />
2.4.4 Internal representation of solid models in Gmsh . . . . . . . . . . . . 25<br />
3
4 CONTENTS<br />
2.5 <strong>Geometrical</strong> Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . 31<br />
2.5.1 Differential Geometry of Curves . . . . . . . . . . . . . . . . . . . . 31<br />
2.5.2 Differential Geometry of Surfaces . . . . . . . . . . . . . . . . . . . . 34<br />
2.5.3 Classifying the parametrizations . . . . . . . . . . . . . . . . . . . . 37<br />
2.5.4 Computing harmonic <strong>and</strong> conformal maps . . . . . . . . . . . . . . . 38<br />
2.5.5 Examples of analytical parametrizations . . . . . . . . . . . . . . . . 41<br />
2.6 Non-Uniform Rational b-Splines (NURBS) . . . . . . . . . . . . . . . . . . . 44<br />
2.6.1 NURBS curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44<br />
2.6.2 NURBS surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47<br />
2.7 Surface Intersections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48<br />
2.7.1 Intersection two implicit surfaces . . . . . . . . . . . . . . . . . . . . 48<br />
2.7.2 Intersection of a parametric surface with an implicit surface . . . . . 50<br />
2.7.3 From parametric <strong>to</strong> implicit representations . . . . . . . . . . . . . . 51<br />
2.7.4 Intersection of NURBS . . . . . . . . . . . . . . . . . . . . . . . . . . 53<br />
2.8 Geodesics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53<br />
3 <strong>Mesh</strong> <strong>Generation</strong> 57<br />
3.1 Generalities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57<br />
3.1.1 <strong>The</strong> Euler-Poincaré Formula . . . . . . . . . . . . . . . . . . . . . . . 58<br />
3.1.2 <strong>Mesh</strong> generation procedure . . . . . . . . . . . . . . . . . . . . . . . 61<br />
3.2 <strong>Mesh</strong> size field <strong>and</strong> quality measures . . . . . . . . . . . . . . . . . . . . . . 63<br />
3.2.1 <strong>Mesh</strong> size field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63<br />
3.2.2 Element quality measures . . . . . . . . . . . . . . . . . . . . . . . . 64<br />
3.3 One Dimensional <strong>Mesh</strong>ing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65<br />
3.4 Delaunay <strong>and</strong> Voronoï . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65<br />
3.4.1 <strong>The</strong> Voronoï diagram . . . . . . . . . . . . . . . . . . . . . . . . . . 65<br />
3.4.2 <strong>The</strong> Delaunay Triangulation . . . . . . . . . . . . . . . . . . . . . . . 68<br />
3.4.3 Construction of Delaunay Triangulations . . . . . . . . . . . . . . . 75<br />
3.5 Planar <strong>Mesh</strong>ing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84<br />
3.5.1 <strong>The</strong> general procedure . . . . . . . . . . . . . . . . . . . . . . . . . . 85<br />
3.5.2 Boundary edges recovery . . . . . . . . . . . . . . . . . . . . . . . . 89
CONTENTS 5<br />
3.5.3 Point insertion <strong>and</strong> Delaunay kernel . . . . . . . . . . . . . . . . . . 89<br />
3.5.4 <strong>An</strong>isotropic Delaunay meshing . . . . . . . . . . . . . . . . . . . . . 92<br />
3.5.5 Practical implementation . . . . . . . . . . . . . . . . . . . . . . . . 93<br />
3.6 Surface <strong>Mesh</strong>ing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95<br />
3.7 3-D <strong>Mesh</strong> <strong>Generation</strong> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99<br />
3.7.1 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102<br />
3.7.2 Mixed <strong>Mesh</strong>es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106<br />
4 Remeshing based on surface parametrization 107<br />
4.1 Parametrization of triangulated surfaces . . . . . . . . . . . . . . . . . . . . 109<br />
4.2 Computing discrete harmonic <strong>and</strong> conformal maps . . . . . . . . . . . . . . 112<br />
4.3 Boundary conditions for discrete maps . . . . . . . . . . . . . . . . . . . . . 115<br />
4.4 Issues with discrete linear mappings . . . . . . . . . . . . . . . . . . . . . . 121<br />
4.5 Au<strong>to</strong>matic remeshing with parametrizations . . . . . . . . . . . . . . . . . . 125<br />
4.5.1 Multiscale Laplace partitioning method . . . . . . . . . . . . . . . . 126<br />
4.5.2 Au<strong>to</strong>matic algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 126<br />
4.6 Quality remeshing with parametrizations . . . . . . . . . . . . . . . . . . . . 126
6 CONTENTS
Chapter 1<br />
Introduction<br />
When we started the Gmsh project in the summer of 1996, our goal was <strong>to</strong> develop a<br />
fast, light <strong>and</strong> user-friendly software <strong>to</strong> easily create geometries <strong>and</strong> meshes that could<br />
be used in our three-dimensional finite element solvers [?], <strong>and</strong> then visualize <strong>and</strong> export<br />
the computational results with maximum flexibility. At the time, no open-source<br />
software combining a CAD engine, a mesh genera<strong>to</strong>r <strong>and</strong> a post-processor was available:<br />
the existing integrated <strong>to</strong>ols were expensive commercial packages [?], <strong>and</strong> the freeware<br />
or shareware <strong>to</strong>ols were limited <strong>to</strong> either CAD [?], two-dimensional mesh generation [?],<br />
three-dimensional mesh generation [?, ?, ?], or post-processing [?]. <strong>The</strong> need for a free<br />
integrated solution was conspicuous, <strong>and</strong> several projects similar in spirit <strong>to</strong> Gmsh were<br />
also born around the same time—some of them still actively developed <strong>to</strong>day [?, ?]. Gmsh<br />
however was unique in its design: it consisted of a very small kernel with four modules<br />
(geometry, mesh, solver <strong>and</strong> post-processing), not tied <strong>to</strong> any particular computational<br />
solver, <strong>and</strong> designed from the start <strong>to</strong> be driven both using a user-friendly graphical interface<br />
(GUI) <strong>and</strong> its own scripting language.<br />
<strong>The</strong> first public release of Gmsh occurred in 1998. This version was Unix-only, distributed<br />
over the internet in binary form, with the graphics layer based on OpenGL [?] <strong>and</strong><br />
the user interface written in Motif [?]. After several updates <strong>and</strong> a short-lived Windowsonly<br />
fork in 2000, the whole user interface was rewritten using FLTK [?] in early 2001, <strong>and</strong><br />
the code, still in binary-only form, was released for Windows <strong>and</strong> a variety of Unix operating<br />
systems. In 2003 the full source code was released under the GNU General Public<br />
License [?], <strong>and</strong> it was modified <strong>to</strong> provide native support for all major operating systems:<br />
Windows, MacOS <strong>and</strong> all Unix/X11 variants. In the summer of 2006 Gmsh underwent<br />
a major rewrite, which led <strong>to</strong> the release of version 2 of the software in February 2007.<br />
About 50% of the code in version 2 is new: an abstract geometrical <strong>and</strong> post-processing<br />
layer has been introduced, the mesh data structures <strong>and</strong> algorithms have been rewritten<br />
from scratch, <strong>and</strong> the graphics layer has also been completely overhauled.<br />
Today Gmsh enjoys a thriving community of several hundred users <strong>and</strong> developers<br />
worldwide. It is driven by the need of researchers <strong>and</strong> engineers in academia <strong>and</strong> industry<br />
7
8 CHAPTER 1. INTRODUCTION<br />
alike for a small, open-source pre- <strong>and</strong> post-processing solution for grid-based numerical<br />
methods. <strong>The</strong> aim of this paper is not <strong>to</strong> be a user’s guide or a reference manual—see [?]<br />
instead. Rather, it is <strong>to</strong> present the philosophy <strong>and</strong> the original features of Gmsh which<br />
make it st<strong>and</strong> out from its free <strong>and</strong> commercial alternatives.<br />
<strong>The</strong> paper is structured as follows. In Section 1.1 we outline the overall philosophy<br />
<strong>and</strong> design goals of Gmsh, as well as the main technical choices that were made in order <strong>to</strong><br />
achieve these goals. Sections ??, ??, ?? <strong>and</strong> ?? then respectively describe the geometry,<br />
mesh, solver <strong>and</strong> post-processing modules. <strong>The</strong> paper is concluded in Section ?? with<br />
perspectives for future developments.<br />
1.1 <strong>The</strong> Design of Gmsh<br />
Gmsh is built around four modules: geometry, mesh, solver <strong>and</strong> post-processing. Each<br />
module can be controlled either interactively using the GUI or using the scripting language.<br />
<strong>The</strong> design of all four modules relies on a simple philosophy—be fast, light <strong>and</strong><br />
user-friendly.<br />
Fast: on a st<strong>and</strong>ard personal computer at any given point in time Gmsh should launch<br />
instantaneously, be able <strong>to</strong> generate a “larger than average” mesh (compared <strong>to</strong> the<br />
st<strong>and</strong>ards of the finite element community; say, one million tetrahedra in 2008) in<br />
less than a minute, <strong>and</strong> be able <strong>to</strong> visualize such a mesh <strong>to</strong>gether with associated<br />
post-processing datasets at interactive speeds.<br />
Light: the memory footprint of the application should be minimal <strong>and</strong> the source code<br />
should be small enough so that a single developer can underst<strong>and</strong> it. Installing<br />
or running the software should not depend on any non-widely available third-party<br />
software package.<br />
User-friendly: the graphical user interface should be designed in such a way that a new<br />
user can create simple meshes in a matter of minutes. In addition, the code should<br />
be robust, portable, scriptable, extensible <strong>and</strong> thoroughly documented—all features<br />
contributing <strong>to</strong> a user-friendly experience.<br />
In the following sections we describe the technical choices that we made <strong>to</strong> achieve<br />
these sometimes conflicting design objectives. Although major parts of the code have been<br />
rewritten over the years, the overall initial architecture <strong>and</strong> design from 1996 have always<br />
stayed the same.<br />
1.1.1 Fast <strong>and</strong> Light<br />
In order <strong>to</strong> be fast <strong>and</strong> light in the sense just described above, Gmsh is entirely written in<br />
st<strong>and</strong>ard C++ [?]—both the kernel <strong>and</strong> the user interface.
1.1. THE DESIGN OF GMSH 9<br />
<strong>The</strong> kernel uses BLAS [?] (through the GSL, the GNU Scientific Library [?]) for<br />
most of the basic linear algebra. To keep them easy <strong>to</strong> underst<strong>and</strong> the algorithms have<br />
not been overly optimized for speed or memory usage, yet Gmsh currently generates about<br />
a million tetrahedra per minute <strong>and</strong> per 150 Mb of RAM on a st<strong>and</strong>ard personal computer,<br />
which makes it powerful enough for many academic <strong>and</strong> engineering applications.<br />
<strong>The</strong> graphical interface is built using FLTK [?] <strong>and</strong> OpenGL [?]. Using FLTK instead<br />
of a larger or more complex widget <strong>to</strong>olkit, like for example Java, TCL/TK, GTK or QT,<br />
allows <strong>to</strong> link Gmsh statically with the <strong>to</strong>olkit. This tremendously reduces the launch time,<br />
memory footprint <strong>and</strong> installation complexity (installing Gmsh requires copying a single<br />
executable file), as well as the build time—a statically linked, ready <strong>to</strong> use executable is<br />
produced in a few minutes on a st<strong>and</strong>ard personal computer. <strong>An</strong>alogously, directly using<br />
OpenGL instead of a more complex graphics library like Inven<strong>to</strong>r [?] or VTK [?] makes<br />
Gmsh lightweight, without sacrificing rendering performance (Gmsh makes extensive use<br />
of OpenGL vertex arrays).<br />
<strong>The</strong> design of the solver <strong>and</strong> scripting interfaces follows the same strategy: the solver<br />
interface is written using st<strong>and</strong>ard Unix <strong>and</strong> TCP/IP sockets instead of, e.g., Corba [?],<br />
<strong>and</strong> the scripting interface is built using Lex/Flex <strong>and</strong> Yacc/Bison [?] instead of using an<br />
external scripting language like, e.g., Python.<br />
1.1.2 User-friendly<br />
Although Gmsh can be built as a library (which can then be linked with other software<br />
<strong>to</strong>ols), it is usually distributed as a st<strong>and</strong>-alone software, ready <strong>to</strong> be used by end users.<br />
This st<strong>and</strong>-alone version can be run either interactively using the graphical user interface<br />
or in a non-interactive mode—either from the comm<strong>and</strong> line or via the scripting language.<br />
Achieving “user-friendliness” has been an important driving fac<strong>to</strong>r behind key technical<br />
choices. We detail some of these choices hereafter, focusing on the list of desirable<br />
features given at the beginning of the section.<br />
Robustness <strong>and</strong> Portability<br />
To achieve robustness, i.e., working for the largest possible range of input data <strong>and</strong> being<br />
as <strong>to</strong>lerant as possible <strong>to</strong> erroneous user input, we use robust geometrical predicates [?]<br />
in critical portions of the algorithms, <strong>and</strong> strive <strong>to</strong> provide useful error messages when an<br />
unmanageable exception is triggered.<br />
In order <strong>to</strong> easily produce a native version of the code on all major operating systems,<br />
Gmsh is written entirely in st<strong>and</strong>ard C++, <strong>and</strong> uses portable <strong>to</strong>olkits for its GUI (FLTK)<br />
<strong>and</strong> graphics rendering (OpenGL). Open-sourcing Gmsh under the GNU General Public<br />
License [?] also helped portability, as the code was made part of several official Linux<br />
distributions (most notably Debian [?]), <strong>and</strong> thus benefited from their extensive au<strong>to</strong>mated<br />
testing infrastructure. Either with the graphical user interface or in batch mode, the same
10 CHAPTER 1. INTRODUCTION<br />
version of Gmsh now runs on most computers, from lap<strong>to</strong>ps <strong>to</strong> workstations <strong>and</strong> large<br />
HPC clusters.<br />
Scriptability<br />
Gmsh is scriptable so that all input data can be parametrized, <strong>and</strong> so that Gmsh can be<br />
easily inserted as a component inside a larger computational chain. As mentioned above,<br />
scripting is implemented in Gmsh using Lex <strong>and</strong> Yacc. <strong>The</strong> tight integration with the<br />
resulting language means that full access <strong>to</strong> internal capabilities is provided, including<br />
bidirectional access <strong>to</strong> more than 500 internal options fine-tuning the behavior of the four<br />
modules. <strong>The</strong> scripting language allows for example <strong>to</strong> fully parametrize all geometrical<br />
entities, <strong>to</strong> interface external solvers without modifying the source code, or <strong>to</strong> au<strong>to</strong>mate<br />
all post-processing operations, e.g., <strong>to</strong> create complex animations or perform off-screen<br />
rendering [?].<br />
Extensibility<br />
We tried <strong>to</strong> ease the modification <strong>and</strong> addition of features by users <strong>and</strong> developers. Such<br />
extensibility takes different forms for each of the four modules:<br />
Geometry: the abstract, object-oriented geometry layer permits <strong>to</strong> write all the algorithms<br />
independently of the underlying CAD representation. At the source code<br />
level Gmsh is thus easily extensible by adding support for additional CAD engines.<br />
Currently two engines are interfaced: the native Gmsh CAD engine <strong>and</strong> OpenCascade<br />
[?]. Adding support for other engines like, e.g., Parasolid [?], can be done<br />
simply by deriving four abstract classes—see Section ??. At the scripting level users<br />
can then transparently mix <strong>and</strong> match geometrical parts represented internally by<br />
different CAD engines. For example, it is possible <strong>to</strong> extend an OpenCascade model<br />
of an airplane with a terrain model defined in the scripting language.<br />
<strong>Mesh</strong>: using the abstract geometrical interface it is also possible <strong>to</strong> interface additional<br />
meshing kernels. Currently, in addition <strong>to</strong> its own meshing algorithms (see Section<br />
??), Gmsh is interfaced with Netgen [?] <strong>and</strong> Tetgen [?].<br />
Solver: a socket-based communication interface allows <strong>to</strong> interface Gmsh with various<br />
solvers without changing the source code; tailored graphical user interfaces can also<br />
easily be added when more fine-grained interactions are needed.<br />
Post-processing: the post-processor can be extended with user-defined operations through<br />
dynamically loadable plug-ins. <strong>The</strong>se plug-ins act on post-processing datasets (called<br />
views) in one of two ways: either destructively changing the contents of a view, or<br />
creating one or more views based on the current view.
1.1. THE DESIGN OF GMSH 11<br />
All source code-level extensions can be enabled or disabled at compile time thanks <strong>to</strong><br />
an au<strong>to</strong>conf-based build mechanism [?], which selects which parts of the code <strong>to</strong> include/exclude.<br />
Documentation <strong>and</strong> Open File Formats<br />
Documentation is provided both in the source code <strong>and</strong> in the form of a reference manual,<br />
including several h<strong>and</strong>s-on tu<strong>to</strong>rial examples <strong>and</strong> a comprehensive web site with several<br />
mailing lists <strong>and</strong> a wiki.<br />
<strong>An</strong>other important feature contributing <strong>to</strong> user-friendliness is the availability of<br />
st<strong>and</strong>ard input <strong>and</strong> output file formats. Gmsh uses open or de fac<strong>to</strong> st<strong>and</strong>ard formats<br />
whenever possible, from st<strong>and</strong>ard bitmap graphics formats (JPEG, GIF, PNG) <strong>and</strong> vec<strong>to</strong>r<br />
formats [?] (SVG, PostScript, PDF) <strong>to</strong> mesh formats (Ideas UNV, Nastran BDF).<br />
Combined with the open-source release of the code this greatly facilitates the integration<br />
of Gmsh with other computational <strong>to</strong>ols.
12 CHAPTER 1. INTRODUCTION
Chapter 2<br />
Solid Models<br />
A solid model is a computer model of a 3D solid. It is a virtual representation of the shape<br />
of a solid. Solid models can be simple parts (Figure 2.1, part (a)) or complex assemblies<br />
of multiple parts (Figure 2.1, part (b)).<br />
We aim here at explaining how such solids can be described on a computer. We will<br />
principally focus on the ability of such solid models <strong>to</strong> serve as input <strong>to</strong> numerical simulations.<br />
In particular, we will adress the issues related <strong>to</strong> finite element mesh generation.<br />
2.1 Principal characteristics of a solid modeling software<br />
A solid modeling software may have some specific characteristics that enables <strong>to</strong> enhance<br />
both its efficiency <strong>and</strong> the productivity of the solid modeling process:<br />
2.1.1 Feature-based modeling<br />
Features are defined <strong>to</strong> be parametric shapes associated with attributes such as intrinsic<br />
geometric parameters (length, width, depth etc), position <strong>and</strong> orientation, geometric<br />
<strong>to</strong>lerances, material properties, <strong>and</strong> references <strong>to</strong> other features.<br />
Feature-based modelers allow operations such as creating holes, fillets, chamfers,<br />
bosses, <strong>and</strong> pockets <strong>to</strong> be associated with specific edges <strong>and</strong> faces. When the edges or<br />
faces move because of a regeneration, the feature operation moves along with it, keeping<br />
the original relationships.<br />
2.1.2 Constraint-based modeling<br />
<strong>The</strong>re are two types of constraints. Dimensional constraints are used <strong>to</strong> specify distances<br />
between items. Geometric constraints define positional relationships between entities in<br />
13
14 CHAPTER 2. SOLID MODELS<br />
(a) (b)<br />
Figure 2.1: A simple part (a) <strong>and</strong> a complex assembly (b).<br />
the model in terms of the geometry. Examples of geometric constraints include tangency,<br />
parallelism, symmetry, concentricity...<br />
Constraint-based modeling allows the engineer or designer <strong>to</strong> incorporate “intelligence”<br />
in<strong>to</strong> the design. <strong>The</strong> initial sketch of a two-dimensional profile in constraint-based<br />
solid modeling does not need <strong>to</strong> be created with a great deal of accuracy. It just needs <strong>to</strong><br />
represent the basic geometry of the cross section. <strong>The</strong> exact size <strong>and</strong> shape of the profile<br />
is defined through assigning enough parameters <strong>to</strong> fully “constrain” it.<br />
2.1.3 Parametric modeling<br />
Parametric modeling means that parameters of the model may be modified <strong>to</strong> change<br />
the geometry of the model. A dimension is a simple example of a parameter. When a<br />
dimension is changed, the geometry of the part is updated. Thus, the parameter drives the<br />
geometry. <strong>An</strong> additional feature of parametric modeling is that parameters can reference<br />
other parameters through relations or equations. <strong>The</strong> power of this approach is that<br />
when one dimension is modified, all linked dimensions are updated according <strong>to</strong> specified<br />
mathematical relations, instead of having <strong>to</strong> update all related dimensions individually.<br />
2.1.4 His<strong>to</strong>ry-based modeling<br />
<strong>The</strong> last aspect of solid modeling is that the order in which parts are created is critical.<br />
This is known as his<strong>to</strong>ry-based modeling. For example, a hole cannot be created before a<br />
solid volume of material in which the hole occurs has been modeled. If the solid volume<br />
is deleted, then the hole is deleted with it. This is known as a parent-child relation. <strong>The</strong>
2.2. CSG REPRESENTATION OF SOLIDS 15<br />
child (hole) cannot exist without the parent (solid volume) existing first. Parent-child<br />
relations are critical <strong>to</strong> maintaining design intent in a part. Most solid modeling software<br />
recognizes that if you delete a feature with a hole in it, you do not want the hole <strong>to</strong> remain<br />
floating around without being attached <strong>to</strong> the feature. Consequently, careful thought <strong>and</strong><br />
planning of the base feature <strong>and</strong> initial additional features can have a significant effect on<br />
the ease of adding subsequent features <strong>and</strong> making modifications.<br />
2.1.5 Associative modeling<br />
<strong>The</strong> associative character of solid modeling software causes modifications in one object <strong>to</strong><br />
“ripple though” all associated objects. For instance, suppose that you change the diameter<br />
of a hole on the engineering drawing that was created based on your original solid model.<br />
<strong>The</strong> diameter of the hole will be au<strong>to</strong>matically changed in the solid model of the part,<br />
<strong>to</strong>o. In addition, the diameter of the hole will be updated on any assembly that includes<br />
that part. Similarly, changing the dimension in the part model will au<strong>to</strong>matically result<br />
in updated values of that dimension in the drawing or assembly incorporating the part.<br />
This aspect of solid model software makes the modification of parts much easier <strong>and</strong> less<br />
prone <strong>to</strong> error.<br />
As a result of being feature based, constraint based, parametric, his<strong>to</strong>ry based, <strong>and</strong><br />
associative, modern solid modeling software captures “design intent”, not just the design.<br />
This comes about because the solid modeling software incorporates engineering knowledge<br />
in<strong>to</strong> the solid model with features, constraints, <strong>and</strong> relationships that preserve the intended<br />
geometric relationships in the model.<br />
2.2 CSG Representation of Solids<br />
We discuss here briefly the Constructive Solid Geometry (CSG) representation of solids.<br />
CSG allow <strong>to</strong> construct complex solid through primitives, boolean opera<strong>to</strong>rs <strong>and</strong> rigid<br />
motions.<br />
2.2.1 Basic Primitives<br />
<strong>The</strong> st<strong>and</strong>ard CSG basic primitives are the sphere, the <strong>to</strong>rus, the parallelipiped (block), the<br />
cylinder <strong>and</strong> the cone. All those primitives defined bounded closed orientable domains. All<br />
basic primitives are defined in the world system of coordinates. Rigid motions (rotations,<br />
translations) <strong>and</strong> scalings can be applied <strong>to</strong> re-position the primitives.<br />
2.2.2 Regularized Boolean Opera<strong>to</strong>rs<br />
Each primitive divides the 3D space in<strong>to</strong> two parts: the one that is inside the primitive<br />
<strong>and</strong> the one that is outside. <strong>The</strong> closure of a primitive is the surface that separates its
16 CHAPTER 2. SOLID MODELS<br />
interior with its exterior.<br />
It is easy <strong>to</strong> think a primitive as a set where st<strong>and</strong>ard boolean operations like union,<br />
intersection <strong>and</strong> difference can be defined. Basic primitives can be combined using boolean<br />
operations. Three boolean opera<strong>to</strong>rs are defined. Consider two primitives A <strong>and</strong> B.<br />
1. <strong>The</strong> Union A ∪ B operation returns of all the points x ∈ R 3 that are either inside A<br />
or inside B.<br />
2. <strong>The</strong> Intersection A ∩ B operation returns of all the points x ∈ R 3 that are both<br />
inside A <strong>and</strong> inside B.<br />
3. <strong>The</strong> Difference A \ B operation returns of all the points x ∈ R 3 that are inside A<br />
<strong>and</strong> outside B.<br />
Regularized boolean opera<strong>to</strong>rs differ from the set-theoretic ones in that dangling<br />
lower dimensional structures are eliminated, all remaining faces, edges <strong>and</strong> vertices belonging<br />
<strong>to</strong> the closure of the resulting volume.<br />
2.2.3 <strong>The</strong> CSG tree<br />
A CSG object can be easily represented in a tree structure where the leaves of the tree<br />
are simple primitives, nodes of the tree are solids, edges of the tree are boolean operations<br />
<strong>and</strong> where the root of the tree is a solid that is the final CSG object. Figure 2.2 shows an<br />
example of a simple CSG tree.<br />
Most of the current commercial solid modelers enable <strong>to</strong> use CSG trees. Designing<br />
robust algorithms for computing both the geometry <strong>and</strong> the <strong>to</strong>pology of surface intersections<br />
is a complex problem. A few number of softwares enable <strong>to</strong> perform CSG computations<br />
efficiently <strong>and</strong>, <strong>to</strong> our best knowledge, only one is open source. In Gmsh, we have<br />
interfaced Opencascade primitives <strong>and</strong> opera<strong>to</strong>rs <strong>to</strong> build the solid of Figure 2.2. <strong>The</strong><br />
Gmsh lua interface code for building this solid is<br />
R = 1.0;<br />
s = .7;<br />
t = 1.3;<br />
myModel = GModel();<br />
myTool = GModel();<br />
myTool:addSphere(0,0,0,R*t);<br />
myModel:addBlock({-R,-R,-R},{R,R,R});<br />
myModel:computeIntersection(myTool,0);<br />
myTool2 = GModel();<br />
myTool2:addCylinder({-2*R,0,0},{2*R,0,0},R*s);<br />
myTool3 = GModel();<br />
myTool3:addCylinder({0,-2*R,0},{0,2*R,0},R*s);
2.2. CSG REPRESENTATION OF SOLIDS 17<br />
<br />
<br />
<br />
Figure 2.2: Example of a CSG tree.<br />
\
18 CHAPTER 2. SOLID MODELS<br />
myModel2 = GModel();<br />
myModel2:addCylinder({0,0,-2*R},{0,0,2*R},R*s);<br />
myModel2:computeUnion(myTool2,0);<br />
myModel2:computeUnion(myTool3,0);<br />
myModel:computeDifference(myModel2,0);<br />
2.2.4 Gluing<br />
Consider two spheres A <strong>and</strong> B both centered at the origin <strong>and</strong> of radiuses 2 <strong>and</strong> 1. <strong>The</strong><br />
Union A ∪ B returns A, i.e. the closure of B has been eliminated. <strong>The</strong> Difference A \ B<br />
returns a sphere with a hole. At some point, it can be useful <strong>to</strong> build<br />
C = (A \ B) ⊕ (A ∩ B)<br />
where ⊕ is not a regularized boolean opera<strong>to</strong>r but that simply adds the two volumes A\B<br />
<strong>and</strong> A ∩ B in the same model. <strong>The</strong> model contains two volumes that share a common<br />
boundary. Our aim here being <strong>to</strong> build a model that has a <strong>to</strong>pology, vertices, edges <strong>and</strong><br />
faces that are geometrically identical should be glued <strong>to</strong>gether in order <strong>to</strong> defined a proper<br />
<strong>to</strong>pology <strong>to</strong> the model. This kind of gluing opera<strong>to</strong>r has <strong>to</strong> be present in any modeler.<br />
2.3 Boundary Representation of Solids<br />
<strong>The</strong> CSG representation of a solid is used as a method for the construction of solids. This<br />
construction allows <strong>to</strong> test wether a point is inside or a solid, is on its surface or is outside<br />
of it. This is usually called point/solid classification. Point/solid classification can be<br />
done walking first downward the CSG tree in order <strong>to</strong> classify the point with respect <strong>to</strong><br />
the primitive that are on the leaves. <strong>The</strong>n, an upward sweep enables <strong>to</strong> apply the boolean<br />
operations that will determine the classification.<br />
Yet, CSG representation alone cannot represent accurately the boundaries of the<br />
solid. CSG representation are “<strong>to</strong>p-down” representations because they consider high<br />
level primitives <strong>and</strong> combine them <strong>to</strong> represent complex parts. It is indeed possible <strong>to</strong><br />
imagine a “bot<strong>to</strong>m-up” representation where every model entity is represented using its<br />
boundary.<br />
<strong>The</strong> boundary representation of a model also allows <strong>to</strong> determine whether a position<br />
is inside, outside, or on the boundary of a volume. This distinguishes a solid modeler from<br />
a surface or wireframe modeler. <strong>The</strong> “boundary” in “boundary representation” is the<br />
boundary between solid material <strong>and</strong> empty space. This boundary is made from a closed<br />
set of surfaces.<br />
It is common <strong>to</strong> distinguish the <strong>to</strong>pological part of the boundary representation <strong>and</strong><br />
its geometrical part.<br />
Topology is a branch of mathematics concerned with spatial properties preserved
2.4. TOPOLOGICAL REPRESENTATION 19<br />
Figure 2.3: Winged-edge data structure.<br />
under deformation (stretching without tearing or gluing). <strong>The</strong>se properties are the <strong>to</strong>pological<br />
invariants. On its own, <strong>to</strong>pology defines a ”rubber” model, whose position is not<br />
fixed in space. For example, a sphere <strong>and</strong> a cube are <strong>to</strong>pologically equivalent, but not<br />
geometrically.<br />
A <strong>to</strong>pological entity’s shape, position, <strong>and</strong> orientation are fixed in space when it is<br />
associated with a geometric entity. This is the geometrical part of the boundary representation.<br />
2.4 Topological Representation<br />
<strong>An</strong>y solid can be represented unambiguously by describing its surface <strong>and</strong> <strong>to</strong>pologically<br />
orienting it so that, for any point x ∈ R 3 , we can tell on which side of the solid this point<br />
lies.<br />
<strong>The</strong>re exist a variety of data structures that allow <strong>to</strong> represent the <strong>to</strong>pology of solid<br />
models on a computer. In what follows, we will present the classical winged-edge data<br />
structure. <strong>The</strong>n, we’ll present a more sophisticated version that allow <strong>to</strong> represent nonmanifold<br />
models. <strong>The</strong>n, we’ll present the way Gmsh s<strong>to</strong>res the <strong>to</strong>pology of models, with<br />
the aim of using that information for mesh generation.<br />
2.4.1 Winged-edge data structure<br />
Perhaps the oldest data structure for a boundary representation is the winged-edge data<br />
structure. <strong>The</strong> winged-edge data structure was initially used for representing polygonal<br />
meshes. A common way <strong>to</strong> represent a polygonal mesh is <strong>to</strong> define a list of vertices <strong>and</strong><br />
a list of faces s<strong>to</strong>ring pointers for its vertices. This representation is both convenient<br />
<strong>and</strong> efficient for many purposes, however it proves ineffective for dynamically modifying<br />
meshes.<br />
<strong>The</strong> winged-edge data structure has been designed <strong>to</strong> allow effective local modification<br />
of the <strong>to</strong>pology. It describes the <strong>to</strong>pology of objects by three tables. A face is<br />
bounded by closed loops of edges, one of which is the outside boundary (usually the first<br />
one) <strong>and</strong> the other ones are inner holes. Each vertex s<strong>to</strong>res a circularly ordered set of<br />
adjacent edges. Finally, each edge s<strong>to</strong>res four informations: (i) its two end vertices, (ii)<br />
left <strong>and</strong> right faces (manifold), (iii) preceding <strong>and</strong> next edge in clockwise order <strong>and</strong> (iv)<br />
preceding <strong>and</strong> next edge in counterclockwise order. Each edge is oriented: its orientation<br />
is given by its starting <strong>and</strong> ending vertex. Clockwise <strong>and</strong> counterclockwise orientations<br />
are given with respect of the orientation of the edge (see Figure 2.3). Operations on edges
20 CHAPTER 2. SOLID MODELS<br />
non manifold zero genus genus one<br />
Figure 2.4: A non manifold solid(left) <strong>and</strong> two different <strong>to</strong>pologies generated through a<br />
small variation of the geometry.<br />
like splitting, collapsing or flipping can be performed by doing local operations only.<br />
<strong>The</strong> winged-edge data structure assumes that every edge of the model has exactly<br />
two adjacent faces. This restricts the <strong>to</strong>pology of surfaces <strong>to</strong> be 2-manifolds. A surface<br />
embedded in R 3 is a 2-manifold if every point x has a neighborhood that can be mapped<br />
continuously in<strong>to</strong> an open set of R 2 .<br />
2.4.2 Manifold <strong>and</strong> Non-Manifold models<br />
A manifold model only contains manifold surfaces. <strong>The</strong> <strong>to</strong>pological properties of manifold<br />
representations are well unders<strong>to</strong>od mathematically. Restricting our attention <strong>to</strong> manifolds<br />
is attractive because of this mathematical theory. Yet, the result of boolean operations on<br />
manifold solids can lead <strong>to</strong> a result that is non-manifold. Let us consider the example in<br />
Figure 2.4 <strong>and</strong> that has been created using the following Gmsh script.<br />
myModel = GModel();<br />
myTool = GModel();<br />
myTool2 = GModel();<br />
myModel:addBlock({-1,-1,-1},{1,1,1});<br />
myTool:addBlock({-.4,-.4,-1},{.4,.4,1});<br />
myTool2:addBlock({.4,.4,-1},{1,1,1});<br />
myModel:computeDifference(myTool,0);<br />
myModel:computeDifference(myTool2,0);<br />
This object is non-manifold: one of its edge has more than 2 adjacent surfaces (actually<br />
4). <strong>An</strong>y point of this edge has non neighborhood that can be mapped <strong>to</strong> a subset of R 3 .<br />
<strong>The</strong> resulting figure is non-manifold. Indeed, even if the result of those two boolean<br />
operations is one only solid, it is impossible <strong>to</strong> define a proper genus <strong>to</strong> the surface that
2.4. TOPOLOGICAL REPRESENTATION 21<br />
bounds this solid. Slightly different parameters enables <strong>to</strong> generate either a surface with<br />
genus one or genus zero (see Figure 2.4).<br />
2.4.3 Non-manifold <strong>to</strong>pologies<br />
Here, we describe Weiler’s radial edge non manifold <strong>to</strong>pology data structure. This data<br />
structure is more or less the one that is used in solid modelers like OpenCascade or<br />
ACIS. Both those solid modelers have been interfaced in Gmsh’s abstract <strong>to</strong>pological data<br />
structure. <strong>The</strong> different entities that appear in such a <strong>to</strong>pology are described below. <strong>The</strong><br />
<strong>introduction</strong> of the notion of co-edge allow <strong>to</strong> represent non-manifold models.<br />
Body<br />
<strong>The</strong> body is the highest level of model object, which is composed of zero or more lumps.<br />
Lump<br />
A lump is a set of connected points. It may consist of volumes, sheets, <strong>and</strong>/or wires. For<br />
a volume the lump includes not only the points on the boundary of the volume, but also<br />
the points in the interior of the volume. For sheets <strong>and</strong> wires there is no interior; so they<br />
consist strictly of the points on the boundary. Lumps are not necessary. You could design<br />
a <strong>to</strong>pological structure without them. <strong>The</strong>y are sometimes included in the <strong>to</strong>pological<br />
structure for efficiency.<br />
Shell<br />
A shell is a connected set of boundary elements. For sheet bodies <strong>and</strong> wire bodies, there<br />
is a one-<strong>to</strong>-one correspondence between lumps <strong>and</strong> shells. In other words, a sheet body or<br />
wire body with a single lump will have a single shell. For solid bodies, there can be more<br />
than one shell per lump, when there is an interior void in the volume.<br />
Face<br />
A face defines a bounded region on a surface. A face may be a sheet face, in which case<br />
it is exterior <strong>to</strong> all solid regions, or a face may bound a solid region, in which case it<br />
separates the inside of the solid from the outside of the solid, or a face may be embedded<br />
inside a solid region. A face may be bounded by 0, 1, or more loops of edges. Usually if<br />
a face has multiple loops, it has holes in it, although a loop may degenerate <strong>to</strong> a single<br />
point, in which case the hole is infinitesimally small. A common example of a face with<br />
two loops, one of which that has degenerated <strong>to</strong> a single point is a conical face (or any<br />
surface of revolution that contains a point on the revolution axis), where the degenerate<br />
loop is at the apex of the cone.
22 CHAPTER 2. SOLID MODELS<br />
Loop<br />
A loop consists of one or more co-edges <strong>and</strong> is used <strong>to</strong> bound a face. A loop of coedges<br />
separates the region that is inside the face from the region that is outside the face. <strong>The</strong><br />
direction of a loop of coedges is counter clockwise with respect <strong>to</strong> an outward pointing face<br />
normal. Multiple loops are required on a face if there are holes in the face, in a similar<br />
way as lumps may have multiple shells. Loops are closed, having no actual start or end<br />
point.<br />
Wire<br />
A wire is a set of connected free edges i.e. that do not bound faces. Wires may contain one<br />
or more edges, be open or closed, have branches, <strong>and</strong> have multiple circuits. In addition,<br />
a wire may be either outside or inside a volume. If the wire is inside a volume, it can be<br />
interpreted as a 1D inclusion in the volume. A wire cannot be both inside <strong>and</strong> outside a<br />
volume.<br />
Coedge<br />
Coedges represent the use of an edge by upper <strong>to</strong>pology. <strong>The</strong> <strong>introduction</strong> of coedges<br />
allow <strong>to</strong> represent regions that are non-manifold along an edge. If an edge is used by a<br />
wire, then the edge will have a single coedge. If an edge is used by one or more faces, it<br />
will have a coedge for each use by each face. Indeed, an edge can be used twice by a face,<br />
when the face is on both sides of the edge. <strong>The</strong>re are three terms for edges that are used<br />
twice by a face<br />
• A spur edge is an edge that is not closed <strong>and</strong> it does not connect <strong>to</strong> another edge on<br />
one or both ends. In other words, on one or both ends it has a free vertex or a spur<br />
vertex. Spur edges can also exist in wires.<br />
• A prop edge is an edge that is not closed that is used twice by a face <strong>and</strong> is not a<br />
spur edge. It has adjacent edges at both ends. <strong>The</strong> exception <strong>to</strong> this if one or both<br />
of the vertices lie at singularities. A spur edge may have a vertex at which there<br />
are no adjacent edges if the vertex lies at a surface singularity. Prop edges <strong>and</strong> spur<br />
edges are mutually exclusive.<br />
• A seam edge is a special case of a prop edge. If a prop edge runs along the parametric<br />
boundary of a periodic surface (that is, it splits the face along parametric boundary<br />
of a periodic surface), then it may be called a seam edge.<br />
In general, spur, prop <strong>and</strong> seam edges are optional for the <strong>to</strong>pology of a face <strong>and</strong> may be<br />
removed by merging.
2.4. TOPOLOGICAL REPRESENTATION 23<br />
Edge<br />
G 1 1<br />
G 0 3<br />
G 0 2<br />
G 1 5<br />
G 1 2<br />
G 1 4<br />
G 0 5<br />
G 2 1<br />
Figure 2.5: A simple 2D model.<br />
<strong>An</strong> edge is either part of a wire or used <strong>to</strong> bound a face. A single edge can bound many<br />
faces. <strong>The</strong> faces bounded by an edge are obtained from the coedges of the edge. Each<br />
coedge represents the use of an edge by a face (or a wire). <strong>An</strong> edge has a direction: it<br />
has a start <strong>and</strong> an end vertex. <strong>The</strong>se may be the same vertex. In addition <strong>to</strong> spur, prop,<br />
<strong>and</strong> seam edges, there are a few more terms related <strong>to</strong> edges. Edges can be categorized<br />
according <strong>to</strong> their closure. For instance, if an edge has two distinct vertices, then the edge<br />
is open. If the edge start <strong>and</strong> end vertices of an edge are the same, the edge is closed. If<br />
the edge is closed <strong>and</strong> underlying curve’s start <strong>and</strong> end tangent directions are the same,<br />
then the edge is periodic. <strong>An</strong>other special type of edge is one with zero length. Such an<br />
edge is considered <strong>to</strong> be a degenerate edge. If a degenerated edge resides in the middle of<br />
a face, it is an isolated vertex.<br />
Vertex<br />
A boundary of an edge. A Vertex corresponds <strong>to</strong> a point in 3D space.<br />
As an illustration, let us look at the 2D model presented in Figure 2.5. This model<br />
has 1 face, 5 edges <strong>and</strong> 5 vertices. It has 2 loops <strong>and</strong> every edge has only one use (i.e. one<br />
co-edge).<br />
Model edge G 1 1 ’s boundary, ∂G1 1<br />
consist in two signed vertices:<br />
∂G 1 1 = −G 0 2 + G 0 3<br />
which means that model edge G 1 1 goes from model vertex G0 2 <strong>to</strong> model vertex G0 3 .<br />
G 0 4<br />
G 1 3<br />
G 0 1
24 CHAPTER 2. SOLID MODELS<br />
Model face G2 1 ’s boundary consist in two closed edge loops that consist of respectively<br />
four <strong>and</strong> one signed model edges:<br />
(2.1) ∂G 2 1 = {−G 1 1 + G 1 4 + G 1 3 − G 1 2, G 5 1}.<br />
Model edge G 1 5<br />
is periodic:<br />
∂G 5 1 = G 0 5 − G 0 5 = 0<br />
which makes perfect sense: the boundary of a closed curve is zero. For being consistent,<br />
the boundary of a closed edge loop has also <strong>to</strong> be zero. In other words,<br />
∂∂G 2 1 = {−∂G 1 1 + ∂G 1 2 + ∂G 1 3 − ∂G 1 4, ∂G 5 1}<br />
= {−(G 0 3 − G 2 0) + (G 0 4 − G 2 3) + (G 0 4 − G 2 1) − (G 0 1 − G 2 2), G 0 5 − G 0 5}<br />
= {0, 0}.<br />
Vertices that bound model curves of a model face have <strong>to</strong> appear once positively <strong>and</strong> once<br />
negatively. Two things have <strong>to</strong> be noted. First, ∂G0 i = i.e. the boundary of a model<br />
vertex is zero. <strong>The</strong>n, changing the sign of the boundary representation of a model face<br />
(2.2) − ∂G 2 1 = −{−G 1 1 + G 1 4 + G 1 3 − G 1 2, G 5 1}.<br />
gives the same <strong>to</strong>pological model face, yet with a different sign i.e. a different orientation.<br />
<strong>The</strong>n, a model region can also be described using its boundary representation. For<br />
example the cube of Figure 2.6 with one model region G3 1 consist in one closed face loop<br />
∂G 3 1 = {G 2 1 + G 2 2 + G 2 3 + G 2 4 + G 2 5 + G 2 6 + G 2 7 + G 2 8}<br />
with model face orientations that have <strong>to</strong> verify<br />
∂∂G 3 1 = 0.<br />
Let us now consider the cylindrical rod of Figure 2.7. <strong>The</strong> model region G 3 1 is<br />
bounded by three model faces<br />
Model faces G 2 1 <strong>and</strong> G2 2<br />
∂G 3 1 = G 2 1 + G 2 2 + G 2 3.<br />
are usual model faces composed of one only closed edge loop:<br />
∂G 2 1 = G 1 1 <strong>and</strong> ∂G 2 2 = −G 1 3.<br />
Model face G2 3 is different. It is a periodic model face <strong>and</strong> it has no interior holes. In order<br />
<strong>to</strong> be consistent with the boundary representation, its boundary representation should be<br />
one single closed loop. In order <strong>to</strong> achieve that goal, one seam edge, G1 1 , has <strong>to</strong> be added<br />
in the model. This seam edge acts like G0 4 which is both the starting point <strong>and</strong> the ending<br />
. We have then<br />
point of G 1 3<br />
∂G 2 3 = G 1 1 + G 1 3 − G 1 1 − G 1 2.
2.4. TOPOLOGICAL REPRESENTATION 25<br />
G 0 1<br />
G 2 3<br />
G 1 8<br />
G 0 3<br />
G 1 9<br />
G 0 5<br />
G 1 6<br />
G 1 11<br />
G 1 7<br />
G 1 10<br />
G 0 7<br />
G 2 2<br />
G 0 2<br />
G 1 1<br />
G 1 12<br />
G 1 5<br />
G 1 2<br />
G 0 4<br />
Figure 2.6: A cube.<br />
<strong>The</strong> seam model edge G1 1 appears twice in the same face loop <strong>and</strong> effectively acts as a<br />
seam that closes the periodic model face.<br />
Figure 2.8, which shows one of the 76 model faces of the propeller in the parametric<br />
space (left) <strong>and</strong> in real space (right). Three features of surface S, common in CAD<br />
descriptions, make its meshing non-trivial:<br />
1. S is periodic. <strong>The</strong> <strong>to</strong>pology of the model face is modified in order <strong>to</strong> define its closure<br />
properly. A seam is present two times in the closure of the model face. <strong>The</strong>se two<br />
occurrences are separated by one period in the parametric space.<br />
2. S is trimmed: it contains four holes <strong>and</strong> one of them is crossed by the seam.<br />
3. One of the model edges of S is degenerated. This is done for accounting of a singular<br />
point in the parametrization of the surface. This kind of degeneracy is present in<br />
many shapes: spheres, cones <strong>and</strong> other surfaces of revolution.<br />
2.4.4 Internal representation of solid models in Gmsh<br />
Gmsh never had the ambition of becoming a solid modeling platform that competes with<br />
the few well-established, state of the art CAD engines [?, ?, ?, ?]. <strong>The</strong> native Gmsh CAD<br />
engine thus has only a limited set of features, well suited for dealing with simple academic<br />
geometries. Yet, over the years, Gmsh has been used by an increasing number of people<br />
in industry, <strong>and</strong> a strong dem<strong>and</strong> emerged from this user community for Gmsh <strong>to</strong> be able<br />
mesh industrial CAD models.<br />
G 1 4<br />
G 0 6<br />
G 1 3<br />
G 0 8<br />
G 2 1
26 CHAPTER 2. SOLID MODELS<br />
G 1 3<br />
G 1 2<br />
G 2 1<br />
G 2 2<br />
G 0 4<br />
G 1 1<br />
G 0 5<br />
G 2 3<br />
Figure 2.7: A cylindrical rod.<br />
One option for addressing this dem<strong>and</strong> is <strong>to</strong> use exchange files, such as IGES (Initial<br />
Graphics Exchange Specification), VRML (Virtual Reality Markup Language) or STEP<br />
(ST<strong>and</strong>ard for the Exchange of Product model data). However, the use of such exchange<br />
file formats has always been a cause of trouble in engineering design offices, mainly because<br />
internal data structures of CAD systems are usually much richer than those in the exchange<br />
formats.<br />
Those differences between modelers can be very subtle. Consider for example skinning<br />
<strong>and</strong> lofting. Those two techniques enable <strong>to</strong> create a model entity (surface or volume)<br />
using curve constraints which the surface passes through. Skinning <strong>and</strong> lofting are actually<br />
the same technique in Open CASCADE that does not make a difference between them.<br />
ACIS kernel does make a little difference, in terms of types of the inputs parameters <strong>and</strong><br />
way of constraints definition. Even though differences are small, a translation between<br />
ACIS <strong>and</strong> Open CASCADE will generate modelling errors.<br />
<strong>An</strong>other issue is the importance of modeler <strong>to</strong>lerances that are not taken in<strong>to</strong> account<br />
in exchange files. Translations always lead <strong>to</strong> the time-consuming need <strong>to</strong> “fix” most of<br />
these exchange files before any meshing can be performed.<br />
In Gmsh, we thus chose <strong>to</strong> deal with CAD engines differently, by providing native<br />
access <strong>to</strong> the underlying CAD models—without translation files (a similar approach is<br />
used in CAPRI [?]). For that, the geometry module is based on a set of abstract data<br />
structures that enables us <strong>to</strong> represent the <strong>to</strong>pology of virtually any solid model.
2.4. TOPOLOGICAL REPRESENTATION 27<br />
Figure 2.8: Geometry of a model face in parametric space (left) <strong>and</strong> in real space (right).<br />
Two seam edges are present in the face. <strong>The</strong> <strong>to</strong>p model edge is degenerated in one point.<br />
CAD systems are able <strong>to</strong> represent industrial geometries within the fabrication <strong>to</strong>lerance.<br />
Companies that are in the business have been largely consolidated recently: there<br />
exist a limited number of big players in the CAD modeler market: CATIA (Dassault<br />
Systèmes), Pro EngineerTM (Parametric Technology Corporation), NX (Siemens), Au<strong>to</strong>CAD<br />
or SolidWorks. Some smaller players exist such as Cobalt, MasterCAM, Top-<br />
Solid, IronCAD or MicroStation that provide “niche” solutions. A lot of those software<br />
share the same modelling kernel. Professional modelling kernels are even fewer.<br />
CATIA <strong>and</strong> ProEngineerTM have their own, SolidWorks, NX, MasterCAM, TopSolid<br />
<strong>and</strong> MicroStation use Parasolid (Siemens), IronCADTM <strong>and</strong> Cobalt use ACIS (Dassault<br />
Systèmes). <strong>The</strong>re is only one open source modelling kernel: Open CASCADE<br />
(http://www.opencascade.org/). Open CASCADE is the modelling kernel of SALOME<br />
(http://www.salome-platform.org/) that is itself open source under LGPL. Open CAS-<br />
CADE is also the modelling kernel used in SAMCEF Field.<br />
We have seen that 3-D models can be defined using a Boundary Representation. In<br />
Gmsh, only four kinds of model entities are defined:<br />
1. Model Vertices G 0 i<br />
2. Model Edges G 1 i<br />
3. Model Faces G 2 i<br />
4. Model Regions G 3 i<br />
that are <strong>to</strong>pological entities of dimension 0,<br />
that are <strong>to</strong>pological entities of dimension 1,<br />
that are <strong>to</strong>pological entities of dimension 2,<br />
that are <strong>to</strong>pological entities of dimension 3.<br />
Those 4 entities are the only ones that are common <strong>to</strong> every modelling kernel that we<br />
found. In fact, those are the only ones that have an associated geometry. Model entities<br />
are <strong>to</strong>pological entities, i.e., they only deal with adjacencies in the model, <strong>and</strong> we use a
28 CHAPTER 2. SOLID MODELS<br />
bi-directional data structure [?] for representing the graph of adjacencies. In this representation,<br />
a model entity Gd i of dimension d holds one lists of upward adjacencies Gd+1<br />
j (Gd i ),<br />
i.e., all its adjacent entities of dimension d + 1, <strong>and</strong> one list of downward adjacencies of<br />
). Schematically, we have<br />
dimension d − 1, G d−1<br />
j<br />
(G d i<br />
G 0 i ⇋ G 1 i ⇋ G 2 i ⇋ G 3 i .<br />
This representation is said <strong>to</strong> be complete because any model entity is able <strong>to</strong> build its<br />
list of adjacencies of any dimension using local operations, i.e., without having <strong>to</strong> do a<br />
complete traversal of the adjacency graph of the model.<br />
Each model entity G d i<br />
has a shape, a geometry. More precisely, it is a manifold of<br />
dimension d that is embedded in 3-D space. (Note that the overall geometric model may<br />
itself be non-manifold: Gmsh supports non-manifold features).<br />
<strong>The</strong> geometry of a model entity depends on the solid modeler kernel for its underlying<br />
representation. Solid modelers provide a parametrization of the shapes, i.e., a mapping<br />
x ∈ R d ↦→ p ∈ R 3 :<br />
1. <strong>The</strong> geometry of a model vertex G 0 i is simply its 3-D location xi = (xi, yi, zi).<br />
2. <strong>The</strong> geometry of a model edge G 1 i is its underlying curve Ci with its parametrization<br />
p(t) ∈ Ci, t ∈ [t1, t2].<br />
3. <strong>The</strong> geometry of a model face G 2 i is its underlying surface Si with its parametrization<br />
p(u, v) ∈ Si. Note that, for any curve Cj that is on a surface Si, mesh generation<br />
procedures require the ability <strong>to</strong> reparametrize any point p(t) ∈ Cj on the surface<br />
Si, i.e., <strong>to</strong> compute the mapping u = u(t) <strong>and</strong> v = v(t). Gmsh either uses a brute<br />
force algorithm <strong>to</strong> compute the direct mapping x = x(t), y = y(t) <strong>and</strong> z = z(t) <strong>and</strong><br />
its inverse u = u(x, y, z) <strong>and</strong> v = v(x, y, z) (see Figure 2.9), or, when the underlying<br />
CAD system provides it, the direct reparametrization of a point on a model face<br />
(i.e., a function that directly computes u = u(t) <strong>and</strong> v = v(t)).<br />
4. <strong>The</strong> geometry associated <strong>to</strong> a model region is R 3 .<br />
Solid modelers usually provide an API for the creation, manipulation, interrogation<br />
<strong>and</strong> s<strong>to</strong>rage of 3-D models. To perform mesh generation only a small subset of this API has<br />
<strong>to</strong> be interfaced—only some of the interrogation functions are necessary. In order <strong>to</strong> get<br />
the full functionality of Gmsh, only five CAD-system dependent interrogation functions<br />
have <strong>to</strong> be implemented for the model edge (see Figure 2.10). For example, it is m<strong>and</strong>a<strong>to</strong>ry<br />
<strong>to</strong> be able <strong>to</strong> evaluate the mapping p(t) ∈ C on the curve as well as the tangent vec<strong>to</strong>r<br />
t(t) = ∂tp(t). For the model face, only four functions have <strong>to</strong> be overloaded in order<br />
<strong>to</strong> enable 2-D mesh generation (see Figure 2.11). Note that the default 2-D algorithm<br />
does not require the computation of derivatives of the surface parametrization, so that the<br />
function modelFace::tangent is not strictly required (a description of this 2-D algorithm<br />
is presented in Section ??). <strong>The</strong> other 2-D algorithms available in Gmsh, as well as most
2.4. TOPOLOGICAL REPRESENTATION 29<br />
v<br />
S ′<br />
z<br />
C C<br />
u = u(x)<br />
p(u) v = v(x)<br />
u<br />
u = u(t), v = v(t)<br />
t1<br />
y<br />
t2<br />
x<br />
S<br />
t<br />
p(x)<br />
x = x(t), y = y(t), z = z(t)<br />
Figure 2.9: Point p located on the curve C that is itself embedded in a 2D surface S ′ (left)<br />
or a 3D surface S (right).<br />
p(t)<br />
class modelEdge : public modelEntity{<br />
// bi-directional data structure<br />
modelVertex *v1, *v2;<br />
std::list faces;<br />
public:<br />
// pure virtual functions that have <strong>to</strong> be overloaded<br />
// for every solid modeler<br />
virtual std::pair parRange() = 0;<br />
virtual Point3 value(double t) = 0;<br />
virtual Vec<strong>to</strong>r3 tangent(double t) = 0;<br />
virtual Point2 reparam(modelFace *mf, double t, int dir) = 0;<br />
virtual bool isSeam(modelFace *mf) = 0;<br />
// other functions of the class are non pure virtual<br />
// ...<br />
};<br />
Figure 2.10: A part of the model edge class description. modelEdge::parRange returns the<br />
range for the parameter in the curve. modelEdge::value returns the 3-D point p(t) that is<br />
located on the curve C for a given parameter t. modelEdge::tangent evaluates the tangent<br />
vec<strong>to</strong>r ∂tp(t) for a given parameter t. modelEdge::reparam computes the local parameters<br />
of the point p(t) on a model face mf that has C in its closure, modelEdge::isSeam tells if<br />
the curve is or is not a seam of the face mf. Generally, seam edges are used <strong>to</strong> maintain<br />
consistency of data structure for periodic surfaces.<br />
C
30 CHAPTER 2. SOLID MODELS<br />
class modelFace : public modelEntity{<br />
// bi-directional data structure<br />
modelRegion *r1, *r2;<br />
std::list edges;<br />
public:<br />
// pure virtual functions that have <strong>to</strong> be overloaded<br />
// for every solid modeler<br />
virtual std::pair parRange(int dir) const = 0;<br />
virtual Point3 value(double u, double v) const = 0;<br />
virtual std::pair tangent( double u, double v) const = 0;<br />
virtual double curvature(double u, double v) const;<br />
// other functions of the class are non pure virtual<br />
// ...<br />
};<br />
Figure 2.11: A part of the model face class description. modelFace::parRange returns<br />
the range for the parameter in the surface in direction dir. modelFace::value returns<br />
the 3-D point p(u, v) that is located on the surface S for the given parameter couple<br />
(u, v). modelFace::tangent the evaluates two tangent vec<strong>to</strong>rs ∂up(u, v) <strong>and</strong> ∂vp(u, v).<br />
<strong>The</strong> modelFace::curvature function computes the divergence of the unit normal vec<strong>to</strong>r<br />
at (u, v). This last function is used for the definition of mesh size fields. It is not a pure<br />
virtual function: a default implementation is available using finite differences.
2.5. GEOMETRICAL REPRESENTATION 31<br />
of the available 2-D meshers (e.g. bamg [?] or blsurf [?]), make use of derivatives of the<br />
parametrization.<br />
To date, Gmsh is interfaced with Open CASCADE <strong>and</strong> ACIS. It also contains a<br />
naive solid modeler kernel that do not provide boolean operations.<br />
2.5 <strong>Geometrical</strong> Representation<br />
Each model entity Gd i has a shape, a geometry. More precisely, it is a manifold of dimension<br />
d that is embedded in 3-D space.<br />
Solid modelers usually provide a parametrization of the shapes, i.e., a mapping<br />
x ∈ R d ↦→ x ∈ R 3 . <strong>The</strong> geometry of a model vertex G 0 i is simply its 3-D location<br />
x = (x1, x2, x3).<br />
<strong>The</strong> geometry of a model edge G 1 i is its underlying curve Ci with its parametrization<br />
(2.3) t ∈ [t1, t2] ↦→ x(t) ∈ R 3 .<br />
<strong>The</strong> geometry of a model face G 2 i is its underlying surface Si with its parametrization<br />
(u, v) ∈ R 2 ↦→ x(u, v) ∈ R 3 .<br />
<strong>The</strong> geometry associated <strong>to</strong> a model region is R 3 .<br />
If a curve is included within a surface, it is usually drawn on the parameter plane<br />
(u, v) of the surface:<br />
(2.4) t ∈ [t1, t2] ↦→ (u, v) ∈ R 2 ↦→ x (u(t), v(t)) ∈ R 3 .<br />
2.5.1 Differential Geometry of Curves<br />
A parameterization of a curve is a bijective mapping from a 1D domain <strong>to</strong> the 3D curve.<br />
<strong>The</strong> mapping can be defined as follows:<br />
(2.5) t ∈ R 1 ↦→ x(t) ∈ R 3 .<br />
Consider a segment of curve C defined by a range of parameter t ∈ [ta, tb], ta ≥ t1, tb ≤ t2.<br />
<strong>The</strong> length of that segment can be computed as<br />
<br />
dl<br />
with dl = dx2 1 + dx22 + dx23 . Using C’s parametrization (2.3), we have<br />
<br />
dx2 1 + dx22 + dx23 =<br />
tb <br />
x2 1,t + x22,t + x23,t dt<br />
C<br />
C<br />
=<br />
ta<br />
tb<br />
x,t dt<br />
ta
32 CHAPTER 2. SOLID MODELS<br />
This can be easily extended <strong>to</strong> the computation of integral quantities over model edges:<br />
(2.6)<br />
<br />
C<br />
f(x1, x2, x3)dl =<br />
tb<br />
f(x1(t), x2(t), x3(t)) x,t dt<br />
ta<br />
<strong>The</strong> curvilinear abscissa l(t) of a point x(t) of curve C, is the length of the segment<br />
defined by parameter range [t1, t], i.e. the length of the curve from the origin x(t1) <strong>to</strong> x(t):<br />
(2.7)<br />
t<br />
l(t) =<br />
We have seen before that dl = x,t dt.<br />
t1<br />
x,t dt<br />
A parametrization of C is said <strong>to</strong> be regular if x,t = 0. For regular parametrizations,<br />
the unit tangent vec<strong>to</strong>r is defined as<br />
t(t) = x,t dx<br />
=<br />
x,t dl .<br />
<strong>The</strong> normal plane at point x(t) is the plane that contains x(t) <strong>and</strong> that has t(t) as normal<br />
vec<strong>to</strong>r (see Figure 2.12). <strong>The</strong> curvature of the curve at a point x can be defined as the<br />
amplitude of the variations of the unit tangent t along the curve. <strong>The</strong> vec<strong>to</strong>r t,l is obviously<br />
orthogonal <strong>to</strong> t because t’s amplitude is one along l. Recalling that<br />
we have<br />
t,l =<br />
=<br />
=<br />
1<br />
d 1<br />
dt x = −x,t · x<br />
x 3<br />
x,t t,t<br />
<br />
1 x,tt x,t · x,tt<br />
− x,t<br />
x,t x,t x,t3 <br />
1<br />
x,t 3<br />
<br />
x,tt x,t − x,t<br />
x,t · x,tt<br />
x,t<br />
Clearly, t,l · t = 0. Because we have defined the curvature as the amplitude of the<br />
variations of the unit tangent t along the curve, we call rewrite<br />
t,l = t,l t,l<br />
= Cn<br />
t,l<br />
with n a unit normal vec<strong>to</strong>r orthogonal <strong>to</strong> t <strong>and</strong> C the curvature that is the norm of tl.<br />
Remembering that<br />
a × b 2 = a 2 b 2 sin 2 (a, b) = a 2 b 2<br />
<br />
(a · b)2<br />
1 −<br />
a2b2 <br />
= a 2 b 2 − (a · b) 2 ,<br />
<br />
.
2.5. GEOMETRICAL REPRESENTATION 33<br />
t1<br />
it is easy <strong>to</strong> see that<br />
<strong>and</strong> we get the formula<br />
t<br />
t2<br />
x1<br />
x(t)<br />
x3<br />
1/C<br />
n(t)<br />
x2<br />
t(t)<br />
Figure 2.12: A curve C defined by the mapping x(t).<br />
C 2 = 1<br />
x,t 6<br />
<br />
x,t 2 x,tt 2 − (x,tt · x,t) 2 = 1<br />
x,t 6 xt × x,tt 2<br />
(2.8) C = xt × x,tt<br />
x,t 3 .<br />
Consider the function y = f(x) in the (x, y) plane. Its parametric representation is x(t) = t<br />
<strong>and</strong> y(t) = f(t) or x(t) = {}. <strong>The</strong> tangent vec<strong>to</strong>r is x,t = {1, f ′ (t)} <strong>and</strong> x,tt = {0, f ′′ (t)}.<br />
We have therefore the classical formula<br />
(2.9) C =<br />
|f ′′ (t)|<br />
(1 + f ′ (t) 2 .<br />
) 3/2<br />
It is possible <strong>to</strong> define a local system of coordinates at any point x of the curve<br />
(t, n, b)<br />
with b = t × n. This system of coordinates is usually called the Frenet frame. <strong>The</strong><br />
osculating plane of the curve at point x can be defined as the plane containing x <strong>and</strong><br />
normal <strong>to</strong> b. <strong>The</strong> curvature C(t) is the inverse of the radius of the osculating circle at<br />
point x i.e. the circle which most closely approximates the curve near x:<br />
R(t) = 1<br />
C(t) .<br />
This gives an interesting intuitive interpretation of the curvature.<br />
C
34 CHAPTER 2. SOLID MODELS<br />
v<br />
S ′<br />
u<br />
x(u, v)<br />
x1<br />
x3<br />
x,u × x,v<br />
x,v<br />
Figure 2.13: A surface S defined by the mapping x(u, v).<br />
2.5.2 Differential Geometry of Surfaces<br />
A parameterization of a surface is a bijective mapping from a suitable two-dimensional<br />
domain S ′ <strong>to</strong> the 3D surface S (see Figure 2.13). In CAD modelers, surfaces have explicit<br />
parametrizations i.e. their parametrization is given explicitly as a continuous <strong>and</strong><br />
differentiable function:<br />
(2.10) (u, v) ∈ S ′ ⊂ R 2 ↦→ x(u, v) ∈ S ⊂ R 3 .<br />
Such a parametrization exists if the two surfaces S <strong>and</strong> S ′ have the same <strong>to</strong>pology, i.e are<br />
both zero genus surfaces (G = 0) <strong>and</strong> have at least one boundary (NB ≥ 1) 1 .<br />
Given the parametrization x(u), let us compute fundamental properties of surfaces<br />
such as lengths, angles, areas <strong>and</strong> curvatures. Consider a curve that is included in surface<br />
S. It is easy <strong>to</strong> extend the integration formula (2.6) as:<br />
(2.11)<br />
<br />
C<br />
f(x, y, z) dx 2 + dy 2 + dz 2<br />
=<br />
=<br />
=<br />
<br />
<br />
<br />
C<br />
C<br />
C<br />
<br />
f(x, y, z) x,u 2 du2 + 2 x,u · x,vdu dv + x,v 2 dv2 <br />
<br />
du<br />
f(x, y, z)<br />
dv<br />
<br />
f(x, y, z) du T M du.<br />
S<br />
θ<br />
x2<br />
T x,u · x,u x,u · x,v<br />
x,v · x,u x,v · x,v<br />
x,u<br />
du<br />
dv<br />
1 For example, a sphere has G = 0 <strong>and</strong> NB = 0 <strong>and</strong> a <strong>to</strong>rus has G = 1 <strong>and</strong> NB = 0.
2.5. GEOMETRICAL REPRESENTATION 35<br />
In (2.12), the matrix M is called the metric tensor or first fundamental form.<br />
defined as follows:<br />
It is<br />
(2.12) M = x T <br />
x,u · x,u<br />
,ux,u =<br />
x,v · x,u<br />
x,u · x,v<br />
x,v · x,v<br />
<br />
E<br />
=<br />
F<br />
<br />
F<br />
G<br />
<strong>The</strong> metric tensor is a symmetric definite positive second order tensor that varies smoothly<br />
over the manifold <strong>and</strong> that has two real eigenvalues.<br />
We have just seen that the tensor metric enables <strong>to</strong> measure curve lengths drawn<br />
in the parametric plane. It also allows <strong>to</strong> generalizes many familiar properties of the<br />
dot product of vec<strong>to</strong>rs in Euclidean space. In particular, it allows <strong>to</strong> compute the angle<br />
between two tangent vec<strong>to</strong>rs <strong>to</strong> the surface as well as areas. <strong>An</strong>y tangent vec<strong>to</strong>r at a point<br />
of the parametric surface can be written in the form<br />
t = ax,u + bx,v<br />
with a, b ∈ R. Let us consider two tangent vec<strong>to</strong>rs<br />
t1 = a1x,u + b1x,v <strong>and</strong> t2 = a2x,u + b2x,v.<br />
Coordinates a = (a1, a2) <strong>and</strong> b = (b1, b2) are called covariant coordinates of t1 <strong>and</strong> t2.<br />
We have<br />
t1 · t2 = a1a2x,u · x,u + (a1b2 + a2b1)x,u · x,v + b1b2x,v · x,v = a T Mb,<br />
which gives us the angle θ between the two tangent vec<strong>to</strong>rs (see Fig.2.13):<br />
<br />
aT Mb<br />
(2.13) θ = arccos<br />
Consider a small rectangle du dv at a point on the parametric plane. Its area on the 3D<br />
surface is given by:<br />
t1t2<br />
(2.14) s = x,udu × x,vdv = du dv √ det M.<br />
Note again that the value of the area only depends on the tensor metric M.<br />
<strong>The</strong> last important fundamental quantity related <strong>to</strong> the shape of surfaces is the<br />
curvature. Let us first define the unit surface normal n that is orthogonal <strong>to</strong> both tangent<br />
vec<strong>to</strong>rs:<br />
(2.15) n = x,u × x,v<br />
x,u × x,v = x,u × x,v<br />
√ det M = x,u × x,v<br />
√ EG − F 2 .<br />
<strong>The</strong> three vec<strong>to</strong>rs (x,u, x,v, n) form at each point of the surface a local system of coordinates<br />
usually called the local frame. It is easy <strong>to</strong> orthonormalize the local frame, i.e. by choosing<br />
t1 = x,u<br />
x,u , t2 = n × t1
36 CHAPTER 2. SOLID MODELS<br />
so that vec<strong>to</strong>rs (t1, t2, n) form an orthonormal system of coordinates usually called the<br />
Darboux frame. To study the curvature of the surface at a point x, one can examine the<br />
variations of the unit normal n around x. In particular, one can derivate n in the direction<br />
specified by the tangent vec<strong>to</strong>rs at x: this is called the Weingarten map. Note that n,u<br />
<strong>and</strong> n,v are both tangent vec<strong>to</strong>rs because n is a unit vec<strong>to</strong>r:<br />
∂ v<br />
∂u v<br />
v,u v<br />
= − (v · v,u)<br />
v v3 Applying that formula <strong>to</strong> Equation (2.15) (an after tedious calculations), we obtain the<br />
Weingarten equations that express the derivatives of the normal <strong>to</strong> a surface using derivatives<br />
of the position vec<strong>to</strong>r x<br />
n,u =<br />
n,v =<br />
MF − LG<br />
EG − F 2 x,u +<br />
NF − MG<br />
EG − F 2 x,u +<br />
where the scalars e, f <strong>and</strong> g are defined as:<br />
LF − ME<br />
x,v<br />
EG − F 2<br />
MF − NE<br />
x,v<br />
EG − F 2<br />
L = n · x,uu, M = n · x,uv <strong>and</strong> N = n · x,vv.<br />
Those scalars define the curvature tensor or second fundamental tensor of the surface<br />
denoted M2:<br />
(2.16) M2 =<br />
L M<br />
M N<br />
<strong>The</strong> curvature tensor is a tensor, <strong>and</strong> like for any tensor, some invariants can be defined<br />
that are independent of the system of coordinates. In other words, invariants are intrinsic<br />
measures of the curvature, i.e., their value depends only on how distances are measured on<br />
the surface, not on the way it is embedded in space. <strong>The</strong> principal curvatures κ1 <strong>and</strong> κ2<br />
are the two eigenvalues of M2. <strong>The</strong>y are the largest <strong>and</strong> smallest values of the curvature<br />
at a point. <strong>The</strong> mean curvature ¯κ = κ1 + κ2 is proportional <strong>to</strong> the trace of the curvature<br />
tensor <strong>and</strong> ¯κ is therefore an invariant of the tensor. It is easy <strong>to</strong> see that<br />
(2.17) ¯κ = ∇ · n = 1<br />
2 trace<br />
<br />
M2<br />
=<br />
M<br />
LG − 2MF + NE<br />
<br />
2 (EG − F 2 .<br />
)<br />
<strong>The</strong> Gaussian curvature κ of a point on a surface is the square root of the product of the<br />
principal curvatures, κ1 <strong>and</strong> κ2, of the given point. Its value can be computed as<br />
(2.18) κ =<br />
det M2<br />
det M<br />
LN − M2<br />
= .<br />
EG − F 2
2.5. GEOMETRICAL REPRESENTATION 37<br />
2.5.3 Classifying the parametrizations<br />
By studying how the surface lengths, angles <strong>and</strong> areas vary during the mapping (<strong>and</strong><br />
hence how the metric tensor <strong>and</strong> associated eigenvalues vary) (2.10) we can classify the<br />
parametrizations (mappings) by looking at the eigenvalues λ1 <strong>and</strong> λ2 of the metric tensor<br />
M (2.12):<br />
• A mapping is called isometric or length-preserving if the length of any arc is preserved.<br />
Such a mapping is called an isometry <strong>and</strong> exist only in very special cases.<br />
For example, the mapping of a cylinder in<strong>to</strong> the plane that transforms cylindrical<br />
coordinates in<strong>to</strong> cartesian coordinates is isometric. <strong>The</strong> following relation holdq:<br />
1 0<br />
x(u) is isometric ⇐⇒ M = ⇐⇒ λ1 = λ2 = 1.<br />
0 1<br />
• A mapping is conformal or angle-preserving if the angle of intersection of every<br />
pair of intersecting curves is the same on the parametric plane <strong>and</strong> on the surface.<br />
For example, the stereographic <strong>and</strong> Merca<strong>to</strong>r projections are conformal maps from<br />
the sphere <strong>to</strong> the plane. <strong>The</strong>following relation holds:<br />
η 0<br />
x(u) is conformal ⇐⇒ M = ⇐⇒ λ1/λ2 = 1<br />
0 η<br />
• A mapping is equiareal if the areas are conserved by the mapping. For example,<br />
the Lambert projection is an equiareal mapping from the sphere <strong>to</strong> the plane. We<br />
have the relation:<br />
x(u) is equiareal ⇐⇒ det M = 1 ⇐⇒ λ1λ2 = 1.<br />
Isometric mappings are optimal because they introduce no dis<strong>to</strong>rsion. Every isometric<br />
mapping is conformal <strong>and</strong> equiareal, <strong>and</strong> every conformal <strong>and</strong> equiareal mapping<br />
is isometric, so that the following equivalence holds:<br />
isometric ⇐⇒ conformal + equiareal.<br />
We can thus view an isometric mapping as ideal, in the sense that it preserves just<br />
about everything we could ask for: angles, areas, <strong>and</strong> lengths. However, as is well known,<br />
isometric mappings only exist in very special cases of developable surfaces , i.e. surfaces<br />
with zero Gaussian curvature (planes, cylinders <strong>and</strong> cones). Many approaches <strong>to</strong> surface<br />
parameterization therefore attempt <strong>to</strong> find a mapping which either<br />
• is conformal, i.e., has no dis<strong>to</strong>rtion in angles, or<br />
• is equiareal, i.e., has no dis<strong>to</strong>rtion in areas, or<br />
• minimizes some combination of angle dis<strong>to</strong>rtion <strong>and</strong> area dis<strong>to</strong>rtion.
38 CHAPTER 2. SOLID MODELS<br />
2.5.4 Computing harmonic <strong>and</strong> conformal maps<br />
One possible mapping can be found by minimizing the area functional A(x) that is the<br />
area of the mapping x(u). This area functional can be computed by combining equations<br />
of the area (2.14) <strong>and</strong> the metric tensor (2.12):<br />
<br />
<br />
(2.19) A(x) = x,u × x,v dudv = EG − F 2dudv, S ′<br />
where E, D <strong>and</strong> G are the coefficients of the metric tensor M.<br />
As can be seen, this area functional is in general complicated <strong>to</strong> compute. A lof<br />
of approaches in numerical approximation of minimal surface do not minimize the area<br />
functional directly. Instead, they try <strong>to</strong> minimize the following functional called Dirichlet<br />
enery ED(x):<br />
(2.20) ED(x) = 1<br />
<br />
2 S ′<br />
∇x 2 dudv = 1<br />
<br />
2 S ′<br />
2<br />
x,u + x 2 <br />
1<br />
,v dudv =<br />
2 S ′<br />
(E + G) dudv<br />
<strong>The</strong> map that minimizes the Dirichlet energy is called a harmonic map since the variational<br />
derivative of the Dirichlet functional (Euler equation) corresponds <strong>to</strong> the Laplacian:<br />
(2.21) ∇ 2 x = x,uu + x,vv.<br />
One should note that since the mapping is a bijective function, the following Laplacian<br />
equation also minimizes the Dirichet energy:<br />
<br />
∇u 2 ds.<br />
(2.22) ∇ 2 1<br />
u = 0 ↔ min ED(u) = min<br />
u u 2<br />
<strong>The</strong> area functional A(x) <strong>and</strong> the Dirichlet energy ED(x) have the following relation:<br />
(2.23)<br />
<br />
A(x) =<br />
<br />
EG − F 2dudv ≤<br />
S ′<br />
√<br />
<br />
1<br />
EGdudv ≤<br />
2 S ′<br />
(E + G)dudv = ED(x)<br />
S ′<br />
It is simple <strong>to</strong> verify that the first inequality becomes an equality if F = 0, i.e. if x,u · x,v<br />
is zero everywhere, while the second does if E = G, i.e if x,u = x,v. It follows that<br />
the the minimum possible value of the Dirichlet energy is attained when there is no shape<br />
dis<strong>to</strong>rsion anywhere, the resulting mapping is then called conformal mapping since<br />
E 0<br />
the corresponding mesh metric is then given by : M = . If we only fix the<br />
0 E<br />
shape of the boundary of a parametric domain, but not the map from the boundary <strong>to</strong><br />
the surface, a conformal parameterization always exists for smooth surfaces <strong>and</strong> smooth<br />
domain boundaries. As the conformal mapping also minimizes the Dirichlet energy, we<br />
have the following implication for the mappings:<br />
S ′<br />
conformal =⇒ harmonic.<br />
S
2.5. GEOMETRICAL REPRESENTATION 39<br />
How far from conformality is the mapping u(x) that is the solution of the two<br />
Laplace equations (2.22) that minimize the Dirichlet energy ED(u)?<br />
∇ 2 u = 0 <strong>and</strong> ∇ 2 v = 0.<br />
It actually all depends on the boundary conditions of those equations. If we fix with<br />
appropriate Dirichlet boundary conditions the map u(x) on the boundary ∂S of the domain<br />
S <strong>to</strong> a fixed boundary in the parametric space (a circle, a squatre, etc.), full conformality<br />
may be impossible, but minimizing the Dirichlet energy will move us closer <strong>to</strong> a conformal<br />
map, i.e. will reduce the dis<strong>to</strong>rtion of shape. If on the other h<strong>and</strong>, we only fix the shape<br />
of the boundary of a parametric domain (any planar curve), but not the map from the<br />
boundary <strong>to</strong> the surface, a conformal parameterization always exists for smooth surfaces<br />
<strong>and</strong> smooth domain boundaries. However, fixing the shape will introduce a coupling<br />
between the u <strong>and</strong> the v mapping coordinates that is not straighforward <strong>to</strong> implement.<br />
It is therefore convenient <strong>to</strong> minimize another energy, the least square conformal<br />
energy ELSCM as defined by Levy et al. [?]:<br />
<br />
(2.24) ELSCM =<br />
S<br />
1<br />
2 ∇u⊥ − ∇v 2 ds,<br />
where ⊥ denotes a counterclockwise 90 ◦ rotation on S (on the plane defined by the two<br />
vec<strong>to</strong>rs ∇u = u,x <strong>and</strong> ∇v = v,x) (see fig.2.14). Minimizing this energy is then equivalent<br />
<strong>to</strong> asking that the gradient of u <strong>and</strong> the gradient of v be as orthogonal as possible in the<br />
parametrization, which is the necessary condition for a conformal (angle preserving) map.<br />
Equation (2.24) can be simplified <strong>and</strong> rewritten as follows:<br />
z y<br />
x<br />
∇v<br />
iso-v<br />
n<br />
S<br />
∇u<br />
iso-u<br />
∇u ⊥ = n × ∇u<br />
u(x)<br />
Figure 2.14: Definitions for a conformal mapping. ∇u ⊥ denotes the counterclockwise 90 ◦<br />
rotation of the gradient ∇u for a 3D surface.<br />
(2.25)<br />
<br />
ELSCM(u) =<br />
<br />
=<br />
S<br />
S<br />
iso-u<br />
S ′<br />
iso-v<br />
<br />
∇u ⊥ · ∇u ⊥ + ∇v · ∇v − 2∇u ⊥ <br />
· ∇v ds,<br />
1<br />
2<br />
1<br />
<br />
(∇u)<br />
2<br />
2 + (∇v) 2 <br />
− 2 (n × ∇u) · ∇v ds.
40 CHAPTER 2. SOLID MODELS<br />
Recalling the idenity that a a ”dot” <strong>and</strong> a ”cross” can be interchanged without changing<br />
the result, we can finally write the least square conformal energy as follows:<br />
(2.26)<br />
ELSCM(u) =<br />
<br />
S<br />
1<br />
<br />
(∇u)<br />
2<br />
2 + (∇v) 2<br />
− n · (∇u × ∇v) ds.<br />
= ED(u) − A(u).<br />
It follows from (2.26) that the conformal energy is then simply defined as the dirichlet<br />
functional ED(u) minus the area functional A(u).<br />
Figure 2.15 shows two examples of mappings u(x) of a 3D surface S. <strong>The</strong> <strong>to</strong>p figures<br />
shows the harmonic map that is computed by minimizing the Dirichlet energy ED(u) <strong>and</strong><br />
the bot<strong>to</strong>m figures show a conformal map that is obtained by minimizing the least square<br />
conformal energy ELSCM(u). <strong>The</strong> iso-u <strong>and</strong> iso-v values that are visible on the 3D surface<br />
show that the conformality is also almost achieved for the harmonic map except near the<br />
fixed boundaries.<br />
S S<br />
S<br />
u harm (x)<br />
u conf (x)<br />
iso-u<br />
iso-u<br />
iso-v<br />
S ′<br />
iso-v<br />
Figure 2.15: Example of harmonic (<strong>to</strong>p) <strong>and</strong> conformal map (bot<strong>to</strong>m) for the mapping<br />
of a surface S that have been computed respectively by minimizing the Dirichlet energy<br />
ED(u) <strong>and</strong> the least square conformal energy ELSCM(u). <strong>The</strong> iso-u <strong>and</strong> iso-v values are<br />
visible on the 3D surfaces <strong>and</strong> it can be shown that the conformality is almost achieved<br />
for the harmonic map except near the fixed boundaries.
2.5. GEOMETRICAL REPRESENTATION 41<br />
2.5.5 Examples of analytical parametrizations<br />
We have just shown how <strong>to</strong> compute parametrizations u(x) by minimizing some functionals.<br />
However, for some simple surfaces S such as cylinders <strong>and</strong> spheres, an analytical<br />
parametrization can be derived.<br />
Cylindrical coordinates<br />
A first simple example of such an analytical parameterization are cylindrical coordinates.<br />
Imagine an open cylinder (without bot<strong>to</strong>m <strong>and</strong> <strong>to</strong>p) being cut open along its side <strong>and</strong><br />
unrolled in the plane. This gives a rectangle <strong>and</strong> there exists a natural bijective mapping<br />
between the points in this rectangle <strong>and</strong> the points on the surface of the cylinder. This<br />
mapping is a parameterization of the cylinder surface <strong>and</strong> very h<strong>and</strong>y, because it allows us<br />
<strong>to</strong> capture the cylinder by using only two coordinates u = φ <strong>and</strong> v = h in the parameter<br />
domain instead of the three coordinates x, y, <strong>and</strong> z in space (see Fig.2.16). <strong>The</strong> mapping<br />
is given by:<br />
(2.27) x(φ, h) = (sin φ, cos φ, h)<br />
h<br />
S ′<br />
(φ, h)<br />
φ<br />
x(φ, h)<br />
Figure 2.16: Mapping with cylindrical coordinates.<br />
<strong>The</strong> metric tensor relative <strong>to</strong> that parametrization is then<br />
(2.28) M =<br />
1 0<br />
0 1<br />
This parametrization is isometric <strong>and</strong> hence equiareal <strong>and</strong> conformal.<br />
Spherical coordinates<br />
<br />
.<br />
S<br />
φ<br />
h<br />
(x, y, z)<br />
<strong>An</strong>other simple example is the parametrization of a sphere of radius R using spherical<br />
coordinates u = φ <strong>and</strong> v = η (see Fig.2.17). <strong>The</strong> mapping is given by:<br />
⎡ ⎤<br />
x<br />
⎡<br />
⎤<br />
R cos θ sin φ<br />
x(φ, η) = ⎣ y ⎦ = ⎣ R sin θ sin φ ⎦ .<br />
z R cos φ
42 CHAPTER 2. SOLID MODELS<br />
We have<br />
x1<br />
⎡<br />
x,φ = ⎣<br />
x1<br />
θ<br />
x2<br />
x3<br />
φ<br />
Figure 2.17: Spherical coordinates.<br />
R cos θ cos φ<br />
R sin θ cos φ<br />
−R sin φ<br />
⎤<br />
x3<br />
eφ<br />
er<br />
⎦ , x,θ = ⎣<br />
<strong>and</strong> the metric tensor relative <strong>to</strong> that parametrization is<br />
(2.29) M = R 2<br />
<br />
1 0<br />
0 sin2 φ<br />
⎡<br />
eθ<br />
x2<br />
−R sin θ sin φ<br />
R cos θ sin φ<br />
0<br />
This parametrization is neither isometric, neither equiareal, neither conformal.<br />
Stereographic projection<br />
A third well-known example is the stereographic projection (see an example in Fig.2.18).<br />
<strong>The</strong> mapping from the surface of the sphere S <strong>to</strong> the parameter domain can be constructed<br />
as follows. For any point x = (x, y, z) on the sphere, consider the ray that connects another<br />
point s on the sphere. <strong>The</strong> corresponding parameter point u is the intersection π(x) of<br />
that ray with a plane S ′ perpendicular <strong>to</strong> the z axis. <strong>The</strong> parametrization is then defined<br />
for every point on the sphere, except at the point s.<br />
In Fig. 2.18, we have chosen for the stereographic projection that s is the South Pole<br />
<strong>and</strong> that the z-plane is the z = R plane. <strong>The</strong> parametrization <strong>and</strong> inverse parametrizations<br />
u(x) <strong>and</strong> x(u)) can then be computed as the intersection of vec<strong>to</strong>r s − p with the plane<br />
<br />
.<br />
⎤<br />
⎦
2.5. GEOMETRICAL REPRESENTATION 43<br />
z = R:<br />
x<br />
u<br />
u(x) =<br />
x(u) =<br />
s<br />
v<br />
π(x)<br />
y<br />
x = (x, y, z)<br />
S<br />
S ′<br />
Figure 2.18: Stereographic projection.<br />
<br />
2R 2R<br />
x,<br />
R + z R + z y<br />
<br />
,<br />
4R 2<br />
u 2 + v 2 + 4R 2<br />
u(x) = π(x)<br />
u, v, R(4R 2 − u 2 + v 2 ) .<br />
<strong>The</strong> metric tensor M for the stereographic projection is then given by:<br />
(2.30) M =<br />
with<br />
<br />
λ(u, v) =<br />
λ 0<br />
0 λ<br />
<br />
.<br />
4R 2<br />
u 2 + v 2 + 4R 2<br />
Those two eigenvalues are equal: the stereographic mapping is therefore conformal. This<br />
means that any infinitesimally small angle measured in the map is exactly the same as<br />
if measured on the corresponding point on the surface of the sphere. <strong>The</strong> mapping is<br />
neither isometric nor area-preserving: that is, it preserves neither distances nor the areas<br />
of figures.<br />
To illustrate this projection, 2.19 shows the World Ocean in stereographic coordinates<br />
u(x) = π(x). <strong>The</strong> outside loop surrounding the domain is the stereographic<br />
projection of the <strong>An</strong>tarctica. <strong>The</strong> radius of the Earth is chosen arbitrarily <strong>to</strong> R = 1. No<br />
seam is required <strong>to</strong> define the overall domain <strong>and</strong> no singular point exists in the domain<br />
of interest.<br />
<br />
.
44 CHAPTER 2. SOLID MODELS<br />
Figure 2.19: <strong>The</strong> World Ocean in stereographic coordinates.<br />
2.6 Non-Uniform Rational b-Splines (NURBS)<br />
Non-uniform rational B-splines (NURBS) are a family of parametric curves <strong>and</strong> surfaces.<br />
NURBS representations offer great flexibility <strong>and</strong> precision for h<strong>and</strong>ling both analytic <strong>and</strong><br />
free-form shapes.<br />
NURBS curves <strong>and</strong> surfaces are useful for at least two reasons:<br />
• <strong>The</strong>y are invariant under affine as well as perspective transformations: operations<br />
like rotations <strong>and</strong> translations can be applied <strong>to</strong> NURBS curves <strong>and</strong> surfaces by<br />
applying them <strong>to</strong> their control points.<br />
• <strong>The</strong>y offer one common mathematical form for both st<strong>and</strong>ard analytical shapes (e.g.,<br />
conics) <strong>and</strong> free-form shapes.<br />
2.6.1 NURBS curves<br />
A NURBS curve C is a parametric curve with a parametrization<br />
t ∈ [ta, tb] ↦→ x(t) ∈ R 3 .
2.6. NON-UNIFORM RATIONAL B-SPLINES (NURBS) 45<br />
Control points<br />
<strong>The</strong> geometry of a NURBS curve C is defined through a set of nc = n + 1 control points<br />
or poles pi, i = 0, . . . , n. A point x on the curve is computed by taking a weighted sum<br />
of some of the control points pi:<br />
(2.31) x(t) =<br />
where the N d i<br />
Knots<br />
n<br />
i=0<br />
N d i (t) pi<br />
(t) are some shape functions of degree d.<br />
In (2.31), the value of x(t) for a parameter t is only influenced by a finite number of control<br />
points. Typically, for a NURBS of degree d, the maximum number of control points that<br />
influences the NURBS for any parameter t is d + 1.<br />
<strong>The</strong> knot vec<strong>to</strong>r T = {t0, . . . , tk} is a sequence of parameter values t that determines<br />
where <strong>and</strong> how the control points affect the NURBS curve. For a non-periodic NURBS,<br />
the number of knots is equal <strong>to</strong><br />
We have of course that t0 = ta <strong>and</strong> tk = tb.<br />
k + 1 = nc + (d + 1) ⇒ k = n + (d + 1).<br />
<strong>The</strong> knot vec<strong>to</strong>r divides the parametric space in intervals. For a curve of degree<br />
d, every shape function N d i of any control point is only nonzero in d + 1 intervals of the<br />
parameter space. Shape function overlap in parameter intervals. <strong>The</strong> number of overlaps<br />
correspond <strong>to</strong> the number of control points that influence the NURBS shape in this interval<br />
(so the name control points).<br />
Shape functions are polynomials of degree d that go smoothly <strong>to</strong> zero at boundaries<br />
of the interval, the smoothness being determined by the degree of the polynomial.<br />
Knots can have the same value. This has impact on continuity of the resulting<br />
curve or its higher derivatives. For instance, it allows <strong>to</strong> lower the continuity of the curve,<br />
leading possibly <strong>to</strong> the creation of corners in an otherwise smooth NURBS curve.<br />
A number of coinciding knots is sometimes referred <strong>to</strong> as a knot with a certain<br />
multiplicity. <strong>The</strong> multiplicity of a knot is limited <strong>to</strong> the degree of the curve; since a higher<br />
multiplicity would split the curve in<strong>to</strong> disjoint parts <strong>and</strong> it would leave control points<br />
unused.<br />
<strong>The</strong> knot vec<strong>to</strong>r usually starts with a knot that has multiplicity equal <strong>to</strong> the order.<br />
This makes sense, since this activates the control points that have influence on the first<br />
knot span. Similarly, the knot vec<strong>to</strong>r usually ends with a knot of that multiplicity. Curves<br />
with such knot vec<strong>to</strong>rs start <strong>and</strong> end in a control point.
46 CHAPTER 2. SOLID MODELS<br />
<strong>The</strong> individual knot values are not meaningful by themselves; only the ratios of the<br />
difference between the knot values matter. Hence, the knot vec<strong>to</strong>rs T = {0, 0, 1, 2, 3, 3} <strong>and</strong><br />
T = {0, 0, 2, 4, 6, 6} produce the same curve. <strong>The</strong> positions of the knot values influences<br />
the mapping of parameter space <strong>to</strong> curve space.<br />
Consider a cubic NURBS with nc = 7 control points.<br />
• A knot vec<strong>to</strong>r T = {0, 0, 0, 0, 1, 2, 3, 4, 4, 4, 4} is the st<strong>and</strong>ard B-spline knot vec<strong>to</strong>r.<br />
This knot vec<strong>to</strong>r is of size 7+3+1 = 11 <strong>and</strong> defines 10 knot spans: (0,0), (0,0), (0,0),<br />
(0,1), (1,2), (2,3), (3,4),(4,4),(4,4) <strong>and</strong> (4,4). Shape function N 3 1 defines the influence<br />
of control point p1 on the curve. <strong>The</strong> number of parameter intervals required for<br />
defining a proper 3rd order curve is d + 1 = 4 which means that N 3 1 is non zero<br />
is non zero between<br />
between t = t1 = 0 <strong>and</strong> t = t5 = 1. Shape function N 3 2<br />
t = t2 = 0 <strong>and</strong> t = t6 = 2, N 3 3 is non zero between t = t3 = 0 <strong>and</strong> t = t7 = 3 <strong>and</strong> N 3 4<br />
is non zero between t = t4 = 0 <strong>and</strong> t = t8 = 4 which is the whole interval.<br />
• A knot vec<strong>to</strong>r T = {0, 0, 0, 0, 1, 1, 1, 4, 4, 4, 4} defines piecewise Bézier curves. This<br />
knot vec<strong>to</strong>r of size m = 11 = 7+3+1 defines 10 knot spans: (0,0), (0,0), (0,0), (0,1),<br />
(1,1), (1,1), (1,2),(2,2),(2,2) <strong>and</strong> (2,2). N 3 1 , N 3 2 , N 3 3 , are non zero between t = 0 <strong>and</strong><br />
t = 1 <strong>and</strong> N 3 5 , N 3 6 , N 3 7 , are non zero between t = 1 <strong>and</strong> t = 4. Only N 3 4 is non zero<br />
on the whole interval.<br />
B-spline Basis Functions<br />
<strong>The</strong>re are many ways <strong>to</strong> define B-spline basis functions <strong>and</strong> <strong>to</strong> demonstrate their interesting<br />
properties. Here, we use the recursive definition since it is the most useful in practical<br />
implementations.<br />
<strong>The</strong> B-spline functions at order d are defined recursively using functions at degree<br />
d − 1:<br />
(2.32) N d i (t) =<br />
(t − ti) d−1<br />
Ni (t) +<br />
(ti+d − ti) (ti+1+d − t) d−1<br />
Ni+1 (ti+1+d − ti+1) (t)<br />
with the degree-0 functions (first order) Ni,1 being piecewise constant functions:<br />
(2.33) N 0 i (t) =<br />
1 if t ∈ [ti, ti+1[<br />
0 otherwise.<br />
Those B-spline functions are positive because they are constructed recursively as positive<br />
weighted sums of functions of lower order. <strong>The</strong>y have a compact support since they are<br />
are non-zero only in the following interval:<br />
N d i (t) > 0, t ∈ [ti, ti+1+d[
2.6. NON-UNIFORM RATIONAL B-SPLINES (NURBS) 47<br />
Except for the d first <strong>and</strong> d last knot points, it can be proven by induction that the<br />
B-spline functions satisfy the partition of unity, i.e:<br />
(2.34)<br />
n<br />
i=0<br />
N d i (t) = 1, t ∈ [td, tn−d[.<br />
Non Uniform Rational B-splines (NURBS)<br />
B-splines are non uniform when the knot vec<strong>to</strong>r is not uniformly distributed. This defines<br />
what could be called NUBS or non uniform B-splines.<br />
Let us introduce a vec<strong>to</strong>r of positive weights W = w0, . . . , wn that has the size of<br />
the control points vec<strong>to</strong>r. <strong>The</strong> general form of a Non Uniform Rational B-spline (NURBS)<br />
curve is<br />
n (2.35) x(t) =<br />
i=0 wiN d i n i=0 wiN d i<br />
(t) pi<br />
.<br />
(t)<br />
We observe that the weights introduce new rational basis function Rd i<br />
R d n i=0<br />
i (t) =<br />
wiN d i (t)<br />
n i=0 wiN d i (t),<br />
defined as:<br />
<strong>and</strong> we also note that when all the weights have value wi = 1, we have a B-spline curve<br />
since R d i (t) = N d i (t).<br />
<strong>The</strong> main advantage of NURBS in CAD modelling is that NURBS can both represent<br />
free shapes <strong>and</strong> conics. A full circle can be represented using points placed on vertices <strong>and</strong><br />
mid-edges of an equilateral triangle. Let us call s = sin(30) <strong>and</strong> c = cos(30). Consider 7<br />
control points<br />
with weights <strong>and</strong> knots<br />
P = {{2 − c, s}, {2c, 2s}, {c, s}, {0, 0}, {1, 0}, {2, 0}, {2 − c, s}},<br />
W = {1, 0.5, 1, 0.5, 1, 0.5, 1}, T = {0, 0, 0, 1/3, 1/3, 2/3, 2/3, 1, 1, 1}.<br />
This NURBS is of degree p = 2 (order 3). It defines a complete circle that is tangent <strong>to</strong><br />
p0, p2 <strong>and</strong> p4.<br />
2.6.2 NURBS surfaces<br />
Recall that the geometry of a model face G 2 is its underlying surface S with its parametrization<br />
x(u):<br />
(u, v) ∈ R 2 ↦→ x(u, v) ∈ R 3 .
48 CHAPTER 2. SOLID MODELS<br />
A B-spline surface S of order d in the u−direction <strong>and</strong> of order e in the v−direction is a<br />
bivariate piecewise function of the form:<br />
n m<br />
x(u, v) =<br />
Two knot vec<strong>to</strong>rs<br />
i=0 j=0<br />
pijN d i (u)N e j (v).<br />
TU = {u0, . . . , uku } <strong>and</strong> TV = {v0, . . . , vkv }<br />
are defined, with ku = n + (d + 1) <strong>and</strong> kv = m + (e + 1).<br />
NURBS surfaces can also use weights wij so that the most general form of the<br />
NURBS surface is written as<br />
n m i=0 j=0<br />
(2.36) x(u, v) =<br />
wijpijN d i (u)N e j (v)<br />
.<br />
(v)<br />
n<br />
i=0<br />
2.7 Surface Intersections<br />
m<br />
j=0 wijN d i (u)N e j<br />
Solid modelers allow <strong>to</strong> perform boolean operations on Boundary representations. <strong>The</strong><br />
algorithm for the evaluation of boolean opera<strong>to</strong>rs on boundary representations can be<br />
stated as:<br />
1. Determine the intersection of all edges of one object with the edges of the other<br />
objects <strong>and</strong> split the edges at the point of intersection<br />
2. Determine all intersections of the edges of one solid with faces of the other solid <strong>and</strong><br />
split the edge, <strong>and</strong> place a vertex in the face intersected.<br />
3. Determine all coincident vertices of the two solids. (<strong>The</strong>se include the vertices created<br />
in steps 1 <strong>and</strong> 2)<br />
4. Create intersection polygons around the coincident vertices.<br />
5. Choose the appropriate sides of intersection polygons from each object <strong>and</strong> ”glue”<br />
them <strong>to</strong>gether.<br />
Curve-curve intersections or vertex gluing require subtle care about model <strong>to</strong>lerance.<br />
Curve-surface intersection may<br />
2.7.1 Intersection two implicit surfaces<br />
Consider two implicit surfaces f(x, y, z) = 0 <strong>and</strong> g(x, y, z) = 0 <strong>and</strong> a point p on their<br />
intersection. We wish <strong>to</strong> trace the intersection curve, beginning at p. We define a trace<br />
direction<br />
t = ∇f × ∇g
2.7. SURFACE INTERSECTIONS 49<br />
that defines the tangent of the intersecting curve at point p. We have <strong>to</strong> assume here<br />
that tangent vec<strong>to</strong>rs ∇f <strong>and</strong> ∇g are linearly independant, otherwise the two surfaces are<br />
tangent <strong>to</strong> each others at point p. If the gradients vanish at p or if they are colinear, then<br />
the intersection curve has a singularity at p.<br />
Assume that the intersection is regular at p. Let us build a local parametrization<br />
of the intersection at the neighborhood of p:<br />
(2.37) x(t) = p + tx (1) (0) + t2<br />
2 x(2) (0) + t3<br />
6 x(3) (0) + . . .<br />
where x (m) is the m-the derivative of x with respect <strong>to</strong> t. It is then possible <strong>to</strong> build<br />
an algorithm that traces the interface steb by step. <strong>The</strong> next point on the curve is<br />
first approximated as x(t). <strong>The</strong>n, a New<strong>to</strong>n iteration is used <strong>to</strong> bring the point <strong>to</strong> the<br />
intersection of f <strong>and</strong> g.<br />
<strong>The</strong> idea here is <strong>to</strong> find derivatives x (m) using partial derivatives of f <strong>and</strong> g. Let<br />
us call x(y) = {xp + dx, yp + dy, zp + dz} a point of the intersection that is close <strong>to</strong><br />
p = {xp, yp, zp} = x(0). We have<br />
or, in a closed form<br />
f(x, y, z) = f(xp, yp, zp) + f,xdx + f,ydy + f,zdz + . . .<br />
(2.38) f(x, y, z) = f(xp, yp, zp) +<br />
∞<br />
i,j,k=1<br />
1<br />
!i!j!k f ,x i y j z kdxi dy j dz k<br />
We look here for dx, dy <strong>and</strong> dz. Those are found using (2.37):<br />
dx = {dx, dy, dz} = x(t) − p = tx (1) (0) + t2<br />
2 x(2) (0) + t3<br />
6 x(3) (0) + . . .<br />
In a similar manner, if we look for a third order approximation, we have<br />
dx 2 = (x(t) − xp) 2 = (x (1) ) 2 t 2 + x (1) x (2) t 3 + . . .<br />
dx 3 = (x(t) − xp) 3 = (x (1) ) 3 t 3 + . . .<br />
dx dy = (x(t) − xp)(y(t) − yp) = x (1) y (1) t 2 + (x (2) y (1) + x (1) y (2) ) t3<br />
dx dy dz = (x(t) − xp)(y(t) − yp)(z(t) − zp) = x (1) y (1) z (1) t 3 + . . .<br />
2<br />
+ . . .<br />
Since x(t) is on f, f(x+dx, y +dy, z +dz) = 0. We can introduce values of dx, dx 2 , dx dy,<br />
... in<strong>to</strong> (2.38) <strong>and</strong> zero all expressions fac<strong>to</strong>r of t m , m = 0, 1, 2, 3. This is of course trivial<br />
for m = 0, p being on the intersection. For m = 1, we have of course<br />
∇f · x (1) = 0.<br />
Higher order values for m give more complex expressions.
50 CHAPTER 2. SOLID MODELS<br />
2.7.2 Intersection of a parametric surface with an implicit surface<br />
In this section, we will give some hints on the way it is possible <strong>to</strong> compute the intersection<br />
of surfaces <strong>and</strong> show how hard this problem may be. Let us consider two surfaces S1 <strong>and</strong><br />
S2 that have both a parametric representation <strong>and</strong> an implicit representation:<br />
<br />
x(u1, v1) = {x(u1, v1), y(u1, v1), z(u1, v1)}<br />
(2.39) S1 =<br />
f1(x, y, z) = 0.<br />
<strong>and</strong><br />
<br />
x(u2, v2) = {x(u2, v2), y(u2, v2), z(u2, v2)}<br />
(2.40) S2 =<br />
f2(x, y, z) = 0.<br />
Let us consider the parametric plane (u, v) of S1. <strong>The</strong> intersection of the two surfaces can<br />
be represented as the implicit curve g(u1, v1) that verifies the implicit representation of<br />
S2:<br />
g(u1, v1) = f2(x(u1, v1), y(u1, v1), z(u1, v1)) = 0.<br />
In principle, this seems simple. Yet, the <strong>to</strong>pology of the intersecting curve may become<br />
complex, even for simple surfaces. As an example, consider two cylinders<br />
<br />
x(u1, v1) = {R1 cos u1, R1 sin u1, v1}, u1 ∈ [0, 2π[, v1 ∈ ℜ<br />
(2.41) S1 =<br />
f1(x, y, z) = x 2 + y 2 − R 2 = 0.<br />
<br />
x(u2, v2) = {u2, R2 cos v2, R2 sin v2}, u2 ∈ ℜ, v2 ∈ [0, 2π[<br />
(2.42) S2 =<br />
f2(x, y, z) = y 2 + z 2 − r 2 = 0.<br />
We introduce the parametric representation of S1 in the implicit representation of S2 <strong>to</strong><br />
obtain<br />
R 2 1 sin 2 u1 + v 2 1 − R 2 2 = 0<br />
which is an implicit equation g(u1, v1) = 0 that represents a curve in the parametric plane<br />
of S1. We obtain easily that<br />
<br />
v1 = ± R2 2 − R2 1 sin2 u1.<br />
Imagine first that R2 > R1. In this case, the intersection is composed of two separate<br />
periodic curves that divide the parameter plane in 3 regions (see Figure 2.20) so that the<br />
intersection is not simply connected. In the case R2 > R1, the intersection is composed<br />
of two closed curves in the parameter plane that dig two holes so that the intersecting<br />
surface is simply connected, yet with two holes. <strong>The</strong> case R2 = R1 is the more complicated.<br />
<strong>The</strong>re, two singular points are present in the intersection, where the curve is “non locally<br />
manifold” i.e. a branching exists. For removing such singularity, it is useful in practice <strong>to</strong><br />
introduce a new model vertex that separates the parts of the intersecting curve that are<br />
adjacent <strong>to</strong> this model vertex (see Figure 2.21). Solving numerically surface intersections is<br />
a hard problem because the <strong>to</strong>pology of the intersecting curves may become complicated:<br />
.
2.7. SURFACE INTERSECTIONS 51<br />
Figure 2.20: Intersection of two cylinders S1 <strong>and</strong> S2. Figures show the intersection in the<br />
parameter plane of S1 for R2 > R1 (left), R2 = R1 (center) <strong>and</strong> R2 < R1 (right).<br />
the intersecting curve may non be connected, singular points may appear <strong>and</strong> the solution<br />
of g(u1, v1) may be complex. Building a robust code for doing such intersections takes<br />
time <strong>and</strong> experience so that few solid modelling kernels have survived the 1990’s.<br />
<strong>An</strong>other way of proceeding is <strong>to</strong> use homogeneous coordinates. We transform the<br />
equations as<br />
f1(x, y, z, w) = x 2 + y 2 − w 2 R 2 = 0,<br />
f2(x, y, z, w) = y 2 + z 2 − w 2 r 2 = 0,<br />
those having a singularity at the origin w = 0.<br />
f1(x, y, z, w) = x 2 + y 2 − w 2 R 2 = 0,<br />
2.7.3 From parametric <strong>to</strong> implicit representations<br />
Let us see how this parametric surface can be transformed in<strong>to</strong> an algebraic surface i.e.<br />
an implicit surface f(x, y, z) = 0 whose equation is formed by polynomials. <strong>An</strong> algebraic<br />
surface of degree d is of the form<br />
f(x, y, z) = <br />
aijkx i y j z k = 0.<br />
i+j+k≤d<br />
<strong>An</strong> algebraic surface at order d has (d + 1)(d + 2)(d + 3)/6 coefficients aijk.<br />
For sake of simplicity, let us first consider the following bilinear surface:<br />
x(u, v) = a0 + a1u + a2v + a3uv<br />
y(u, v) = b0 + b1u + b2v + b3uv<br />
z(u, v) = c0 + c1u + c2v + c3uv
52 CHAPTER 2. SOLID MODELS<br />
Figure 2.21: Intersection of two cylinders S1 <strong>and</strong> S2 with R2 = R1 (left) <strong>and</strong> R2 = R1<br />
(right).<br />
that we can rewrite as:<br />
(a0 − x) + a1u + a2v + a3uv = 0<br />
(b0 − y) + b1u + b2v + b3uv = 0<br />
(c0 − z) + c1u + c2v + c3uv = 0.<br />
Our aim is <strong>to</strong> express those equations as an implicit function f(x, y, z) = 0. Here, we use<br />
Sylvester’s Diadic Expansion that consist in considering all the individual monomials of<br />
a polynomial as independant variables. Here, we have 3 equations <strong>and</strong> 4 “independant<br />
variables” 1, u, v <strong>and</strong> uv.<br />
Those equations can be multiplied either by u or v <strong>to</strong> form a set of 6 equations with<br />
6 “independant variables”. Assume that we multiply those equations by u, we obtain<br />
⎡<br />
⎢<br />
⎣<br />
(a0 − x) a1 a2 a3 0 0<br />
(b0 − y) b1 b2 b3 0 0<br />
(c0 − z) c1 c2 c3 0 0<br />
0 (a0 − x) 0 a1 a2 a3<br />
0 (b0 − y) 0 b1 b2 b3<br />
0 (c0 − z) 0 c1 c2 c3<br />
⎤ ⎡<br />
⎥ ⎢<br />
⎥ ⎢<br />
⎥ ⎢<br />
⎥ ⎢<br />
⎥ ⎢<br />
⎥ ⎢<br />
⎦ ⎣<br />
1<br />
u<br />
v<br />
uv<br />
u 2<br />
u 2 v<br />
⎤<br />
⎥ = 0.<br />
⎥<br />
⎦<br />
Note here that the trick was <strong>to</strong> find the right set of monomials so that the number of<br />
equations is exactly equal <strong>to</strong> the number of independant variables.<br />
This system has no trivial solution if its determinant f(x, y, z) is zero. This is the<br />
implicit version of the surface, which is indeed a quadratic surface. More precisely, it is a<br />
hyperbolic paraboloid.
2.8. GEODESICS 53<br />
Consider now the case of a bivariate surface<br />
Px(u, v) = f1(a | u m , v n ) − x = 0<br />
Py(u, v) = f2(b | u m , v n ) − y = 0<br />
Pz(u, v) = f3(c | u m , v n ) − z = 0.<br />
We look for the conditions under which those 3 equations can be satisfied simultaneously.<br />
<strong>The</strong> strategy is analogous <strong>to</strong> what has been done for bilinear surfaces: our goal is still <strong>to</strong><br />
arrive at a number of auxiliary equations, deduced from the parametric surface equations,<br />
equal <strong>to</strong> the number of “independant variables”. Yet, that method can introduce linearly<br />
independant equations which cause the resultant <strong>to</strong> vanish identically.<br />
A complete development of the method is presented in [?]. <strong>The</strong> result are twofold:<br />
• A bivariate surface of degree n in u <strong>and</strong> m in v is equivalent <strong>to</strong> an algebraic surface<br />
of degree d = 2mn,<br />
• A rationale bivariate surface of degree n in u <strong>and</strong> m in v is also equivalent <strong>to</strong> an<br />
algebraic surface of degree d = 2mn.<br />
This means that it is in general possible <strong>to</strong> represent any NURBS as an implicit surface.<br />
Yet, the most common NURBS surfaces are cubic. Those can be represented as an implicit<br />
surface of order 18! This would require the computation of (d + 1)(d + 2)(d + 3)/6 = 1330<br />
terms.<br />
2.7.4 Intersection of NURBS<br />
<strong>The</strong> intersection of two cubic NURBS can then be seen as the intersection of an algebraic<br />
surfaces S1 of degree 18 with a bicubic parametric surface S2.<br />
(2.43)<br />
<strong>The</strong> intersection verifies<br />
x(u1, v1) = {Px(u, v), Py(u, v), Pz(u, v)}<br />
f(x, y, z) = <br />
i+j+k≤18 aijkx i y j z k = 0.<br />
where Px, Py <strong>and</strong> Pz are bicubic polynomials in u <strong>and</strong> v. We can then compute the<br />
intersection in the (u, v) plane as<br />
<br />
i+j+k≤18<br />
aijkPx(u, v) i Py(u, v) j Pz(u, v) k = 0<br />
that is an algebraic planar curve of degree 3 × 18 = 54!<br />
2.8 Geodesics<br />
Consider a surface S <strong>and</strong> two points with coordinates u1 <strong>and</strong> u2 on the parameter plane<br />
of S. <strong>The</strong>re exists an infinity of paths (curves) on the surface that connect u1 <strong>and</strong>
54 CHAPTER 2. SOLID MODELS<br />
u2. In cartesian coordinates, the straight line is the shortest path between two points.<br />
Geodesics are the generalization of straight lines <strong>to</strong> metric spaces. Consider a curve<br />
u(t) = {u(t), v(t)}, with u(t1) = u1 <strong>and</strong> u(t2) = u2, that is drawn on the parametric<br />
plane of S. Its length l is a functional<br />
<br />
t2<br />
l(u, u,t) =<br />
C<br />
<br />
du T M du =<br />
t1<br />
<br />
u T ,t M(u) u,t dt.<br />
In order <strong>to</strong> minimize l, we use the calculus of variations <strong>and</strong> put <strong>to</strong> zero the first<br />
variation of the functional for all admissible variations of u.<br />
Consider the following functional T :<br />
t2<br />
l = F (t, y, y ′ )dt<br />
with y ′ = y,t. Using integration by parts, i.e.<br />
x2<br />
fg ′ x2<br />
dx = −<br />
we have<br />
δl =<br />
=<br />
=<br />
x1<br />
t1<br />
t1<br />
x1<br />
f ′ gdx + fg| x2<br />
x1<br />
<br />
t2 ∂F ∂F<br />
δy + δy′ dx<br />
t1 ∂y ∂y ′<br />
t2 ∂F d ∂F<br />
−<br />
t1 ∂y dt ∂y ′<br />
<br />
δydt + ∂F<br />
<br />
<br />
δy<br />
∂y ′ <br />
t2 ∂F d ∂F<br />
−<br />
∂y dx ∂y ′<br />
<br />
δydt = 0<br />
because δy = 0 on both t = t1 <strong>and</strong> t = t2. With arbitrary variations δy, one lemma of the<br />
calculus of variations ensures that the quantity<br />
<br />
∂F d ∂F<br />
−<br />
∂y dt ∂y ′<br />
<br />
= 0<br />
has <strong>to</strong> be zero <strong>to</strong> ensure the extremality of the functional. This is the famous Euler-<br />
Lagrange equation. Here, for geodesics,<br />
F =<br />
<br />
uT ,tM(u) u,t<br />
Consider for example an isometric mapping, i.e. M is the identity. We have<br />
F =<br />
<strong>The</strong> Euler-Lagrange equations are written as<br />
<br />
u 2 ,t + v2 ,t .<br />
− d<br />
dt (2u,t) = 0 , − d<br />
dt (2v,t) = 0<br />
t2<br />
t1
2.8. GEODESICS 55<br />
that have the simple solution that both u <strong>and</strong> v are linear in t which means that the<br />
geodesic is the straight line.<br />
Consider now the stereographic projection, i.e. a conformal mapping. We have<br />
<br />
<br />
F =<br />
.<br />
A COMPLETER ...<br />
4R 2<br />
u 2 + v 2 + 4R 2
56 CHAPTER 2. SOLID MODELS
Chapter 3<br />
<strong>Mesh</strong> <strong>Generation</strong><br />
3.1 Generalities<br />
<strong>The</strong> goal of a finite element analysis is <strong>to</strong> solve a set of partial differential equations over<br />
a geometrical domain G. <strong>The</strong> most common way <strong>to</strong> describe G is <strong>to</strong> use a boundary-based<br />
scheme where the geometric domain is represented as a set of <strong>to</strong>pological types <strong>to</strong>gether<br />
with adjacencies. This has already be described in the sections of Chapter 2.<br />
<strong>The</strong> mesh M is a discrete version of the domain. In some sense, it is similar <strong>to</strong> what<br />
we’ve defined for the geometric model: it consists of<br />
• A collection of mesh entities M d i<br />
of controlled size <strong>and</strong> distribution;<br />
• Topological relationships or adjacencies forming the graph of the mesh.<br />
We have<br />
1. <strong>Mesh</strong> Vertices M 0 i<br />
2. <strong>Mesh</strong> Edges M 1 i<br />
3. <strong>Mesh</strong> Faces M 2 i<br />
4. <strong>Mesh</strong> Regions M 3 i<br />
that are <strong>to</strong>pological entities of dimension 0,<br />
that are <strong>to</strong>pological entities of dimension 1,<br />
that are <strong>to</strong>pological entities of dimension 2,<br />
that are <strong>to</strong>pological entities of dimension 3.<br />
What differs is that mesh entities are more numerous than model entities but have<br />
limited complexity.<br />
<strong>Mesh</strong> entities are <strong>to</strong>pologically equivalent <strong>to</strong> the unit d-dimensional sphere S d =<br />
{x ∈ R d ; x 2 < 1}: they are made of one part, they are simply connected (a manifold is<br />
said <strong>to</strong> be simply connected if every closed curve can be smoothly shrunk <strong>to</strong> a point) <strong>and</strong><br />
they have no holes.<br />
57
58 CHAPTER 3. MESH GENERATION<br />
<strong>Mesh</strong> entities have simple shapes: they are are lines in 1D, triangles <strong>and</strong> quadrangles<br />
in 2D <strong>and</strong> tetrahedra, hexahedra <strong>and</strong> prisms in 3D.<br />
, d ≤ q<br />
(a mesh entity must have dimensionality less than or equal <strong>to</strong> the geometry it is associated<br />
with). We call this association a classification of a mesh entity <strong>to</strong> a geometrical entity <strong>and</strong><br />
[?, ?, ?].<br />
<strong>An</strong>y mesh entity M d i is a piece of the discretization of a geometric entity G q<br />
j<br />
we note it as M d i<br />
⊏ Gq<br />
j<br />
Simulation attributes like boundary conditions or material properties are naturally<br />
related <strong>to</strong> model entities <strong>and</strong> not <strong>to</strong> mesh entities. In mesh generation <strong>and</strong> mesh enrichment<br />
procedures, the classification information is critical for ensuring that the mesh is<br />
constructed so that it improves the geometric approximation of the domain when it is is<br />
refined. It is therefore necessary <strong>to</strong> maintain the classification of mesh entities through all<br />
our algorithms.<br />
A mesh M is composed of a collection of mesh entities <strong>to</strong>gether with their adjacencies.<br />
<strong>An</strong>y mesh entity bounds <strong>and</strong>/or is bounded by other ones of higher <strong>and</strong>/or lower dimension.<br />
This adjacency information represents the graph of a mesh.<br />
It is interesting at this point <strong>to</strong> gather some statistics about the average number of<br />
adjacencies per entity that occurs in usual three dimensional tetrahedral <strong>and</strong> hexahedral<br />
meshes.<br />
3.1.1 <strong>The</strong> Euler-Poincaré Formula<br />
<strong>The</strong> Euler-Poincaré formula describes the relationship of the number of vertices, the number<br />
of edges <strong>and</strong> the number of faces of the cellular decomposition (a mesh) of a manifold.<br />
It has been generalized <strong>to</strong> include potholes <strong>and</strong> holes that penetrate the solid. To state<br />
the Euler-Poincaré formula, we need the following definitions:<br />
• #V is the number of vertices in the cellular decomposition,<br />
• #E is the number of edges in the cellular decomposition,<br />
• #F is the number of faces in the cellular decomposition,<br />
• G is the number of holes that penetrate the solid, usually referred <strong>to</strong> as genus in<br />
<strong>to</strong>pology,<br />
• H is the number of shells. A shell is an internal void of a solid. A shell is bounded<br />
by a 2-manifold surface, which can have its own genus value. Note that the solid<br />
itself is counted as a shell. <strong>The</strong>refore, the value for #S is at least 1.<br />
• L is the number of loops. All outer <strong>and</strong> inner loops of faces are counted. <strong>The</strong><br />
Euler-Poincaré formula is<br />
#V − #E + #F − (L − #F ) − 2(S − H) = 0.
3.1. GENERALITIES 59<br />
Consider a cube. It has eight vertices (#V = 8), 12 edges (#E = 12) <strong>and</strong> six faces<br />
(#F = 6), no holes <strong>and</strong> one shell (S = 1); but #L = #F since each face has only one<br />
outer loop. <strong>The</strong>refore, we have<br />
#V − #E + #F − (L − #F ) − 2(S − H) = 8 − 12 + 6 − (6 − 6) − 2(1 − 0) = 0.<br />
Consider now M, a 2D mesh of a domain Ω. <strong>The</strong> Euler-Poincaré relation gives the<br />
following relation between those quantities:<br />
#V − #E + #F − χ(M) = 0<br />
where χ(Ω) is the Euler-Poincaré characteristic of the surface. <strong>The</strong> Euler-Poincaré characteristic<br />
of different surfaces is given in the following bullet list:<br />
• for the sphere, χ = 2 (#V − #E + #F = 2 − 4 + 4),<br />
• for the <strong>to</strong>rus, χ = 0 (#V − #E + #F = 4 − 8 + 4),<br />
• for the disk, χ = 1,<br />
• for the Klein bootle, χ = 1.<br />
<strong>An</strong>other form of the Euler-Poincaré relation, more useful for general domains is given by:<br />
(3.1) χ(M) = #V − #E + #F = 2 − 2G − NB<br />
where,<br />
• NB is the number of boundaries (1 for the plane or 0 for a <strong>to</strong>rus or a sphere),<br />
• G is the genus of the surface. <strong>The</strong> genus is the largest number of nonintersecting<br />
simple closed curves that can be drawn on the surface without separating it. Roughly<br />
speaking, it is the number of h<strong>and</strong>les in a surface.<br />
From Eq. 3.1, it is then easy <strong>to</strong> compute the genus G of a given mesh M:<br />
(3.2) G(M) = −χ(M) − NB + 2<br />
2<br />
Property 3.1.1 We consider a mesh of a 2D domain that is isomorphic <strong>to</strong> a disk. <strong>The</strong>n,<br />
the following relations holds<br />
(3.3)<br />
(3.4)<br />
where #Vb is the number of vertices on b.<br />
#F − 2(#V − 1) + #Vb = 0<br />
#E − 3(#V − 1) + #Vb = 0
60 CHAPTER 3. MESH GENERATION<br />
This is an important relation that gives a relation between the number of triangles<br />
<strong>and</strong> the number of vertices in the triangular mesh of a “disk-like” surface. In order <strong>to</strong><br />
proove this, let us first remark that relations (3.3) <strong>and</strong> (3.4) are true for one triangle alone:<br />
#F = 1, #V = #Vb = 3.<br />
Swapping an edge of the mesh does not modify #V , #E, #F or #Vb. All triangulations<br />
with #N given are therefore equivalent: edge swaps allow <strong>to</strong> transform any given<br />
triangulation <strong>to</strong> any other.<br />
Inserting a point inside a triangle adds one vertex, 2 triangles <strong>and</strong> 3 edges <strong>to</strong> the<br />
mesh, leaving #Vb unchanged:<br />
(#F + 2) − 2((#V + 1) − 1) + #Vb = #F − 2(#V − 1) + #Vb = 0<br />
(#E + 3) − 3((#V + 1) − 1) + #Vb = #E − 3(#V − 1) + #Vb = 0.<br />
Inserting a point on the domain boundary b adds one vertex, one triangles <strong>and</strong> two edges<br />
<strong>to</strong> the mesh. Relations (3.3) <strong>and</strong> (3.4) are still true:<br />
(#F + 1) − 2((#V + 1) − 1) + (#Vb + 1) = #F − 2(#V − 1) + #Vb = 0<br />
(#E + 2) − 3((#V + 1) − 1) + (#Vb + 1) = #E − 3(#V − 1) + #Vb = 0.<br />
Property 3.1.2 We consider a mesh of a 3D domain that is isomorphic <strong>to</strong> a sphere. <strong>The</strong><br />
following relation holds<br />
#E − #R = #V + #Vb − 3<br />
where #Vb is the number of vertices on the boundary.<br />
Note that this relation is true for one tetrahedron only, as well as for any other 3D element.<br />
In a 3D tetrahedral mesh, there exist no relation between the number of tetrahedra<br />
<strong>and</strong> the number of nodes, as it exists in 2D. As an example, it is possible <strong>to</strong> define<br />
the following “face swap” transformation: 2 tets that have a face in common can be<br />
transformed in 3 tets without changing the number of vertices. Yet one additional edge<br />
has <strong>to</strong> be added <strong>to</strong> the mesh in order <strong>to</strong> verify the relation, verifying the Euler-Poincaré<br />
formula.<br />
Asymp<strong>to</strong>tically, the 3D Euler-Poincaré gives:<br />
#V − #E + #F − #R 0.<br />
In the following Tables 3.1 <strong>and</strong> 3.2, we present some statistics about 3-D meshes.<br />
Those are “asymp<strong>to</strong>tically” correct for sufficiently large meshes but are patently wrong<br />
for coarse meshes. <strong>The</strong> average number of mesh entities in tetrahedral <strong>and</strong> hexahedral<br />
meshes are presented in Table 3.1.<br />
A second interesting set of statistics concerns the average number of mesh entities<br />
of dimension d adjacent <strong>to</strong> a mesh entity of dimension q. We call this N d (M q ). <strong>The</strong>se<br />
statistics are represented in Table 3.2.
3.1. GENERALITIES 61<br />
Tetrahedral <strong>Mesh</strong> M Hexahedral <strong>Mesh</strong> M<br />
#R = 6#V<br />
#F = 12#V<br />
#E = 7#V<br />
#R = #V<br />
#F = 3#V<br />
#E = 3#V<br />
Table 3.1: Relation between number of entities in a mesh.<br />
Tetrahedral <strong>Mesh</strong> M Hexahedral <strong>Mesh</strong> M<br />
d 3 2 1 0<br />
N 3 (M d ) 1 2 5 23<br />
N 2 (M d ) 4 1 5 35<br />
N 1 (M d ) 6 3 1 14<br />
N 0 (M d ) 4 3 2 1<br />
d 3 2 1 0<br />
N 3 (M d ) 1 2 4 8<br />
N 2 (M d ) 6 1 4 12<br />
N 1 (M d ) 12 4 1 6<br />
N 0 (M d ) 8 4 2 1<br />
Table 3.2: Average number of adjacencies per entity<br />
We read these tables as follow: most of the tetrahedron meshes will contain, when<br />
they are sufficiently big, 6 times more tetrahedron than vertices. Every edge is connected,<br />
on average, <strong>to</strong> 5 tetrahedron.<br />
<strong>The</strong> information contained in these two tables are important when designing mesh<br />
data structures or when choosing one finite element interpolation scheme. In a tetrahedral<br />
mesh for example, it is important <strong>to</strong> figure out that there are 12 times more faces than<br />
vertices <strong>and</strong> that any scheme that imposes <strong>to</strong> s<strong>to</strong>re in memory the faces of the mesh will be<br />
expensive. Moreover, building finite element interpolations on tetrahedral meshes based<br />
on any other entity than vertices will generate large number of degrees of freedom.<br />
3.1.2 <strong>Mesh</strong> generation procedure<br />
Usual mesh generation procedures work as follows<br />
• Curves are discretized first i.e. are subdivided in<strong>to</strong> line elements,<br />
• <strong>The</strong>n, surfaces are triangulated using the discretization of the curves as boundaries,<br />
• Finally, regions are tetrahedralized using surface meshes.<br />
Some authors have proposed an alternative procedure that consist in building the 3D<br />
mesh at first [?, ?]. This kind or approach is not used in Gmsh <strong>and</strong> will not be discussed<br />
here. Figure 3.1 illustrate this three steps procedure.<br />
At the end, some pre- <strong>and</strong> post-processing steps can be plugged in the general mesh<br />
generation ”three steps” flow.<br />
• High order curvilinear meshed are usually build starting from a valid 3D straight<br />
sided mesh.
62 CHAPTER 3. MESH GENERATION<br />
Figure 3.1: Example of a 3D meshing procedure in Gmsh. From <strong>to</strong>p, 1D meshing procedure,<br />
surface meshing <strong>and</strong> volume meshing.
3.2. MESH SIZE FIELD AND QUALITY MEASURES 63<br />
• Quadrilateral meshes generation procedures usually use a valid triangulation as their<br />
starting point.<br />
• Boundary layer meshes are often build using an extrusion of the triangulation.<br />
All the stages of those mesh generation procedures are presented in the next sections of<br />
the chapter.<br />
3.2 <strong>Mesh</strong> size field <strong>and</strong> quality measures<br />
<strong>The</strong> aim of mesh generation is twofold<br />
1. Generating elements of the right size,<br />
2. Generating elements of the right shape.<br />
For addressing those aims, we have <strong>to</strong> clarify what is right for an element, both in terms<br />
of size <strong>and</strong> shape.<br />
3.2.1 <strong>Mesh</strong> size field<br />
A mesh size field is a <strong>to</strong>ol that aims at controlling the mesh size. We define the mesh<br />
size function δ(x, y, z) as a function the defines at every point of the domain a target size<br />
for the elements at the point. Recall that one of the two aims of the mesh generation<br />
procedure is <strong>to</strong> be able <strong>to</strong> build a mesh that complies with this mesh size field. Note that<br />
δ may me a tensor valued function. In this case, the mesh size field may be used <strong>to</strong> control<br />
directional sizes of the mesh <strong>and</strong> therefore enables <strong>to</strong> build anisotropic meshes.<br />
<strong>The</strong> present ways of defining such a mesh size field in Gmsh are:<br />
1. mesh sizes prescribed at model vertices <strong>and</strong> interpolated linearly on model edges;<br />
2. prescribed mesh gradings on model edges (geometrical progressions, ...);<br />
3. mesh sizes defined on another mesh (a background mesh) of the domain;<br />
4. mesh sizes that adapt <strong>to</strong> the principal curvature of model entities.<br />
<strong>The</strong>se size fields can then be acted on by functionals that may depend, for example, on<br />
the distance <strong>to</strong> model entities or on user-prescribed analytical functions; <strong>and</strong> when several<br />
size fields are provided, Gmsh uses the minimum of all fields. Thanks <strong>to</strong> that mechanism,<br />
Gmsh allows for a mesh size field defined on a given model entity <strong>to</strong> extend in higher<br />
dimensional entities. For example, using a distance function, a refinement based on the<br />
curvature of a model edge can extend on any surface adjacent <strong>to</strong> it.
64 CHAPTER 3. MESH GENERATION<br />
Let us now consider an edge e of the mesh. We define the adimensional length of<br />
the edge with respect <strong>to</strong> the size field δ as<br />
<br />
(3.5) le =<br />
e<br />
1<br />
δ(x, y, z) dl.<br />
We can now define a more precise criterion regarding <strong>to</strong> the mesh size: we aim at<br />
generating a mesh for which each mesh edge e is of size close <strong>to</strong> le = 1,<br />
3.2.2 Element quality measures<br />
To quickly evaluate the adequation between the mesh <strong>and</strong> the prescribed mesh size field,<br />
we defined an efficiency index τ [?] as<br />
<br />
1 ne<br />
(3.6) τ = exp<br />
ne<br />
with τe = le − 1 if le < 1 <strong>and</strong> τe = 1<br />
<strong>and</strong> should be as close as possible <strong>to</strong> τ = 1.<br />
le<br />
e=1<br />
τe<br />
<br />
− 1 if le ≥ 1. <strong>The</strong> efficiency index ranges in τ ∈ [0, 1]<br />
For measuring the quality of elements, various element shape measures are available<br />
in the literature [?, ?]. Here, we choose a measure based on the element radii ratio, i.e.<br />
the ratio between the inscribed <strong>and</strong> the circumcircles.<br />
If K is a triangle, we have the following formula<br />
sin â sin<br />
γK = 4<br />
ˆb sin ĉ<br />
sin â + sin ˆb + sin ĉ ,<br />
â, ˆ b <strong>and</strong> ĉ being the three inner angles of the triangle. With this definition, the equilateral<br />
triangle has a γK = 1 <strong>and</strong> degenerated (zero surface) triangles have a γK = 0.<br />
For a tetrahedron, we have the following formula:<br />
6<br />
γK =<br />
√ 6 Vk<br />
<br />
4<br />
<br />
a(fi) max<br />
i=1,...,6 l(ei)<br />
,<br />
i=1<br />
with VK the volume of K, a(fi) the area of the i th face of K <strong>and</strong> l(ei) the dimensional<br />
length of the i th edge of K. This quality measurement lies in the interval [0, 1], an element<br />
with γK = 0 being a sliver (zero volume).
3.3. ONE DIMENSIONAL MESHING 65<br />
3.3 One Dimensional <strong>Mesh</strong>ing<br />
Let us consider a point p(t) on a curve C, t ∈ [t1, t2]. <strong>The</strong> number of subdivisions N of<br />
the curve is its adimensional length:<br />
(3.7)<br />
t2<br />
t1<br />
1<br />
δ(x, y, z) ∂tp(t)dt = N.<br />
<strong>The</strong> N + 1 mesh points on the curve are located at coordinates {T0, . . . , TN}, where<br />
Ti is computed with the following rule:<br />
(3.8)<br />
Ti<br />
t1<br />
1<br />
δ(x, y, z) ∂tp(t)dt = i.<br />
With this choice, each subdivision of the curve is exactly of adimensional size 1, <strong>and</strong> the<br />
1-D mesh exactly satisfies the size field δ. In Gmsh, (3.8) is evaluated with a recursive<br />
numerical integration rule.<br />
3.4 Delaunay <strong>and</strong> Voronoï<br />
3.4.1 <strong>The</strong> Voronoï diagram<br />
Let p1 <strong>and</strong> p2 be two points of R 2 . <strong>The</strong> media<strong>to</strong>r M(p1, p2) is the locus of all the points<br />
which are equidistant <strong>to</strong> p1 <strong>and</strong> p2:<br />
M(p1, p2) = {p ∈ R 2 , d(p, p1) = d(p, p2)}<br />
where d(., .) is the euclidian distance between two points of R 2 , i.e.<br />
(3.9) d 2 (p1, p2) = (p2 − p1) · (p2 − p1).<br />
<strong>The</strong> equation of the media<strong>to</strong>r can be found out using this definition<br />
or<br />
(p1 − p) · (p1 − p) = (p2 − p) · (p2 − p)<br />
⎡<br />
⎢<br />
(p1 − p2) · ⎢<br />
1<br />
⎣p −<br />
2 (p1<br />
⎥<br />
+ p2) ⎥<br />
⎦ = 0<br />
<br />
pm<br />
This shows that the media<strong>to</strong>r is the orthogonal bissec<strong>to</strong>r of the straight edge linking the<br />
two points. <strong>The</strong> media<strong>to</strong>r separates the plane in<strong>to</strong> two regions. <strong>The</strong> first region contains<br />
all the points that are closer <strong>to</strong> p1, the second one contains the ones that are closer <strong>to</strong> p2.<br />
<strong>An</strong>y point of R 2 /M can be associated <strong>to</strong> one of those two points.<br />
⎤
66 CHAPTER 3. MESH GENERATION<br />
p2<br />
M<br />
p<br />
p m<br />
Figure 3.2: <strong>The</strong> media<strong>to</strong>r.<br />
p1
3.4. DELAUNAY AND VORONOÏ 67<br />
C(pi)<br />
pj<br />
vI<br />
p i<br />
Figure 3.3: <strong>The</strong> Voronoï diagram. <strong>The</strong> Voronoï cell C(pi) relative <strong>to</strong> vertex pi is colored.<br />
Let us consider a set of N points S = {p1, . . . , pN}. More specifically, we assume<br />
that the points are in general position, by which we mean no four points are cocircular.<br />
<strong>The</strong> Voronoï cell C(pi) associated <strong>to</strong> point pi is the locus of points of R 2 that are closer<br />
<strong>to</strong> pi than any other point pj, j = 1, . . . , N, i = j.<br />
<strong>The</strong> Voronoï cell is constructed as follow. Consider all media<strong>to</strong>rs M(pi, pj). Each<br />
of those media<strong>to</strong>rs define a half plane. <strong>The</strong> Voronoï diagram is the part of the space<br />
that is always closer <strong>to</strong> pi, i.e. that always associate pi <strong>to</strong> the point p, for all possible<br />
media<strong>to</strong>rs.(see Figure 3.3). <strong>The</strong> set of all Voronoï cells is called the Voronoï diagram of S<br />
(see Figure 3.3).<br />
Let us present some remarkable properties of the Voronoï diagram.<br />
Property 3.4.1 Voronoï cells are convex poly<strong>to</strong>pes.<br />
By definition, each Voronoi region C(pi) is the intersection of open half planes containing<br />
vertex pi. <strong>The</strong>refore, C(pi) is open <strong>and</strong> convex. Different Voronoï regions are disjoint.<br />
Voronoï cells are polygons in 2D, polyhedra in 3D <strong>and</strong> d-poly<strong>to</strong>pes in dD. Voronoï cells<br />
are either closed or open. <strong>The</strong>y can only be open for points that are located on the convex<br />
hull of the 2D domain. A point pi of S lies on the convex hull of S if <strong>and</strong> only if its<br />
Voronoï cell C(pi) is unbounded.<br />
pk
68 CHAPTER 3. MESH GENERATION<br />
Figure 3.4: Two triangulations of S, both containing nt = 13 triangles defined by a <strong>to</strong>tal<br />
of N = 12 points with Nh = 9 points that lie on the convex hull of S.<br />
Property 3.4.2 Voronoï points vI are always located at intersection of 3 media<strong>to</strong>rs.<br />
Property 3.4.2 is only true if there exist no quadruplets of points in S that are cocircular.<br />
If such a set exists, it may happen that a vertex of the Voronoï is at the the intersection of<br />
more than 3 media<strong>to</strong>rs. Consider the example of Figure 3.3 where vi is at the intersecion<br />
of C(pi), C(pj) <strong>and</strong> C(pk). Voronoï point vI is located at the center of the unique circle<br />
passing through pi, pj <strong>and</strong> pk.<br />
3.4.2 <strong>The</strong> Delaunay Triangulation<br />
We first define what is a triangulation of S: it is a planar subdivision whose bounded faces<br />
are triangles <strong>and</strong> whose vertices are the points pi of S. Note that all triangulations do not<br />
cover the same subset of R 2 . In what follows, we consider that the domain <strong>to</strong> triangulate<br />
is the convex hull of S.<br />
Even with the same domain <strong>to</strong> cover, several triangulations are possible (see Figure<br />
3.4). Yet, every triangulation has the same number of triangles <strong>and</strong> edges!<br />
Property 3.4.3 Let S be a set of N points in the plane, not all collinear, <strong>and</strong> let Nh<br />
denote the number of points in S that lie on the convex hull of S. <strong>The</strong>n any triangulation<br />
of S has nt(N, Nh) = 2N − 2 − Nh triangles <strong>and</strong> ne(N, Nh) = 3N − 3 − Nh edges.
3.4. DELAUNAY AND VORONOÏ 69<br />
Proof Consider first that all the points in S are in the convex hull: N = Nh. A triangulation<br />
consist simply in triangles tI(p1, pi, pi+1), i = 2, . . . , N − 1. <strong>The</strong> number of triangle<br />
is therefore nt = N − 2 which is consistent with the formula. <strong>The</strong> number of edges in the<br />
triangulation is calculated as follows: Nh = N edges on the convex hull <strong>and</strong> N −3 internal<br />
edges wich gives ne = N + N − 3 = 2N − 3 which is again consistent with the proposition.<br />
<strong>The</strong> rest of the proof works using a recurrence argument. Assume that formulas are<br />
true for N. Let us now consider one new vertex pN+1 that lies inside the convex hull.<br />
This new vertex lies inside one of the existing triangles, say tI(pi, pj, pk). We remove tI<br />
<strong>and</strong> replace it by three new triangles tJ(pi, pj, pN+1), tJ(pj, pk, pN+1), tJ(pk, pi, pN+1).<br />
We have therefore nt(Nh, Nh) = Nh − 2 <strong>and</strong> nt(N + 1, Nh) = nt(N, Nh) + 2 which gives<br />
nt(N, Nh) = Nh − 2 + 2(N − Nh) = 2N − 2 − Nh. Similarly, three new edges have been<br />
added in the process. <strong>The</strong>n, ne(Nh, Nh) = 2Nh − 3 <strong>and</strong> ne(N + 1, Nh) = ne(N, Nh) + 3<br />
which gives ne(N, Nh) = 2Nh − 3 + 3(N − Nh) = 3N − 3 − Nh.<br />
Consider a triangulation T with nt triangles. This triangulation has 3nt internal<br />
angles. Consider the vec<strong>to</strong>r of angles A(T ) = (α1, . . . , α3nt) sorted by increasing values.<br />
We can define such a vec<strong>to</strong>r for any triangulation of the convex hull of the domain. Each<br />
of those vec<strong>to</strong>rs has the same length <strong>and</strong> it is therefore possible <strong>to</strong> compare them, e.g.<br />
lexicographically. We say that one given triangulation T is angle-optimal if A(T ) ≤ A(T ′ ),<br />
∀T ′ . According <strong>to</strong> that criterion, left triangulation of Figure 3.4 is better than the right<br />
one.<br />
<strong>An</strong>gle-optimal triangulations have interesting interpolation properties <strong>and</strong> it is therefore<br />
useful <strong>to</strong> find methods that allow <strong>to</strong> construct such triangulations.<br />
For a given set of points, the (unique) angle-optimal triangulation is the triangulation<br />
that has the highest minimal angle. Let us see now how <strong>to</strong> build such a triangulation.<br />
Consider now the edge e(p4, p6) of Figure 3.5. This edge is surrounded by two<br />
triangles t1(p4, p6, p1) <strong>and</strong> t2(p4, p6, p2) . <strong>An</strong> edge swap is a local mesh modification<br />
opera<strong>to</strong>r that consist in changing locally the triangulation by replacing edge e(p4, p6) by<br />
e ′ (p1, p2). Triangles t1(p4, p6, p1) <strong>and</strong> t2(p4, p6, p2) are replaced by t ′ 1 (p1, p2, p4) <strong>and</strong><br />
t ′ 2 (p1, p2, p6). Figure 3.5 illustrate the edge swap operation.<br />
It is indeed possible <strong>to</strong> use the edge swap opera<strong>to</strong>r in order <strong>to</strong> build angle-optimal<br />
triangulation. In that purpose, we can simply decide <strong>to</strong> swap edge e if<br />
min (α1, . . . , α6) < min (α ′ 1, . . . , α ′ 6).<br />
Such an edge is said invalid. Given a finite set of points, there is a finite number of<br />
possible triangulations. When the angle criterion is applied, every edge swap produce a<br />
new triangulation that is better than the actual one. <strong>The</strong>refore, building the angle-optimal<br />
triangulation consist in looping over all the edges of the mesh <strong>and</strong> swap them until the<br />
optimal configuration is attained i.e. when no invalid edges remain in the triangulation.<br />
Figure 3.6 illustrate that procedure.<br />
Yet, computing angles is a costly operation <strong>and</strong> it is possible <strong>to</strong> use a simpler <strong>and</strong><br />
cheaper rule <strong>to</strong> verify the validity of an edge.
70 CHAPTER 3. MESH GENERATION
3.4. DELAUNAY AND VORONOÏ 71<br />
Figure 3.6: Building an angle-optimal triangulation using swaps.<br />
Property 3.4.4 Let C be a circle, l a line intersecting C in points p4 <strong>and</strong> p6 <strong>and</strong> p1, <strong>and</strong><br />
p2, p3 <strong>and</strong> p5 points lying on the same side of l. Suppose that p2 <strong>and</strong> p3 lie on C, that<br />
p5 lies inside C, <strong>and</strong> that p1 lies outside C. <strong>The</strong>n (see Fig. 3.7):<br />
α1 < α2 = α3 < α5.<br />
Property 3.4.5 [Lawson’s Criterion] Consider an edge e with its two neighboring triangles<br />
t1 <strong>and</strong> t2. Consider the circumcircle C of triangle t1 <strong>and</strong> point p that belongs <strong>to</strong> t2<br />
but not <strong>to</strong> t1. Edge e is invalid if p ∈ C.<br />
Property 3.4.5 has been demonstrated by Sibson in [?]. Consider Figure 3.8. <strong>The</strong> proof<br />
consist in demonstrating that α ′ > α if p1 ∈ C. <strong>The</strong> demonstration make use of property<br />
3.4.4 (Thalès’s <strong>The</strong>orem).<br />
Note that, when two neighboring triangles separated by an edge e form a concave<br />
quadrilateral, edge e is always valid.<br />
Procedure described in Figure 3.6 allow <strong>to</strong> build angle-optimal triangulations. Yet,<br />
it can be shown that such an algorithm is slow in practice.<br />
<strong>The</strong>re exists a much faster manner <strong>to</strong> build angle optimal triangulations of S that<br />
is based on the Voronoï diagram. This triangulation DT (S) is called the Delaunay triangulation<br />
<strong>and</strong> its construction works as follows.<br />
First recall that each Voronoï cell C(pi) is associated <strong>to</strong> one only point pI of S.<br />
Consider a Voronoï point vI that at the meeting point of 3 Voronoï cells C(pi),<br />
C(pj), C(pk). Because of the Voronoï property, point v is at the circumcenter of triangle<br />
tI(pi, pj, pk). Triangle tI ∈ DT (S) is one of the triangles of the Delaunay triangulation.<br />
<strong>The</strong> resulting figure is a triangulation (see Figure 3.9).<br />
Property 3.4.6 Let S be a set of points in the plane.
72 CHAPTER 3. MESH GENERATION<br />
p6<br />
C ′<br />
p1<br />
α1<br />
p6<br />
p5<br />
α5<br />
α2<br />
p2<br />
α3<br />
C<br />
p3<br />
Figure 3.7: <strong>The</strong>orem of Thalès<br />
α ′<br />
e<br />
p1<br />
p2<br />
e ′<br />
α<br />
Figure 3.8: Lawson’s criterion<br />
p4<br />
C<br />
l<br />
p4
3.4. DELAUNAY AND VORONOÏ 73<br />
Figure 3.9: <strong>The</strong> Voronoï diagram <strong>and</strong> its associated Delaunay triangulation
74 CHAPTER 3. MESH GENERATION<br />
p1<br />
C(t)<br />
t<br />
v<br />
p2<br />
v ′<br />
a<br />
b<br />
p3<br />
Figure 3.10: Illustration of why property (i) of 3.4.6 is true.<br />
(i) Three points pi , pj <strong>and</strong> pk ∈ S are vertices of the same triangle tI of the Delaunay<br />
triangulation if <strong>and</strong> only if the circumcircle C(tI) contains no point of S in its<br />
interior.<br />
(ii) Two points pi <strong>and</strong> pj ∈ S form an edge eI of the Delaunay triangulation if <strong>and</strong><br />
only if there is a closed disc C that contains pi <strong>and</strong> pj on its boundary <strong>and</strong> does not<br />
contain any other point of S.<br />
Proof Property (i) of 3.4.6, also called the incircle property, is a simple consequences of<br />
the properties of construction of the Voronoï diagram. Figure 3.12 show one triangle t<br />
<strong>and</strong> its circumcenter v. If a point like a exist in S, triangle t is cannot be in the Delaunay<br />
triangulation because point a is closer <strong>to</strong> v that at least one of the three points p1 p2 or<br />
p3. <strong>The</strong>refore, as it is drawn in the Figure, media<strong>to</strong>r la crosses another media<strong>to</strong>r at point<br />
v ′ inside the triangle, which is impossible.<br />
Property 3.4.7 Let S be a set of points in the plane in general position. A triangulation<br />
T of S is angle-optimal if <strong>and</strong> only if T is the Delaunay triangulation of S.<br />
Proof We shall prove that the angle-optimal triangulation is the Delaunay triangulation<br />
by contradiction. So assume T is a legal triangulation of S that is not a Delaunay<br />
triangulation. By Property (ii) of 3.4.6, this means that there is a triangle t(pi, pj, pk)<br />
such that the circumcircle C(t) contains a point pl ∈ S in its interior. Let e(pi, pj) be<br />
the edge of t ′ (pi, pj, pl) such that the triangle t ′ does not intersect t. Of all such pairs<br />
c<br />
la<br />
lc<br />
lb
3.4. DELAUNAY AND VORONOÏ 75<br />
pi+1<br />
C(Ti, pi+1)<br />
pi+1<br />
C(Ti, pi+1)<br />
Figure 3.11: Delaunay triangulation Ti (left). <strong>The</strong> Delaunay cavity Cp(Ti, pi+1) is represented<br />
in both middle (pi+1 is inside Ti) <strong>and</strong> right (pi+1 is outside Ti) figures.<br />
(pi, pj, pk, pl) in T , choose the one that maximizes the angle pi, pl, pj. Now look at the<br />
triangle t ′′ (pi, pj, pm) adjacent <strong>to</strong> t along e. Since T is angle-optimal, e is legal. By Property<br />
3.4.5, this implies that pm does not lie in the interior of C(t). <strong>The</strong> circumcircle C(t ′′ )<br />
contains the part of C(t) that is separated from t by e. Consequently, pl ∈ C(t ′′ ) Assume<br />
that e ′ (pj, pm) is the edge of t ′′ such that triangle t ′′′ (pj, pm, pl) does not intersect t ′′ . But<br />
now angle pj, pl, pm > angle pi, pl, pj by Thalès’s <strong>The</strong>orem, contradicting the definition<br />
of the pair (pi, pj, pk, pl).<br />
Note that the unicity of the Delaunay triangulation is only guaranteed when there<br />
exists no quadruplets of points in the set S that are cocircular, i.e. for points in general<br />
position. When S is not in general position, some of the Delaunay triangulations may not<br />
be angle-optimal.<br />
3.4.3 Construction of Delaunay Triangulations<br />
<strong>The</strong>re are two categories of algorithms that allow <strong>to</strong> create Delaunay triangulations.<br />
Incremental Construction of Delaunay Triangulations: the Delaunay kernel<br />
We consider a triangulation Ti <strong>and</strong> a point pi+1 inside Ti. <strong>The</strong> cavity C(Ti, pi+1) associated<br />
<strong>to</strong> Ti <strong>and</strong> pi+1 is the set of all the triangles for which their circumsphere contains pi+1.<br />
We consider a triangulation Ti <strong>and</strong> a point pi+1 outside Ti. <strong>The</strong> cavity Cp(Ti, pi+1)<br />
associated <strong>to</strong> Ti <strong>and</strong> pi+1 is the set of all the triangles for which their circumsphere contains<br />
pi+1 completed by all triangles that can be formed by joining all the edges of Ti visible by<br />
pi+1.
76 CHAPTER 3. MESH GENERATION<br />
pi+1<br />
B(Ti, pi+1)<br />
pi+1<br />
B(Ti, pi+1)<br />
Figure 3.12: Delaunay triangulation Ti+1 In the left Figure, pi+1 is inside Ti <strong>and</strong>, in the<br />
right Figure, pi+1 is outside Ti.<br />
Property 3.4.8 <strong>The</strong> cavity Cp(Ti, pi+1) is star shaped <strong>and</strong> pi+1 belong <strong>to</strong> its Haddad<br />
kernel.<br />
A polygon is star-shaped with respect <strong>to</strong> pi+1 if, for each point pk, k = 1 . . . , Nc<br />
of the polygon the edge e(pi+1, pk) lies entirely within the polygon. <strong>The</strong> set of all points<br />
pi+1 with the described property is called the kernel of the polygon, or its Haddad Kernel.<br />
Figure ?? illustrate what we call a star shaped cavity. A convex polygons is star<br />
shaped, but the inverse is not true. Thanks <strong>to</strong> property 3.4.8, it is quite easy <strong>to</strong> build<br />
a triangulation of the cavity, simply by adding Nc triangles. This set of new triangles is<br />
called the ball B(Ti, pi+1).<br />
Let us assume that we have build the Delaunay Triangulation Ti with the first i<br />
points of the set S.<br />
It is possible <strong>to</strong> build iteratively the delaunay triangulation Ti+1, i.e. using Ti <strong>and</strong><br />
pi+1. We define the Delaunay kernel as the following procedure<br />
Ti+1 = Ti − C(Ti, pi+1) + B(Ti, pi+1)<br />
that consist in removing from the triangulation elements of C(Ti, pi+1) that violate the<br />
incircle property (i) of 3.4.6 <strong>and</strong> subsequently <strong>to</strong> triangulate the cavity with the ball<br />
B(Ti, pi+1) Figure 3.12 illustrates the Delaunay kernel.<br />
Property 3.4.9 if Ti is the Delaunay triangulation of the convex hull of the i first points<br />
of a set S, then Ti+1, the triangulation constructed using the Delaunay kernel is a Delaunay<br />
triangulation
3.4. DELAUNAY AND VORONOÏ 77<br />
Recursive Construction of Delaunay Triangulations: Divide <strong>and</strong> Conquer<br />
<strong>The</strong>re exists a “Divide <strong>and</strong> Conquer” type of algorithm for triangulating a known set of<br />
points. It allows a O(N log N) complexity. Divide <strong>and</strong> conquer (DC) is an important<br />
algorithm design paradigm. It works by recursively breaking down a problem in<strong>to</strong> two or<br />
more sub-problems of the same (or related) type, until these become simple enough <strong>to</strong> be<br />
solved directly. <strong>The</strong> solutions <strong>to</strong> the sub-problems are then combined <strong>to</strong> give a solution <strong>to</strong><br />
the original problem.<br />
<strong>The</strong> Divide <strong>and</strong> Conquer algorithm for triangulations in two dimensions is due <strong>to</strong><br />
Lee <strong>and</strong> Schachter which was improved by Guibas <strong>and</strong> S<strong>to</strong>lfi <strong>and</strong> later by Dwyer. In this<br />
algorithm, one recursively draws a line <strong>to</strong> split the vertices in<strong>to</strong> two sets. <strong>The</strong> Delaunay<br />
triangulation is computed for each set, <strong>and</strong> then the two sets are merged along the splitting<br />
line<br />
Algorithm 1 DelDC(PointIndex left, PointIndex right)<br />
1: n = right - left + 1<br />
2: if n = 2 then<br />
3: InsertInDList (left,right)<br />
4: else if n = 3 then<br />
5: InsertInDList (left,right)<br />
6: InsertInDList (left,left+1)<br />
7: InsertInDList (left+1,right)<br />
8: else if n > 3 then<br />
9: middle = (left + right) ≫ 1<br />
10: DelDC ( left, middle )<br />
11: DelDC ( middle+1, right )<br />
12: DelMerge ( left, middle , right )<br />
13: end if<br />
Algorithm 1 gives the pseudo code of the Divide <strong>and</strong> Conquer Delaunay triangula<strong>to</strong>r<br />
of Gmsh.<br />
<strong>The</strong> set of points is assumed <strong>to</strong> be sorted lexicographically, i.e. points are sorted<br />
form left <strong>to</strong> right <strong>and</strong> from bot<strong>to</strong>m <strong>to</strong> <strong>to</strong>p. Points are subsequently numbered using their<br />
lexicographic index (PointIndex). Figure 3.13 shows a set<br />
of 9 points sorted lexicographically.<br />
S = {p1, p2, . . . , p9}<br />
A doubly linked circular list is assigned <strong>to</strong> every point pi of the set S. This data<br />
structure contains every point pj that is connected through a mesh edge <strong>to</strong> point pi. Data<br />
are s<strong>to</strong>red in the list in the counter-clockwise sense, as it is pictured in Figure 3.14. <strong>The</strong><br />
list is doubly-linked i.e. it is possible <strong>to</strong> advance forward <strong>and</strong> backward.<br />
Four functions have <strong>to</strong> be implemented in order <strong>to</strong> use the doubly-linked lists.<br />
Function InsertInDList(i,j) adds edge (i,j) in the triangulation i.e. inserts point
78 CHAPTER 3. MESH GENERATION<br />
p1<br />
S<br />
p2<br />
p3<br />
p4<br />
Figure 3.13: A set of points sorted lexicographically<br />
p2<br />
p3<br />
p4<br />
p6<br />
p6 p5 p3<br />
Figure 3.14: <strong>The</strong> doubly-linked circular list associated <strong>to</strong> point p4.<br />
p5<br />
p5<br />
p7<br />
p6<br />
p8<br />
p2<br />
p9
3.4. DELAUNAY AND VORONOÏ 79<br />
j in the list of adjacencies of i <strong>and</strong> inserts i in the list of adjacencies of j. Function<br />
DeleteInDList(i,j) deletes edge (i,j) from the triangulation. Functions k =<br />
Predecessor(j) <strong>and</strong> k = Successor(i,j) respectively computes the predecessor <strong>and</strong><br />
the successor k <strong>to</strong> point j in the adjacency list of i.<br />
<strong>The</strong> DelDC function (see algorithm 1) builds a Delaunay triangulation for the subset<br />
of points<br />
Ssubset = {pleft, pleft+1, . . . , pright}.<br />
Three trivial cases are treated:<br />
• If the number of points n = right − left + 1 in Ssubset is less that n = 2, the<br />
triangulation contains no edge;<br />
• If n = 2, one edge is added in the triangulation;<br />
• If n = 3, three edges are created that form one triangle.<br />
If n > 3, the middle point of Ssubset is computed. <strong>The</strong> DelDC function is called twice<br />
recursively with ranges of half the initial size: DelDC(left,middle) <strong>and</strong> DelDC(middle+1,right).<br />
When those two function calls are terminated, both sets of points going from left <strong>to</strong><br />
middle <strong>and</strong> from middle+1 <strong>to</strong> right are Delaunay triangulations. A procedure that we<br />
call DelMerge enables <strong>to</strong> merge the two disconnected Delaunay triangulations <strong>to</strong> form a<br />
unique Delaunay triangulation of the whole range going from left <strong>to</strong> right<br />
<strong>The</strong> first part of the DelDC procedure is illustrated graphically at Figure ??. <strong>The</strong><br />
set of points is first split in two subsets S1 <strong>and</strong> S2 (part (a) of Figure ??). <strong>The</strong>n, each<br />
part is split again, giving four subsest S11, S12, S21 <strong>and</strong> S22 (part (b) of Figure ??). <strong>The</strong><br />
recursion s<strong>to</strong>ps when sub-sets of points have at most three points. At this point, every<br />
subset can be processed trivially (part (c) of Figure ??).<br />
<strong>The</strong> second part of the DelDC procedure is illustrated graphically at Figure 3.16. Delaunay<br />
triangulations DT (S11) <strong>and</strong> DT (S12) are merged as well as DT (S21) <strong>and</strong> DT (S22),<br />
forming two Delaunay triangulations DT (S1) <strong>and</strong> DT (S2) (part (a) of Figure 3.16). <strong>The</strong>n<br />
DT (S1) <strong>and</strong> DT (S2) are merged <strong>to</strong> form the final result DT (S) (part (b) of Figure 3.16).<br />
Let us now describe the most complex part of the algorithm, i.e. the DelMerge<br />
procedure. We will illustrate it using DT (S1) <strong>and</strong> DT (S2). <strong>The</strong> DelMerge procedure<br />
stars by computing the lower common tangent (LCT) <strong>and</strong> the upper common tangent<br />
(UCT) of the union of both triangulations (Figure 3.17).<br />
Edges UCT <strong>and</strong> LCT are edges of the Delaunay triangulation of the union of the two<br />
sets because they belong <strong>to</strong> the convex hull <strong>and</strong> Delaunay triangulations are triangulations<br />
of the convex hull. <strong>The</strong> merging process MergeDC aims at filling the empty gap between<br />
the two triangulations DT (S1) <strong>and</strong> DT (S2),<br />
<strong>The</strong> MergeDC procedure starts from the LCT with its two points l <strong>and</strong> r. Even though<br />
triangles surrounding those two points are part of respectively DT (S1) <strong>and</strong> DT (S2), they<br />
may not be part of DT (S).
80 CHAPTER 3. MESH GENERATION<br />
p1<br />
S1<br />
p2<br />
p3<br />
p4<br />
p5<br />
p7<br />
p6<br />
p8<br />
S2<br />
p9<br />
p4<br />
p5<br />
p7<br />
S11 S12 S21<br />
(a) (b)<br />
S11 S12<br />
S22<br />
p1<br />
p2<br />
p3<br />
p4<br />
(c)<br />
Figure 3.15: Illustration of the Divide <strong>and</strong> Conquer procedure.<br />
p1<br />
p5<br />
p7<br />
S21<br />
p6<br />
p2<br />
p3<br />
p8<br />
p9<br />
p6<br />
p8<br />
S22<br />
p9
3.4. DELAUNAY AND VORONOÏ 81<br />
S1<br />
p1<br />
p2<br />
p3<br />
p4<br />
p5<br />
p7<br />
p6<br />
p8<br />
S2<br />
p9<br />
(a) (b)<br />
Figure 3.16: Illustration of the DelMerge procedure of the Divide <strong>and</strong> Conquer procedure.<br />
This procedure merges the two left triangulations DT (S1) <strong>and</strong> DT (S2) <strong>to</strong> form the final<br />
result DT (S).<br />
ul,l2<br />
ll,l<br />
UCT<br />
l1<br />
LCT<br />
Figure 3.17: Computation of both lower common tangent (LCT) <strong>and</strong> the upper common<br />
tangent (UCT) of the union of both triangulations. Point indices like l,ll or l1 refer <strong>to</strong> the<br />
notations of algorithm 2<br />
p1<br />
r1<br />
S<br />
ur<br />
p2<br />
p3<br />
lr,r<br />
r2<br />
p4<br />
p5<br />
p7<br />
p6<br />
p8<br />
p9
82 CHAPTER 3. MESH GENERATION<br />
ul,l2<br />
ll,l<br />
UCT<br />
l1<br />
Figure 3.18: One step of the merging procedure.<br />
Consider point r in Figure 3.17. Edge (r,r1) is the one the is the Predecessor of<br />
LCT in r’s adjacency list <strong>and</strong> edge (r,r2) is the one the is the Predecessor of (r,r1) in r’s<br />
adjacency list. We apply Lawson’s criterion <strong>to</strong> edge (r,r1), i.e. look if point r2 lies inside<br />
the circumcircle of triangle (l,r,r1). If it is not the case, then triangle (l,r,r1) cannot be<br />
excluded regarding <strong>to</strong> DT (S2).<br />
Similarly, consider point l in Figure 3.17. Edge (l,l1) is the one the is the Successor<br />
of LCT in l’s adjacency list <strong>and</strong> edge (l,l2) is the one the is the Successor of (l,l1) in l’s<br />
adjacency list. We apply Lawson’s criterion <strong>to</strong> edge (l,l1), i.e. look if point l2 lies inside<br />
the circum circle of triangle (l,l,l1). If it is not the case, then triangle (r,l,l1) cannot be<br />
excluded regarding <strong>to</strong> DT (S1).<br />
Among the two possible new edges (r,l1) <strong>and</strong> (l,r2) that may be added <strong>to</strong> the triangulation,<br />
edge (r,l1) is chosen because it satisfies the incircle property (see Figure 3.18).<br />
In the particular case of Figure 3.17, the process can be continued two times (see<br />
Figure 3.4.3).<br />
At the next step (Figure 3.20, part (a)), it is clear that edge (r,r1) cannot be part of<br />
the triangulation because triangle (l,r,r1) has its circumcircle that contains r2. Note that<br />
Lawson’s criterion is symmetric, which means that, if the circumcircle of triangle (l,r,r1)<br />
contains r2, then the circumcircle of triangle (l,r,r2) contains r1. At this point, we simply<br />
replace edge (r,r1) by edge (l,r2) <strong>and</strong> continue the process.<br />
r1<br />
ur<br />
lr,r<br />
r2
3.4. DELAUNAY AND VORONOÏ 83<br />
ul,l2<br />
ll<br />
ul,l1<br />
ll<br />
l<br />
l1<br />
r<br />
ur,l1<br />
lr<br />
r2<br />
ul,l1<br />
Figure 3.19: Two steps of the merging procedure.<br />
l<br />
r<br />
ur,r1<br />
lr<br />
r2<br />
ul,l1<br />
(a) (b)<br />
Figure 3.20: Three steps of the merging procedure.<br />
ll<br />
ll<br />
l<br />
ur,r1<br />
lr<br />
r<br />
l<br />
r<br />
ur=r1<br />
lr<br />
r2
84 CHAPTER 3. MESH GENERATION<br />
Algorithm 2 MergeDC(PointIndex left, PointIndex mid, PointIndex right)<br />
1: [ll,lr] = LowerCommonTangent(left, mid, right) , l = ll, r = lr<br />
2: [ul,ur] = UpperCommonTangent(left, mid, right)<br />
3: while l = ul or r = ur do<br />
4: b = false<br />
5: InsertInDList (l,r)<br />
6: r1 = Predecessor (r,l)<br />
7: while true do<br />
8: r2 = Predecessor(r, r1)<br />
9: if not InCirlce (l,r,r1,r2) then<br />
10: break<br />
11: else<br />
12: DeleteFromList (r,r1), r2=r1<br />
13: end if<br />
14: end while<br />
15: l1 = Successor (l,r)<br />
16: while true do<br />
17: l2 = Successor(l, l1)<br />
18: if not InCirlce (r,l,l1,l2) then<br />
19: break<br />
20: else<br />
21: DeleteFromList (l,l1), l2=l1<br />
22: end if<br />
23: end while<br />
24: if b or InCircle(l,r,r1,l1) then<br />
25: r = r1<br />
26: else<br />
27: l = l1<br />
28: end if<br />
29: end while<br />
30: InsertInDList (l,r)<br />
<strong>An</strong> implementation of that algorithm is provided in Gmsh. Source code can be found<br />
in gmsh/<strong>Mesh</strong>/Divide<strong>An</strong>dConquer.cpp.<br />
3.5 Planar <strong>Mesh</strong>ing<br />
This sections deals with the following issue: how <strong>to</strong> generate a well shaped triangulation<br />
that respects a size criterion δ(x) on a planar domain S.
3.5. PLANAR MESHING 85<br />
0.15<br />
0.125<br />
0.1<br />
0.075<br />
0.05<br />
0.025<br />
0<br />
4 5 8<br />
3<br />
12 8<br />
2 13 3<br />
16 14<br />
15<br />
14 2<br />
3.5.1 <strong>The</strong> general procedure<br />
1<br />
1<br />
17<br />
6<br />
17<br />
18<br />
-0.075 -0.05 -0.025 0 0.025 0.05 0.075<br />
10<br />
19 20<br />
16<br />
15<br />
20<br />
11 9<br />
18 23 22<br />
Figure 3.21: A simple 2D model (conge.geo).<br />
Let us start by defining a simple planar surface in Gmsh (Figure 3.21). This model is<br />
contained in the Gmsh distribution <strong>and</strong> is called conge.geo. This model is composed of<br />
two planar surfaces, 20 model edges <strong>and</strong> 25 model vertices. We consider a uniform size<br />
field δ = 0.005. <strong>The</strong> first step for doing the mesh is <strong>to</strong> discretize (or mesh) the edges of the<br />
model. This operation is done computing the primitive (3.8) for every edge of the model.<br />
<strong>The</strong> result is presented in Figure 3.22. <strong>The</strong>n, each of the two model faces is triangulated.<br />
At first, all the mesh vertices that bounds the model face are considered. Four extra<br />
mesh vertices are added <strong>to</strong> the list. <strong>The</strong>se four vertices are the corners of a rectangle that<br />
encompasses the model surfaces (Figure 3.24).<br />
<strong>The</strong> convex hull of the domain is then triangulated using any convenient (<strong>and</strong> fast)<br />
algorithm. In Gmsh, we use the divide <strong>and</strong> conquer approach that is presented in §3.4<br />
(Figure 3.24).<br />
Triangulating the set of points using the pre-cited algorithm produces a Delaunay<br />
triangulation of the convex hull of the point set, i.e. the rectangle bounded by the additional<br />
four points. Yet, there is no guarantee that all the edges of the 1D mesh are present<br />
in the triangulation. <strong>The</strong> Delaunay triangulation only deals with points <strong>and</strong> triangles, not<br />
24<br />
25<br />
19<br />
21<br />
4<br />
7<br />
13<br />
9<br />
10<br />
5<br />
7<br />
11<br />
6<br />
12
86 CHAPTER 3. MESH GENERATION<br />
with edges.<br />
0.15<br />
0.125<br />
0.1<br />
0.075<br />
0.05<br />
0.025<br />
0<br />
-0.075 -0.05 -0.025 0 0.025 0.05<br />
Figure 3.22: <strong>The</strong> 1D mesh of model conge.geo.<br />
Some of the mesh edges that discretize the model edges may not be in the triangulation.<br />
<strong>The</strong>re exists one condition that ensure that all the edges of the 1D mesh will be<br />
present in the initial Delaunay triangulation. Consider an edge with points p1 <strong>and</strong> p2.<br />
This edge will be present in the Delaunay triangulation if the circle centered at 1<br />
2 (p2 + p1)<br />
of diameter p2 − p1 does not contain any other point of the set than p1 <strong>and</strong> p2. In<br />
practice, it is possible <strong>to</strong> refine the 1D mesh in order <strong>to</strong> fullfill this circle criterion.<br />
It is also possible <strong>to</strong> recover the missing 1D edges using edge swaps. In our first<br />
simple case, all edges of the 1D mesh are indeed present in the Delaunay triangulations<br />
<strong>and</strong> nothing has <strong>to</strong> be done. We will present in a further discussion examples where edge<br />
recovery has been applied as well as the edge recovery algorithm. Note that, when an edge<br />
has <strong>to</strong> be recovered, the resulting triangulation is not anymore a Delaunay triangulation.<br />
This kind of triangulation is sometimes called a constrained Delaunay triangulation.<br />
<strong>An</strong>other issue that may occur during the definition of initial mesh concerns possible<br />
self-intersections of 1D mesh edges. We assume here that model edges of the geometry<br />
do not self intersect. However, this does not guarantee that, even if the model edges G 1 j<br />
that constitute the boundaries of the domain are non intersecting, the corresponding 1D<br />
meshes do not self intersect. Figure 3.23 shows two model edges that are very close <strong>to</strong><br />
0.075
3.5. PLANAR MESHING 87<br />
Figure 3.23: A geometry with two isl<strong>and</strong>s that are very close <strong>to</strong> each other. <strong>The</strong> first<br />
image shows the initial 1D mesh that respects mesh size field. <strong>The</strong> second image shows<br />
the first iteration of the recovery algorithm. <strong>The</strong> third image shows the final mesh that<br />
was possible <strong>to</strong> realize after 2 recovery iterations<br />
each other. Yet, even the geometry is itself not self-intersecting, the first 1D generated<br />
mesh intersects itself. This can be been considered as a critical issue: modifying the mesh<br />
size field by h<strong>and</strong> locally cannot be considered when several thous<strong>and</strong> of boundaries are<br />
<strong>to</strong> be involved. It is therefore m<strong>and</strong>a<strong>to</strong>ry <strong>to</strong> define a systematic recovery procedure. Such<br />
an algorithm illustrated in Figure 3.23 works as follow:<br />
1. A Delaunay mesh that contains all points of the 1D mesh is initially constructed<br />
using a divide <strong>and</strong> conquer algorithm [?].<br />
2. Missing edges are recovered using edge swaps [?]. If a mesh edge ei that belongs <strong>to</strong><br />
the 1D mesh is <strong>to</strong> be swapped for recovering edge ej, then the mesh edges ei <strong>and</strong> ej<br />
that both belong <strong>to</strong> the 1D mesh intersect.<br />
3. All intersecting edges ek are split in 2 segments <strong>and</strong> the new point is snapped on<strong>to</strong><br />
the geometry. <strong>The</strong>n, we go back <strong>to</strong> the first step until the list of intersecting edges<br />
is empty.<br />
If an intersecting edge is smaller than the geometrical <strong>to</strong>lerance, then an error message is<br />
thrown claiming that the geometry is self intersecting.<br />
Triangles that are outside the domain have <strong>to</strong> be removed form the triangulation.<br />
This can be done simply by choosing one triangle that contains one of the four corners<br />
<strong>and</strong> <strong>to</strong> walk through its edge-neighbors, recursively, s<strong>to</strong>pping the process when crossing<br />
an edge that belongs <strong>to</strong> the boundary of the domain. <strong>The</strong> element that is on the other<br />
side of this edge is inside the domain. <strong>The</strong>n, we walk again through the neighbors allow<br />
<strong>to</strong> get all element that are inside the domain(Figure 3.25).<br />
Points are inserted in the domain in order <strong>to</strong> refine the triangulation. <strong>The</strong> way<br />
points are inserted is the key point of the method. Different algorithms are available in<br />
Gmsh. We will present them in forthcoming sections.(Figure 3.25).
88 CHAPTER 3. MESH GENERATION<br />
Figure 3.24: <strong>The</strong> first <strong>and</strong> second stages of the 2D meshing procedure for the model<br />
conge.geo.
3.5. PLANAR MESHING 89<br />
0.15<br />
0.125<br />
0.1<br />
0.075<br />
0.05<br />
0.025<br />
0<br />
-0.075 -0.05 -0.025 0 0.025 0.05 0.075<br />
-0.075 -0.05 -0.025 0 0.025 0.05 0.075<br />
Figure 3.25: <strong>The</strong> fourth <strong>and</strong> fifth stages of the 2D meshing procedure for the model<br />
conge.geo.<br />
3.5.2 Boundary edges recovery<br />
Triangulating the set of points using a Delaunay-based procedure produces a Delaunay<br />
triangulation of the convex hull of the set. Yet, there is no guarantee that all the edges of<br />
the 1D mesh are present in the triangulation. As an example, let us consider the initial<br />
mesh of Figure 3.26. <strong>The</strong> boundaries of this U-shaped domain were discretized using a<br />
prescribed spacing. <strong>The</strong> Delaunay triangulation of this set of points does not contain the<br />
mesh edge with nodes 3 <strong>and</strong> 4.<br />
Figure 3.27 presents the edge recovery procedure that enables <strong>to</strong> enforce the presence<br />
of any edge M 1 i in the mesh. <strong>The</strong> procedure works as follows:<br />
0.15<br />
0.125<br />
0.1<br />
0.075<br />
0.05<br />
0.025<br />
• A cavity containing triangles that are crossed by the edge <strong>to</strong> recover is set up first<br />
(grey triangles in the first Figure).<br />
• Internal edges of the cavity are counted. Here, we count initially 7 internal edges<br />
that are all crossed by M 1 i .<br />
• Edges of the cavity MISSING SENTENCE ...<br />
3.5.3 Point insertion <strong>and</strong> Delaunay kernel<br />
Assume that an initial mesh that matches the 1D boundary is available. New points have<br />
now <strong>to</strong> be insterted in the mesh in order <strong>to</strong> build triangles that have both a good sizes<br />
0
90 CHAPTER 3. MESH GENERATION<br />
2<br />
48<br />
47<br />
46<br />
45<br />
44<br />
43<br />
42<br />
41<br />
1<br />
72<br />
71<br />
3<br />
4<br />
70<br />
69<br />
Figure 3.26: Initial Delaunay mesh based for the U model 2Drecovery.geo.<br />
Figure 3.27: Boundary edge recovery procedure that recovers all the edges of the 1D<br />
discretization procedure using swaps.<br />
68<br />
67<br />
6<br />
56<br />
55<br />
54<br />
53<br />
52<br />
51<br />
50<br />
49<br />
5<br />
66<br />
65<br />
7<br />
57<br />
58<br />
59<br />
60<br />
61<br />
62<br />
63<br />
64<br />
8<br />
Y<br />
Z<br />
X
3.5. PLANAR MESHING 91<br />
<strong>and</strong> shapes. <strong>The</strong>re exist a bunch of point insertion techniques that are described in the<br />
litterature.<br />
One first idea would be for example <strong>to</strong> insert a new vertex in the middle of the longest<br />
edge with points p1 <strong>and</strong> p2 (using, of course, its adimensional length). This is the default<br />
surface meshing algorithm of Gmsh. We are aware that this point insertion algorithm has<br />
a fundamental flaw. <strong>The</strong>re is indeed no guarantee that there exist no point in the mesh<br />
that is closer <strong>to</strong> the middle point than p1 <strong>and</strong> p2. This point insertion algorithm may then<br />
generate a new edge that is indeed <strong>to</strong>o short <strong>and</strong> that will have <strong>to</strong> be removed afterwards<br />
through edge collapsing.<br />
A variant of the previous technique is used in BAMG [?]. It consist in saturating<br />
the edges of the mesh with points, using e.g. the 1D technique described in §3.3. A bucket<br />
tree datastructure is used <strong>to</strong> remove points that are <strong>to</strong>o close. Thanks <strong>to</strong> that filtering<br />
operation, no point removal has <strong>to</strong> be performed afterwards.<br />
<strong>An</strong> optimal point insertion procedure should be able <strong>to</strong> insert points that will not<br />
have <strong>to</strong> be removed afterwards. In other words, one should not insert points that are <strong>to</strong>o<br />
close <strong>to</strong> other points. <strong>An</strong> alternative <strong>to</strong> edge splitting would be insert the new point at the<br />
circumcenter of the largest triangle [?]. We could define the adimensional size of a triangle<br />
t(a, b, c) as the ratio between its circumradius <strong>and</strong> the mesh size at its circumcenter. <strong>The</strong><br />
circumcenter C of a planar triangle t can be computed as follows:<br />
This leads <strong>to</strong> the system:<br />
(bx − ax) (by − ay)<br />
(cx − ax) (cy − ay)<br />
(ax − Cx) 2 + (ay − Cy) 2 = (bx − Cx) 2 + (by − Cy) 2<br />
(ax − Cx) 2 + (ay − Cy) 2 = (cx − Cx) 2 + (cy − Cy) 2 .<br />
Cx<br />
Cy<br />
<br />
= 1<br />
<br />
b2 x − a<br />
2<br />
2 x + b2 y − a2 y<br />
c2 x − a2 x + c2 y − a2 y<br />
Circumradius Rt <strong>and</strong> inner radius rt of a triangle t are nicely related as<br />
Rt = C − a = 1<br />
2rt<br />
<strong>The</strong> adimensional size lt of triangle t is computed as<br />
(3.10) lt = √ 3 Rt<br />
δ(C) .<br />
b − ac − aa − b<br />
b − a + c − a + a − b .<br />
<strong>The</strong> √ 3 fac<strong>to</strong>r in (3.10) is explained by the fact that the circumradius of an equilateral<br />
triangle with edges of size 1 being Rt = 1/ √ 3.<br />
Triangles are sorted with respect <strong>to</strong> this adimensional length. A new point is inserted<br />
at C <strong>and</strong> the Bowyer-Watson algorithm is used <strong>to</strong> locally recreate a new Delaunay triangulation<br />
with the additional point. <strong>The</strong> algorithm s<strong>to</strong>ps when lt < lmax with lmax ≥ 1. It<br />
is indeed NOT a good idea <strong>to</strong> take lmax > 1. Imagine that triangle t has an adimensional<br />
<br />
.
92 CHAPTER 3. MESH GENERATION<br />
Figure 3.28: Illustration of the Bowyer-Watson algorithm with a point insertion scheme<br />
based on the circumcenter of the largest triangle<br />
length of lt = 1.1. Inserting a new point at its circumcenter would generate edges that are<br />
about two times smaller than the existing ones that are of size 1.1. We define a range of<br />
acceptable sizes [lmin, lmax] in a way that splitting a large triangle edge lt > lmax would<br />
not generate a triangle that is <strong>to</strong>o small i.e. for which lt < lmin. This can be translated<br />
in lmax = 2lmin. <strong>An</strong> usual choice for the acceptable range is <strong>to</strong> center it around 1 i.e.<br />
lmax + lmin = 2. This gives [lmin, lmax] = [2/3, 4/3]. Figure 3.28 gives an example of the<br />
Bowyer <strong>and</strong> Watson algorithm with a point insertion based on the circumcenter of the<br />
largest triangle. Points on the final mesh are nicely distributed so that only a very light<br />
optimization (laplace smoothing) is necessary for obtaining the final mesh.<br />
All point insertion algorithms that we have described before do not converge <strong>to</strong> a<br />
mesh that is composed of a majority of equilateral triangles. Frontal methods have the<br />
advantage of generating nicely shaped triangles. Yet, those latter methods are less robust<br />
<strong>and</strong> slower than Delaunay meshers. It is possible <strong>to</strong> build a hybrid method that uses the<br />
Bowyer <strong>and</strong> Watson algorithm that guarantees always <strong>to</strong> play with a valid mesh but where<br />
points are inserted in a “frontal fashion”. Such a frontal-delaunay method should remain<br />
fast, which means that a point that is inserted should never be removed afterwards.<br />
3.5.4 <strong>An</strong>isotropic Delaunay meshing<br />
<strong>The</strong> Delaunay kernel as it has been explained in §3.4 can be extended so that distances<br />
<strong>and</strong> angles are measured with respect <strong>to</strong> a given metric (see (2.12))<br />
M =<br />
E F<br />
F G<br />
<br />
.
3.5. PLANAR MESHING 93<br />
Consider first the case of a spatially constant metric. <strong>The</strong> <strong>The</strong> circumcenter C of a planar<br />
triangle t with respect <strong>to</strong> the metric M can be computed as follows:<br />
E(ax − Cx) 2 + G(ay − Cy) 2 + 2F (ax − Cx)(ay − Cy) =<br />
E(bx − Cx) 2 + G(by − Cy) 2 + 2F (bx − Cx)(by − Cy)<br />
E(ax − Cx) 2 + G(ay − Cy) 2 + 2F (ax − Cx)(ay − Cy) =<br />
E(cx − Cx) 2 + G(cy − Cy) 2 + 2F (cx − Cx)(cy − Cy)<br />
This leads <strong>to</strong> the system:<br />
E(bx − ax) + F (by − ay) G(by − ay) + F (bx − ax)<br />
(3.11)<br />
G(cx − ax) + F (cy − ay) G(cy − ay) + F (cy − ay)<br />
1<br />
2<br />
<strong>The</strong> circumradius Rt is computed as<br />
Cx<br />
Cy<br />
E(b 2 x − a 2 x) + G(b 2 y − a 2 y) + 2F (bxby − axay)<br />
E(c 2 x − a 2 x) + G(c 2 y − a 2 y) + 2F (cxcy − axay)<br />
R 2 t = E(Cx − ax) 2 + G(Cy − ay) 2 + 2F (Cx − ax)(Cy − ay).<br />
Bowyer <strong>and</strong> Watson <strong>and</strong> Lawson’s algorithms can be applied straight away using those new<br />
formulas for cicumcenter <strong>and</strong> circumradius <strong>and</strong> the change in a Delaunay code is minimal.<br />
Yet, most of the metrics we consider are not uniform i.e. those metrics vary in space. <strong>The</strong><br />
problem gets tricky because, in a Riemannian space (i.e. a space with a smooth metric),<br />
the notion of distance involves the computation of geodesics. <strong>The</strong> media<strong>to</strong>r of two points<br />
is not a line anymore <strong>and</strong> the Voronoi diagram is composed of curvilinear cells. Delaunay<br />
meshes in a general Riemannian sense are curvilinear. This is indeed a nice <strong>to</strong>pic that has<br />
been tackled in [?]. Yet, it does not lead <strong>to</strong> practical applications.<br />
It is indeed possible <strong>to</strong> use a metric that is constant locally i.e. <strong>to</strong> work on the so<br />
called tangent plane at a given point x. This is the usual way of dealing with anisotropic<br />
Delaunay meshing. <strong>The</strong> choice of the point at which the metric is computed is quite<br />
important. We can still choose <strong>to</strong> compute the metric at the circumcenter of the triangle.<br />
Yet, the position of the circumcenter depends on the metric itself, leading <strong>to</strong> a nonlinear<br />
version of problem (3.11), i.e. where E, F <strong>and</strong> G all depend on Cx <strong>and</strong> Cy. In Gmsh,<br />
we perform 2 or 3 fixed point iterations of (3.11). This gives usually a sufficiently precise<br />
location of the circumcenter.<br />
3.5.5 Practical implementation<br />
To our opinion, the most important aspect of a practical implementation of a Bowyer <strong>and</strong><br />
Watson algorithm is its lightness. <strong>The</strong> algorithm should use the fewest possible amount of<br />
memory (especially in 3D, but also in 2D). <strong>The</strong> procedure should of course be reasonably<br />
fast but this is less important.<br />
Recall now the definition of the Delaunay kernel. We consider a triangulation Ti<br />
<strong>and</strong> a point pi+1 outside Ti. <strong>The</strong> cavity Cp(Ti, pi+1) associated <strong>to</strong> Ti <strong>and</strong> pi+1 is the set<br />
<br />
=<br />
<br />
.
94 CHAPTER 3. MESH GENERATION<br />
of all the triangles for which their circumsphere contains pi+1 completed by all triangles<br />
that can be formed by joining all the edges of Ti visible by pi+1. We define the Delaunay<br />
kernel as the following procedure<br />
Ti+1 = Ti − C(Ti, pi+1) + B(Ti, pi+1)<br />
that consist in removing from the triangulation elements of C(Ti, pi+1) that violate the<br />
incircle property (i) of 3.4.6 <strong>and</strong> subsequently <strong>to</strong> triangulate the cavity with the ball<br />
B(Ti, pi+1). Figure 3.12 illustrates the Delaunay kernel.<br />
<strong>The</strong> following datastructure is used in Gmsh for computing the Delaunay kernel.<br />
class MTri3<br />
{<br />
bool deleted;<br />
double adimensional_size;<br />
MVertex *v[3];<br />
MTri3 *neigh[3];<br />
// ...<br />
};<br />
A point insertion procedure typically inserts <strong>and</strong> removes triangles from a set. On<br />
the other side, it is usually interesting <strong>to</strong> s<strong>to</strong>re the triangles in a datastructure that allows<br />
<strong>to</strong> have access <strong>to</strong> the largest one. Binary trees allow <strong>to</strong> add <strong>and</strong> remove elements in<br />
logarithmic time. In our implementation, we have decided <strong>to</strong> add a deleted tag <strong>to</strong> every<br />
triangle that tells if it is deleted. It is only when a traversal of the tree is performed that<br />
tagged triangles are truly deleted (it is then a constant time operation).<br />
<strong>The</strong> adimensional size of the triangle is also computed by the construc<strong>to</strong>r of the<br />
class MTri3 <strong>and</strong> s<strong>to</strong>red. <strong>The</strong> three vertices of the triangle are also s<strong>to</strong>red as well as its<br />
three neighbors. A binary tree std::set with a comparison<br />
function compareTri3Ptr that compares two MTri3* with respect <strong>to</strong> their adimensional<br />
size is created. <strong>The</strong> worst triangle is the one on the <strong>to</strong>p of the tree, which means that the<br />
Bowyer <strong>and</strong> Watson algorithm can be written as<br />
while (1){<br />
MTri3 *worst = *AllTris.begin();<br />
if (worst->isDeleted()){<br />
delete worst;<br />
AllTris.erase(AllTris.begin());<br />
}<br />
else{<br />
if (worst->getAdimensionalSize() < LMAX) break;<br />
insertAPoint(AllTris, worst);<br />
}<br />
};
3.6. SURFACE MESHING 95<br />
Let’s now be more clear about function insertAPoint. <strong>The</strong> aim of this function is <strong>to</strong> break<br />
triangle worst. We can either choose <strong>to</strong> add the new point pi+1 on its circumcenter, <strong>to</strong><br />
put it somewhere on a Voronoi edge or <strong>to</strong> use any fancy point insertion policy. <strong>The</strong> first<br />
task of the algorithm is <strong>to</strong> compute the Delaunay cavity Cp(Ti, pi+1). This task can be<br />
done recursively:<br />
void computeCavity(std::list &closure,<br />
std::list &cavity,<br />
double p[2], MTri3 *t)<br />
{<br />
t->setDeleted(true);<br />
cavity.push_back(t);<br />
for (int i = 0; i < 3; i++){<br />
MTri3 *neigh = t->getNeigh(i) ;<br />
if (!neigh)<br />
closure.push_back(edgeXface(t, i));<br />
else if (!neigh->isDeleted()){<br />
if(inCircumCircle(neigh, p))<br />
computeCavity(closure, cavity, p, neigh);<br />
else<br />
closure.push_back(edgeXface(t, i));<br />
}<br />
}<br />
}<br />
In our algorithm, not only the cavity is computed but also its closure i.e. a list of edges of<br />
triangles that form the “shell” of the cavity. This shell will be used for both creating the<br />
new triangles <strong>and</strong> reconnecting the new triangles with their neighbors on the other side of<br />
the shell.<br />
3.6 Surface <strong>Mesh</strong>ing<br />
Curved surface shapes designed by CAD systems are usually defined by parametric surfaces,<br />
for example, NURBS [?]. Let us consider a model face G2 i with its underlying<br />
geometry, in this case a surface S ∈ R3 with its parametrization p(u, v) ∈ S, where the<br />
domain of definition of the parameters (u, v) is defined by a series of boundary curves. <strong>An</strong><br />
example of such a surface is given in Figure 3.29, which shows one of the 76 model faces<br />
of the propeller in the parametric space (left) <strong>and</strong> in real space (right). Three features of<br />
surface S, common in CAD descriptions, make its meshing non-trivial:<br />
1. S is periodic. <strong>The</strong> <strong>to</strong>pology of the model face is modified in order <strong>to</strong> define its closure<br />
properly. A seam is present two times in the closure of the model face. <strong>The</strong>se two<br />
occurrences are separated by one period in the parametric space.
96 CHAPTER 3. MESH GENERATION<br />
2. S is trimmed: it contains four holes <strong>and</strong> one of them is crossed by the seam.<br />
3. One of the model edges of S is degenerated. This is done for accounting of a singular<br />
point in the parametrization of the surface. This kind of degeneracy is present in<br />
many shapes: spheres, cones <strong>and</strong> other surfaces of revolution.<br />
Figure 3.29: Geometry of a model face in parametric space (left) <strong>and</strong> in real space (right).<br />
Two seam edges are present in the face. <strong>The</strong> <strong>to</strong>p model edge is degenerated in one point.<br />
Techniques for generating finite element meshes on curved surfaces are of two kind:<br />
1. techniques for which the surface mesh is generated directly in the real 3-D space;<br />
2. techniques for which the surface mesh is generated in the parametric space.<br />
<strong>The</strong> principal advantage of doing the surface mesh in the 3-D space directly is that no<br />
interface <strong>to</strong> the solid modeler is required. Such algorithms have been used for building<br />
meshes from STL (stereolithography) data files [?], from medical imaging [?] or <strong>to</strong><br />
adapt/modify existing meshes [?]. <strong>The</strong> main drawback of such algorithms is their relative<br />
lack of robustness.<br />
<strong>The</strong> second alternative can be applied only if a parametrization of the surfaces is<br />
available. If it is the case, doing the mesh in the parametric space is usually advantageous<br />
because all the meshing procedures can be applied in the parametric plane. This allows<br />
mesh opera<strong>to</strong>rs <strong>to</strong> be highly robust—we will detail that argument later.<br />
Yet, all surfaces do not always have a parametrization that conserves angles <strong>and</strong><br />
lengths. Consequently, only 2-D algorithms that allow <strong>to</strong> build anisotropic meshes in the<br />
plane can be considered as good c<strong>and</strong>idates for doing surface meshing. Figure 3.30 presents<br />
the surface mesh of the model face of Figure 3.29, both in the parametric space <strong>and</strong> in<br />
the real space. <strong>The</strong> mesh in the real space is isotropic <strong>and</strong> uniform while the one in the
3.6. SURFACE MESHING 97<br />
Figure 3.30: <strong>Mesh</strong> of a model face drawn in the parametric space (left) <strong>and</strong> in the real<br />
space (right).<br />
parametric space is highly anisotropic <strong>and</strong> non uniform. To solve this problem, George <strong>and</strong><br />
Borouchaki [?] have proposed the use of a metric derived from the first fundamental form<br />
of the surface (2.12). <strong>The</strong> metric field is a second order tensor field that has the form, at<br />
any point of the parametric space, of a 2×2 matrix. <strong>The</strong> metric is used <strong>to</strong> define angles <strong>and</strong><br />
distances in parametric space (see Sec. 2.5.2). With their Delaunay approach, the ”empty<br />
circle” property, effectively becomes an ”empty ellipse” property. <strong>An</strong> equivalent “metricbased”<br />
advancing front surface mesh generation algorithms is presented by Cuilliere in<br />
[?]. A more exotic metric-based approach based on packing ellipses has been devised by<br />
Yamada et al. [?] <strong>and</strong> has been used more recently by Lo <strong>and</strong> Wang in [?].<br />
In addition <strong>to</strong> a Delaunay implementation similar <strong>to</strong> [?] <strong>and</strong> a frontal-Delaunay<br />
meshing technique inspired by [?], Gmsh provides an original surface meshing strategy<br />
based on the concept of local mesh modifications [?, ?, ?]. <strong>The</strong> main advantage of the new<br />
approach, compared <strong>to</strong> the other ones based on the Delaunay criterion, is that it does not<br />
require the computation of derivatives of the parametrization. For that reason, the new<br />
approach remains robust even when the parametrization is singular.<br />
Surface meshing algorithm based on local mesh modifications This surface<br />
meshing algorithm works as follows. First, an initial mesh containing all the mesh points<br />
of the curves bounding the face is built in the parametric space using a divide <strong>and</strong> conquer<br />
strategy [?]. <strong>The</strong>n, all the edges of the 1-D discretization are recovered using swaps [?].<br />
Finally, local mesh modifications are applied:<br />
1. Each edge that is <strong>to</strong>o long is split;<br />
2. Each edge that is <strong>to</strong>o short is removed using an edge collapse opera<strong>to</strong>r;<br />
3. Edges for which a better configuration is obtained by swapping are swapped;
0<br />
H h<br />
98 CHAPTER 3. MESH GENERATION<br />
Fig. 1. Shallow water notations for water depth H with a time-independent bathymetry h. Notice that the relative elevation η is usually several<br />
orders of magnitude smaller than the unperturbed depth.<br />
e1<br />
e1<br />
e2<br />
y<br />
e2<br />
Fig. 2. Local mesh modifications. Edge split (<strong>to</strong>p), edge collapse (middle) <strong>and</strong> edge swap (bot<strong>to</strong>m). <strong>The</strong> zone depicted in bold represents the<br />
cavity that is modified by the local mesh modification.<br />
Figure 3.31: Illustration of local mesh modifications.<br />
4. Vertices are re-located optimally.<br />
More precisely, here is how these four local mesh modifications procedures are applied<br />
in Gmsh:<br />
Edge Splitting: <strong>An</strong> edge is considered <strong>to</strong>o long when its adimensional length is greater<br />
than le > 1.4. When split, the two new edges will have a minimal size of 0.7. In<br />
order <strong>to</strong> converge <strong>to</strong> a stable configuration, an edge of size le = 0.7 should not be<br />
considered as a short edge.<br />
Edge Collapsing: <strong>An</strong> edge is considered <strong>to</strong> be short when its adimensional length is<br />
smaller than le < 0.7. <strong>An</strong> edge cannot be collapsed if one of the remaining triangles<br />
after the collapse is inverted in the parametric space.<br />
Edge Swapping: <strong>An</strong> edge is swapped if min (γe1 , γe2 ) < min (γe3 , γe4 ) (see Figure 3.31),<br />
unless<br />
1. it is classified on a model edge;<br />
2. the two adjacent triangles e1 <strong>and</strong> e2 form a concave quadrilateral in the parametric<br />
space;<br />
3. the angle between the triangles normals is greater than a threshold, typically<br />
30 degrees.<br />
Vertex Re-positioning: Each vertex is moved optimally inside the cavity made of all<br />
its surrounding triangles. <strong>The</strong> optimal position is chosen in order <strong>to</strong> maximize the<br />
worst element quality [?].<br />
e3<br />
e5<br />
e3<br />
e4<br />
e6<br />
e4
3.7. 3-D MESH GENERATION 99<br />
For each of these local mesh modification procedures, the opportunity of doing a<br />
mesh modification is evaluated in the real space, i.e., in (x, y, z), while the validity of<br />
a mesh modification is evaluated in the parametric space (u, v). <strong>The</strong>refore, Gmsh mesh<br />
genera<strong>to</strong>rs always retain both real <strong>and</strong> parametric coordinates of any mesh vertex. To<br />
ensure robustness, all the elementary geometrical predicates make use of robust algorithmic<br />
[?].<br />
In practice, this algorithm converges in about 6-8 iterations <strong>and</strong> produces anisotropic<br />
meshes in the parametric space without computing derivatives of the mapping.<br />
Let us illustrate the algorithm on an example. We have meshed the model face of<br />
Figure 3.30 using an analytical size field<br />
δ(x, y, z) = δ0[1 + cos(π(x + y − z)/L)] + ɛ<br />
where L is a characteristic size of the domain <strong>and</strong> ɛ ≪ δ0 < L. Figure 3.32 shows the mesh<br />
in the parametric space at different stages of the algorithm. Note that the derivatives of<br />
the parametrization of the underlying surface are not defined at the singular point so that<br />
any algorithm that requires <strong>to</strong> compute such derivatives would be in trouble in this case.<br />
3.7 3-D <strong>Mesh</strong> <strong>Generation</strong><br />
Once a surface triangulation is available, an au<strong>to</strong>matic mesh generation procedure does<br />
not usually require an interface <strong>to</strong> a CAD system. Indeed, Gmsh interfaces several open<br />
source 3-D tetrahedral mesh generation kernels [?, ?] in addition <strong>to</strong> its own Delaunay<br />
refinement algorithm. <strong>The</strong>se algorithms are st<strong>and</strong>ard [?, ?] <strong>and</strong> will not be explained<br />
here. We focus on two other issues instead:<br />
1. the way Gmsh interfaces multiple mesh generation algorithms;<br />
2. the way Gmsh optimizes the quality of 3-D meshes.<br />
Note that there is a third issue concerning the way Gmsh h<strong>and</strong>les mixed structured/unstructured<br />
grids, <strong>and</strong> that this issues is addressed in Section 3.7.2.<br />
<strong>Mesh</strong> Algorithm Interfaces<br />
Gmsh is able <strong>to</strong> deal with most of the st<strong>and</strong>ard finite element shapes: lines, triangles,<br />
quadrangles, tetrahedra, hexahedra, prisms <strong>and</strong> pyramids. <strong>The</strong> internal mesh data structures<br />
are designed <strong>to</strong> minimize the memory footprint without compromising flexibility:<br />
in addition <strong>to</strong> a integer tag <strong>and</strong> a partition/visualisation index, any element only holds<br />
its ordered list of vertices. With that simple design, Gmsh can load about 12 million<br />
tetrahedra per Gigabyte of memory (28 bytes per tetrahedron, 44 bytes per mesh vertex),<br />
including graphics representation, i.e., OpenGL vertex arrays [?].
100 CHAPTER 3. MESH GENERATION<br />
initial iter. 1 iter. 3<br />
iter. 5 final<br />
Figure 3.32: Illustration of the surface meshing algorithm based on local mesh modifications.<br />
<strong>The</strong> images correspond <strong>to</strong> the initial mesh containing boundary vertices, the mesh<br />
after 1, 3, 5 <strong>and</strong> 8 iterations. At iteration 8, the algorithm has converged. <strong>The</strong> size field<br />
efficiency τ = 0.89 can be considered as excellent: 90 % of the elements have a radii ratio<br />
γK greater that 0.9.
3.7. 3-D MESH GENERATION 101<br />
When “in house” meshing routines are used, Gmsh derives (in the object oriented<br />
sense) enriched data structures specifically tailored for each meshing algorithm. Those<br />
derived structures contain just the right extra information necessary: the parametric coordinates<br />
of a vertex for parametric 2-D meshing algorithms, the neighbors of a tetrahedron<br />
for the 3-D Delaunay algorithm, etc. With this approach the footprint of a tetrahedron is<br />
for example extended <strong>to</strong> 84 bytes, <strong>and</strong> the 3-D Delaunay algorithm implemented in Gmsh,<br />
using a classical Bowyer-Watson algorithm [?], is able <strong>to</strong> build about 7 million tetrahedron<br />
per Gigabyte of memory (including overhead like the data structures of the CAD engine).<br />
When a third party mesh genera<strong>to</strong>r is invoked, Gmsh needs of course <strong>to</strong> allocate the<br />
appropriate structures required by that specific software. But thankfully, while transferring<br />
the data from the third party algorithm in<strong>to</strong> Gmsh, only the minimal internal data<br />
structures need <strong>to</strong> be allocated (i.e., 28 byte per tetrahedron in the 3-D case mentioned<br />
above). This greatly reduces the overhead incurred by interfacing external algorithms.<br />
Tetrahedral <strong>Mesh</strong> Improvement<br />
Tetrahedral mesh improvement is usually required <strong>to</strong> produce 3-D meshes suitable for gridbased<br />
numerical methods [?]. Unfortunately, mesh optimization procedures have a lot <strong>to</strong><br />
do with “black magic”: even if the ingredients required <strong>to</strong> construct a mesh optimization<br />
procedure are well known (essentially swapping <strong>and</strong> smoothing), there is no known “best<br />
recipe”, i.e., no known optimal way of combining those smoothing <strong>and</strong> swapping opera<strong>to</strong>rs.<br />
Gmsh implements its own mesh optimization procedure <strong>to</strong> enhance tetrahedral mesh<br />
quality by means of edge- <strong>and</strong> face-swappings <strong>and</strong> vertex relocations, <strong>and</strong> also interfaces<br />
third party mesh optimizers—in particular the open-source optimizer from Netgen [?].<br />
Interestingly, applying optimization routines one after the other enables <strong>to</strong> produce better<br />
meshes than applying mesh optimizers separately. Figure 3.33 shows the distribution of<br />
elemental qualities on the mesh of a <strong>to</strong>roidal domain containing about 600,000 tetrahedra<br />
(the mesh was generated in about 30 seconds with the “in house” 3-D Delaunay algorithm).<br />
<strong>The</strong> unoptimized mesh contains quite a few ill shaped elements: more than 5000 elements<br />
have an aspect ratio γK below 0.2 <strong>and</strong> the worst shaped element has an aspect ratio of<br />
10 −3 . After one pass of the Gmsh mesh optimizer, which takes about 12 seconds, all slivers<br />
have disappeared <strong>and</strong> the worst element has an aspect ratio of 0.32. <strong>The</strong> distribution of<br />
element quality is enhanced, with a clear right shift of the distribution. Applying the<br />
Netgen optimizer after the Gmsh optimizer, additional improvement can be observed: the<br />
worst elemental quality is now 0.41 <strong>and</strong> another shift <strong>to</strong> the right has occurred. However,<br />
the application of the Netgen optimizer also dramatically reduced the number of elements<br />
in the mesh, <strong>and</strong> this second optimization pass <strong>to</strong>ok more than 200 seconds—about 15<br />
times more than for the Gmsh optimizer. Transferring the mesh in Netgen format also<br />
doubled the memory usage.
102 CHAPTER 3. MESH GENERATION<br />
25000<br />
no optimization<br />
gmsh optimization<br />
both netgen <strong>and</strong> gmsh optimizations<br />
20000<br />
15000<br />
#Elements<br />
10000<br />
5000<br />
0<br />
0 0.2 0.4 0.6 0.8 1<br />
Element Quality<br />
Figure 3.33: Distribution of γK in a mesh of about 600, 000 tetrahedra.<br />
3.7.1 Examples<br />
One of the objectives of this section is <strong>to</strong> demonstrate that Gmsh is able build meshes<br />
that can be used by the finite element community. <strong>The</strong> various examples shown below<br />
can all be downloaded from the Gmsh web site. <strong>The</strong>y come from different sources: native<br />
Gmsh CAD models, CAD models found on the web, or CAD models that were proposed<br />
by industrial <strong>and</strong> academic partners. <strong>The</strong> formats considered are IGES, STEP, BREP <strong>and</strong><br />
Gmsh. Various size fields have been used, uniform or not. Both 2-D <strong>and</strong> 3-D statistics<br />
are provided.<br />
Table 3.3 presents details for some of the models (see Figure 3.34) used in the Gmsh<br />
2-D test suite. <strong>Mesh</strong> size field are defined in a variety of ways: analytic, uniform, size<br />
fields driven by distance functions (attrac<strong>to</strong>rs), boundary layers, size fields related <strong>to</strong> the<br />
curvature of surfaces, or size fields interpolated using sizes that are defined on model<br />
vertices. Table 3.4 gives statistics for the 2-D meshes generated with the surface meshing<br />
algorithm presented in Section 3.6. In the case of planar surfaces <strong>and</strong> uniform meshes this<br />
algorithm is about three times slower than the 2-D anisotropic Delaunay mesh genera<strong>to</strong>r<br />
implemented in Gmsh. However, when multiple size fields are involved <strong>and</strong>/or when the<br />
surfaces are very complex, this new approach becomes competitive in terms of CPU time—<br />
<strong>and</strong> is much more robust than the anisotropic Delaunay mesher. With the caveat that<br />
the performance <strong>and</strong> robustness of mesh generation algorithms are highly dependent on<br />
their implementation, we believe this shows evidence that the new algorithm proposed in<br />
Section 3.6 is a viable alternative <strong>to</strong> classical Frontal or Delaunay approaches.<br />
Table 3.5 presents some statistics for 3-D meshes. <strong>The</strong> first example can serve as<br />
reference: it is a unit cube that is meshed uniformly with about one million tetrahedra.
3.7. 3-D MESH GENERATION 103<br />
gmsh zylkopf cylhead<br />
fuse frog world ocean<br />
Figure 3.34: Some images of surface meshes.<br />
type nR nF nE nV δ<br />
cube GMSH 1 6 12 8 uniform<br />
gmsh GMSH 0 1 35 23 attrac<strong>to</strong>r<br />
frog IGES 1 475 950 477 uniform<br />
frogadapt IGES 1 475 950 477 analytic<br />
linkrods STEP 1 37 108 74 analytic<br />
zylkopf STEP 1 137 404 270 at vertices<br />
cylhead BREP 1 1054 2485 1445 uniform<br />
fuse STEP 1 249 723 476 curvature<br />
block STEP 1 533 1586 1048 uniform<br />
senzor GMSH 8 90 200 146 at vertices<br />
world ocean GMSH 0 1 4245 145291 boundary layer<br />
media GMSH 1274 8398 5779 3894 uniform<br />
Table 3.3: Statistics on the models that are considered: nR,nF ,nE <strong>and</strong> nV are respectively<br />
the number of model regions, of model faces, of model edges <strong>and</strong> of model vertices in the<br />
model. δ is the size field.
104 CHAPTER 3. MESH GENERATION<br />
block linkrods senzor<br />
frogadapt media<br />
Figure 3.35: Some images of volume meshes.<br />
(W. Scholz, T.U. Wien)
3.7. 3-D MESH GENERATION 105<br />
np ne γK > 0.9 minK γK avg KγK l √ 2 τ cpu<br />
gmsh 28041 55922 83.5% 0.287 0.946 99.0% 0.891 10<br />
linkrods 55959 119922 84.2% 0.385 0.946 98.9% 0.893 61<br />
zylkopf 32806 65668 86.0% 0.105 0.947 98.5% 0.860 8<br />
cylhead 84014 188150 77.5% 0.050 0.915 95.5% 0.892 45<br />
fuse 23485 47038 76.0% 0.010 0.919 97.3% 0.886 11<br />
block 19694 55530 76.0% 0.021 0.923 96.8% 0.895 20<br />
senzor 19876 40002 84.6% 0.546 0.947 98.4% 0.896 11<br />
ocean 1152011 2255212 89.0% 0.211 0.950 99.1% 0.901 729<br />
Table 3.4: Surface mesh generation statistics. Here, np are ne are the number of points<br />
<strong>and</strong> triangles in the surface mesh, γK > 0.9 states for the percentage of triangles that<br />
have a quality measure γK greater that 0.9, minK γK is the worst element quality in the<br />
surface mesh <strong>and</strong> avgKγK is the average elemental quality. <strong>The</strong> quantity l√ 2 states for<br />
the percentage of edges that have an adimensional length in the range 1/ √ 2 < le < √ 2.<br />
<strong>The</strong> fac<strong>to</strong>r τ is the efficiency index defined in Equation (3.6). <strong>The</strong> last column gives the<br />
cpu time (in seconds) for performing the surface mesh generation.<br />
np ne minK γK avg KγK cpu(mesh) cpu(opti)<br />
cube 195,671 1,098,530 0.235 0.717 49 sec. 36 sec.<br />
linkrods 341,297 1,836,634 0.347 0.756 111 sec. 117 sec.<br />
block 48,897 221,090 0.012 0.660 12 sec. 14 sec.<br />
senzor 143,799 805,392 0.222 0.765 35 sec. 27 sec.<br />
frogadapt 403,947 2,381,969 0.172 0.691 126 sec. 180 sec.<br />
media 164,517 890,756 0.071 0.696 55 sec. 31 sec.<br />
Table 3.5: Volume mesh generation statistics. Here, np are ne are the number of points<br />
<strong>and</strong> tetrahedron in the volume mesh, minK γK is the worst element quality in the volume<br />
mesh <strong>and</strong> avg KγK is the average elemental quality. <strong>The</strong> last two columns give mesh<br />
generation <strong>and</strong> mesh optimization timings.<br />
Some of the examples have complex mesh size fields (linkrods or frogadapt). One has small<br />
features in the geometry (block). Some have multiple volumes (media or senzor). Complex<br />
mesh size fields such as the ones of linkrods or frogadapt make the mesh generation process<br />
slower of about 20%. This overhead is essentially due <strong>to</strong> the evaluation of the mesh size<br />
field. <strong>Mesh</strong> with strong size variations or with small geometric features require more<br />
optimization. <strong>The</strong> performance figures mentioned in Section 3.7 hold even for models<br />
with a large number of model regions: the model called “media”, created in the native<br />
Gmsh CAD format, involves over 1000 model regions <strong>and</strong> was meshed using the 3-D<br />
Delaunay algorithm in less than one minute. All timings were measured on a st<strong>and</strong>ard<br />
MacBook Pro with a CPU clocked at 2.0 GHz.
106 CHAPTER 3. MESH GENERATION<br />
boundary layer sweep sweep (detail)<br />
3.7.2 Mixed <strong>Mesh</strong>es<br />
(R. V. Sabariego, Univ. of Liège)<br />
Figure 3.36: Some images of hybrid volume meshes.<br />
In addition <strong>to</strong> unstructured meshes, Gmsh enables the generation of simple structured<br />
meshes in 1-D, 2-D <strong>and</strong> 3-D, <strong>and</strong> allows <strong>to</strong> couple these with unstructured meshes. Structured<br />
technologies include transfinite <strong>and</strong> elliptic meshes as well as a variety of sweeping<br />
techniques.<br />
For example, <strong>to</strong> build a boundary layer mesh from a set of source surfaces (see<br />
Figure 3.36), Gmsh<br />
1. creates the <strong>to</strong>pology of the boundary layer by sweeping zero-height volumes from all<br />
the source surfaces. (In addition <strong>to</strong> the boundary layer volumes, this creates a set<br />
of new boundary layer points, curves <strong>and</strong> surfaces. <strong>The</strong>se new points, curves <strong>and</strong><br />
surfaces will only acquire a concrete representation during the meshing process.)<br />
2. meshes the source surfaces <strong>and</strong> computes (unique) normals at the mesh vertices;<br />
3. sweeps the boundary layer points along the normals, <strong>and</strong> remeshes all the nonboundary-layer<br />
curves connected <strong>to</strong> these points, <strong>and</strong> then meshes the boundary<br />
layer curves by sweeping along the normals;<br />
4. meshes the non-source surfaces, then the boundary layer surfaces (again by sweeping<br />
along the normals), <strong>and</strong> finally the volumes.<br />
Once all the structured parts are meshed, the remaining parts are meshed using the<br />
unstructured algorithms, resulting in conforming mixed meshes.
Chapter 4<br />
Remeshing based on surface<br />
parametrization<br />
<strong>The</strong>re are two kind of applications for which it might be desirable <strong>to</strong> remesh a 3D surface<br />
(see Fig. 4.1).<br />
Figure 4.1: Examples of geometries for which a remeshing procedure is desirable. Left<br />
figure show an example of oversampled triangluation resulting from a mesh segmentation<br />
of a human pelvis <strong>and</strong> right figure shows the straightforward meshing of a CAD geometry<br />
of a maxi-cosi.<br />
<strong>The</strong> first application concerns medical geometries that are often described only by<br />
a triangulation (in stereoli<strong>to</strong>graphy STL format). This triangulation is the result of a<br />
segmentation procedure from the CT scan or MRI dicom-images. Those triangulations<br />
can be oversampled <strong>and</strong> have triangles of poor quality with small elementary angles. Those<br />
low quality meshes are not suitable for finite element simulations since the quality of the<br />
mesh will impact both on the accuracy <strong>and</strong> efficiency of the numerical method [?, ?]. In<br />
107
108 CHAPTER 4. REMESHING BASED ON SURFACE PARAMETRIZATION<br />
this case, it is desirable <strong>to</strong> build a high quality mesh from those low quality meshes before<br />
performing any numerical simulation.<br />
<strong>The</strong> other application is about CAD models. CAD models are often made of a<br />
huge amount of patches that have no physical significance <strong>and</strong> a straightforward meshing<br />
of those patches gives often meshes that are not suitable for finite element simulations.<br />
Indeed, as most surface mesh algorithms mesh model faces individually, mesh points are<br />
generated on the bounding edges of those patches <strong>and</strong> if thin CAD patches exist in the<br />
model they will result in the creation of small dis<strong>to</strong>rted triangles with very small angles<br />
- even if the bounding edges of these thin patches (Fig.4.2). Those low quality elements<br />
present in the surface mesh will often hinder the convergence of the FE simulations on those<br />
surface meshes. Besides, they also prevent the generation of quality volumetric meshes<br />
for three-dimensinal finite element computations (CFD, structure mechanics, etc.). <strong>An</strong><br />
efficient manner <strong>to</strong> build a high quality mesh for those CAD models is then <strong>to</strong> build from<br />
the initial CAD mesh a cross-patch parametrization that enables the remeshing of merged<br />
patches.<br />
Figure 4.2: Example of 2 patches of a CAD geometry (left) for which the mesh (right)<br />
contains triangles of poor quality.<br />
<strong>The</strong>re are mainly two approaches for surface remeshing: mesh adaptation strategies<br />
[?, ?, ?] <strong>and</strong> parametrization techniques [?, ?, ?, ?, ?, ?]. <strong>Mesh</strong> adaptation strategies<br />
use local mesh modifications in order both <strong>to</strong> improve the quality of the input surface mesh<br />
<strong>and</strong> <strong>to</strong> adapt the mesh <strong>to</strong> a given mesh size criterion. In parametrization techniques, the<br />
input mesh serves as a support for building a continuous parametrization of the surface.<br />
(In the case of CAD geometries, the initial mesh can be created using any off the shelf<br />
surface mesher for meshing the individual patches.) Surface parametrization techniques<br />
originate mainly from the computer graphics community: they have been used extensively<br />
for applying textures on<strong>to</strong> surfaces [?, ?] <strong>and</strong> have become a very useful <strong>and</strong> efficient <strong>to</strong>ol<br />
for many mesh processing applications [?, ?, ?, ?, ?]. In the context of remeshing procedures,<br />
the initial surface is parametrized on<strong>to</strong> a surface in R 2 , the surface is meshed<br />
using any st<strong>and</strong>ard planar mesh generation procedure <strong>and</strong> the new triangulation is then<br />
mapped back <strong>to</strong> the original surface [?, ?].<br />
<strong>The</strong> existing methods for discrete parametrization can be classified as follows: linear,
4.1. PARAMETRIZATION OF TRIANGULATED SURFACES 109<br />
non-linear <strong>and</strong> hybrid methods. Non-linear methods based on discrete or differentialgeometric<br />
non-linear dis<strong>to</strong>rtion measure [?, ?, ?] offer strong guarantees on the absence of<br />
triangle folding <strong>and</strong> flipping at the cost of a generally higher computational effort. Some<br />
authors have also suggested hybrid techniques that linearize those non-linear measures at<br />
the cost of only a few linear solvers [?, ?]. Linear methods require only the resolution of<br />
a single linear system. Most methods require <strong>to</strong> map the vertex of the patch boundary <strong>to</strong><br />
a given polygon (usually convex ) in the parametric plane. This is for example the case of<br />
the discrete harmonic map introduced by Eck [?] or the more robust convex combination<br />
map of Floater [?] Some authors suggested also extension <strong>to</strong> free boundaries by pinning<br />
down only two vertices. This is the case for example in the least square conformal maps<br />
(LSCM) introduced by levy et al. [?] <strong>and</strong> the discrete conformal parametrizations (DCP)<br />
of Desbrun et al. [?]. <strong>The</strong>se mapping could achieve lower angle dis<strong>to</strong>rtion than previous<br />
results. However, as the quality of the parametrization can depend signification the choice<br />
of the constraint vertices, Mullen et al. [?] suggested <strong>to</strong> spread the constraints throughout<br />
the mesh by constraining that the barycenter of the mapping must be at (0, 0) <strong>and</strong> that<br />
the moment of inertia of the boundary must be unit. In [?], those spread constraints are<br />
taken in<strong>to</strong> account through recourse <strong>to</strong> spectral theory.<br />
4.1 Parametrization of triangulated surfaces<br />
We consider that the only available representation of a surface S is a conforming triangulated<br />
mesh ST in 3D , i.e. the set of K triangles Tj that intersect only at N common<br />
vertices pi <strong>and</strong> E common edges eij:<br />
M = ST = {T1, ..., TK}.<br />
<strong>The</strong> discrete parametrization aims at computing the discrete mapping u(x) that<br />
maps every triangle of the three dimensional surface S <strong>to</strong> another triangle of S ′ that has<br />
a well known parametrization.<br />
(4.1) x ∈ ST ⊂ R 3 ↦→ u(x) ∈ S ′ T ⊂ R 2<br />
Such a parametrization exists if the two surfaces ST <strong>and</strong> ST ′ have the same <strong>to</strong>pology, that<br />
is have the same genus G <strong>and</strong> the same number of boundaries NB 1 . As we have seen, the<br />
genus of a triangulated surface G(ST ) can be computed from the Euler-Poincaré formula<br />
(Eqs. (3.1) <strong>and</strong> (3.2)):<br />
−N + E − K + 2 − NB<br />
(4.2) G(ST ) = .<br />
2<br />
where N, E, K are respectively the number of vertices, edges <strong>and</strong> triangles of the triangulation<br />
ST .<br />
For example, let us consider Figure 4.3 that shows the triangulated Tutankhamun<br />
mask. This triangulated surface is diffeomorphic <strong>to</strong> the unit disk i.e. it is possible <strong>to</strong><br />
1 For example, a sphere has a genus G = 0 <strong>and</strong> NB = 0, a disk has G = 0 but NB = 1 <strong>and</strong> a <strong>to</strong>rus has<br />
G = 1 <strong>and</strong> NB = 0
110 CHAPTER 4. REMESHING BASED ON SURFACE PARAMETRIZATION<br />
z<br />
y<br />
R 3<br />
x<br />
ST<br />
u(x)<br />
x(u)<br />
Figure 4.3: Discrete parametrization of the Tutankhamun mask.<br />
find a transformation u(x) that maps S on<strong>to</strong> S ′ = {u : |u| ≤ 1}. Each vertex pi has its<br />
coordinates xi on ST <strong>and</strong> ui on ST ′ . Consider for example one triangle Tj composed of<br />
three vertices p1, p2 <strong>and</strong> p3. This triangle can itself be parametrized using st<strong>and</strong>ard linear<br />
shape functions (see Figure 4.4):<br />
(4.3) x(ξ) = (1 − ξ − η)x1 + ξx2 + ηx3.<br />
Similarly, we can also parametrize the triangle in S ′ :<br />
(4.4) u(ξ) = (1 − ξ − η)u1 + ξu2 + ηu3.<br />
<strong>The</strong> mapping that is interesting <strong>to</strong> us is x(u) (see Figure 4.4).<br />
It is easy <strong>to</strong> compute (ξ, η) as a function of u using<br />
<br />
u2 − u1 u3 − u1<br />
u − u1 =<br />
v2 − v1 v3 − v1<br />
<br />
<br />
ξ<br />
η<br />
<br />
u,ξ<br />
ξ<br />
which gives<br />
(4.5) ξ(u) = (u,ξ) −1 (u − u1) = (ξ,u) (u − u1).<br />
<strong>and</strong> therefore<br />
<strong>The</strong> derivatives of the mapping x(u)<br />
x,u = x,ξ ξ,u =<br />
⎡<br />
⎣<br />
x2 − x1 x3 − x1<br />
y2 − y1 y3 − y1<br />
z2 − z1 z3 − z1<br />
v<br />
R 2<br />
x(u) = x(ξ(u)).<br />
⎤<br />
<br />
u<br />
v3 − v1<br />
−(u3 − u1)<br />
S ′ T<br />
−(v2 − v1) u2 − u1<br />
⎦<br />
(u2 − u1)(v3 − v1) − (v2 − v1)(u3 − u1)
4.1. PARAMETRIZATION OF TRIANGULATED SURFACES 111<br />
x3<br />
Tj ∈ ST<br />
x2<br />
x1<br />
x(ξ)<br />
η<br />
x(u)<br />
ξ(u)<br />
ξ<br />
u1<br />
u3<br />
Tj ∈ S ′ T<br />
Figure 4.4: Unit triangle in local coordinates <strong>and</strong> the mappings u(x), x(ξ) <strong>and</strong> u(ξ).<br />
allow <strong>to</strong> compute the metric tensor Mu = (x,u) T x,u of the mapping u(x) on the surface<br />
ST .<br />
<strong>The</strong> curvature tensor is indeed more complicated <strong>to</strong> compute for such a piecewise<br />
linear mapping. <strong>The</strong> usual way of computing the curvature is <strong>to</strong> use a normal smoothing<br />
procedure that is similar <strong>to</strong> the one used in the Gouraud shading technique. <strong>The</strong> basic<br />
principle behind the method is as follows: <strong>An</strong> estimate <strong>to</strong> the surface normal of each<br />
vertex in a 3D model is found by averaging the surface normals of triangles which meet<br />
at each vertex. Consider again triangle Tj of Figure 4.4. <strong>The</strong> Gouraud normal smoothing<br />
procedure allows <strong>to</strong> obtain three normal vec<strong>to</strong>rs n1, n2 <strong>and</strong> n3 at the three vertices. We<br />
assume that the unit normal vec<strong>to</strong>r n(x) can be computed using linear shape functions<br />
n(ξ) = (1 − ξ − η)n1 + ξn2 + ηn3<br />
|(1 − ξ − η)n1 + ξn2 + ηn3| .<br />
A last issue related <strong>to</strong> discrete parametrizations is the way <strong>to</strong> compute efficiently x(u)<br />
(see Fig.4.4). This operation requires two steps. First, one has <strong>to</strong> find the triangle in the<br />
parametric plane that contains u. This can be done efficiently using the octree technique<br />
described in §??. <strong>The</strong>n, it is possible <strong>to</strong> compute the mapping ξ(u) using (4.5) <strong>and</strong> next<br />
<strong>to</strong> compute the mapping x(ξ), i.e. interpolating the x coordinates using linear shape<br />
functions.<br />
We will now explain how <strong>to</strong> compute efficiently different types of discrete mappings<br />
by restricting ourselves <strong>to</strong> the parametrization of non-closed triangulated surfaces, i.e<br />
surfaces that are homeomorphic <strong>to</strong> a unit disk. Surfaces that are not of this kind will be<br />
dealt with later on.<br />
u2
112 CHAPTER 4. REMESHING BASED ON SURFACE PARAMETRIZATION<br />
4.2 Computing discrete harmonic <strong>and</strong> conformal maps<br />
<strong>The</strong> first type of mapping we will consider is the harmonic mapping since it is the easiest<br />
mapping <strong>to</strong> compute approximately. This type of mapping minimizes the Dirichlet enery<br />
(see Eq. (2.22)):<br />
(4.6) ED(u) = 1<br />
2<br />
<br />
ST<br />
∇u 2 ds = 1<br />
<br />
(∇u)<br />
2 ST<br />
2 + (∇v) 2 ds.<br />
<strong>The</strong> strong formulation corresponding <strong>to</strong> this minimization problem is given by:<br />
(4.7) ∇ 2 u = 0, ∇ 2 v = 0 on ST<br />
with appropriate Dirichlet <strong>and</strong> Neumann boundary conditions on the NB boundaries of<br />
SD, denoted ∂ST i, i = 1, ..., NB:<br />
(4.8) u = uD(x), on ∂ST 1,<br />
∂u<br />
∂n = 0, on (∂ST − ∂ST 1).<br />
This means that if one can compute numerically the solution <strong>to</strong> those two PDE equations<br />
(4.7), the solutions u(x) a <strong>and</strong> v(u) define the discrete harmonic mapping u(x).<br />
<strong>The</strong> second type of mapping <strong>to</strong> be considered is the conformal mapping that mimimizes<br />
the least square conformal energy (see Eqs.(2.24) <strong>and</strong> (2.25)):<br />
<br />
1<br />
ELSCM(u) =<br />
ST 2 ∇u⊥ − ∇v 2 ds<br />
<br />
1<br />
<br />
= (∇u)<br />
2<br />
2 + (∇v) 2<br />
(4.9)<br />
− n · (∇u × ∇v) ds.<br />
ST<br />
= ED(u) − A(u),<br />
where A(u) is the area functional defined in (2.19).<br />
One efficient way <strong>to</strong> compute numerically those two quadratic minimization problems<br />
is <strong>to</strong> use finite elements. We denote by the functional J either the Derichlet energy<br />
ED(u) or the least-square conformal energy ELSCM(u) <strong>to</strong> be minimized. <strong>The</strong> minimization<br />
problem reads as follows: find u ∗ such that<br />
(4.10)<br />
u ∗ = arg min J(u), with U(S) = {u ∈ H<br />
u∈U(S)<br />
1 (S), u = uD(x), or ∂u<br />
∂n = 0 on ∂ST i}.<br />
In what follows, we will first derive the finite element formulation for the conformal map<br />
(J = ELSCM). We assume the following finite expansions for u:<br />
(4.11) uh(x) = <br />
uiφi(x) + <br />
uD(xi)φi(x)<br />
i∈I<br />
where I denotes the set of i = 1, ..., N nodes of ST that do not belong <strong>to</strong> the Dirichlet<br />
boundary, J denotes the set of nodes of ST that belong <strong>to</strong> the Dirichlet boundary (see Fig.<br />
i∈J
4.2. COMPUTING DISCRETE HARMONIC AND CONFORMAL MAPS 113<br />
nodes of I<br />
nodes of J<br />
Figure 4.5: Sets of I = 12 nodes defined in the first order FE expansion for a triangular<br />
surface mesh ST made of K = 13 triangles <strong>and</strong> N = 12 vertices.<br />
4.5 for an example for linear finite elements) <strong>and</strong> the φi’s are the nodal shape functions<br />
associated <strong>to</strong> the nodes of the mesh. We assume here that nodal shape function φi is equal<br />
<strong>to</strong> 1 on vertex xi <strong>and</strong> 0 on any other vertex: φi(xj) = δij.<br />
Thanks <strong>to</strong> the finite element expansion (4.11), functional J defining for example the<br />
least square conformal energy Eq. (4.9) can be rewritten as:<br />
(4.12)<br />
J(u1, . . . , uI) = 1<br />
2<br />
<br />
i∈I<br />
j∈I<br />
uiuj<br />
<br />
ST<br />
∇φi · ∇φj ds + <br />
<br />
uiuD(xj)<br />
i∈I j∈J<br />
ST<br />
∇φi · ∇φj ds+<br />
1 <br />
<br />
vivj ∇φi · ∇φj ds +<br />
2<br />
ST<br />
i∈I j∈I<br />
<br />
<br />
vivD(xj) ∇φi · ∇φj ds+<br />
ST<br />
i∈I j∈J<br />
<br />
<br />
uD(xi)uD(xj) ∇φi · ∇φj ds + <br />
<br />
vD(xi)vD(xj) ∇φi · ∇φj ds−<br />
i∈I j∈J<br />
<br />
i∈I j∈J<br />
uivj<br />
<br />
ST<br />
<br />
<br />
uivD(xi)<br />
i∈I j∈J<br />
ST<br />
i∈I j∈J<br />
n · (∇φi × ∇φj) ds − <br />
<br />
uD(xi)vj<br />
ST<br />
i∈I j∈J<br />
n · (∇φi × ∇φj) ds − <br />
<br />
uD(xi)vD(xi)<br />
i∈I j∈J<br />
ST<br />
ST<br />
n · (∇φi × ∇φj) ds−<br />
In order <strong>to</strong> minimize this functional J, we can simply cancel the derivative of J with<br />
ST<br />
n · (∇φi × ∇φj) ds.
114 CHAPTER 4. REMESHING BASED ON SURFACE PARAMETRIZATION<br />
respect <strong>to</strong> uk (the same derivation can be done with respect <strong>to</strong> vk):<br />
∂J<br />
=<br />
∂uk<br />
<br />
<br />
uj ∇φk · ∇φj ds +<br />
ST<br />
j∈I <br />
<br />
<br />
uD(xj) ∇φk · ∇φj ds −<br />
ST<br />
j∈J <br />
(4.13)<br />
<br />
(4.14) A Tk<br />
kj =<br />
<br />
Akj<br />
n · (∇φk × ∇φj) ds − <br />
<br />
vD(xj) n · (∇φk × ∇φj) ds<br />
j∈I<br />
ST <br />
vj<br />
j∈I<br />
ST <br />
= 0 , ∀k ∈ I.<br />
Ti<br />
Ckj<br />
In this equations the elementary matrixes Akj of triangle Ti can be computed as follows:<br />
<br />
1 1−ξ<br />
∇φk · ∇φjds = ∇ ξ,η φk M −1<br />
ξ ∇ξ,η <br />
φj det Mξ dξdη,<br />
where Mξ is the metric tensor of the mapping x(ξ) (see Fig.4.4 <strong>and</strong> Eq.(4.3)).<br />
0<br />
0<br />
<strong>The</strong> combination of the equations (4.13) for the uk <strong>and</strong> vk derivatives gives us a<br />
linear system of 2I equations that can be written as follows:<br />
(4.15)<br />
<br />
A −C<br />
−CT <br />
A<br />
<br />
<br />
U<br />
V<br />
<br />
<br />
0<br />
=<br />
0<br />
<br />
,<br />
LC<br />
where A is a symmetric positive definite matrix <strong>and</strong> C is an antisymmetric matrix that<br />
are both build by assembling the elementary matrices Akj <strong>and</strong> Ckj, <strong>and</strong> the vec<strong>to</strong>rs U<br />
<strong>and</strong> V denote respectively the vec<strong>to</strong>r of unknowns uk <strong>and</strong> vk. <strong>The</strong> resulting matrix LC is<br />
then symmetrix definite positive such that the linear system LCU = 0 can be efficiently<br />
solved using a direct sparse symmetric-positive-definite solver such as TAUCS. <strong>The</strong> linear<br />
system of equations is then the discrete version of the minimization problem (4.10) that<br />
can now be rewritten as:<br />
(4.16) U ∗ = arg min<br />
U<br />
1<br />
2 UT LCU<br />
As the Dirichlet energy is related <strong>to</strong> the least square conformal energy, the linear<br />
system resulting from the finite element formulation for the harmonic map can be derived<br />
from Eq. (4.15), by vanishing the off-diagonal matrixes of LC:<br />
<br />
A 0 U 0<br />
(4.17)<br />
= ,<br />
0 A V 0<br />
<br />
LD<br />
which makes the system of equations uncoupled: AU = 0, AV = 0. This finite element<br />
harmonic map can be is quite similar <strong>to</strong> the discrete harmonic map introduced first by<br />
Eck et al. [?]<br />
ENFORCING INSENSITIVITY TO SAMPLING IIREGULARITY ... SEE MULLEN<br />
2008 AND ALSO benchmark/geo/spherehalf.geo<br />
Akj<br />
Ckj
4.3. BOUNDARY CONDITIONS FOR DISCRETE MAPS 115<br />
4.3 Boundary conditions for discrete maps<br />
It is necessary <strong>to</strong> impose appropriate boundary conditions <strong>to</strong> guarantee that the discrete<br />
minimization problem has a unique solution <strong>and</strong> that this unique solution defines a one<strong>to</strong>-one<br />
mapping (<strong>and</strong> hence avoids the degenerate solution u =constant).<br />
We first consider the Dirichlet boundary conditions that are often used for the<br />
Laplacian harmonic map:<br />
(4.18) u = uD(x) on ∂ST i.<br />
This boundary condition allows <strong>to</strong> map one of the boundaries of ST (∂ST 1) <strong>to</strong> a fixed<br />
boundary in the parametric space (a circle, a square, an ellipse, the projection of ∂S<br />
on its mean plane etc.). <strong>The</strong> fixed boundaries that are considered are convex polygons<br />
since the continuous harmonic map is proven <strong>to</strong> be one-<strong>to</strong>-one if the mapped surface S ′<br />
is convex. This result is called the Radò-Kneser-Choquet (RKC) theorem [?, ?] <strong>and</strong> it<br />
strongly depends on the fact that the solution of the Laplace equation obeys a strong<br />
maximum principle: u(x) attains its maximum on the boundary ∂S of the domain. This<br />
means that there exists only one single iso-curve u = u0 in S <strong>and</strong> that this iso-curve goes<br />
continuously from one point of the boundary <strong>to</strong> another. If another iso-curve u = u0<br />
existed, it should be closed inside S, violating the maximum principle. This is also true<br />
for the iso-curve v = v0. Consider the surface S of Figure 4.6a with one single boundary<br />
(NB = 1) that is mapped <strong>to</strong> a unit circle with appropriate Dirichlet boundary conditions.<br />
Surface S ′ is convex so that any vertical line u = u0 intersects ∂S ′ at most two times.<br />
This is also true for any horizontal line v = v0. This means that any coordinate u = u0<br />
(u0 ∈] − 1, 1[) appears also exactly two times on the boundary ∂S. <strong>The</strong> two points of<br />
∂S for which u = u0 are designated as VA <strong>and</strong> VB while the two points for which v = v0<br />
are designated as VC <strong>and</strong> VD. Note that those points appear interleaved while running<br />
through ∂S (VA appears either after VD or after VC but never after VB). This means that<br />
there exists one point in S for which u = u0 <strong>and</strong> v = v0.<br />
VB<br />
VD<br />
v = v0<br />
S S ′<br />
u = u0<br />
VA<br />
VC<br />
∂S<br />
u(x)<br />
u = u0<br />
∂S ′<br />
v = v0<br />
Figure 4.6: Iso-values of coordinates u <strong>and</strong> v on a surface S for which the mapping u(x)<br />
is computed as the solutions of the Laplace equation with Dirichlet boundary conditions<br />
that map ∂S on the unit circle ∂S ′ .
116 CHAPTER 4. REMESHING BASED ON SURFACE PARAMETRIZATION<br />
Figure 4.7 illustrates the Dirichlet boundary conditions that map the boundary of the<br />
triangulation of the Toutankhamon mask ∂ST 1 <strong>to</strong> a unit circle. This boundary condition<br />
can be implemented by choosing arbitrarily a starting vertex M 0 s on the boundary ∂ST 1.<br />
<strong>The</strong>n, the curvilinear abscissa li of point M 0 i = xi along the curve can computed for<br />
all vertices along the curve of <strong>to</strong>tal length L. <strong>The</strong> mapping of the boundary nodes (the<br />
position (ui, vi)) of M 0 i in can then be written as:<br />
<br />
2πli(xi)<br />
(4.19) uD(xi) = cos<br />
L<br />
<br />
2πli(xi)<br />
, vD(xi) = sin<br />
.<br />
L<br />
Figure 4.7: Dirichlet boundary conditions: mapping the boundary of the Toutankhamon<br />
mask ∂ST 1 <strong>to</strong> a unit circle.<br />
Instead of fixing all the boundary nodes ∂S1 <strong>to</strong> a convex polygon, one might fix two<br />
(u, v) coordinates, thus pinning down two vertices in the parameter plane with Dirichlet<br />
boundary conditions. Indeed, for least square conformal maps, the mapping (4.15) has full<br />
rank only when the number of pinned vertices is greater or equal <strong>to</strong> 2 [?]. Pinning down<br />
two vertices will set the translation, rotation <strong>and</strong> scale of the solution when solving the<br />
linear system LCU = 0 <strong>and</strong> will lead <strong>to</strong> what is called a free-boundary parametrization.<br />
It was independendty found by the authors of the LSCM [?] <strong>and</strong> the DCP [?] that picking<br />
two boundary vertices the farthest from each other seems <strong>to</strong> give good results in general.<br />
However, the quality of the conformal parametrization depend drastically on the choice of<br />
these constraint vertices. Indeed, global dis<strong>to</strong>rtion can ensue <strong>and</strong> a degradation of conformality<br />
can be observed around the pinned vertices. Figure 4.8 compares a LSCM with<br />
two pinned vertices with a less dis<strong>to</strong>rted LSCM that spreads the constraints throughout<br />
the mesh (we call this approach the constrained LSCM or CLSCM)<br />
How can we define a less dis<strong>to</strong>rted least square conformal map (CLSCM) without<br />
pinning down two vertices ? <strong>The</strong> idea is <strong>to</strong> add the two following constraints <strong>to</strong> the minimization<br />
problem that that set the translation, rotation <strong>and</strong> scale of the solution: (i) the<br />
barycenter of the solution must be at zero <strong>and</strong> (ii) the moment of inertia of the boundary<br />
∂ST 1 must be unit. Those constraints can be taken in<strong>to</strong> account through recourse <strong>to</strong><br />
spectral theory. This idea was derived also by Mullen et al. [?] <strong>and</strong> named after spectral<br />
conformal parametrization. In what follows, we try <strong>to</strong> present the spectral conformal<br />
map in a more comprehensive manner than the way it is presented in [?].<br />
<strong>The</strong> constrained least square conformal map corresponds <strong>to</strong> the following discrete<br />
constrained minimization problem. Find U ∗ such that<br />
(4.20) U ∗ = arg min<br />
U<br />
1<br />
2 UT LCU, subject <strong>to</strong> U T E = 0, U T BU = 1.<br />
<strong>The</strong> first constraint in (4.20) U T E = 0 states that the barycenter of the solution must be<br />
at zero. Indeed, as E denotes the 2I × 2 matrix that is such that Ei1 = 1, i = 1, ..., I <strong>and</strong>
4.3. BOUNDARY CONDITIONS FOR DISCRETE MAPS 117<br />
a) b) c)<br />
Figure 4.8: Initial triangulation ST of a boudda statue a) that has been parametrized by<br />
computing b) the LSCM with two constrained vertices shown in red c) the constrained<br />
LSCM solved with a spectral method.<br />
Ei2 = 1, i = I + 1, ..., 2I (the other entries of E being zero):<br />
⎛<br />
⎜<br />
E = ⎜<br />
⎝<br />
1<br />
.<br />
1<br />
0<br />
.<br />
0<br />
.<br />
0<br />
1<br />
.<br />
⎞<br />
⎟ ,<br />
⎟<br />
⎠<br />
0 1<br />
V = 0. In in (4.20), the second constraint<br />
UTBU = 1 indicates that the moment of inertia of the boundary must be unit, the B<br />
matrix being a 2I × 2I diagonal matrix with 1 at each diagonal element corresponding<br />
<strong>to</strong> boundary vertices <strong>and</strong> 0 everywhere else. <strong>The</strong>re are two different ways <strong>to</strong> solve this<br />
constrained minimization problem. <strong>The</strong> first method tries <strong>to</strong> find the optimum of the<br />
following Lagrangian function L (U, µ) with Lagrange multipliers µi ≥ 0:<br />
UTE = 0 is equivalent <strong>to</strong> I i=0 U = 0 <strong>and</strong> I i=0<br />
(4.21) L (U, λµ) = 1<br />
2 UT LCU − µ(U T E) − λ(U T BU − 1).<br />
<strong>The</strong> second method is based on spectral theory that shows that the solution of the constrained<br />
minimization problem Eq. (4.20) is the generalized eigenvec<strong>to</strong>r U ∗ associated <strong>to</strong><br />
the smallest non-zero eigenvalue of the matrix LC, i.e the vec<strong>to</strong>r satisfying<br />
(4.22) LCU = λBU,<br />
where λ is the smallest non-zero eigenvalue of LC. This generalized eigenvec<strong>to</strong>r U ∗ is<br />
called the Fiedler vec<strong>to</strong>r of LC. We now show that optimizing (4.21) is equivalent <strong>to</strong><br />
finding the Fiedler vec<strong>to</strong>r U ∗ (4.22). Indeed, for the discrete optimization problem, the
118 CHAPTER 4. REMESHING BASED ON SURFACE PARAMETRIZATION<br />
solution must satisfy:<br />
(4.23)<br />
(4.24)<br />
(4.25)<br />
∂L<br />
∂U = 0 ⇐⇒ LCU − µE − λBU = 0<br />
∂L<br />
∂µ = 0 ⇐⇒ UTE = 0<br />
∂L<br />
∂λ = 0 ⇐⇒ UTBU = 1<br />
That is, (LC − λB) U = µE . Premultiplying Eq.4.23 by E T gives:<br />
(4.26) E T LCU − λE T BU = µE T E = µD,<br />
where D is a 2 × 2 diagonal matrix with value I at both diagonal entries. But we have<br />
that ETBU = 0 (combination of the two constraints (4.24) <strong>and</strong> (4.25)) <strong>and</strong> also that<br />
ETLC = 0 (because the matrix LC is a block matrix composed of Laplacian matrixes A<br />
<strong>and</strong> antisymmetric matrices C that are such that <br />
j Ckj = 0). Thus we<br />
have µ = 0 <strong>and</strong> hence,<br />
(4.27) (LC − λB) U = 0,<br />
j Akj = 0 <strong>and</strong> <br />
with U being the generalized eigenvec<strong>to</strong>r of the eigenvalue problem (4.22). <strong>The</strong> matrix LC<br />
is positive semi-definite with smallest eigenvalue λ1 = 0 <strong>and</strong> corresponding eigenvec<strong>to</strong>r E<br />
being the kernel vec<strong>to</strong>r (since we have that LCE = 0). Clearly E is not a solution <strong>to</strong> the<br />
problem since it does not satisfy the constraint that the barycenter of the solution must<br />
be at zero. Since the LC matrix is positive definite positive, then it can be shown that the<br />
next smallest eigenvalue λ2 is positive. <strong>The</strong> eigenvec<strong>to</strong>r associated with this eigenvalue<br />
(also called Fiedler vec<strong>to</strong>r) satisfies the constraint U T E = 0 because it is orthogonal <strong>to</strong><br />
the first eigenvec<strong>to</strong>r E. It also satisfies the constraint U T BU = 1 by proper scaling, <strong>and</strong><br />
thus is the solution of the constrained minimization problem (4.20).<br />
From a numerical point of view, there exists very efficient eigensolvers that find the<br />
Fiedler vec<strong>to</strong>r U ∗ of the sparse generalized eigenvalue problem we need <strong>to</strong> solve (4.22).<br />
Those methods usually proceed through Choleski decomposition (<strong>to</strong> turn the problem<br />
in<strong>to</strong> a conventional eigenvalue problem) <strong>and</strong> Lanczos iterations, particulary fast in our<br />
case since we deal with sparse matrices. Softwares libraries such as Slepc [?] or Arpack [?]<br />
provide all those methods for solving efficiently the generalized eigenproblem. It is however<br />
interesting <strong>to</strong> transform the minimization problem (finding the Fiedler vec<strong>to</strong>r that<br />
corresponds <strong>to</strong> the smallest eigenvalue λ) (4.22) in<strong>to</strong> a maximisation problem (finding the<br />
vec<strong>to</strong>r corresponding <strong>to</strong> the largest eigenvalue ˜ λ = 1/λ of the eigenvalue problem (4.22)<br />
in which the left <strong>and</strong> right h<strong>and</strong> side have been switched):<br />
(4.28) BU = ˜λLCU,<br />
since this transformation makes the eigen solver more robust. As in Mullen et al. [?], we<br />
also found that robustness <strong>to</strong> large triangulations with extremely degenerated triangles<br />
could be improved by adding ɛId (with Id being the identity matrix) <strong>to</strong> LC in order <strong>to</strong>
4.3. BOUNDARY CONDITIONS FOR DISCRETE MAPS 119<br />
ensure that numerical inaccuracies in the coefficients of the conformal matrix LC will not<br />
alter the positive semi-definiteness of the matrix (we have used ɛ = 1.e −8 ). Finally, a last<br />
interesting transformation consists in removing the kernel of LC through the following<br />
modified generalized eigenvalue problem:<br />
(4.29) (B − Be) U = ˜λLCU, with Be = 1<br />
(BEE<br />
IB<br />
T B T ).<br />
<strong>The</strong> vec<strong>to</strong>r U∗ we are looking for is the eigenvec<strong>to</strong>r corresponding <strong>to</strong> the largest eigenvalue<br />
˜λ. In (4.29), IB is the number of boundary nodes <strong>and</strong> the Be matrix is now a non-diagonal<br />
matrix with value 1 for every matrix entry (i, j) <strong>and</strong> (i + I, j + I) (where i <strong>and</strong> j are the<br />
indexes of the IB boundary nodes) <strong>and</strong> value 0 for all other entries. As this matrix Be<br />
reduces the sparsity of the eigenvalue problem, we suggest <strong>to</strong> compute it with a reduced<br />
boundary matrix ˜ B that takes in<strong>to</strong> account a limited number of nodes on the boundary<br />
Imax B that are distributed uniformly along the boundary (usually we take Imax B = 50). To<br />
illustrate this, consider the very simple triangulation ST on Fig.4.9 with N = 5 nodes <strong>and</strong><br />
IB = 4 boundary nodes. For this triangulation in Fig.4.9, the matrices Be <strong>and</strong> ˜ Be (with<br />
2<br />
1<br />
5<br />
3 4<br />
Figure 4.9: Simple triangulation ST with 3 triangles, N = 5 vertices (I = 5 finite element<br />
nodes for linear finite elements) <strong>and</strong> IB = 4 boundary nodes.<br />
I max<br />
B<br />
= 2 = {1, 5}) are given by:<br />
Be = 1<br />
<br />
L 0<br />
4 0 L<br />
˜Be = 1<br />
<br />
˜L 0<br />
2 0 L˜<br />
<br />
, with L =<br />
<br />
, with ˜ L =<br />
⎛<br />
⎜<br />
⎝<br />
⎛<br />
⎜<br />
⎝<br />
1 1 0 1 1<br />
1 1 0 1 1<br />
0 0 0 0 0<br />
1 1 0 1 1<br />
1 1 0 1 1<br />
1 0 0 0 1<br />
0 0 0 0 0<br />
0 0 0 0 0<br />
0 0 0 0 0<br />
1 0 0 0 1<br />
So far, we have discussed Dirichlet boundary conditions <strong>and</strong> have introduced constrained<br />
LSCM in order <strong>to</strong> avoid <strong>to</strong> pin down two vertices for the LSCM. <strong>An</strong>other type of<br />
⎞<br />
⎟<br />
⎠<br />
⎞<br />
⎟<br />
⎠
120 CHAPTER 4. REMESHING BASED ON SURFACE PARAMETRIZATION<br />
boundary conditions <strong>to</strong> be considered are natural boundaries, also called zero Neumann<br />
boundary conditions:<br />
(4.30)<br />
∂u<br />
∂n = 0, on ∂ST i<br />
From an implementation point of view, those boundaries conditions correspond <strong>to</strong> a ”do<br />
noting BC” since the Neumann boundary condition is already taken in<strong>to</strong> account in the<br />
minimization problem (4.10). Consider for example a surface ST that has two boundaries<br />
denoted ∂ST 1 <strong>and</strong> ∂ST 2 (see Fig.4.10a)). Suppose now, we compute the discrete<br />
∂ST 2<br />
∂ST 1<br />
a) b)<br />
Figure 4.10: Triangulation ST A with two holes on which a discrete harmonic map u(x)<br />
is computed as solutions of the Laplace equations α∇ 2 u = 0, α∇ 2 v = 0 with boundary<br />
conditions that map ∂ST 1 on the unit circle. <strong>The</strong> bot<strong>to</strong>m a) figure shows the iso-u <strong>and</strong><br />
iso-v values for the mapping (α = 1) of the surface ST that excludes the interior disk <strong>and</strong><br />
for which zero Neumann boundary conditions are applied on ∂ST 2. <strong>The</strong> bot<strong>to</strong>m c) figure<br />
shows the iso-u <strong>and</strong> iso-v values for the mapping of ST that also includes the interior disk,<br />
<strong>and</strong> for which α = 1 inside ST A <strong>and</strong> α = 1.e −8 (small value) inside ST B.<br />
Laplacian map by solving (4.17) with Dirichlet boundary conditions (4.19) on ∂ST 1 <strong>and</strong><br />
zero Neumann boundary conditions on ∂ST 2. <strong>The</strong> iso-u <strong>and</strong> iso-v values of this mapping<br />
are shown in Fig. 4.10b). Figures 4.10a) <strong>and</strong> b) show that imposing Neumann<br />
boundary conditions on ∂ST 1 is equivalent <strong>to</strong> the resolution of a Laplace problem on the<br />
whole domain ST = ST A + ST B while defining a small diffusivity constant α (solving<br />
α∇ 2 u = 0, α∇ 2 v = 0) inside the hole ST B (Figure 4.6b). This means that this problem<br />
also obeys the same maximum principle as the one with constant diffusivity, which means<br />
ST B<br />
ST A
4.4. ISSUES WITH DISCRETE LINEAR MAPPINGS 121<br />
that the mapping remains one-<strong>to</strong>-one even when considering holes in the domain. However,<br />
as can be seen clearly in Fig.4.10 the conformality is deteriorated near the Neumann<br />
boundary ∂ST (compare Figs. 4.10a with Fig. 4.6 that shows the Laplacian mapping for<br />
the whole surface ST with a constant diffusivity parameter α = 1). That is the reason for<br />
which it might be desirable for surfaces ST that have several interior boundaries ∂ST i <strong>to</strong><br />
mesh the surface ST B bounded by those boundaries <strong>and</strong> <strong>to</strong> compute the mapping for ex-<br />
tended surface ˜<br />
ST that includes those newly defined mesh surfaces [?] ˜<br />
ST = ST ∪ <br />
i ST Bi.<br />
4.4 Issues with discrete linear mappings<br />
A very important aspect when computing the parametrization is <strong>to</strong> obtain bijective (one<strong>to</strong>-one)<br />
maps, where each point of the parametric domain corresponds <strong>to</strong> exactly one<br />
point of the mesh. One can make a difference between global bijectivity <strong>and</strong> local bijectivity.<br />
<strong>The</strong> latter requires only that the maps of any sufficiently small region of the<br />
mesh is bijective. If the discrete convex combination map is guaranteed <strong>to</strong> be bijective,<br />
non-bijective parametrizations might occur when computing the discrete harmonic<br />
or conformal map as the solution of linear systems. Figure 4.11 shows two examples of<br />
non-bijective parametrizations. <strong>The</strong> <strong>to</strong>p figure shows a discrete harmonic map for which<br />
the local bijectivity condition is violated. Indeed, the mapping of adjacent mesh triangles<br />
intersect <strong>and</strong> the parametrization contains triangle flips. <strong>The</strong> bot<strong>to</strong>m figure 4.11 shows a<br />
parametrization with a global domain overlap (global bijectivity violated). A well as the<br />
issues of bijectively, there exists an additional important numerical issue that concerns<br />
all type of mappings <strong>and</strong> that rarely mentionned in the litterature. This issue exists for<br />
triangulations with large geometrical aspect ratio for which the mapping often contains<br />
clustered triangles with numerically undistinguisable node coordinates. We now discuss<br />
those three different issues <strong>and</strong> present different algorithms <strong>to</strong> get rid of those issues <strong>and</strong><br />
<strong>to</strong> guarantee bijectivity.<br />
<strong>The</strong> first issue concerns triangle flipping <strong>and</strong> is illustrated on the <strong>to</strong>p of Fig.4.11.<br />
In this figure, looking at the triangles normals in the parametric space, one can see that<br />
one triangle have been reversed (the normal of the face is flipped). Indeed, in contrast <strong>to</strong><br />
the continuous harmonic map, it was shown in [?, ?] that the discrete harmonic map is not<br />
always one-<strong>to</strong>-one. To illustrate this, the next example introduced by Floater [?] shows<br />
that the discrete harmonic map is not guaranteed <strong>to</strong> be one-<strong>to</strong>-one. Consider a coarse<br />
triangulation (Figure 4.12) made of three triangles ST = {(1, 2, 3), (1, 3, 4), (1, 4, 2)} <strong>and</strong><br />
let x1 = (r, 0, 1) for some real value r > 0 <strong>and</strong> x2 = (1, 1, 0), x3 = (0, 0, 0), x4 = (1, −1, 0).<br />
<strong>The</strong> three boundary vertices x1, x2 <strong>and</strong> x3 are mapped on<strong>to</strong> the boundary of the unit disk<br />
(Figures 4.12b <strong>and</strong> c) <strong>and</strong> the vertex x1 should be mapped inside the triangle (u2, u3, u4) <strong>to</strong><br />
ensure a one-<strong>to</strong>-one mapping. However, numerical methods for solving Laplace equation<br />
may not provide solutions that obey <strong>to</strong> a discrete maximum principle, especially when<br />
meshes are dis<strong>to</strong>rted [?]—which can lead <strong>to</strong> discrete harmonic maps which are not one-<strong>to</strong>one<br />
(Figure 4.12c). One possible way <strong>to</strong> enforce the discrete harmonic <strong>to</strong> be one-<strong>to</strong>-one [?]<br />
is <strong>to</strong> implement a local cavity check algorithm that locally modifies mesh cavities in which
122 CHAPTER 4. REMESHING BASED ON SURFACE PARAMETRIZATION<br />
u harm (x)<br />
u conf (x)<br />
Figure 4.11: Non-bijective parametrizations might occur when computing the discrete<br />
harmonic or conformal map as the solution of linear systems: (<strong>to</strong>p) a parametrization<br />
which contains triangle flips <strong>and</strong> (bot<strong>to</strong>m) a parametrization with a global overlap of<br />
triangles.<br />
a) b) c)<br />
Figure 4.12: a) Triangulation for which the discrete harmonic mapping is not guaranteed<br />
<strong>to</strong> be one-<strong>to</strong>-one: x1 = (r, 0, 1) for r > 0 <strong>and</strong> x2 = (1, 1, 0), x3 = (0, 0, 0), x4 = (1, −1, 0).<br />
b) Case r = 1.5: the mapping is one-<strong>to</strong>-one , c) Case r = 3.5 : the mapping is not<br />
one-<strong>to</strong>-one. <strong>The</strong> point u1 does not even lie within the unit disk.<br />
flipping occurs. This algorithm goes as follows:<br />
1. Compute harmonic map using finite elements;<br />
2. For every interior vertex Vi of the parameter plane, check if each of its neighboring<br />
triangles (defining a cavity) is oriented properly 2 ;<br />
2 This is simply implemented by comparing normal orientations of the triangles in the parametric space<br />
v<br />
v<br />
u<br />
u
4.4. ISSUES WITH DISCRETE LINEAR MAPPINGS 123<br />
3. If elements are reversed, move the vertex at the center of gravity of the kernel of the<br />
polygon P surrounding the point (see Figure 4.13).<br />
In order <strong>to</strong> find the kernel of a star-shaped polygon, different algorithms have been proposed<br />
in the literature[?, ?]. In this work, as the polygons have a small number of vertices<br />
we have implemented a simple quadratic algorithm. It should be noted that the situation<br />
presented in Fig. 4.13a) does occur very rarely <strong>and</strong> only occurs for very poor quality initial<br />
stl files. <strong>The</strong> local cavity check algorithm enables most of the time <strong>to</strong> repair the triangle<br />
v3<br />
T3<br />
v5<br />
T2<br />
v1<br />
T1<br />
v4<br />
T4<br />
v2<br />
v3<br />
v5<br />
v4<br />
v5<br />
a) b) c)<br />
Figure 4.13: Vertex v1 with four neighboring triangles T1 = (v1, v2, v3), T2 = (v1, v3, v4),<br />
T3 = (v1, v4, v5), T4 = (v1, v5, v2) defining the polygon P = (v2, v3, v4, v5). a) Triangle<br />
T3 (in red) is not well oriented <strong>and</strong> overlaps the triangles T2 <strong>and</strong> T4 . b) <strong>The</strong> vertex v1<br />
is moved <strong>and</strong> placed inside the kernel of the polygon P (yellow area), c) Now, all four<br />
triangles become well oriented without overlapping <strong>and</strong> hence the discrete mapping is<br />
guaranteed <strong>to</strong> be one-<strong>to</strong>-one for this cavity.<br />
flips. However, in some cases of very low quality input meshes it might fail. In those cases<br />
in which the algorithm fails, we suggest <strong>to</strong> switch <strong>to</strong> a guaranteed one-<strong>to</strong>-one mapping<br />
introduced by Floater [?, ?, ?]: the convex combination map. One possible definition<br />
of the convex combination maps is the barycentric mapping [?, ?] that asks every interior<br />
vertex ui be the barycenter of its neighbors:<br />
di <br />
(4.31) ui = λkuj,<br />
k=1<br />
v6<br />
v1<br />
di <br />
k=1<br />
v2<br />
λk = 1,<br />
where di denotes the number of vertices that are neighbors <strong>to</strong> node i. <strong>The</strong> resulting system<br />
of equations is also uncoupled as in (4.17):<br />
(4.32) DU = 0, DV = 0,<br />
the matrix D being now the assembly of the following elementary matrices Dkj for every<br />
triangle Ti:<br />
⎛<br />
1 −0.5<br />
⎞<br />
−0.5<br />
(4.33) Dkj = ⎝ −0.5 1 −0.5 ⎠<br />
−0.5 −0.5 1<br />
One can easily see that by assembling for example the 4 elementary matrices of the 4<br />
elements surrounding node v1 in Fig.4.13c, equation (4.31) is satisfied. This convex combination<br />
seems attractive from a mathematical point of view <strong>and</strong> is widely used in the<br />
v3<br />
v5<br />
v4<br />
T2<br />
T3<br />
T1<br />
T4<br />
v1<br />
v2
124 CHAPTER 4. REMESHING BASED ON SURFACE PARAMETRIZATION<br />
computer Graphics Community. However, in the context of surface remeshing is not used<br />
as default mapping since the metric tensor associated with this mapping is much more<br />
dis<strong>to</strong>rted than the one obtained with the harmonic mapping. This in turn impacts on the<br />
quality of the the remeshing procedure. This is illustrated in Fig. 4.14 where an initially<br />
low quality triangulation ST has been remeshed with a parametrization based both on the<br />
convex combination map <strong>and</strong> Laplacian harmonic map.<br />
a) b) c) d)<br />
Figure 4.14: Poor quality initial triangulation ST (a) that has been remeshed using a<br />
harmonic map (<strong>to</strong>p figures) <strong>and</strong> a convex combination map (bot<strong>to</strong>m figures): b) mapping<br />
of the initial mesh on<strong>to</strong> the unit disk ST ′ with iso-x <strong>and</strong> iso-v values in red, c) the determinant<br />
of the mesh metric tensor Mu that defines the area dis<strong>to</strong>rstion map <strong>and</strong> d) the<br />
final mesh obtained using the 2D Delaunay algorithms.<br />
<strong>The</strong> second issue is about overlapping of triangles. This issue might occur when<br />
computing linear conformal maps with open boundaries. Indeed, a linear conformal algorithm<br />
cannot guarantee that triangles do not overlap. To remain efficient in the context<br />
of surface remeshing, we use an idea similar <strong>to</strong> the one suggested by Sheffer et al. [?] that<br />
checks the presence of edge folding. Edge foldings are detected by looping over the edges<br />
of the boundary ∂ST 1 <strong>and</strong> by computing if there exists intersections between the edges<br />
(see Fig. 4.15). <strong>The</strong> intersection of two edge segments (p1, p2) <strong>and</strong> (p3, p4) of parametric<br />
equations:<br />
pa = p1 + ta(p2 − p1), pb = p1 + tb(p4 − p3),<br />
can be computed by solving for the point where pa = pb. This gives the following linear<br />
system of equations:<br />
<br />
x2 − x1<br />
(4.34)<br />
y2 − y1<br />
x3 − x4<br />
y3 − y4<br />
<br />
ta<br />
<br />
x3 − x1<br />
=<br />
y3 − y1<br />
<br />
.<br />
tb
4.5. AUTOMATIC REMESHING WITH PARAMETRIZATIONS 125<br />
If ta ∈ [0, 1] <strong>and</strong> tb ∈ [0, 1], we are in the case of segment intersections. In the case of<br />
p2<br />
p3<br />
p4<br />
p1<br />
Figure 4.15: Intersection boundary ∂ST 1 that is present in the case of triangle folding.<br />
triangle folding, we suggest <strong>to</strong> switch <strong>to</strong> a harmonic mapping.<br />
<strong>The</strong> last issue concerns indistinguishable coordinates. As shown in Fig.4.16<br />
<strong>and</strong> explained in [?] the solution of the mapping becomes exponentially small for vertices<br />
located away from ∂ST 1. As a consequence, local coordinates u <strong>and</strong> v of those far away<br />
vertices might numerically become indistinguishable. By deriving an analytical solution of<br />
Laplacian harmonic maps for cylinders, we showed in [?] that the geometrical aspect ratio<br />
of the surface η should be reasonable <strong>to</strong> be numerically able <strong>to</strong> distinguish the coordinates.<br />
(4.35) η = H<br />
D<br />
< ηmax,<br />
where H is the maximal distance computed on the 3D mesh ST of a mesh vertex <strong>to</strong><br />
the boundary ∂ST 1 <strong>and</strong> D is the equivalent diameter of the boundary ∂ST 1. As the<br />
distance on the 3d mesh is not straightforward <strong>to</strong> compute, an upper <strong>and</strong> lower bound for<br />
η is computed. <strong>The</strong> upper bound for η is computed by using the analytical expression for<br />
cylinders: η = 2πA/L2 , where A is the area of the 3D surface mesh <strong>and</strong> L∂ST is the arc<br />
∂ST 1<br />
1<br />
length of the boundary ∂ST 1. <strong>The</strong> lower bound is estimated by choosing for H the maximal<br />
size of the oriented bounding box of the 3D surface mesh <strong>and</strong> for D the maximal size of<br />
the oriented bounding box for the boundary curve ∂ST 1. <strong>The</strong> oriented bounding boxes<br />
are computed with the fast Oriented bounding box HYBBRID optimization algorithm<br />
presented in [?] which combines the genetic <strong>and</strong> Nelder-Mead algorithms [?]. As we<br />
showed in [?] that η = 4 corresponds <strong>to</strong> an area of mapped triangles of about r 2 i<br />
= 10−10<br />
(see Eq. (23) <strong>and</strong> Fig. 10c in [?]), we choose ηmax = 4 as upper limit for the geometrical<br />
aspect ratio of the 3D surface mesh.<br />
4.5 Au<strong>to</strong>matic remeshing with parametrizations<br />
In this chapter, we have put <strong>to</strong> the fore in the context of discrete harmonic mapping three<br />
limitations, namely limitations on the genus G, the number of boundaries NB <strong>and</strong> the
126 CHAPTER 4. REMESHING BASED ON SURFACE PARAMETRIZATION<br />
z<br />
y<br />
x<br />
H<br />
D<br />
ST<br />
∂ST 2<br />
u harm (x)<br />
∂ST 1<br />
Figure 4.16: Issue of numerically indistinguishable coordinates illustrated for a Laplacian<br />
map of a cylindrical mesh. When the geometrical aspect ratio η = H/D becomes <strong>to</strong>o large,<br />
the vertices that are located far away from the boundary ∂ST 1 become exponentially close<br />
<strong>to</strong> each other in the parametric space ST ′ .<br />
geometrical aspect ratio η. Those three criteria can be summarized as follows:<br />
(4.36)<br />
i) G = 0;<br />
ii) NB ≥ 1;<br />
iii) η < ηmax.<br />
In the next section, we will first consider a disk-like surface (G = 0, NB ≥ 1)<br />
<strong>and</strong> present a novel max-cut partitioning algorithm for those family of surfaces. We will<br />
then present an au<strong>to</strong>matic approach for arbitrary genus surfaces that combines this novel<br />
algorithm with a multilevel partitioning algorithm.<br />
4.5.1 Multiscale Laplace partitioning method<br />
WAIT FOR REVIEW PAPER GMSHREPARAM2<br />
4.5.2 Au<strong>to</strong>matic algorithm<br />
WAIT FOR REVIEW PAPER GMSHREPARAM2<br />
4.6 Quality remeshing with parametrizations<br />
Figures 4.17 show the remeshing of a triangulation of a teeth of very low input quality<br />
(see STL quality curves). <strong>The</strong> compare the quality of the remeshing procedure using<br />
successively a Laplacian map, a conformal map <strong>and</strong> a convex combination map. <strong>The</strong><br />
v<br />
S ′ T<br />
u
4.6. QUALITY REMESHING WITH PARAMETRIZATIONS 127<br />
quality of the isotropic meshes is evaluated by computing the aspect ratio of every mesh<br />
triangle as follows [?]:<br />
inscribed radius sin â sin<br />
(4.37) κ = α<br />
= 4<br />
circumscribed radius ˆb sin ĉ<br />
sin â + sin ˆb + sin ĉ ,<br />
â, ˆ b, ĉ being the three inner angles of the triangle. With this definition, the equilateral<br />
triangle has κ = 1 <strong>and</strong> degenerated (zero surface) triangles have κ = 0. A can be seen<br />
from Fig.4.17 the conformal parametrization gives rise <strong>to</strong> the highest quality mesh while<br />
the worst is found <strong>to</strong> be the convex combination map. <strong>The</strong> Laplacian mapping has a<br />
slightly lower quality that can be explained by a loss in conformality at the boundaries<br />
that gives rise <strong>to</strong> a less smoother mesh metric.<br />
Frequency<br />
0.025<br />
0.02<br />
0.015<br />
0.01<br />
0.005<br />
STL mesh<br />
Laplacian map<br />
Conformal map<br />
Convex map<br />
0<br />
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8<br />
Aspect ratio<br />
Frequency<br />
0.25<br />
0.2<br />
0.15<br />
0.1<br />
0.05<br />
STL mesh<br />
Laplacian map<br />
Conformal map<br />
Convex map<br />
0<br />
0.8 0.9<br />
Aspect ratio<br />
1<br />
Figure 4.17: Remeshing of an teeth. Top figures show the initial STL triangulation <strong>and</strong><br />
new mesh based on the conformal mapping <strong>and</strong> the bot<strong>to</strong>m figures show the quality<br />
his<strong>to</strong>gram obtained when remeshing the stl file with different mappings.
128 CHAPTER 4. REMESHING BASED ON SURFACE PARAMETRIZATION<br />
Acknowledgements<br />
<strong>The</strong> authors gratefully acknowledge Électricité de France (EDF) for their financial support.<br />
We would also like <strong>to</strong> thank all persons that have contributed <strong>to</strong> the development, testing<br />
<strong>and</strong> debugging of Gmsh. Among those, we especially thank David Colignon for being such<br />
an indefatigable beta-tester.