Level Sets of Weak-Morse Functions for Triangular Mesh Slicing

In the context of CAD CAM CAE (Computer-Aided Design, Manufacturing and Engineering) and Additive Manufacturing, the computation of level sets of closed 2-manifold triangular meshes (mesh slicing) is relevant for the generation of 3D printing patterns. Current slicing methods rely on the assumption that the function used to compute the level sets satisfies strong Morse conditions, rendering incorrect results when such a function is not a Morse one. To overcome this limitation, this manuscript presents an algorithm for the computation of mesh level sets under the presence of non-Morse degeneracies. To accomplish this, our method defines weak-Morse conditions, and presents a characterization of the possible types of degeneracies. This classification relies on the position of vertices, edges and faces in the neighborhood outside of the slicing plane. Finally, our algorithm produces oriented 1-manifold contours. Each contour orientation defines whether it belongs to a hole or to an external border. This definition is central for Additive Manufacturing purposes. We set up tests encompassing all known non-Morse degeneracies. Our algorithm successfully processes every generated case. Ongoing work addresses (a) a theoretical proof of completeness for our algorithm, (b) implementation of interval trees to improve the algorithm efficiency and, (c) integration into an Additive Manufacturing framework for industry applications.


Introduction
In the context of CAD CAM CAE (Computer-Aided Design, Manufacturing and Engineering) and Additive Manufacturing, the computation of closed 2-manifold level sets (mesh slices) is crucial for the generation of contours required in pattern filling. The filling of these patterns require correct classification and orientation of closed 1D contours, allowing the application of filling algorithms that rely on line/polygon boolean operations. The resulting fill patterns are used to generate the G-Code or CLI (Common Layer Interface) code required to 3D print an input model layer by layer, where each layer corresponds to a filled level set [1,2]. Other applications for mesh slicing include visual dimensional inspection, where computed level sets are used to assess 2D geometric features [3,4].
The problem of slicing closed 2-manifold meshes addresses the computation of level sets of a height function f : M → R. The inverse f −1 of such a function at a given point c is known as a level set of f . The properties of the level set f −1 (c) (i.e., 0-, 1-or 2-manifoldness, or non-manifoldness at all) heavily depend on the critical points of f (in f −1 (c)). However, in most application cases f is a non-Morse function, with several degeneracies along the domain M. Therefore, f −1 (c) can produce other types of level sets, such as: non-oriented compact contours, 2-manifold regions, self-intersecting contours (with or without border) or a connected union between Morse and non-Morse cases. It is well-known that a slight rotation of the manifold may remove non-Morse conditions of the height (slicing) function. However, in CAD CAM CAE (and particularly in Additive Manufacturing), these non-Morse degeneracies are of special interest as any tilt to the original model changes the manufacturing feasibility of the workpiece.
In the current literature, most mesh slicing algorithms assume strong-Morseness on the slicing function f , or they do not correctly classify the different types of non-Morse cases that arise in real application cases. To organize the solution of this problem, this manuscript defines weak-Morse functions as functions with a finite set of points C ⊂ R, such that f is only degenerate (non-Morse) at such points f −1 (C) ⊂ M, satisfying Morseness elsewhere. Such a definition allows us to define a classification of different Morse and non-Morse cases in order to develop an algorithm that correctly reflects this classification, producing the correct level sets for each case. Such classification requires our algorithm the evaluation of each vertex, edge and triangle neighborhood, outside of the slicing plane c. Finally, closed contours are correctly oriented to differentiate body holes from external contours. This final step is crucial in Additive Manufacturing operations where pattern filling algorithms require this differentiation for correct line-polygon intersection operations.
The remainder of this manuscript is organized as follows: Section 2 discusses the relevant literature. Section 3 presents the proposed weak-Morse classification and the mesh slicing algorithm. Section 4 presents and discusses some test results. Finally, Section 5 presents the conclusions and introduces what remains for future work.

Literature Review
Mesh slicing and pattern filling are crucial steps in the Additive Manufacturing workflow. This section discusses some of the most relevant literature concerning the computation of 2-manifold level sets. For a more detailed review, the reader may refer to the surveys in References [1,2].

