Browse Source

代码更新

main
hesuicong 1 week ago
parent
commit
0dc83ba187
  1. 4
      clound_print.py
  2. 20
      compute_print_net.py
  3. 5
      config.py
  4. 10
      download_print_out.py
  5. 12
      point_cloud_layout.py
  6. 2
      print_factory_type_setting_obj_run.py
  7. 3
      test_load_json.py

4
clound_print.py

@ -184,7 +184,7 @@ def clear_directory_recursive(dir_path):
# 如果是文件或符号链接,直接删除 # 如果是文件或符号链接,直接删除
try: try:
os.unlink(item_path) os.unlink(item_path)
print(f"已删除: {item_path}") # print(f"已删除: {item_path}")
except Exception as e: except Exception as e:
print(f"删除失败 {item_path}: {e}") print(f"删除失败 {item_path}: {e}")
elif os.path.isdir(item_path): elif os.path.isdir(item_path):
@ -292,7 +292,7 @@ def process_clound_print(data):
) )
list_print_model_info.append(batch_model_info) list_print_model_info.append(batch_model_info)
print("-" * 40) # print("-" * 40)
workdir = f"{print_data_dir}{pre_batch_id}" workdir = f"{print_data_dir}{pre_batch_id}"

20
compute_print_net.py

@ -92,7 +92,7 @@ def compute_bbox_all(dict_mesh_obj,is_downsample):
dict_total_matrix[obj_name] = total_matrix dict_total_matrix[obj_name] = total_matrix
dict_pcd_fix[ply_name] = pcd_fix dict_pcd_fix[ply_name] = pcd_fix
print(f"compute_bbox obj_name={obj_name} ply_name={ply_name} time={time.time()-start_time}") # print(f"compute_bbox obj_name={obj_name} ply_name={ply_name} time={time.time()-start_time}")
# dict_mesh_obj.clear() # dict_mesh_obj.clear()
# del dict_mesh_obj # del dict_mesh_obj
@ -115,13 +115,15 @@ def compute_bbox(mesh_obj, obj_name, is_downsample=True):
succ, total_matrix, z_max, min_bound, max_bound, ply_name = compute_bbox_net(printId) succ, total_matrix, z_max, min_bound, max_bound, ply_name = compute_bbox_net(printId)
if not succ : if not succ :
total_matrix, z_max, min_bound, max_bound, ply_name = compute_bbox_ext(mesh_obj, obj_name, is_downsample) total_matrix, z_max, min_bound, max_bound, ply_name = compute_bbox_ext(mesh_obj, obj_name, is_downsample)
print(f"compute_bbox_net fail {printId}")
else: else:
ply_name = f"{os.path.splitext(obj_name)[0]}={ply_name.split('=')[1]}" ply_name = f"{os.path.splitext(obj_name)[0]}={ply_name.split('=')[1]}"
print(f"compute_bbox_net succ {printId}")
# print(f"compute_bbox_net printId = {printId}, total_matrix = {total_matrix}, ply_name = {ply_name}") # print(f"compute_bbox_net printId = {printId}, total_matrix = {total_matrix}, ply_name = {ply_name}")
else : else :
total_matrix, z_max, min_bound, max_bound, ply_name = compute_bbox_ext(mesh_obj, obj_name, is_downsample) total_matrix, z_max, min_bound, max_bound, ply_name = compute_bbox_ext(mesh_obj, obj_name, is_downsample)
# print(f"compute_bbox_ext total_matrix = {total_matrix}, ply_name = {ply_name}") print(f"compute_bbox_ext ply_name = {ply_name}")
transformed_vertices = mesh_transform_by_matrix(np.asarray(mesh_obj_origin.vertices), total_matrix) transformed_vertices = mesh_transform_by_matrix(np.asarray(mesh_obj_origin.vertices), total_matrix)
@ -154,7 +156,7 @@ def compute_bbox_net(printId):
try: try:
matrix_list = ast.literal_eval(homo_matrix_str) # 直接转换为二维列表 matrix_list = ast.literal_eval(homo_matrix_str) # 直接转换为二维列表
reconstructed_matrix = np.array(matrix_list, dtype=float) reconstructed_matrix = np.array(matrix_list, dtype=float)
print("矩阵形状:", reconstructed_matrix.shape) # 应该是 (4, 4) # print("矩阵形状:", reconstructed_matrix.shape) # 应该是 (4, 4)
except (ValueError, SyntaxError) as e: except (ValueError, SyntaxError) as e:
print(f"解析错误: {e}") print(f"解析错误: {e}")
@ -215,7 +217,7 @@ class Platform:
if self.is_cross_border(x, y, z, model): if self.is_cross_border(x, y, z, model):
print(f"can_place False 1 cross_border {x}, {y}, {z}, {model}, {self.width}, {self.depth}, {self.height}") # print(f"can_place False 1 cross_border {x}, {y}, {z}, {model}, {self.width}, {self.depth}, {self.height}")
return False return False
# 碰撞检测(正确逻辑与间距处理) # 碰撞检测(正确逻辑与间距处理)
@ -230,7 +232,7 @@ class Platform:
y - my - extend_dist_model_y < py and y - my - extend_dist_model_y < py and
z < pz + pdz and z < pz + pdz and
z + mz > pz): z + mz > pz):
print("can_place False 2",False,model,x,y,z,px,pdx,extend_dist_model_x,py,pdy,extend_dist_model_y,my,pz,pdz,pz) # print("can_place False 2",False,model,x,y,z,px,pdx,extend_dist_model_x,py,pdy,extend_dist_model_y,my,pz,pdz,pz)
return False return False
return True return True
@ -256,7 +258,7 @@ class Platform:
model['position'] = (self.width - extend_dist_border_x_max, self.depth - extend_dist_border_y_max, 0) model['position'] = (self.width - extend_dist_border_x_max, self.depth - extend_dist_border_y_max, 0)
model['first_line'] = False model['first_line'] = False
print("model position1", model['name'], model['position']) # print("model position1", model['name'], model['position'])
self.placed_models.append(model) self.placed_models.append(model)
return True return True
@ -268,7 +270,7 @@ class Platform:
else: else:
px = pre_px - pre_mx - extend_dist_model_x px = pre_px - pre_mx - extend_dist_model_x
model['first_line'] = False model['first_line'] = False
print(model['name'], "px", px, pre_px, pre_mx) # print(model['name'], "px", px, pre_px, pre_mx)
reach_limit_x = False reach_limit_x = False
if self.first_line: if self.first_line:
@ -296,7 +298,7 @@ class Platform:
return False return False
model['position'] = (px, y, z) model['position'] = (px, y, z)
print("model position2", model['name'], model['position']) # print("model position2", model['name'], model['position'])
self.placed_models.append(model) self.placed_models.append(model)
return True return True
else: else:
@ -314,7 +316,7 @@ class Platform:
return False return False
model['position'] = (px, y, z) model['position'] = (px, y, z)
print("model position2", model['name'], model['position']) # print("model position2", model['name'], model['position'])
self.placed_models.append(model) self.placed_models.append(model)
return True return True

