ipymd.visualise.opengl.renderers package

Submodules

ipymd.visualise.opengl.renderers.atom module

Created on Sun May 15 20:10:20 2016

@author: cjs14

added patch to allow for transparent atoms when using ‘impostors’ backend & changed to have pre-processing of colors and radii

class ipymd.visualise.opengl.renderers.atom.AtomRenderer(widget, r_array, radii, colorlist, backend='impostors', shading='phong', transparent=True)[source]

Bases: ipymd.visualise.opengl.renderers.base.AbstractRenderer

Render atoms by using different rendering methods.

Parameters

widget:
The parent QChemlabWidget
r_array: np.ndarray((NATOMS, 3), dtype=float)
The atomic coordinate array
type_array: np.ndarray((NATOMS, 3), dtype=object)
An array containing all the atomic symbols like Ar, H, O. If the atomic type is unknown, use the Xx symbol.
backend: “impostors” | “polygons” | “points”
You can choose the rendering method between the sphere impostors, polygonal sphere and points.
change_shading(shd)[source]
draw()[source]
hide(mask)[source]
update_colors(cols)[source]
update_positions(r_array)[source]

Update the atomic positions

update_radii(radii)[source]

ipymd.visualise.opengl.renderers.base module

class ipymd.visualise.opengl.renderers.base.AbstractRenderer(widget, *args, **kwargs)[source]

Bases: object

AbstractRenderer is the standard interface for renderers. Each renderer have to implement an initialization function __init__ and a draw method to do the actual drawing using OpenGL or by using other, more basic, renderers.

Usually the renderers have also some custom functions that they use to update themselves. For example a SphereRenderer implements the function update_positions to move the spheres around without having to regenerate all of the other properties.

See also

/graphics for a tutorial on how to develop a simple renderer.

Parameters

widget: chemlab.graphics.QChemlabWidget
The parent QChemlabWidget. Renderers can use the widget to access the camera, lights, and other informations.

args, kwargs: Any other argument that they may use.

draw()[source]

Generic drawing function to be implemented by the subclasses.

class ipymd.visualise.opengl.renderers.base.DefaultRenderer(widget)[source]

Bases: ipymd.visualise.opengl.renderers.base.ShaderBaseRenderer

Same as ShaderBaseRenderer with the default shaders.

You can find the shaders in chemlab/graphics/renderers/shaders/ under the names of default_persp.vert and default_persp.frag.

draw_vertices()[source]

Subclasses should reimplement this method.

setup_shader()[source]
class ipymd.visualise.opengl.renderers.base.ShaderBaseRenderer(widget, vertex, fragment)[source]

Bases: ipymd.visualise.opengl.renderers.base.AbstractRenderer

Instruments OpenGL with a vertex and a fragment shader.

This renderer automatically binds light and camera information. Subclasses should not reimplement the draw method but the draw_vertices method where you can bind and draw the objects.

Parameters

widget:
The parent QChemlabWidget
vertex: str
Vertex program as a string
fragment: str
Fragment program as a string
compile_shader()[source]
draw()[source]
draw_vertices()[source]

Method to be reimplemented by the subclasses.

setup_shader()[source]

ipymd.visualise.opengl.renderers.box module

Created on Mon May 16 10:53:56 2016

@author: cjs14

added patch to allow for line width selection

class ipymd.visualise.opengl.renderers.box.BoxRenderer(widget, vectors, origin=<Mock object>, color=(0, 0, 0, 255), width=1.5)[source]

Bases: ipymd.visualise.opengl.renderers.base.ShaderBaseRenderer

Used to render one wireframed box.

Parameters

widget:
The parent QChemlabWidget
vectors: np.ndarray((3,3), dtype=float)
The three vectors representing the sides of the box.
origin: np.ndarray((3,3), dtype=float), default to zero
The origin of the box.
color: 4 int tuple
r,g,b,a color in the range [0,255]
width: float
width of wireframe lines
draw_vertices()[source]
update(vectors)[source]

Update the box vectors.

ipymd.visualise.opengl.renderers.hexagon module

Created on Mon May 16 12:41:12 2016

@author: cjs14

class ipymd.visualise.opengl.renderers.hexagon.HexagonRenderer(widget, vectors, origin=<Mock object>, color=(0, 0, 0, 255), width=1.5)[source]

Bases: ipymd.visualise.opengl.renderers.base.ShaderBaseRenderer

Used to render one wireframed hexagonal prism.

Parameters

widget:
The parent QChemlabWidget
vectors: np.ndarray((2,3), dtype=float)
The two vectors representing the orthogonal a,c crystal vectors.
origin: np.ndarray((3,), dtype=float), default to zero
The origin of the box.
color: 4 int tuple
r,g,b,a color in the range [0,255]
width: float
width of wireframe lines
draw_vertices()[source]
update(vectors)[source]

Update the box vectors.

ipymd.visualise.opengl.renderers.line module

class ipymd.visualise.opengl.renderers.line.LineRenderer(widget, startends, colors, width=1.5)[source]

Bases: ipymd.visualise.opengl.renderers.base.ShaderBaseRenderer

Render a set of lines.

_static/line_renderer.png

Parameters

widget:
The parent QChemlabWidget
startends: np.ndarray((NLINES, 2, 3), dtype=float)

Start and end position of each line in the form of an array:

s1 = [0.0, 0.0, 0.0]
startends = [[s1, e1], [s2, e2], ..]
colors: np.ndarray((NLINES, 2, 4), dtype=np.uint8)
The corresponding color of each extrema of each line.
draw_vertices()[source]
update_colors(colors)[source]

Update the colors

update_positions(vertices)[source]

Update the line positions

ipymd.visualise.opengl.renderers.point module

