Ejemplo n.º 1
0
def rdmb_povray_color(file_base,
                      time_point=2000,
                      width=800, height=600,
                      rotx=0, roty=0, rotz=0,
                      angle=14,
                      mode="C"):
    """Render and save RD results using Pov-Ray (color)

    Render and save RD results using Pov-Ray
    with color indicating parameter values

    Args:
        file_base:
        time_point:
        width, height:
        rotx, roty, rotz:
        angle:
        mode:
        
    """

    vs, ucs, As, Cs = load_rd_mb(file_base)
    
    file_png = file_base + "_color_{:05}.png".format(time_point)
    
    tempfile = file_png[:-4] + "__temp__" + ".pov"

    camera = Camera('location', [0, 0, -25],
                    'look_at', [0, 0, 0],
                    'angle', angle,
                    'right x*image_width/image_height')
    
    light = LightSource([-3, 2, -6],
                        'color', [1.0, 1.0, 1.0], 'parallel')
    light2 = LightSource([2, -2, -6],
                         'color', [0.2, 0.2, 0.2], 'parallel')
    background = Background('color', [1, 1, 1, 1])
    
    spheres = []
    spheres +=  sph(vs, ucs, As, Cs,
                    0, 0, 0,
                    rotx=rotx, roty=roty, rotz=rotz,
                    mode=mode)
    
    objects = [light, light2, background] + spheres
    
    scene = Scene(camera, objects=objects)
    
    scene.render(file_png,
                 width=width, height=height,
                 tempfile=tempfile,
                 output_alpha=True, antialiasing=0.001)

    return file_png
Ejemplo n.º 2
0
def main():
    lookfrom = (13 / 1.5, 2 / 1.5, -5 / 1.5)
    lookat = (0, 0, 0)
    # dist_to_focus = 10.0
    # aperture = 0.1
    step = 1
    # camera
    camera = Camera('location', lookfrom, 'look_at', lookat)

    # background
    light = LightSource((0, 20, 0), 'color', (1, 1, 1))
    bg = Background('color', (0.5, 0.7, 1.0))
    base = Sphere((0, -1000, 0), 1000,
                  Texture(Pigment('color', (0.5, 0.5, 0.5))))
    htlist = [bg, base, light]
    for a in range(-11, 11, step):
        for b in range(-11, 11, step):
            choose_mat = random.random()
            center = (a + 0.9 * random.random(),
                      0.2, b + 0.9 * random.random())
            if distance(center, (4, 0.2, 0)) < 0.9:
                continue
            if choose_mat < 0.8:
                # diffuse
                color = (random.random() * random.random(),
                         random.random() * random.random(),
                         random.random() * random.random())
                htlist.append(
                    Sphere(center, 0.2, Texture(Finish('diffuse', 1), Pigment('color', color))))
            elif choose_mat < 0.95:
                # metal
                color = (0.5 * (1 + random.random()),
                         0.5 * (1 + random.random()),
                         0.5 * (1 + random.random()))
                # p1 = 0.5 * random.random()
                htlist.append(
                    Sphere(center, 0.2, Texture(Finish('Metal'), Pigment('color', color))))
            else:
                # glass
                htlist.append(Sphere(center, 0.2, Material('M_Glass')))

    # main 3 sphere
    htlist.append(
        Sphere((0, 1, 0), 1.0, Material('M_Glass')))
    htlist.append(
        Sphere((-4, 1, 0), 1.0, Texture(Finish('diffuse', 1), Pigment('color', (0.4, 0.2, 0.2)))))
    htlist.append(Sphere((4, 1, 0), 1.0, Texture('Chrome_Texture')))
    scene = Scene(camera, objects=htlist, included=[
                  'metals.inc', 'glass.inc', 'textures.inc', 'colors.inc'])
    with open("where-next.pov", "w") as ofp:
        print(str(scene), file=ofp)
    scene.render('where-next.png', width=800, height=600,
                 antialiasing=0.1, quality=10)
