FROM TO MESH AND VICE-VERSA A Simple and Efficient Conversion

Francisco J. Galdames1,3 and Fabrice Jaillet2,3 1Department of Electrical Engineering, Universidad de Chile, Av. Tupper 2007, Santiago, Chile 2Universite´ de Lyon, IUT Lyon 1, Department, F-01000, Lyon, France 3Universite´ de Lyon, CNRS, Universite´ Lyon 1, LIRIS, SAARA team, UMR5205, F-69622, Lyon, France

Keywords: Simplex Mesh, , Optimized Surface Interpolation, Surface Mesh Conversion.

Abstract: We propose an accurate method to convert from a triangular mesh model to a simplex mesh and vice-versa. For this, we are taking advantage of the fact that they are topologically duals, turning it into a natural swap between these two models. Unfortunately, they are not geometrically equivalents, leading to loss of information and to geometry deterioration when performing the conversion. Therefore, optimal positions of the vertices in the dual mesh have to be found while avoiding shape degradation. An accurate and effective transformation technique is described in this paper, where we present a direct method to perform an appropriate interpolation of a simplex mesh to obtain its dual, and/or vice-versa. Our method is based on the distance minimization between the local tangent planes of the mesh and vertices of each face.

1 INTRODUCTION unfortunately in this case, mesh smoothing is gener- ally high; original shape (curvature) and volume is not Deformable model techniques are widely used in properly respected. In (De Putter et al., 2006), an it- image segmentation tasks. Among these models, erative curvature correction algorithm for the dual tri- simplex meshes are valuable candidates (Delingette, angulation of a two-simplex mesh is proposed. Their 1999), for their favorable characteristics in this type solution provides optimal error distribution between of modeling, as its convenient way to model inter- the two dual surfaces while preserving the geometry nal forces. With this type of meshes, as with trian- of the mesh, but at the price of an iterative global min- gulations, any topology can be described. Triangu- imization over the whole meshes. lations are meshes of triangles in which, if they are In this paper, a new technique is presented, achiev- manifolds, each triangle has three neighboring trian- ing reasonable computation cost and minimal loss of gles, while simplex meshes are meshes of geometric information. From a geometric point of in which each vertex has three neighboring vertices. view, the problem can be reduced to finding an in- Simplex meshes and triangulations are topologically terpolation of the center of each face, and to build duals (Delingette, 1999), and this allows us to natu- the dual mesh accordingly to these points. We pro- rally obtain a simplex mesh by applying a dual oper- pose to use a geometric interpolation, based on the ation to the triangulation, and vice-versa. Moreover, distance to the tangent planes of the vertices of each there are some tasks for which simplex meshes are face. A similar measure has been successfully used not suitable, and thus triangulated meshes are more in (Ronfard and Rossignac, 1996) to perform trian- adapted. Examples of these applications are: genera- gular mesh simplifications. Another equivalent mea- tion of volumetric meshes, rendering and calculation sure has been employed, using this time a summation of area. to obtain a quadratic error in (Garland and Heckbert, Currently, the most common way to perform con- 1997; Heckbert and Garland, 1999). In a more recent versions between triangulations and simplex meshes work, a method for refining triangulations has been is to determine the set of vertices for the final mesh developed (Yang, 2005) using a similar measure. It as the gravity center of each face of the initial is worth pointing out that our global objective is to mesh (e.g. (The Insight Segmentation and Registra- perform a transformation between meshes, and not to tion Toolkit (ITK), 2011)). This technique is fast, but refine them. However, we mainly got inspiration from

J. Galdames F. and Jaillet F.. 151 FROM TRIANGULATION TO SIMPLEX MESH AND VICE-VERSA - A Simple and Efficient Conversion. DOI: 10.5220/0003851801510156 In Proceedings of the International Conference on Theory and Applications (GRAPP-2012), pages 151-156 ISBN: 978-989-8565-02-0 Copyright c 2012 SCITEPRESS (Science and Technology Publications, Lda.) GRAPP 2012 - International Conference on Computer Graphics Theory and Applications

