コード例 #1
0
    def test_scene_colors(self, methanegsd):
        scene, info = get_scene(methanegsd, color="bsu")
        assert type(scene) is type(fresnel.Scene())

        scene, info = get_scene(methanegsd, color={"C": "grey"})
        assert type(scene) is type(fresnel.Scene())

        scene, info = get_scene(methanegsd, color="jet")
        assert type(scene) is type(fresnel.Scene())

        with pytest.raises(ValueError):
            get_scene(methanegsd, color="heck")
コード例 #2
0
def render_disk_frame(frame, Ly=None):

    if Ly is None:
        if hasattr(frame, 'configuration'):
            Ly = frame.configuration.box[1]
        else:
            Ly = frame.box.Ly

    scene = fresnel.Scene(device)
    g = fresnel.geometry.Sphere(scene,
                                position=frame.particles.position,
                                radius=frame.particles.diameter * 0.5)
    g.material = fresnel.material.Material(solid=1.0,
                                           color=blue,
                                           primitive_color_mix=1.0)
    g.outline_width = 0.1
    scene.camera = fresnel.camera.orthographic(position=(0, 0, 10),
                                               look_at=(0, 0, 0),
                                               up=(0, 1, 0),
                                               height=Ly)

    g.color[frame.particles.typeid == 0] = blue
    g.color[frame.particles.typeid == 1] = orange

    scene.background_color = (1, 1, 1)

    return preview_tracer.render(scene)
コード例 #3
0
def test_camera_fit_no_geometry(device_):
    """Test that fit() errors when there is no geometry."""
    scene = fresnel.Scene()

    # fit cannot be called on a scene with no geometries
    with pytest.raises(ValueError):
        fresnel.camera.Orthographic.fit(scene, view='front', margin=0)
コード例 #4
0
def render_polygon_frame(frame, verts, Ly=None):

    if Ly is None:
        if hasattr(frame, 'configuration'):
            Ly = frame.configuration.box[1]
        else:
            Ly = frame.box.Ly

    scene = fresnel.Scene(device)
    ang = numpy.arctan2(frame.particles.orientation[:, 3],
                        frame.particles.orientation[:, 0]) * 2
    g = fresnel.geometry.Prism(scene,
                               vertices=verts,
                               position=frame.particles.position[:, 0:2],
                               angle=ang,
                               height=numpy.ones(frame.particles.N) * 0.5)
    g.outline_width = 0.1
    g.material = fresnel.material.Material(solid=1.0, color=blue)
    scene.camera = fresnel.camera.orthographic(position=(0, 0, 10),
                                               look_at=(0, 0, 0),
                                               up=(0, 1, 0),
                                               height=Ly)
    scene.background_color = (1, 1, 1)

    return preview_tracer.render(scene)
コード例 #5
0
def render_sphere_frame(frame, height=None):

    if height is None:
        if hasattr(frame, 'configuration'):
            Ly = frame.configuration.box[1]
            height = Ly * math.sqrt(3)
        else:
            Ly = frame.box.Ly
            height = Ly * math.sqrt(3)

    scene = fresnel.Scene(device)
    g = fresnel.geometry.Sphere(scene,
                                position=frame.particles.position,
                                radius=numpy.ones(frame.particles.N) * 0.5)
    g.material = fresnel.material.Material(solid=0.0,
                                           color=fresnel.color.linear(
                                               [0.25, 0.5, 1]),
                                           primitive_color_mix=1.0)
    g.outline_width = 0.1
    scene.camera = fresnel.camera.orthographic(position=(height, height,
                                                         height),
                                               look_at=(0, 0, 0),
                                               up=(0, 1, 0),
                                               height=height)

    g.color[frame.particles.typeid == 0] = fresnel.color.linear([0.25, 0.5, 1])
    g.color[frame.particles.typeid == 1] = fresnel.color.linear(
        [1.0, 0.714, 0.169])

    scene.background_color = (1, 1, 1)

    return tracer.render(scene)