5
config.py

File diff suppressed because one or more lines are too long

10
download_print_out.py

@ -183,7 +183,7 @@ class DataTransfer:
new_name = f"{json_model_info.order_id}_{old_name}" new_name = f"{json_model_info.order_id}_{old_name}"
lines[i] = f"map_Kd {new_name}" lines[i] = f"map_Kd {new_name}"
mtllib_modified = True mtllib_modified = True
print(f"已更新材质库引用: {old_name} -> {new_name}") # print(f"已更新材质库引用: {old_name} -> {new_name}")
break # 找到第一个后立即退出 break # 找到第一个后立即退出
# 批量写入,减少I/O操作 [6](@ref) # 批量写入,减少I/O操作 [6](@ref)
@ -212,7 +212,7 @@ class DataTransfer:
prefix_exists = True prefix_exists = True
if obj.key != prefix: # 跳过目录本身 if obj.key != prefix: # 跳过目录本身
objects.append(obj.key) objects.append(obj.key)
print(f"obj.key={obj.key}") # print(f"obj.key={obj.key}")
if not prefix_exists: if not prefix_exists:
print(f"前缀 '{prefix}' 下没有找到任何文件或目录。") print(f"前缀 '{prefix}' 下没有找到任何文件或目录。")
@ -223,11 +223,11 @@ class DataTransfer:
# 下载所有文件,添加进度条 # 下载所有文件,添加进度条
for obj_key in tqdm(objects, desc="下载进度"): for obj_key in tqdm(objects, desc="下载进度"):
if obj_key.endswith('/'): if obj_key.endswith('/'):
print("下载 endswith('/'") # print("下载 endswith('/'")
continue continue
if "printId" in obj_key: if "printId" in obj_key:
print(f"下载 in obj_key") # print(f"下载 in obj_key")
continue continue
# 计算相对路径 # 计算相对路径
@ -311,7 +311,7 @@ class DataTransfer:
new_name = f"{batch_model_info.order_id}_{old_name}" new_name = f"{batch_model_info.order_id}_{old_name}"
lines[i] = f"map_Kd {new_name}" lines[i] = f"map_Kd {new_name}"
mtllib_modified = True mtllib_modified = True
print(f"已更新材质库引用: {old_name} -> {new_name}") # print(f"已更新材质库引用: {old_name} -> {new_name}")
break # 找到第一个后立即退出 break # 找到第一个后立即退出
# 批量写入,减少I/O操作 [6](@ref) # 批量写入,减少I/O操作 [6](@ref)

