Exemple #1
0
def write_to_pov(P):
    """
    Write the data of a polytope to a POV-Ray include file for rendering.

    :param P: a polytope instance.
    """
    if isinstance(P, Catalan3D):
        vert_macros = "\n".join(VERT_MACRO.format(i, v + sum(len(vlist) for vlist in P.vertex_coords[:i]))
                                for i, vlist in enumerate(P.vertex_coords)
                                for v in range(len(vlist)))
        face_macros = "\n".join(FACE_MACRO.format(0, len(face), helpers.pov_array(face))
                                for face in P.face_indices)
        vertex_coords = helpers.pov_vector_list(P.vertex_coords_flatten)
    else:
        vert_macros = "\n".join(VERT_MACRO.format(0, i) for i in range(P.num_vertices))
        face_macros = "\n".join(FACE_MACRO.format(i, len(face), helpers.pov_array(face))
                                for i, flist in enumerate(P.face_indices)
                                for face in flist)
        vertex_coords = helpers.pov_vector_list(P.vertex_coords)

    edge_macros = "\n".join(EDGE_MACRO.format(i, e[0], e[1])
                            for i, elist in enumerate(P.edge_indices)
                            for e in elist)

    with open("./povray/polyhedra-data.inc", "w") as f:
        f.write(POV_TEMPLATE.format(
            P.num_vertices,
            P.num_vertices,
            vertex_coords,
            vert_macros,
            edge_macros,
            face_macros))
Exemple #2
0
    def export_pov(self, filename="./povray/polychora-data.inc"):
        vstr = "Vertex({})\n"
        estr = "Edge({}, {})\n"

        extent = np.max(
            [np.linalg.norm(helpers.proj3d(v)) for v in self.vertex_coords])

        with open(filename, "w") as f:
            f.write("#declare extent = {};\n".format(extent))

            for v in self.vertex_coords:
                f.write(vstr.format(helpers.pov_vector(v)))

            for i, edge_list in enumerate(self.edge_coords):
                for edge in edge_list:
                    f.write(estr.format(i, helpers.pov_vector_list(edge)))

            for i, face_list in enumerate(self.face_coords):
                for face in face_list:
                    isplane, center, radius, facesize = helpers.get_sphere_info(
                        face)
                    f.write(helpers.pov_array(face))
                    f.write(
                        helpers.export_face(i, face, isplane, center, radius,
                                            facesize))
def write_to_pov(P,
                 camera=(0, 0, 180),
                 rotation=(0, 0, 0),
                 vertex_size=0.04,
                 edge_size=0.02,
                 size_func=0,
                 face_index=[0],
                 face_max=3,
                 face_min=0.5):
    """Write the data of a polytope `P` to the include file.

    :param camera: camera location.

    :param rotation: rotation angles (in degree) of the polytope.

    :param vertex_size: controls size of the vertices.

    :param edge_size: controls size of the edges.

    :param size_func: choose which way to adjust the size of the edges.
        currently there are three choices, so it can only be 0-2.

    :param face_index: controls which type of faces are rendered,
        must be a list of integers.

    :param face_max: faces larger than this value will not be rendered.

    :param face_min: faces smaller than this value will not be rendered.
    """
    with open("./povray/polychora-data.inc", "w") as f:
        extent = max(np.linalg.norm(helpers.proj3d(v)) for v in P.vertex_coords)
        vert_macros = "\n".join(VERT_MACRO.format(k) for k in range(P.num_vertices))
        edge_macros = "\n".join(EDGE_MACRO.format(i, e[0], e[1])
                                for i, elist in enumerate(P.edge_indices)
                                    for e in elist)
        face_macros = "\n".join(helpers.export_face(i, face)
                                for i, flist in enumerate(P.face_coords)
                                    for face in flist)
        f.write(POV_TEMPLATE.format(
            vertex_size,
            edge_size,
            helpers.pov_vector(camera),
            helpers.pov_vector(rotation),
            extent,
            P.num_vertices,
            helpers.pov_vector_list(P.vertex_coords),
            size_func,
            face_max,
            face_min,
            helpers.pov_array(face_index),
            vert_macros,
            edge_macros,
            face_macros)
            )
Exemple #4
0
    def export_pov(self, filename="./povray/polyhedra-data.inc"):
        vstr = "Vertex({})\n"
        estr = "Edge({}, {})\n"
        fstr = "Face({}, {}, vertices_list)\n"
        with open(filename, "w") as f:
            for v in self.vertex_coords:
                f.write(vstr.format(helpers.pov_vector(v)))

            for i, edge_list in enumerate(self.edge_coords):
                for edge in edge_list:
                    f.write(estr.format(i, helpers.pov_vector_list(edge)))

            for i, face_list in enumerate(self.face_coords):
                for face in face_list:
                    f.write(helpers.pov_array(face))
                    f.write(fstr.format(i, len(face)))
def render(T):
    vertex_coords = helpers.pov_vector_list(T.vertices_coords)
    vert_macros = "\n".join(
        VERT_MACRO.format(i) for i in range(T.num_vertices))
    edge_macros = "\n".join(
        EDGE_MACRO.format(i, e[0], e[1])
        for i, elist in T.edge_indices.items() for e in elist)
    face_macros = "\n".join(
        FACE_MACRO.format((i + j) % 3, len(face), helpers.pov_array(face))
        for (i, j), flist in T.face_indices.items() for face in flist)

    with open("./povray/polyhedra-data.inc", "w") as f:
        f.write(
            POV_TEMPLATE.format(T.num_vertices, T.num_vertices, vertex_coords,
                                vert_macros, edge_macros, face_macros))

    subprocess.call(POV_COMMAND, shell=True)
Exemple #6
0
def write_to_pov(P, glass_tex, face_index, vertex_color, edge_color):
    """Write the data of a polytope to a POV-Ray include file for rendering.

    :param P: a polytope instance.

    :param glass_tex: glass texture defined in POV-Ray's "textures.inc".

    :param face_index: controls which type of faces are rendered.
        This input can be either an integer or a list/tuple of integers,
        for example if face_index=1 then the second list of faces will be
        rendered, or if face_index=(0, 1) then the first and second lists
        of faces will be rendered.

    :param vertex_color && edge_color: colors defined in POV-Ray's "colors.inc".
    """
    vert_macros = "\n".join(VERT_MACRO.format(i, vertex_color) for i in range(P.num_vertices))
    edge_macros = "\n".join(EDGE_MACRO.format(e[0], e[1], edge_color) for elist in P.edge_indices for e in elist)

    faces = []
    for i, flist in enumerate(P.face_indices):
        try:
            if (face_index == "all" or i == face_index or i in face_index):
                faces += flist
        except:
            pass

    face_macros = "\n".join(FACE_MACRO.format(len(face), helpers.pov_array(face), glass_tex) for face in faces)

    with open("./povray/polychora-data.inc", "w") as f:
        f.write(POV_TEMPLATE.format(
            vertex_color,
            edge_color,
            P.num_vertices,
            P.num_vertices,
            helpers.pov_vector_list(P.vertex_coords),
            vert_macros,
            edge_macros,
            face_macros
            )
        )