• 沒有找到結果。

Chapter 2 Related Works

2.3 Legolization

Silva et al. [8] provided a process of subdividing triangles and voxelization by using GPU. They transformed a polygon model to a LEGO sculpture efficiently. However, this technique just showed the models on screen after legolizating. They did not discuss the stability of a sculpture and build it practically. Lambrecht [5] categorized LEGO sculpture into two types: stud-up and stud-out model, as shown in Figure 2.3. They focused on the stud-out model, whose bricks allowed orthogonal connections. Despite the bricks make the sculptures more realistic, they are not used widely.

Figure 2.3: The illustrations [5] of (a) stud-up sculpture, and (b) stud-out sculpture.

Testuz et al. [12] replaced graphic algorithm with heuristic optimization algorithms.

Using their algorithm, the whole process does not need to consider all heuristics, because most heuristics are related to the connections among bricks. The more connection of a brick has, the more stable the sculpture is. Calculating the connection of a brick and optimizing LEGO structures by graphic algorithm can enhance the efficiency of computing a stable structure layer-by-layer. We propose our improvement to extend to hollowing and center of mass adjusted models.

9

Chapter 3 Algorithm

The goal of this research is to build a LEGO sculpture easier. In this chapter, we describe the process of the assembly instructions generation. By following the instructions of each layer, users can build a stable and low-cost LEGO sculpture. Figure 3.1 explains the flow of our proposed system. The final output present the assembly instructions of each layer. These instructions assist people to build a LEGO sculpture of an input model in any pose. Furthermore, the constructed LEGO sculpture can always stand at the ground plane stably.

The input of our proposed system is a closed polygonal model. Users can rotate or scale the model arbitrary. The first step is voxelization. The input model is voxelized into a volumetric model. Secondly, in order to make the LEGO sculpture stand stably, we need to adjust the center of mass (CoM) by removing proper inner voxels of the LEGO sculpture. Finally, we optimize the trade-off between the connection and brick cost to construct a suitable structure of each layer. The connection influences the stability of a sculpture and the brick cost is related to the usage rate of different bricks.

The rest of this chapter is organized as follows. In section 3.1 we describe how to test the intersection between a voxel and a triangle by Akenine-Möller’ approach [1].

We define “erasable voxel” and “safe region”, and explain the process of adjusting center of mass in section 3.2. And the section 3.3 discuss about the greedy merge algorithm which deals with the trade-off between the connection and each brick cost

10

Figure 3.1: The flow of our proposed system architecture. (a) The input model and its axis-aligned bounding box. (b) The voxelized model. (c) It shows the center of mass

before and after adjusting center of mass. (d) The 2nd and 3rd layers’ assembly instructions of the oblique bunny. (e) The bunny LEGO sculpture.

3.1 Voxelization

The first step of our algorithm is to transform a polygonal model into voxel data.

11

We apply Akenine-Möller’s approach [1] to detect the intersection among voxels and triangles. Based on the separating axis theorem (SAT), if there exists an axis onto which the projections of a voxel V and a triangle T do not overlap, V and T do not overlap.

The axes onto which V and T project are separating axes. If V and T are disjoint, there is a separating plane between them. And the axes is orthogonal to a separating plane.

We test 13 separating axes as shown in Figure 3.2:

1. [3 tests] Let e , 0 e , and 1 e2 are the normals of a voxel. Voxels always align with the axes of 3D coordinates, so we define normals e = (0, 1, 0), 0 e1 = (0, 0, 1), and e = (1, 0, 0). 2

2. [1 tests] Let n be the normal of a triangle.

3. [9 tests] The cross product of an edge from a voxel with an edge from a triangle.

Treat the normals (e ) of a voxel as its edges, and i uj is the edge of a triangle.

Then we can define aij as follows:

aij = ei × uj (𝑖, 𝑗 ∈ {0, 1, 2}) (1)

Figure 3.2: The illustration of the 13 separating axes. e , 0 e , 1 e , and 2 n are the normals of V and T. The other 9 axes are e i × u j (𝑖, 𝑗 ∈ {0, 1, 2}).

12

To simplify the test, we move the triangle first, so that the voxel is centered on the origin. Let a = (𝑎𝑥, 𝑎𝑦, 𝑎𝑧) stands for one of the 13 separating axes. The process of

As illustrated in Figure 3.3, as soon as a separating axis is found that the projections of a triangle T and a voxel V do not overlap, we keep the voxel V and test other voxels and triangles. Otherwise, we continue testing whether the projections of V and T overlap on other separating axes. If V and T overlap on all the 13 separating axes, V intersects with T

Figure 3.3: (a) The projections of V and T onto a do not overlap, so V and T are disjoint. (b) The projections of V and T are overlap on this separating axis. We test