def render_sphere_frame(frame, height=None):

    if height is None:
        if hasattr(frame, 'configuration'):
            Ly = frame.configuration.box[1]
            height = Ly * math.sqrt(3)
        else:
            Ly = frame.box.Ly
            height = Ly * math.sqrt(3)

    scene = fresnel.Scene(device)
    scene.lights = fresnel.light.cloudy()
    g = fresnel.geometry.Sphere(scene,
                                position=frame.particles.position,
                                radius=frame.particles.diameter * 0.5)
    g.material = fresnel.material.Material(solid=1,
                                           color=blue,
                                           primitive_color_mix=1.0,
                                           specular=1.0,
                                           roughness=0.2)
    g.outline_width = 0.07
    scene.camera = fresnel.camera.orthographic(position=(height, height,
                                                         height),
                                               look_at=(0, 0, 0),
                                               up=(0.2, 1, 0),
                                               height=height)

    g.color[frame.particles.typeid == 0] = blue
    g.color[frame.particles.typeid == 1] = orange
    g.color[frame.particles.typeid == 2] = [1, 0, 0]
    g.color[frame.particles.typeid == 3] = orange

    scene.background_color = (1, 1, 1)

    return path_tracer.sample(scene, samples=64, light_samples=20)
コード例 #7
0
def scene_one_triangle(device):
    """Create a test scene with one triangle."""
    scene = fresnel.Scene(device, lights=conftest.test_lights())

    geometry = fresnel.geometry.Mesh(scene,
                                     vertices=[[-1, -1, 0], [1, -1, 0],
                                               [-1, 1, 0]],
                                     N=1)
    geometry.color[:] = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]

    geometry.material = fresnel.material.Material(color=fresnel.color.linear(
        [1.0, 0, 0]),
                                                  roughness=0.8,
                                                  specular=0.5,
                                                  primitive_color_mix=0.0,
                                                  solid=1)

    geometry.outline_material = fresnel.material.Material(
        color=fresnel.color.linear([0, 1.0, 0]),
        roughness=0.8,
        specular=0.5,
        primitive_color_mix=0.0,
        solid=1)

    geometry.orientation[:] = [1, 0, 0, 0]

    scene.camera = fresnel.camera.Orthographic(position=(0, 0, 20),
                                               look_at=(0, 0, 0),
                                               up=(0, 1, 0),
                                               height=2.1)

    return scene
コード例 #8
0
def test_background_color(device_):
    """Test the background_color property."""
    scene = fresnel.Scene(device=device_)

    scene.background_color = fresnel.color.linear((0.125, 0.75, 0.375))

    numpy.testing.assert_array_equal(
        scene.background_color, fresnel.color.linear((0.125, 0.75, 0.375)))

    scene.background_alpha = 0.5

    assert scene.background_alpha == 0.5

    scene.camera = fresnel.camera.Orthographic(position=(0, 0, 10),
                                               look_at=(0, 0, 0),
                                               up=(0, 1, 0),
                                               height=7)
    buf_proxy = fresnel.preview(scene, w=100, h=100, anti_alias=False)
    buf = buf_proxy[:]

    numpy.testing.assert_array_equal(
        buf[:, :, 3],
        numpy.ones(shape=(100, 100), dtype=buf.dtype) * 128)
    numpy.testing.assert_array_equal(
        buf[:, :, 0:3],
        numpy.ones(shape=(100, 100, 3), dtype=buf.dtype) * (32, 191, 96))
コード例 #9
0
def scene_eight_polyhedra(device):
    """Create a test scene with eight polyhedra."""
    scene = fresnel.Scene(device, lights=conftest.test_lights())

    # place eight polyhedra
    position = []
    for k in range(2):
        for i in range(2):
            for j in range(2):
                position.append([2.5 * i, 2.5 * j, 2.5 * k])

    # create the polyhedron faces
    origins = []
    normals = []
    colors = []

    for v in [-1, 1]:
        origins.append([v, 0, 0])
        normals.append([v, 0, 0])
        origins.append([0, v, 0])
        normals.append([0, v, 0])
        origins.append([0, 0, v])
        normals.append([0, 0, v])
        colors.append([178 / 255, 223 / 255, 138 / 255])
        colors.append([178 / 255, 223 / 255, 138 / 255])
        colors.append([178 / 255, 223 / 255, 138 / 255])

    for x in [-1, 1]:
        for y in [-1, 1]:
            for z in [-1, 1]:
                normals.append([x, y, z])
                origins.append([x * 0.75, y * 0.75, z * 0.75])
                colors.append([166 / 255, 206 / 255, 227 / 255])

    poly_info = {
        'face_normal': normals,
        'face_origin': origins,
        'radius': math.sqrt(3),
        'face_color': fresnel.color.linear(colors)
    }
    geometry = fresnel.geometry.ConvexPolyhedron(scene,
                                                 poly_info,
                                                 position=position)

    geometry.material = \
        fresnel.material.Material(color=fresnel.color.linear([1.0, 0, 0]),
                                  roughness=0.8,
                                  specular=0.5,
                                  primitive_color_mix=0.0)
    geometry.orientation[:] = [1, 0, 0, 0]

    scene.camera = fresnel.camera.Orthographic(position=(20, 20, 20),
                                               look_at=(0, 0, 0),
                                               up=(0, 1, 0),
                                               height=7)

    return scene
