Bodies¶
Bodies are used to model physical objects like samples, optical elements like
gratings, etc. A MovableBody
can be moved by using an instance of
syris.geometry.Trajectory
. It is also possible to move it by
manipulating its transformation matrix directly. CompositeBody
can
contain multiple bodies in order to model complex motion patterns, e.g. a
robotic arm.
Base¶
A base module for pysical bodies, which are optical elements having spatial extent.
- class syris.bodies.base.Body(material=None)¶
An abstract body class with a material, which is a
syris.materials.Material
instance.- project(shape, pixel_size, offset=None, t=None, queue=None, out=None, block=False)¶
Project thickness at time t to the image plane of size shape which is either 1D and is extended to (n, n) or is 2D as HxW. pixel_size is the point size, also either 1D or 2D. offset is the physical spatial body offset as (y, x). queue is an OpenCL command queue, out is the pyopencl array used for result. If block is True, wait for the kernel to finish.
- class syris.bodies.base.CompositeBody(trajectory, orientation=array([0., 1., 0.]) * dimensionless, bodies=None)¶
Class representing a body consisting of more sub-bodies. A composite body can be thought of as a tree structure with children representing another bodies.
- add(body)¶
Add a body body.
- property all_bodies¶
All bodies inside this body recursively.
- bind_trajectory(pixel_size)¶
Bind trajectory for pixel_size.
- property bodies¶
All bodies which are inside this composite body.
- property bounding_box¶
Get bounding box around all the bodies inside.
- clear_transformation()¶
Clear all transformations.
- property direct_primitive_bodies¶
Return primitive bodies on the level immediately after this body’s level.
- property furthest_point¶
Furthest point is 0 for composite object.
- get_distance(t_0, t_1)¶
Return the translational and rotational travelled distance in time interval t_0, t_1.
- get_maximum_dt(pixel_size)¶
Get the maximum delta time for which the body will not move more than pixel_size divided by the number of bodies because their movement can sum up constructively.
- get_next_time(t_0, pixel_size, xtol=1e-12)¶
Get next time at which the body will have traveled pixel_size, the starting time is t_0. xtol is the absolute tolerance for bisection passed to
scipy.optimize.bisect()
.
- move(abs_time, clear=True)¶
Move to a position of the body in time abs_time. If clear is true clear the transformation matrix first.
- moved(t_0, t_1, pixel_size)¶
Return True if the body moves more than pixel_size in time interval t_0, t_1.
- remove(body)¶
Remove body body.
- remove_all()¶
Remove all sub-bodies.
- restore_transformation_matrices()¶
Restore transformation matrices of all bodies.
- rotate(angle, vec, shift=None)¶
Rotate the body by angle around vector vec, where shift is the translation which takes place before the rotation and -shift takes place afterward, resulting in the transformation TRT^-1. Sub-bodies are rotated with respect to their relative position to the composite body.
- save_transformation_matrices()¶
Save transformation matrices of all bodies and return them in a dictionary {body: transform_matrix}.
- property time¶
The total trajectory time of the body and all its subbodies.
- translate(vec)¶
Translate all sub-bodies by a vector vec.
- class syris.bodies.base.MovableBody(trajectory, material=None, orientation=array([0., 1., 0.]) * dimensionless, cache_projection=True)¶
Class representing a movable body.
- apply_transformation(trans_matrix)¶
Apply transformation given by the transformation matrix trans_matrix on the current transformation matrix.
- bind_trajectory(pixel_size)¶
Bind trajectory for pixel_size.
- property bounding_box¶
Bounding box defining the extent of the body.
- property cache_projection¶
Whether or not projection cache is being used.
- property center¶
Center.
- clear_transformation()¶
Clear all transformations.
- property furthest_point¶
The furthest point from body’s center with respect to the scaling factor of the body.
- get_distance(t_0, t_1)¶
Return the maximum principal axes translational and rotational travelled distance in time interval t_0, t_1.
- get_maximum_dt(pixel_size)¶
Get the maximum delta time for which the body will not move more than pixel_size between any two time points.
- get_next_time(t_0, pixel_size)¶
Get time from t_0 when the body will have travelled more than pixel_size.
- get_rescaled_transform_matrix(units, coeff=1)¶
The last column of the transformation matrix holds displacement information has SI units, convert those to the units specified, apply coefficient coeff and return a copy of the matrix.
- property last_position¶
Last position.
- move(abs_time, clear=True)¶
Move to a position of the body in time abs_time. If clear is true clear the transformation matrix first.
- moved(t_0, t_1, pixel_size, bind=True)¶
Return True if the body moves more than pixel_size in time interval t_0, t_1. If bind is True bind the trajectory to the specified pixel_size, otherwise use the trajectory as-is to compute an estimate.
- property position¶
Current position.
- project(shape, pixel_size, offset=None, t=None, queue=None, out=None, block=False)¶
Project thickness at time t (if it is None no transformation is applied) to the image plane of size shape which is either 1D and is extended to (n, n) or is 2D as HxW. pixel_size is the point size, also either 1D or 2D. offset is the physical spatial body offset as (y, x). queue is an OpenCL command queue, out is the pyopencl array used for result. If block is True, wait for the kernel to finish.
- rotate(angle, axis, shift=None)¶
Rotate the body by angle around vector vec, where shift is the translation which takes place before the rotation and -shift takes place afterward, resulting in the transformation TRT^-1.
- translate(vec)¶
Translate the body by a vector vec.
- update_projection_cache(t=None, shape=None, pixel_size=None, offset=None, projection=None)¶
Update projection cache with time t, shape, pixel_size, offset and projection.
Simple Bodies¶
A static body.
- class syris.bodies.simple.StaticBody(thickness, pixel_size, material=None, queue=None)¶
A static body is defined by its projected thickness, which is a quantity and it is always converted to meters, thus the
project()
method always returns the projection in meters. pixel_size is the pixel size of the thickness and material is asyris.materials.Material
instance. Use OpenCL command queue.- get_next_time(t_0, distance)¶
A simple body doesn’t move, this function returns infinity.
- syris.bodies.simple.make_grid(n, period, width=array(1.) * m, thickness=array(1.) * m, pixel_size=array(1.) * m, material=None, queue=None)¶
Make a rectangluar grid with shape (n, n), the bars are spaced period and are width in diameter. thickness is the projected thickness and pixel_size, material and queue, which is an OpenCL command queue, are used to create
StaticBody
.
- syris.bodies.simple.make_sphere(n, radius, pixel_size=array(1.) * m, material=None, queue=None)¶
Make a sphere with image shape (n, n), radius and pixel_size. Sphere center is in n / 2 + 0.5, which means between two adjacent pixels. pixel_size, material and queue, which is an OpenCL command queue, are used to create
StaticBody
.
Isosurfaces¶
Bodies based on isosurfaces.
- class syris.bodies.isosurfaces.MetaBall(trajectory, radius, material=None, orientation=array([0., 1., 0.]) * dimensionless)¶
“Metaball bodies are smooth blobs formed by summing density functions representing particular bodies.
- property bounding_box¶
Bounding box of the metaball.
- property furthest_point¶
Furthest point is twice the radius because of the influence region of the metaball.
- get_transform_const()¶
Precompute the transformation constant which does not change for x,y position.
- pack()¶
Pack the body into a structure suitable for OpenCL kernels. Packed units are in meters.
- class syris.bodies.isosurfaces.MetaBalls(trajectory, metaballs, orientation=array([0., 1., 0.]) * dimensionless)¶
Composite body composed of metaballs.
- syris.bodies.isosurfaces.get_format_string(string)¶
Get string in single or double precision floating point number format.
- syris.bodies.isosurfaces.get_moved_groups(bodies, t_0, t_1, distance)¶
Filter only bodies which truly move in the time interval t_0, t_1 more than distance. Return a set of moved groups, where a group is defined by the last composite body which holds only primitive bodies. If a primitive body is in the bodies it is included without further testing because if it didn’t move it wouldn’t be in the list.
- syris.bodies.isosurfaces.project_metaballs(metaballs, shape, pixel_size, offset=None, queue=None, out=None, block=False)¶
Project a list of
MetaBall
on an image plane with shape, pixel_size. offset is the physical spatial body offset as (y, x). Use OpenCL queue and out pyopencl Array instance for returning the result. If block is True, wait for the kernel to finish.
- syris.bodies.isosurfaces.project_metaballs_naive(metaballs, shape, pixel_size, offset=None, z_step=None, queue=None, out=None, block=False)¶
Project a list of
MetaBall
on an image plane with shape, pixel_size. z_step is the physical step in the z-dimension, if not specified it is the same as pixel_size. offset is the physical spatial body offset as (y, x). Use OpenCL queue and out pyopencl Array instance for returning the result. If block is True, wait for the kernel to finish.
Meshes¶
Bodies made from mesh.
- class syris.bodies.mesh.Mesh(triangles, trajectory, material=None, orientation=array([0., 1., 0.]) * dimensionless, iterations=1, center='bbox')¶
Rigid Body based on triangles which form a polygon mesh. The triangles are a 2D array with shape (3, N), where N / 3 is the number of triangles. One polygon is formed by three consecutive triangles, e.g. when:
triangles = [[Ax, Bx, Cx] [Ay, By, Cy] [Az, Bz, Cz]]
then A, B, C are one triangle’s points. iterations are the number of iterations within one pixel which try to find an intersection. center determines the center of the local coordinates, it can be one of None, ‘bbox’, ‘gravity’ or a (x, y, z) tuple specifying an arbitrary point.
- property areas¶
Triangle areas.
- property bounding_box¶
Bounding box implementation.
- property center_of_bbox¶
The bounding box center.
- property center_of_gravity¶
Get body’s center of gravity as (x, y, z).
- compute_slices(shape, pixel_size, queue=None, out=None, offset=None)¶
Compute slices with shape as (z, y, x), pixel_size. Use queue and out for outuput. Offset is the starting point offset as (x, y, z).
- property diff¶
Smallest and greatest difference between all mesh points in all three dimensions. Returns ((min(dx), max(dx)), (min(dy), max(dy)), (min(dz), max(dz))).
- property extrema¶
Mesh extrema as ((x_min, x_max), (y_min, y_max), (z_min, z_max)).
- property furthest_point¶
Furthest point from the center.
- get_degenerate_triangles(eps=array(0.001) * deg)¶
Get triangles which are close to be parallel with the ray in z-direction based on the current transformation matrix. eps is the tolerance for the angle between a triangle and the ray to be still considered parallel.
- property max_triangle_x_diff¶
Get the greatest x-distance between triangle vertices.
- property normals¶
Triangle normals.
- property num_triangles¶
Number of triangles in the mesh.
- sort()¶
Sort triangles based on the greatest x-coordinate in an ascending order. Also sort vertices inside the triangles so that the greatest one is the last one, however, the position of the two remaining ones is not sorted.
- transform()¶
Apply transformation matrix and return the resulting triangles.
- property triangles¶
Return current triangle mesh.
- property vectors¶
The triangles as B - A and C - A vectors where A, B, C are the triangle vertices. The result is transposed, i.e. axis 1 are x, y, z coordinates.
- syris.bodies.mesh.make_cube()¶
Create a cube triangle mesh from -1 to 1 m in all dimensions.
- syris.bodies.mesh.read_blender_obj(filename, objects=None)¶
Read blender wavefront filename, extract only objects which are object indices.