# A G-Code Generator for Volumetric Models
## 1 Introduction  
Compared with traditional subtractive manufacturing methods, layered manufacturing (LM) techniques are more flexible, low-cost, and efficient in prototyping and object fabrication. Thus, LM improves productivities and shortens development time in industries [1]. In an LM process, an assistant software, the slicer, is responsible for converting the input geometry into the G-code program, which guides the 3D printer to build the physical object [2]. Since the accuracy, build time, and strength of the finished part are decided by the G-codes, the slicer is, thus, a vital component in the LM process. In recent years, enormous efforts had been paid on developing efficient slicers for LM. As a result, many decent slicers are currently available in the market and internet [3]. Conventionally, the input models of LM are expressed in polygonal representations, for example stereolithography (STL) files. Thus, most slicers focus on translating models, formed by triangular meshes, into G-codes. Though STL has become the de facto format in LM, not all geometric models are defined by facets. For instance, tissues and organs segmented from medical data sets [4] and objects created by using volumetric modeling methods [5] are composed of voxels. These geometries cannot be converted into G-codes by using conventional slicers. One can transform these voxel-based models into surface representations at first and then processes the intermediate geometries by using conventional G-code generators [6; 7]. However, this format transformation process increases computational costs and induces extra geometric errors. In this article, we propose a slicer, which is capable of translating volumetric models into G-codes without producing intermediate surface representations. Therefore,computational efforts are saved, and unwanted geometric errors are prevented. Consequently, manufacturing volumetric models becomes more convenient and efficient. The proposed slicer consists of several stages. At the first stage, the input model is oriented such that its stability is maximized and its height is decreased. For some LM modalities, support structures are needed to prevent the printed objects from collapsing during the printing process. At the second stage, the proposed slicer detects and classifies overhangs and grows auxiliary structures to support the input model. In the following computation, our slicer divides the input model into the skin and internal regions and cuts the input model into a stack of 2D images. The skin region is then hatched by using a contouring method to produce toolpaths that fabricate a high-quality surface. On the other hand, the internal region is rasterized by using a texture-mapping method to speed up the printing process and to reduce the weight of the printed object. Finally, the toolpaths for printing the skin and internal regions are smoothed and encoded into G-codes, and the resultant G-code program is kept in a disk file. The principle methodology of our slicer is similar to that of the conventional ones [3]. Nonetheless, as the input models of our slicer are expressed in volumetric data format, those algorithms, adopted by the conventional G-code generators, cannot be employed to process the input models. Instead, alternative methods have to be developed to fulfill the tasks. These innovative algorithms can be summarized as follows:  
1. We explore the mass distribution of the input model to calculate the printing direction. Hence, the stability of the input model is maximized, and the volume of the support structures is greatly reduced. 2. We design patterns to classify overhangs to avoid generating too much support structures while necessary pillars are always created. 3. Thirdly, we treat the input model as a 3D image such that the skin region can be produced by using image processing techniques. Contouring the skin region can be accomplished by using erosion and graph traversal algorithms. 4. Our slicer adopts a texture mapping method in filling the internal region.