Parallel-Planes Mesh Slicing
Height functions f (x) = x z are the most common functions used for mesh slicing. These functions naturally produce parallel planar slices of M in the z-direction, and they can be generalized to any direction v ∈ R 3 by applying a 3D rotation to the input mesh. Standard triangle/plane intersection algorithms are used to compute the level sets of f [5][6][7][8][9][10][11][12], which in most cases are assumed to produce closed (and oriented) 2-manifold contours. Adaptive slicing algorithms introduce techniques to compute non-uniformly spaced slicing planes [13][14][15]. Adaptive techniques are relevant for avoiding surface aliasing, without having to rely on oversampling.
To reduce the complexity of slicing algorithms, Reference [16] introduces interval trees, which reduces the complexity of mesh slicing algorithms by testing subsets of mesh triangles in given z-intervals. For regularly spaced slicing planes, the complexity can be further reduced by sorting the mesh triangles in ascending z-order [17].
All of the aforementioned slicing algorithms limit their level set retrieval using only triangle/plane intersection information. This relies on the assumption of the slicing function f to be a Morse function. However, this assumption does not always hold true, specially for CAD models where sharp edges, planar faces and saddle points intersect the slicing plane. The non-Morseness of f requires additional evaluation of local vertex, edge and triangle neighborhoods, which do not necessarily lie on the slicing plane but are crucial for determining the type of slice degeneracy. Reference [24] addresses the problem of some non-Morse slicing functions by considering degenerate 2-manifold faces lying on the slicing plane. However, degenerate 1-manifold regions and saddle points are still not considered.

Non-Parallel-Planes Mesh Slicing
As discussed before, most slicing algorithms consider height maps as slicing functions. However, some approaches have been recently proposed to include other kind of slicing functions [1,2]. These functions vary the slicing direction through the surface, producing non-parallel slicing planes.
References [25,26] apply an error minimization algorithm, which segments the mesh model and produces a diferent slicing direction for each computed sub-mesh. Reference [27] maps surface normals to the unit sphere and solves an optimization problem inside this sphere. The optimization procedure results in a slicing function that produces non-parallel slicing planes.
Reference [28] defines a slicing function that travels along a parametric curve (which the authors name streamline). References [29,30] fit B-Spline surfaces to the mesh. Many non-planar slices of M are produced afterwards by offsetting the fitted B-Splines in the surface normal direction.
In terms of Morseness of the slicing function f , non-parallel-planes methods also arise the same problems of their parallel-plane methods counterparts. Computation of level sets still happens at a local triangle/plane intersection level, neglecting the information of local vertex, edge and triangle neighborhoods.

Conclusions of the Literature Review
Current mesh slicing algorithms rely on the assumption of Morseness of the slicing function f . However, non-Morse slicing functions are frequent in Computational Geometry applications and (particularly) in CAD applications, where input models present saddle points, sharp edges and planar faces that intersect the slicing plane. These non-Morse cases, produce incorrect slicing results when not correctly addressed. Furthermore, literature on discrete Morse theory has been already discussed by different authors [31][32][33]. Nevertheless, to the best of our knowledge, there is not a Morse-based mathematical description of the mesh slicing problem in the context of Engineering and Manufacturing applications.
To overcome these problems, this manuscript discusses and classifies the different types of plane/surface intersections that arise when computing level sets. To do so, we define weak-Morse functions, in which non-Morse degeneracies are allowed in a finite set of planar slices C ⊂ R. Additional to the classic plane/triangle intersection algorithm, this classification requires our algorithm to evaluate vertex, edge, and triangle neighborhoods outside of the slicing plane. The resulting slices may produce not only closed 1-manifold contours, but also non-manifold (with or without boundary) self-intersecting contours, 0-manifold points and 2-manifold surfaces. In order to differentiate holes from external contours, the resulting closed contours are correctly oriented. The orientation of the closed contours is crucial in Additive Manufacturing operations where pattern filling algorithms require this specification for correct line/polygon boolean operations. Future work is intended to produce a theoretical proof of the completeness of the algorithm presented in this manuscript.

