Browse Source

调c进行isosurfing

final
mckay 2 months ago
parent
commit
d5ac19e093
  1. 66
      brep2sdf/IsoSurfacing.py

66
brep2sdf/IsoSurfacing.py

@ -0,0 +1,66 @@
import os
import subprocess
from tqdm import tqdm
# 使用一个 c++ 程序处理,这里只是调用,注意要在docker里面运行。宿主机编译失败
def main():
# 定义 STEP 文件目录和名称列表文件路径
output_data_root_dir = "/workspace/home/wch/brep2sdf/data/output_data"
name_list_path = "/workspace/home/wch/brep2sdf/data/name_list.txt"
# 读取名称列表
try:
with open(name_list_path, 'r') as f:
names = [line.strip() for line in f if line.strip()] # 去除空行
except FileNotFoundError:
print(f"Error: File '{name_list_path}' not found.")
return
except Exception as e:
print(f"Error reading file '{name_list_path}': {e}")
return
# 遍历名称列表并处理每个 STEP 文件
for name in tqdm(names, desc="ISOsurfing pt files"):
pt_file = os.path.join(output_data_root_dir, f"{name}.pt")
if not pt_file:
print(f"Warning: No pt files found in directory '{output_data_root_dir}'. Skipping...")
continue
# ./ISG_console_pytorch -i ./test/teaser.pt -o outputmesh.ply -v -0.01 -d 8
# 构造子进程命令
command = [
"python", "/workspace/home/wch/brep2sdf/data/scripts/IsoSurfacing/build/App/console_pytorch/ISG_console_pytorch",
"-i", pt_file, # 使用当前遍历的pt文件
"-o", os.path.join(output_data_root_dir, f"{name}_outputmesh.ply"), # 动态生成输出文件路径
"-v", "-0.01", "-d", "8"
]
# 调用子进程运行命令
try:
result = subprocess.run(
command,
capture_output=True,
text=True,
check=True # 如果返回非零退出码,则抛出 CalledProcessError
)
print(f"Successfully processed '{name}'")
print("STDOUT:", result.stdout)
print("STDERR:", result.stderr)
except subprocess.CalledProcessError as e:
print(f"Error processing '{name}': Command failed with return code {e.returncode}")
print(f"Command: {e.cmd}")
print(f"Error type: {type(e).__name__}")
print("STDOUT:", e.stdout)
print("STDERR:", e.stderr)
print("Traceback:", e.__traceback__)
except Exception as e:
print(f"Unexpected error processing '{name}': {str(e)}")
print(f"Command: {command}")
print("Traceback:", traceback.format_exc())
if __name__ == '__main__':
main()
Loading…
Cancel
Save