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
- backend: “impostors” | “polygons” | “points”
- You can choose the rendering method between the sphere impostors, polygonal sphere and points.
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.
- widget:
-
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 ofdefault_persp.vert
anddefault_persp.frag
.
-
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 thedraw_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
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
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
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.
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.
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]
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.
-
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
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]
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.
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.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]
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.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]