示例#1
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);
示例#2
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)
示例#3
0
    def generate_primitives(self):
        assert (len(self.scalar_field) == len(self.base_points))
        assert (self.radius_range[1] > self.radius_range[0])

        #self.__cluster_points();

        # hide actual mesh
        color = self.vertex_colors
        if len(color) > 0:
            color[:, :, -1] = 0.0
        self.vertex_colors = color

        min_val = np.amin(self.scalar_field)
        max_val = np.amax(self.scalar_field)
        radius_gap = self.radius_range[1] - self.radius_range[0]
        value_gap = max_val - min_val
        for value, base in zip(self.scalar_field, self.base_points):
            if value_gap > 0:
                ratio = (value - min_val) / value_gap
            else:
                ratio = 0.0
            radius = self.radius_range[0] + ratio * radius_gap
            if radius > 1e-6:
                ball = Sphere(base, radius)
                ball.color = self.color_map.get_color(ratio).color
                self.primitives.append(ball)
示例#4
0
    def generate_primitives(self):
        assert(len(self.scalar_field) == len(self.base_points));
        assert(self.radius_range[1] > self.radius_range[0]);

        #self.__cluster_points();

        # hide actual mesh
        color = self.vertex_colors;
        if len(color) > 0:
            color[:,:,-1] = 0.0;
        self.vertex_colors = color;

        min_val = np.amin(self.scalar_field) if self.bounds[0] is None else self.bounds[0];
        max_val = np.amax(self.scalar_field) if self.bounds[1] is None else self.bounds[1];
        radius_gap = self.radius_range[1] - self.radius_range[0];
        value_gap = max_val - min_val;
        for value, base in zip(self.scalar_field, self.base_points):
            if value_gap > 0:
                ratio = (value - min_val) / value_gap;
            else:
                ratio = 0.0;
            radius = self.radius_range[0] + ratio * radius_gap;
            if radius > 1e-6:
                ball = Sphere(base, radius);
                ball.color = self.color_map.get_color(ratio).color;
                self.primitives.append(ball);
示例#5
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]

        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)
示例#6
0
    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);
示例#7
0
    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)
示例#8
0
    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)