other axes to ensure the intersection status of V and T.

13

3.2 Center of Mass Adjustment

A model can stand stably if the projection of the center of mass is located on the suitable area, which is denoted as the “safe region” of the sculpture. However, for an arbitrary solid model, the center of mass may not lie in the safe region. Thus, we remove voxels to adjust the center of mass. In addition, to avoid destroying the appearance of a model, only the inner voxels can be removed.

3.2.1 Erasable Voxel

To ensure the appearance and the stability of a LEGO sculpture, voxels on the shell cannot be removed. As shown in Figure 3.4, a shell is composed of the outer voxels of a voxelized model. The thickness of a shell is the number of voxels counted from the interior to the exterior of a model. A sculpture is more stable with a thicker shell. In order to strengthen the connections of bricks on a shell, the thickness of a shell should be greater than 2-unit-brick. If voxels are not on the shell, they are denoted as the

“erasable voxel”.

Figure 3.4: (a) The shell in the 8th layer of the voxelized bunny model in (b). The thickness of the shell is 3-unit-birck.

14

The method of determining an erasable voxel is to count the number of its surrounded voxels. If the surrounded voxels of the voxel V is over the shell’s thickness in all the six directions, V is an “erasable voxel”, as displayed in Figure 3.5(a). Figure 3.5(b) illustrates the example of erasable voxels. Voxel A is not an erasable voxel because its number of surrounded voxels in right and behind side is less than the shell’s thickness. In contrast, Voxel B is an erasable voxel.

Figure 3.5: (a) The six direction of a voxel V. (b) The shell’s thickness is 2-unit-birck.

For voxel A, the number of surrounded voxels is 0 in the right side, and it is 1 in the behind side. For voxel B, the number of surrounded voxels is over 2 in all directions.

3.2.2 Safe Region

A safe region means the convex hull of the area where voxels in the lowest layer contacting the ground plane. Based on Prevost’s approach [7], the model can stand stably without any struts when the projection of center of mass onto the ground plane

15

lies in the safe region. We apply Andrew's Monotone Chain convex hull algorithm [2]

to build the convex hull. The pseudo codes are presented in Pseudocode 1 and 2.

In this algorithm, we build a lower hull and an upper hull separately, and concatenate them to form a complete convex hull. Both of the lower hull and upper hull connect to the center of voxels counterclockwise, but a lower hull connects voxels form the leftmost to the rightmost, and the other is reverse, as shown in Figure 3.6.

16

Figure 3.6: The top view of voxels in the bottom layer. The green line is the upper hull and the red line is the lower hull. If it is clockwise from AE to AF , A, E and F

are the vertices of the convex hull.

The processes of building a lower and upper hull are the same. We use a list (L and U, as shown in pseudocode 1) to record the vertices of them. As described at line 7 and

14 in pseudocode 1, the last two vertices in the list and P[i] are used to determine whether the vertices in the list are real vertices or not. For example, as displayed in figure 3.6, voxel A and E are vertices of the lower hull and recorded in list L, and voxel F is the current P[i]. If the cross product of AE and AF is lower than 0, which means they are clockwise, we remove E from L, and then compute the cross product for the current last two vertices and F iteratively. In contrast, F is the new vertex of the convex hull, so we insert B into L. Figure 3.7 displays the safe region built by this algorithm and the center of mass’s projection (𝑐, as shown in Figure 3.7) that is not in the safe region.

17

Figure 3.7: The voxelized bunny model. The blue convex is the safe region of the bunny model. 𝑐 is the projection of center of mass onto the ground plane.

3.2.3 Adjusting Center of Mass

According to Prevost’ approach [7]. If the distance from a voxel to center of mass is greater, removing the voxel can adjust center of mass much closer to the safe region.

Therefore, we sort the voxels in decreasing order by the distance and remove the voxels.

We calculate the distance as follows:

𝑑𝑖 = (𝑐𝑖− 𝑐) ∙ (𝑐 − 𝑐) (4)

, where 𝑐𝑖 is the center of a voxel. 𝑐 is the center of the safe region and its height equals to the center of mass. 𝑐 is also treated as the ideal center of mass. 𝑐 is the center of mass’s position, and we get it by Eg. 5:

𝑐 = 𝑛𝑖=0𝑛𝑐𝑖 (5)

, where 𝑛 is the total number of voxels in a model. As shown in Figure 3.8, a model is separated into two half spaces by a plane which is perpendicular to the ground plane and passes through 𝑐. Removing the voxels located in the half space, which contains

18

the center of mass, can make 𝑐 closer to 𝑐. In contrast, removing the voxels in the other half space makes 𝑐 further away from 𝑐. Consequently, voxels can be removed if they are in the same half space with center of mass. We remove voxels whose distances are greater than 0.