this last work. a restricted number of entities is defined, the simplex The paper is organized as follows. In section 2, angle and the metric parameters (Delingette, 1999). we present essential background on simplex meshes, The mesh deformation can be controlled by using their characteristics and relationship with triangula- these entities. tions. The main part concerning the interpolation To perform transformations in any direction be- method used to find the dual mesh is explained in sec- tween these two types of dual meshes, we have to find tion 3. Application of this method to swap between an associated vertex qu of the dual mesh M2 for each meshes is shown in sections 4 and 5, where details face fu of the initial mesh M1. When dealing with can be found for each swap direction. Finally, some triangulations, faces are triangles; and conversely for results are exhibited in section 6, followed by conclu- simplex meshes, faces are polygons whose vertices sions in 7. are generally not coplanar. The resulting mesh M2 should have a regular shape and preserve the geome- try defined by M1, what is far from being straightfor- 2 TRIANGULATION VS. ward. For trying to maintain the geometry, we can im- pose that qu remains close to the tangent planes πi of SIMPLEX MESH each vertex pi defining the face fu. Constraining M2 to have a regular shape, can be achieved by choosing A simplex mesh can be seen as the topological dual qu close to the center of the face fu, i.e. minimize the of a triangulation, each vertex of the simplex mesh distance between qu and all pi. Therefore, we must corresponding to a triangle in the dual triangulation minimize the distance between a point qu and a set of (Fig. 1). However, simplex meshes and triangulations points and planes. A method to achieve the aforemen- are not geometrically duals. Their geometry is de- tioned goal is explained in the next section. termined by the coordinates of their vertices; never- theless, the number of vertices is different between a simplex meshe VS and a triangulation VT . The Euler’s characteristic for a triangulation without holes and its 3 INTERPOLATION BASED ON dual simplex mesh states: TANGENT PLANES

VS VT − = 2(1 − g), (1) The equation of a plane can be denoted as A · p = 0, T 2 where A = [a,b,c,d] and p = [xp,yp,zp,1] is a point where g is the genus of the mesh. As the sets of coor- lying on this plane. The coefficients a,b,c are the −→ dinates have different sizes for a triangulation and its components of the unit vector N normal to the plane, −→ dual simplex mesh (different number of vertices), no accordingly a2 + b2 + c2 = 1, and d = − N · p. For q homeomorphism can be constructed between them. an arbitrary point in the space, |A · q| is the distance to the plane. Considering now a set of planes πi represented by Ai · p = 0 (i = 1,...,L), the distance between T any point q = [x,y,z,1] and each plane πi is |Ai · q|.  On the other hand, consider a set of points p j ( j =    1,...,M). If we want to find the point q minimizing its distance to planes πi and points p j, the function to  be considered follows: L M 2 2 D(q) = ∑ αi |Ai · q| + ∑ β j q − p j (2) i=1 j=1

Figure 1: Simplex meshes and triangulations are topolog- where αi and β j are positive weights for the distance ical but not geometrical duals. White dots: triangulation to the planes (in order to respect geometry and cur- vertices; Black dots: simplex mesh vertices. A vertex of the vature) and points (controlling shape regularity), re- simplex mesh pi and its three neighbors pN1, pN2, pN3 are spectively. Equation (2) can be rewritten in matrix shown. form as: D(q) = qT Qq (3) Simplex meshes can be used to efficiently im- plement segmentation methods based on deformable where L M models. Each vertex of a simplex mesh has three T Q = ∑ αiAi Ai + ∑ β jQ j (4) neighbors pN1(i), pN2(i), pN3(i) (Fig. 1); between them, i=1 j=1

152 FROM TRIANGULATION TO SIMPLEX MESH AND VICE-VERSA - A Simple and Efficient Conversion