コード例 #10
0
def test_camera_fit_isometric(device_):
    scene = fresnel.Scene()

    geom1 = fresnel.geometry.Sphere(scene,
                                    position=[[-9, -2, 0], [-5, -1, 0],
                                              [4, 0, 0], [2, 1, 0]],
                                    radius=1.0)

    cam = fresnel.camera.fit(scene, view='isometric', margin=0)
コード例 #11
0
def test_scene_auto(device_):
    scene = fresnel.Scene()

    geom1 = fresnel.geometry.Sphere(scene,
                                    position=[[-9, -2, 0], [-5, -1, 0],
                                              [4, 0, 0], [2, 1, 0]],
                                    radius=1.0)
    assert scene.camera == 'auto'

    fresnel.preview(scene)
コード例 #12
0
def test_camera_fit_isometric(device_):
    """Test that fit works with the isometric option."""
    scene = fresnel.Scene()

    fresnel.geometry.Sphere(scene,
                            position=[[-9, -2, 0], [-5, -1, 0], [4, 0, 0],
                                      [2, 1, 0]],
                            radius=1.0)

    fresnel.camera.Orthographic.fit(scene, view='isometric', margin=0)
コード例 #13
0
def test_scene_default_camera(device_):
    """Test that there is a default camera."""
    scene = fresnel.Scene()

    fresnel.geometry.Sphere(scene,
                            position=[[-9, -2, 0], [-5, -1, 0], [4, 0, 0],
                                      [2, 1, 0]],
                            radius=1.0)

    fresnel.preview(scene, anti_alias=False)
コード例 #14
0
ファイル: abcv.py プロジェクト: tsaie79/abcv
    def generate_scene(self, background_color=None, isosurface=0.1,
                       radius_scale=0.5):
        self.scene = fresnel.Scene()
        self.scene.lights = fresnel.light.rembrandt()

        if background_color is not None:
            self.scene.background_color = background_color[:3]
            self.scene.background_alpha = background_color[-1]

        # set up atoms
        self.atoms = fresnel.geometry.Sphere(
            self.scene,
            position=self.structure.cart_coords,
            radius=1.0,
            outline_width=0.
        )

        self.atoms.radius[:] = \
            [radius_scale * x.specie.data['Atomic radius']
             for x in self.structure]

        self.atoms.material = fresnel.material.Material()
        self.atoms.material.solid = 0.
        self.atoms.material.primitive_color_mix = 1.
        self.atoms.material.roughness = 0.5
        self.atoms.material.specular = 0.7
        self.atoms.material.spec_trans = 0.
        self.atoms.material.metal = 0.
        self.atoms.color[:] = fresnel.color.linear(
            [self.colors[x.specie.name] for x in self.structure]
        )

        # set up bonds
        self.bonds = make_bonds(self.scene, self.structure)

        # set up unit cell
        self.unit_cell = make_unit_cell(
            self.scene,
            self.structure.lattice.matrix
        )

        # set up isosurfaces
        if isosurface is not None and self.grid_data is not None:
            if not isinstance(isosurface, Iterable):
                isosurface = [isosurface]

            for iso in isosurface:
                self.isosurfaces.extend(make_isosurface(
                    self.scene, self.structure, self.grid_data, iso
                ))

        self.scene.camera = \
            fresnel.camera.fit(self.scene, view='front', margin=0.5)

        return self.scene
