MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / __init__

Method __init__

python/pymesh/CSGTree.py:55–126  ·  view source on GitHub ↗

Args: tree: dictionary describing the csg tree

(self, tree)

Source from the content-addressed store, hash-verified

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")

Callers

nothing calls this directly

Calls 11

RuntimeErrorClass · 0.85
NotImplementedErrorClass · 0.85
create_leafMethod · 0.80
set_operand_1Method · 0.80
set_operand_2Method · 0.80
CSGTreeClass · 0.70
createMethod · 0.45
compute_unionMethod · 0.45
compute_intersectionMethod · 0.45
compute_differenceMethod · 0.45

Tested by

no test coverage detected