Rasterization Method for Voxel Model Cutting

Background. The analysis of voxel dataset cuts is a widespread task in computer graphics applications. A comprehensive study of volume image cuts enables deeper learning of the structure of an object, which is visualized, as well as getting a clear view of the organization of its components. Very often, there is a need to investigate an internal structure of the object, and in this case, researchers can be more interested in certain parts of the model, in particular, in cuts of voxel data. Objective. The objective of the research is to develop a rasterization method which enables obtaining cuts of voxel datasets at arbitrary angles. The method should use only integer arithmetic and minimize the number of calculations. Methods. The essence of the method is to rasterize the cutting plane by parallel transferring of master-line fragments along the base-line, as it is proposed in the weaving algorithms of rasterization. To rasterize both types of lines, it is proposed to use the Bresenham's line algorithm. The developed method consists of two stages: the initialization stage, in which both the master-line is rasterized and boundaries of rasterization fragments are found, and the main stage, when rasterization of the master-line fragments is performed within the boundaries found on the initialization stage. Results. The developed method uses only integer arithmetic and minimizes the number of calculations in the rasterization cycles of master-line fragments which makes the use of the method sufficiently effective for rasterization of sections of voxel models. Conclusions. The developed method can be used in various applications where three-dimensional images are used, including medical images, three-dimensional visualization in scientific applications, multimedia and mulsemedia systems.


Introduction
The analysis of voxel dataset cuts is a widespread task in computer graphics applications [1 -4]. A comprehensive study of volume image cuts enables deeper learning of the structure of an object, which is visualized, as well as getting a clear view of the organization of its components. Very often, there is a need to investigate an internal structure of the object, and in this case, researchers can be more interested in certain parts of the model, in particular, in cuts of voxel data. A cut is a set of voxels which belong to a given plane of the cut or reproduce it as accurately as possible. Based on the features of the voxel data models, a method of cutting depends on an angle at which this cut is made. Since the voxel model is a three-dimensional array of data, the most trivial cases for rasterization of the cut correspond to angles multiple of 90. At the same time, special methods of rasterization are necessary for cutting at arbitrary angles.
Such methods differ in approaches used to determine a corresponding set of voxels representing the cutting plane.
Thus, in [5,6], a scan-conversion algorithm to rasterize polygons is proposed. This algorithm is based on the principle of scanline-rasterization [7] in two-dimensional space and was extended for the usage in three-dimensional space. This algorithm can be used to construct cuts of the voxel model. The main idea of this approach is to rasterize a contour of the polygon (i.e. a contour of the cut) and then gradually fill it rasterizing the parallel lines connecting pairs of opposite points of the contour.
Another approach which can be applied to rasterization of a voxel model cut is based on the usage of weaving techniques. The basic idea is that one rasterized line (master-line) is copied along the other rasterized line (base-line) with a certain shift. Thus, a rasterization of the plane which contains the master-line and the base-line will be obtained. One of the algorithms which use such technique is an exact weaving rasterization algorithm [8], the use of which allows obtaining a fairly accurate representation of the voxel model cut. In this case, the number of computations is optimized by calculating special chains for the line segments that form the cutting plane [9]. It is proved that such chains have a certain periodicity, and therefore, for rasterization of the plane it is enough to compute such chains and then copy them to cover the sur-face of the plane. It allows to reduce the number of necessary calculations for rasterization of the entire plane.
There are also methods which allow to make cuts where voxels completely cover the cutting plane [10]. Such cuts consist of all voxels which intersect the given plane (it is a requirement in some cases) but the thickness of such cut may be greater than one voxel.
The analysis of these methods and algorithms allows us to consider the weaving algorithms as the most promising ones.
Although these methods are intended to solve the same problem, results of the cuts rasterization may differ. Different requirements such as cut accuracy, cut thickness, voxels connectivity, etc. may be set to a voxel model cutting. Accordingly, the choice of a rasterization method should be done depending on a particular case.

Problem Statement
The objective of the research is to develop a rasterization method which enables obtaining cuts of voxel datasets at arbitrary angles. The method should use only integer arithmetic and minimize the number of calculations.

Basic Definitions
A voxel is a part of a discrete space with a certain value. In the context of this paper, a voxel is considered as a unit cube with coordinates in a discrete space.
It is assumed that a voxel model is a collection of voxels which mutually touch faces. Together they form a three-dimensional structure which is a parallelepiped. In this structure there are no cavities, that is, each facet of the internal voxel touches the faces of the neighbouring voxels. The model has an integer length, height, and width.
Every voxel in the considered model has integer coordinates: where L is a model length, H is a model height, and W is a model width, respectively. The origin of the rectangular coordinate system, in which the model is considered, coincides with a position of the voxel having coordinates (0, 0, 0) . The edges of the model belong to the planes Oxy , Oxz , Oyz .
A voxel dataset cut rasterization is a process of finding all voxels which form the desired cutting plane.