12
point_cloud_layout.py

@ -244,6 +244,8 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma
y_step=1 y_step=1
x_step=1 x_step=1
x_step_big = x_step * 2
y_step_big = y_step * 2
delta = 10 delta = 10
edge_x_min=0 + extend_dist_border_x_min edge_x_min=0 + extend_dist_border_x_min
@ -285,7 +287,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma
# is_first = 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 is_first = index >= len_first
if (is_first): if (is_first or True):
pcd_first.append(pcd) pcd_first.append(pcd)
else: else:
pcd_second.append(pcd) pcd_second.append(pcd)
@ -354,8 +356,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma
print("fail to place (x=0)", ply_file_name, dx) print("fail to place (x=0)", ply_file_name, dx)
dict_unplaced[name]=name dict_unplaced[name]=name
pcd_processed_curr = pcd_processed pcd_processed_curr = pcd_processed
x_step_big = x_step * 2
y_step_big = y_step * 2
collision_threshold_big = collision_threshold + 6 collision_threshold_big = collision_threshold + 6
y_init_big = 5 y_init_big = 5
if dx > 80: if dx > 80:
@ -599,10 +600,11 @@ 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 check_top_right = False
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]
name = dict_name[pcd]
obj_name = ply_file_name.split("=")[0]+".obj" obj_name = ply_file_name.split("=")[0]+".obj"
# print("pcd_second2", obj_name) # print("pcd_second2", obj_name)
@ -620,6 +622,7 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma
T_transTemp, tx, ty = move_to_top_right(pcd, edge_x_max, edge_y_max) T_transTemp, tx, ty = move_to_top_right(pcd, edge_x_max, edge_y_max)
check_top_right = False check_top_right = False
collision_threshold_init = collision_threshold+1
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 move_top_right",name,bbox['x_max'],bbox['y_max'],len(last_pcd_processed)) print("succ move_top_right",name,bbox['x_max'],bbox['y_max'],len(last_pcd_processed))
T_trans1 = T_transTemp @ T_trans1 T_trans1 = T_transTemp @ T_trans1
@ -636,7 +639,6 @@ def compact_mode_for_min_dis_json(placed_models,dict_unplaced,dict_bounds_fix,ma
T_trans1 = T_transTemp @ T_trans1 T_trans1 = T_transTemp @ T_trans1
name = dict_name[pcd]
# print("pcd_second2",name,"tx",tx,"ty",ty) # print("pcd_second2",name,"tx",tx,"ty",ty)
succ_move = True succ_move = True
y_accum = 0 y_accum = 0

2
print_factory_type_setting_obj_run.py

@ -143,7 +143,7 @@ def print_type_setting_obj(base_original_obj_dir=None,batch_id=0,selected_mode="
is_upload_result = True is_upload_result = True
if is_upload_result: if is_upload_result:
print(f"执行上 传-parent_dir={print_factory_type_dir},base_original_obj_dir={base_original_obj_dir},batch_id={batch_id}") print(f"执行上传: base_original_obj_dir={base_original_obj_dir}, batch_id={batch_id}")
upload_result(base_original_obj_dir, oss_config, batch_id) upload_result(base_original_obj_dir, oss_config, batch_id)

3
test_load_json.py

@ -301,7 +301,7 @@ def set_orthographic(meshes, width=1920, height=1080,
# vis.poll_events() # vis.poll_events()
# vis.update_renderer() # vis.update_renderer()
print("set_orthographic End") # print("set_orthographic End")
return vis return vis
@ -352,7 +352,6 @@ def render_to_texture(meshes, output_image_path):
# 保存带文字的图片 # 保存带文字的图片
image.save(output_image_path) image.save(output_image_path)
print(f"带文字的渲染图片已保存到: {output_image_path}")
except Exception as e: except Exception as e:
print(f"添加文字时出错: {e}") print(f"添加文字时出错: {e}")

Loading…
Cancel
Save