def foam_graph_to_mesh(k_foam, thickness): V, E = k_foam.vertices, k_foam.edges V_ = [] E_ = [] dups = [] for v in V: V_.append(10 * np.array(v)) nv = E[v] for ni in nv: if (ni, v) in dups: continue E_.append(np.array([V.index(v), V.index(ni)])) dups.append((ni, v)) dups.append((v, ni)) V_, E_ = np.array(V_), np.array(E_) wire_network = WireNetwork().create_from_data(V_, E_) wire_network.center_at_origin() wire_network.compute_symmetry_orbits() inflator = Inflator(wire_network) inflator.inflate(thickness, allow_self_intersection=True, per_vertex_thickness=False) return inflator.mesh
def generate_supports(wire_network, print_dir, support_length, support_thickness, tol): min_height = np.amin(np.dot(wire_network.vertices, print_dir)); proj_dist = []; vertices = []; edges = []; for i,v in enumerate(wire_network.vertices): neighbors = wire_network.vertices[wire_network.get_vertex_neighbors(i)]; neighbors = neighbors.reshape((-1, 3), order="C"); h = np.dot(v, print_dir); if np.any(np.dot(neighbors, print_dir) <= h + tol) and h > min_height + tol: continue; vertices.append(v); proj_dist.append(h); num_supports = len(vertices); base_vertices_top_end = vertices - print_dir * support_thickness; base_vertices_bottom_end = vertices - np.outer( (proj_dist - min_height + support_length), print_dir); vertices = np.vstack((vertices + 0.05 * print_dir, base_vertices_top_end, base_vertices_bottom_end)); edges = np.vstack(( np.arange(num_supports * 2).reshape((num_supports, 2), order="F"), np.arange(num_supports, num_supports * 3).reshape((num_supports, 2), order="F"))); thickness = np.hstack(( np.ones(num_supports) * support_thickness * 0.5, np.ones(num_supports) * support_thickness, np.ones(num_supports) * support_thickness,)); support_wires = WireNetwork(); support_wires.load(vertices, edges); support_wires.add_attribute("thickness", thickness); return support_wires;
def load_wire(wire_file): network = WireNetwork(); network.load_from_file(wire_file); return network;
def load_wire(wire_file): network = WireNetwork() network.load_from_file(wire_file) return network