Пример #1
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))
Пример #2
0
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)
            )
Пример #3
0
def write_to_pov(P):
    with open("./povray/120-cell-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(e[0], e[1]) for elist in 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(extent, P.num_vertices,
                                helpers.pov_vector_list(P.vertex_coords),
                                vert_macros, edge_macros, face_macros))