Bucketing Strategies for Efficient Triangle Detection in Cam-system Based on Faceted Models

Triangleâ€™s checking in 3D faceted models is an essential step in gouging detection and elimination process. To check whether model surface intersects the tool, every triangle in the model has to be checked. Unfortunately, this process takes much time. Since the computer canâ€™t see and doesnâ€™t know which triangles located under the current tool position, then the triangles all over the surface model should be checked. To reduce the time, region checking at every position of tool has to be detected. Triangles that have to be checked are only in that region. The way of creating the region can be done by bucketing. Bucketing process will make some buckets as representation of regions and each bucket will be filled with triangles that lie in the corresponding region. There are several bucketing methods. This paper will explain all methods which have been implemented in the research. Pengecekan segitiga dalam model 3 dimensi berfaset merupakan tahapan penting dalam deteksi gouging dan proses eliminasi. Untuk mengecek apakah permukaan model bersinggungan dengan alat, setiap segitiga pada model harus diperiksa. Akan tetapi, proses ini membutuhkan waktu yang lama. Segitiga-segitiga pada seluruh permukaan model harus diperiksa karena komputer tidak dapat melihat dan tidak mengetahui segitiga mana yang terletak di bawah posisi alat saat ini. Untuk mengurangi konsumsi waktu, pengecekan wilayah pada setiap posisi alat harus dapat dideteksi. Segitiga yang harus diperiksa adalah hanya yang berada pada wilayah tersebut. Cara yang dapat dilakukan untuk menetapkan wilayah adalah dengan menggunakan bucketing. Proses bucketing akan membuat beberapa bucket sebagai representasi dari beberapa wilayah dan setiap bucket akan diisi dengan segittiga yang terletak pada wilayah terkait. Terdapat beberapa metode bucketing. Paper ini akan menjelaskan semua metode yang telah diimplementasikan di dalam riset.


Introduction
7ULDQJOH ¶V FKHFNLQJ LV RQH RI WKH FUXFLDO processes in CAM system. The tool path in the CAM System has to be free gouging, which PHDQV WKHUH ¶V QR LQWHUIHUHQFH RFFXUV EHWZHHQ WRRO model and surface model. To fulfill this requirement, every sidH RI VXUIDFH PRGHO PXVWQ ¶W contact the tool to avoid gouging. Gouging means the tool cuts the material more than what has been specified.
The surface model, 3D faceted model, consists of many triangles which arrange the VXUIDFH 7R FKHFN ZKHWKHU WKHUH ¶V Lnterference between the surface and the tool, computer has to check all the triangles toward the tool. Since the tool path is arranged with several cc-points, then the computer has to check all triangles at every cc-point. This process takes pretty much time and inefficient. More over if the diameter of the tool and the average area of triangles are small, while the size of the model is big.
In fact, not all the triangles need to be checked at a cc-point. Only triangles which lie in some certain regions need to be noticed. For human, these regions can easily be seen and determined by showing the model and place the tool at one of the cc-point. Unfortunately, FRPSXWHU FDQ ¶W GR WKH VDPH DV KXPDQ 7KH computer can only calculate several numbers with incredible VSHHG EXW LW FDQ ¶W VHH DQG HVWLPDWH WKH triangles under the tool projection. Therefore all triangles have to be checked.
To reduce the number of triangles to be checked at every cc-point, an approach has to be implemented. The triangles have to be localized based on its position on the surface. Localization process can be done by bucketing. The model is divided into several buckets, and each bucket consists of triangles which lie in that region.
In [1][2][3][4] bucketing is explained. But the SURFHVV LVQ ¶W ZHOO described. This paper will explain bucketing process in the detail, and some approach to conduct the task.

