Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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 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):
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:
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;
mesh = pymesh.form_mesh(self.view.vertices, np.array([]),
self.view.voxels);
mesh.add_attribute("voxel_centroid");
mesh.add_attribute("voxel_face_index");
voxel_face_id = mesh.get_voxel_attribute("voxel_face_index").astype(int);
centroids = mesh.get_voxel_attribute("voxel_centroid");
self.V_to_keep = [should_keep(v) for v in centroids];
voxels_to_keep = self.view.voxels[self.V_to_keep];
voxel_face_id = voxel_face_id[self.V_to_keep];
self.mesh = pymesh.form_mesh(self.view.vertices, np.zeros((0,3)), voxels_to_keep);
self.mesh.add_attribute("voxel_face_index");
new_voxel_face_id = self.mesh.get_voxel_attribute("voxel_face_index").astype(int);
old_vertex_colors = self.vertex_colors;
new_vertex_colors = np.zeros((self.mesh.num_faces, 3, 4));
cut_color = get_color(interior_color);
cut_color = np.array([cut_color.red, cut_color.green,
cut_color.blue, cut_color.alpha]);
is_interface = np.zeros(self.mesh.num_faces, dtype=bool);
for old_i,new_i in zip(voxel_face_id.ravel(), new_voxel_face_id.ravel()):
if new_i >= 0 and old_i >= 0:
new_vertex_colors[new_i] = old_vertex_colors[old_i];
elif new_i >= 0:
is_interface[new_i] = True;
new_vertex_colors[new_i,:] = cut_color;
self.vertex_colors = new_vertex_colors;
self.interface = pymesh.form_mesh(self.mesh.vertices,
self.mesh.faces[is_interface]);
self.boundary = pymesh.form_mesh(self.mesh.vertices,
self.mesh.faces[np.logical_not(is_interface)]);
self.interface, __ = pymesh.remove_isolated_vertices(self.interface);
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;