def create_arrows(self): magnitudes = norm(self.vector_field, axis=1) scale = self.max_length / np.amax(magnitudes) scaled_vectors = self.vector_field * scale magnitudes *= scale for v, p, l in zip(scaled_vectors, self.base_points, magnitudes): if l < 1e-6: continue arrow_scale = l / self.max_length c = self.color_map.get_color(l / self.max_length).color v = v / l if l < self.radius: if self.head_based: arrow_head = Cone(p - v * l, p, l * arrow_scale) else: arrow_head = Cone(p, p + v * l, l * arrow_scale) arrow_head.color = c self.primitives.append(arrow_head) else: if self.head_based: p2 = p - v * self.radius arrow_body = Cylinder(p2, p - v * l, self.stem_radius * arrow_scale) arrow_head = Cone(p2, p, self.radius * arrow_scale) else: p2 = p + v * (l - self.radius) arrow_body = Cylinder(p, p2, self.stem_radius * arrow_scale) arrow_head = Cone(p2, p + v * l, self.radius * arrow_scale) arrow_body.color = c arrow_head.color = c self.primitives.append(arrow_body) self.primitives.append(arrow_head)
def extract_texture_boundary(self): if self.boundary_color is None: color = color_table["black"]; elif self.boundary_color == "random": color = ColorMap("RdYlBu").get_color( random.choice([0.1, 0.3, 0.5, 0.7, 0.9])); else: assert(self.boundary_color in color_table); color = color_table[self.boundary_color]; radius = self.boundary_radius / self.scale; cutted_mesh = pymesh.cut_mesh(self.mesh); bd_edges = cutted_mesh.boundary_edges; vertices = cutted_mesh.vertices; for e in bd_edges: v0 = vertices[e[0]]; v1 = vertices[e[1]]; assert(np.all(np.isfinite(v0))); assert(np.all(np.isfinite(v1))); if numpy.linalg.norm(v0 - v1) <= radius: continue; cylinder = Cylinder(v0, v1, radius); cylinder.color = color; self.primitives.append(cylinder); bd_vertices = np.unique(bd_edges.ravel()); for v in bd_vertices: ball = Sphere(vertices[v,:], radius); ball.color = color; self.primitives.append(ball);
def extract_texture_boundary(self): if self.boundary_color is None: color = get_color("black") elif self.boundary_color == "random": color = ColorMap("RdYlBu").get_color( random.choice([0.1, 0.3, 0.5, 0.7, 0.9])) else: color = get_color(self.boundary_color) radius = self.boundary_radius / self.scale cutted_mesh = pymesh.cut_mesh(self.mesh) bd_edges = cutted_mesh.boundary_edges vertices = cutted_mesh.vertices for e in bd_edges: v0 = vertices[e[0]] v1 = vertices[e[1]] assert (np.all(np.isfinite(v0))) assert (np.all(np.isfinite(v1))) if numpy.linalg.norm(v0 - v1) <= radius: continue cylinder = Cylinder(v0, v1, radius) cylinder.color = color self.primitives.append(cylinder) bd_vertices = np.unique(bd_edges.ravel()) for v in bd_vertices: ball = Sphere(vertices[v, :], radius) ball.color = color self.primitives.append(ball)
def extract_texture_boundary(self): if self.boundary_color is None: color = color_table["black"] elif self.boundary_color == "random": color = ColorMap("RdYlBu").get_color( random.choice([0.1, 0.3, 0.5, 0.7, 0.9])) else: assert (self.boundary_color in color_table) color = color_table[self.boundary_color] vertices = self.mesh.vertices faces = self.mesh.faces uv = self.texture_coordinates num_faces, vertex_per_face = faces.shape assert (len(uv) == num_faces * vertex_per_face) uv_faces = np.arange(len(uv), dtype=int).reshape((-1, vertex_per_face)) mesh = pymesh.form_mesh(uv, uv_faces) mesh, info = pymesh.remove_duplicated_vertices(mesh) index_map = info["index_map"] input_vertex_index = faces.ravel() output_vertex_index = np.ones(mesh.num_vertices, dtype=int) * -1 output_vertex_index[index_map] = input_vertex_index assert (np.all(output_vertex_index >= 0)) radius = self.boundary_radius / self.scale bd_edges = output_vertex_index[mesh.boundary_edges] for e in bd_edges: v0 = vertices[e[0]] v1 = vertices[e[1]] assert (np.all(np.isfinite(v0))) assert (np.all(np.isfinite(v1))) if numpy.linalg.norm(v0 - v1) <= radius: continue cylinder = Cylinder(v0, v1, radius) cylinder.color = color self.primitives.append(cylinder) bd_vertices = np.unique(bd_edges.ravel()) for v in bd_vertices: ball = Sphere(vertices[v, :], radius) ball.color = color self.primitives.append(ball)
def generate_primitives(self): if self.mesh.num_faces <= 0: return; self.primitives = []; d = norm(self.bmax - self.bmin) / math.sqrt(self.mesh.dim); radius = d * self.line_width; assert(radius > 0); vertices, edges = pymesh.mesh_to_graph(self.mesh); lengths = norm(vertices[edges[:,0],:] - vertices[edges[:,1],:], axis=1); color = color_table["dark_gray"]; for v in vertices: ball = Sphere(v, radius); ball.color = color; self.primitives.append(ball); for e,l in zip(edges, lengths): if l <= 0.5 * radius : continue; cylinder = Cylinder(vertices[e[0]], vertices[e[1]], radius); cylinder.color = color; self.primitives.append(cylinder);
def generate_primitives(self): if self.mesh.num_faces <= 0: return self.primitives = [] d = norm(self.bmax - self.bmin) / math.sqrt(self.mesh.dim) radius = d * self.line_width assert (radius > 0) vertices, edges = pymesh.mesh_to_graph(self.mesh) lengths = norm(vertices[edges[:, 0], :] - vertices[edges[:, 1], :], axis=1) color = get_color(self.line_color) for v in vertices: ball = Sphere(v, radius) ball.color = color self.primitives.append(ball) for e, l in zip(edges, lengths): if l <= 0.5 * radius: continue cylinder = Cylinder(vertices[e[0]], vertices[e[1]], radius) cylinder.color = color self.primitives.append(cylinder)
def generate_primitives(self): if self.color_name is None: self.color = get_color("nylon_white") elif self.color_name == "random": self.color = ColorMap("RdYlBu").get_color( random.choice([0.1, 0.3, 0.5, 0.7, 0.9])) else: self.color = get_color(self.color_name) self.wires.add_attribute("edge_length") vertices = self.wires.vertices edges = self.wires.edges lengths = self.wires.get_attribute("edge_length") for v in vertices: ball = Sphere(v, self.radius) ball.color = self.color self.primitives.append(ball) for e, l in zip(edges, lengths): if l <= 0.1 * self.radius: continue cylinder = Cylinder(vertices[e[0]], vertices[e[1]], self.radius) cylinder.color = self.color self.primitives.append(cylinder)