(mesh_1, mesh_2, operation, with_timing=False)
| 37 | return None |
| 38 | |
| 39 | def quick_csg(mesh_1, mesh_2, operation, with_timing=False): |
| 40 | exe_name = None |
| 41 | for suffix in ["mac", "linux", "win.exe"]: |
| 42 | exe_name = which("mesh_csg_{}".format(suffix)) |
| 43 | if exe_name is not None: |
| 44 | break |
| 45 | if exe_name is None: |
| 46 | raise NotImplementedError("Cannot find QuickCSG executable.") |
| 47 | |
| 48 | tmp_dir = tempfile.mkdtemp() |
| 49 | file_1 = os.path.join(tmp_dir, "mesh1.off") |
| 50 | file_2 = os.path.join(tmp_dir, "mesh2.off") |
| 51 | output_file = os.path.join(tmp_dir, "out.off") |
| 52 | |
| 53 | # Use anoymous to avoid QuickCSG parsing errors. |
| 54 | save_mesh(file_1, mesh_1, anonymous=True) |
| 55 | save_mesh(file_2, mesh_2, anonymous=True) |
| 56 | |
| 57 | op_flag = { |
| 58 | "union": "-union", |
| 59 | "intersection": "-inter", |
| 60 | "difference": "-diff 1", |
| 61 | "symmetric_difference": "-xor", |
| 62 | } |
| 63 | if operation not in op_flag: |
| 64 | raise NotImplementedError("Unsupported boolean operation: {}"\ |
| 65 | .format(operation)) |
| 66 | |
| 67 | command = "{} -tess3 {} -O {} {} {}".format( |
| 68 | exe_name, op_flag[operation], output_file, file_1, file_2) |
| 69 | if with_timing: |
| 70 | start_time = time() |
| 71 | check_call(command.split()) |
| 72 | if with_timing: |
| 73 | finish_time = time() |
| 74 | running_time = finish_time - start_time |
| 75 | |
| 76 | assert(os.path.exists(output_file)) |
| 77 | mesh = load_mesh(output_file) |
| 78 | |
| 79 | os.remove(file_1) |
| 80 | os.remove(file_2) |
| 81 | os.remove(output_file) |
| 82 | os.rmdir(tmp_dir) |
| 83 | |
| 84 | if with_timing: |
| 85 | return mesh, running_time |
| 86 | else: |
| 87 | return mesh |
nothing calls this directly
no test coverage detected