File size: 4,265 Bytes
92f98bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import os
import numpy as np
from translateLdr import process_ldr, getmin_ldr

max_x, max_y, max_z = float('-inf'), float('-inf'), float('-inf')
all_coordinates = []  

root_dir = '/public/home/wangshuo/gap/assembly/data/car_1k/subset_bottom_300/ldr_rot_expand_test'  # 替换为你的根目录路径
output_dir = '/public/home/wangshuo/gap/assembly/data/car_1k/subset_bottom_300/ldr_rot_expand_trans_test'
#import ipdb; ipdb.set_trace()
sorted_files = sorted(os.listdir(root_dir), key=lambda x: int(x.split('_')[1]))
# 遍历根目录下的每个文件夹
for file_name in sorted_files:
    #file_name = 'car_5_rot.ldr'
    if file_name == 'car_1627_rot.ldr':
        continue
    original_file_path = os.path.join(root_dir, file_name)

    if os.path.exists(original_file_path):
        # 打开并读取原始 LDR 文件
        with open(original_file_path, "r") as file:
            lines = file.readlines()

        # if len(lines) > 310:
        #     continue
        # 初始化最小坐标值
        #min_x, min_y, min_z = float('inf'), float('inf'), float('inf')

        # # 第一遍遍历文件找到最小坐标值
        # for line in lines:
        #     parts = line.split()  # 按空格分割行数据
        #     if len(parts) == 15:  # 检查是否为零件数据行
        #         # 提取 x, y, z 坐标
        #         x, y, z = float(parts[2]), float(parts[3]), float(parts[4])

        #         # 更新最小坐标值
        #         min_x = min(min_x, x)
        #         min_y = min(min_y, y)
        #         min_z = min(min_z, z)
        min_x, min_y, min_z = getmin_ldr(original_file_path)
        #print(file_name)
        x_new, y_new, z_new = process_ldr(original_file_path, os.path.join(output_dir, f'modified_{file_name}'), -min_x, -min_y, -min_z, False)
        all_coordinates.append([round(x_new), round(y_new), round(z_new)])

        #if x_new > 200 or y_new > 150 or z_new > 500:
        if x_new > 200:
            print(file_name)
            print(f"Maximum coordinates found this LDR files:")
            print(f"Max X: {x_new}")
            print(f"Max Y: {y_new}")
            print(f"Max Z: {z_new}")
        
        max_x = max(max_x, x_new)
        max_y = max(max_y, y_new)
        max_z = max(max_z, z_new)



        #import ipdb; ipdb.set_trace()
            # # 新的 LDR 文件内容
            # new_lines = []

            # # 第二遍遍历文件,更新坐标
            # for line in lines:
            #     parts = line.split()  # 按空格分割行数据
            #     if len(parts) == 15:  # 检查是否为零件数据行
            #         # 提取 x, y, z 坐标
            #         x, y, z = float(parts[2]), float(parts[3]), float(parts[4])

            #         # 计算新的坐标
            #         x_new = round(x - min_x)
            #         y_new = round(y - min_y)
            #         z_new = round(z - min_z)

            #         # 更新坐标
            #         parts[2] = str(x_new)
            #         parts[3] = str(y_new)
            #         parts[4] = str(z_new)

            #         max_x = max(max_x, x_new)
            #         max_y = max(max_y, y_new)
            #         max_z = max(max_z, z_new)

            #         # 将修改后的行添加到新文件内容中
            #         new_lines.append(" ".join(parts) + "\n")
            #     else:
            #         # 如果是非零件行,直接添加到新文件中
            #         new_lines.append(line)

            # # 设置新的 LDR 文件路径
            # modified_file_path = os.path.join(folder_path, f'modified_{folder_name}.ldr')

            # # 将修改后的内容写入新的 LDR 文件
            # with open(modified_file_path, "w") as file:
            #     file.writelines(new_lines)

            # print(f"LDR file '{original_file_path}' has been modified and saved as '{modified_file_path}'")
coordinates_array = np.array(all_coordinates, dtype=np.int32)
output_npy_path = os.path.join(os.path.dirname(output_dir), 'all_coordinates_test.npy')
np.save(output_npy_path, coordinates_array)

print(f"Maximum coordinates found across all LDR files:")
print(f"Max X: {max_x}")
print(f"Max Y: {max_y}")
print(f"Max Z: {max_z}")