Weaving Algorithms
The weaving algorithms for voxel model rasterization are a family of algorithms which follow the principle of weaving technology [11].
Let us assume that it is necessary to perform a rasterization of a certain area of the plane. According to this technology, in order to perform such rasterization, two non-parallel lines which lay on this plane must be selected. These lines are, so called, master-line and base-line.
Rasterization of a given plane is achieved by copying of the rasterized master-line along the base-line. An example of such rasterization is shown in Figure 1.
Let us consider that the master-line is given by the segment AB , and the base-line is given by the segment AC , and, thus, the point A is a common point for both segments. Since the voxels must have integer coordinates, the lines are considered in the discrete space, and, accordingly, the coordinates of all points, obtained by rasterization, will be integer. At first, a set of points which belong to the segment AB is obtained. Let it be a certain set M . Then, while moving along the points of the segment AC , the copying of the points from the set M is performed on each step with a certain shift. Thus, the rasterization of the plane ABC is obtained. Different types of weaving algorithms differ in how the rasterization of the master-line and baseline is performed. In general case, it is possible to use rasterization algorithms for arbitrary curves instead of using rasterization algorithms for lines. In this case, the rasterization of a surface instead of a flat plane will be fulfilled as a result. Within the framework of this paper, a flat cut of the voxel model is necessary, and algorithms for curves rasterization are not considered.

Method Description
For the cutting plane, which is supposed to be obtained by the method proposed in this paper, the following requirements must be satisfied: voxels of the cutting plane must satisfy the requirement of 26-connectivity, that is, they can touch each other by faces, edges or vertices [12]; the plane should be solid, that is, it should not contain holes; the rasterized plane should not be distorted.
This method should use only integer arithmetic in calculations to provide greater performance. In this case, the rasterization of the cutting plane cannot be considered as absolutely accurate but the result would provide a good approximation which may satisfy requirements of most cases.

A. Rasterization Process
The essence of the method is to rasterize the cutting plane by parallel transferring of master-line fragments along the base-line, as it is proposed in the weaving algorithms of rasterization. To rasterize both types of lines, it is proposed to use the Bresenham's line algorithm [13]. This algorithm is a fast rasterization algorithm and allows to use only integer arithmetic, which is one of the advantages of such approach. Also, the Bresenham's line algorithm for a two-dimensional case can be extended for lines in three-dimensional space. However, if the rasterization of the lines will be made on planes, which are orthogonal to the coordinate axes, then the original version of Bresenham's line algorithm can be used for a two-dimensional case.
The process of rasterization of a plane is a process of finding coordinates of all voxels which belong to this plane or considered as such. To improve performance and increase the speed of rasterization, it is necessary to minimize the number of computations. Usage of the Bresenham's al-gorithm will allow to get the rasterization of the cut, using only integer operations. In addition, such rasterization would be sufficiently accurate. On every iteration of the Bresenham's algorithm for the master-line two coordinates for a single voxel are found. The third coordinate is found on the current iteration of the Bresenham's algorithm for the base-line, and this coordinate will be the same for all of other voxels of the master-line.
In general case, the cut of the voxel model may be represented by one of four shapes (a triangle, a quad, a pentagon, or a hexagon) or by one single point. All possible cases are shown in Figure 2. The cutting plane, the rasterization of which must be obtained, can be represented by the general equation of the plane: where a , b , c , and d are provided coefficients. To simplify explanations and avoid the generality loss, it is assumed that the cutting plane is given by three points, which lie on the axes Ox , Oy , Oz and have integer coordinates. Also, for simplicity, we assume that the coordinates of these points cannot be negative. These points are marked as 1 P , 2 P , 3 P . At first, let us consider the approach where the rasterization of the cut is made by the Bresenham's line algorithm without copying of the master-line. Figure 3 shows an example of such rasterization.
Let us consider that 1 3 P P is selected as a master-line, and 1 2 P P is selected as a base-line. At each rasterization step of the segment 1 2 P P shifts y  and z  of coordinates y and z are accumulated. At the same time, the current segment parallel to 1 3 P P is rasterized with the obtained values of shifts. Thus, when passing along 1 2 P P , one rasterization of the line is performed on each step from It should be noted that with this approach it is necessary to check the boundaries of the voxel model on every iteration in order not to exceed its borders. As a result, a plane generated by sequential rasterization of parallel lines is obtained. This plane rasterization satisfies the initial requirements. However, it is obvious that this approach may be greatly optimized. The master-line and the baseline should be correctly selected, the master-line should be rasterized only at once and checking of the boundaries is unnecessary in case of using the certain techniques. It is proposed that during onetime rasterization of the master-line, left and right boundaries are found and preserved for the further rasterization of the necessary fragments of the master-line. As it will be shown below, rasterization of such fragments can be programmed in a simple loop with a counter, where a single addition operation will be applied in the loop body. Thus, the rasterization method described above will consist of two stages: the initialization stage, in which both the master-line is rasterized and boundaries of rasterization fragments are found, and the main stage, when rasterization of the master-line fragments determined by the found limits will be performed.