and ⃗ pα ⃗   1 0 0 −x j π p p π2  0 1 0 −y j  1 1 pβ 2 Q j =   (5)  0 0 1 −z j  −x −y −z x2 + y2 + z2 j j j j j j Figure 2: Solution of equation (2) as the affine combination Since Q and AT A are symmetric matrices, then of the generalized intersection of planes πi (pα) and the av- j i i erage of all points p (p , here for = ). Q is also symmetric and can be written as: i β βi β q q q q  11 12 13 14 where w is a free positive parameter controlling the q q q q Q =  12 22 23 24 (6) smoothness of the interpolation, and c is the average q q q q  u 13 23 33 34 position of the vertices p . Replacing q by its estimate q q q q i 14 24 34 44 q¯ = [x¯,y¯,z¯]T in eq. (7), it follows: To minimize the quadratic form of eq. (3), the par- ∂D(q) ∂D(q) q11 q12 q13 q14x¯ δx tial derivatives of D(q) are used: x = 0, y = ∂ ∂ q12 q22 q23 q24 y¯ δy ∂D(q)    =  , (10) 0, ∂z = 0. This system of equations can be rewrit- q13 q23 q33 q34z¯ δz ten in a matrix form as: 0 0 0 1 1 1 q q q q x 0 11 12 13 14 Now, the weights β that minimize the residues δ q q q q y 0 i  12 22 23 24  =   (7) should be found, such thatq ¯ approximates the solu- q q q q z 0 13 23 33 34 tion of equation (10) for those β . Because q should 0 0 0 1 1 1 i lie close to the face center, the same weight can be Finally, the solution of eq. (7) follows: assigned to all points, i.e. βi = β. Using the original    −1   planes to express the residues δ, it follows: x q11 q12 q13 −q14 ! y = q12 q12 q23 −q24 (8) L L z q13 q23 q33 −q34 δx = ∑ αiai (Ai · q¯) + β Lx¯− ∑ xi i=1 i=1 T where q = [x,y,z] . This system always has a unique L L ! solution (i.e. the matrix is invertible) because function δy = ∑ αibi (Ai · q¯) + β Ly¯− ∑ yi (2) is strictly convex and therefore has no more than i=1 i=1 one minimum. L L ! δz = ∑ αici (Ai · q¯) + β Lz¯− ∑ zi (11) 3.1 Weights Calculation i=1 i=1 Then, finding the weight can be achieved by The solution of equation (2) can be understood as an β minimizing 2 + 2 + 2. The solution of ( 2 + 2 + affine combination of the generalized intersection of δx δy δz ∂ δx δy 2)/ = 0 leads to: all planes πi (first term) and the average of all points δz ∂β p j (second term). This affine combination is con- TB β = (12) trolled by the weights αi and βi. For example, let’s B2 consider points p1, p2 and planes π1,π2 as shown on where: Figure 2. Planes intersect at point pα, and the aver- L L age of the points (for βi = β) is pβ. The weights αi −→ should reflect the importance of each plane to the in- T = ∑ αi(Ai · q¯)Ni , B = ∑(pi) − Lq¯ (13) terpolation; and this importance will be estimated in i=1 i=1 a different way for triangulations or simplex meshes, To avoid a negative or zero value of β, and to keep as it will be detailed in the next sections. a regular surface, β = min(max(TB/B2,0.1),2) The weights βi can be calculated using a similar method to the one used for mesh refinement in (Yang, 2005). We are looking for an interpolated point q at 4 FROM TRIANGULATION TO the center of each face. Assuming that L vertices p −→ i SIMPLEX SURFACE MESH define a face, and Ni are the unit normal vectors to the mesh at pi, then we can estimate the position for q as: In this section, we will see the first case, i.e. convert- L −→ −→ ing a triangulation into a simplex surface mesh. In q¯ = cu + w ∑((pi − cu) · Ni )Ni (9) i=1 this case, an appropriate vertex qu on the new simplex

153 GRAPP 2012 - International Conference on Computer Graphics Theory and Applications