Ejemplo n.º 3
0
def rdmb_povray_save(out_file,
                     vs,
                     ucs, vcs,
                     width=800, height=600,
                     rotx=0, roty=0, rotz=0,
                     angle=14):
    """Render and save RD results using Pov-Ray

    Render and save RD results using Pov-Ray

    Args:
        out_file: output file
        vs: vertices
        ucs, vcs: u/v conc.
        width, height: width and height of output image
        rotx, roty, rotz: rotation angle
        angle: camera angle

    """

    ucmax = 6.0
    ucs = ucs / ucmax
    ucs[ucs > 1.0] = 1.0
    # ucs = ucs / np.max(ucs)

    rot1 = [rotx, 0, 0]
    rot2 = [0, roty, 0]
    rot3 = [0, 0, rotz]

    camera = Camera('location', [0, 0, -25],
                    'look_at', [0, 0, 0],
                    'angle', angle,
                    'right x*image_width/image_height')

    light = LightSource([-3, 2, -6], 'color', [1.0, 1.0, 1.0], 'parallel')
    light2 = LightSource([2, -2, -6], 'color', [0.6, 0.6, 0.6], 'parallel')
    background = Background('color', [1, 1, 1, 1])

    spheres = [Sphere(v, 0.02,
                      Finish('ambient', 0.2, 'diffuse', 0.8, 'phong', 1.0),
                      Texture(Pigment('color',
                                      [0.3+uc*0.7, 0.2+uc*0.8, 0.2+uc*0.8])),
                      'rotate', rot1,
                      'rotate', rot2,
                      'rotate', rot3) for v, uc in zip(vs, ucs)]

    objects = [light, light2, background] + spheres

    scene = Scene(camera, objects=objects)
    scene.render(out_file, width=width, height=height,
                 output_alpha=True, antialiasing=0.001,
                 tempfile=out_file+"__temp__.pov")
Ejemplo n.º 4
0
    def save_frame_image(self, path):
        meshes = [Background("color", [self.bk_r, self.bk_g, self.bk_b])]
        tex = Texture(Pigment('color', [self.cc_r, self.cc_g, self.cc_b]),
                      Finish('specular', self.specular))
        texo = Texture(Pigment('color', [self.cco_r, self.cco_g, self.cco_b]),
                       Finish('specular', self.specularo))
        for i in xrange(-1, self.expert.nr_obstacles_c()):
            vss, nss, iss = self.save_frame_mesh(i)
            meshes += [ClothMesh(vss, iss, nss, tex if i == -1 else texo)]

        #render
        scene = Scene(Camera('location', [self.cx, self.cy, self.cz], 'sky',
                             [self.ux, self.uy, self.uz], 'look_at',
                             [self.fx, self.fy, self.fz], 'right', [1, 0, 0],
                             'up', [0, -1, 0], 'angle', self.fovy),
                      objects=self.lights + meshes)
        scene.render(path,
                     width=self.w,
                     height=self.h,
                     antialiasing=self.aa if hasattr(self, "aa") else 0.0)
Ejemplo n.º 5
0
def render_povray_mb(mbs, rotx=0, roty=0, rotz=0,
                     width=400, height=400, angle=14):
    """Render metaballs using Pov-Ray (Vapory)

    Render metaballs using Pov-Ray (Vapory)

    Args:
        mbs: Metaballs
        width, height:

    Returns:
        rendered_scene:

    """

    rot1 = [rotx, 0, 0]
    rot2 = [0, roty, 0]
    rot3 = [0, 0, rotz]

    camera = Camera('location', [0, 0, -25],
                    'look_at', [0, 0, 0],
                    'angle', angle,
                    'right x*image_width/image_height')

    light = LightSource([-3, 2, -6], 'color', [1.0, 1.0, 1.0], 'parallel')
    # light2 = LightSource([2, -2, -6], 'color', [0.6, 0.6, 0.6], 'parallel')
    background = Background('color', [1, 1, 1, 1])

    mbs_function = mbs.to_povray_func()

    isosurface = Isosurface(Function(mbs_function),
                            ContainedBy(Box(-5, 5)),
                            'max_gradient', 1.8,
                            Pigment('color', [1.0, 0.15, 0.3]),
                            Finish('phong', 0.7,
                                   'specular', 0.2,
                                   'diffuse', 0.9,
                                   'ambient', 0.1),
                            'rotate', rot1,
                            'rotate', rot2,
                            'rotate', rot3,
                            'translate', [0, 0, 0],
                            'no_shadow')

    objects = [light, background] + [isosurface]

    scene = Scene(camera, objects=objects)

    return scene.render('ipython', width=width, height=height)
