Full text
Facultat d’Inform` atica de Barcelona Final Master Project Master in Innovation and Research in Informatics Computer Graphics and Virtual Reality Efficient discretization of signed distance fields Eduard Pujol Puig Director: Antonio Chica Calaf June 21, 2022
Acknowledgements I would like to thank and express my gratitude to my thesis supervisor, Professor Antonio Chica. He has been helping me a lot since I started thinking about the thesis. He has always solved all my doubts and questions. I appreciate all the dedication he offered when I needed it. I would not have been able to finish this project without him. Finally, I want to thank my friends and family for their continuous support. 1
Abstract A Signed distance field (SDF) is an implicit function that returns the distance to the surface of a volume given a point in the space. The sign of the field indicates if the point is inside or outside the volume. These fields are usually used to accelerate computer graphics algorithms in different areas, such as rendering or collision detection. There are many well-defined primitives and operators to model objects using these functions. For example, SDFs allow applying smooth boolean operations between primitives. Applying these operators to triangles meshes can require complex algorithms susceptible to precision problems. Even though SDFs allow modelling objects, they currently are not a used format, and not many modelling tools use it. Most of the time, we want to calculate this field from triangle meshes. If the mesh is two-manifold, the easiest way to calculate the signed distance from a point is by searching for the minimum distance at all the mesh triangles. This strategy requires iterating all the triangles for each query to the signed distance field. There are methods based on different strategies that accelerate this nearest triangle search. If the user does not require getting exact distances to the object, other strategies exist that discretize the space in some fixed sample points. Then, the queries to arbitrary points are calculated using an interpolation of the precalculated discretization. This project presents a new approach based on an octree-like subdivision to accelerate the computation of these signed distance fields queries from a triangle mesh. The main idea is to construct an octree structure in which each leaf will contain only the nearest triangles for all the points in that region. Therefore, when the user wants to calculate the distance from an arbitrary point in the space, it will only compare the triangles influencing that region. Moreover, we present a method to calculate approximated distances based on the discretization approach mentioned before. We designed and developed an octree discretization strategy and explored different interpolation techniques. The distance computation of this discretization is accelerated by the strategy developed in the project. 2
Contents 1 Introduction 8 2 Related work 9 2.1 Signed distance field computation . . . . . . . . . . . . . . . . . . . . . . . . 9 2.1.1 Accelerating signed distance field queries . . . . . . . . . . . . . . . 9 2.1.2 Gridcomputation ............................ 11 2.1.3 Grid interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.2 Applications.................................... 14 2.2.1 Calculate geometric properties . . . . . . . . . . . . . . . . . . . . . 14 2.2.2 Surface reconstruction . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.2.3 Collision detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.2.4 Rendering................................. 17 3 Overview 18 4 Signed distance field from a triangle mesh 20 4.1 Distance to a triangle mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 4.2 Signcomputation................................. 22 4.3 Fieldgradient................................... 23 4.4 Implementation details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 5 Triangles influencing a region 25 5.1 Rbyradius.................................... 27 5.2 Rbyinterpolation ................................ 29 5.3 Computing distance between convex shapes . . . . . . . . . . . . . . . . . . 32 5.4 Implementation.................................. 39 6 Signed distance field acceleration structure 52 6.1 TerminationHeuristic .............................. 52 6.2 Results....................................... 53 7 Approximated signed distance field 59 7.1 TerminationHeuristic .............................. 59 7.2 Polynomial apporximation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 7.3 Forcingcontinuity ................................ 63 3
7.4 Results....................................... 64 8 Conclusions and future work 69 8.1 Conclusions.................................... 69 8.2 Futurework.................................... 70 A Trilinear interpolation properties 71 A.1 Trilinear interpolation is a composition of linear interpolations . . . . . . . 71 A.2 Trilinear interpolation is distributive over addition . . . . . . . . . . . . . . 71 A.3 The norm of the interpolation of a set of vectors with the same direction is equal to the norms interpolation . . . . . . . . . . . . . . . . . . . . . . . . 72 A.4 The norm of the interpolation of a set of vectors is smaller or equal to the normsinterpolation................................ 72 B Convex Hull properties 73 B.1 The convex hull of a dilation of a set is the dilation of its convex hull if the structuring element used by the dilation is convex. . . . . . . . . . . . . . . 73 4
List of Figures 2.1 (a) Voronoi regions of faces. (b) Voronoi regions of edges. (c) Voronoi region of an edge. (d) Voronoi regions of vertices. Image from [5] . . . . . . 12 2.2 Comparison between the trilinear interpolation and the method proposed by B´an and Valasek [9]. Image from [9] . . . . . . . . . . . . . . . . . . . . 14 2.3 Representation of the Macklin [17] method to search a collision between a segment and an object represented by a distance field. The red circles represent the solver iterations. Image from [17]. . . . . . . . . . . . . . . . . 16 2.4 Scene with the global illumination calculated using the Evans [19] method. The distance field has a resolution of 128 x 128 x 128. Image from [19]. . . 17 4.1 Triangle transformed for the distance computation. The variables are the data needed to test in which region belongs the point. . . . . . . . . . . . . 21 4.2 The vertex pseudonormal average. . . . . . . . . . . . . . . . . . . . . . . . 23 5.1 Example of region R∗from only a segment S................. 26 5.2 Composition of regions that form R∗for a mesh containing three segments. 27 5.3 Example of the region Rr S.xis the furthest point to the segment S. Therfore, δ=d(x, S). ................................. 28 5.4 Shape comparison between the set R∗ Sand Rr S. Where Sis the segment in black. ....................................... 29 5.5 Example of RCH ................................. 30 5.6 Shape comparison between the set R∗ Sand RCH S. Where Sis the segment inblack....................................... 32 5.7 Minkowski difference between Aand B..................... 33 5.8 Example of the Minkowski difference support point computation. Where sMD(A,B)(v) = sA(v)−sB(−v)......................... 34 5.9 GJKiterationexample.............................. 36 5.10 Example calculating direction by v, the nearest direction to the origin from atriangle. .................................... 37 5.11 Frank-Wolfe iteration example . . . . . . . . . . . . . . . . . . . . . . . . . 38 5.12 Frank-Wolfe example when origin is inside. . . . . . . . . . . . . . . . . . . 39 5.13 GJK early termination example . . . . . . . . . . . . . . . . . . . . . . . . . 40 5.14 RCH Tisupport point computation in direction v................ 41 5.15 Example of Frank-Wolfe termination criterias. . . . . . . . . . . . . . . . . . 42 5
5.16 Example of RCH Tispherically eroded by the minimum sphere radius, which is d00 ........................................ 44 5.17 Execution time with different strategies. . . . . . . . . . . . . . . . . . . . . 47 5.18 Mean of triangles per node in each octree depth with different strategies. . . 48 5.19 The number of calls in percentage solved with a number of iterations. . . . 48 5.20 Comparison of selected triangles between region methods . . . . . . . . . . 49 5.21 Comparison of selected triangles between region methods. . . . . . . . . . . 50 5.22 Execution time using different heuristics with Rby interpolation. . . . . . . 51 5.23 The percentage of more triangles selected than in the best heuristics. . . . . 51 6.1 Results using different minimum number of triangles per leaf with the Armadillomodel. .................................. 54 6.2 Percentage of leaf nodes in each octree depth with different minimum numberoftrianglesperleaf ............................. 54 6.3 Armadillo slice signed distance filed. . . . . . . . . . . . . . . . . . . . . . . 55 6.4 Octree with a minimum of 32 triangles per leaf. The colours go from 32 triangles (white) to 132 triangles (dark red). . . . . . . . . . . . . . . . . . . 55 6.5 Octree with a minimum of 64 triangles per leaf. The colours go from 64 triangles (white) to 164 triangles (dark red). . . . . . . . . . . . . . . . . . . 56 6.6 Octree with a minimum of 96 triangles per leaf. The colours go from 96 triangles (white) to 196 triangles (dark red). . . . . . . . . . . . . . . . . . . 56 6.7 Octree with a minimum of 128 triangles per leaf. The colours go from 128 triangles (white) to 228 triangles (dark red). . . . . . . . . . . . . . . . . . . 57 6.8 Octree with a minimum of 160 triangles per leaf. The colours go from 160 triangles (white) to 260 triangles (dark red). . . . . . . . . . . . . . . . . . . 57 7.1 Comparison between neighbour cases. . . . . . . . . . . . . . . . . . . . . . 63 7.2 Subdivisionexample. .............................. 64 7.3 Computation time with different requested errors. . . . . . . . . . . . . . . 65 7.4 Comparison between the requested error and real error. . . . . . . . . . . . 66 7.5 Octree generated using trilinear interpolation with an error threshold of 10−3........................................ 66 7.6 Octree generated using tricubic interpolation with an error threshold of 10−3........................................ 67 7.7 Forcing continuity example. . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 7.8 Query time (in microseconds) with different requested errors. . . . . . . . . 68 6
List of Tables 6.1 Computation time and query time comparison with other methods. . . . . . 58 7
Chapter 1 Introduction A signed distance field (SDF) is a function that returns a distance to the surface object at any point in the space. The distance sign indicates whether the point is inside or outside the object. Knowing the distance to an object is an interesting property required in many fields related to computer graphics and geometry processing. Signed distance fields are used in rendering, collision detection or shape reconstruction. Recently, there have been investigations using signed distance fields for shape reconstruction and shape synthesis using deep learning. In computer graphics, triangle meshes are the most used format to represent objects. Therefore, computing the signed distance from a point to a triangle mesh is an interesting application. There are different approaches to accelerate the process. Some methods are based on finding the nearest triangles to the query point, and others are based on computing an approximation of the field using a space discretization. In this thesis, we propose a new strategy for accelerating signed distance field queries from objects represented with triangles meshes. 8
Applying offsets, spherical dilations and erosions, is usually used in modeling tools, for example, to apply tolerances in CAD programs. Liu and Wang [11] propose a method for offsetting objects. The method calculates the distance field near the object’s surface and then extracts a mesh of the field in the desired isovalue. The main disadvantage of this method is that the extracted mesh can present bad results in complex parts of the object if the distance field resolution is not enough. The medial axis of an object is the set of points that have more than one nearest point to the object’s surface. This property is usually used for automatic object rigging [12] and for shape segmentation [13]. In a signed distance field, these points represent local minimums. There are methods [14] that calculate these medial axis points by searching the local minimums in a distance field. 2.2.2 Surface reconstruction Surface reconstruction is a technique that generates a triangle mesh from a point set. Usually, these point clouds contain noise and do not have the same point density in all parts. Therefore, in most cases, extracting a triangle mesh directly from the points will not give a good reconstruction. Some methods use a distance field as an intermediate representation between the point representation and the final reconstructed mesh. Calakli and Taubin [15] proposes a method that uses a distance field for reconstructing point-sets that contain the position and surface normal of each point. They represent a distance function using an octree discretization of the space. The function inside an octree node is calculated using a trilinear interpolation of its eight corners. The octree is subdivided if the number of points contained by one node exceeds a threshold. They define an energy function that promotes the correspondence between the points and the function. The energy function forces the function to be zero and its gradient to be equal to the point normal at each point of the point-set. Also, they add a regularization factor to force some smoothness degree to the function. The regularization factor forces the square sum of the Hessian matrix components to be close to zero. Finally, they minimize the energy function by formulating it as a least-squares minimization problem. 2.2.3 Collision detection Another useful usage of distance fields is for detecting and solving collisions. Depending on the type of collision needed to solve, they are used in different ways. 15
Macklin and M¨uller [16] uses SDFs to solve collisions with solid shapes in fluid simulation. They simulate the fluid as a set of particles that have internal forces between the nearest particles. The distance fields are used to solve the collision between the fluid particles and a complex solid shape. The method only requires evaluating the field one time for each particle to detect if particles are inside or outside the solid. The collision response is calculated using the gradient of the field. SDFs are very efficient in solving collisions with spherical particles, but solving collisions with more complex objects can be more complicated. Macklin et al. [17] proposes a method to solve collision between a deformable object represented by a mesh and a solid represented by a signed distance field. They formulate the problem as a constraint minimization problem to find the smallest field values inside the object mesh. If the smallest value is negative, the objects are colliding. They search the minimum point using gradient descent. From the mathematical point of view, this collision detection will only work if both objects are convex, otherwise, the gradient descent could find a local minimum. The paper simulates collisions between non-convex objects using multiple starting points in the search. However, the method does not guarantee to detect always the collision between non-convex objects. Figure 2.3: Representation of the Macklin [17] method to search a collision between a segment and an object represented by a distance field. The red circles represent the solver iterations. Image from [17]. 16
2.2.4 Rendering SDFs are used in some rendering algorithms to improve renderization quality. Most of the methods use a technique proposed by Hart [18] called sphere tracing. Sphere tracing is a ray casting technique for distance fields. The method given a start position and direction iterates the ray in a variable step size until colliding with a surface. The step size in one point of the ray is equal to the value of the distance field because we can guarantee that there is no surface in that radius. Sphere tracing can be used to visualize distance fields by throwing a ray for each pixel of the virtual camera. Next, we present some methods that use SDFs to improve the render quality. Evans [19] presents a real-time method to approximate the global illumination of a scene using distance fields. For each fragment rasterized, the method makes some samples to the distance fields towards the fragment’s normal direction. If the field value in one sample point is smaller than the real distance between the sample point and the surface point, the sample has another surface point near that can be a potential light blocker. They use the difference between the real distance and the field value in each sample point to calculate the level of light reached by global illumination. Figure 2.4: Scene with the global illumination calculated using the Evans [19] method. The distance field has a resolution of 128 x 128 x 128. Image from [19]. Tan et al. [20] proposes a method that approximates soft-shadows for real-time applications. The technique uses sphere tracing to check if the light reaches the surface points. If the ray does not collide with any object, they use the minimum distance obtained during the ray tracing to estimate the amount of light reaching the surface point. Moreover, they explain some techniques to reduce artifacts obtained using a low-resolution SDF. 17
Chapter 3 Overview In the project, we present a new approach to accelerate queries for the signed distance field from a triangle mesh. We present two different methods using a similar strategy: •A data structure for accelerating arbitrary queries to an object’s distance field. •An adaptive discretization of the signed distance field to solve distance queries faster. This data structure represents an approximation of the distance field. The queries solved using this method does not return the real distance to the surface, but a very close approximation. Both data structures are based on a space subdivision using an octree. Each leaf of the octree represents a region of the space. The difference between the methods is the data stored in each tree leaf. The objective of the first method is to accelerate the distance field queries at any point in the space. Therefore, each leaf stores the necessary information to calculate the real distance field at any point inside the node. We explain the method in more detail in chapter 6. In the second method, each leaf stores a polynomial representing the field’s behaviour inside the region. The data structure and the algorithm are explained in more detail in chapter 7. We use a common strategy to compute these structures efficiently using the incremental subdivision of the octree. The algorithm starts with a box representing the space we want to represent and a triangle mesh. The box is the root node of the octree. Initially, we assign all the mesh triangles to the root node. In each algorithm step, the nodes are subdivided into eight equal children. For each child, we select only the triangles of the parent that influence the child. When the octree reaches the desired depth, we calculate the leaf information of the chosen method using only the node triangles. 18
The distance field behaviour in a region is usually described by a subset of the triangles forming the object. The smaller the region, the fewer triangles will describe the distance field of that region. When a triangle describes a part of the field in a region, we say that the triangle influences that region. With this strategy, we reduce the number of triangles per node in each subdivision. At large octree depths, the number of nodes is also large, but the number of triangles per node is small. Therefore, it is faster to recursively subdivide the space than computing directly the leafs’ node information using all the mesh triangles. In chapter 5, we explain the different techniques used to test if a triangle influences a node. Some of these techniques overestimate the triangles’ influence for efficiency purposes. So, the method can classify a primitive as an influencing triangle when, in reality, it is not. But, if the triangle influences the node, the method must classify it as influencing. In the end, our strategy is conservative. 19
Chapter 4 Signed distance field from a triangle mesh In this chapter, we will explain how to get the signed distance field from a triangle mesh. A signed distance field represents a function that returns the distance to the volume surface for every point in the space. The sign of the distance represents if the point is inside or outside. If the point is inside, the distance will be negative, and if it is outside positive. The subset of points in which the distance is zero forms the volume surface. Next, we will explain the different steps of calculating the signed distance from a triangle at any arbitrary point. 4.1 Distance to a triangle mesh Given an arbitrary point p, the distance to a surface is defined as the infimum distance between pand all the points belonging to the surface. So, we compute the distance to a triangle mesh as the minimum distance to all the triangles. To calculate the distance between pand a triangle, first, we have to identify in which Voronoi region it belongs. It can belong to the face, edge or vertex regions. A triangle has seven different regions and nine separating planes. After determining which region contains p, we only need to calculate the distance between pand the element of the region. For example, if pbelongs to a vertex region, the distance to the triangle will be the distance to that vertex. It is crucial to evaluate the distance between point and triangle fast because it is one of the most used functions in our method. 20
We use a technique proposed by Jones [21]. The method transforms the triangle to do the region detection in 2D instead of 3D. However, the technique requires storing more data than only three points to be efficient. We calculate the properties needed to evaluate the triangle distance using this method in a preprocess before starting the signed distance field generation. Given a triangle formed by the vertices v1,v2.v3. We set the origin of the new space as v1. Then, we create an orthonormal transform that rotates the triangles in a way in which the triangle normal vector becomes the Z-axis, and the vector −−−→ v1v2becomes the X-axis. We use an orthonormal transformation to be able to evaluate representative distances in the transformed space. Also, we need to store information about the triangle in the new space. The position of the vertex v1is the origin, so we do not need to store extra information. For the v2po- sition we have to store only the X-axis coordinate, because −−−→ v1v2is aligned to the X-axis. Finally, for the v3position, we have to store the two coordinates. Moreover, we store the unitary vectors perpendicular to the edges in this XY-plane in the new space to reduce the number of operations needed in the region evaluation. In Figure 4.1, we have a representation of a triangle transformed. The seven different regions are the different colour zones. The variables in the image are the extra data explained in the previous paragraphs (the point coordinates and the perpendicular vectors to the edges). Figure 4.1: Triangle transformed for the distance computation. The variables are the data needed to test in which region belongs the point. 21
Without storing extra data, a triangle is represented by three vectors, a total of 9 decimal values. With this method, we have to store the origin of the space, a 3x3 transform matrix, and the extra data explained before. So, we need to keep 19 decimal values for each triangle. That is more or less the double of storing the triangle as usual. To evaluate if the increase in memory is worth it, we compare the method with an algorithm that uses only the three vertices position. This other technique computes the separating planes on the fly in 3D. In the analysis, we conclude that our method is 3.6 times faster than the other technique. Our method takes 19ns for each call, and the other takes 69ns for each call. 4.2 Sign computation In the previous section, we explain how to calculate the distance to a surface formed of triangles. The distance to the surface is always positive; therefore, we want to change the distance sign when the point is inside the object. Any mesh represents a surface, but it does not always represent a volume. In this project, we only support closed orientable two-manifold meshes because they always represent a closed volume and computing if a point is inside or outside only requires the nearest triangle. A mesh is a closed two-manifold if it does not contain intersections between triangles. Every edge is adjacent to two triangles. And the triangles on a vertex form a single cycle around the vertex. A Voronoi region of a triangle mesh can contain points inside and outside the volume, but in the case of triangle meshes, there is always a plane that separates the two types of points. For example, in a region formed by a face, the plane containing the face is a separating plane. The points outside the volume will always be on the side towards the face normal, and the points inside will always be on the other side. The separating plane for face regions is simply the face normal, but in edges and vertices, we have to calculate this plane. Baerentzen and Aanaes[2] define and prove a pseudonormal that always separates the inside and outside vertex regions. They define the plane normal as the normal vector weighted average of all the triangles incident on the vertex. The weight of each triangle is the corner angle formed by the vertex. In Figure 4.2, we have a drawing representing the pseudonormal computation. The vector nαis the separating plane normal of the top vertex. 22
Figure 4.2: The vertex pseudonormal average. In the edges’ region, they use the normal average of the two faces incidents to the edge. From a theoretical point of view, the Voronoi cell of an edge will only contain points inside or outside the volume. If the two triangles are convex, all the region points will be outside, and if they are concave, all the points will be inside. However, we compute the sign in each call to avoid precision errors when the incident faces are coplanar. In the implementation, we precompute these normals before computing the distance field data structure. We store these normals for each triangle. 4.3 Field gradient In some methods of the project, we need the gradient of the signed distance field. In the case of triangle meshes, the gradient can be easily computed after identifying which Voronoi region owns the query point. If it belongs to a region formed by a face, then the gradient is always the unit normal of the triangle. In a vertex region, the gradient is the vector going from the vertex to the point normalized. Finally, in an edge region, the gradient is the vector perpendicular to the edge and with direction towards the query point. Given an edge form by e1and e2and a query point pwhich its nearest element is the edge. Then the gradient of the signed distance field at that point is: ∇f(p) = (e2−e1)×((p−e1)×(e2−e1)) ∥(e2−e1)×((p−e1)×(e2−e1)) ∥ 23
4.4 Implementation details In the project, we usually have to calculate the signed distance field in one point, given a set of triangles influencing a region of the space. To reduce the amount of work to do, first, we search which is the nearest triangle, computing only the square distance without the sign. After determining the nearest triangle, we calculate the sign and, if it is needed, the gradient. 24
∀α, β, γ ∈[0,1] T riInt(α, β, γ, dijk)≥d(T riInt(α, β, γ, Cijk), Ti) First, we define Qijk as the nearest points from Tito Cijk: Qijk = arg min x∈T1 ∥x−Cijk∥ TriInt(α, β, γ, dijk) = (5.1) =TriInt(α, β, γ, ∥Qijk −Cijk∥)≥(5.2) ≥ ∥TriInt(α, β, γ, Qijk −Cijk)∥= (5.3) =∥TriInt(α, β, γ, Qijk)−T riInt(α, β, γ, Cijk)∥= (5.4) =d(TriInt(α, β, γ, Qijk), T riInt(α, β, γ, Cijk)) ≥(5.5) ≥d(TriInt(α, β, γ, Cijk), Ti) (5.6) The step from eq (5.1) to eq (5.2) is by definition of distance. The step from eq (5.2) to eq (5.3) is using a property of trilinear interpolation. The property says that given a trilinear interpolation of vectors, the norm of interpolating the vectors will always be smaller or equal to the trilinear interpolation of their norms. See appendix A.4 for a formal proof. In the step eq (5.3) to eq (5.4) we use the trilinear interpolation distribution over addition (see appendix A.2): TriInt(α, β, γ, uijk +vijk) = T riInt(α, β, γ, uijk) + T riInt(α, β, γ, vijk) From the eq (5.4) to eq (5.5) we use the definition of distance. Finally, from the eq (5.5) to eq (5.6), we use that T riInt(α, β, γ, Qijk) will always belong to Ti, because, by definition, all the Qijk are inside Ti. In a trilinear interpolation between points if the points belong to the convex shape then all the interpolated points will, also, be inside the shape. Therefore, T riInt(α, β, γ, Qijk) can be the nearest point to Cijk or a further point. Next, we want to prove that RCH Ti⊇R+ Tiby demonstrating that any point pinside R+ Tiis inside RCH Ti. phas to be inside one of the spheres S(T riInt(α, β, γ, Cijk), TriInt(α, β, γ, dijk)) that compose R+ Ti, which means that we can write pas T riInt(α, β, γ, Cijk) + vwhere ∥v∥ ≤ TriInt(α, β, γ, dijk). 31
Now, we define one vector vijk inside each of the spheres Sijk =S(Cijk, dijk) with the same direction as v, and a norm equal to their radii dijk. The trilinear interpolation of these vectors at pwill be T riInt(α, β, γ, vijk) and by appendix A.3 it has a norm equal to TriInt(α, β, γ, dijk) which is larger than ∥v∥. By scaling vijk by the ratio between ∥v∥ and TriInt(α, β, γ, dijk) we get new vectors v′ ijk that are smaller than their correspondent vijk and, thus, are still inside their respective spheres Sijk. But now, using the trilinear interpolation of v′ ijk, we can express pas T riInt(α, β, γ, Pijk) + TriInt(α, β, γ, v′ ijk) or the trilinear interpolation of points C′ ijk =Cijk +v′ ijk which are each inside one of the 8 spheres Sijk. Therefore, pis inside the convex hull of {P′ ijk}and has to be in RCH Ti, and thus R+ Tiis a subset of RCH Ti. As we proved earlier, RCH Tiis convex and allows us to test if a triangle intersected with the methods we will explain in the next section. However, RCH, the intersection of all the RCH Ti, is not convex and easy to compute. Therefore, using this method, we can only test if a triangle influences a region over another triangle. In Figure 5.6, we have a comparison between the region R∗and RCH of the segment S. As we can see, the method region is more similar to the optimal area than the method explained before. In most cases, both regions are almost identical. In the example, the segment was positioned in a worst-case scenario to be able to see the two sets. Figure 5.6: Shape comparison between the set R∗ Sand RCH S. Where Sis the segment in black. 5.3 Computing distance between convex shapes To test if a triangle influences a node, we will test if it intersects one of the regions explained before. We need an algorithm to test if two convex sets intersect each other. We develop and analyze two methods with different characteristics, GJK and Frank-Wolfe. Before explaining the two methods, we will explain the Minkowski difference operator, an operation used in both methods. 32
Minkowski difference Given two sets of points Aand Bwe define the Minkowski difference MD of both sets as: MD(A, B) = {a−b|a∈A, b ∈B} We can see MD(A, B) as the set of differences between the points of the two sets. If the two sets intersect, then at least one point will belong to both, so the point −→ 0must belong to the set MD(A, B). Furthermore, the minimum distance between the two sets is the nearest point to the origin of MD(A, B), because the point is the smaller possible distance between points of both sets. So, we can compute the distance between the two sets as: d(A, B) = min x∈MD(A,B)∥x∥ An attractive property of the Minkowski difference is that if Aand Bare convex sets, then MD(A, B) will be convex. In Figure 5.7, we can see an example of a Minkowski difference of two sets A,B. Notice that the distance between Aand Bis equal to the distance between MD(A, B) and the origin O. Figure 5.7: Minkowski difference between Aand B The methods we will explain later are designed to find the nearest point to the origin given a convex set of points. The most interesting part is that the methods do not require all the points of the set. They only need the support mapping of the set. The support mapping of a convex set Ais a function sAthat returns the furthest point in a given direction v: sA(v) = arg max x∈Av·x 33
The resulting point of support mapping is called the support point. By the Minkowski difference definition, we can calculate sMD(A,B)using only sAand sBwithout computing all the points of the set. Given a direction v, we want to find the largest point on the set MD(A, B) in that direction. The points of the set sMD(A,B)are the points of Aless the points of B. Therefore, we want to find the maximum point of Aand the smaller point of Bin the direction v. So, we can formulate sMD(A,B)as: sMD(A,B)(v) = sA(v)−sB(−v) In the Figure 5.8, we can see an example of the support point in a direction v. Notice that the vector from sB(−v) to sA(v) is the same as the vector from the origin to sMD(A,B)(v). Figure 5.8: Example of the Minkowski difference support point computation. Where sMD(A,B)(v) = sA(v)−sB(−v) GJK GJK [22] is an algorithm that, given a convex set A, returns the distance from Ato the origin. The algorithm is based on the construction of simplexes. A simplex is the simpler polygon in any given space. In 3D, we can construct four possible simplexes: •A point to represent only one point of the space. •A segment to represent a closed 1-dimensional subspace. •A triangle to represent a closed 2-dimensional subspace. •A tetrahedron to represent a closed 3-dimensional subspace. If we construct any simplex using the points of A, all the points of the simplex will belong to A, because the simplex and Aare convex. 34
The GJK founds the nearest point to the origin iteratively. Each step constructs a simplex closer to the origin than the simplex of the previous iteration. The GJK can stop for two reasons. If it founds a simplex containing the origin, it returns zero because the origin is inside A. And, if it does not find any nearest simplex, it returns the distance from the simplex to the origin. Because if it cannot find any nearest simplex, it does not exist any point in Anearer the origin than the points belonging to the simplex. We define a simplex Sas a set of vertices defining the simplex. In one iteration, using the simplex calculated in the previous iteration Sn−1and the direction vn−1in which Sn−1is nearest the origin. The GJK algorithm searches the support point in the direction vn−1, using the support mapping function sA. If the support point sA(vn−1) is further to the origin than the points in Sn−1, the GJK has converged. Otherwise, it creates a new simplex S′adding to the simplex Sn−1the support point, S′=Sn−1∪ {sA(v)}. If S′contains the origin, the GJK stops. Otherwise, it computes the direction vnin which S′is nearest the origin, and defines the simplex Sncontaining the nearest points to the origins in the direction vn. Finally, it starts the next iteration. In the first iteration, the GJK uses an arbitrary direction v0because it does have any simplex defined yet. The Algorithm 1 is a pseudocode of the GJK. Lines 7 and 9 are the stop conditions. Algorithm 1 GJK algorithm 1: procedure distToOrigin(A) 2: v0←random direction 3: S0← {} 4: n←1 5: loop 6: x←sA(v) 7: if x·vn−1> anyP oint(Sn−1)·vn−1then return anyP oint(Sn−1)·vn−1 8: S′←Sn−1∪ {sA(v)} 9: if 0∈S′then return 0 10: vn←nearestDirection(S′) 11: Sn←nearestSimplex(S′, vn) 12: n←n+ 1 In Figure 5.9, we have an example of one iteration of the GJK split in three different steps. The red lines are the simplex shape. Notice that the iteration does not fulfill any stop criteria at any moment. Therefore, the GJK will continue iterating. 35
(a) Start: We have Sn−1={x4,x6}and vn−1. (b) Step 1: Create a simplex S′adding the support point of vn−1. Therefore, S′= {x4,x6,x2} (c) Step 2: Calculate the direction vn(the nearest direction to the origin) (d) Step 4: define Snas the simplex containing the nearest points of S′in direction vn. Therfore, Sn={x4,x2} Figure 5.9: GJK iteration example During GJK iterations, we need to calculate the direction in which the simplex is nearest to the origin. This direction depends on which Voronoi region of the simplex the origin belongs to. If the origin belongs to a Voronoi region of a point, the direction is the vector from the point to the origin. If it belongs to an edge, the direction is a vector perpendicular to the edge with a direction towards the origin. And, if it belongs to a face, the direction is the face normal. Moreover, the structure that influences the Voronoi region is the simplex containing the nearest point to the origin. In Figure 5.10, we have the resulting directions vwith different origin positions regarding a triangle (a possible simplex). In the right image, the origin belongs to the Voronoi region of an edge. Therefore, simplex containing all the nearest points to the origin is the edge. 36
(a) Point Voronoi region (b) Edge Voronoi region Figure 5.10: Example calculating direction by v, the nearest direction to the origin from a triangle. The advantage of the GJK is that it always converges. The disadvantage is the cost of each iteration because testing which Voronoi region of the simplex owns the origin requires many dot and cross products. Frank-Wolfe Frank-Wolfe is a gradient descend minimization algorithm for solving constraint convex problems. We will use specifically Frank-Wolfe to find the between a convex set and the origin. First, we will explain the Frank-Wolfe algorithm and how we used it to calculate the distance to a convex set. Given a compact convex set Dand a function fwhich for each point returns a scalar. The Frank-Wolfe algorithm search a point xinside the set Dthat minimizes f(x). As the GJK, the algorithm only needs the support mapping function of the set D. The algorithm starts xat any point inside D. Then in each iteration it moves xin a calculated direction to a new position which has a smaller value f(x). The basic gradient descent moves the point in the opposite direction of the gradient −∇f(x). Instead, the Frank-Wolf algorithm moves xtowards the support point in the opposite gradient direction, which is defined as sD(−∇f(x)). Moving the point xtowards a support point guarantees that we will never move the point outside the set by the convexity properties. Given a start point x0inside D. In each iteration, Frank-Wolf calculates the new point value as: xn+1 =xn+α(sD(−∇f(xn)) −xn) 37
Where αis the step value, the αmust be a real number between 0 and 1. Otherwise, we would move in the other direction or go outside the set S. The optimal αis the one minimizing f(xn+α(sD(−∇f(xn)) −xn)). Usually, in some problems computing the optimal step value is computationally expensive, so it is better to use a step value αthat decreases in each iteration. For example, a function related to the number of iterations as: α=2 n+ 2 In our case, we want to use Frank-Wolfe to find the distance between the set Dand the origin. Therefore, we want to minimize the distance to the origin: f(x) = ∥x∥ ∇f(x) = x ∥x∥ In our case, we can calculate the optimal step value as the projection of the origin to the line xn+α(sD(−∇f(xn)) −xn), because the projection of a point in a line represents the nearest point inside the line. We need to clamp the αvalue to 1 to avoid going outside the set Dwhen the projection of the origin is outside D. Therefore, we can define the optimal αas: α=min 1,−xn·d ∥d∥2 Where d= (sD(−∇f(xn)) −xn, the Frank-Wolf descend direction. In Figure 5.11, we have an example of one Frank-Wolfe iteration minimizing the distance to the origin. The opposite gradient of the minimization function is the vector pointing to the origin. The orange point is the support point in the opposite gradient direction. Notice the algorithm moves xto the projection of the origin in the support point direction. Figure 5.11: Frank-Wolfe iteration example 38
In Figure 5.12, we have an example of Frank-Wolfe minimizing the distance to the origin. As we can see, the algorithm converges over the optimal value located at the origin. The method’s main disadvantage is that it only descends toward the support points, a reduced set of directions. Even though each step converges towards the solution, the method never reaches the optimal solution in some situations. So, we need to add a threshold to specify when the solution has enough precision. In the next section, we will explain some modifications made to the algorithm to ensure that the results always guarantee a solution overestimation. Figure 5.12: Frank-Wolfe example when origin is inside. 5.4 Implementation Next, we will explain the adaptation made to use GJK and Frank-Wolfe with the regions Rfor testing if a triangle influences a node’s distance field. In all the methods, we can use overestimations of the triangle influence. So, even though a triangle does not intersect the region, we can classify it as intersecting. But we cannot do the opposite thing, classify a triangle as non-intersecting when in reality is intersecting. Otherwise, we could affect the computed signed distance filed. We use the Minkowski difference between the influence region Rand a triangle, to detect if the two shapes intersect using GJK or Frank-Wolfe. In this section, we will also describe how we implement each shape’s support mapping function, which is necessary to compute the support mapping of the Minkowski difference, as we explain in the previous section. The support mapping of a triangle Tis always the same method. Given a direction v, the method searches which of the three vertices is the furthest in that direction and returns that vertex: 39
sT(v) = arg max x∈V(x·v) Where Vis a set containing the three vertices of T. GJK Rby radius We want to test if the triangle has a distance to the node bigger than a threshold δ. As we prove later, δis the maximum distance to the mesh in the eight vertices of the node. We calculate the distance between the triangle and the node using the GJK. To calculate this distance, we need the support mapping function of the node. We could test the eight vertices to get the furthest one. Instead, we use a trick that allows us to get the support point given a direction vwithout evaluating the eight vertices: sC(v) = center +sign(v)∗size Where Cis the node, size is the node size and center is the center point of the node. sign is a function that, given a vector, returns a vector of the same size representing the sign in each coordinate. If the coordinate is positive, it sets the value to 1 and if it is negative to −1. The GJK iterates until converging to the real distance, but we only need to know if the distance is bigger or smaller than the threshold δ. In each iteration, the algorithm creates a simplex nearer than the simplex of the previous iteration. Therefore, if the simplex in one iteration is nearer the origin than the threshold δ, we can stop the GJK earlier. In Figure 5.13, we have an example of one case in which the GJK can stop earlier because the current simplex, in red, has a smaller distance to the origin than δ. The sphere represents the range of δ. Figure 5.13: GJK early termination example 40
First, we have an analysis of how the final solution performance is affected by using GJK and Frank-Wolfe with Rby radius and Rby interpolation. In this first part, we will use the region Rby interpolation using the heuristic nearest vertex to center. In Figure 5.17, we have the algorithm’s execution time using different strategies. As we can see in the plot, there is a big difference in performance between using Rby radius and Rby interpolation. Also, the solver used has a big impact. Notice that using Rby radius, the time difference between solvers is much smaller than using Rby interpolation. Figure 5.17: Execution time with different strategies. In Figure 5.18, we can see a plot showing the mean of triangles per node in each octree depth. Reducing more triangles in each octree subdivision impacts the execution time because it allows faster computation of the next depths and the final distance field. We can see that using Rby interpolation allows us to discard more triangles in each depth. In Rby radius, the solver used does not change the mean of triangles per node in each depth, both methods discard the same amount of triangles. But, with Rby interpolation, there is a difference, the Frank-Wolf method discards slightly fewer triangles than the GJK. This difference affects the mean of triangles per node between 1% and 2%. However, as we saw before, the whole computation is much faster using Frank-Wolf. 47
Figure 5.18: Mean of triangles per node in each octree depth with different strategies. In Figure 5.19, we compare the number of iterations needed by GJK and Frank-Wolfe to determine if there are intersections in each call. The histogram shows the number of calls in percentage solved with a specific number of iterations. In the histogram, we can see that Frank-Wolfe usually needs fewer iterations than GJK. Notice that Rby interpolation requires more iterations than Rby radius, but it is faster because, as we saw in the previous plot, it can classify more triangles as non-influencing. Figure 5.19: The number of calls in percentage solved with a number of iterations. 48
The Figures 5.20 and 5.21 are visual comparison of the two methods, Rby radius and R by interpolation. The triangles printed are triangles classified as influencing the red cube. To estimate the quality of the solution regarding the optimal solution, we do a random sampling inside the cube and print the nearest triangles to the samples in red. As we can see, Rby interpolation fits more the optimal solution than Rby radius. (a) Using Rby radius. 466 selected triangles. (b) Using Rby interpolation. 23 selected triangles. Figure 5.20: Comparison of selected triangles between region methods 49
(a) Using Rby radius. 4659 selected triangles. (b) Using Rby interpolation. 189 selected triangles. Figure 5.21: Comparison of selected triangles between region methods. Finally, we will compare the heuristics proposed for selecting triangles using Rby interpolation. In all the tests, we will use the Frank-Wolfe solver. In Figure 5.22, we compare the program execution time using the different heuristics. As we can see, the fastest method is the heuristic nearest vertex to center. Notice that between testing the eight vertices’ smallest regions (regions per vertex) and only comparing the two nearest vertices (2 nearest vertices), there is not a big difference in performance. This is produced because to find the closest vertex we have to calculate the distance to the eight vertices of the node for each triangle, which is an expensive extra process to do. 50
Figure 5.22: Execution time using different heuristics with Rby interpolation. Figure 5.23 is an analysis of the difference in selected triangles compared to the region per vertex which is the method that selects fewer triangles per node. To compare the difference in all the octree depths, we use percentages. The plot shows for each octree depth the percentage of more triangles selected regarding the triangles selected with the heuristic region per vertex. Notice that the number of selected triangles is accumulated during the space subdivisions. As we can see, the faster heuristics discard fewer triangles in each subdivision. Therefore, if we are interested in reducing the computation time, the best heuristic is nearest vertex to center. But, if we are more interested in the number of triangles per node in the octree leaves, it is better to use the heuristic region per vertex. Figure 5.23: The percentage of more triangles selected than in the best heuristics. 51
Chapter 6 Signed distance field acceleration structure In this chapter, we will explain and analyze our method for accelerating signed distance field queries from triangle meshes in arbitrary points in space. The technique subdivides the space in an octree where each leaf contains the triangles influencing that node. After the octree generation, for every query point, the method traverses the octree to identify in which leaf the point belongs. Then, it iterates all the triangles influencing that leaf and computes the signed distance of the triangle mesh using the nearest triangle. The octree and the triangles influencing each leaf node are not computed at every query. They are calculated in the initialization of the accelerating data structure. 6.1 Termination Heuristic The number of triangles influencing a node depends on the node location regarding the triangle mesh. Nodes nearer the surface will be influenced by fewer triangles than nodes nearer the model’s medial axis. Therefore, an adaptive subdivision of the space may help in containing a more precise subdivision only in critical parts. We need a heuristic to determine when the octree subdivision in a node should stop. We implement a heuristic that ends the octree subdivision when a node is influenced by a minimum amount of triangles. The user will set the threshold smaller or larger depending on the query time requirements. Having fewer triangles per node will decrease the query time, but it will increase the octree size and the initialization time. 52
Also, we try other heuristics to reduce the computation time regarding the query time, as only subdividing when it is expected to reduce more than a certain amount of triangles. The results obtained with these other heuristics were very similar to the results using the one explained before. So, we integrate the minimum number of triangles strategy in our final solution. 6.2 Results In this section, we have some tests done with the heuristic explained before. In all the tests, we use an octree with a maximum depth of eight and the Armadillo model (345944 triangles) as the input model. In this case, the bounding box of the octree root node is the bounding box of the model plus a 12% of margins in each axis. We calculate the query time by averaging the needed time to solve signed distance field queries at arbitrary points inside the octree bounding box. In Figure 6.1, we have some properties of the octree got using the heuristic that subdivides until reaching a minimum number of triangles. We did tests with a minimum of 32, 64, 96, 128 and 160. As shown in the plot, increasing the threshold decreases the computation time but increases the mean of triangles per node and the query time. Notice that the computation time does not decreases linearly. However, the other two seem to have a more linear behaviour. So, increasing the minimum number of triangles will not produce big gains in computation time regarding the query time. Figure 6.2 shows the percentage of leaf nodes in each octree depth. In each depth, the number of nodes increases exponentially and the node size decreases, so the number of ended nodes in each node is difficult to compare. To offer a more intuitive visualization, we calculate the percentage of ended nodes in each depth, considering the node area. For example, a node at depth 1, where we only have eight nodes, has a 12.5% of the space area. As shown in the plots, increasing the threshold pushes the leaf nodes to lower depths. In Figures 6.4, 6.5, 6.6, 6.7, 6.8, we have a part of the generated octree with different minimum number of triangles per leaf. The colour of each node represents the number of triangles in the node. As more red, more triangles have the node regarding the minimum specified by the user. Figure 6.3 represents the signed distance field in the same location. Notice that we usually have more subdivisions inside the model and on discontinuities of the distance field. 53
(a) Computation time in seconds (b) Mean of triangles per leaf (c) Query time in microseconds Figure 6.1: Results using different minimum number of triangles per leaf with the Armadillo model. (a) 32 (b) 64 (c) 96 (d) 128 (e) 160 Figure 6.2: Percentage of leaf nodes in each octree depth with different minimum number of triangles per leaf 54
Figure 6.3: Armadillo slice signed distance filed. Figure 6.4: Octree with a minimum of 32 triangles per leaf. The colours go from 32 triangles (white) to 132 triangles (dark red). 55
Figure 6.5: Octree with a minimum of 64 triangles per leaf. The colours go from 64 triangles (white) to 164 triangles (dark red). Figure 6.6: Octree with a minimum of 96 triangles per leaf. The colours go from 96 triangles (white) to 196 triangles (dark red). 56
7.3 Forcing continuity In the main implementation, the subdivision strategy is done in a depth-first approach, and each node is calculated independent of its neighbours. This strategy can produce zero-level discontinuities at node boundaries. If a leaf and a neighbour had the same size, it always has zero continuity because both nodes have the same vertices in contact, and the polynomial at the contact boundary will behave equally. But, when a node and its neighbour have different depths, not all the vertices in touch are the same. Therefore, some discontinuities can appear in the boundary. Figure 7.1 shows an example of these two cases. (a) Neighbour nodes at the same depth. (b) Neighbour nodes at different depth. Figure 7.1: Comparison between neighbour cases. In some applications, we do not require a continuous representation of the field, but in other applications, these discontinuities can generate problems. To ensure continuity between neighbours at different depths, we force the not shared vertices in the boundary to have the same values as the neighbour node. So, instead of forcing the vertices values to be equal to the signed distance field, we calculate the value using the neighbour polynomial representation of the field. In Figure 7.2, we have an example of this case. At one point during the octree generation, the node is subdivided, but its neighbour is not. The nodes that will not be more subdivided are coloured in green. The not shared vertices with its neighbour are represented as red dots. Then, to ensure continuity, the values of the red dots are calculated using the polynomial representation of the neighbour node, the green ones, instead of the real signed distance field. 63
Figure 7.2: Subdivision example. In each subdivision step, we need to get the state of the neighbour nodes. So, we need a breadth-first strategy in which all the nodes at the same depth are calculated before processing the next depth nodes. This octree subdivision per depth is more expensive than the depth-first strategy because it requires having all the nodes of one depth in memory at the same time. Moreover, we need extra work to keep track of the neighbour nodes. In the next section, we analyze the performance penalties for forcing the generated field’s continuity. 7.4 Results In this section, we will present some analyses made using the technique explained in this chapter. In all the tests, we use an octree with a maximum depth of eight and the Frog model (390978 triangles) as the input model. The bounding box of the octree is set as the model bounding box plus a 12% of margins in each axis. We observe both termination heuristics purposed give similar results. So, we will use the trapezoid rule in all the tests. In Figure 7.3, we have a plot showing the computation times regarding the desired error specified by the user. We noticed that between the computation time and the desired error, there was an exponential relation. To better visualize the progression, we applied a logarithmic scale at the error threshold axis, the X-axis. In the plot, we have a comparison between using the trilinear interpolation and the tricubic interpolation. As we can see, the tricubic method is faster at all the requested errors because each node can represent a more complex behaviour and, therefore, needs fewer octree subdivisions. 64
The termination heuristic uses an approximation of the integral. To calculate the precision of the heuristic, we develop a method that calculates the RMSE of the hole octree bounding box using the Monte Carlo approximation. We use 10 million samples to estimate the model error. In Figure 7.4, we compare the error requested by the user and the actual error of the resulting model. The gray line represents the perfect behaviour, where the model error is exactly the one requested by the user. As we can see, trilinear and tricubic methods always produce smaller errors than the required ones. Therefore, our approach is conservative regarding the user demands. Notice that this plot uses the logarithmic scale in both axes. In Figures 7.5 and 7.6, we have two pictures at the same position of the octree generated using trilinear and tricubic interpolation. In both cases, the user requested an error of 10−3. Comparing the images, we can see that the tricubic method uses bigger nodes, especially in rounded parts of the octree. Figure 7.3: Computation time with different requested errors. 65
Figure 7.4: Comparison between the requested error and real error. Figure 7.5: Octree generated using trilinear interpolation with an error threshold of 10−3 66
Figure 7.6: Octree generated using tricubic interpolation with an error threshold of 10−3 The computation times plotted before were made using the depth-first algorithm without forcing the continuity of the field. In this case, we found that the forcing the continuity increases between 1% and 5% the computation cost. In Figure 7.7, we have an example of the resulting distance field not forcing and forcing the continuity of the field. (a) Not forcing continuity. (b) Forcing continuity. Figure 7.7: Forcing continuity example. 67
In Figure 7.8, we have a plot showing the query time regarding the requested error. The queries are more expensive at smaller errors because the octree has deeper leaves. Even though the tricubic interpolation requires less depth to achieve the same error as the trilinear interpolation, the trilinear interpolation is faster. The trilinear interpolation is faster because its polynomial is much faster to evaluate. Figure 7.8: Query time (in microseconds) with different requested errors. 68
Chapter 8 Conclusions and future work 8.1 Conclusions This thesis presents a solution to accelerate signed distance fields queries from triangle meshes, using a strategy based on subdividing the space and filtering the triangles not influencing that subspace. One of the main project’s contributions is the process of finding if a triangle is influencing a node. We start with a basic idea of comparing distances to the node, and we improve the technique until creating these new methods that perform much better than the initial solution. Also, we prove the correctness of all the proposed methods. Moreover, we explore and analyze different methods to calculate the distance between convex sets, the GJK and Frank-Wolfe. We propose some optimizations to these solvers specifics for the problem we want to solve, finding intersections between an influence region and a triangle. We present two algorithms using our strategy for finding the triangles influencing a zone to accelerate the signed distance field computation in points. First, we present a method for accelerating the signed distance field computation in arbitrary query points. The method generates an octree which accelerates the search of the nearest triangle to the query point. Even though our proposal takes more time to initialize than other solutions, our method achieves faster query times. The method solves queries 28 times faster than the solution offered by CGAL, an important library of geometric algorithms. 69
We also present a method for accelerating the computation of an adaptive approximation of the signed distance field using an octree. The method can calculate approximations of the field with a precision specified by the user. Moreover, we present an algorithm to guarantee no discontinuities of the field between neighbour nodes at a different depth. The method calculates this discretization at reasonable computation times. 8.2 Future work We strongly believe that our method for detecting the influencing triangles in a box can also be used for other types of convex shapes. So, we would like to search for other algorithms that benefit from this new procedure. The two methods for solving signed distance field queries are designed to solve any point inside the octree bounding box. We would like to explore solutions to offer faster query times at specific parts, for example, near the object surface. This would improve the computation time because we will not have to improve the query time or the field quality in all the space. We could not compare our method for computing the signed distance field approximations with other strategies because all the competitive techniques are developed in the GPU. We would like to port our method to the GPU to compare it with others. We believe that given the times achieved using only the CPU with one thread, our solution would perform very well at the GPU. In addition, we would like to give practical uses to the method developed in the thesis. As we saw in the related work, the signed distance fields can be used in many areas such as rendering, collision detection, and shape reconstruction. 70
Appendix A Trilinear interpolation properties A.1 Trilinear interpolation is a composition of linear interpolations Trilinear interpolation TriInt can be expressed as a composition of linear interpolations LinInt, first four linear interpolations on the Xaxis, then two on the Yaxis, and a final one on the Zaxis. TriInt(α, β, γ, vijk) = LinInt(γ,LinInt(β, LinInt(α, v000, v100), LintInt(α, v010, v110)), LinInt(β, LinInt(α, v001, v101), LintInt(α, v011, v111))) Where vijk are 8 values or vectors. A.2 Trilinear interpolation is distributive over addition Given 2 values viand v′ i(where i∈ {0,1}). We define the linar interpolation LinInt as: LinInt(α, v0, v1) = (1 −α)v0+αv1 We can clearly see, using the distributive propery of the product: LinInt(α, v0+v′ 0, v1+v′ 1) = LinInt(α, v0, v1) + LinInt(α, v′ 0, v′ 1) Trilinar interpolation is distributive over addition, beacuse a trilinar interpolation is a composition of linear interpolations (appendix A.1) and a linear interpolation is distributive over addition. 71
A.3 The norm of the interpolation of a set of vectors with the same direction is equal to the norms interpolation Given 8 vectors all towars the same direction vijk (where i, j, k ∈ {0,1}). We want to proof: ∀α, β, γ ∈[0,1] : ∥T riInt(α, β, γ, vijk)∥=T riInt(α, β, γ, ∥vijk∥) Trilinar interpolation is a composition of linear interpolations (appendix A.1), therfore, we only need to prove it for linear interpolation. Moreover, the demostrating the statment is equivalent to prove it for the square of the norms. So, given two vectors v0and v1with the same direction (vT 0v1=∥v0∥∥v1∥), we need to prove that the square of the norm of their linear interpolation is equal to the square of the linear interpolation of their norms: ∥LintInt(α, v0, v1)∥2=∥(1 −α)v0+αv1∥2= [(1 −α)v0+αv1]T[(1 −α)v0+αv1] = = (1 −α)2∥v0∥2+α2∥v1∥2+ 2α(1 −α)∥v0∥∥v1∥= [(1 −α)∥v0∥+α∥v1∥]2 = [LintInt(α, ∥v0∥,∥v1∥)]2 A.4 The norm of the interpolation of a set of vectors is smaller or equal to the norms interpolation Given 8 vectors vijk (where i, j, k ∈ {0,1}). We want to proof: ∀α, β, γ ∈[0,1] : ∥T riInt(α, β, γ, vijk)∥ ≤ T riInt(α, β, γ, ∥vijk∥) Trilinar interpolation is a composition of linear interpolations (appendix A.1), therfore, we only need to prove it for linear interpolation. Moreover, the demostrating the statment is equivalent to prove it for the square of the norms. So, given two vectors v0and v1, we need to prove that the square of the norm of their linear interpolation is less or equal to the square of the linear interpolation of their norms. We pove it using the Cauchy-Schwarz inequality. ∥LintInt(α, v0, v1)∥2= (1 −α)2∥v0∥2+α2∥v1∥2+ 2α(1 −α)vT 0v1≤ ≤(1 −α)2∥v0∥2+α2∥v1∥2+ 2α(1 −α)∥v0∥∥v1∥= [(1 −α)∥v0∥+α∥v1∥]2= = [LintInt(α, ∥v0∥,∥v1∥)]2 72