Args: tree: dictionary describing the csg tree
(self, tree)
| 53 | >>> mesh = tree.mesh |
| 54 | """ |
| 55 | def __init__(self, tree): |
| 56 | """ |
| 57 | Args: |
| 58 | tree: dictionary describing the csg tree |
| 59 | |
| 60 | """ |
| 61 | |
| 62 | if isinstance(tree, CSGTree): |
| 63 | self.tree = tree.tree |
| 64 | elif "mesh" in tree: |
| 65 | # leaf case |
| 66 | mesh = tree["mesh"] |
| 67 | self.tree = PyMesh.CSGTree.create_leaf("igl", |
| 68 | mesh.vertices, mesh.faces) |
| 69 | elif "union" in tree: |
| 70 | num_operands = len(tree["union"]) |
| 71 | if num_operands == 1: |
| 72 | self.tree = CSGTree(tree["union"][0]).tree |
| 73 | elif num_operands == 2: |
| 74 | children = [ CSGTree(subtree) for subtree in tree["union"] ] |
| 75 | self.tree = PyMesh.CSGTree.create("igl") |
| 76 | self.tree.set_operand_1(children[0].tree) |
| 77 | self.tree.set_operand_2(children[1].tree) |
| 78 | self.tree.compute_union() |
| 79 | elif num_operands > 2: |
| 80 | mid = num_operands // 2 |
| 81 | child1 = CSGTree({"union": tree["union"][:mid]}) |
| 82 | child2 = CSGTree({"union": tree["union"][mid:]}) |
| 83 | self.tree = PyMesh.CSGTree.create("igl") |
| 84 | self.tree.set_operand_1(child1.tree) |
| 85 | self.tree.set_operand_2(child2.tree) |
| 86 | self.tree.compute_union() |
| 87 | else: |
| 88 | raise RuntimeError("No operand provided for union operation") |
| 89 | elif "intersection" in tree: |
| 90 | num_operands = len(tree["intersection"]) |
| 91 | if num_operands == 1: |
| 92 | self.tree = CSGTree(tree["intersection"][0]).tree |
| 93 | elif num_operands == 2: |
| 94 | children = [ CSGTree(subtree) for subtree in tree["intersection"] ] |
| 95 | self.tree = PyMesh.CSGTree.create("igl") |
| 96 | self.tree.set_operand_1(children[0].tree) |
| 97 | self.tree.set_operand_2(children[1].tree) |
| 98 | self.tree.compute_intersection() |
| 99 | elif num_operands > 2: |
| 100 | mid = num_operands // 2 |
| 101 | child1 = CSGTree({"intersection": tree["intersection"][:mid]}) |
| 102 | child2 = CSGTree({"intersection": tree["intersection"][mid:]}) |
| 103 | self.tree = PyMesh.CSGTree.create("igl") |
| 104 | self.tree.set_operand_1(child1.tree) |
| 105 | self.tree.set_operand_2(child2.tree) |
| 106 | self.tree.compute_intersection() |
| 107 | else: |
| 108 | raise RuntimeError("No operand provided for intersection operation") |
| 109 | elif "difference" in tree: |
| 110 | children = [ CSGTree(subtree) for subtree in tree["difference"] ] |
| 111 | assert(len(children) == 2) |
| 112 | self.tree = PyMesh.CSGTree.create("igl") |
nothing calls this directly
no test coverage detected