Ejemplo n.º 6
0
def render_povray(vs, rotx=0, roty=0, rotz=0,
                  width=400, height=400, angle=14, antialiasing=0.001):
    """Render vertices using Pov-Ray (Vapory)

    Render vertices using Pov-Ray (Vapory)

    Args:
        vs: vertices
        rotx, roty, rotz: rotation angle
        width, height:
        angle: camera angle

    Returns:
        rendered_scene:

    """

    rot1 = [rotx, 0, 0]
    rot2 = [0, roty, 0]
    rot3 = [0, 0, rotz]

    camera = Camera('location', [0, 0, -25],
                    'look_at', [0, 0, 0],
                    'angle', angle,
                    'right x*image_width/image_height')

    light = LightSource([-3, 2, -6], 'color', [1.0, 1.0, 1.0], 'parallel')
    light2 = LightSource([2, -2, -6], 'color', [0.6, 0.6, 0.6], 'parallel')
    background = Background('color', [1, 1, 1])

    spheres = [Sphere(v, 0.05,
                      Finish('ambient', 0.2, 'diffuse', 0.8, 'phong', 1.0),
                      Texture(Pigment('color', [1.0, 1.0, 1.0])),
                      'rotate', rot1,
                      'rotate', rot2,
                      'rotate', rot3) for v in vs]

    objects = [light, light2, background] + spheres

    scene = Scene(camera, objects=objects)

    return scene.render('ipython',
                        width=width, height=height,
                        antialiasing=antialiasing)
Ejemplo n.º 7
0
    def _render_structure(self, change=None):
        """Render the structure with POVRAY."""

        if not isinstance(self.structure, Atoms):
            return

        self.render_btn.disabled = True
        omat = np.array(self._viewer._camera_orientation).reshape(
            4, 4).transpose()

        zfactor = norm(omat[0, 0:3])
        omat[0:3, 0:3] = omat[0:3, 0:3] / zfactor

        bb = deepcopy(self.structure)
        bb.pbc = (False, False, False)

        for i in bb:
            ixyz = omat[0:3, 0:3].dot(np.array([i.x, i.y, i.z]) + omat[0:3, 3])
            i.x, i.y, i.z = -ixyz[0], ixyz[1], ixyz[2]

        vertices = []

        cell = bb.get_cell()
        vertices.append(np.array([0, 0, 0]))
        vertices.extend(cell)
        vertices.extend([
            cell[0] + cell[1],
            cell[0] + cell[2],
            cell[1] + cell[2],
            cell[0] + cell[1] + cell[2],
        ])

        for n, i in enumerate(vertices):
            ixyz = omat[0:3, 0:3].dot(i + omat[0:3, 3])
            vertices[n] = np.array([-ixyz[0], ixyz[1], ixyz[2]])

        bonds = []

        cutOff = neighborlist.natural_cutoffs(
            bb)  # Takes the cutoffs from the ASE database
        neighborList = neighborlist.NeighborList(cutOff,
                                                 self_interaction=False,
                                                 bothways=False)
        neighborList.update(bb)
        matrix = neighborList.get_connectivity_matrix()

        for k in matrix.keys():
            i = bb[k[0]]
            j = bb[k[1]]

            v1 = np.array([i.x, i.y, i.z])
            v2 = np.array([j.x, j.y, j.z])
            midi = v1 + (v2 - v1) * Radius[i.symbol] / (Radius[i.symbol] +
                                                        Radius[j.symbol])
            bond = Cylinder(
                v1,
                midi,
                0.2,
                Pigment("color", np.array(Colors[i.symbol])),
                Finish("phong", 0.8, "reflection", 0.05),
            )
            bonds.append(bond)
            bond = Cylinder(
                v2,
                midi,
                0.2,
                Pigment("color", np.array(Colors[j.symbol])),
                Finish("phong", 0.8, "reflection", 0.05),
            )
            bonds.append(bond)

        edges = []
        for x, i in enumerate(vertices):
            for j in vertices[x + 1:]:
                if (norm(np.cross(i - j, vertices[1] - vertices[0])) < 0.001
                        or norm(np.cross(i - j,
                                         vertices[2] - vertices[0])) < 0.001
                        or norm(np.cross(i - j,
                                         vertices[3] - vertices[0])) < 0.001):
                    edge = Cylinder(
                        i,
                        j,
                        0.06,
                        Texture(
                            Pigment("color",
                                    [212 / 255.0, 175 / 255.0, 55 / 255.0])),
                        Finish("phong", 0.9, "reflection", 0.01),
                    )
                    edges.append(edge)

        camera = Camera(
            "perspective",
            "location",
            [0, 0, -zfactor / 1.5],
            "look_at",
            [0.0, 0.0, 0.0],
        )
        light = LightSource([0, 0, -100.0], "color", [1.5, 1.5, 1.5])

        spheres = [
            Sphere(
                [i.x, i.y, i.z],
                Radius[i.symbol],
                Texture(Pigment("color", np.array(Colors[i.symbol]))),
                Finish("phong", 0.9, "reflection", 0.05),
            ) for i in bb
        ]

        objects = (
            [light] + spheres + edges + bonds +
            [Background("color", np.array(to_rgb(self._viewer.background)))])

        scene = Scene(camera, objects=objects)
        fname = bb.get_chemical_formula() + ".png"
        scene.render(
            fname,
            width=2560,
            height=1440,
            antialiasing=0.000,
            quality=11,
            remove_temp=False,
        )
        with open(fname, "rb") as raw:
            payload = base64.b64encode(raw.read()).decode()
        self._download(payload=payload, filename=fname)
        self.render_btn.disabled = False
