|
|
|
@ -12,12 +12,17 @@ from plyfile import PlyData, PlyElement |
|
|
|
from general import mesh_tranform_to_pcd |
|
|
|
from general import mesh_tranform_to_pcd |
|
|
|
from general import need_upload_result |
|
|
|
from general import need_upload_result |
|
|
|
from general import extend_dist_min_collision |
|
|
|
from general import extend_dist_min_collision |
|
|
|
|
|
|
|
from general import extend_dist_border_x_min |
|
|
|
|
|
|
|
from general import extend_dist_border_x_max |
|
|
|
|
|
|
|
from general import extend_dist_border_y_min |
|
|
|
|
|
|
|
from general import extend_dist_border_y_max |
|
|
|
|
|
|
|
|
|
|
|
from compute_print_net import arrange_models_on_platform |
|
|
|
from compute_print_net import arrange_models_on_platform |
|
|
|
from compute_print_net import compute_bbox_all |
|
|
|
from compute_print_net import compute_bbox_all |
|
|
|
|
|
|
|
|
|
|
|
from compute_print_net_out import read_mesh |
|
|
|
from compute_print_net_out import read_mesh |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_bbox_for_print(base_original_obj_dir,dict_bad,dict_origin,is_downsample): |
|
|
|
def make_bbox_for_print(base_original_obj_dir,dict_bad,dict_origin,is_downsample): |
|
|
|
"""获取需要的盒子大小""" |
|
|
|
"""获取需要的盒子大小""" |
|
|
|
start_time = time.time() |
|
|
|
start_time = time.time() |
|
|
|
@ -241,10 +246,10 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma |
|
|
|
x_step=1 |
|
|
|
x_step=1 |
|
|
|
delta = 10 |
|
|
|
delta = 10 |
|
|
|
|
|
|
|
|
|
|
|
edge_x_min=0 + 4 |
|
|
|
edge_x_min=0 + extend_dist_border_x_min |
|
|
|
edge_y_min=0 + 4 |
|
|
|
edge_y_min=0 + extend_dist_border_y_min |
|
|
|
edge_x_max=machine_size[0] |
|
|
|
edge_x_max=machine_size[0] - extend_dist_border_x_max |
|
|
|
edge_y_max=machine_size[1] |
|
|
|
edge_y_max=machine_size[1] - extend_dist_border_y_max |
|
|
|
|
|
|
|
|
|
|
|
collision_threshold=2 |
|
|
|
collision_threshold=2 |
|
|
|
move_last = True |
|
|
|
move_last = True |
|
|
|
@ -265,18 +270,22 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma |
|
|
|
min_x = 0 |
|
|
|
min_x = 0 |
|
|
|
max_delta_x = 0 |
|
|
|
max_delta_x = 0 |
|
|
|
x_top_delta = 1 |
|
|
|
x_top_delta = 1 |
|
|
|
border_delta = 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pcd_first= [] |
|
|
|
pcd_first= [] |
|
|
|
pcd_second= [] |
|
|
|
pcd_second= [] |
|
|
|
|
|
|
|
|
|
|
|
index = 0 |
|
|
|
index = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
len_all = len(placed_models) |
|
|
|
|
|
|
|
len_first = len_all * 0.7 |
|
|
|
for model in placed_models: |
|
|
|
for model in placed_models: |
|
|
|
pcd = dict_bounds_fix[model['name']] |
|
|
|
pcd = dict_bounds_fix[model['name']] |
|
|
|
|
|
|
|
|
|
|
|
pcd_all.append(pcd) |
|
|
|
pcd_all.append(pcd) |
|
|
|
|
|
|
|
|
|
|
|
if (get_axis_aligned_bbox(pcd)['y_min']>edge_y_max*0.3 or True): |
|
|
|
# is_first = get_axis_aligned_bbox(pcd)['y_min']>edge_y_max*0.3 or True |
|
|
|
|
|
|
|
is_first = index >= len_first |
|
|
|
|
|
|
|
if (is_first): |
|
|
|
pcd_first.append(pcd) |
|
|
|
pcd_first.append(pcd) |
|
|
|
else: |
|
|
|
else: |
|
|
|
pcd_second.append(pcd) |
|
|
|
pcd_second.append(pcd) |
|
|
|
@ -286,7 +295,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma |
|
|
|
dx = model['dimensions'][0] |
|
|
|
dx = model['dimensions'][0] |
|
|
|
x = model['position'][0] |
|
|
|
x = model['position'][0] |
|
|
|
|
|
|
|
|
|
|
|
if (x>=edge_x_max-x_top_delta) : |
|
|
|
if (x>=edge_x_max) : |
|
|
|
pcd_processed_x_top.append(pcd) |
|
|
|
pcd_processed_x_top.append(pcd) |
|
|
|
print("pcd_processed_x_top", model['name']) |
|
|
|
print("pcd_processed_x_top", model['name']) |
|
|
|
if dx > max_x: |
|
|
|
if dx > max_x: |
|
|
|
@ -327,7 +336,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma |
|
|
|
dist_x = x - edge_x_min |
|
|
|
dist_x = x - edge_x_min |
|
|
|
if y - 10 < edge_y_min: |
|
|
|
if y - 10 < edge_y_min: |
|
|
|
dist_y = y - edge_y_min |
|
|
|
dist_y = y - edge_y_min |
|
|
|
if (x<edge_x_max-x_top_delta) : |
|
|
|
if (x<edge_x_max) : |
|
|
|
if draw_down: |
|
|
|
if draw_down: |
|
|
|
pcd.translate([-dist_x, -dist_y, 0]) |
|
|
|
pcd.translate([-dist_x, -dist_y, 0]) |
|
|
|
|
|
|
|
|
|
|
|
@ -347,7 +356,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma |
|
|
|
pcd_processed_curr = pcd_processed |
|
|
|
pcd_processed_curr = pcd_processed |
|
|
|
x_step_big = x_step * 2 |
|
|
|
x_step_big = x_step * 2 |
|
|
|
y_step_big = y_step * 2 |
|
|
|
y_step_big = y_step * 2 |
|
|
|
collision_threshold_big = collision_threshold + 10 |
|
|
|
collision_threshold_big = collision_threshold + 6 |
|
|
|
y_init_big = 5 |
|
|
|
y_init_big = 5 |
|
|
|
if dx > 80: |
|
|
|
if dx > 80: |
|
|
|
y_init_big = 10 |
|
|
|
y_init_big = 10 |
|
|
|
@ -439,8 +448,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma |
|
|
|
if bbox['y_min'] <= edge_y_min + collision_threshold_init and False: |
|
|
|
if bbox['y_min'] <= edge_y_min + collision_threshold_init and False: |
|
|
|
pcd.translate([0, y_step, 0]) |
|
|
|
pcd.translate([0, y_step, 0]) |
|
|
|
break |
|
|
|
break |
|
|
|
# if bbox['y_max'] >= edge_y_max - collision_threshold_init: |
|
|
|
if bbox['y_max'] >= edge_y_max: |
|
|
|
if bbox['y_max'] >= edge_y_max - border_delta: |
|
|
|
|
|
|
|
pcd.translate([0, -y_step, 0]) |
|
|
|
pcd.translate([0, -y_step, 0]) |
|
|
|
T_transTemp = np.eye(4) |
|
|
|
T_transTemp = np.eye(4) |
|
|
|
T_transTemp[:3, 3] = [0, -y_step, 0] |
|
|
|
T_transTemp[:3, 3] = [0, -y_step, 0] |
|
|
|
@ -464,7 +472,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma |
|
|
|
pcd.translate([x_step, 0, 0]) |
|
|
|
pcd.translate([x_step, 0, 0]) |
|
|
|
break |
|
|
|
break |
|
|
|
# if bbox['x_max'] >= edge_x_max - collision_threshold_init: |
|
|
|
# if bbox['x_max'] >= edge_x_max - collision_threshold_init: |
|
|
|
if bbox['x_max'] >= edge_x_max - border_delta: |
|
|
|
if bbox['x_max'] >= edge_x_max: |
|
|
|
# print("1pcd.translate([-x_step, 0, 0])",name_list[idx]) |
|
|
|
# print("1pcd.translate([-x_step, 0, 0])",name_list[idx]) |
|
|
|
pcd.translate([-x_step, 0, 0]) |
|
|
|
pcd.translate([-x_step, 0, 0]) |
|
|
|
T_transTemp = np.eye(4) |
|
|
|
T_transTemp = np.eye(4) |
|
|
|
@ -591,6 +599,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma |
|
|
|
pcd_second2 = [pcd_second[i] for i in sorted_indices] |
|
|
|
pcd_second2 = [pcd_second[i] for i in sorted_indices] |
|
|
|
# print("pcd_second2 len", len(pcd_second2)) |
|
|
|
# print("pcd_second2 len", len(pcd_second2)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
check_top_right = True |
|
|
|
for idx, pcd in enumerate(pcd_second2): |
|
|
|
for idx, pcd in enumerate(pcd_second2): |
|
|
|
|
|
|
|
|
|
|
|
ply_file_name = dict_name[pcd] |
|
|
|
ply_file_name = dict_name[pcd] |
|
|
|
@ -607,7 +616,23 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma |
|
|
|
tx = edge_x_min - min_x |
|
|
|
tx = edge_x_min - min_x |
|
|
|
ty = -max_y - 0.001 |
|
|
|
ty = -max_y - 0.001 |
|
|
|
|
|
|
|
|
|
|
|
T_transTemp = move_to_top_left(pcd, edge_x_min+2, edge_y_max-2) |
|
|
|
if (check_top_right): |
|
|
|
|
|
|
|
T_transTemp, tx, ty = move_to_top_right(pcd, edge_x_max, edge_y_max) |
|
|
|
|
|
|
|
check_top_right = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not check_collision_all(pcd, last_pcd_processed, collision_threshold_init): |
|
|
|
|
|
|
|
print("succ move_top_right",name,bbox['x_max'],bbox['y_max'],len(last_pcd_processed)) |
|
|
|
|
|
|
|
T_trans1 = T_transTemp @ T_trans1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
last_pcd_processed.append(pcd) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dict_total_matrix[obj_name]= T_trans1 @ dict_total_matrix[obj_name] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
pcd.translate((-tx, -ty, 0), relative=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
T_transTemp = move_to_top_left(pcd, edge_x_min, edge_y_max) |
|
|
|
|
|
|
|
|
|
|
|
T_trans1 = T_transTemp @ T_trans1 |
|
|
|
T_trans1 = T_transTemp @ T_trans1 |
|
|
|
|
|
|
|
|
|
|
|
@ -948,6 +973,21 @@ def move_to_top_left(pcd, edge_x_min, edge_y_max): |
|
|
|
|
|
|
|
|
|
|
|
return T_transTemp |
|
|
|
return T_transTemp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def move_to_top_right(pcd, edge_x_max, edge_y_max): |
|
|
|
|
|
|
|
points = np.asarray(pcd.points) |
|
|
|
|
|
|
|
min_x = np.min(points[:, 0]) |
|
|
|
|
|
|
|
max_y = np.max(points[:, 1]) # 当前最大y值 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tx = edge_x_max - min_x |
|
|
|
|
|
|
|
ty = edge_y_max - max_y |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
T_transTemp = np.eye(4) |
|
|
|
|
|
|
|
T_transTemp[:3, 3] = [tx, ty, 0] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pcd.translate((tx, ty, 0), relative=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return T_transTemp, tx, ty |
|
|
|
|
|
|
|
|
|
|
|
def move_to_bottom_right(pcd, edge_x_max, edge_y_min): |
|
|
|
def move_to_bottom_right(pcd, edge_x_max, edge_y_min): |
|
|
|
|
|
|
|
|
|
|
|
points = np.asarray(pcd.points) |
|
|
|
points = np.asarray(pcd.points) |
|
|
|
|