コード例 #15
0
ファイル: Scene.py プロジェクト: glotzerlab/plato
 def __init__(self, *args, tracer_kwargs={}, **kwargs):
     super(Scene, self).__init__(*args, **kwargs)
     self._device = fresnel.Device()
     self._fresnel_scene = fresnel.Scene(device=self._device)
     default_size = self.size_pixels.astype(np.uint32)
     self._preview_tracer = fresnel.tracer.Preview(
         device=self._device, w=default_size[0], h=default_size[1])
     self._path_tracer = fresnel.tracer.Path(
         device=self._device, w=default_size[0], h=default_size[1])
     self._geometries = []
     self._output = None
コード例 #16
0
def test_camera_fit_front(device_):
    scene = fresnel.Scene()

    geom1 = fresnel.geometry.Sphere(scene,
                                    position=[[-9, -2, 0], [-5, -1, 0],
                                              [4, 0, 0], [2, 1, 0]],
                                    radius=1.0)

    cam = fresnel.camera.fit(scene, view='front', margin=0)
    assert cam.position[0] == -2.5
    assert cam.position[1] == -0.5
    assert cam.look_at == (-2.5, -0.5, 0)
    assert cam.height == 5
コード例 #17
0
ファイル: conftest.py プロジェクト: wsrinin/fresnel
def scene_hex_sphere(device):
    scene = fresnel.Scene(device, lights = test_lights())

    position = []
    for i in range(6):
        position.append([2*math.cos(i*2*math.pi / 6), 2*math.sin(i*2*math.pi / 6), 0])

    geometry = fresnel.geometry.Sphere(scene, position = position, radius=1.0)
    geometry.material = fresnel.material.Material(solid=0.0, color=fresnel.color.linear([1,0.874,0.169]))
    geometry.outline_width = 0.12

    scene.camera = fresnel.camera.orthographic(position=(0, 0, 10), look_at=(0,0,0), up=(0,1,0), height=6)

    return scene
コード例 #18
0
def test_camera_fit_front(device_):
    """Test that fit works with the front option."""
    scene = fresnel.Scene()

    fresnel.geometry.Sphere(scene,
                            position=[[-9, -2, 0], [-5, -1, 0], [4, 0, 0],
                                      [2, 1, 0]],
                            radius=1.0)

    cam = fresnel.camera.Orthographic.fit(scene, view='front', margin=0)
    assert cam.position[0] == -2.5
    assert cam.position[1] == -0.5
    numpy.testing.assert_array_equal(cam.look_at, (-2.5, -0.5, 0))
    assert cam.height == 5
コード例 #19
0
def scene_box(device):
    """Create a test scene."""
    scene = fresnel.Scene(device, lights=conftest.test_lights())

    fresnel.geometry.Box(scene, [1, 2, 3, 0.4, 0.5, 0.6],
                         box_radius=0.2,
                         box_color=[1, 0, 1])

    scene.camera = fresnel.camera.Orthographic(position=(10, 10, 10),
                                               look_at=(0, 0, 0),
                                               up=(0, 1, 0),
                                               height=4)

    return scene
コード例 #20
0
def test_background_color(device_):
    scene = fresnel.Scene(device=device_)

    scene.background_color = fresnel.color.linear((0.125, 0.75, 0.375))

    assert scene.background_color == tuple(fresnel.color.linear((0.125, 0.75, 0.375)))

    scene.background_alpha = 0.5

    assert scene.background_alpha == 0.5

    buf_proxy = fresnel.preview(scene, w=100, h=100)
    buf = buf_proxy[:]

    numpy.testing.assert_array_equal(buf[:,:,3], numpy.ones(shape=(100,100), dtype=buf.dtype)*128)
    numpy.testing.assert_array_equal(buf[:,:,0:3], numpy.ones(shape=(100,100,3), dtype=buf.dtype)*(32,191,96))