class ipymd.visualise.opengl.renderers.point.PointRenderer(widget, positions, colors)[source]

Bases: ipymd.visualise.opengl.renderers.base.ShaderBaseRenderer

Render colored points.

Parameters

widget:
The parent QChemlabWidget
positons: np.ndarray((NPOINTS, 3), dtype=np.float32)
Positions of the points to draw.
colors: np.ndarray((NPOINTS, 4), dtype=np.uint8) or list of tuples
Color of each point in the (r,g,b,a) format in the interval [0, 255]
draw_vertices()[source]
update_colors(colors)[source]

Update the colors

update_positions(vertices)[source]

Update the point positions

ipymd.visualise.opengl.renderers.sphere module

class ipymd.visualise.opengl.renderers.sphere.Sphere(radius, center, parallels=20, meridians=15, color=[0.0, 0.0, 0.0, 0.0])[source]

Bases: object

Create a Sphere object specifying its radius its center point. You can modulate its smoothness using the parallel and meridians settings.

rotate(axis, angle)[source]
class ipymd.visualise.opengl.renderers.sphere.SphereRenderer(widget, poslist, radiuslist, colorlist, shading='phong')[source]

Bases: ipymd.visualise.opengl.renderers.base.AbstractRenderer

Renders a set of spheres.

The method used by this renderer is approximating a sphere by using triangles. While this is reasonably fast, for best performance and animation you should use SphereImpostorRenderer

_static/sphere_renderer.png

Parameters

widget:
The parent QChemlabWidget
poslist: np.ndarray((NSPHERES, 3), dytpe=float)
A position array. While there aren’t dimensions, in the context of chemlab 1 unit of space equals 1 nm.
radiuslist: np.ndarray(NSPHERES, dtype=float)
An array with the radius of each sphere.
colorlist: np.ndarray(NSPHERES, 4) or list of tuples
An array with the color of each sphere. Suitable colors are those found in chemlab.graphics.colors or any tuple with values (r, g, b, a) in the range [0, 255]
draw()[source]
update_colors(colorlist)[source]
update_positions(positions)[source]

Update the sphere positions.

ipymd.visualise.opengl.renderers.sphere_imp module

class ipymd.visualise.opengl.renderers.sphere_imp.SphereImpostorRenderer(viewer, poslist, radiuslist, colorlist, transparent=False, shading='phong')[source]

Bases: ipymd.visualise.opengl.renderers.base.ShaderBaseRenderer

The interface is identical to SphereRenderer but uses a different drawing method.

The spheres are squares that always face the user. Each point of the sphere, along with the lighting, is calculated in the fragment shader, resulting in a perfect sphere.

SphereImpostorRenderer is an extremely fast rendering method, it is perfect for rendering a lot of spheres ( > 50000) and for animations.

_static/sphere_impostor_renderer.png
change_shading(shd_typ)[source]
draw()[source]
hide(mask)[source]
setup_shader()[source]
update_colors(colorlist)[source]
update_positions(rarray)[source]
update_radii(radiuslist)[source]

ipymd.visualise.opengl.renderers.triangle module

Created on Mon May 16 09:55:43 2016

@author: cjs14

added patch to allow for transparent surface

class ipymd.visualise.opengl.renderers.triangle.TriangleRenderer(widget, vertices, normals, colors, shading='phong', transparent=False, wireframe=False)[source]

Bases: ipymd.visualise.opengl.renderers.base.DefaultRenderer

Renders an array of triangles.

A lot of renderers are built on this, for example SphereRenderer. The implementation is relatively fast since it’s based on VertexBuffers.

_static/triangle_renderer.png

Parameters

widget:
The parent QChemlabWidget
vertices: np.ndarray((NTRIANGLES*3, 3), dtype=float)
The triangle vertices, keeping in mind the unwinding order. If the face of the triangle is pointing outwards, the vertices should be provided in clokckwise order.
normals: np.ndarray((NTRIANGLES*3, 3), dtype=float)
The normals to each of the triangle vertices, used for lighting calculations.
colors: np.ndarray((NTRIANGLES*3, 4), dtype=np.uint8)
Color for each of the vertices in (r,g,b,a) values in the interval [0, 255]
draw_vertices()[source]
setup_shader()[source]
update_colors(colors)[source]

Update the triangle colors.

update_normals(normals)[source]

Update the triangle normals.

update_vertices(vertices)[source]

Update the triangle vertices.

ipymd.visualise.opengl.renderers.triangles module

TriangleRenderer is the basics for other shapes, we pass just triangle vertices and we got the result.

class ipymd.visualise.opengl.renderers.triangles.TriangleRenderer(widget, vertices, normals, colors, shading='phong')[source]

Bases: ipymd.visualise.opengl.renderers.base.DefaultRenderer

Renders an array of triangles.

A lot of renderers are built on this, for example SphereRenderer. The implementation is relatively fast since it’s based on VertexBuffers.

_static/triangle_renderer.png

Parameters

widget:
The parent QChemlabWidget
vertices: np.ndarray((NTRIANGLES*3, 3), dtype=float)
The triangle vertices, keeping in mind the unwinding order. If the face of the triangle is pointing outwards, the vertices should be provided in clokckwise order.
normals: np.ndarray((NTRIANGLES*3, 3), dtype=float)
The normals to each of the triangle vertices, used for lighting calculations.
colors: np.ndarray((NTRIANGLES*3, 4), dtype=np.uint8)
Color for each of the vertices in (r,g,b,a) values in the interval [0, 255]
draw_vertices()[source]
setup_shader()[source]
update_colors(colors)[source]

Update the triangle colors.

update_normals(normals)[source]

Update the triangle normals.

update_vertices(vertices)[source]

Update the triangle vertices.

Module contents