Methodology
Let M be a surface model. M consists of triangles 6 = <P 1 , P 2 , å , P J =, where n is the number of triangles composed the model. M is divided into several regions 4 = <N 1 , N 2 , å , N I =, where m is the number of the regions. Every triangleP E is included into one or more region based on its location toward the surface. All triangles have to EH LQFOXGHG DW OHDVW LQWR RQH UHJLRQ DQG WKHUH ¶V QR triangle without region.
Buckets can be illustrated as a set of triangles. Triangle t i is an element of bucket b j if the position of the triangle t i is in the bucket b j (t i WKHUH ¶V VRPH SDUW RI t i or the entire triangles t i lies on bucketb j . Triangle t i can be included into more than one bucket if its location is between more This means that every bucket possibly intersect with other bucket(s). Figure 1 shows the intersection of buckets. Since all the triangles has to be included into at least one bucket, then the complement of union of all buckets is an empty set,:‚ > E I E=1 ; = { } where m is the number of buckets.
Bucketing is conducted by projecting the surface model into 2D bucket coordinate. The area of the surface model projection is in accordance with the area of bounding box (figure 2). The projection is then divided into several rectangles denote the buckets, where each bucket has an information about triangles which belong to that bucket ( figure 3). The number of bucket is determined based on bucket size (width and height) which is input by the user, and relative to WKH [\ DUHD RI PRGHO ¶V ERXQGLQJ ER[ 7KH ELJJHU size of the bucket, the more triangles belong to that bucket.  The number of buckets in the coordinate x and y can be calculated by the following equation.

n_x = x_max/bucket_width n_y = y_max/bucket_height
(1) Where n_x is number of bucket in x coordinate, n_y is number of bucket in y coordinate, x_max is the length of bounding box in x coordinate, and y_max is the length of bounding box in y coordinate. To check a region, one has to detect the position of the bucket in that region. Since bucket is a 2D vector, the position of the bucket means the index of the bucket itself. It can be obtained by calculating xy location of the point in that region.
Where i is x index of the bucket, j is y index of the bucket and xy is the location of the point which region is checked. By implementing bucketing, the process of triangle checking in the series of gouging detection and elimination process can be fastened and done efficiently, since not all triangles are checked. Only triangles in the buckets that are intersected with tool projection are considered (figure 4).

Result and Analysis
Every triangle must be checked and included into one or more buckets. The problem is how to detect which buckets that the triangle belongs. This can be illustrated in figure 5. There are several methods that have been studied to implement bucketing process. They are polygon scanning method, point spreading method, and whole rectangle area method. Each method is explained in the following subsection.
In Polygon scanning method, there are 2 steps that have to be accomplished. First is detecting the side of the triangle edge in bucket coordinate, the second is getting all buckets which lie in the triangle. There are several ways to detect triangle edges in bucket coordinate. Figure 5 shows a triangle in bucket coordinate. To get bucket that is located at triangle side, one has to obtain the bucket where the vertices of triangle lie. In figure  5, triangle vertices located at bucket (2,3), (5,6), and (8,4). Next the buckets along the obtained buckets are searched, which are buckets between bucket (2,3) and (5,6), buckets between (5,6) and (8,4), and buckets between (8,4) and (2,3). The following line formula can be used to get those buckets By incrementing x from x 1 to x 2 , (x,y) indexes bucket coordinate between (x 1 ,y 1 ) and (x 2 ,y 2 ) can be obtained. Since the index coordinate can only handle non-floating point number, then the form of coordinate obtained has to be (x,round(y)) where round(y) is calculated by After obtaining all buckets lying on WULDQJOH ¶V HGJHV QH[W LV VHDUFKLQJ IRU EXFNHWV WKDW located inside the triangle. This is conducted by getting the maximum and minimum value of x and y bucket index of triangle vertices. In figure  5, using triangle vertices which located in bucket (2,3), (5,6), and (8,4), those maximum and minimum xy can be found, which are 2 (minimum x), 8 (maximum x), 3 (minimum y), 6 (maximum y).
By combining minimum and maximum xy using Cartesian product, vertices of rectangle buckets area that the triangle lies in are known. Using the same example, the vertices of rectangle are (2,3), (2,6), (8,6), and (8,3). The checking triangle is considered as polygon where the vertices of triangle (in bucket index coordinate) are the polygon vertices. The process of gaining the buckets inside the triangle is conducted by scanning the polygon from minimum xy until maximum xy (from bucket index (2,3) until bucket index (8,6)). Those buckets that located inside the polygon must include the triangle that is being checked.  (7,2)). It appears to be line bresenham algorithm is not appropriate to be used for bucketing process.
Point Spreading Method uses points that are spread all over the bucket with a constant distance to check whether a triangle is included into the bucket or not (figure 8). The number of points is determined by the system. The more point spread, the more accurate the result will be, but the computational time will be longer. System developer has to decide how many points needed and how much is the distance between points. The step of getting all buckets detected inside the triangle is similar with previous method. By obtaining maximum and minimum xy values based on triangle vertices in bucket coordinate, the bucket is then scanned from maximum xy to minimum xy. At each scanned bucket, the points are spread to detect if the triangle belongs to the checked bucket. If one point is found to be inside the triangle, then the triangle is included into the bucket.  The weakness of this method is if the triangle checked is not inside the bucket, the computational time will reach its worse case which is O(n 2 ) where n is the number of points in x element or y element. Moreover this method is not really accurate to predict a small triangle, smaller than the distance between points that PDNHV WKH SRLQW FDQ ¶W SUHGLFW WKH WULDQJOH $QRWKHU weakness is the maximum number of triangles inside the bucket that can be detected is the same as the number of the points, where each point detects one triangle. It the system spreads 625 points all over a bucket (25×25 points), then the maximum number of small triangles detected will EH ,I WKHUH ¶V VPDOO WULDQJOH EHWZHHQ SRLQWV EXW LW GRHVQ ¶W FRYHU WKH SRLQW WKHQ WKH WULDQJOH LV not detected to be inside of the bucket being checked.
Whole Rectangle Area Method is similar with two previous methods, this method collecting the predicted buckets using minimum and maximum xy values of triangle vertices in bucket coordinate. But instead of scanning the polygon, a triangle is included in all predicted buckets. This method is obviously faster then the first and the VHFRQG PHWKRG VLQFH LW GRHVQ ¶W QHHG WR VFDQ WKH polygon area of the rectangle. Figure 9 shows the area (in thick line) where the triangle should be included in. The buckets which contain the triangle are {(3,2), (4,2), (5,2), « ` $OWhough some bucket GRQ ¶W HYHQ WRXFK WKH WULDQJOH OLNH EXFNHW (6,4), etc, since it is in the predicting area, they have to insert the triangle into their group.
The weakness of this method is obvious. There are many triangles included into the buckets ZKHUH WKH\ VKRXOGQ ¶W EHORQJ WR (YHQ WKRXJK WKH process of bucketing is faster than the other method, there would be a lot of wasting time when searching a triangle in some area, since many triangles that are out of checking area is checked as well as they are inside that region. However, this method is the fastest and most effective among several methods explained, since LW GRHVQ ¶W OHW DQ\ WULDQJOHV WKDW D EXFNHW VKRXOG have are missed.

Conclusion
Triangle checking is an important part of gouging detection and elimination in CAM system. To check if the tool model intersects the surface model at a cc-point, every triangle on the surface model should be checked. If one of the triangles intersects the tool, then the tool should be lifted or rotated to avoid gouging. But the process of checking all triangles takes much time. Instead of checking triangles all over the surface model, region checking is preferable. This makes the computational cost for checking greatly reduced. Only regions which located in the tool projection are checked. To provide this ability, bucketing is implemented. This is conducted by creating several buckets to localize triangles based on their location.
There are three methods that have been studied for this process. They are Polygon Scanning Method, Points Spreading Method, and Whole Rectangle Area Method. All methods have been implemented, and each method has its advantages and weaknesses. Based on the logic that every method has, Whole Rectangle Area Method is the most applicable for the CAMsystem due to its speed and reliability in collecting triangles into buckets.