コード例 #21
0
def renderMeshCloud(    mesh=None, mesh_outline_width=None, meshflat=False,  # mesh settings
                        cloud=None, cloudR=0.006, cloudC=None,  # pc settings
                        camPos=None, camLookat=None, camUp=np.array([0,0,1]), camHeight=1.,  # camera settings
                        samples=8, axes=False, resolution=(1024,1024),  # render settings
                        **kwargs):
    device = fresnel.Device()

    scene = fresnel.Scene(device)
    if mesh is not None:
        mesh = fresnel.geometry.Mesh(scene,vertices=mesh['vert'][mesh['face']].reshape(-1,3) ,N=1)
        mesh.material = fresnel.material.Material(color=fresnel.color.linear([0.7,0.7,0.7]), 
                                                    roughness=0.3,
                                                    specular=1.,
                                                    spec_trans=0.)
        if mesh_outline_width is not None:
            mesh.outline_width = mesh_outline_width
    if cloud is not None:
        cloud = fresnel.geometry.Sphere(scene, position = cloud, radius=cloudR)
        solid = .7 if mesh is not None else 0.
        cloud.material = fresnel.material.Material(solid=solid, \
                                                    color=fresnel.color.linear([1,0.0,0]),\
                                                    roughness=1.0,
                                                    specular=0.0)
        if cloudC is not None:
            #cloudC = vis.rescale(cloudC, cloudC)
            cloud.material.primitive_color_mix = 1.0
            cloud.color[:] = fresnel.color.linear(plt.cm.plasma(cloudC)[:,:3])
    if axes == True:
       addAxes(scene)
    if camPos is None or camLookat is None:
        scene.camera = fresnel.camera.fit(scene,margin=0)
    else:
        scene.camera = fresnel.camera.orthographic(camPos, camLookat, camUp, camHeight)
    scene.lights = fresnel.light.cloudy()
    #scene.lights = fresnel.light.rembrandt()
    #scene.lights = fresnel.light.lightbox()
    #scene.lights = fresnel.light.loop()
    scene.lights = fresnel.light.butterfly()
    #scene.lights[0].theta = 3

    tracer = fresnel.tracer.Path(device=device, w=resolution[0], h=resolution[1])
    tracer.sample(scene, samples=samples, light_samples=8)
    #tracer.resize(w=450, h=450)
    #tracer.aa_level = 3
    image = tracer.render(scene)[:]
    return image
コード例 #22
0
def render_polymer(pos, sigma=1.0, color=[0.41, 0.30, 0.59]):
    scene = fresnel.Scene()
    N = len(pos)

    geometry = fresnel.geometry.Sphere(scene, N=N, position=pos, radius=sigma)
    geometry.material = fresnel.material.Material(
        color=fresnel.color.linear(color), roughness=0.8)

    scene.camera = fresnel.camera.Orthographic.fit(scene,
                                                   view='isometric',
                                                   margin=0.0)

    out = fresnel.preview(scene)
    image = PIL.Image.fromarray(out[:], mode='RGBA')
    image.save('polymer_render.png')

    return IPython.display.Image('polymer_render.png')
