Miscellaneous Functions

Utilities.usefulfunctions.append_in_dict_of_list(base, d)[source]
Utilities.usefulfunctions.apply_linear_transform_3d(points, A)[source]
Utilities.usefulfunctions.export_implicit1_growth(filename, points, growth)[source]
Utilities.usefulfunctions.export_mesh(filename, points, triangles)[source]
Utilities.usefulfunctions.export_mesh_points(filename, points)[source]
Utilities.usefulfunctions.export_point_basis(filename, points, basis)[source]
Utilities.usefulfunctions.extent_transformation4d(extent0, extent1)[source]
Utilities.usefulfunctions.flatten_tensor_list(l, out_list=None)[source]

Simple recursive list flattening function that stops at torch.Tensor (without unwrapping).

Utilities.usefulfunctions.grid2vec(*args)[source]

Convert a grid of points (such as given by torch.meshgrid) to a tensor of vectors.

Utilities.usefulfunctions.import_implicit1_growth(filename, fieldname='growth', dtype=None)[source]
Utilities.usefulfunctions.import_point_basis(filename, fieldname='basis', dtype=None)[source]
Utilities.usefulfunctions.linear_transform(points, A)[source]

Applies a linear transformation to a point tensor.

Parameters
  • points (torch.Tensor) – A \(N\times d\) tensor that will be transformed.

  • A (torch.Tensor) – A \(d\times d\) matrix that represent the linear transformation.

Returns

The transformed points.

Return type

torch.Tensor

Utilities.usefulfunctions.make_grad_graph(tensor, filename, params=None)[source]
Utilities.usefulfunctions.nel2points(nels, frame_shape, frame_extent)[source]
Utilities.usefulfunctions.pixels2points(pixels, frame_shape, frame_extent)[source]

Transform points from pixel space onto an uniformly mapped square space defined by an extent.

Utilities.usefulfunctions.points2nel(points, frame_shape, frame_extent, toindices=False)[source]
Utilities.usefulfunctions.points2pixels(points, frame_shape, frame_extent, toindices=False)[source]

Transform points to pixel space.

Utilities.usefulfunctions.points2voxels_affine(points, cube_shape, affine, toindices=False)[source]
Utilities.usefulfunctions.rigid_deformation3d(angles, translation)[source]
Utilities.usefulfunctions.rot2d(theta)[source]

Returns a 2D rotation matrix.

Utilities.usefulfunctions.rot2d_vec(thetas)[source]
Utilities.usefulfunctions.rot3d_x(theta)[source]
Utilities.usefulfunctions.rot3d_x_vec(thetas)[source]
Utilities.usefulfunctions.rot3d_y(theta)[source]
Utilities.usefulfunctions.rot3d_y_vec(thetas)[source]
Utilities.usefulfunctions.rot3d_z(theta)[source]
Utilities.usefulfunctions.rot3d_z_vec(thetas)[source]
Utilities.usefulfunctions.scale_matrix4d(scales, dtype=None)[source]
Utilities.usefulfunctions.shared_tensors_property(tensors, prop)[source]

Check if all tensors share the same property.

given by prop(tensor). Ignores None tensors and None property values. Returns the shared property or None if the property is not shared.

Parameters
  • tensors (Iterable) – Iterable of tensors we want to check the common property from.

  • prop (callable) – Callable function which outputs the parameter we want to compare of the input tensor.

Returns

Common property shared by all tensors. Returns none if properties are different among the tensors.

Return type

object

Utilities.usefulfunctions.tensors_device(tensors)[source]

Returns the common device on which tensors (an iterable of torch.Tensor) lives. Return None if tensors are on different devices.

Parameters

tensors (Iterable) – Iterable of tensors.

Returns

The common device of the iterable of tensors. None if tensors lives on different devices.

Return type

torch.device

Utilities.usefulfunctions.tensors_dtype(tensors)[source]

Returns the common dtypes on which tensors (an iterable of torch.Tensor) lives. Return None if tensors are of different dtypes.

Parameters

tensors (Iterable) – Iterable of tensors.

Returns

The common dtype of the iterable of tensors. None if tensors lives on different devices.

Return type

torch.dtype

Utilities.usefulfunctions.translation_matrix4d(translation, dtype=None)[source]
Utilities.usefulfunctions.vec2grid(vec, *args)[source]

Convert a tensor of vectors to a grid of points.

Utilities.usefulfunctions.voxels2points_affine(voxels, cube_shape, affine)[source]