Methodology
The idea of mesh slicing considers a triangular discretization M = (X, T) of a continuous, closed 2-manifold M that is embedded in R 3 . M is a triangular mesh defined by a set of vertices X = {x 0 , x 1 , . . . , x n } and a set of triangles T = {t 0 , t 1 , . . . , t m }. The slicing of M requires to compute the level sets f −1 of a slicing function f : M → R.
For a given slicing value c ∈ R, the level set f −1 (c) ⊂ M produces an oriented 1-manifold contour if such a level set does not contain any critical points of f . However, when f −1 (c) contains one (or more) critical points of M, the resulting level set cannot be guaranteed to be 1-manifold closed contour. In fact, several cases arise depending on the nature of the critical point, and the resulting contour can either be: (a) a 0-manifold point, (b) a self-intersecting (non-manifold), closed, 1D oriented contour, (c) a non-manifold, 1D non-oriented contour ( possibly with borders), and (d) a closed 2-manifold region. The nature of these critical points can be classified in terms of Morse theory, as illustrated in Figure 2. The mathematical and algorithmic details for the computation of the level sets of f are discussed in the following subsections.
where ∇ M and H M are the tangent gradient operator and tangent 2 × 2 Hessian matrix, respectively. These tangent operators are defined in the tangent planes T x M of M. The function f is known as the slicing function, and the inverse f −1 : R → P (M) defines the level sets of f .

Weak-Morse Function
We define a weak-Morse function, as a function f that satisfies the Morse criterion everywhere, except in a finite set of slice values C ⊂ R, that is: Since the set C is allowed to be the empty set, any strong-Morse function is also a weak-Morse one.
It is worth noting that in the discrete domain (e.g., in the case of triangle meshes), weak-Morse and non-Morse are equivalent definitions. However, in the continuous domain these two definitions are not the same. As an example, consider the surface S ⊂ M, defined as x, y ∈ (−a, a) (with a ∈ R), and the non-Morse function z = f (x, y) defined as follows (see Figure 3): The function f ∈ C 2 (S) has infinite critical values and, since for all x, y ∈ S, ∂ f 2 ∂xy = ∂ f 2 ∂y 2 = 0, the Hessian matrix H M f (x, y, z) is singular everywhere in S. As a consequence, the non-Morse function f does not satisfy weak-Morse conditions on M ⊃ S.
In particular, this manuscript considers the function f as the height function f (x) = x z , which maps each point x ∈ M to its corresponding z-value (see Figure 1). In this case, the level sets of f are parallel planar slices of M.

Level Set Types
Let M ⊂ R 3 be a closed, oriented and differentiable 2-manifold, and the slicing function f : M → R, f ∈ C 2 (M). For a given c ∈ R, this subsection defines a classification of the level set f −1 (c) based on the characteristics of the critical points of f (in f −1 (c)).
Without loss of generality, the following classification assumes that f −1 (c) is connected. In the case that f −1 (c) is disconnected, each connected component of such a level set can be treated separately.
Furthermore, such a classification is applied locally (i.e., in a small neighborhood N ε (x) ⊂ M around a point x ∈ M), allowing more than one type instances at the same level set f −1 (c). Without further ado, we identify the following level set types (see Figure 2): 1. Closed 1-manifold contour: f −1 (c) contains no critical points: In this case f −1 (c) defines a simple, oriented, closed curve (1-manifold homeomorphic to the unit circle).

5.
Degenerate 1D region: f −1 (c) contains a local minimum (or maximum) along a 1D path: This region defines a non-manifold 1D compact region, possibly with non-empty boundaries. 6.
Degenerate 2-Manifold region: f −1 (c) contains a critical 2-manifold region: The definition of locally homeomorphic permits the existence of holes in the region f −1 (c).

Contours Orientation
Since the slicing function is the height function f (x) = x z , each contour f −1 (c) naturally lies in a 2D linear space (i.e., planar slice). The orientation of each contour is defined as follows (see Figure 2):

1.
Closed 1-manifold: The orientation of f −1 (c) on the slicing plane is defined by the projection of the surface normal vector, that is: where n(x) ∈ R 3 is the vector normal to M at x, and n XY (x) ∈ R 2 is the corresponding projection on the slicing plane.

3.
Non-degenerate saddle: The orientation of the non-degenerate saddle point f (x) = c is equally defined by the projection to the surface normal vector: n XY (y) = Proj XY ( n(y)) for all y ∈ N ε (x)\{x}.

4.
Degenerate saddle: Exactly the same as the non-degenerate saddle case.

6.
Degenerate 2-manifold region: Not oriented in the slicing plane. However, the boundary ∂ f −1 (c) is an oriented, closed 1-manifold embedded in R 2 . The different types of level sets f −1 (c) on M are defined as follows (see Figure 2):

2.
Degenerate 1D region: is the z-coordinate of the vertex that is opposite to the oriented edge (x i , x j ).