Figure 3.8: We separate the model into two half spaces based on the ideal center of mass (𝑐). When 𝑐 and 𝑐𝑖 are in the same half space, removing 𝑐𝑖 can make 𝑐

closer to 𝑐.

The effect of adjusting center of mass is presented in Figure 3.9. 𝑐 is moved into the safe region after adjusting center of mass, so the model can stand stably after built in reality. Although a model is stable while the center of mass lies in the safe region, we continue removing erasable voxels to decrease the number of voxels as less as

19

possible. At last, we will remove all voxels which are in the same half space with center of mass.

Figure 3.9: The model (a) before and (b) after adjusting center of mass. (c) and (d) Compare the inner structure of the model before and after adjusting center of mass.

3.3 LEGO Brick Merging

To build a stable LEGO sculpture more easily in reality, we need the assembly instructions of each layer. Because the types of LEGO bricks are various, it costs too much time to test all types of bricks and choose the proper one. Therefore, we constrain the usable types, as shown in Figure 3.10, and denote them as “legal brick”.

20

Figure 3.10: The legal bricks [12].

We construct the instructions layer-by-layer by a greedy merge algorithm, which merges voxels into a legal brick with highest value. The process of optimizing an assembly instruction is presented in Pseudocode 3. We describe the details of each step in the following sub-sections:

3.3.1 Voxel Selection

The shell of a LEGO sculpture is often difficult to build because there are too many 1*1 bricks. It causes weak connection of the bricks on the shell, as displayed in Figure 3.11. Thus, we raise the probability of being selected for the voxels which are on a shell in order to merge them into bricks first. The probability is determined by the number of a voxel’s neighbors and computed as Eg. 6,