Ejemplo n.º 8
0
class VaporyAnimation(Vis):
    def __init__(self, sm: SysManager, frame_step: int = 1) -> None:
        super().__init__(sm, frame_step)

        # vapory objects
        self.scene: Scene = None
        self.lights: list = None
        self.objects: list = None
        self.camera: Camera = None
        self.radiosity: Radiosity = None
        self.background: Background = None

        # Colors
        self.clr_sun = (1, 1, 1)  # (1, 0.8, 0.7)
        self.clr_background = (0.1, 0.1, 0.12)  # rgb2unit((70, 80, 100))
        self.clr_particle = rgb2unit((50, 75, 175))  # (1, 0.75, 0)

        # INIT
        self.initialize()

    def initialize(self):
        # Set up camera
        camera_location = [
            2 * self.sm.LEN_BOX, 1.25 * self.sm.LEN_BOX, -0.5 * self.sm.LEN_BOX
        ]

        self.camera = Camera(
            "location", camera_location, "look_at",
            [self.sm.LEN_BOX / 2, self.sm.LEN_BOX / 2.5, self.sm.LEN_BOX / 2])

        # Set up background
        self.background = Background("color", self.clr_background)

        # Set up lighting
        self.lights = [
            LightSource(camera_location, "color", [1, 1, 1]),
            LightSource([
                100 * self.sm.LEN_BOX, 100 * self.sm.LEN_BOX,
                -100 * self.sm.LEN_BOX
            ], "color", self.clr_sun),
        ]

        # Global Settings
        # self.radiosity = Radiosity()

        # Goup Objects
        self.objects = [self.background, *self.lights]

    def render_frame(self, step, outn):

        particles = []
        for i in range(self.sm.NUM_PARTICLES):
            clr = speed2color(speed=self.speeds[step][i],
                              speed_limit=self.maxspeed,
                              alpha=False)
            p = Sphere(
                [
                    self.r_vecs[step][i][1], self.r_vecs[step][i][2],
                    self.r_vecs[step][i][0]
                ],
                self.sm.RADIUS_PARTICLE,
                Texture(Pigment("color", clr)),
            )
            particles.append(p)

        self.scene = Scene(self.camera, objects=self.objects + particles)

        self.scene.render(f"{self.sm.png_path}/img{outn:06}.png",
                          width=600,
                          height=400)

    def render(self):
        n = 1
        for step in range(self.sm.STEPS):
            if not (step % self.frame_step):
                self.render_frame(step, n)
                n += 1