fresnel.geometry#

Overview

Box

Box geometry.

ConvexPolyhedron

Convex polyhedron geometry.

Cylinder

Cylinder geometry.

Geometry

Geometry base class.

Mesh

Mesh geometry.

Polygon

Polygon geometry.

Sphere

Sphere geometry.

Details

Geometric primitives.

Geometry defines objects that are visible in a Scene. The base class Geometry provides common operations and properties. Instantiate specific geometry class to add objects to a Scene.

class fresnel.geometry.Box(scene, box, box_radius=0.5, box_color=[0, 0, 0])#

Bases: Cylinder

Box geometry.

Generate a triclinic box outline with spherocylinders. The geometry’s material defaults to material.Material(solid=1.0).

Parameters:
  • scene (Scene) – Add the geometry to this scene.

  • box ((1, ), (3, ), or (6, ) numpy.ndarray of float32) – Box parameters.

  • box_radius (float) – Radius of box edges.

  • box_color ((3, ) numpy.ndarray of float32) – Color of the box edges.

Note

A 1-element box array expands to a cube. A 3-element box array [Lx, Ly, Lz] expands to an orthorhobic cuboid, and a 6-element box array represents a fully triclinic box in the same format as GSD and HOOMD: [Lx, Ly, Lz, xy, xz, yz].

See also

Tutorials:

Note

The Box class is constructed from spherocylinders, which can be modified individually. The convenience attributes box_radius and box_color can be used to set the thickness and color of the entire box.

property box#

Box parameters.

Set box to update the shape of the box.

Type:

(1, ), (3, ), or (6, ) numpy.ndarray of float32

property box_color#

Color of the box edges.

Note

This property sets the color of the material.

Type:

(3, ) numpy.ndarray of float32

property box_radius#

Radius of box edges.

Type:

(float)

class fresnel.geometry.ConvexPolyhedron(scene, polyhedron_info, position=(0, 0, 0), orientation=(1, 0, 0, 0), color=(0, 0, 0), N=None, material=None, outline_material=None, outline_width=0.0)#

Bases: Geometry

Convex polyhedron geometry.

Define a set of convex polyhedron primitives with individual positions, orientations, and colors.

A convex polyhedron is defined by P outward facing planes (origin and normal vector) and a radius that encompass the shape. Use convex_polyhedron_from_vertices to construct this from the convex hull of a set of vertices.

Parameters:
  • scene (Scene) – Add the geometry to this scene.

  • polyhedron_info (Dict) – A dictionary containing the face normals (face_normal), origins (face_origin), face colors (face_color), and the radius (radius)).

  • position ((N, 3) numpy.ndarray of float32) – Position of each polyhedron instance.

  • orientation ((N, 4) numpy.ndarray of float32) – Orientation of each polyhedron instance (as a quaternion).

  • color ((N, 3) numpy.ndarray of float32) – Color of each polyhedron.

  • N (int) – Number of spheres in the geometry. If None, determine N from position.

  • material (material.Material) – Define how light interacts with the geometry. When None, defaults to material.Material().

  • outline_material (material.Material) – Define how light interacts with the geometry’s outline. When None, defaults to solid black material.Material(solid=1, color=(0,0,0)).

  • outline_width (float) – Width of the outline in scene units.

See also

Tutorials:

Hint

Avoid costly memory allocations and type conversions by specifying primitive properties in the appropriate array type.

property color#

The color of each polyhedron.

Type:

(N, 3) Array

property color_by_face#

Mix face colors with the per-polyhedron color.

Set to 0 to color particles by the per-particle color. Set to 1 to color faces by the per-face color. Set to a value between 0 and 1 to blend between the two colors.

Type:

float

get_extents()#

Get the extents of the geometry.

Returns:

The lower left and upper right corners of the scene.

Return type:

(3,2) numpy.ndarray of float32

property orientation#

The orientation of each polyhedron.

Type:

(N, 4) Array

property position#

The position of each polyhedron.

Type:

(N, 3) Array

class fresnel.geometry.Cylinder(scene, points=((0, 0, 0), (0, 0, 0)), radius=0.5, color=(0, 0, 0), N=None, material=None, outline_material=None, outline_width=0.0)#

Bases: Geometry

Cylinder geometry.

Define a set of spherocylinder primitives with individual start and end positions, radii, and colors.

Parameters:
  • scene (Scene) – Add the geometry to this scene.

  • points ((N, 2, 3) numpy.ndarray of float32) – N cylinder start and end points.

  • radius ((N, ) numpy.ndarray of float32) – Radius of each cylinder.

  • color ((N, 2, 3) numpy.ndarray of float32) – Color of each start and end point.

  • N (int) – Number of cylinders in the geometry. When None, determine N from points.

  • material (material.Material) – Define how light interacts with the geometry. When None, defaults to material.Material().

  • outline_material (material.Material) – Define how light interacts with the geometry’s outline. When None, defaults to solid black material.Material(solid=1, color=(0,0,0)).

  • outline_width (float) – Width of the outline in scene units.

See also

Tutorials:

Hint

Avoid costly memory allocations and type conversions by specifying primitive properties in the appropriate array type.

Tip

When all cylinders are the same size or color, pass a single value and NumPy will broadcast it to all elements of the array.

property color#

Color of each start and end point.

Type:

(N, 2, 3) Array

get_extents()#

Get the extents of the geometry.

Returns:

The lower left and upper right corners of the scene.

Return type:

(3,2) numpy.ndarray of float32

property points#

The start and end points of the cylinders.

Type:

(N, 2, 3) Array

property radius#

The radii of the cylinders.

Type:

(N, ) Array

class fresnel.geometry.Geometry#

Bases: object

Geometry base class.

