def vertex_colors(self): """ Return corner field. One vector per face corner. """ if self.color_name == "random": c = ColorMap("RdYlBu").get_color( random.choice([0.1, 0.3, 0.5, 0.7, 0.9])) elif self.color_name is not None: c = get_color(self.color_name) else: c = get_color("nylon_white") c.color[-1] = self.alpha colors = np.array([[c.color] * self.mesh.vertex_per_face] * self.mesh.num_faces) return colors
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.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)
def color_map(self, val): self.__color_map = ColorMap(val)