コード例 #23
0
def test_multiple_geometries(device_, generate=False):
    scene = fresnel.Scene(lights=conftest.test_lights())
    scene.camera = fresnel.camera.orthographic(position=(0, 0, 10), look_at=(0,0,0), up=(0,1,0), height=7)

    geom1 = fresnel.geometry.Sphere(scene, position = [[-4, 1, 0], [-4, -1, 0], [-2, 1, 0], [-2, -1, 0]], radius=1.0)
    geom1.material = fresnel.material.Material(solid=1.0, color=fresnel.color.linear([0.42,0.267,1]))
    geom1.outline_width = 0.12

    geom2 = fresnel.geometry.Sphere(scene, position = [[4, 1, 0], [4, -1, 0], [2, 1, 0], [2, -1, 0]], radius=1.0)
    geom2.material = fresnel.material.Material(solid=0.0, color=fresnel.color.linear([1,0.874,0.169]))

    buf_proxy = fresnel.preview(scene, w=200, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(open('output/test_scene.test_multiple_geometries1.png', 'wb'), 'png');
    else:
        conftest.assert_image_approx_equal(buf_proxy[:], 'reference/test_scene.test_multiple_geometries1.png')

    geom1.disable()

    buf_proxy = fresnel.preview(scene, w=200, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(open('output/test_scene.test_multiple_geometries2.png', 'wb'), 'png');
    else:
        conftest.assert_image_approx_equal(buf_proxy[:], 'reference/test_scene.test_multiple_geometries2.png')

    geom1.enable()

    buf_proxy = fresnel.preview(scene, w=200, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(open('output/test_scene.test_multiple_geometries3.png', 'wb'), 'png');
    else:
        conftest.assert_image_approx_equal(buf_proxy[:], 'reference/test_scene.test_multiple_geometries3.png')

    geom2.remove()

    buf_proxy = fresnel.preview(scene, w=200, h=100)

    if generate:
        PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(open('output/test_scene.test_multiple_geometries4.png', 'wb'), 'png');
    else:
        conftest.assert_image_approx_equal(buf_proxy[:], 'reference/test_scene.test_multiple_geometries4.png')
コード例 #24
0
def scene_four_spheres(device):
    """Create a test scene with four spheres."""
    scene = fresnel.Scene(device, lights=conftest.test_lights())

    mat = fresnel.material.Material(
        color=fresnel.color.linear([0.42, 0.267, 1]))
    fresnel.geometry.Sphere(scene,
                            position=[[1, 0, 1], [1, 0, -1], [-1, 0, 1],
                                      [-1, 0, -1]],
                            radius=1.0,
                            material=mat,
                            color=[[1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 0, 1]])

    scene.camera = fresnel.camera.Orthographic(position=(10, 10, 10),
                                               look_at=(0, 0, 0),
                                               up=(0, 1, 0),
                                               height=4)

    return scene
コード例 #25
0
ファイル: fresnelvis.py プロジェクト: QhelDIV/xgutils
    def setup_scene(self, camera_kwargs={}, lights="rembrandt"):
        device = fresnel.Device()
        scene = fresnel.Scene(device)

        self.camera_opt = camera_opt = copy.deepcopy(dflt_camera)
        camera_opt.update(camera_kwargs)
        self.camera_kwargs = camera_opt

        if camera_opt["fit_camera"] == True:
            print("Camera is not setup, now auto-fit camera")
            scene.camera = fresnel.camera.fit(scene, margin=0)
        else:
            camPos = camera_opt["camPos"]
            camLookat = camera_opt["camLookat"]
            camUp = camera_opt["camUp"]
            camHeight = camera_opt["camHeight"]
            scene.camera = fresnel.camera.orthographic(camPos, camLookat,
                                                       camUp, camHeight)
        # setup lightings
        if "lights" in camera_kwargs:
            lights = camera_kwargs["lights"]
        if type(lights) is not str:
            scene.lights = camera_kwargs["lights"]
        elif lights == "cloudy":
            scene.lights = fresnel.light.cloudy()
        elif lights == "rembrandt":
            scene.lights = fresnel.light.rembrandt()
        elif lights == "lightbox":
            scene.lights = fresnel.light.lightbox()
        elif lights == "loop":
            scene.lights = fresnel.light.loop()
        elif lights == "butterfly":
            scene.lights = fresnel.light.butterfly()
        elif lights == "up":
            scene.lights = get_world_lights([np.array([0, 1, 0])],
                                            colors=[np.array([1, 1, 1])],
                                            thetas=[1.],
                                            camera_pos=camPos)
        # addAxes(scene)
        # addBBox(scene)
        self.scene, self.device = scene, device
コード例 #26
0
def scene_four_cylinders(device):
    scene = fresnel.Scene(device, lights=conftest.test_lights())

    position = [[[-5, -5, 0], [-5, 5, 0]], [[5, -5, -5], [5, 5, 5]],
                [[3, 3, -3], [-3, -3, -3]], [[-2, 2, 2], [2, -2, -2]]]

    geometry = fresnel.geometry.Cylinder(
        scene,
        points=position,
        radius=1.0,
        color=[0.9, 0.9, 0.9],
        material=fresnel.material.Material(
            color=fresnel.color.linear([0.42, 0.267, 1])),
    )

    scene.camera = fresnel.camera.orthographic(position=(0, 2, 10),
                                               look_at=(0, 0, 0),
                                               up=(0, 1, 0),
                                               height=15)

    return scene
コード例 #27
0
def scene_rounded_polygons(device):
    scene = fresnel.Scene(device, lights=conftest.test_lights())

    geometry = fresnel.geometry.Polygon(scene,
                                        N=2,
                                        rounding_radius=0.3,
                                        vertices=[[-1, -1], [1, -1], [1, 1],
                                                  [0, 0], [-1, 1]],
                                        position=[[-1.5, 0], [1.5, 0]],
                                        angle=[0.1, -0.2],
                                        color=[[0, 0, 1], [0, 1, 0]],
                                        material=fresnel.material.Material(
                                            color=fresnel.color.linear(
                                                [0.42, 0.267, 1]),
                                            solid=1))

    scene.camera = fresnel.camera.orthographic(position=(0, 0, -2),
                                               look_at=(0, 0, 0),
                                               up=(0, 1, 0),
                                               height=5)

    return scene
コード例 #28
0
def scene_tetrahedra(device):
    """Create a test scene with a tetrahedron."""
    scene = fresnel.Scene(device, lights=conftest.test_lights())

    verts = [(1, 1, 1), (1, -1, -1), (-1, 1, -1), (-1, -1, 1)]
    triangles = [
        verts[0], verts[1], verts[2], verts[2], verts[1], verts[3], verts[2],
        verts[3], verts[0], verts[1], verts[0], verts[3]
    ]

    geometry = fresnel.geometry.Mesh(scene, vertices=triangles, N=4)
    geometry.color[0:2, :] = [0.9, 0, 0]
    geometry.color[3:5, :] = [0, 0.9, 0]
    geometry.color[6:8, :] = [0, 0, 0.9]
    geometry.color[9:11, :] = [0.9, 0, 0.9]

    geometry.material = fresnel.material.Material(color=fresnel.color.linear(
        [1.0, 0, 0]),
                                                  roughness=0.8,
                                                  specular=0.5,
                                                  primitive_color_mix=1.0,
                                                  solid=0)

    geometry.position[:] = [[-2, -2, 0], [2, -2, 0], [2, 2, 0], [-2, 2, 0]]

    geometry.orientation[:] = [
        [0.03723867, 0.38927173, -0.73216521, -0.55768711],
        [-0.32661186, 0.43644863, -0.09899935, 0.83248808],
        [0.25624845, 0.32632096, -0.11995704, -0.9019211],
        [-0.78025512, -0.12102377, 0.24947819, 0.56063877]
    ]

    scene.camera = fresnel.camera.Orthographic(position=(0, 0, -20),
                                               look_at=(0, 0, 0),
                                               up=(0, 1, 0),
                                               height=7.5)

    return scene
def render_sphere_frame(frame, height=None):

    """
        render_sphere_frame takes in a HOOMD system snapshot
        and generates scene of the box, which it returns
        back through a path_tracer sample
        
        This function is an extension of the function provided 
        in the HOOMD tool kit
    
    """
    
    
    if height is None:
        if hasattr(frame, 'configuration'):
            Ly = frame.configuration.box[1]
            height = Ly * math.sqrt(3)
        else:
            Ly = frame.box.Ly;
            height = Ly * math.sqrt(3)

    scene = fresnel.Scene(device)
    scene.lights = fresnel.light.cloudy();
    g = fresnel.geometry.Sphere(scene, position=frame.particles.position, radius=frame.particles.diameter*0.5)
    g.material = fresnel.material.Material(solid=1, color=blue, primitive_color_mix=1.0, specular=1.0, roughness=0.2)
    g.outline_width = 0.07
    scene.camera = fresnel.camera.orthographic(position=(height, height, height), look_at=(0,0,0), up=(0.2,1,0), height=height)

    g.color[frame.particles.typeid == 0] = blue;
    g.color[frame.particles.typeid == 1] = orange;
    g.color[frame.particles.typeid == 2] = [1,0,0];
    g.color[frame.particles.typeid == 3] = [0.5,0.4,0.2];
    g.color[frame.particles.typeid == 4] = [0.2,0.7,0.7];

    scene.background_color = (1,1,1)

    return path_tracer.sample(scene, samples=64, light_samples=20)
コード例 #30
0
def scene_four_spheres(device):
    scene = fresnel.Scene(device, lights=conftest.test_lights())

    position = []
    for i in range(6):
        position.append([
            2 * math.cos(i * 2 * math.pi / 6),
            2 * math.sin(i * 2 * math.pi / 6), 0
        ])

    geometry = fresnel.geometry.Sphere(
        scene,
        position=[[1, 0, 1], [1, 0, -1], [-1, 0, 1], [-1, 0, -1]],
        radius=1.0,
        material=fresnel.material.Material(
            color=fresnel.color.linear([0.42, 0.267, 1])),
        color=[[1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 0, 1]])

    scene.camera = fresnel.camera.orthographic(position=(10, 10, 10),
                                               look_at=(0, 0, 0),
                                               up=(0, 1, 0),
                                               height=4)

    return scene