示例#1
0
    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)
示例#2
0
    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);
示例#3
0
def solve_heat_equation(mesh):
    cell_ids = mesh.get_attribute("cell").ravel().astype(int)
    cut_mesh = pymesh.cut_mesh(mesh, cell_ids)

    tree = pymesh.AABBTree2()
    tree.load_data(cut_mesh.vertices, cut_mesh.boundary_edges)
    sq_dist, indices = tree.look_up(mesh.vertices)

    mesh.add_attribute("sq_dist")
    mesh.set_attribute("sq_dist", sq_dist)

    return mesh
示例#4
0
def solve_heat_equation(mesh):
    cell_ids = mesh.get_attribute("cell").ravel().astype(int);
    cut_mesh = pymesh.cut_mesh(mesh, cell_ids);

    tree = pymesh.AABBTree2();
    tree.load_data(cut_mesh.vertices, cut_mesh.boundary_edges);
    sq_dist, indices = tree.look_up(mesh.vertices);

    mesh.add_attribute("sq_dist");
    mesh.set_attribute("sq_dist", sq_dist);

    return mesh;
示例#5
0
def compute_metric(mesh):
    if mesh.has_attribute("cell"):
        cell_ids = mesh.get_attribute("cell").astype(int).ravel();
        cut_mesh = pymesh.cut_mesh(mesh, cell_ids);
    else:
        cut_mesh = mesh;

    tree = pymesh.AABBTree2();
    tree.load_data(cut_mesh.vertices, cut_mesh.boundary_edges);
    sq_dist, indices = tree.look_up(mesh.vertices);
    dist = np.sqrt(sq_dist);

    bbox_min, bbox_max = mesh.bbox;
    tol = norm(bbox_max - bbox_min) / 20.0;

    metric = np.clip(dist / tol, 0.1, 1.0) * tol;
    return metric;
示例#6
0
def compute_metric(mesh):
    if mesh.has_attribute("cell"):
        cell_ids = mesh.get_attribute("cell").astype(int).ravel()
        cut_mesh = pymesh.cut_mesh(mesh, cell_ids)
    else:
        cut_mesh = mesh

    tree = pymesh.AABBTree2()
    tree.load_data(cut_mesh.vertices, cut_mesh.boundary_edges)
    sq_dist, indices = tree.look_up(mesh.vertices)
    dist = np.sqrt(sq_dist)

    bbox_min, bbox_max = mesh.bbox
    tol = norm(bbox_max - bbox_min) / 20.0

    metric = np.clip(dist / tol, 0.1, 1.0) * tol
    return metric
示例#7
0
def main():
    args = parse_args()
    mesh = pymesh.load_mesh(args.input_mesh)
    if not mesh.has_attribute("corner_texture"):
        raise RuntimeError("Mesh contains no uv!")

    mesh.add_attribute("face_area")
    cutted_mesh = pymesh.cut_mesh(mesh)

    uvs = cutted_mesh.get_attribute("corner_texture").reshape((-1, 2))
    faces = cutted_mesh.faces
    per_vertex_uv = np.ndarray((cutted_mesh.num_vertices, 2))
    per_vertex_uv[faces.ravel(order="C")] = uvs

    if not args.save_uv:
        cutted_mesh.add_attribute("u")
        cutted_mesh.set_attribute("u", per_vertex_uv[:, 0])
        cutted_mesh.add_attribute("v")
        cutted_mesh.set_attribute("v", per_vertex_uv[:, 1])
        pymesh.save_mesh(args.output_mesh, cutted_mesh, "u", "v")
    else:
        uv_mesh = pymesh.form_mesh(per_vertex_uv, faces)
        pymesh.save_mesh(args.output_mesh, uv_mesh)