Browse Source

代码更新

main
hesuicong 1 week ago
parent
commit
469155434d
  1. 15
      compute_print_net.py
  2. 7
      config.py
  3. 2
      general.py
  4. 68
      point_cloud_layout.py

15
compute_print_net.py

@ -112,8 +112,12 @@ def compute_bbox(mesh_obj, obj_name, is_downsample=True): @@ -112,8 +112,12 @@ def compute_bbox(mesh_obj, obj_name, is_downsample=True):
match = re.search(r"P(\d+)", obj_name) # 匹配 "P" 后的连续数字
if match:
printId = match.group(1)
total_matrix, z_max, min_bound, max_bound, ply_name = compute_bbox_net(printId)
ply_name = f"{os.path.splitext(obj_name)[0]}={ply_name.split('=')[1]}"
succ, total_matrix, z_max, min_bound, max_bound, ply_name = compute_bbox_net(printId)
if not succ :
total_matrix, z_max, min_bound, max_bound, ply_name = compute_bbox_ext(mesh_obj, obj_name, is_downsample)
else:
ply_name = f"{os.path.splitext(obj_name)[0]}={ply_name.split('=')[1]}"
# print(f"compute_bbox_net printId = {printId}, total_matrix = {total_matrix}, ply_name = {ply_name}")
else :
total_matrix, z_max, min_bound, max_bound, ply_name = compute_bbox_ext(mesh_obj, obj_name, is_downsample)
@ -135,11 +139,14 @@ import requests @@ -135,11 +139,14 @@ import requests
import ast
def compute_bbox_net(printId):
url = f"https://mp.api.suwa3d.com/api/printOrder/infoByPrintId?printId={printId}"
url = f"{url_infoByPrintId}{printId}"
res = requests.get(url)
datas = res.json()["data"]["layout"]
# print("datas=", datas)
if not "ply_name" in datas:
return False, np.eye(4), 0.0, np.zeros(3), np.zeros(3), ""
homo_matrix_str = datas.get("homo_matrix")
# print("homo_matrix_str=", homo_matrix_str)
@ -157,7 +164,7 @@ def compute_bbox_net(printId): @@ -157,7 +164,7 @@ def compute_bbox_net(printId):
ply_name = datas.get("ply_name",0)
# print(f"layout_z={layout_z}, max_bound={max_bound}, min_bound={min_bound}, ply_name={ply_name}, ")
return reconstructed_matrix, layout_z, max_bound, min_bound, ply_name
return True, reconstructed_matrix, layout_z, max_bound, min_bound, ply_name
class Platform:
def __init__(self, width, depth, height):

7
config.py

File diff suppressed because one or more lines are too long

2
general.py

@ -222,7 +222,7 @@ def copy_obj_2x(base_obj_dir): @@ -222,7 +222,7 @@ def copy_obj_2x(base_obj_dir):
# -------------------------- 开始:碰撞检测和越界 --------------------------
extend_dist_border_x_min = 6
extend_dist_border_x_max = 3
extend_dist_border_x_max = 6
extend_dist_border_z_max = 3
extend_dist_border_y_min = 6
extend_dist_border_y_max = 6

68
point_cloud_layout.py

@ -12,12 +12,17 @@ from plyfile import PlyData, PlyElement @@ -12,12 +12,17 @@ from plyfile import PlyData, PlyElement
from general import mesh_tranform_to_pcd
from general import need_upload_result
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 compute_bbox_all
from compute_print_net_out import read_mesh
def make_bbox_for_print(base_original_obj_dir,dict_bad,dict_origin,is_downsample):
"""获取需要的盒子大小"""
start_time = time.time()
@ -241,10 +246,10 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma @@ -241,10 +246,10 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma
x_step=1
delta = 10
edge_x_min=0 + 4
edge_y_min=0 + 4
edge_x_max=machine_size[0]
edge_y_max=machine_size[1]
edge_x_min=0 + extend_dist_border_x_min
edge_y_min=0 + extend_dist_border_y_min
edge_x_max=machine_size[0] - extend_dist_border_x_max
edge_y_max=machine_size[1] - extend_dist_border_y_max
collision_threshold=2
move_last = True
@ -265,18 +270,22 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma @@ -265,18 +270,22 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma
min_x = 0
max_delta_x = 0
x_top_delta = 1
border_delta = 4
pcd_first= []
pcd_second= []
index = 0
len_all = len(placed_models)
len_first = len_all * 0.7
for model in placed_models:
pcd = dict_bounds_fix[model['name']]
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)
else:
pcd_second.append(pcd)
@ -286,7 +295,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma @@ -286,7 +295,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma
dx = model['dimensions'][0]
x = model['position'][0]
if (x>=edge_x_max-x_top_delta) :
if (x>=edge_x_max) :
pcd_processed_x_top.append(pcd)
print("pcd_processed_x_top", model['name'])
if dx > max_x:
@ -327,7 +336,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma @@ -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
if y - 10 < 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:
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 @@ -347,7 +356,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma
pcd_processed_curr = pcd_processed
x_step_big = x_step * 2
y_step_big = y_step * 2
collision_threshold_big = collision_threshold + 10
collision_threshold_big = collision_threshold + 6
y_init_big = 5
if dx > 80:
y_init_big = 10
@ -439,8 +448,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma @@ -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:
pcd.translate([0, y_step, 0])
break
# if bbox['y_max'] >= edge_y_max - collision_threshold_init:
if bbox['y_max'] >= edge_y_max - border_delta:
if bbox['y_max'] >= edge_y_max:
pcd.translate([0, -y_step, 0])
T_transTemp = np.eye(4)
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 @@ -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])
break
# 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])
pcd.translate([-x_step, 0, 0])
T_transTemp = np.eye(4)
@ -591,6 +599,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma @@ -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]
# print("pcd_second2 len", len(pcd_second2))
check_top_right = True
for idx, pcd in enumerate(pcd_second2):
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 @@ -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
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
@ -627,7 +652,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma @@ -627,7 +652,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma
if (finish_move2):
break
else:
if not check_collision_all(pcd, last_pcd_processed,collision_threshold_init):
if not check_collision_all(pcd, last_pcd_processed, collision_threshold_init):
print("succ_move1",name,bbox['x_max'],bbox['y_max'],len(last_pcd_processed))
break
@ -948,6 +973,21 @@ def move_to_top_left(pcd, edge_x_min, edge_y_max): @@ -948,6 +973,21 @@ def move_to_top_left(pcd, edge_x_min, edge_y_max):
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):
points = np.asarray(pcd.points)

Loading…
Cancel
Save