Geometry provides operations and properties common to all geometry classes.

Note

You cannot instantiate a Geometry directly. Use one of the subclasses.

disable()#

Disable the geometry.

When disabled, the geometry will not visible in the Scene.

See also

enable

enable()#

Enable the geometry.

When enabled, the geometry will be visible in the Scene.

See also

disable

property material#

Define how light interacts with the geometry.

Type:

material.Material

property outline_material#

Define how light interacts with the geometry’s outline.

Type:

material.Material

property outline_width#

Width of the outline in scene units.

Type:

float

remove()#

Remove the geometry from the scene.

After calling remove, the geometry is no longer part of the scene. It cannot be added back into the scene. Use disable and enable hide geometry reversibly.

class fresnel.geometry.Mesh(scene, vertices, position=(0, 0, 0), orientation=(1, 0, 0, 0), color=(0, 0, 0), N=None, material=None, outline_material=None, outline_width=0.0)#

Bases: Geometry

Mesh geometry.

Define a set of triangle mesh primitives with individual positions, orientations, and colors.

Parameters:
  • scene (Scene) – Add the geometry to this scene.

  • vertices ((3T, 3) numpy.ndarray of float32) – Vertices of the triangles, listed contiguously. Vertices 0,1,2 define the first triangle, 3,4,5 define the second, and so on.

  • color ((3T, 3) numpy.ndarray of float32) – Color of each vertex.

  • position ((N, 3) numpy.ndarray of float32) – Position of each mesh instance.

  • orientation ((N, 4) numpy.ndarray of float32) – Orientation of each mesh instance (as a quaternion).

  • N (int) – Number of mesh instances in the geometry. If None, determine N from position.

  • material (material.Material) – Define how light interacts with the geometry. When None, defaults to material.Material().

  • outline_material (material.Material) – Define how light interacts with the geometry’s outline. When None, defaults to solid black material.Material(solid=1, color=(0,0,0)).

  • outline_width (float) – Width of the outline in scene units.

See also

Tutorials:

Hint

Avoid costly memory allocations and type conversions by specifying primitive properties in the appropriate array type.

property color#

The color of each sphere.

Type:

(N, 3) Array

get_extents()#

Get the extents of the geometry.

Returns:

The lower left and upper right corners of the scene.

Return type:

(3,2) numpy.ndarray of float32

property orientation#

The orientation of each mesh.

Type:

(N, 4) Array

property position#

The position of each mesh.

Type:

(N, 3) Array

class fresnel.geometry.Polygon(scene, vertices, position=(0, 0), angle=0, color=(0, 0, 0), rounding_radius=0, N=None, material=None, outline_material=None, outline_width=0.0)#

Bases: Geometry

Polygon geometry.

Define a set of simple polygon primitives in the xy plane with individual positions, rotation angles, and colors.

Parameters:
  • scene (Scene) – Add the geometry to this scene.

  • vertices ((N_vert, 2) numpy.ndarray of float32) – Polygon vertices.

  • position ((N, 2) numpy.ndarray of float32) – Position of each polygon.

  • angle ((N, ) numpy.ndarray of float32) – Orientation angle of each polygon (in radians).

  • color ((N, 3) numpy.ndarray of float32) – Color of each polygon.

  • rounding_radius (float) – Rounding radius for spheropolygons.

  • N (int) – Number of polygons in the geometry. If None, determine N from position.

  • material (material.Material) – Define how light interacts with the geometry. When None, defaults to material.Material().

  • outline_material (material.Material) – Define how light interacts with the geometry’s outline. When None, defaults to solid black material.Material(solid=1, color=(0,0,0)).

  • outline_width (float) – Width of the outline in scene units.

See also

Tutorials:

Hint

Avoid costly memory allocations and type conversions by specifying primitive properties in the appropriate array type.

property angle#

The rotation angle of each polygon (in radians).

Type:

(N, ) Array

property color#

The color of each polygon.

Type:

(N, 2, 3) Array

get_extents()#

Get the extents of the geometry.

Returns:

The lower left and upper right corners of the scene.

Return type:

(3,2) numpy.ndarray of float32

property position#

The position of each polygon.

Type:

(N, 2) Array

class fresnel.geometry.Sphere(scene, position=(0, 0, 0), radius=0.5, color=(0, 0, 0), N=None, material=None, outline_material=None, outline_width=0.0)#

Bases: Geometry

Sphere geometry.

Define a set of sphere primitives with individual positions, radii, and colors.

Parameters:
  • scene (Scene) – Add the geometry to this scene.

  • position ((N, 3) numpy.ndarray of float32) – Position of each sphere.

  • radius ((N, ) numpy.ndarray of float32) – Radius of each sphere.

  • color ((N, 3) numpy.ndarray of float32) – Color of each sphere.

  • N (int) – Number of spheres in the geometry. If None, determine N from position.

  • material (material.Material) – Define how light interacts with the geometry. When None, defaults to material.Material().

  • outline_material (material.Material) – Define how light interacts with the geometry’s outline. When None, defaults to solid black material.Material(solid=1, color=(0,0,0)).

  • outline_width (float) – Width of the outline in scene units.

See also

Tutorials:

Hint

Avoid costly memory allocations and type conversions by specifying primitive properties in the appropriate array type.

Tip

When all spheres are the same size, pass a single value for radius and numpy will broadcast it to all elements of the array.

property color#

The color of each sphere.

Type:

(N, 3) Array

get_extents()#

Get the extents of the geometry.

Returns:

The lower left and upper right corners of the scene.

Return type:

(3,2) numpy.ndarray of float32

property position#

The position of each sphere.

Type:

(N, 3) Array

property radius#

The radius of each sphere.

Type:

(N, ) Array