probability = { 1, 𝑖𝑓 𝑛𝑢𝑚 ≤ 3

1 / exp(𝑛𝑢𝑚) , 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 (6)

, where num is the number of neighbors. We make the voxels with less neighbors are

21

chosen more easily because they are usually on the shell, as shown in Figure 3.12.

Figure 3.11: (a) A shell is composed of 1*1 bricks. It cannot be built in reality because of the weak connection of bricks. (b) Using proper bricks makes the shell

stable and buildable.

Figure 3.12: Ignore the vertical neighbors. Red voxel: the number of neighbors is 2.

Yellow voxels: the number of neighbors is 3. The voxels with few neighbors usually exist on the shell.

22

3.3.2 A Set of Valid Legal Bricks

We combine the chosen voxel and its neighbors to form a legal brick. A brick can be put laterally or longitudinally, which means that a brick is able to involve in the chosen voxel with different positions. For example, there exists 16 different selections for a 2*4 brick as presented in Figure 3.13.

Figure 3.13: The yellow voxel is a chosen voxel. The green brick is a 2*4 brick. (a) Two examples of putting a 2*4 brick on the chosen voxel laterally. (b) Two examples

of putting a 2*4 brick on the chosen voxel longitudinally.

We test all the selections of each legal brick to confirm whether they are valid or not. As illustrated in Figure 3.14, a brick becomes valid if all the voxels in this brick exist; otherwise, the brick is invalid. Therefore, each brick’s type can produce several

“valid legal bricks”. We compute the connections and brick costs of all the valid legal bricks, and merge the chosen voxel and its neighbors to the optimal one.

23

Figure 3.14: The chosen voxel (yellow) and its neighbors is merged into a 2*4 brick (red). We put the brick in different positions. The positions of a brick in (a) and (b) are

valid legal bricks. (c) A 2*4 brick with unsuitable position is invalid because it does not contains 8 voxels

3.3.3 Merging LEGO Bricks

In order to build a stable and low-cost sculpture, we need to consider the vertical connections and brick costs of all the valid legal bricks in the greedy merge algorithm.

As shown in Figure 3.15, brick A connects with brick B if they overlap in vertical.

Figure 3.15: Two bricks are connected when they overlap.

The connection of a brick means how many bricks it connects with. It influences the stability of a LEGO sculpture because bricks do not drop easily if they are connected by a lot of other bricks. A large brick has higher connection commonly. For example, a

24

2*4 brick can connect with 8 bricks at most, but a 1*4 brick only connect with 4 bricks.

The brick cost is determined by the number of each brick’s type. Larger bricks are less in reality. Consequently, though the large bricks own higher connections, their brick costs are higher because of their rarity. We can reduce the usage rate of the large bricks to cost down. Our algorithm deals with the trade-off between connection and each brick cost, then selects a valid legal brick with highest value. The value of a valid legal brick is computed as Eg. 7,

𝑉𝑏 = 𝛼𝑐1− (1 − 𝛼)𝑐2 (7) , where 𝑐1 is the connection, and 𝑐2 is the cost of a brick’s type. We square the connection in order to reinforce its influence. 𝛼 is the weight of 𝑝1. Higher α-value can strengthen the connections of bricks. Otherwise, the structure with low α-value is frail, but the demands for rare bricks are decreased.

In some special cases, it is not enough to take care of only connections and brick costs when merging bricks. Therefore, we propose three exceptions and show them as follows:

(a) In the button layer. The bricks are as larger as possible.

(b) If the brick does not connect with other bricks. 𝑉𝑏= −∞

(c) If the brick connects with other bricks and its center does not overlap the bricks it connect. 𝑉𝑏= ∞ + 𝑑𝑖𝑠𝑡, where 𝑑𝑖𝑠𝑡 is the minimal distance from the center of the brick to the centers of voxels it connects.

As displayed in Figure 3.16, 𝑑𝑖𝑠𝑡 is the distance between B1 and V2. Higher distance means that B1 is a larger brick. We use larger bricks to avoid producing bricks which are pendent. In Figure 3.18(a), B2 does not connect with other bricks, thus it cannot be built practically. Otherwise, there is not any brick pendent by using larger

25

brick B1, as shown in Figure 3.18(b). After increase exceptions, the process of calculating optimal brick value is presented in Peeudocode 4. Exception (a)(b)(c) are implemented at line 9, 11, and 14 respectively.

Figure 3.16: V1 and V2 are the voxels in the brick B3, which connects with brick B1. B2 is also a brick.

26

These exceptions reduce the bricks which do not connect with other bricks. Figure 3.17 shows the parts of the bunny sculpture. Our system merges a 2*4 brick which crosses the gap, as displayed in Figure 3.17 (c), so the brick does not drop into the gap and it becomes a good base for the above bricks, as shown in Figure 3.17 (e).

Figure 3.17: (a) the 19th, (c) 20th, and (e) the 21th layers of the bunny sculpture. (b), (d) and (f) are the assembly instructions of them respectively. (c) The effect of the exceptions. It chooses larger brick in priority, so that the bricks in the 21th layer can be

built successfully.

27

Chapter 4

Implementation and Results

In this chapter, we present our implementation and results. The explanation of how to decide the brick costs is discussed in section 4.1. Moreover, there are two modes to remove inner voxels. In section 4.2, we shows our results and the structures with different parameters.

4.1 Implementation

The implementation was under the Intel Extreme CPU X9650 with 3.0 GHz and 4GB memory. The IDE is Microsoft Visual Studio 2012. All the polygonal models are acquired from Google 3D warehouse, as shown in Figure 4.1.

Figure 4.1: (a) Coca. (b) Bunny. (c) Yoshi. (d) Dragon models.

There are two modes to remove the inner voxels: hollowing mode and adjusting CoM mode. If the projection of center of mass is located on the safe region after voxelizing, we can use hollowing mode. Therefore, all the erasable voxels are removed, and the model can be built with fewer bricks. The sculpture turns into a stable status

28

when the thickness of the shell is higher than 3-unit-brick, as shown in Figure 4.2. On the other hand, while a model’s center of mass is not situated on the safe region, we use adjusting CoM mode. Under this circumstance, the model’s center of mass is moved into the safe region. However, not all the erasable voxels can be removed because the current center of mass will be further away from the safe region, after removing the inappropriate voxels. Figure 4.3 illustrates the effect on adjusting center of mass. The voxels in the green dash area cannot be removed because they are not in the same half space with center of mass. After adjusting the center of mass, we cannot use the hollowing mode for the same model.

Figure 4.2: The structures of 7th and 8th layers of the bunny sculpture. The thickness is 3-unit-brick.

29

Figure 4.3: (a) and (b) show the structures of the 8th and 9th layers of the voxelized coca model. The shell’s thickness of the model is a 2-unit-brick length.

In a LEGO box, there are several types of bricks with different quantities. Figure 4.4 presents the quantities of the brick types in a LEGO box. The less quantity of the brick type, the higher the brick cost is. Take red bricks as an example, 1*2 and 2*2 bricks are more than others, thus, we can use them more frequently. In contrast, there is only one 2*8 brick in this box, so we raise its cost to reduce the usage rate. The cost is the quotient of dividing 1*2 brick’s quantity by each brick type’s quantity, and then

In a LEGO box, there are several types of bricks with different quantities. Figure 4.4 presents the quantities of the brick types in a LEGO box. The less quantity of the brick type, the higher the brick cost is. Take red bricks as an example, 1*2 and 2*2 bricks are more than others, thus, we can use them more frequently. In contrast, there is only one 2*8 brick in this box, so we raise its cost to reduce the usage rate. The cost is the quotient of dividing 1*2 brick’s quantity by each brick type’s quantity, and then

相關文件