3.
Degenerate and non-degenerate saddle: Let where N T X : X → P (T) maps each vertex x i to the set of all triangles t j that are incident to it. Therefore, A(x i ) is the set of all triangles that intersect the slicing plane and |A(x i )| is the number of segments in the triangle/plane intersections in such a set. 4. 0-manifold point: Let x i ∈ X, z(x i ) = c. x i ∈ P is a local minimum (or maximum) if: where N X X : X → P (X) maps each vertex x i ∈ X to the set of all vertices x j ∈ X that are adjacent to it.

5.
Closed 1-manifold: Let t ∈ T, t ∩ f −1 (c) = ∅. The edge (p 1 , p 2 ) ∈ S O if: with 0 ≤ α ≤ 1 and (x j , x k ) ∈ E being one of the triangle t edges that intersect the plane z(x) = c. It is worth noting that p i ∈ R 3 not necessarily belongs to the vertex set X.
For the discrete case, the list is defined in reverse order, considering the most degenerate (non-Morse) cases first and the non-degenerate (Morse) cases at the end. The given order defines the priority of the slicing Algorithm when finding weak-Morse degeneracies.
Algorithm 1 presents the slicing algorithm according to the presented classification, as follows: (1) The computation of the degenerate faces is performed in lines 1-6. (2) The computation of degenerate 1D edges is performed in lines 7-15, where x opp (x i , x j ) is the vertex that is opposite to the oriented edge (x i , x j ). The orientation of the closed 1D contours (in R 2 ) is defined such that a counter-clockwise polyline represents an external contour, while a clockwise polyline represents an internal hole.

Results
This section presents graphical results for the resulting slices of different closed 2-manifold meshes. These test datasets have been been generated explicitly to show different weak-Morse degeneracies that usually arise in CAD CAM CAE applications. On the one hand, Section 4.1 presents the slicing results on different weak-Morse datasets. On the other hand, Section 4.2 presents an application case in the context of Additive Manufacturing.