B. Initialization Stage
Let us assume that it is necessary to rasterize the cut of the voxel model shown in Figure 4, where the cut is presented in the form of a hexagon, the voxel model is represented by a parallelepiped, and the cutting plane is given by the points 1 P , 2 P , 3 P . Before starting the cutting plane rasterization, it is necessary to make an initialization step. At the initialization stage, master-line and base-line are selected, rasterization of the master-line is performed, and boundaries for fragments of the master-line are found. Master-line and base-line are selected in the following way. To choose a master-line, one of the segments starting with 1 P , 2 P or 3 P , must be taken. The end point of the considered segment must be one of the vertices of the cut. Both ends of the segment must belong to one of the planes Oxy , Oxz or Oyz . Since points 1 P , 2 P , 3 P lay on the corresponding coordinate axis, the angle between the selected segment and the axis must be greater than or equal to 45. If selected angle is less than 45, it is possible that the rasterized fragments of the master-line will overlap each other.
The selected segment cannot be shorter than the smallest of the dimensions in the model, since the parallel transfer of the rasterized fragment of the master-line must cover the entire cutting plane. Among the segments which satisfy the criteria described above, it is necessary to select the shortest, which will be accepted as a master-line.
The master-line should be selected as short as possible, since it reduces the amount of computing operations, as it will be shown below. Thus, let the corresponding segment for the master-line be 1 3 P P  .
The segment of the base-line will be in the coordinate plane orthogonal to the plane of the master-line and its beginning will coincide with the beginning of the segment of the master-line. The base line must satisfy such conditions, because otherwise the fragments of the master-line will overlap when copied, as noted above. Thus, the segment corresponding to the base line will be 1 2 P P  . After choosing the master-line and the baseline, we will rasterize the master-line using the Brezhenham's line algorithm. During the rasterization of the master-line, boundaries L A and R A of the fragments, which will be copied when rasterizing the plane, are determined. L A and R A are left and right boundaries, respectively. Also, a chain of coordinate shifts C is found.
The result of such rasterization of the master-line defined from point 1 (0, 0,8) P to point 3 (9, 0, 2) P  is presented in Figure 5. The figure shows the master-line rasterized along the Ox axis and filled arrays L A , R A , and C with corresponding values. C is an array of shifts, each element of which is either 0 or 1, according to whether there is a shift in the current iteration, or no.
The array L A , in this example, contains those x coordinates which correspond to the shifts in the chain C , and the R A array contains coordinates x which correspond to the shifts which would be obtained by rasterizing the master-line in the opposite direction. Also, at the initialization stage, values of L and R variables are set. These variables define the initial limits within which the first fragment of the master line will be rasterized. The variable L corresponds to the element L A , which first falls within the boundary of the model, and the variable R is the last element of R A .

C. Main Stage
After the initialization stage it is necessary to perform the main stage, which is sequential rasterization of the fragments of the resulting master-line along the base line. Base-line is also rasterized by the Bresenham's line algorithm.
The following formulas are used during the fragment rasterization: .
where b z and b y are coordinates of the current voxel when base-line is rasterized and r x , r y , r z are coordinates of the voxel from the fragment of master-line.
The L and R variables determine the limits in which the master-line fragment will be rasterized, and they are indices of the array C . Their values are changing during the base-line rasterization when z coordinate is changed. The variable L will change its value to the previous one in the array L A until it reaches the first element (zeroelement). The variable R will remain constant until the following condition returns true: where S is a number of shifts in the chain C . Otherwise, its value will be changed in the same way as variable L .
The process of the cutting plane rasterization is shown in Figure 6.
Average time characteristics for both the exact weaving algorithm and the developed algorithm are given in the Table. It is obvious that the exact rasterization algorithm has a significant advantage at the initialization stage, since the specificity of the method en- ables the use of low-level functions for fast memory copying. Instead, the algorithm proposed in this paper can be more efficient during its main stage execution of the rasterization by optimizing the number of computations. The exact rasterization algorithm usually requires less memory than the algorithm proposed in the paper, since in addition to maintaining the chain of shifts, the boundaries of the master-line fragments must be stored too.
The proposed rasterization method enables obtaining cuts of voxel datasets at arbitrary angles. The resulting slices have a unit thickness, and they accurately reproduce the cutting plane.
The developed rasterization method uses only integer arithmetic and minimizes the number of

Conclusions
Within the framework of this research, methods and algorithms for rasterization of planes and polygons in three-dimensional space were considered and analysed. As a result, a method based on weaving algorithms is proposed in this paper. This method allows to obtain voxel model cuts with a required thickness and at an arbitrary angle. The resulting slices have a unit thickness and they accurately reproduce the cutting plane. The developed method uses only integer arithmetic and minimizes the number of calculations in the rasterization cycles of master-line fragments, what makes the use of the method sufficiently effective for rasterization of sections of voxel models.
The developed method can be used in various applications where three-dimensional images are used, including medical images, three-dimensional visualization in scientific applications, multimedia and mulsemedia systems. The further work should be focused on parallel realization of the main stage algorithm of the developed method.