mesh must be computed for each triangular face tu. faces of a simplex mesh do not have a fixed num- Then, we need information for each triangle tu about ber of vertices pi (i = 1,...,Nu), and moreover they the curvature of the mesh. Let us consider the tangent are generally not coplanar. The distance between qu planes to the vertices pi (i = 1,2,3) composing tri- and the planes πi tangent to the vertices pi, is mini- angle tu (Fig. 3(a)); these planes πi can be written as mized to maintain the geometry of the mesh. These Ai · p = 0 as defined previously. The normal vectors planes are defined by the vertices pi and the nor- that define these planes can be calculated as: mal vector at each vertex. In a simplex mesh, nor- L −→ mals are defined by the plane containing the three −→ i φ N ∑k=1 k k p , p , p Ni = −→ , (14) neighbors N1(i) N2(i) N3(i) of the considered ver- Li N p q ∑k=1 φk k tex i (Delingette, 1999). As in the inverse case, u −→ should lie close to the center of the face fu to preserve where Nk (k = 1,...,Li) are the normals of the trian- a regular shape. Figure 3(b) illustrates these planes gles tk to which the vertex pi belongs, and φk is the and vertices. As previously, eq. (2) can be used to angle of the triangle tk at vertex pi (Fig. 3(a)). calculate qu by minimizing the distance to planes πi To approximate the surface, the distance between and vertices pi. the new vertex qu and planes πi is minimized. Again, The surface of the circle defined by the neighbors qu should not lie too far from the center of triangle tu of each vertex pi is a good estimation of the impor- to preserve a regular shape, therefore qu should mini- tance the plane πi has within the mesh, therefore its mize its distance to vertices pi. The direct minimiza- radius ri is used to calculate the weights αi. It fol- tion of eq. (2) will provide us with an appropriate qu. lows: 2 ri αi = N (16) ⃗ ⃗ ∑ u r2 ⃗ j=1 j π 3 π5 Again, in this case, weights βi are calculated with p p5 ⃗ π 3 p4 equation (12). 1 ⃗ π ⃗ π1 ⃗ 4 p1 tu fu π 2 p ⃗ p3 φk p2 1 π3 6 RESULTS p2 π2 (a) (b) To measure the quality of the transformations in both directions, the set of successive transformations Figure 3: (a) Scheme of triangle t , planes and vertices used u (T1 → S1 → T2 → ··· → Tk → Sk → Tk+1 → ··· → to find vertex qu of the dual simplex mesh. (b) Scheme of TN → SN) is performed, where Tk is a triangulation face fu, planes and vertices used to find vertex qu of the dual triangulation. and Sk a simplex mesh, with (k = 1,...,N). It is ob- vious that such back and forth conversion will never be required by any application, but successive trans- Each weight α computation is based on the area a i i formations magnify, and thus pointing out, incorrect corresponding to the sum of the areas of all triangles behaviors of a technique. tk sharing pi (Fig. 3(a)): a The proposed technique has been compared to the i i.e. αi = 3 . (15) most commonly used at this time, using the Cen- ∑ j=1 a j ter of Mass of each face to compute the corresponding This way, the distance to each plane is weighted vertex of the dual mesh (Delingette, 1999). Since all according to the area of triangles that were used to meshes Tk and Sk have respectively the same number calculate it. The weights βi are calculated with equa- of vertices, we have considered that the most appro- tion (12). priate measure was a simple vertex-to-vertex distance computation after each transformation cycle. This way, each triangulation is compared at each step to the 5 FROM SIMPLEX TO initial triangulation; and correspondingly, each sim- plex meshes is considered accordingly to the first sim- TRIANGULATION SURFACE plex mesh obtained. MESH Figure 4 shows the distance graph measured for the surface of cerebral ventricles (1360 ver- In this section, we are dealing now with the converse tices/simplex faces, 2728 triangles/simplex vertices), case. A vertex qu of the triangulation must be calcu- for 150 iterations. The vertex-to-vertex mean dis- lated for each face fu of the simplex mesh. However, tances are expressed as a percentage of the bounding

154 FROM TRIANGULATION TO SIMPLEX MESH AND VICE-VERSA - A Simple and Efficient Conversion

Table 1: Hausdorff distances and computational time. Center Distance Gain of Mass to Planes [%] min 0.0 0.0 0.0 Block max 0.019153 0.014321 25.23 (a) Mesh mean 0.002397 0.001820 24.07 time [ms] 165.219 6330.415 -3731.53 min 0.0 0.0 0.0 Horse max 0.004596 0.003873 15.74 Mesh mean 0.000126 0.000047 62.50 time [ms] 3718.78 116221.5 -3025.26 (b) (c) min 0.0 0.0 0.0 Bunny max 0.003321 0.002761 16.85 Mesh mean 0.000220 0.000096 56.36 time [ms] 2734.51 86895.5 -3077.74

(d) (e) box diagonal of T1 or S1, respectively. Curve 4(a) shows results using the Center of Mass technique, while 4(b) draws results with our technique. If we compare the results for a set of meshes, the Center of Mass technique produces high degeneration in some (f) (g) parts of the mesh (Fig. 5(b), (d) and (f)), losing most Figure 5: Cerebral ventricles mesh (a) after successive of the details present in the initial geometry. However, transformations between simplex (lighter) mesh and trian- using an interpolation based on the tangent planes gulation (darker). Left: meshes obtained using the faces’ as presented in this article, it can be clearly seen on mass centers, after (b) 5, (d) 15 and (f) 50 cycles. Right: Fig. 5(c), (e) and (g), that the initial geometry is much meshes obtained using our technique, after (c) 5, (e) 15 and better preserved. (g) 50 cycles.