Weak-Morse Slicing
This section presents the slicing results for different weak-Morse datasets. As already stated above, these simple datasets have been manually designed and generated in order to provoke and illustrate all the different weak-Morse cases that have been already discussed in previous sections. In addition, benchmark datasets have been used to illustrate the application of our implementation. Figure 4 presents the slicing results for the Upright Torus dataset already introduced in Figure 1. In this case, the function f is a strong-Morse one, containing a non-degenerate saddle point on the slicing plane. The resulting slices are the oriented contours S O . Note that despite the self-intersection in Figure 4b, our algorithm correctly computes the orientation of the contour.   Figure 5 shows the Double Torus dataset. This dataset presents a degenerate, non-Morse saddle point (m = 4, see Figure 2). Similar to the Upright Torus dataset, the resulting level set is an oriented polyline that self-intersects 2m − 1 times at such saddle point. The orientation of the polyline is always preserved according to the input mesh M orientation. Figure 6 illustrates some cases where degenerate 1D regions arise. On the one hand, Figure 6a plots a Lying Torus and the planar slice at a non-Morse (degenerate) region. Figure 6b plots the corresponding S NO 1D region. Despite of being closed and non-self intersecting, S NO has no orientation. This fact is consistent with the mesh M, as S NO has no internal or external region. As a contrast, Figure 6c plots the resulting level set computed using a naive strong-Morse approach. The resulting level set is filled to illustrate the fact that a naive approach assumes oriented contours and does not discriminate the possible degeneracies. This filling is relevant since in Additive Manufacturing, the fabricated workpiece would end (incorrectly) with such a cover at the top. On the other hand, Figure 6d plots a Grid dataset. The resulting level set f −1 (c) at the top of the Grid is a non-Manifold 1D region S NO (see Figure 6e). In this case, S NO is not closed (i.e., it has borders), and since it is non-manifold, our slicing algorithm S NO into 1-manifold subset. Again, this 1D contour is non-oriented as there is no external or internal 2D region associated to the contour. In addition, Figure 6f plots the resulting level set computed by the naive strong-Morse approach. Again, the result is filled illustrating the orientated polyline produced by the algorithm and 3D printing of such a workpiece would end with a top cover.  The resulting level set is a 2-manifold region F composed by the set of all mesh triangles that intersect the slicing plane. A contour can be extracted from F by computing all of its boundary edges and its orientation can be computed from the information of the triangles incident to such boundary (as illustrated in Figure 7b).   Figure 8a). Furthermore, our algorithm is capable of differentiating internal holes from external contours in 2-manifold regions F, as illustrated in Figure 8b.
As already mentioned in the previous section, the current weak-Morse classifications works locally. As a consequence, it is not uncommon (specially in CAD datasets) to find multiple weak-Morse degeneracies of different types on the same level set f −1 (c). Furthermore, these degeneracies can be connected. As an example, the Peg Cube dataset (Figure 9a) presents an oriented contour S O extracted from a region with no critical points, connected to a non-oriented contour S NO extracted from a degenerate 1D critical region, both from the same connected level set (see Figure 9b). Figure 9c plots the Chamfered Cylinder dataset. In this case, the level set contains an oriented contour S O from a non-degenerate region and a face F extracted from a degenerate 2-manifold region (see Figure 9d. It is worth nothing that both contours S O and ∂F share a polyline section, each with its own orientation (which is consistent with the orientation of its owner polyline). This guarantees that both contours are closed and oriented consistently, according to the orientation of the input mesh M.
Finally, Figure 9e presents the Platform Grid dataset. The level set f −1 (c) at the top of this dataset contains both a non-oriented polyline S NO from a degenerate 1D region, connected to a 2-manifold region F (with its respective oriented boundary contour ∂F). The level set results are presented in Figure 9f.
All of these cases are easily managed by our algorithm due to the data structure used f −1 (c) = (S O , P, S NO , F), which handles each type of Morse/non-Morse case separately.

Applications in Additive Manufacturing
As already illustrated in the previous subsection, our level set computation algorithm allows to easily back track the normals of M from each level set f −1 (c). Using this information, it is possible to produce a filling pattern for f −1(M). This subsection applies the presented mesh slicing algorithm to real-life CAD datasets. Afterwards, a fill pattern is computed for each level set f −1 (c) using a line-polygon intersection algorithm [34]. Figure 10 presents the resulting mesh slices and their corresponding fill patterns. CAD workpiece. The datasets have been extracted from the National Design Repository [35]. The resulting filling patterns can be used to produce 3D printing routines that accurately fabricate the original CAD models, even in the presence of non-Morse level sets. Future work aims to explore this topic in detail. Figure 10. Mesh slicing of benchmark weak-Morse CAD datasets. Our algorithm computes the level sets (slices). As a test for our level sets, they are then fed to another algorithm (not part of this manuscript) which correctly generates the tool paths for Additive Manufacturing. Datasets from the National Design Repository [35].

Conclusions
This manuscript develops a mathematical and algorithmic classification of the level sets of closed 2-manifold triangular meshes. These level sets are classified in terms of weak-Morse functions, where Morse and non-Morse degeneracies arise. This classification relies on the position of vertices, edges and triangles in the neighborhood outside of the slicing plane. The test results show that the presence of such degeneracies on the slicing function f results on level sets that are not only oriented, 1-manifold closed contours, but also self-intersecting (non-manifold) contours, 0-manifold points, non-oriented contours, and even 2-manifold level sets. Our algorithm correctly computes and classifies each resulting contour, and produces its orientation (if it exists) in concordance with the input mesh M. Furthermore, our algorithm correctly handles different degeneracies that arise simultaneously at the same level set. Finally, the presented slicing algorithm enables consistent line-polygon operations (even in weak-Morse cases), allowing the computation of filling patterns that are relevant in the context of Additive Manufacturing.
Future work addresses-(a) A theoretical proof of the completeness of the proposed weak-Morse classification and the slicing algorithm. Such a proof would guarantee the correctness of every (Morse and non-Morse) level set for any given 2-manifold model. (b) The implementation of the interval tree data structure [16,17] to speed-up the computation times. Such a speed-up could prove valuable for large CAD datasets (i.e., with high triangle count). (c) The integration of the proposed slicing algorithm into an Additive Manufacturing framework, enabling the fabrication of complex models with problematic non-Morse degeneracies. Funding: This research received no external funding.

Conflicts of Interest:
The authors declare no conflict of interest.

Abbreviations
The following abbreviations are used in this manuscript:

M
A closed 2-manifold embedded in R 3 . f A scalar function f : M → R. In this manuscript, f (x) = z(x) is the height function, named also as the slicing function. Set of bidirectional edges that belong to the graph of the mesh M. (x i , x j ) ∈ E if for any k, (x i , x j , x k ) ∈ T. N X X (x i ) Set of all vertices x j ∈ X that are adjacent to the vertex x i ∈ X. N X X : X → P (X). N T X (x i ) Set of all triangles t j ∈ T that are incident to the vertex x i ∈ X. N T X : X → P (T).