mations, i.e. swapping back and forth to simplex mesh and triangulation. Figure 6 shows the initial meshes with coloration according to their distance to the resulting one, and Table 1 shows the well known ratio between measured distances and the bounding box diagonal of the original mesh. The mean dis- tance between two surfaces M1 and M2 is defined 1 R as: Mean dist.(M1,M2) = HD(p,M2)ds, |M1| p∈M1 where HD(p,M) is the Hausdorff distance between point p and surface M, and |M| its area. As it can be guessed, in both cases, the main error is concen- trated in high curvature areas. But, as previously seen, Figure 4: Curves of the mean error of the successive trans- the error dramatically decreases with our technique formations of a cerebral ventricles surface (a) Transforma- (Fig. 6, right column). tion based on the faces center of mass. (b) Interpolation From examining equation (2), the question of the based on tangent planes. topological validity of the resulting mesh may arise. The solution is an equilibrium between shape preser- As a complementary result, the Hausdorff dis- vation and mesh smoothing, that behaves properly tance was measured as well between initial and (i.e. the point lays inside the triangle). However, for transformed meshes by using the Metro tool that extreme cases like spiky meshes with high curvature adopts a surface sampling approach (Cignoni et al., areas, some additional feature preserving process may 1998). The Block (2132 vertices, 4272 triangles; be required. from AIM@SHAPE), Horse (48485 vertices, 96966 Table 1 also shows the computational time of each triangles; from Cyberware, Inc), and Bunny (34834 mesh in milliseconds1. The computational time was vertices, 69451 triangles; from Stanford 3D Scan- ning Repository) meshes have been considered; and 1Developed in Python Language on AMD Athlon 62x2 the distance was measured after a cycle of transfor- Dual, 2GHz, 1Gb RAM.

155 GRAPP 2012 - International Conference on Computer Graphics Theory and Applications

multiplied by approximately 33 with our method. The vice-versa. Compared to the ones proposed in the lit- computational time is linear according to the number erature, our method is straightforward and does not of vertices of the mesh because our method is direct require any iteration. It is intuitively based on the in- and performed locally for each vertex. From the re- terpolation of the initial mesh to find the correspond- sults we obtain, we believe it is worth paying an ex- ing vertices of the dual mesh. The interpolation is tra (but limited) amount of computation to drastically based on a direct and local minimization of the dis- improve the final quality of the dual mesh. Moreover, tance to tangent planes, and vertices of each face. Our the large computational time may be explained by the transformation technique was compared to the most fact that our implementation is carried out in an in- frequently used method, which is based on placing the terpreted language (Python). By performing a sim- dual vertices at the center of mass of the initial faces, ple test of numerical computation, we have verified and the weaknesses of this latter have been illustrated. that the computational time can be reduced about 400 The performance of the proposed method was mea- times with a C++ implementation instead of Python. sured using a vertex-to-vertex distance between both triangulations and simplex meshes, after performing a chain of successive transformations. Moreover, we measured the Hausdorff distance between meshes af- ter performing a cycle of transformations, i.e. after carrying out a transformation to simplex mesh and back to triangulation. The performance of our method was more than satisfactory, providing a significant re- duction of the error, of nearly 50%, at reasonable lin- ear time. Thus, our method has proven to be ade- quate to be used in any application requiring topolog- ical mesh transformation while preserving geometry, (a) (b) and without increasing complexity.

REFERENCES

Cignoni, P., Rocchini, C., and Scopigno, R. (1998). Measur- ing error on simplified surfaces. Computer Graphics (c) (d) Forum, 17(2):167–174. De Putter, S., Vosse, F., Gerritsen, F., Laffargue, F., and Breeuwer, M. (2006). Computational mesh generation for vascular structures with deformable surfaces. Int. J. of Computer Assisted Radiology and Surgery, 1:39– 49. Delingette, H. (1999). General object reconstruction based on simplex meshes. Int. J. of Computer Vision, 32(2):111–146. (e) (f) Garland, M. and Heckbert, P. S. (1997). Surface simplifica- tion using quadric error metrics. In ACM SIGGRAPH Figure 6: Block, Horse and Bunny meshes colored accord- proceedings, pages 209–216. ing to the Hausdorff distance after a cycle of transforma- Heckbert, P. S. and Garland, M. (1999). Optimal triangu- tions. The blue-green-red color scale is used, where red rep- lation and quadric-based surface simplification. Com- resents the largest value .1) Left, subfigures (a), (c) and (e) putational Geometry: Theory and Applications, 14(1- using Center of Mass. 2) Right, subfigures (b), (d) and (f) 3):49 – 65. using our method based on Distance to the tangent planes. Ronfard, R. and Rossignac, J. (1996). Full-range approxi- mation of triangulated polyhedra. Proc. of Eurograph- ics, Computer Graphics Forum, 15(3):67–76. The Insight Segmentation and Registration Toolkit (ITK) 7 CONCLUSIONS AND (2011). www.itk.org. www.itk.org. DISCUSSION Yang, X. (2005). Surface interpolation of meshes by geometric subdivision. Computer-Aided Design, 37(5):497–508. We have presented a method to carry out transforma- tions between triangulations and simplex meshes, and

156